Condense starting point state update into one function
This commit is contained in:
parent
a858cbf144
commit
8e026944aa
1 changed files with 37 additions and 0 deletions
37
src/app/views/starting-point/starting-point.state.ts
Normal file
37
src/app/views/starting-point/starting-point.state.ts
Normal 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,
|
||||||
|
})),
|
||||||
|
}))
|
||||||
|
);
|
Loading…
Add table
Reference in a new issue