Create function to update current view in global app state
This commit is contained in:
parent
f2d67bc56f
commit
171377d0b5
1 changed files with 12 additions and 2 deletions
|
@ -1,4 +1,4 @@
|
||||||
import { signalStore, withState } from '@ngrx/signals';
|
import { patchState, signalStore, withMethods, withState } from '@ngrx/signals';
|
||||||
|
|
||||||
export type AppState = {
|
export type AppState = {
|
||||||
currentView: CurrentView;
|
currentView: CurrentView;
|
||||||
|
@ -12,4 +12,14 @@ const initialState: AppState = {
|
||||||
currentView: CurrentView.StartingPoint,
|
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,
|
||||||
|
})),
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
|
Loading…
Add table
Reference in a new issue