mobx-persist
mobx-persist copied to clipboard
How to do a Recursive Schema Definition
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?