1

In a same component, I have following code:

this.store.select(state => state.someProperty)).pipe(
        takeUntil(this.destroy$),
        // distinctUntilChanged((prev, curr) => JSON.stringify(prev) === JSON.stringify(curr))
      ).subscribe(val => {
        dosomething()
      })

And in the same component, I have store action to fire a new value.


this.store.dispatch(
            someAction({
              payload: {
                value
              }
            }));

I don't want the subscription above to emit value if the below action fires, I know it is not a common requirement nor a built-in support nor a correct pattern that prevent specific store selector to emit values, but I got this requirement from a specific situation.

I have tried to fire a specific token before I dispatch that action, e.g.

this.storeToken$.next('Hey, some one please don't emit following action')
this.store.dispatch(
            someAction({
              payload: {
                value
              }
            }));

And trying some rxjs tricks when subscribing the selector:

race(this.store.select(state => state.someProperty).pipe(
      delay(100)), this.storeToken$)

I want to filter the token away, but it never works. The store selector always win the race,

May I ask if anyone have idea?

Vincent
  • 1,178
  • 1
  • 12
  • 25

1 Answers1

0

You can just take the first value with the take operator. If you need to be more specific, use one of the distinct operators or filter.

this.store.select(state => state.someProperty).pipe(take(1))
timdeschryver
  • 14,415
  • 1
  • 19
  • 32