Condense starting point state update into one function

This commit is contained in:
Z. Charles Dziura 2025-07-01 09:09:50 -04:00
parent a858cbf144
commit 8e026944aa

View file

@ -0,0 +1,37 @@
import { patchState, signalStore, withMethods, withState } from '@ngrx/signals';
export type StartingPointState = {
name: string;
gender: Gender;
afterHighSchool: AfterHighSchool;
};
export enum Gender {
Undefined = '',
Male = 'male',
Female = 'female',
}
export enum AfterHighSchool {
Undefined = '',
College = 'college',
Workforce = 'workforce',
}
const initialState: StartingPointState = {
name: '',
gender: Gender.Undefined,
afterHighSchool: AfterHighSchool.Undefined,
};
export const StartingPointStateStore = signalStore(
withState(initialState),
withMethods(store => ({
updateState: ({ name, gender, afterHighSchool }: Partial<StartingPointState>) =>
patchState(store, () => ({
name: name ?? '',
gender: gender ?? Gender.Undefined,
afterHighSchool: afterHighSchool ?? AfterHighSchool.Undefined,
})),
}))
);