Skip to content

Commit 34324fe

Browse files
committed
Add behavior-subject on examples-nagular
1 parent 452df7a commit 34324fe

File tree

21 files changed

+419
-5
lines changed

21 files changed

+419
-5
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import nx from '@nx/eslint-plugin';
2+
import baseConfig from '../../eslint.config.mjs';
3+
4+
export default [
5+
...baseConfig,
6+
...nx.configs['flat/angular'],
7+
...nx.configs['flat/angular-template'],
8+
{
9+
files: ['**/*.ts'],
10+
rules: {
11+
'@angular-eslint/directive-selector': [
12+
'error',
13+
{
14+
type: 'attribute',
15+
prefix: 'app',
16+
style: 'camelCase',
17+
},
18+
],
19+
'@angular-eslint/component-selector': [
20+
'error',
21+
{
22+
type: 'element',
23+
prefix: 'app',
24+
style: 'kebab-case',
25+
},
26+
],
27+
},
28+
},
29+
{
30+
files: ['**/*.html'],
31+
// Override or add rules here
32+
rules: {},
33+
},
34+
];
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export default {
2+
displayName: 'angular-behavior-subject',
3+
preset: '../../jest.preset.js',
4+
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
5+
coverageDirectory: '../../coverage/apps/angular-behavior-subject',
6+
transform: {
7+
'^.+\\.(ts|mjs|js|html)$': [
8+
'jest-preset-angular',
9+
{
10+
tsconfig: '<rootDir>/tsconfig.spec.json',
11+
stringifyContentPathRegex: '\\.(html|svg)$',
12+
},
13+
],
14+
},
15+
transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
16+
snapshotSerializers: [
17+
'jest-preset-angular/build/serializers/no-ng-attributes',
18+
'jest-preset-angular/build/serializers/ng-snapshot',
19+
'jest-preset-angular/build/serializers/html-comment',
20+
],
21+
};
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
{
2+
"name": "angular-behavior-subject",
3+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
4+
"projectType": "application",
5+
"prefix": "app",
6+
"sourceRoot": "apps/angular-behavior-subject/src",
7+
"tags": [],
8+
"targets": {
9+
"build": {
10+
"executor": "@angular/build:application",
11+
"outputs": ["{options.outputPath}"],
12+
"options": {
13+
"outputPath": "dist/apps/angular-behavior-subject",
14+
"browser": "apps/angular-behavior-subject/src/main.ts",
15+
"polyfills": ["zone.js"],
16+
"tsConfig": "apps/angular-behavior-subject/tsconfig.app.json",
17+
"assets": [
18+
{
19+
"glob": "**/*",
20+
"input": "apps/angular-behavior-subject/public"
21+
}
22+
],
23+
"styles": ["apps/angular-behavior-subject/src/styles.css"]
24+
},
25+
"configurations": {
26+
"production": {
27+
"budgets": [
28+
{
29+
"type": "initial",
30+
"maximumWarning": "500kb",
31+
"maximumError": "1mb"
32+
},
33+
{
34+
"type": "anyComponentStyle",
35+
"maximumWarning": "4kb",
36+
"maximumError": "8kb"
37+
}
38+
],
39+
"outputHashing": "all"
40+
},
41+
"development": {
42+
"optimization": false,
43+
"extractLicenses": false,
44+
"sourceMap": true
45+
}
46+
},
47+
"defaultConfiguration": "production"
48+
},
49+
"serve": {
50+
"continuous": true,
51+
"executor": "@angular/build:dev-server",
52+
"configurations": {
53+
"production": {
54+
"buildTarget": "angular-behavior-subject:build:production"
55+
},
56+
"development": {
57+
"buildTarget": "angular-behavior-subject:build:development"
58+
}
59+
},
60+
"defaultConfiguration": "development"
61+
},
62+
"extract-i18n": {
63+
"executor": "@angular/build:extract-i18n",
64+
"options": {
65+
"buildTarget": "angular-behavior-subject:build"
66+
}
67+
},
68+
"lint": {
69+
"executor": "@nx/eslint:lint"
70+
},
71+
"test": {
72+
"executor": "@nx/jest:jest",
73+
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
74+
"options": {
75+
"jestConfig": "apps/angular-behavior-subject/jest.config.ts",
76+
"tsConfig": "apps/angular-behavior-subject/tsconfig.spec.json"
77+
}
78+
},
79+
"serve-static": {
80+
"continuous": true,
81+
"executor": "@nx/web:file-server",
82+
"options": {
83+
"buildTarget": "angular-behavior-subject:build",
84+
"port": 4200,
85+
"staticFilePath": "dist/apps/angular-behavior-subject/browser",
86+
"spa": true
87+
}
88+
}
89+
}
90+
}
14.7 KB
Binary file not shown.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import {
2+
ApplicationConfig,
3+
provideBrowserGlobalErrorListeners,
4+
provideZoneChangeDetection,
5+
} from '@angular/core';
6+
import { provideRouter } from '@angular/router';
7+
import { appRoutes } from './app.routes';
8+
9+
export const appConfig: ApplicationConfig = {
10+
providers: [
11+
provideBrowserGlobalErrorListeners(),
12+
provideZoneChangeDetection({ eventCoalescing: true }),
13+
provideRouter(appRoutes),
14+
],
15+
};

