type alias Node = { children : Children }
type Children = Children (List Node)
deserializeJsonNode jsonNode =
{ jsonNode
| children =
Children <| List.map deserializeJsonNode jsonNode.children
}
port initialModel : {} -- ?
model =
deserializeJsonNode initialModel
var tree =
{ children: [
{ children: [
{ children: [] },
{ children: [] },
]},
{ children: [] }
]};
Elm.embed(Elm.App, element, { initialModel: tree });
var tree =
{ id: 1, children: [
{ id: 2, children: [
{ id: 3, children: [] },
{ id: 4, children: [] },
]},
{ id: 5, children: [] }
]};
var app = Elm.embed(Elm.App, element);
// psuedo code starts here
addChildToParent = function(node, parentNode) {
app.ports.addChildToParent(node, parentNode)
node.children.each(function() {
addChildToParent(this, node);
});
};
addChildToParent(tree, null);
// end psuedo code
// JavaScript
var tree =
{ children: [
{ children: [
{ children: [] },
{ children: [] },
]},
{ children: [] }
]};
Elm.worker(Elm.App, { model: tree });
-- Elm
port model : ???
That’s not quite true. There are other things that may pass through as well, for example List
s and Maybe
s, which are neither primitive types, nor Json.Decode.Value
s. See http://elm-lang.org/guide/interop#customs-and-border-protection.
To clarify the solution for posterity: Elm ports only allow primitive types through... and additionally, `Json.Decode.Value`s.
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Or, actually, yes, you are right. The Json.Decode.Value
gets through and then is decoded to some of these other things like List
s and Maybe
s.