ngrx issues with concatLatestFrom and skipwhile

huangapple go评论55阅读模式
英文:

ngrx issues with concatLatestFrom and skipwhile

问题

I have to call two endpoints and for the second I need to wait for a value from the first. since the first value will be in the store anyways.

I am following this pattern:

this.actions$.pipe(
  ofType('SOME_ACTION'),
  withLatestFrom(store.select(someThing).skipWhile(c => c == null)),
  switchMap(([action, state]) => hitEndPoint(state.data))
)

The problem is that the withLatestFrom runs once and completes the stream (I think), and that is not making the action trigger. What I actually want is to wait for the state to not be null and then run the hitEndPoint function.

I looked around and did not find an example that actually worked. Filter also ended up not working. Any ideas on how to get this behavior?

英文:

I have to call two endpoints and for the second I need to wait for a value from the first. since the first value will be in the store anyways.

I am following this pattern:

this.actions$.pipe(
  ofType('SOME_ACTION'),
  withLatestFrom(store.select(someThing).skipWhile(c=>c==null)),
  switchMap(([action, state]) => hitEndPoint(state.data))
)

The problem is that the withLatestFrom runs once and completes the stream (I think), and that is not making the action trigger. What I actually want is to wait the state to not be null and then run the hitEndPoint function.

I looked around did not find a example that actually worked. Filter also ended not working. Any ideas how to get this behavior

答案1

得分: 0

I think what you're looking for is the filter operator.

this.actions$.pipe(
  ofType('SOME_ACTION'),
  withLatestFrom(store.select(someThing).filter(c => c !== null)),
  switchMap(([action, state]) => hitEndPoint(state.data))
)
英文:

I think what you're looking for is the filter operator.

this.actions$.pipe(
  ofType('SOME_ACTION'),
  withLatestFrom(store.select(someThing).filter(c=>c!==null)),
  switchMap(([action, state]) => hitEndPoint(state.data))
)

huangapple
  • 本文由 发表于 2023年5月14日 02:39:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76244350.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定