From 452fcfffae8579752175e92e1eb60a2c2ce0c7f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=80=20?= =?UTF-8?q?=D0=A1=D0=BE=D0=BA=D0=BE=D0=BB=D0=BE=D0=B2?= Date: Mon, 16 Jun 2025 01:04:04 +0300 Subject: [PATCH] feat(challenge 8): pure pipe - my solution --- apps/angular/8-pure-pipe/src/app/app.component.ts | 9 +++------ .../8-pure-pipe/src/app/heavy-computation.pipe.ts | 11 +++++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 apps/angular/8-pure-pipe/src/app/heavy-computation.pipe.ts diff --git a/apps/angular/8-pure-pipe/src/app/app.component.ts b/apps/angular/8-pure-pipe/src/app/app.component.ts index 930fe1313..42b4f7d09 100644 --- a/apps/angular/8-pure-pipe/src/app/app.component.ts +++ b/apps/angular/8-pure-pipe/src/app/app.component.ts @@ -1,18 +1,15 @@ import { Component } from '@angular/core'; +import { HeavyComputationPipe } from './heavy-computation.pipe'; @Component({ selector: 'app-root', template: ` @for (person of persons; track person) { - {{ heavyComputation(person, $index) }} + {{ person | heavyComputation: $index }} } `, + imports: [HeavyComputationPipe], }) export class AppComponent { persons = ['toto', 'jack']; - - heavyComputation(name: string, index: number) { - // very heavy computation - return `${name} - ${index}`; - } } diff --git a/apps/angular/8-pure-pipe/src/app/heavy-computation.pipe.ts b/apps/angular/8-pure-pipe/src/app/heavy-computation.pipe.ts new file mode 100644 index 000000000..ed6cc7e09 --- /dev/null +++ b/apps/angular/8-pure-pipe/src/app/heavy-computation.pipe.ts @@ -0,0 +1,11 @@ +import { Pipe, PipeTransform } from '@angular/core'; + +@Pipe({ + name: 'heavyComputation', +}) +export class HeavyComputationPipe implements PipeTransform { + transform(name: string, index: number): string { + // very heavy computation + return `${name} - ${index}`; + } +}