gpt4 book ai didi

angular - 来自 ngrx/store 的 Reducer 不触发

转载 作者:太空狗 更新时间:2023-10-29 17:51:47 26 4
gpt4 key购买 nike

我在 "@angular/core": "4.4.3""@ngrx/store": "4.0.3 中使用 combineReducers " 项目和我遇到的问题是在发送操作后 reducer 没有被拾取。

这可能只是我对 ngrx/store 的有限体验

整个项目可以在这里看到https://github.com/raduchiriac/workflow

app.module.ts

import { AppStore } from './app.store'

@NgModule({
imports: [
StoreModule.forRoot(AppStore),
...
],
providers: [
...
]
})

app.store.ts

import { createSelector } from 'reselect';
import * as ModalsReducer from "./store/reducers/modals.reducer";

export interface AppState {
modals: ModalsReducer.State,
}

const metaReducer: ActionReducer<AppState> = combineReducers({
modals: ModalsReducer.reducer,
});

export function AppStore(state: any, action: any) {
return metaReducer(state, action);
}

modals.reducer.ts

import * as ModalsActions from '../actions/modals.actions';

export interface State {
triggerAdd: boolean;
}

const initialState: State = {
triggerAdd: false,
};

export function reducer(state = initialState, { type, payload }): State {
switch (type) {
case ModalsActions.MODALS_TRIGGER_ADD_CLOSE : {
return Object.assign({...state}, {
triggerAdd: false
});
}
...
}

triggers.component.ts

addNew() {
this.store.dispatch(new ModalsActions.OpenTriggerAddAction());
}
...

编辑:商店运作的唯一方法就是这样做。为什么?

app.module.ts

import { AppStore, reducers } from './app.store'
...
imports: [
StoreModule.forRoot(reducers, {}),
]

最佳答案

看来你应该看看 migration guide对于 ngrx v4。

v4 改变了注册 reducer 的方式。

StoreModule.forRoot(reducers, {})工作是因为 StoreModule.forRoot需要一个 ActionReducerMap<T, V> 类型的对象.第二个参数:{} - 是初始状态。

关于angular - 来自 ngrx/store 的 Reducer 不触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46409651/

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