Skip to content
This repository has been archived by the owner on Feb 3, 2020. It is now read-only.

Allow returning arbitrary data from the handleAction function #7

Merged
merged 4 commits into from
Feb 10, 2019

Conversation

cinnabarcaracal
Copy link
Contributor

Useful for completely replacing the state when it makes more sense than modifying the current state. Acts as a sort of escape hatch for when more traditional reducer logic, including the use of higher-order array functions, is desired.

e.g.

handleAction(actions.storeFooArray, (draft, { payload }) => {
  return payload;
}),
handleAction(actions.storeUpdatedFooInArray, (draft, { payload }) => {
  return [...draft.filter(f => f.x !== payload.x), payload]
}),

@cinnabarcaracal
Copy link
Contributor Author

cinnabarcaracal commented Feb 5, 2019

New PR updated for the new version. From my testing it is able to detect if you have also changed the draft, and will ignore any return value if that is the case. The return value undefined will be ignored (much like how immer ignores undefined return values)

I won't have time to add tests to this PR until later tonight, sorry.

src/handle-action.ts Show resolved Hide resolved
@codecov-io
Copy link

codecov-io commented Feb 5, 2019

Codecov Report

Merging #7 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master     #7   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           4      4           
  Lines          31     32    +1     
  Branches        5      4    -1     
=====================================
+ Hits           31     32    +1
Impacted Files Coverage Δ
src/handle-action.ts 100% <100%> (ø) ⬆️
src/create-action.ts 100% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8167bba...e0bd7c7. Read the comment docs.

Copy link
Owner

@knpwrs knpwrs left a comment

Choose a reason for hiding this comment

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

One more request -- could you add something to the README and maybe example.ts? Thanks!

@cinnabarcaracal
Copy link
Contributor Author

No problem, and happy to fix any issues with those

@knpwrs knpwrs merged commit ee82164 into knpwrs:master Feb 10, 2019
@knpwrs
Copy link
Owner

knpwrs commented Feb 10, 2019

Published as 3.1.0. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants