只使用一个reducer会让我误解ngrx

问题描述 投票:0回答:1

我正在使用商店处理Angular,由于一些redux'错误,我无法构建我的项目。

实际上,使我的商店工作的唯一方法是使用此配置

app.module.ts - 进口

StoreModule.forRoot({applicationState: AppReducer}),

app.reducer.ts

export function AppReducer(state = initialState, action: Action): AppState {
switch (action.type) {
    case types....:
      return {...state, ...};
...

在我的组件中

this.store.select(s => s.applicationState.myValue).subscribe()...

它没有正确构建,但是当我服务两次时,我至少可以测试我的项目。由于我没有任何子状态(我的Appstate充满了数字,数组等但没有子状态),只有一个reducer,我不知道如何在app.module.ts中声明我的ActionMapReducer,以便能够订阅我的价值观如下:

this.store.select('myValue').subscribe(..)

我尝试了很多东西,查看了许多样本,但我无法弄清楚如何解决这个问题,而我的项目无法构建,因为:(。

angular dictionary redux store ngrx
1个回答
0
投票

即使你只有一个减速器,似乎你不能在没有ReducerMap的情况下使用ngrx的商店。 :(

这样做了

index.ts

export interface State {
    state: AppState; // contains my store, real 'state'
}

export const reducers: ActionReducerMap<State> = { // State isnt my 'real' state !
  state: AppReducer
};

export const getValueState = createFeatureSelector<AppState>('state')
export const getValue = createSelector(getValueState, (state: AppState) => state.value);

app.modules.ts - 进口

StoreModule.forRoot(reducers)

component.ts

this.store.select(getValue).subscribe(...);

我仍然无法弄清楚为什么我不能使用像select('myValue')这样的选择器......但现在它很好。

© www.soinside.com 2019 - 2024. All rights reserved.