In my project using combineReducers
with "@angular/core": "4.4.3"
and "@ngrx/store": "4.0.3"
, I am facing an issue where the reducers are not being detected after dispatching the actions.
It could be due to my lack of experience with ngrx/store
.
You can view the entire project here: 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());
}
...
EDIT: I found that the only way the store will work is by following this method. But why?
app.module.ts
import { AppStore, reducers } from './app.store'
...
imports: [
StoreModule.forRoot(reducers, {}),
]