polemius / recoil-persist

Package for recoil state manager to persist and rehydrate store
https://polemius.dev/recoil-persist/
MIT License
350 stars 39 forks source link

Reseting atom causes key to be empty instead of default value #26

Open toddmcbrearty opened 3 years ago

toddmcbrearty commented 3 years ago

When you reset the atom it becomes an empty state saved in storage. According to the docs https://recoiljs.org/docs/guides/atom-effects/#asynchronous-storage-persistence the key should be removed when it's a default value (at least for now)

the fix is to simply add this to onSet

if (newValue instanceof DefaultValue) {
      if(state.hasOwnProperty(node.key)) delete state[node.key];
} else {
     state[node.key] = newValue
}
polemius commented 3 years ago

I have released a new 2.3.0 version with your fix.

ramiel commented 3 years ago

This is still not working in version 2.4.0

polemius commented 3 years ago

The new version 2.5.0 with fix just released.