cartant/ts-action

what is the best approach to union actions when we have more than the limited number?

cvgaviao opened this issue ยท 6 comments

The function union() supports a limited number (11) of actions to be passed as its parameters.

what would be the best approach in case my action class do have more than eleven actions ?

I guess the best approach is the one that you've taken: raise an issue and ask a question about the part of this library that I'm least happy with and prompt me to improve it. ๐Ÿ˜„

Well, I've had a think about it and I have a much better way of doing it. And there won't be an arbitrary maximum number of actions. I'll publish a new version of the package later today.

Version 5.0.0 has been published. Instead of:

union(Foo, Bar);

You should now use:

union({ Foo, Bar });

Actually, it's now version 6.0.0, as I've made similar changes to isType and ofType, too.

Cool, I will test it now...
thanks

Hi @cartant - recently discovered this library and totally loved it.

The usecase I'm trying to do is export an object of actions, or do an import * as actions from './actions' - and pass it onto union so it need not be updated each time along with actions before passing into reducer.

I see latest version of ts-action (11.0.0) doesn't accept passing an object into union. Is there any other approach to accomplish above usecase?

This is the error

Argument of type '{ increment: ((payload: IPayload) => { payload: IPayload; } & { type: "INCREMENT"; }) & { type: "INCREMENT"; }; decrement: ((payload: IPayload) => { payload: IPayload; } & { ...; }) & { ...; }; }' is not assignable to parameter of type 'Creator & { type: string; }'.
  Object literal may only specify known properties, and 'increment' does not exist in type 'Creator & { type: string; }'.ts(2345)

I have a codesandbox with this issue: https://codesandbox.io/s/typescript-redux-i8lwk?file=/src/reducer.ts

@aarjithn union takes an arbitrary number of arguments. There is no limit:

const both = union(increment, decrement);

It no longer takes an object: https://github.com/cartant/ts-action/blob/master/packages/ts-action/CHANGELOG.md#900-2019-04-06

FWIW, it's generally preferred - everywhere, AFAICT - to open new issues for problems or questions, instead of commenting on closed issues.