轮询效果Ngrx

时间:2019-06-11 17:41:22

标签: angular ngrx polling ngrx-effects

我是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)))
     );
   })
 );

我希望看到这种效果每100毫秒被调用一次,但是看来,只有在我调度LoadProcessByUser()时才会调用该效果

请注意;我希望在应用程序的整个生命周期中都可以运行该轮询。

谢谢

1 个答案:

答案 0 :(得分:0)

您没有对interval做任何事情,您将必须返回间隔并在interval的{​​{1}}内添加服务呼叫。

例如,如果您不需要pipe,也可以基于LoadProcessesByUser创建一个流

interval

您可以在Start using ngrx/effects for this

中找到更多信息
相关问题