Menu

1 / 3

react-mobx-manager 4.6.0: persisting MobX stores without rewriting all of them

DEV Community: react·Melissa Ashford·13 days ago
#95LAZW4I
#devtoreact#devto#dev#manager#storage
Reading 0:00
15s threshold

Persistence in react-mobx-manager used to be simple and a bit wasteful. Every persisted store had a MobX reaction on toJS(store) , and toJS walks every observable the store can reach, including other stores referenced from its fields. So a loading flag flipping in one store could make another store serialize itself again. Then every save wrote the whole storage value: one JSON blob holding all persisted stores.

Version 4.6.0 (released 30 September, PR #53, promoted to latest in #54) reworks this. Short version: it saves less, and less often.

What the listener watches now

The change listener tracks only the fields that are actually persisted. That is the union of the attributes you route to storages, or all exported fields when you use '*' . Stores referenced from those fields are no longer traversed.

So if a persisted store also has short-lived fields, keep them out of storage.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.