angular - NgRx - 状态改变不当
问题描述
我有两个页面 FlowGroupPanel 和 FlowPanel。对于这些屏幕中的每一个,我都为过滤器创建了一个状态管理。但是,当我调度 FlowPanel 时,它会更改 FlowGroupPanel 资产。我不知道为什么会这样。我添加了代码的主要部分以及一些图片以便更好地理解。
FilterFlowGroupPanel 操作
import { createAction, props } from '@ngrx/store';
import { SearchFilterMessageLog } from '../models/SearchFilterMessageLog';
export enum FilterFlowGroupPanelActionTypes {
ADDFILTER = '[Filter Flow Group Panel] Add Filter',
CLEARFILTER = '[Filter Flow Group Panel] Clear Filter',
}
export const addFilter = createAction(
FilterFlowGroupPanelActionTypes.ADDFILTER,
props<{ searchFilterFlowGroupPanel: SearchFilterMessageLog }>()
)
export const clearFilter = createAction(
FilterFlowGroupPanelActionTypes.CLEARFILTER,
props<{ searchFilterFlowGroupPanel: null }>()
)
FilterFlowGroupPanel 缩减器
import { createReducer, props, on, State } from '@ngrx/store';
import { FilterFlowGroupPanelActions } from '../actions/action-types';
import { SearchFilterMessageLog } from '../models/SearchFilterMessageLog';
export interface FilterFlowGroupPanelState{
filterFlowGroupPanel: SearchFilterMessageLog
}
// export const initialState = null;
const initialState: FilterFlowGroupPanelState = null
export const _filterFlowGroupPanelReducer = createReducer(initialState,
on(FilterFlowGroupPanelActions.addFilter, (state, { searchFilterFlowGroupPanel }) => ({ ...state, ...searchFilterFlowGroupPanel})),
on(FilterFlowGroupPanelActions.clearFilter, state => state )
)
export function filterFlowGroupPanelReducer(state, action) {
return _filterFlowGroupPanelReducer(state, action);
}
FlowGroupPanel 模块
StoreModule.forFeature('filterFlowGroupPanelFeature', {
filterFlowGroupPanel: filterFlowGroupPanelReducer,
})
调度
this.store.dispatch(FilterFlowGroupPanelActions.addFilter({searchFilterFlowGroupPanel}))
FilterFlowPanel 操作
import { createAction, props } from '@ngrx/store';
import { SearchFilterMessageLog } from '../models/SearchFilterMessageLog';
export enum FilterFlowPanelActionTypes {
ADDFILTER = '[Filter Flow Panel] Add Filter',
CLEARFILTER = '[Filter Flow Panel] Clear Filter',
}
export const addFilter = createAction(
FilterFlowPanelActionTypes.ADDFILTER,
props<{ searchFilterFlowPanel: SearchFilterMessageLog }>()
)
export const clearFilter = createAction(
FilterFlowPanelActionTypes.CLEARFILTER,
props<{ searchFilterFlowPanel: null }>()
)
FilterFlowPanel 减速器
import { createReducer, props, on, State } from '@ngrx/store';
import { FilterFlowPanelActions } from '../actions/action-types';
import { SearchFilterMessageLog } from '../models/SearchFilterMessageLog';
export interface FilterFlowPanelState{
filterFlowPanel: SearchFilterMessageLog
}
export const initialState: FilterFlowPanelState = null
export const _filterFlowPanelReducer = createReducer(initialState,
on(FilterFlowPanelActions.addFilter, (state, {searchFilterFlowPanel} ) => ({ ...state, ...searchFilterFlowPanel})),
on(FilterFlowPanelActions.clearFilter, state => state )
)
export function filterFlowPanelReducer(state, action) {
return _filterFlowPanelReducer(state, action);
}
FlowPanel模块
StoreModule.forFeature('filterFlowPanelFeature', {
filterFlowPanel: filterFlowPanelReducer,
})
调度
this.store.dispatch(FilterFlowPanelActions.addFilter({searchFilterFlowPanel}))
解决方案
推荐阅读
- sql - 如何找到一年多一天订单超过 1 笔的客户
- asp.net - 创建表时出错:指定 ON DELETE NO ACTION 或 ON UPDATE NO ACTION,或修改其他 FOREIGN KEY 约束
- node.js - URL 解析 NodeJS 已弃用
- javascript - 在 JavaScript 中将圆转换为折线
- python - 如何在两个 forloops 中获取 forloop.counter
- docker - docker-compose 启动单个容器
- python - 将特定公式应用于熊猫数据框
- html - 如何在高度为 100Vh 的页面上添加 100vh 的标题图像?
- windows - PowerShell中的管道:不将参数绑定到参数
因为它是空的 - c++ - 给定一个非空整数数组 nums,每个元素出现两次,除了一个。使用散列找到那个单一的