首页 > 解决方案 > NGRX 如何获得以前的状态?

问题描述

我有一个使用实体的 Ngrx 商店。我需要获取以前版本的状态才能撤消。我使用了下面的代码,但是当我从一个组件更改为另一个组件时它不起作用,因为为此我需要订阅顶部组件,这在我的情况下不是最好的。它是一种通过定义选择器或其他方式来获取状态版本的方法吗?

// The number of state transitions is given by the user (subscriber)
export const selectLastStateTransitions = (count: number, selector: any) => {
  return pipe(
    // Thanks to `createSelector` the operator will have memoization "for free"
    select(selector),
    // Combines the last `count` state values in array
    scan((acc, curr) => {

      const x = [curr, ...acc].filter((val, index) => index < count); // && val !== undefined);
      return x;

    }, [])
    // Equivalent to what is emitted by the selector
  );
};

最好的,赫门德兹姆

标签: angularngrx

解决方案


推荐阅读