From 171377d0b54f83476c3a8589afd708dff4e8c368 Mon Sep 17 00:00:00 2001 From: "Z. Charles Dziura" Date: Tue, 1 Jul 2025 11:09:50 -0400 Subject: [PATCH] Create function to update current view in global app state --- src/app/app.state.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/app/app.state.ts b/src/app/app.state.ts index ec1c3ff..9357c3b 100644 --- a/src/app/app.state.ts +++ b/src/app/app.state.ts @@ -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, + })), + })) +);