Skip to content

Commit ada7966

Browse files
committed
feat(challenge 8): implement heavy computation pipe for optimized rendering
1 parent 543770b commit ada7966

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1-
import { Component } from '@angular/core';
1+
import { Component, Pipe, PipeTransform } from '@angular/core';
2+
3+
@Pipe({
4+
name: 'heavyComputation',
5+
})
6+
export class HeavyComputationPipe implements PipeTransform {
7+
transform(name: string, index: number) {
8+
// very heavy computation
9+
return `${name} - ${index}`;
10+
}
11+
}
212

313
@Component({
414
selector: 'app-root',
15+
imports: [HeavyComputationPipe],
516
template: `
617
@for (person of persons; track person) {
7-
{{ heavyComputation(person, $index) }}
18+
{{ person | heavyComputation: $index }}
819
}
920
`,
1021
})
1122
export class AppComponent {
1223
persons = ['toto', 'jack'];
13-
14-
heavyComputation(name: string, index: number) {
15-
// very heavy computation
16-
return `${name} - ${index}`;
17-
}
1824
}

0 commit comments

Comments
 (0)