Skip to content

Do not warn if replaceReducer causes reducer shape to change #2651

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

Conversation

Kaivosukeltaja
Copy link

Attempts to solve issue #1636.
replaceReducer calls the new reducer with empty objects as parameter to get the desired state shape, then filters out the keys in the current state that don't exist in the new one.
Added new test to verify functionality.
My first PR to Redux, please be gentle :)

@quinnnned
Copy link
Contributor

I don't believe this will work for unusually deep or unusually shallow state trees.

  1. Deep: This will only fix the warning for a top-layer combineReducers. A deeper state tree with multiple layers of combineReducers would still produce the warning.

  2. Shallow: Consider the following reducer:

export default (state = {}, action) => {
    switch (action.type) {
        case "ADD_KEY_VALUE_PAIR":
            return {
                ...state,
                [action.key]: action.value
            }
        default:
            return state
    }
}

This state tree is a simple collection of key-value pairs. The proposed solution would wipe the state back to an empty object

@timdorr
Copy link
Member

timdorr commented Oct 22, 2017

I appreciate the PR, but I think #2673 is the way to go here. Thanks anyways!

@timdorr timdorr closed this Oct 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants