Angular,ngrx-选择器中的不定式循环问题 [英] Angular, ngrx - problem with infinitive loop in selector

查看:75
本文介绍了Angular,ngrx-选择器中的不定式循环问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以在一个商店的选择器中分派动作吗?

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...

推荐答案

如果此操作打算在订阅商店选择器后触发一次,则可以将以上语句链接到RxJS take()

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

这篇关于Angular,ngrx-选择器中的不定式循环问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