edy / redux-persist-transform-filter

Filter transformator for redux-persist
MIT License
191 stars 21 forks source link

Can't blacklist a subset #21

Open martakielpinska opened 6 years ago

martakielpinska commented 6 years ago

Hello, I'm running into troubles trying to blacklist a part of my reducer. here is my entriesReducer's initial state:


const initialState = {
    serverCopy : [],
    entriesPerDay : [], 
    pickedDate : new Date(),
    total: "0:00",
    workingCopy : [],
    activities: [],
    pickedEntry: null,
    loggedInUser: null,
    newnewPickedDate : null,
}

I want the entriesPerDay, the pickedDate and the pickedEntry to have their default values when the app starts. That's the most important thing. If possible, I'd like to rehydrate ONLY the serverCopy and the workingCopy. Here is the code of my store configurations:


const saveSubsetFilter = createFilter(
    'entriesReducer',
    ['serverCopy', 'workingCopy']
  );

    const loadSubsetFilter = createFilter(
        'entriesReducer',
    null,
    ['serverCopy', 'workingCopy']
  );

   const saveSubsetBlacklistFilter = createBlacklistFilter(
    'entriesReducer',
    [ 'pickedEntry' , 'entriesPerDay', 'pickedDate']
  );

const persistConfig = {
    key: 'root',
    storage: storage,
    stateReconciler: autoMergeLevel2  ,// see "Merge Process" section for details.
    transforms: [

        saveSubsetFilter,
      loadSubsetFilter,
      saveSubsetBlacklistFilter

    ]
   };

When I reload the app everything in the entriesReducer gets rehydrated. Why would that happen? help

devpascoe commented 5 years ago

I had a similar issue just now. using the actual reducer object rather than a string seemed to do the trick. try passing entriesReducer instead of 'entriesReducer'

const saveSubsetBlacklistFilter = createBlacklistFilter( entriesReducer, [ 'pickedEntry' , 'entriesPerDay', 'pickedDate'] );

I also found that i needed to restart the app on iOS, a simple cmd+R reload didnt work.

... update....scratch that. getting inconsistent results.

another update. I'm having better luck just sticking to whitelists with createFilter and forgetting about blacklists. And gone back to using the string for the reducer rather than the object itself. Working well.

ThomasStubbe commented 5 years ago

Did you manage to solve this with blacklists? I'm having the same issue. The createBlacklistFilter simply doesn't work. The README.md also says to use persistStore to pass the filter, but that's an invalid property. I suppose it should be in the persistCombineReducers's config... ?