gpt4 book ai didi

angular - ngrx/store init store 工作不正常

转载 作者:行者123 更新时间:2023-12-02 06:50:08 27 4
gpt4 key购买 nike

我的商店包含以下 reducer :

export const centralStampState = {
layoutState : layoutReducer, //this one is not initialized
eventTabState : eventTabReducer,
eventTimelineState: eventTimelineReducer,
eventWorkflowState : eventWorkflowReducer,
displayLayerState : displayLayerReducer,
treeState : TreeReducer
}

问题是 Angular 初始化了所有的 reducer,只有一个 'layoutState' 在触发第一个 Action 后被初始化(这导致访问 undefined 对象).

我对所有 reducer 和状态都遵循相同的实现,但我没有弄清楚这种奇怪行为的原因。

下面是Store在初始化之后和第一个action之后的状态 enter image description here

enter image description here

我的实现对所有 reducer 都是一样的。

export function layoutReducer(state: LayoutState = INITIAL_LAYOUT_STATE, action: Action) : LayoutState{
switch (action.type){
case UPDATE_SPLIT_CONFIG_DIMENSION :
return updateSplitConfigDimension(state, action);
case DISABLE_SPLIT_CONFIGURATION:
return state;
case UPDATE_SPLIT_AREA_VISIBILITY :
return state;
case RESTORE_DEFAULT_CONFIG_LAYOUT :
return state;
}
}

export function eventTabReducer(state: EventTabState = EVENT_TAB_INITIAL_STATE, action: CSAction): EventTabState {
switch (action.type) {
case LOAD_SUPPORTED_REPORT_FIELDS:
return state;
default:
return state;
}
}

最佳答案

我发现了,如果它是 JAVA 而不是 Typescript,代码将根本无法编译!!!!!!!!!

我在 switch case 中遗漏了 default 语句,当 Angular 处理 @ngrx/store/init layoutReducer Action 时将忽略此操作,并且如果找不到默认语句,Angular 似乎将返回 undefined

export function layoutReducer(state: LayoutState = INITIAL_LAYOUT_STATE, action: Action) : LayoutState{
switch (action.type){
case UPDATE_SPLIT_CONFIG_DIMENSION :
return updateSplitConfigDimension(state, action);
case DISABLE_SPLIT_CONFIGURATION:
return state;
case UPDATE_SPLIT_AREA_VISIBILITY :
return state;
case RESTORE_DEFAULT_CONFIG_LAYOUT :
return state;
default:
return state;// with this Angular can perform the ngrx init action
}
}

关于angular - ngrx/store init store 工作不正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47288006/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com