我正在创建一个用于显示等待列表的简单应用,并且我有一些状态模型和简化器:
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接口?