I am trying to "lock down" an @ngrx/component-store effect so that if it is invoked several times each call is sequentially processed in full. Here's the code I came up with:
private readonly _init = this.effect( (createNewSession$: Observable<boolean>) => {
return createNewSession$.pipe(
concatMap( createNewSession => {
return of(createNewSession).pipe(
withLatestFrom(this.state$),
filter( ([_, state]) => state.session == null),
switchMap(([createNewSession2, state]) => this.orderInitService.init(state.batch, createNewSession2)),
tapResponse(orderInitResponse => this.setState(() => {
...
It works, but feels awkward. I also had success using of(undefined).pipe(, but that doesn't get me away from the feeling that I am missing something.
I need to make sure tapResponse finishes before the next sequence (of rxjs operators) starts as that changes this.state, and hence withLatestFrom(this.state$) should provide me the latest correct values.