I've been wondering if it's safe to assume that after the using the tap operator, the side effect inside it has completed.
My use case is with ngrx.
...
tap(() => {
this.store.dispatch(new SetValue("Hello World"));
}
}),
switchMap(() => this.store),
select(state => state.value),
tap(state => {
if (state === undefined) {
throw new Error("Couldn't find value");
}
})
SetValue is an class that implements ngrx
export class SetValue implements Action {
readonly type = SET_VALUE;
constructor(public payload: string) {}
}
What I'm trying to implement is to set a value on the store and then check if it's effectively been set.
Can I assume the dispatch has completed after tap operator?
Answer
I used this on Angular Router guards to set initial state by the parameters on the url, so I ended up filtering to only continue when the store has new value
...
tap(() => this.store.dispatch(new SetValue("Hello World"))),
switchMap(() => this.store),
select(state => state.value),
filter(value => value === "Hello World"),
take(1)