Skip to content

Add createReducer default handler#273

Open
rafael81 wants to merge 2 commits into
piotrwitek:masterfrom
rafael81:feature/default-reducer-handler
Open

Add createReducer default handler#273
rafael81 wants to merge 2 commits into
piotrwitek:masterfrom
rafael81:feature/default-reducer-handler

Conversation

@rafael81
Copy link
Copy Markdown

@rafael81 rafael81 commented May 12, 2026

Summary

  • add .defaultHandler() to the createReducer chain API for remaining unhandled actions
  • preserve the explicit handlers map while carrying default-handler behavior through chained reducers
  • skip Redux initialization actions by default, with an opt-in flag when initialization should use the default handler
  • add runtime, dts-jest, snapshot, and README coverage

Fixes #156

Validation

  • npm run ci-check

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:


Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/create-reducer.ts Outdated
...initialHandlers,
};

const initializationActionTypes = /^@@redux\/INIT/;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
const initializationActionTypes = /^@@redux\/INIT/;
const initializationActionTypes = /^@@redux\//;

@rafael81
Copy link
Copy Markdown
Author

Addressed the review by broadening the default exclusion from only @@redux/INIT to all @@redux/ internal actions, and added coverage for @@redux/PROBE_UNKNOWN_ACTION in both the default and opt-in paths.\n\nValidation: npm run ci-check passed locally.

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.

Add default handler in createReducer

1 participant