angular - NgRx 取消订阅 store in effects
问题描述
我有一个简单的效果:
@Effect()
simpleEffect = this.actions.pipe(
ofType<ActionA>('Action A'),
withLatestFrom(this.store.select(selectSomething)),
map(([action, something]) => console.log('CALLED TWICE'))
);
这是选择器:
export const selectSomething = createSelector(
(appState) => appState.someState,
(someState) => someState.something
)
下面是一个简单的 reducer,它更新 的值something
:
export const someReducer = (state: SomeState = someInitialState, action: ActionB) => {
switch (action.type) {
case 'Action B':
return {
...state,
something: action.payload
};
default:
return state;
}
};
问题:
当我调度 ActionB 时,会调用 ActionA 的效果,尽管它不是。
正如我发现的那样,它的发生是因为withLatestFrom(this.store.select(selectSomething))
效果,它观察到something
FOREVER 的任何变化。
问题:
是否可以取消订阅该选择器?还是有其他功能代替withLatestFrom
?
解决方案
问题不在您显示的代码中,因为withLatestFrom只发出一个事件。安装Redux DevTools以查看您发送了哪些操作,并查看您是否没有发送两次“操作 A”
推荐阅读
- regex - 扫描文件夹以查找所有匹配词最少的文件 (UNIX)
- shell - 如何从 shell 中的日志“更新 2f8b547d..eb94967a 快进....”中获取“2f8b547d..eb94967a”字符串?
- regex - 为连续完整日志文件中的每个部分匹配 REGEX
- mongodb - 在 $ 或 mongodb 中使用 $text 搜索
- android - 在 Android Studio 中使用 Jpeg UI 布局
- javascript - 用于音乐可视化器的嵌套 For 循环不迭代 (p5.js)
- vim - 在 Vim 中移动代码折叠
- python - ImportError: 无法从 'hymnbook.models.author' 导入名称 'Author' (C:\..\hymnbook\models\author.py)
- python - tkinter 滚动条未按预期应用选项
- typescript - 如何访问内联子类型