Inerface的工作是排版检查和一些智能感知。这个
forRoot
注册你的减速器,这是最重要的部分,否则你的减速器不会被调用。
在示例中,您发布
State
接口实际上并没有添加任何值,但如果按如下方式进行,它会添加一些类型检查值。
// reducer.ts
/**
* As mentioned, we treat each reducer like a table in a database. This means
* our top level state interface is just a map of keys to inner state types.
*/
export interface State {
layout: fromLayout.State;
router: fromRouter.RouterReducerState;
}
/**
* Our state is composed of a map of action reducer functions.
* These reducer functions are called with each dispatched action
* and the current or initial state and return a new immutable state.
*/
export const reducers: ActionReducerMap<State> = {
layout: fromLayout.reducer,
router: fromRouter.routerReducer,
};
// app.module.ts
StoreModule.forRoot(reducers),
取自
NgRx example app