Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support?! to mobx-state-tree #37

Closed
yordis opened this issue Nov 23, 2017 · 12 comments
Closed

Add support?! to mobx-state-tree #37

yordis opened this issue Nov 23, 2017 · 12 comments

Comments

@yordis
Copy link

yordis commented Nov 23, 2017

Any idea how can we use this with mobx-state-tree?

@pinqy520
Copy link
Owner

#33

@yordis
Copy link
Author

yordis commented Nov 24, 2017

@pinqy520 I think is worth to add that example to the readme, it will help a lot people.

But also the point of my request this is to have the same API, where you can setup the storage you want and the fields of the data structure you want to save by default. Just look how many checks like one https://github.com/mobxjs/mobx-state-tree/blob/master/packages/mst-example-bookshop/src/stores/CartStore.js#L56 is happening. The proposal is to use a common package for this interaction.

@pinqy520
Copy link
Owner

I think I understand your request now, and I will try to support MST when I have time. My job is quite busy, recently.

@yordis
Copy link
Author

yordis commented Jan 12, 2018

@pinqy520 hey man, are you gonna consider to open this issue?

@nickbreaton
Copy link

If it is decided to make this a separate package, I grabbed the npm name mst-persist a while back, but never did anything with it. Ping me if you want to publish under that name and I'll hand it over.

@codybrouwers
Copy link

Found this gist that I might try using:
https://gist.github.com/benjick/c48dd2db575e79c7b0b1043de4556ebc

Otherwise, I too would be interested in direct mobx state tree support from this library.

@tallpants
Copy link

tallpants commented Sep 7, 2018

If anyone's interested, I have a super simple working example repo that includes a helper to initialize the store and configure it for persistence, a way to pass in a default state snapshot for when no persisted state is found, an injectStore HOC, and a <PersistGate /> component similar to Redux Persist that delays rendering until the store is initialized: https://github.com/tallpants/mobx-state-tree-persist-example

It's web only, but you can adapt it for React Native by changing storage.js to use AsyncStorage instead of localforage.

@AdamGerthel
Copy link

AdamGerthel commented Sep 10, 2018

I haven't used MST, but it looks like you don't really need more than a few lines of code to do this without mobx-persist since MST already handles all the serialization/deserialization. In the egghead video by the MobX creator (Michel Weststrate), it looks extremely straightforward:
https://egghead.io/lessons/react-store-store-in-local-storage

agilgur5 added a commit to agilgur5/react-native-manga-reader-app that referenced this issue May 19, 2019
- made a bunch of changes, but works in mostly the same fashion
  - mostly additions and superificial changes to the underlying code
    - e.g. whitelists + blacklists (and as arrays, like redux-persist),
      persist returns promise instead of calling `afterHydration`, etc

- wanted lib per pinqy520/mobx-persist#37 ,
  but only gists and examples around
  - it's a tiny wrapper library for now, but still faster than writing
    by yourself

- installing via GH since empty NPM package is owned by someone else rn
  - pinqy520/mobx-persist#37 (comment)
agilgur5 added a commit to agilgur5/react-native-manga-reader-app that referenced this issue May 19, 2019
- made a bunch of changes, but works in mostly the same fashion
  - mostly additions and superificial changes to the underlying code
    - e.g. whitelists + blacklists (and as arrays, like redux-persist),
      persist returns promise instead of calling `afterHydration`, etc

- wanted lib per pinqy520/mobx-persist#37 ,
  but only gists and examples around
  - it's a tiny wrapper library for now, but still faster than writing
    by yourself

- installing via GH since empty NPM package is owned by someone else rn
  - pinqy520/mobx-persist#37 (comment)
@agilgur5
Copy link

Hey folks, since there were a bunch of examples here, but no concrete library, I decided to make my own at agilgur5/mst-persist. It takes as inspiration some of the examples here, as well as mobx-persist and redux-persist.

I extracted it out of an RN app of mine and it's currently being used in it in production there. It supports whitelists and blacklists out-of-the-box and I'm planning on adding transforms to support some of my own use cases as well.

@nickbreaton would appreciate if you could transfer ownership of the NPM package to me so I can publish it under the same name! :)

Since the dependencies are different between mobx-persist (MobX and serializr) and mst-persist (just MST), I didn't think a PR made sense. That being said, a bunch of the components of mobx-persist, redux-persist, and mst-persist are very similar (with minor differences/features). I didn't want to introduce dependencies to either (though redux-persist is good at splitting up different parts from each other, would still have to install unnecessary things), but it would be good to have some "core" library that could be used by different persistence libs, handling common things like storage adaptors, persist gates, etc.

@nickbreaton
Copy link

@agilgur5 You should be good to go! 👍

@agilgur5
Copy link

Thanks @nickbreaton ! Just published v0.0.1!

@pinqy520 or @yordis think we can close this one out now. hope to collaborate more in the future on similar features :)

@yordis
Copy link
Author

yordis commented May 22, 2019

@agilgur5 Amazing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants