Skip to content

handleAction always triggers if not FSA #185

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

Closed
inxilpro opened this issue Jan 26, 2017 · 3 comments
Closed

handleAction always triggers if not FSA #185

inxilpro opened this issue Jan 26, 2017 · 3 comments

Comments

@inxilpro
Copy link

The code revert referenced in #177 results in handleAction always running the reducer if an action with no type is dispatched:

if (type && !includes(actionTypes, type.toString())) {
  return state;
}

return (action.error === true ? throwReducer : nextReducer)(state, action);

It seems to me that it should be:

if (!type || !includes(actionTypes, type.toString())) {
  return state;
}

return (action.error === true ? throwReducer : nextReducer)(state, action);

…so that the reducer simply returns the existing state if no type is provided in an action.

@inxilpro
Copy link
Author

For anyone out there who's running into the same issue, a temporary fix is:

const actionReducer = handleActions(/* ... */);
const reducer = (state = initialState, action) => {
	if (!action.type) {
		return state;
	}
	
	return actionReducer(state, action);
}

@ronaldheft
Copy link

Agreed on ignoring actions without a type.

I test all my reducers' default state by passing an empty action, and I've had to go through my tests and change them to use an invalid/unknown action instead.

@yangmillstheory
Copy link
Contributor

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

No branches or pull requests

3 participants