knpwrs / redux-ts-utils

Everything you need to create type-safe applications with Redux!
MIT License
55 stars 4 forks source link

Allow returning arbitrary data from the handleAction function #6

Closed cinnabarcaracal closed 5 years ago

cinnabarcaracal commented 5 years ago

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]
}),
knpwrs commented 5 years ago

I just upgraded to immer@2.0.0 which changes the implementation a little bit. I'd be happy to take a new PR which takes that into account! Feel free to open a new PR or reopen this one when ready.