缓冲直到使用redux-observable和rxjs

时间:2018-02-26 01:50:09

标签: rxjs redux-observable

在存储中的值为真之前,是否存在制作redux-observable史诗缓冲区的模式?

const uploadsCompleteEpic = (action$, store) => {
  return action$
    .ofType(actionTypes.UPLOAD_SUCCESS)
    .bufferWhen(store => store.getState().remaining -1 === 0)
    .do(action => console.log(action))
    .ignoreElements();
};

上述方法无效,因为bufferWhen中的函数不是Observable。我还尝试在Observable.single中包装缓冲区功能但没有成功。

1 个答案:

答案 0 :(得分:0)

我猜您必须先将setState转换为BehaviorSubject,然后才能获得信号

const remaining$=new BehaviorSubject(0)
store.setState({remaining:1},()=>{
      remaining$.next(1)
})

const uploadsCompleteEpic = (action$, store) => {
 return action$
.ofType(actionTypes.UPLOAD_SUCCESS)
.switchMap(()=>$remaining)
.bufferWhen(remain => remain ==1)
.do(action => console.log(action))
.ignoreElements();
};