如何访问ngrx选择器中选择器内的先前状态和当前状态?

问题描述 投票:0回答:1

我想知道是否可以在 ngrx selectors 中访问 previouscurrent 状态。我一直无法找到这方面的相关信息。是因为我使用了createSelector吗?有可用的“工厂方法”吗?我的目标是访问当前和之前的状态并执行一些操作来导出数据。 如果可以的话,请分享一些例子。 预先感谢!

angular redux rxjs state ngrx
1个回答
0
投票
pairwise

  store.pipe(select(<selector>)
    startWith({ oldValue: null, newValue: null }),
    distinctUntilChanged(),
    pairwise(),
    map(([oldValue, newValue]) => { return { oldValue, newValue } })
  )
  .subscribe({
      next: (val) => {
          console.log(val)
      }
  });

	
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.