keajs / kea-localstorage

Persist the state of your reducers in localstorage
https://kea.js.org/plugins/localstorage
MIT License
9 stars 3 forks source link

How to access the original logic.defaults? #14

Closed kairyu closed 4 years ago

kairyu commented 4 years ago

Thank you for the great plugin again!

Recently I have a use case which needs to access the original logic.defaults while kea-localstorage plugin is enabled.

From my understanding, kea-localstorage will override the original defaults with the values in localStorage when the values has option { permit: true }. Is there any way to access the original defaults in this case?

If there is no existing way to access it, could you please consider to add a new feature such as changing the mechanism to avoid overriding the defaults or copying the original defaults to another property e.g. originalDetaults before this plugin override them?

Thank you in advance.

mariusandra commented 4 years ago

Hey! Sure, it's out now in 1.0.2. You can use logic.cache.localStorageDefaults['reducerKey'] to get the original default for reducerKey

kairyu commented 4 years ago

I'm sorry for not getting back to this issue sooner. You are amazing! I really appreciate for you prompt improvement!

mariusandra commented 4 years ago

No problem :).

One more thing though, you might be interested in the new babel-plugin-kea, which automatically adds paths to logic that doesn't have any manually defined. It might save some typing.

kairyu commented 4 years ago

Oh that's good to know. Really cool stuff! Let me try it.