46 lines
1 KiB
TypeScript
46 lines
1 KiB
TypeScript
import { effect } from '@angular/core';
|
|
import { getState, patchState, signalStore, withHooks, 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,
|
|
})),
|
|
})),
|
|
withHooks({
|
|
onInit: store => {
|
|
effect(() => {
|
|
const state = getState(store);
|
|
console.log(state);
|
|
});
|
|
},
|
|
})
|
|
);
|