Monday 9 September 2019

How to deal with inconsistent mobx-state-tree snapshots?

I am writing an electron app and I keep all my app data inside a single MST tree. Now I noticed that every now and then you run into a situation where data becomes inconsistent (missing reference object etc). While this can happen with any type of database, I see a particular problem with MST:

Since we have a single tree which is deserialised on start of the app and then used as a single snapshot, a single inconsistency will cause the whole application to fail. Not a single piece of data will be available to my application.

Any hints on how to deal with that?

More information

Currently I create a snapshot everytime the tree changes (onSnapshot) and save it in localStorage. So a error-usecase would be: create mst object -> create reference in some other part of the tree -> delete mst object -> onSnapshot gets triggered -> corrupt tree gets persisted. Reloading the application won't help, cause tree is persisted in corrupt state.



from How to deal with inconsistent mobx-state-tree snapshots?

No comments:

Post a Comment