ngrx-store-localstorage icon indicating copy to clipboard operation
ngrx-store-localstorage copied to clipboard

How to save only part of deeply nested state

Open gssjr opened this issue 6 years ago • 9 comments

How do I save only the grandchild state in config? {keys: [{parent: {child: ['grandchild']}}]} doesn't seem to work

{
  parent: {
    child: {
      grandchild: { ... }
    }
}

gssjr avatar May 25 '18 16:05 gssjr

Same question for me.

cdupetit avatar Jun 06 '18 12:06 cdupetit

{keys: [{parent: [{child: ['grandchild', 'grandchild2'], 'parentProperty']}]}

Need that extra [ array after parent I think

x3igh7 avatar Jun 11 '18 17:06 x3igh7

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 avatar Jun 20 '18 15:06 dstj

@dstj that is working for me

maxkuzmin avatar Jun 22 '18 10:06 maxkuzmin

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 avatar Sep 07 '18 07:09 EugenAz

@EugenAz I have exactly the same, it doesn't work for me..

larscom avatar Mar 08 '19 11:03 larscom

Any solutions? First of all I really like this plugin, it's helps me a lot.

kép 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

BDominik avatar Jun 21 '19 12:06 BDominik

okay I found the solution, for nested childs I'm using like this keys: ['app.is_logined', 'app.user', 'app.settings'],

BDominik avatar Jun 21 '19 13:06 BDominik

Looks related to #144. Might need some more investigation if this feature is requested by a lot of people...

BBlackwo avatar Apr 24 '20 01:04 BBlackwo