pinqy520 / mobx-persist

persist mobx stores
MIT License
560 stars 62 forks source link

Hard to understand readme example #48

Closed schumannd closed 6 years ago

schumannd commented 6 years ago

I am always in favor of examples. But I wish there was some better naming. E.g.

What does 'some' in

hydrate('some', someStore)

mean or do? In the documentation it is referred to as The key of your datastore. But where is this key initially set?

I thought I understood this package until stuff started breaking and I'm starting over again. If someone explains the usage of @persist and hydrate() I'll rewrite the readme to be more understandable.

Edit:

If I understand correctly, the example is broken and hydrate('some', someStore) does not hydrate anything as there is no datastore key with that name. I will open a PR that fixes this

bram-l commented 6 years ago

I'm confused. Looking at the example code it seems more like The key of your datastore is actually an arbitrary name that is used to store all the persisted properties of the given store, not just the one that matches the specified key.

rgehan commented 6 years ago

I think your correction is incorrect. I've been trying to setup persistence on my store by following the doc and had duplicates.

It seems like hydrate('s', myStore) persists the whole store at the localStorage key s, not only the s observable.

If you look at the examples, it is used that way: hydrate('appState', AppState), with 'appState' being an arbitrary key that is not the name of an observable, and AppState being the instantiated store object.

@pinqy520 If I'm not mistaken, this should be reverted.

pinqy520 commented 6 years ago

@rgehan You are right, I have fixed the README...