Reputation: 291
For this effect,
@Effect()
triggerOtherAction$: Observable<Action> = this.actions$
.ofType(SOME_ACTION)
.do(() => console.log("This line works for both"))
.map(() => new OtherAction())
When I dispatch an action, I can think these two ways
first,
Observable.of(new SomeAction()).subscribe(this.store);
second,
this.store.dispatch(new SomeAction());
what is the difference between above two lines? For the first one, it doesn't trigger other action, but execute the line of do() and reducer works well.
Upvotes: 0
Views: 1292
Reputation: 58410
There is no reason to dispatch actions using code like this:
Observable.of(new SomeAction()).subscribe(this.store);
In fact, there is a good reason not to: the observable to which the store
is subscribing will complete and that will see the store
complete, too.
In version 2.2.1 of @ngrx/store
, that's not a problem - as its implementation of complete
does nothing - but with the current master, complete
is implemented and dispatching an action as above will see the store complete and no further actions will be dispatched.
Upvotes: 3