Create function to update current view in global app state

This commit is contained in:
Z. Charles Dziura 2025-07-01 11:09:50 -04:00
parent f2d67bc56f
commit 171377d0b5

View file

@ -1,4 +1,4 @@
import { signalStore, withState } from '@ngrx/signals';
import { patchState, signalStore, withMethods, withState } from '@ngrx/signals';
export type AppState = {
currentView: CurrentView;
@ -12,4 +12,14 @@ const initialState: AppState = {
currentView: CurrentView.StartingPoint,
};
export const AppStateStore = signalStore({ providedIn: 'root' }, withState(initialState));
export const AppStateStore = signalStore(
{ providedIn: 'root' },
withState(initialState),
withMethods(store => ({
updateCurrentView: (currentView: CurrentView) =>
patchState(store, () => ({
...store,
currentView,
})),
}))
);