Hongbo Miao
Hongbo Miao

Reputation: 49924

How to use Observable.if correctly in redux-observable?

I am trying to use Observable.if in redux-observable to determine which action to dispatch.

In the case below, I expected it dispatch SIGN_OUT. However, it does not dispatch any action.

How can I use it correctly? Thanks

export const initEpic = (action$, store) =>
  action$
    .ofType(INIT)
    .mergeMap(() =>
      Observable.if(
        () => true,
        { type: SIGN_OUT },
        { type: START_SOMETHING }
      ));

Upvotes: 1

Views: 433

Answers (1)

martin
martin

Reputation: 96959

The two parameters to Observable.if should be Observables so you should be using it like:

Observable.if(
  () => true,
  Observable.of({ type: SIGN_OUT }),
  Observable.of({ type: START_SOMETHING })
));

Upvotes: 1

Related Questions