在存储中的值为真之前,是否存在制作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
中包装缓冲区功能但没有成功。
答案 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();
};