英文:
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))
)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论