2017-09-25 87 views
1

我在"@angular/core": "4.4.3""@ngrx/store": "4.0.3"项目中使用combineReducers项目,并且我在调度操作后未收到reducer时遇到问题。来自ngrx/store的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, {}), 
] 

回答

1

看起来你应该看一看在migration guide为NGRX V4。

v4改变了你如何注册减速器。

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