bigpotato
bigpotato

Reputation: 27507

Redux Observable: Fire same epic for multiple actions

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?

Upvotes: 3

Views: 455

Answers (2)

jayphelps
jayphelps

Reputation: 15401

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.

Upvotes: 6

bigpotato
bigpotato

Reputation: 27507

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

Upvotes: 0

Related Questions