Skip to content

Commit b741c7d

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 b741c7d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+286
-404
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { ApplicationConfig } from '@angular/core';
2+
import { provideHttpClient } from '@angular/common/http';
3+
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
4+
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';
9+
10+
import { rootReducers, metaReducers } from '@example-app/reducers';
11+
12+
import { APP_ROUTES } from '@example-app/app.routing';
13+
import { UserEffects, RouterEffects } from '@example-app/core/effects';
14+
import { provideRouter, withHashLocation } from '@angular/router';
15+
import * as fromAuth from '@example-app/auth/reducers';
16+
import { AuthEffects } from './auth/effects';
17+
18+
export const appConfig: ApplicationConfig = {
19+
providers: [
20+
provideAnimationsAsync(),
21+
provideHttpClient(),
22+
provideRouter(APP_ROUTES, withHashLocation()),
23+
24+
/**
25+
* provideStore() is imported once in the root providers, accepting a reducer
26+
* function or object map of reducer functions. If passed an object of
27+
* reducers, combineReducers will be run creating your application
28+
* meta-reducer. This returns all providers for an @ngrx/store
29+
* based application.
30+
*/
31+
provideStore(rootReducers, {
32+
metaReducers,
33+
runtimeChecks: {
34+
// strictStateImmutability and strictActionImmutability are enabled by default
35+
strictStateSerializability: true,
36+
strictActionSerializability: true,
37+
strictActionWithinNgZone: true,
38+
strictActionTypeUniqueness: true,
39+
},
40+
}),
41+
42+
/**
43+
* @ngrx/router-store keeps router state up-to-date in the store.
44+
*/
45+
provideRouterStore(),
46+
47+
/**
48+
* Store devtools instrument the store retaining past versions of state
49+
* and recalculating new states. This enables powerful time-travel
50+
* debugging.
51+
*
52+
* To use the debugger, install the Redux Devtools extension for either
53+
* Chrome or Firefox
54+
*
55+
* See: https://github.com/zalmoxisus/redux-devtools-extension
56+
*/
57+
provideStoreDevtools({
58+
name: 'NgRx Book Store App',
59+
// In a production build you would want to disable the Store Devtools
60+
// logOnly: !isDevMode(),
61+
}),
62+
63+
/**
64+
* The provideEffects() function is used to register effect classes
65+
* so they are initialized when the application starts.
66+
*/
67+
provideEffects(UserEffects, RouterEffects, AuthEffects),
68+
69+
/**
70+
* The Auth state is provided here to ensure that the login details
71+
* are available as soon as the application starts.
72+
*/
73+
provideState({
74+
name: fromAuth.authFeatureKey,
75+
reducer: fromAuth.reducers,
76+
}),
77+
],
78+
};

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

Lines changed: 0 additions & 81 deletions
This file was deleted.
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.routes').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.routes').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.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import { TestBed, ComponentFixture } from '@angular/core/testing';
22
import { NO_ERRORS_SCHEMA } from '@angular/core';
33
import { LoginFormComponent } from '@example-app/auth/components';
4-
import { ReactiveFormsModule } from '@angular/forms';
4+
import { provideNoopAnimations } from '@angular/platform-browser/animations';
55

66
describe('Login Page', () => {
77
let fixture: ComponentFixture<LoginFormComponent>;
88
let instance: LoginFormComponent;
99

1010
beforeEach(() => {
1111
TestBed.configureTestingModule({
12-
imports: [ReactiveFormsModule],
13-
declarations: [LoginFormComponent],
12+
imports: [LoginFormComponent],
13+
providers: [provideNoopAnimations()],
1414
schemas: [NO_ERRORS_SCHEMA],
1515
});
1616

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.spec.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import { ComponentFixture, TestBed } from '@angular/core/testing';
22
import { LogoutConfirmationDialogComponent } from '@example-app/auth/components';
3-
import { MaterialModule } from '@example-app/material';
43

54
describe('Logout Confirmation Dialog', () => {
65
let fixture: ComponentFixture<LogoutConfirmationDialogComponent>;
76

87
beforeEach(() => {
98
TestBed.configureTestingModule({
10-
imports: [MaterialModule],
11-
declarations: [LogoutConfirmationDialogComponent],
9+
imports: [LogoutConfirmationDialogComponent],
1210
});
1311

1412
fixture = TestBed.createComponent(LogoutConfirmationDialogComponent);

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.spec.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import { TestBed, ComponentFixture } from '@angular/core/testing';
2-
import { ReactiveFormsModule } from '@angular/forms';
3-
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
2+
import { provideNoopAnimations } from '@angular/platform-browser/animations';
43
import { LoginPageComponent } from '@example-app/auth/containers';
5-
import { LoginFormComponent } from '@example-app/auth/components';
64
import * as fromAuth from '@example-app/auth/reducers';
75
import { LoginPageActions } from '@example-app/auth/actions/login-page.actions';
86
import { provideMockStore, MockStore } from '@ngrx/store/testing';
9-
import { MaterialModule } from '@example-app/material';
107

118
describe('Login Page', () => {
129
let fixture: ComponentFixture<LoginPageComponent>;
@@ -15,9 +12,9 @@ describe('Login Page', () => {
1512

1613
beforeEach(() => {
1714
TestBed.configureTestingModule({
18-
imports: [NoopAnimationsModule, MaterialModule, ReactiveFormsModule],
19-
declarations: [LoginPageComponent, LoginFormComponent],
15+
imports: [LoginPageComponent],
2016
providers: [
17+
provideNoopAnimations(),
2118
provideMockStore({
2219
selectors: [
2320
{ selector: fromAuth.selectLoginPagePending, value: false },

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.

0 commit comments

Comments
 (0)