Add createReducer default handler#273
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a defaultHandler method to the createReducer API, allowing for a fallback reducer when no specific action handlers match. The implementation includes support for opting into Redux initialization actions, updated type definitions, and comprehensive unit tests. Feedback was provided to broaden the internal Redux action exclusion regex to ensure all internal lifecycle actions, such as probes, are handled correctly by default.
| ...initialHandlers, | ||
| }; | ||
|
|
||
| const initializationActionTypes = /^@@redux\/INIT/; |
There was a problem hiding this comment.
The regex currently only matches Redux initialization actions starting with @@redux/INIT. However, Redux also dispatches other internal actions like @@redux/PROBE_UNKNOWN_ACTION during store creation to verify reducer behavior. It is generally safer to exclude all actions starting with @@redux/ from the default handler to avoid unexpected behavior during Redux's internal lifecycle.
| const initializationActionTypes = /^@@redux\/INIT/; | |
| const initializationActionTypes = /^@@redux\//; |
|
Addressed the review by broadening the default exclusion from only |
Summary
.defaultHandler()to thecreateReducerchain API for remaining unhandled actionshandlersmap while carrying default-handler behavior through chained reducersFixes #156
Validation
Notes
This revives the closed default-handler feature request with a fresh implementation against current
master. The prior PR #241 is closed; I kept this PR focused on the API proposed in the issue and added tests for runtime behavior plus remaining-action typing.Transparency
I used AI assistance to inspect the old discussion and closed PR, draft the implementation and tests, and review the final diff. I manually ran the validation command before submitting.
Funded issue
IssueHunt Summary
Referenced issues
This pull request has been submitted to: