angular - 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
);
};
最好的,赫门德兹姆
解决方案
推荐阅读
- c++ - CreateFont() 创建的字体的度量和大小不正确
- html - img srcs 的内部算法是如何工作的?
- dialogflow-es - Actions On Google 中的错误响应
- java - 在时区之间转换纪元毫秒
- javascript - 获取数组中最接近的值索引
- xml - 如何找到与变量值匹配的特定节点?
- python - 使用自有的python pip依赖和docker进行开发
- vue.js - 在 vuetify v-btn 中正确使用分组棱镜链接字段?
- c# - 有没有办法在 UWP 应用程序中使用带有 foreach 循环的 Windows.Storage.ApplicationData 保存列表?
- javascript - 访问 Javascript 函数变量