1

Can I listen to multiple actions, instead of just one?

Right now, to achieve that, I'm doing it in multiple epics, using combineEpics helper:

combineEpics(
  action$ => action$.ofType("SOME_TYPE_A").mapTo(newAction),
  action$ => action$.ofType("SOME_TYPE_B").mapTo(newAction)
);

However, I can use filter instead:

action$ =>
  action$
    .filter(({ type }) => type === "SOME_TYPE_A" || type === "SOME_TYPE_B")
    .mapTo(newAction);

But it's not scalable, when I need to listen for 5 actions, for example.

Is there exists more elegant way to listen multiple actions?

1ven
  • 6,776
  • 1
  • 25
  • 39

1 Answers1

4

ofType can take multiple keys, so you could use:

action$ => action$.ofType("SOME_TYPE_A", "SOME_TYPE_B").mapTo(newAction),
WayneC
  • 5,569
  • 2
  • 32
  • 43