我有下面的代码,并且每当用户选择一个实体时,我要更新selectedScenarioID。在ngrx存储中,属性会更新。
export interface IScenarioState extends EntityState<ScenarioState> {
selectedScenarioId: string | number | null;
}
export const initialState: IScenarioState = fromAdapter.adapter.getInitialState({
selectedScenarioId: '00001'
});
看看NgRx Example App,我们有完全相同的用例。
总之,您调度一个动作,然后在化简器中对状态进行突变。
export const reducer = createReducer(
initialState,
on(ViewBookPageActions.selectBook, (state, { id }) => ({
...state,
selectedBookId: id,
}))
);