Skip to content

Commit 45bb249

Browse files
committed
docs: update example app to standalone
Updated the example app to standalone, removed all the modules from app.
1 parent 62cceeb commit 45bb249

32 files changed

+223
-268
lines changed
Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,34 @@
1-
import { NgModule } from '@angular/core';
2-
import { CommonModule } from '@angular/common';
3-
import { HttpClientModule } from '@angular/common/http';
4-
import { BrowserModule } from '@angular/platform-browser';
5-
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
1+
import { ApplicationConfig } from '@angular/core';
2+
import { provideHttpClient } from '@angular/common/http';
3+
import { provideAnimations } from '@angular/platform-browser/animations';
64

7-
import { StoreModule } from '@ngrx/store';
8-
import { EffectsModule } from '@ngrx/effects';
9-
import { StoreRouterConnectingModule } from '@ngrx/router-store';
10-
import { StoreDevtoolsModule } from '@ngrx/store-devtools';
11-
12-
import { AuthModule } from '@example-app/auth';
5+
import { provideState, provideStore } from '@ngrx/store';
6+
import { provideEffects } from '@ngrx/effects';
7+
import { provideRouterStore } from '@ngrx/router-store';
8+
import { provideStoreDevtools } from '@ngrx/store-devtools';
139

1410
import { rootReducers, metaReducers } from '@example-app/reducers';
1511

16-
import { CoreModule } from '@example-app/core';
17-
import { AppRoutingModule } from '@example-app/app-routing.module';
12+
import { APP_ROUTES } from '@example-app/app.routing';
1813
import { UserEffects, RouterEffects } from '@example-app/core/effects';
19-
import { AppComponent } from '@example-app/core/containers';
14+
import { provideRouter, withHashLocation } from '@angular/router';
15+
import * as fromAuth from '@example-app/auth/reducers';
16+
import { AuthEffects } from './auth/effects';
2017

