-
Notifications
You must be signed in to change notification settings - Fork 120
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
Rehydrate should do a deep merge only on existing keys #115
Comments
@JohnKis Do you perhaps have your config (LocalStorageConfig) at hand? |
@moniuch Sure, please find it below. export function localStorageSyncReducer(reducer: ActionReducer<any>): ActionReducer<any> {
return localStorageSync({
keys: ['key1', 'key2', 'key3'],
rehydrate: true,
restoreDates: true
})(reducer);
} |
This case is a bit disputable to me. IMO, with this config, we should not expect that While rehydrating, we are only told that we should pick and apply "key1": {
"nestedKey1": "value",
"nestedKey2": "another value",
}, doesn't mean that key1: {
nestedKey1: any;
nestedKey2: any;
nestedKey3?: any;
}, What would make keys: [{'key1': ['nestedKey1', 'nestedKey2']}], which explicitly says that Not sure though, this mixed config for keys is supported: keys: [{'key1': ['nestedKey1', 'nestedKey2']}, 'key2', 'key3'], ) So maybe we should support wildcards, as in keys: [{'key1': ['nestedKey1', 'nestedKey2']}, {'key2': '*'}, {'key3': '*'}], to enable this sort of cherry-pick on some, and en gross selection on other keys. What are your thoughts? @btroncone @bufke |
@moniuch You're right, however this behaviour restores keys that you've removed from your state intentionally. I guess there are cases where it'd be valid not to remove non-existent keys (e.g.: where the initial state does not contain the full structure) so maybe it could be an option instead of the default behaviour. |
What I wanted to say is that there is no way AFAICT to tell, while rehydrating the state from local storage, which keys may are missing by intention and which by not being populated yet. To my understanding, the only way of conveying the intention is |
We could now also look into #100 which introduces an option to provide a custom merging function with the config. |
On 6.0.0 the rehydrated state is incomplete when the store schema changes. There is a PR to fix this (#114) however there is a scenario it doesn't cater for, and it was suggested that this scenario should be documented in a new issue.
Scenario
If a key has been removed from the store's
initialState
but still included in the saved state in local storage, the rehydrated state will include the deleted key. This is not ideal as it makes it impossible to remove keys from your store schema. This also applies to nested keys.Example
Store initial state
Saved state in local storage
Expected rehydrated state
Actual rehydrated state (on #114)
If this issue is fixed, it would also be ideal to remove to redundant keys from local storage as well. However this might be complicated especially on nested keys.
The text was updated successfully, but these errors were encountered: