在@ ngrx / store中,为什么store.select基于根reducer而不是Store的type参数?

时间:2018-07-21 15:58:03

标签: angular typescript dependency-injection ngrx

我正在创建一个用于显示等待列表的简单应用,并且我有一些状态模型和简化器:

app-state.ts:

import { WaitlistState } from "./waitlist/waitlist.state";

export interface AppState {
  readonly waitlistState: WaitlistState;
};

root-reducer.ts:

import waitlistReducer from "./waitlist/waitlist.reducer";

export const rootReducer = {
  waitlistState: waitlistReducer
};

要向我的视图显示应用程序状态,我创建了一个WaitlistService类:

@Injectable()
export class WaitlistService {

  constructor(private store: Store<AppState>, private waitlistActions: WaitlistActions,
  private persistenceService: PersistenceService) {}

  getWaitlists() : Observable<IterableIterator<PersistedWaitlist>> {
    return this.store.select((appState) => appState.waitlistState.persistedWaitlists.values());
  }
}

令人困惑的是,我注意到在运行时,appState函数中getWaitlists的属性是从rootReducer而不是AppState派生的。如果我将根减速器更改为:

export const rootReducer = {
  waitlistReducer: waitlistReducer // changed from waitlistState
};

代码可以很好地编译,但是我会遇到运行时错误:

Cannot read property 'persistedWaitlists' of undefined

谁能告诉我为什么这些属性绑定到reducer而不是AppState接口?

0 个答案:

没有答案