在功能存储区中引用appState / rootState有什么用?

时间:2019-09-08 16:33:02

标签: ngrx

试图理解ngrx示例应用程序,被卡住,无法找出其用例。

在以下摘自ngrx-example-app

的代码中,的重要性是什么
export interface State extends fromRoot.State {
  [booksFeatureKey]: BooksState;
}

/** Provide reducer in AoT-compilation happy way */
export function reducers(state: BooksState | undefined, action: Action) {
  return combineReducers({
    [fromSearch.searchFeatureKey]: fromSearch.reducer,
    [fromBooks.booksFeatureKey]: fromBooks.reducer,
    [fromCollection.collectionFeatureKey]: fromCollection.reducer,
  })(state, action);
}

1 个答案:

答案 0 :(得分:0)

这样做没有运行时差异,只是使打字稿意识到您“拥有”了根状态。

如果您从功能状态选择器中访问根状态或根选择器,则使打字稿满意是必需的。