diff --git a/apps/performance/35-memoization/src/app/app.component.ts b/apps/performance/35-memoization/src/app/app.component.ts index 04c7758fc..44e55db4f 100644 --- a/apps/performance/35-memoization/src/app/app.component.ts +++ b/apps/performance/35-memoization/src/app/app.component.ts @@ -1,10 +1,9 @@ -import { NgIf } from '@angular/common'; import { Component } from '@angular/core'; import { generateList } from './generateList'; import { PersonListComponent } from './person-list.component'; @Component({ - imports: [PersonListComponent, NgIf], + imports: [PersonListComponent], selector: 'app-root', template: `

Performance is key!!

@@ -14,11 +13,9 @@ import { PersonListComponent } from './person-list.component'; Load List - + @if (loadList) { + + } `, }) export class AppComponent { diff --git a/apps/performance/35-memoization/src/app/app.config.ts b/apps/performance/35-memoization/src/app/app.config.ts index 59198e627..81a6edde4 100644 --- a/apps/performance/35-memoization/src/app/app.config.ts +++ b/apps/performance/35-memoization/src/app/app.config.ts @@ -1,6 +1,5 @@ import { ApplicationConfig } from '@angular/core'; -import { provideAnimations } from '@angular/platform-browser/animations'; export const appConfig: ApplicationConfig = { - providers: [provideAnimations()], + providers: [], }; diff --git a/apps/performance/35-memoization/src/app/fibonacci.pipe.ts b/apps/performance/35-memoization/src/app/fibonacci.pipe.ts new file mode 100644 index 000000000..f53021126 --- /dev/null +++ b/apps/performance/35-memoization/src/app/fibonacci.pipe.ts @@ -0,0 +1,17 @@ +import { Pipe, PipeTransform } from '@angular/core'; + +@Pipe({ + name: 'fibonacci', +}) +export class FibonacciPipe implements PipeTransform { + transform(num: number): number { + return fibonacci(num); + } +} + +const fibonacci = (num: number): number => { + if (num === 1 || num === 2) { + return 1; + } + return fibonacci(num - 1) + fibonacci(num - 2); +}; diff --git a/apps/performance/35-memoization/src/app/person-list.component.ts b/apps/performance/35-memoization/src/app/person-list.component.ts index 28cbac267..820f525b2 100644 --- a/apps/performance/35-memoization/src/app/person-list.component.ts +++ b/apps/performance/35-memoization/src/app/person-list.component.ts @@ -1,29 +1,24 @@ import { Component, Input } from '@angular/core'; -import { CommonModule } from '@angular/common'; +import { TitleCasePipe } from '@angular/common'; import { FormsModule } from '@angular/forms'; import { MatChipsModule } from '@angular/material/chips'; import { MatFormFieldModule } from '@angular/material/form-field'; import { MatInputModule } from '@angular/material/input'; import { MatListModule } from '@angular/material/list'; +import { FibonacciPipe } from './fibonacci.pipe'; import { Person } from './person.model'; -const fibonacci = (num: number): number => { - if (num === 1 || num === 2) { - return 1; - } - return fibonacci(num - 1) + fibonacci(num - 2); -}; - @Component({ selector: 'app-person-list', imports: [ - CommonModule, + TitleCasePipe, FormsModule, MatListModule, MatFormFieldModule, MatInputModule, MatChipsModule, + FibonacciPipe, ], template: `

@@ -39,12 +34,14 @@ const fibonacci = (num: number): number => { - -
-

{{ person.name }}

- {{ calculate(person.fib) }} -
-
+ @for (person of persons; track $index) { + +
+

{{ person.name }}

+ {{ person.fib | fibonacci }} +
+
+ }
`, host: { @@ -56,8 +53,4 @@ export class PersonListComponent { @Input() title = ''; label = ''; - - calculate(num: number) { - return fibonacci(num); - } }