Mobx-state-tree: how to define a tree-like model which the type of it's child is self?????

Created on 25 Dec 2017  路  1Comment  路  Source: mobxjs/mobx-state-tree

how to define a tree-like model which the type of it's child is self?????

const DomNode = types.model('DomNode', {
    id: types.identifier(), 
    animationAttr: types.array(types.string),
    style: types.reference(DomStyle),
    children: types.optional(types.array(DomNode), []),
    edittable: types.maybe(types.boolean),
    draggable: types.maybe(types.boolean)
})

then i get:
index.js:15817 Uncaught Error: [mobx-state-tree] expected a mobx-state-tree type as first argument, got undefined instead

the DomNode is undefined before it is created.

Most helpful comment

ha~ i found it. types.optional(types.array(types.late(()=>DomNode)), []), works well.

>All comments

ha~ i found it. types.optional(types.array(types.late(()=>DomNode)), []), works well.

Was this page helpful?
0 / 5 - 0 ratings