Mobx: Can mobx persist state (a la redux)?

Created on 7 Jul 2016  ยท  7Comments  ยท  Source: mobxjs/mobx

Hey there,

Just had a question I didn't see an answer to when searching the issues/google: does mobx have a way to persist state between page refreshes like redux devtools persistState functionality?

Thanks!

โ” question

Most helpful comment

Hi,

MobX doesn't provide a standard app architecture that prescribes how to organize the state, so the answer is, it depends. If you use a plain object tree it is pretty simple, if you use a plain object graph mobx.toJSON will suffice as well. If you use compex objects (classes / constructores), there is currently the serializr package in development that provides the tools to (de) serialize complex object graphs. But existing ORM libraries might help as well.

Usually setting an efficient serialization mechanism yourself is also not too hard, see for example https://github.com/mobxjs/mobx-reactive2015-demo/blob/master/src/stores/domain-state.js#L46

I hope that helps!

All 7 comments

Hi,

MobX doesn't provide a standard app architecture that prescribes how to organize the state, so the answer is, it depends. If you use a plain object tree it is pretty simple, if you use a plain object graph mobx.toJSON will suffice as well. If you use compex objects (classes / constructores), there is currently the serializr package in development that provides the tools to (de) serialize complex object graphs. But existing ORM libraries might help as well.

Usually setting an efficient serialization mechanism yourself is also not too hard, see for example https://github.com/mobxjs/mobx-reactive2015-demo/blob/master/src/stores/domain-state.js#L46

I hope that helps!

You might want to take a look at https://github.com/AriaFallah/mobx-store.

As of May 2018, it looks like 'mobx-store' has had no updates for 2 years and was archived on Github, so, can I instead suggest:

https://github.com/pinqy520/mobx-persist

@sixman9 even mobx-persist seems to be dead.
surprising there is no good solutions out there

@pdeva please refrain from comment on issues that are closed for over a year, most people won't see it.

Standardized persisting solutinos are the serializable and mobx-state-tree package. But if you limit your self (like in Redux) to pure data trees to store the data, you don't even need that, and a simple JSON.stringify(state) will do. For further questions, please open a new issue

vue has "vuex-persistedstate", redux has "redux-persist", so can we has "mobx-persist" package?

@sixman9 even mobx-persist seems to be dead.
surprising there is no good solutions out there

What you mean? dead?
Is it still work now?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

giacomorebonato picture giacomorebonato  ยท  3Comments

cafreeman picture cafreeman  ยท  4Comments

kirhim picture kirhim  ยท  3Comments

josvos picture josvos  ยท  3Comments

kmalakoff picture kmalakoff  ยท  4Comments