Is there any documentation out there for what [<Pojo>] is supposed to do? I got the redux sample and figured it unwraps discriminated unions. The problem was that I have the action defined as a discriminated union but redux does not allow anything but a object literal to be passed as action so a discriminated union cannot be the action.
So the following type
[<Pojo>]
type TodoAction =
| EditTodo of id:int * text:string
| ClearCompleted
console.log(EditTodo(22,"Hello World"))
console.log(ClearCompleted)
compiles to:
console.log({
type: "EditTodo",
id: 22,
text: "Hello World"
});
console.log({
type: "ClearCompleted"
});
Is it a lucky "accident" that the object literal has a "type" property (you need this in redux).
Without Pojo it would be:
console.log(new TodoAction("EditTodo", [22, "Hello World"]));
console.log(new TodoAction("ClearCompleted", []));
That doesn't work if you try to store.dispatch that because an action can only be an object literal (that has a "type" property)
So trying to reverse engineer from a working example is fun but having a documentation that says how it's supposed to work is even more fun.
Is there such a thing?
Using grep in the root source directory got the the following file: ./src/fable/Fable.Core/Fable.Core.fs
with:
/// Compile a record as a JS object literals.
/// More info: http://fable.io/docs/interacting.html
type PojoAttribute() =
inherit Attribute()
but docs interacting has no such thing as more information on what it does. I will try to play with it a little more and see if it's possible to use the value as a union or if it's already unwrapped.
If the creator/contributer of Fable happens to read this; thank you, this is a great idea and I'd love to contribute if needed.
So the question is: where is the documentation if there is no such thing then how do we create it? I'd love to write some but would only be guessing as to how most of the fable compiler works.
If you get the following error:
error FSHARP: The type 'Pojo' is not defined
Please make sure you import Fable.core.dll and open it:
#r "./node_modules/fable-core/Fable.Core.dll"
open Fable.Core