examples-angular/apps/angular-behavior-subject/src/app/app.css

Whitespace-only changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<h1>angular-rxjs</h1>
2+
3+
<p>Compteur : {{ count$ | async }}</p>
4+
<p>Double : {{ double$ | async }}</p>
5+
6+
<button (click)="dec()">-10</button>
7+
<button (click)="inc()">+10</button>
8+
<button (click)="reset()">Reset</button>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { Route } from '@angular/router';
2+
3+
export const appRoutes: Route[] = [];
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { TestBed } from '@angular/core/testing';
2+
import { App } from './app';
3+
4+
describe('App', () => {
5+
beforeEach(async () => {
6+
await TestBed.configureTestingModule({
7+
imports: [App],
8+
}).compileComponents();
9+
});
10+
11+
it('should render title', () => {
12+
const fixture = TestBed.createComponent(App);
13+
fixture.detectChanges();
14+
const compiled = fixture.nativeElement as HTMLElement;
15+
expect(compiled.querySelector('h1')?.textContent).toContain(
16+
'angular-behavior-subject'
17+
);
18+
});
19+
});
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import { Component } from '@angular/core'
2+
import { AsyncPipe, CommonModule } from '@angular/common'
3+
import { BehaviorSubject, map, Observable } from 'rxjs'
4+
5+
@Component({
6+
selector: 'app-root',
7+
standalone: true,
8+
imports: [CommonModule, AsyncPipe],
9+
templateUrl: './app.html',
10+
styleUrls: ['./app.css']
11+
})
12+
export class App {
13+
private readonly countSubject = new BehaviorSubject<number>(0)
14+
15+
readonly count$: Observable<number> = this.countSubject.asObservable()
16+
readonly double$: Observable<number> = this.count$.pipe(map(v => v * 2))
17+
18+
inc(): void {
19+
this.countSubject.next(this.countSubject.value + 10)
20+
}
21+
22+
dec(): void {
23+
this.countSubject.next(this.countSubject.value - 10)
24+
}
25+
26+
reset(): void {
27+
this.countSubject.next(0)
28+
}
29+
}
30+
31+
32+
33+
// import { Component } from '@angular/core'
34+
// import { BehaviorSubject, map, Observable } from 'rxjs'
35+
36+
// @Component({
37+
// selector: 'app-root',
38+
// templateUrl: './app.html',
39+
// styleUrls: ['./app.css']
40+
// })
41+
// export class App {
42+
// private readonly countSubject = new BehaviorSubject<number>(0)
43+
44+
// readonly count$: Observable<number> = this.countSubject.asObservable()
45+
// readonly double$: Observable<number> = this.count$.pipe(map(v => v * 2))
46+
47+
// inc(): void {
48+
// this.countSubject.next(this.countSubject.value + 10)
49+
// }
50+
51+
// dec(): void {
52+
// this.countSubject.next(this.countSubject.value - 10)
53+
// }
54+
55+
// reset(): void {
56+
// this.countSubject.next(0)
57+
// }
58+
// }
59+
60+
61+
62+
// import { Component } from '@angular/core';
63+
// import { BehaviorSubject, map } from 'rxjs';
64+
65+
// @Component({
66+
// selector: 'app-root',
67+
// templateUrl: './app.html',
68+
// styleUrls: ['./app.css']
69+
// })
70+
// export class AppComponent {
71+
// count$ = new BehaviorSubject<number>(0);
72+
// double$ = this.count$.pipe(map(v => v * 2));
73+
74+
// inc() {
75+
// this.count$.next(this.count$.value + 10);
76+
// }
77+
78+
// dec() {
79+
// this.count$.next(this.count$.value - 10);
80+
// }
81+
82+
// reset() {
83+
// this.count$.next(0);
84+
// }
85+
86+
// constructor() {
87+
// console.log('00000000001:', this.count$);
88+
// this.double$.subscribe();
89+
// }
90+
// }
91+

0 commit comments

Comments
 (0)