diff --git a/src/app/app.config.ts b/src/app/app.config.ts index 11f1b40..c79bb5e 100644 --- a/src/app/app.config.ts +++ b/src/app/app.config.ts @@ -1,23 +1,15 @@ import { ApplicationConfig, - importProvidersFrom, isDevMode, provideBrowserGlobalErrorListeners, provideZonelessChangeDetection, } from '@angular/core'; -import { StoreModule } from '@ngrx/store'; import { provideStoreDevtools } from '@ngrx/store-devtools'; -import { appStateReducer } from './state/state.reducer'; export const appConfig: ApplicationConfig = { providers: [ provideBrowserGlobalErrorListeners(), provideZonelessChangeDetection(), - importProvidersFrom( - StoreModule.forRoot({ - app: appStateReducer, - }) - ), provideStoreDevtools({ maxAge: 25, logOnly: !isDevMode(), diff --git a/src/app/app.html b/src/app/app.html index 64edeaa..472811b 100644 --- a/src/app/app.html +++ b/src/app/app.html @@ -1,5 +1,5 @@
- @switch (currentView$ | async) { + @switch (currentView()) { @default { } diff --git a/src/app/app.state.ts b/src/app/app.state.ts new file mode 100644 index 0000000..ec1c3ff --- /dev/null +++ b/src/app/app.state.ts @@ -0,0 +1,15 @@ +import { signalStore, withState } from '@ngrx/signals'; + +export type AppState = { + currentView: CurrentView; +}; + +export enum CurrentView { + StartingPoint = 'startingPoint', +} + +const initialState: AppState = { + currentView: CurrentView.StartingPoint, +}; + +export const AppStateStore = signalStore({ providedIn: 'root' }, withState(initialState)); diff --git a/src/app/app.ts b/src/app/app.ts index 09dfbfb..f8dd1d2 100644 --- a/src/app/app.ts +++ b/src/app/app.ts @@ -1,7 +1,5 @@ -import { AsyncPipe } from '@angular/common'; import { ChangeDetectionStrategy, Component, inject, OnInit } from '@angular/core'; -import { select, Store } from '@ngrx/store'; -import { selectCurrentView } from './state/state.selectors'; +import { AppStateStore } from './app.state'; import { StartingPoint } from './views/starting-point/starting-point'; @Component({ @@ -9,12 +7,11 @@ import { StartingPoint } from './views/starting-point/starting-point'; templateUrl: './app.html', styleUrl: './app.scss', changeDetection: ChangeDetectionStrategy.OnPush, - imports: [AsyncPipe, StartingPoint], + imports: [StartingPoint], }) export class App implements OnInit { - private readonly store$ = inject(Store); - - readonly currentView$ = this.store$.pipe(select(selectCurrentView)); + private readonly state = inject(AppStateStore); + readonly currentView = this.state.currentView; ngOnInit(): void {} } diff --git a/src/app/state/state.reducer.ts b/src/app/state/state.reducer.ts deleted file mode 100644 index a530355..0000000 --- a/src/app/state/state.reducer.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { createReducer } from '@ngrx/store'; - -export interface AppState { - currentView: CurrentView; -} - -export enum CurrentView { - StartingPoint = 'startingPoint', -} - -export const initialState: AppState = { - currentView: CurrentView.StartingPoint, -}; - -export const appStateReducer = createReducer(initialState); diff --git a/src/app/state/state.selectors.ts b/src/app/state/state.selectors.ts deleted file mode 100644 index e248254..0000000 --- a/src/app/state/state.selectors.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { createFeatureSelector, createSelector } from '@ngrx/store'; -import { AppState } from './state.reducer'; - -export const selectAppState = createFeatureSelector('app'); - -export const selectCurrentView = createSelector(selectAppState, (state: AppState) => state.currentView);