Angular, ngrx - problem with infinitive loop in selector

ⅰ亾dé卋堺 提交于 2020-01-25 08:39:05

问题


There is possible to dispatch action in selector in one store?

    this.store$.pipe(select(selectPersonByName, {personSelectorProps: this.id[]0}))
            .subscribe(history => {
                this.store$.dispatch(selectAssignWorkHistory({historyArray:  history}));
            });
    }

When I run that code, I have infinitive loop. Dispatch action refresh the store, and re-run selector and so on...


回答1:


If this action meant to be fired once upon subscribing to the store selector, you may chain the above statement the RxJS take() operator. This operator will ensure that only the specified count values supplied to be take() operator will be emitted by the source observable.

this.store$
  .pipe(
    select(selectPersonByName, {personSelectorProps: this.id[0]}),
    take(1),
  ).subscribe(history => {
    this.store$.dispatch(selectAssignWorkHistory({historyArray:  history}));
  });


来源:https://stackoverflow.com/questions/59417336/angular-ngrx-problem-with-infinitive-loop-in-selector

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!