diff --git a/apps/signal/43-signal-input/src/app/user.component.ts b/apps/signal/43-signal-input/src/app/user.component.ts index 908f952c3..c3035e3c9 100644 --- a/apps/signal/43-signal-input/src/app/user.component.ts +++ b/apps/signal/43-signal-input/src/app/user.component.ts @@ -2,8 +2,9 @@ import { TitleCasePipe } from '@angular/common'; import { ChangeDetectionStrategy, Component, - Input, - OnChanges, + computed, + effect, + input, } from '@angular/core'; type Category = 'Youth' | 'Junior' | 'Open' | 'Senior'; @@ -18,23 +19,26 @@ const ageToCategory = (age: number): Category => { selector: 'app-user', imports: [TitleCasePipe], template: ` - {{ fullName | titlecase }} plays tennis in the {{ category }} category!! + {{ fullName() | titlecase }} plays tennis in the {{ category() }} category!! `, host: { class: 'text-xl text-green-800', }, changeDetection: ChangeDetectionStrategy.OnPush, }) -export class UserComponent implements OnChanges { - @Input({ required: true }) name!: string; - @Input() lastName?: string; - @Input() age?: string; +export class UserComponent { + name = input.required(); + lastName = input(); + age = input({ + transform: (value: string | null | undefined) => Number(value) || 0, + }); - fullName = ''; - category: Category = 'Junior'; + fullName = computed(() => `${this.name()} ${this.lastName() ?? '_'} `); + category = computed(() => ageToCategory(Number(this.age() ?? 0))); - ngOnChanges(): void { - this.fullName = `${this.name} ${this.lastName ?? ''}`; - this.category = ageToCategory(Number(this.age) ?? 0); + constructor() { + effect(() => { + console.log('updated'); + }); } } diff --git a/package-lock.json b/package-lock.json index 3b3a587ce..e527afd06 100644 --- a/package-lock.json +++ b/package-lock.json @@ -78,7 +78,7 @@ "@typescript-eslint/utils": "^7.16.0", "all-contributors-cli": "^6.26.1", "autoprefixer": "^10.4.0", - "cypress": "^14.0.0", + "cypress": "^13.17.0", "eslint": "8.57.0", "eslint-config-prettier": "9.0.0", "eslint-plugin-cypress": "2.15.1", @@ -13821,12 +13821,11 @@ "license": "MIT" }, "node_modules/cypress": { - "version": "14.0.0", - "resolved": "https://registry.npmjs.org/cypress/-/cypress-14.0.0.tgz", - "integrity": "sha512-kEGqQr23so5IpKeg/dp6GVi7RlHx1NmW66o2a2Q4wk9gRaAblLZQSiZJuDI8UMC4LlG5OJ7Q6joAiqTrfRNbTw==", + "version": "13.17.0", + "resolved": "https://registry.npmjs.org/cypress/-/cypress-13.17.0.tgz", + "integrity": "sha512-5xWkaPurwkIljojFidhw8lFScyxhtiFHl/i/3zov+1Z5CmY4t9tjIdvSXfu82Y3w7wt0uR9KkucbhkVvJZLQSA==", "dev": true, "hasInstallScript": true, - "license": "MIT", "dependencies": { "@cypress/request": "^3.0.6", "@cypress/xvfb": "^1.2.4", @@ -13876,7 +13875,7 @@ "cypress": "bin/cypress" }, "engines": { - "node": "^18.0.0 || ^20.0.0 || >=22.0.0" + "node": "^16.0.0 || ^18.0.0 || >=20.0.0" } }, "node_modules/cypress/node_modules/arch": { diff --git a/package.json b/package.json index 63dbb87e5..d816c80fe 100644 --- a/package.json +++ b/package.json @@ -81,7 +81,7 @@ "@typescript-eslint/utils": "^7.16.0", "all-contributors-cli": "^6.26.1", "autoprefixer": "^10.4.0", - "cypress": "14.0.0", + "cypress": "^13.17.0", "eslint": "8.57.0", "eslint-config-prettier": "9.0.0", "eslint-plugin-cypress": "2.15.1",