Skip to content

Commit

Permalink
Ajout de l'exercice sur rxjs
Browse files Browse the repository at this point in the history
  • Loading branch information
yatho committed Jun 7, 2024
1 parent 16aaf83 commit f6673f3
Show file tree
Hide file tree
Showing 19 changed files with 347 additions and 0 deletions.
36 changes: 36 additions & 0 deletions apps/rxjs/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts"],
"extends": [
"plugin:@nx/angular",
"plugin:@angular-eslint/template/process-inline-templates"
],
"rules": {
"@angular-eslint/directive-selector": [
"error",
{
"type": "attribute",
"prefix": "app",
"style": "camelCase"
}
],
"@angular-eslint/component-selector": [
"error",
{
"type": "element",
"prefix": "app",
"style": "kebab-case"
}
]
}
},
{
"files": ["*.html"],
"extends": ["plugin:@nx/angular-template"],
"rules": {}
}
]
}
22 changes: 22 additions & 0 deletions apps/rxjs/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* eslint-disable */
export default {
displayName: 'rxjs',
preset: '../../jest.preset.js',
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
coverageDirectory: '../../coverage/apps/rxjs',
transform: {
'^.+\\.(ts|mjs|js|html)$': [
'jest-preset-angular',
{
tsconfig: '<rootDir>/tsconfig.spec.json',
stringifyContentPathRegex: '\\.(html|svg)$',
},
],
},
transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
snapshotSerializers: [
'jest-preset-angular/build/serializers/no-ng-attributes',
'jest-preset-angular/build/serializers/ng-snapshot',
'jest-preset-angular/build/serializers/html-comment',
],
};
80 changes: 80 additions & 0 deletions apps/rxjs/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"name": "rxjs",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"prefix": "app",
"sourceRoot": "apps/rxjs/src",
"tags": [],
"targets": {
"build": {
"executor": "@angular-devkit/build-angular:application",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/apps/rxjs",
"index": "apps/rxjs/src/index.html",
"browser": "apps/rxjs/src/main.ts",
"polyfills": ["zone.js"],
"tsConfig": "apps/rxjs/tsconfig.app.json",
"assets": [
{
"glob": "**/*",
"input": "apps/rxjs/public"
}
],
"styles": ["apps/rxjs/src/styles.css"],
"scripts": []
},
"configurations": {
"production": {
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "2kb",
"maximumError": "4kb"
}
],
"outputHashing": "all"
},
"development": {
"optimization": false,
"extractLicenses": false,
"sourceMap": true
}
},
"defaultConfiguration": "production"
},
"serve": {
"executor": "@angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"buildTarget": "rxjs:build:production"
},
"development": {
"buildTarget": "rxjs:build:development"
}
},
"defaultConfiguration": "development"
},
"extract-i18n": {
"executor": "@angular-devkit/build-angular:extract-i18n",
"options": {
"buildTarget": "rxjs:build"
}
},
"lint": {
"executor": "@nx/eslint:lint"
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "apps/rxjs/jest.config.ts"
}
}
}
}
Binary file added apps/rxjs/public/favicon.ico
Binary file not shown.
20 changes: 20 additions & 0 deletions apps/rxjs/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Component } from '@angular/core';
import { Ex1Component } from './ex1/ex1.component';
import { Ex2Component } from './ex2/ex2.component';
import { Ex3Component } from './ex3/ex3.component';
import { Ex4Component } from './ex4/ex4.component';
import { Ex5Component } from './ex5/ex5.component';

@Component({
standalone: true,
imports: [Ex1Component, Ex2Component, Ex3Component, Ex4Component, Ex5Component],
selector: 'app-root',
template: `
<app-ex1/>
<!-- <app-ex2/> -->
<!-- <app-ex3/> -->
<!-- <app-ex4/> -->
<!-- <app-ex5/> -->
`
})
export class AppComponent {}
5 changes: 5 additions & 0 deletions apps/rxjs/src/app/app.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';

export const appConfig: ApplicationConfig = {
providers: [provideZoneChangeDetection({ eventCoalescing: true })],
};
17 changes: 17 additions & 0 deletions apps/rxjs/src/app/ex1/ex1.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Component } from '@angular/core';
import { AsyncPipe } from '@angular/common';

@Component({
selector: 'app-ex1',
standalone: true,
imports: [AsyncPipe],
template: ``,
})
export class Ex1Component {
// TODO : Créer un observable qui émet une séquence de nombre de 1 à 10
// TODO : Affiche le résultat dans la console et dans le template
// TODO : Multiplier chaque valeur de l'observable par 2
// TODO : Emettre uniquement les valeurs pairs

constructor() {}
}
24 changes: 24 additions & 0 deletions apps/rxjs/src/app/ex2/ex2.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Component } from '@angular/core';
import { Observable, of, throwError } from 'rxjs';

