Redux Observable: Fire same epic for multiple actions

人走茶凉 提交于 2019-12-23 20:35:25

问题


I want to fire the same contents of my epic in response to several actions. Something like this:

export default function uploadImage(action$, store) {
  return action$.ofType([
      'UPDATE_IMAGE,
      'UPDATE_INTERESTS',
      'UPDATE_LANGUAGE',
      ...
    ])
    .switchMap(action => {
      Api.updateUser();
    })
};

Is this possible?


回答1:


You're correct in your self-answer, ofType accepts an arbitrary number of types as arguments.

This isn't currently documented because in practice we've found almost always it's a sign of an anti-pattern--not always, but it's highly suspicious.

Until we have solid guidance on when it's good or bad, we want to continue to discourage it's use as a general rule, but certainly only you can be the judge of whether it's appropriate or not.




回答2:


From the looks of the docs it seems to take an variable amount of arguments: https://github.com/redux-observable/redux-observable/blob/fd393a1adf359381c98ca494bc5dc2cac80f6d07/src/ActionsObservable.js#L26



来源:https://stackoverflow.com/questions/43540419/redux-observable-fire-same-epic-for-multiple-actions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!