我是Ngrx新手,在使用Ngrx效果设置轮询时遇到问题
我已经尝试了前面提到的How to do http polling in ngrx effect的答案,但这似乎并不能像我的解决方案所预期的那样工作。我有种感觉,这可能是因为我的返回声明
LoadProcessesByUser$: Observable<Action> = this.actions$.pipe(
ofType(AppActions.LoadProcessesByUser),
switchMap(() => {
interval(100).pipe(
startWith(0),
mapTo(this.actions$)
);
return this.apiService.getUserProcesses(this.userService.user.lanId).pipe(
map(result => new LoadProcessesSuccess(result)),
catchError(error => of(new LoadFailure(error)))
);
})
);我希望看到这种效果每隔100ms被调用一次,但是看起来,它只是在我每次发送LoadProcessByUser()时才被调用。
请注意,我希望此轮询在应用程序的生命周期内一直运行。
谢谢
发布于 2019-06-12 02:13:02
您不会对interval执行任何操作,您将不得不返回间隔并在interval的pipe中添加服务调用。
如果不需要LoadProcessesByUser,也可以基于interval创建流,例如
@Effect()
ping = interval(1000).pipe(mapTo(new Ping()));您可以在Start using ngrx/effects for this上找到更多信息
https://stackoverflow.com/questions/56549106
复制相似问题