@Component({
selector: 'app-ex2',
standalone: true,
template: ``
})
export class Ex2Component {
// TODO : Créer deux observables
// TODO : Le premier observable émet des valeurs paires de 1 à 10
// TODO : Le second observable émet des valeurs impaires de 1 à 10
// TODO : Merger les deux observables pour n'en former qu'un seul
// TODO : Utiliser un opérateur pour afficher les retours de la méthode getFromId()
// TODO : Notifier l'utilisateur en cas d'erreur

constructor() {}
}

// - Contraintes : Il est interdit de modifier cette méthode
const getFromId = (id: number): Observable<{id: number, name: string}> => {
if (id < 7) return of({id, name: `Name ${id}`});
return throwError(() => id);
}
16 changes: 16 additions & 0 deletions apps/rxjs/src/app/ex3/ex3.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Component } from '@angular/core';

@Component({
selector: 'app-ex3',
standalone: true,
imports: [],
template: ``
})
export class Ex3Component {
// TODO : Créer deux observables qui emettent des valeurs à interval régulier mais un interval différent
// TODO : Combiner les deux observables pour former un qui émet des tuples des valeurs émises par chacun des deux observables
// TODO : Afficher uniquement les 10 premières valeurs émises par le nouvel observable


constructor() {}
}
16 changes: 16 additions & 0 deletions apps/rxjs/src/app/ex4/ex4.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Component } from '@angular/core';

@Component({
selector: 'app-ex4',
standalone: true,
imports: [],
template: ''
})
export class Ex4Component {
// TODO : Utiliser un interval pour émettre des valeurs
// TODO : Utiliser un opérateur pour limiter le nombre de valeurs émises à 10
// TODO : Utiliser un opérateur pour limiter les valeurs émises en fonction d'une condition
// TODO : Utiliser un opérateur pour émettre les 5 dernières valeurs

constructor() {}
}
17 changes: 17 additions & 0 deletions apps/rxjs/src/app/ex5/ex5.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Component } from '@angular/core';
import { FormsModule } from '@angular/forms';

@Component({
selector: 'app-ex5',
standalone: true,
imports: [FormsModule],
template: ``
})
export class Ex5Component {
// TODO : Créer un formulaire avec un input
// TODO : Afficher dans la console à chaque fois que l'utilisateur change la valeur de l'input
// TODO : Utiliser un opérateur pour limiter le nombre de valeurs émises si l'input change trop rapidement
// TODO : Utiliser un opérateur pour émettre que si il y a un changement de valeur

constructor() {}
}
13 changes: 13 additions & 0 deletions apps/rxjs/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>rxjs</title>
<base href="/" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/x-icon" href="favicon.ico" />
</head>
<body>
<app-root></app-root>
</body>
</html>
7 changes: 7 additions & 0 deletions apps/rxjs/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { bootstrapApplication } from '@angular/platform-browser';
import { appConfig } from './app/app.config';
import { AppComponent } from './app/app.component';

bootstrapApplication(AppComponent, appConfig).catch((err) =>
console.error(err)
);
1 change: 1 addition & 0 deletions apps/rxjs/src/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* You can add global styles to this file, and also import other style files */
8 changes: 8 additions & 0 deletions apps/rxjs/src/test-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// @ts-expect-error https://thymikee.github.io/jest-preset-angular/docs/getting-started/test-environment
globalThis.ngJest = {
testEnvironmentOptions: {
errorOnUnknownElements: true,
errorOnUnknownProperties: true,
},
};
import 'jest-preset-angular/setup-jest';
10 changes: 10 additions & 0 deletions apps/rxjs/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"types": []
},
"files": ["src/main.ts"],
"include": ["src/**/*.d.ts"],
"exclude": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts"]
}
6 changes: 6 additions & 0 deletions apps/rxjs/tsconfig.editor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "./tsconfig.json",
"include": ["src/**/*.ts"],
"compilerOptions": {},
"exclude": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts"]
}
33 changes: 33 additions & 0 deletions apps/rxjs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"compilerOptions": {
"target": "es2022",
"useDefineForClassFields": false,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.editor.json"
},
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.spec.json"
}
],
"extends": "../../tsconfig.base.json",
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false,
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true
}
}
16 changes: 16 additions & 0 deletions apps/rxjs/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"target": "es2016",
"types": ["jest", "node"]
},
"files": ["src/test-setup.ts"],
"include": [
"jest.config.ts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.d.ts"
]
}

0 comments on commit f6673f3

Please sign in to comment.