mobx-persist icon indicating copy to clipboard operation
mobx-persist copied to clipboard

How to do a Recursive Schema Definition

Open stoefln opened this issue 5 years ago • 0 comments

I am having issues hydrating a store which contains a tree data structure consisting of TreeNode objects. The problem is that the instances get hydrated as objects instead of TreeNodes. My guess is (after reading https://github.com/pinqy520/mobx-persist/issues/25) that I can't use a class definition for persist within the class itself.

Thats my TreeNode class:

export default class TreeNode {
   
    @persist id = Math.random();
    @persist @observable title = "Root";
    @persist @observable collapsed = false; // if node should be shown opened
    @persist('list', TreeNode) @observable childNodes  = []; // <- should this work?
    ...

Can you help me with this?

stoefln avatar Jan 02 '19 21:01 stoefln