21-
@NgModule({
22-
imports: [
23-
CommonModule,
24-
BrowserModule,
25-
BrowserAnimationsModule,
26-
HttpClientModule,
27-
AuthModule,
28-
AppRoutingModule,
18+
export const appConfig: ApplicationConfig = {
19+
providers: [
20+
provideAnimations(),
21+
provideHttpClient(),
22+
provideRouter(APP_ROUTES, withHashLocation()),
2923

3024
/**
31-
* StoreModule.forRoot is imported once in the root module, accepting a reducer
25+
* provideStore() is imported once in the root providers, accepting a reducer
3226
* function or object map of reducer functions. If passed an object of
3327
* reducers, combineReducers will be run creating your application
3428
* meta-reducer. This returns all providers for an @ngrx/store
3529
* based application.
3630
*/
37-
StoreModule.forRoot(rootReducers, {
31+
provideStore(rootReducers, {
3832
metaReducers,
3933
runtimeChecks: {
4034
// strictStateImmutability and strictActionImmutability are enabled by default
@@ -48,7 +42,7 @@ import { AppComponent } from '@example-app/core/containers';
4842
/**
4943
* @ngrx/router-store keeps router state up-to-date in the store.
5044
*/
51-
StoreRouterConnectingModule.forRoot(),
45+
provideRouterStore(),
5246

5347
/**
5448
* Store devtools instrument the store retaining past versions of state
@@ -60,22 +54,27 @@ import { AppComponent } from '@example-app/core/containers';
6054
*
6155
* See: https://github.com/zalmoxisus/redux-devtools-extension
6256
*/
63-
StoreDevtoolsModule.instrument({
57+
provideStoreDevtools({
6458
name: 'NgRx Book Store App',
6559
// In a production build you would want to disable the Store Devtools
6660
// logOnly: !isDevMode(),
6761
}),
6862

6963
/**
70-
* EffectsModule.forRoot() is imported once in the root module and
71-
* sets up the effects class to be initialized immediately when the
72-
* application starts.
64+
* The provideEffects() function is used to register effect classes
65+
* so they are initialized when the application starts.
7366
*
7467
* See: https://ngrx.io/guide/effects#registering-root-effects
7568
*/
76-
EffectsModule.forRoot(UserEffects, RouterEffects),
77-
CoreModule,
69+
provideEffects(UserEffects, RouterEffects, AuthEffects),
70+
71+
/**
72+
* The Auth state is provided here to ensure that the login details
73+
* is available as soon as the application starts.
74+
*/
75+
provideState({
76+
name: fromAuth.authFeatureKey,
77+
reducer: fromAuth.reducers,
78+
}),
7879
],
79-
bootstrap: [AppComponent],
80-
})
81-
export class AppModule {}
80+
};
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
import { NgModule } from '@angular/core';
2-
import { Routes, RouterModule } from '@angular/router';
1+
import { Routes } from '@angular/router';
32

43
import { authGuard } from '@example-app/auth/services';
54
import { NotFoundPageComponent } from '@example-app/core/containers';
65

7-
export const routes: Routes = [
6+
export const APP_ROUTES: Routes = [
7+
{
8+
path: 'login',
9+
loadChildren: () =>
10+
import('@example-app/auth/auth.routing').then((m) => m.AUTH_ROUTES),
11+
},
812
{ path: '', redirectTo: '/books', pathMatch: 'full' },
913
{
1014
path: 'books',
1115
loadChildren: () =>
12-
import('@example-app/books/books.module').then((m) => m.BooksModule),
16+
import('@example-app/books/books.routing').then((m) => m.BOOKS_ROUTES),
1317
canActivate: [authGuard],
1418
},
1519
{
@@ -18,13 +22,3 @@ export const routes: Routes = [
1822
data: { title: 'Not found' },
1923
},
2024
];
21-
22-
@NgModule({
23-
imports: [
24-
RouterModule.forRoot(routes, {
25-
useHash: true,
26-
}),
27-
],
28-
exports: [RouterModule],
29-
})
30-
export class AppRoutingModule {}

projects/example-app/src/app/auth/auth-routing.module.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

projects/example-app/src/app/auth/auth.module.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Routes } from '@angular/router';
2+
import { LoginPageComponent } from '@example-app/auth/containers';
3+
4+
export const AUTH_ROUTES: Routes = [
5+
{
6+
path: '',
7+
component: LoginPageComponent,
8+
data: { title: 'Login' },
9+
},
10+
];

projects/example-app/src/app/auth/components/login-form.component.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
import { NgIf } from '@angular/common';
12
import { Component, Input, Output, EventEmitter } from '@angular/core';
2-
import { FormGroup, FormControl } from '@angular/forms';
3+
import { FormGroup, FormControl, ReactiveFormsModule } from '@angular/forms';
34
import { Credentials } from '@example-app/auth/models';
5+
import { MaterialModule } from '@example-app/material';
46

57
@Component({
8+
standalone: true,
69
selector: 'bc-login-form',
10+
imports: [MaterialModule, ReactiveFormsModule, NgIf],
711
template: `
812
<mat-card>
913
<mat-card-title>Login</mat-card-title>

projects/example-app/src/app/auth/components/logout-confirmation-dialog.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { Component } from '@angular/core';
2+
import { MaterialModule } from '@example-app/material';
23

34
/**
45
* The dialog will close with true if user clicks the ok button,
56
* otherwise it will close with undefined.
67
*/
78
@Component({
9+
standalone: true,
10+
imports: [MaterialModule],
811
template: `
912
<h2 mat-dialog-title>Logout</h2>
1013
<mat-dialog-content>Are you sure you want to logout?</mat-dialog-content>

projects/example-app/src/app/auth/containers/login-page.component.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ import { Store } from '@ngrx/store';
33
import { Credentials } from '@example-app/auth/models';
44
import * as fromAuth from '@example-app/auth/reducers';
55
import { LoginPageActions } from '@example-app/auth/actions/login-page.actions';
6+
import { LoginFormComponent } from '../components';
7+
import { AsyncPipe } from '@angular/common';
68

79
@Component({
10+
standalone: true,
811
selector: 'bc-login-page',
12+
imports: [LoginFormComponent, AsyncPipe],
913
template: `
1014
<bc-login-form
1115
(submitted)="onSubmit($event)"

projects/example-app/src/app/auth/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

projects/example-app/src/app/books/books-routing.module.ts

Lines changed: 0 additions & 34 deletions
This file was deleted.

projects/example-app/src/app/books/books.module.ts

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)