weixin_39618339
weixin_39618339
2020-12-09 05:14

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

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 ?

该提问来源于开源项目:cartant/ts-action

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

6条回答

  • weixin_39922147 weixin_39922147 5月前

    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. :smile:

    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.

    点赞 评论 复制链接分享
  • weixin_39922147 weixin_39922147 5月前

    Version 5.0.0 has been published. Instead of:

    ts
    union(Foo, Bar);
    

    You should now use:

    ts
    union({ Foo, Bar });
    
    点赞 评论 复制链接分享
  • weixin_39922147 weixin_39922147 5月前

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

    点赞 评论 复制链接分享
  • weixin_39618339 weixin_39618339 5月前

    Cool, I will test it now... thanks

    点赞 评论 复制链接分享
  • weixin_39622178 weixin_39622178 5月前

    Hi - 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

    点赞 评论 复制链接分享
  • weixin_39922147 weixin_39922147 5月前

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

    ts
    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.

    点赞 评论 复制链接分享

相关推荐