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

Deal with nested combineReducers #4

Open
EQuimper opened this issue Jan 2, 2017 · 7 comments
Open

Deal with nested combineReducers #4

EQuimper opened this issue Jan 2, 2017 · 7 comments

Comments

@EQuimper
Copy link

EQuimper commented Jan 2, 2017

How can I deal with nestedReducer if I have something like

{
	api: {
		...apiReducer
	},
	ui: {
		gamesLiked,
		channelsLiked,
		navBar
	}
}

But I want to deal only with ui.gamesLiked and ui.channelsLiked

@alvarolorentedev
Copy link

alvarolorentedev commented Jan 21, 2017

+1 for this one, any idea or solution?

@edy
Copy link
Owner

edy commented Jan 21, 2017

@EQuimper is this how your store looks like? then the save filter should look like this:

const saveSubsetFilter = createFilter(
  'ui',
  ['gamesLiked', 'channelsLiked']
);

otherwise if its only a subset from the store, then you could try this instead:

const saveSubsetFilter = createFilter(
  'yourReducer',
  ['ui.gamesLiked', 'ui.channelsLiked']
);

see https://github.com/edy/redux-persist-transform-filter/blob/master/spec.js#L43-L50

@yantakus
Copy link

yantakus commented Mar 23, 2017

@edy Here is my store:

{
  route: {
    locationBeforeTransitions: null
  },
  language: {
    locale: 'en'
  },
  home: {
    introductionVisible: false
  }
}

The following code works fine:

const persistReducer = createFilter(
    null,
    ['home.introductionVisible']
);

And this one doesn't:

const persistReducer = createFilter(
    'home',
    ['introductionVisible']
);

According to your previous message, both should work. Any ideas?

@yantakus
Copy link

Hm, this snippet:

const persistReducer = createFilter(
    null,
    ['home.introductionVisible']
);

Doesn't seem to work either. It persists the whole home reducer, not just home.introductionvisible as expected.

May this be caused by the fact I'm using redux-persist-immutable, not just redux-persist?

@alvarolorentedev
Copy link

alvarolorentedev commented Apr 6, 2017

@yantakus i had similar issue and like as you say this is an issue regarding immutable that is not supported by this component, so i ended up doing my own filter:

let whitelistMyTopLevelReducerTransform = createTransform(
  (inboundState, key) => {
      if (key !== 'myTopLevelReducer') 
        return inboundState
      else 
        return { persistProperty: inboundState.persistProperty }
  }
)

also take in count you need to resolve your immutables

import {persistStore, autoRehydrate, createTransform} from 'redux-persist'
import immutableTransform from 'redux-persist-transform-immutable'

persistStore(store, {storage: AsyncStorage, transforms: [whitelistMyTopLevelReducerTransform, immutableTransform()]})

if one day there is a solution for nested reducers with inmmutables i will come back to this component :)

@elado
Copy link

elado commented May 1, 2017

Here's my solution for this: rt2zz/redux-persist#330 (comment)

@actra-gschuster
Copy link

@yantakus @kanekotic https://github.com/actra-development/redux-persist-transform-filter-immutable ;-)
I was facing the same issue and added a pull request #5 that was closed (for a good reason, btw) so I kind-of forked it.

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

6 participants