Feature request: ability to pass dynamic number of arguments into union
aarjithn opened this issue · 3 comments
Hi @cartant,
Opening a new issue as you said as the question here is not regarding limited number of arguments.
Currently, union accepts a list of arguments as actions. If we have a case where all the actions are held in an object (say via import *, the action names need to be duplicated before passing onto union.
// actions.ts
export const action1 = action('ACTION1'..),
export const action2 = action('ACTION2'..),
//reducers.ts
import * as actions from './actions'
const all = union(actions.action1, actions.action2...)
However, if we add/remove actions, this argument list needs to be updated too which is not very DRY.
Now, i tried const all = union.apply(null, Object.values(actions));
, but that doesn't work and all
is getting type any
.
if you think this is a valid usecase and could be handled easily, request you to add support for the same, else this issue can be closed.
Thank you for your work on the library.
You should be able to convert the object to an array and then spread it into the union
call, like this union(...array)
. Have a look at this example:
I'll consider adding a helper - or an overload - to the package to do this, but you should be able to do this yourself, in the interim.
I don't think I'll add anything for this use case. I don't think it's necessary, as Object.values
should do what you need:
const all = union(...Object.values(actions))
yes it works. Thanks a lot!