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

Recursively Prune State on store.replaceReducer #2672

Closed
wants to merge 2 commits into from

Conversation

quinnnned
Copy link
Contributor

Resolves #1636 -- Prevents combineReducers from warning about unexpected keys after calling replaceReducer.

Adds recursive pruneState function to createStore, which uses the differences between the current and next state shapes to determine which state branches have been removed (are not acknowledged by the next reducer). The removed state branches are then removed from the current state.

The state shape is defined here as the union of every path which begins at the state tree root and terminates at a non-plain-object leaf (boolean, number, string, array, etc).

Properties of a plain object which do not appear in the current or next shape are not pruned. This covers the use case where a plain object is being used as a dynamic collection of key-value pairs.

If any plain object is unchanged by the pruning process, the original object is returned instead of a new one.

The state shape for a given reducer is determined by invoking it with an undefined state and the INIT action.

The combineReducers warning does not appear in production, so this pruning process also does not take place in production.

Added unit test which fails (generates warning) when the pruning process does not take place.

@timdorr
Copy link
Member

timdorr commented Oct 22, 2017

I appreciate the PR, but I think #2673 is the way to go here. If I'm convinced otherwise, we can reopen this.

@timdorr timdorr closed this Oct 22, 2017
@quinnnned
Copy link
Contributor Author

Okay. I was looking for a way to supress the error without having to change redux's production behavior.

@timdorr
Copy link
Member

timdorr commented Oct 22, 2017

I think we can do that in 4.0, which would seem to be a better solution. It certainly opens up a few other special case handlers as well (particularly for HMR cases).

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.

None yet

2 participants