在ngrx实体中启动状态时如何为实体设置默认值?
马铃薯模型.ts
export class Potato {
id: number;
weight: number;
}
马铃薯减速器.ts
export interface PotatoState extends EntityState<Potato> { }
export const potatoAdapter: EntityAdapter<Potato> = createEntityAdapter<Potato>();
const potatoesInitialState: PotatoState = potatoAdapter.getInitialState();
export const initialState: State = {
potatoes: potatoesInitialState
};
export function reducer(state = initialState, action: PotatoActions): State {
switch (action.type) {
// ...
}
}
例如,我需要设置默认权重 0.2。