Skip to content
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

Partial initial state and usage help / docs #17

Open
damianobarbati opened this issue Feb 2, 2018 · 3 comments
Open

Partial initial state and usage help / docs #17

damianobarbati opened this issue Feb 2, 2018 · 3 comments

Comments

@damianobarbati
Copy link

damianobarbati commented Feb 2, 2018

@edy thanks for this repo!
It seems the rehydration is not properly dealing with defaults when using transforms.

Here my default state:

const defaultState = {
    computing: [],
    notification: null,
    token: null,
    data: {},
};

Here the persist transforms applied (I want only main.token to be persisted):

import { createFilter, createWhitelistFilter, createBlacklistFilter } from 'redux-persist-transform-filter';

const loadFilter = createWhitelistFilter('main', ['token']);

const persistConfig = {
    key: 'user',
    keyPrefix: 'user/',
    transforms: [loadFilter]
};

What happens after rehydrate dispatch is the following:

{
  main: {
    token: 'blabla'
  },
  _persist: {
    version: -1,
    rehydrated: true
  }
}

Since data:{} default is not applied but totally removed because ignored in the transform I get errors.

How can I deal with this situation? Persist just wanted keys and apply defaults to the others?
Would it be possible to always rehydrate to the default and then apply the rehydration of wanted subkeys?

@erandagan
Copy link

erandagan commented Jun 25, 2018

@edy Any hints on this? This prevents from using nested keys (a.b.c) as the loaded state isn't properly merged to the existing state, rather replaces it completely.

Edit
This problem is actually caused by redux-persist only supporting (out of the box) 2 levels of auto merging. Implementing a deep merge state reconciler might be the way to go.

Related rt2zz/redux-persist#491

@gabceb
Copy link

gabceb commented Sep 25, 2018

I was just looking into this for a new React Native app and after some debugging it looks like using the autoMergeLevel2 state reconciler fixes this issue for me. When using the autoMergeLevel1 state reconciler the whole reducer gets replaced as noted here https://github.com/rt2zz/redux-persist/blob/208c6b112ead87b3701dfacaae2cdbe78377775a/src/stateReconciler/autoMergeLevel1.js#L33 which causes it to blow the initial state up. autoMergeLevel2 merges it instead of only using the persisted state

@jasan-s
Copy link

jasan-s commented May 27, 2019

#24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants