使用普通的Rxjs,我成功地实现了“倒计时”行为,即每秒像这样调用一个方法,直到没有更多的时间:
const time = 5
var timer$ = Rx.Observable.interval(1000)
timer$
.take(time)
.map((v)=> {
const remaining = time - 1 - v
return remaining;
})
.subscribe((v)=>console.log('Countdown', v))现在,使用redux-observable,我想实现一个倒计时行为,我得到初始时间(例如5000秒),然后每秒发送一个动作,直到初始时间降到0。到目前为止,我有这样的想法:
action$.pipe(
ofType(START_COUNTDOWN),
switchMap(() =>
interval(1000)
.map((time) => updateTime(time))),
);但是我得到了一个错误:Property map does not exist on type Observable<Number>。这里我没有错的是什么,因为我觉得用redux-observable来实现这一点应该不是很难。
发布于 2019-01-31 18:19:10
在您的redux-observable应用程序中,您正在使用较新版本的RxJS (> 6.0),该版本仅支持管道运算符,而您正在尝试使用旧的“补丁”风格(也有rxjs-compat包以实现向后兼容,但建议仅支持较旧的代码)。因此,从RxJS 6开始,应该只使用pipe()
action$.pipe(
ofType(START_COUNTDOWN),
switchMap(() => interval(1000).pipe(
map((time) => updateTime(time))
)),
);https://stackoverflow.com/questions/54456869
复制相似问题