identity function in createAction only handles the first parameter
See original GitHub issueThe createAction
function returns an action creator with the signature function(...args)
. However, if you do not pass an actionCreator
method to the createAction
function, then the “identity
” function is used.
The identity
function is this: (t) => t
, which does not do an argument spread and, since it is called with function.apply, it only handles the first argument passed in to the action creator, even though the action creator is designed around supporting n arguments.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:2
- Comments:11 (1 by maintainers)
Top Results From Across the Web
handleAction(s) - redux-actions
Wraps a reducer so that it only handles Flux Standard Actions of a certain type. ... argument ( reducer ) is undefined ,...
Read more >Create Multiple Redux Actions with an Action Map in redux ...
In this lesson, we'll use the plural createActions function and an action map to create multiple action creators with a single utility from...
Read more >Identity function tutorial in SQL Server
Let's insert a few records in this table and view the records. You can see the first employee gets an ID value 100...
Read more >How to work with Roles in ASP.NET Core Identity - YogiHosting
NET Core Identity Role based Authentication; Download Source Codes ... The Create Action takes the Role name as a string in it's parameter ......
Read more >NgRx: Action Creators redesigned - Medium
Good Action Hygiene helps a lot, but only if the application is already running and it ... The new function takes the initialState...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I personally do
(arg1, arg2) => ({ arg1, arg2 })
if i have arguments to pass. Even if it were a single argument, I’d still do(arg1) => ({ arg1 })
just to keep it consistent and make it more readable in the reducers, especially in larger apps.e.g.
Since I pass my own payloadCreator all the time, I don’t encounter the problem as discussed here.
Also, since JavaScript does not have support for named parameters like in some other languages e.g. python where you can specify
functionName(arg1=1, arg2=2)
, you can pass an object literal as your only argument.this then will work with
redux-actions
with the default identityI don’t really agree with passing multiple arguments as an array as payload, since you’d have to again assume the order of the arguments passed which makes code less readable and less flexible.
But, not passing all arguments is bad as well as it restricts by default, so I’d say the solution mentioned by @yangmillstheory above is sufficient.
Yeah, I’m wondering what the maintainers or the upvoters think. ping @timche @hale @calvinnwq.
I didn’t mean to shoot your point down; after discussion what you propose seems reasonable! I do think that in the case multiple arguments, someone might be passing a custom action creator. But this would handle the case of having to pass
👍