-
Notifications
You must be signed in to change notification settings - Fork 300
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
Pass shorthand arguments to reducers #227
base: master
Are you sure you want to change the base?
Pass shorthand arguments to reducers #227
Conversation
Great idea 👍, always a fan of reducing (no pun intended) boilerplate. To clarify, should the handleActions({
SHORT_HAND_ARGS: (state, action, payload, meta, error ) => {
return { ...state, data:payload.data, user: meta.user }
},
SHORT_HAND_DESTRUCTURING: (state, _, { data }, { user }, error) => {
return { ...state, filters, data, user }
},
}) Also, I wish there were a way to not have the unused argument. Can we introspect using |
1. `action`: The redux action | ||
|
||
and as a shorthand, for easier desctructuring: | ||
3. `payload`: The fsa payload of the action, *action.payload* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/fsa/FSA
, please
@@ -29,13 +29,24 @@ import { handleAction } from 'redux-actions'; | |||
|
|||
If a `reducer` function is passed, it is used to handle both normal actions and failed actions. (A failed action is analogous to a rejected promise.) You can use this form if you know a certain type of action will never fail, like the increment example above. | |||
|
|||
The reducer function gets recieves the following arguments |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/recieves/receives
, and we can remove "gets" entirely.
|
||
1. `state`: The current redux state | ||
|
||
1. `action`: The redux action |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Numbering here is incorrect, should be 2
. Also I would say
the Flux Standard Action
instead of
the redux action
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PS markdown suggests using 1. multiple times
- A
- B
- C
1. A
1. B
1. C
as it will auto increment numbers for you, and makes adding a step before/after later on not so tedious reordering all of the numbers
|
||
1. `action`: The redux action | ||
|
||
and as a shorthand, for easier desctructuring: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spelling: "destructuring"
@@ -28,6 +28,12 @@ export default function handleAction(type, reducer = identity, defaultState) { | |||
return state; | |||
} | |||
|
|||
return (action.error === true ? throwReducer : nextReducer)(state, action); | |||
return (action.error === true ? throwReducer : nextReducer)( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we destructure here:
const { payload, meta, error } = action
const hasError = error === true
return (hasError ? throwReducer : nextReducer)(state, action, payload, meta, hasError)
11485ca
to
4bd68b1
Compare
Right now, in order to access the fsa properties you either have to use the the action argument directly or use destructuring:
I'm proposing a third backward compatible form, that simplifies destructuring for the most common cases and I think looks pleasing and simpler, and makes it obvious those should
be the only properties of an fsa action