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

Reducers: add default handler #241

Closed
wants to merge 6 commits into from
Closed

Conversation

bunysae
Copy link

@bunysae bunysae commented Oct 21, 2020

Description

Adds a defaultHandler for reducers

Related issues:

Checklist

  • I have read CONTRIBUTING.md
  • I have linked all related issues above
  • I have rebased my branch

For bugfixes:

  • I have added at least one unit test to confirm the bug have been fixed
  • I have checked and updated TOC and API Docs when necessary

For new features:

  • I have added entry in TOC and API Docs
  • I have added a short example in API Docs to demonstrate new usage
  • I have added type unit tests with dts-jest
  • I have added runtime unit tests with dts-jest

IssueHunt Summary

Referenced issues

This pull request has been submitted to:


@jalopez
Copy link

jalopez commented Nov 26, 2020

Hi, do you have any news on this? I need this desperately. @piotrwitek could you please merge this?

@wi-ski
Copy link

wi-ski commented Jan 12, 2021

lol - i need this too!

@@ -7,10 +7,12 @@ import { getType } from './get-type';
const add = createAction('ADD')<number>();
const increment = createAction('INCREMENT')();
const decrement = createAction('DECREMENT')();
const reduxInit = createAction('@@redux/INIT.1')();
Copy link
Owner

@piotrwitek piotrwitek Jan 12, 2022

Choose a reason for hiding this comment

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

reduxInit cannot be handled as it is implementation details of Redux not a public API, so please remove completely

```ts
const counterReducer = createReducer(0)
.handleAction(add, (state, action) => state + action.payload)
.defaultHandler((state, action) => state = 0, true);
Copy link
Owner

Choose a reason for hiding this comment

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

because reduxInit cannot be handled as it is implementation details of Redux and not a public API, second parameter is not necessary, it should be always invoked by initialization and should be handled in the user code as needed

@jin60641
Copy link

@piotrwitek
Hi.
I have opened a new PR with the comments addressed, please review. Thanks
#264

@piotrwitek
Copy link
Owner

closed because it's stale

@piotrwitek piotrwitek closed this Jan 6, 2024
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
5 participants