ngrx-store-localstorage
ngrx-store-localstorage copied to clipboard
How to save only part of deeply nested state
How do I save only the grandchild state in config? {keys: [{parent: {child: ['grandchild']}}]}
doesn't seem to work
{
parent: {
child: {
grandchild: { ... }
}
}
Same question for me.
{keys: [{parent: [{child: ['grandchild', 'grandchild2'], 'parentProperty']}]}
Need that extra [
array after parent I think
Can someone confirm that @x3igh7's solution works? I've haven't been able to get it to work even after fixing the typo (it's missing a closing bracket for child
).
@dstj that is working for me
Doesn't work for me.
My store looks like this:
{
parent: {
child: {
grandchild: 'string'
}
}
}
and configuration:
export const localStorageSyncReducer = (reducer: ActionReducer<any>): ActionReducer<any> =>
localStorageSync({
keys: [
{
parent: [
{ child: [ 'grandchild' ] }
]
}
],
rehydrate: true,
storageKeySerializer: (key: string) => `store-cache.${key}`,
})(reducer);
As a result in localStorage i see the key store-cache.parent
and its value is "{}"
What do i do wrong?
@EugenAz I have exactly the same, it doesn't work for me..
Any solutions? First of all I really like this plugin, it's helps me a lot.
My state looks like this.
And I only want to store the is_logined, the settings, and the user.
keys: [{ app: ['is_logined', 'user', 'settings'] }],
If I use it like this I got this error
ERROR TypeError: path.split is not a function
okay I found the solution, for nested childs I'm using like this keys: ['app.is_logined', 'app.user', 'app.settings'],
Looks related to #144. Might need some more investigation if this feature is requested by a lot of people...