-
-
Notifications
You must be signed in to change notification settings - Fork 97
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
Reducers: add default handler (without init action handling) #264
base: master
Are you sure you want to change the base?
Conversation
@piotrwitek |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, looks good although I have few comments. Best!
src/create-reducer.ts
Outdated
@@ -92,6 +129,8 @@ export function createReducer<TState, TRootAction extends Action = RootAction>( | |||
); | |||
} | |||
return reducer(state, action); | |||
} else if (defaultReducer && !initializationActionTypes.test(action.type)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!initializationActionTypes.test(action.type)
is not needed user code in default handler should handle the @@redux/init action if needed by just returning the unchanged state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done 9c38e11
But if the defaultHandler's return value is different from initialState, it may not work as intended by some users who are not aware of the existence of redux INIT (due to the redux INIT action triggering the defaultHandler. initialState will change to defaultHandler's return value). This might be confusing for them. What do you think about this issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a trade-off. The default use case is to clear the state and that's that we are aming for to solve as main case. If someone want to use it for some other rare edge case, adding that extra condition check is not a big deal. We just need to put that info in the docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jin60641 could you please add it to the readme?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done 33f9db8
Description
Adds a defaultHandler for reducers
apply #241 's comments
Related issues:
Checklist
For bugfixes:
For new features:
dts-jest
dts-jest