pinqy520 / mobx-persist

persist mobx stores
MIT License
560 stars 62 forks source link

Does not work 1 #53

Open dsame opened 6 years ago

dsame commented 6 years ago

`import { observable, action } from 'mobx'; import { create, persist } from 'mobx-persist';

const DEFAULT_ZOOM = 5; class Map { @persist @observable zoom = DEFAULT_ZOOM; }

class UI { @observable hydrated = false; @observable map = new Map(); }

const ui = new UI();

const hydrate = create({});

export default ui; hydrate('map2ui', ui) `

causes mobx.module.js?daf9:3516 [mobx] Encountered an uncaught exception that was thrown by a reaction or observer component, in: 'Reaction[Reaction@1] Error: [serializr] Failed to find default schema for undefined at invariant (serializr.js?967d:44) at Object.serialize (serializr.js?967d:363) at mobx_1.reaction.delay (index.js?b78b:47) at eval (mobx.module.js?daf9:600) at trackDerivedFunction (mobx.module.js?daf9:3287) at Reaction.track (mobx.module.js?daf9:3491) at reactionRunner (mobx.module.js?daf9:599) at Reaction.eval [as onInvalidate] (mobx.module.js?daf9:587) at Reaction.runReaction (mobx.module.js?daf9:3463) at runReactionsHelper (mobx.module.js?daf9:3589)

dsame commented 6 years ago

The problems seems to appear if there's no at least one persisted field in the object. But i really do not want to persist any of child stories. I want to persist storie's properties (some of them)

designbyadrian commented 6 years ago

I spent hours trying to figure this out. @dsame 's reply helped. I'm now adding one as soon as my store is constructed, but this is only sometimes a viable solution.

shrugs commented 5 years ago

I'd expect that you can also only hydrate that one child store hydrate("map", ui.map) without a problem.

marcelxsilva commented 3 years ago

This error occurs when, for example, a store called user does not have persist inside it, but in the store's index it hashydrate('user', stores.user).

Just remove hydrate('user', stores.user) and the problem will be solved.

it worked for me.