How can I handle such type of error - [mobx-state-tree] Failed to resolve reference of type ComponentItem: 'HkU52t7S-' (in: /assignments/0/layout) ?
For example I have this three models:
const Page = types.model(
{
id: types.identifier(),
label: types.maybe(types.string)
}
)
const Navigation = types.model(
{
id: types.identifier(),
page: types.maybe(types.reference(Page))
}
)
const Store = types.model(
{
navigation: types.maybe(types.array(Navigation))
}
)
Now I am adding (from lookup) some Page as a reference for Navigation - everything works as expected. But then I am removing this Page and now I am getting this above error. This error is obvious - node has been deleted so it can't be find. Is there an option to clear (ie. set this reference as null instead of throw an error) all places in the tree where this node was marked as a reference?
As now internally we don't store that. You could achieve that by using walk and getPath to store all the path where that reference is being used :) There is no builtin methods to reset them because how to reset may change based on how the user reason about the data structure :)
Reformulated question to:
_add support for finding (and automatically clearing?) backreferences_
Potentially quite easy to implement MVP, implementing it efficiently is a little harder
Custom references allows building more forgiving references. Feel free to reopen if something like this is still needed
Most helpful comment
As now internally we don't store that. You could achieve that by using walk and getPath to store all the path where that reference is being used :) There is no builtin methods to reset them because how to reset may change based on how the user reason about the data structure :)