diff --git a/apps/signal/53-big-signal-performance/src/app/address.component.ts b/apps/signal/53-big-signal-performance/src/app/address.component.ts
index f894d697e..f24c491e3 100644
--- a/apps/signal/53-big-signal-performance/src/app/address.component.ts
+++ b/apps/signal/53-big-signal-performance/src/app/address.component.ts
@@ -7,9 +7,9 @@ import { UserStore } from './user.service';
template: `
Address:
-
Street: {{ userService.user().address.street }}
-
ZipCode: {{ userService.user().address.zipCode }}
-
City: {{ userService.user().address.city }}
+
Street: {{ userService.street() }}
+
ZipCode: {{ userService.zipCode() }}
+
City: {{ userService.city() }}
`,
changeDetection: ChangeDetectionStrategy.OnPush,
diff --git a/apps/signal/53-big-signal-performance/src/app/app.component.ts b/apps/signal/53-big-signal-performance/src/app/app.component.ts
index bf15a5dc2..8959b1e27 100644
--- a/apps/signal/53-big-signal-performance/src/app/app.component.ts
+++ b/apps/signal/53-big-signal-performance/src/app/app.component.ts
@@ -1,4 +1,4 @@
-import { Component } from '@angular/core';
+import { ChangeDetectionStrategy, Component } from '@angular/core';
import { AddressComponent } from './address.component';
import { JobComponent } from './job.component';
import { NameComponent } from './name.component';
@@ -22,5 +22,6 @@ import { UserFormComponent } from './user-form.component';
NoteComponent,
UserFormComponent,
],
+ changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AppComponent {}
diff --git a/apps/signal/53-big-signal-performance/src/app/job.component.ts b/apps/signal/53-big-signal-performance/src/app/job.component.ts
index d3186fc9f..91aba9558 100644
--- a/apps/signal/53-big-signal-performance/src/app/job.component.ts
+++ b/apps/signal/53-big-signal-performance/src/app/job.component.ts
@@ -7,8 +7,8 @@ import { UserStore } from './user.service';
template: `
Job:
-
title: {{ userService.user().title }}
-
salary: {{ userService.user().salary }}
+
title: {{ userService.title() }}
+
salary: {{ userService.salary() }}
`,
changeDetection: ChangeDetectionStrategy.OnPush,
diff --git a/apps/signal/53-big-signal-performance/src/app/name.component.ts b/apps/signal/53-big-signal-performance/src/app/name.component.ts
index f93b5675a..e85e67d48 100644
--- a/apps/signal/53-big-signal-performance/src/app/name.component.ts
+++ b/apps/signal/53-big-signal-performance/src/app/name.component.ts
@@ -6,7 +6,7 @@ import { UserStore } from './user.service';
selector: 'name',
template: `
- Name: {{ userService.user().name }}
+ Name: {{ userService.name() }}
`,
changeDetection: ChangeDetectionStrategy.OnPush,
diff --git a/apps/signal/53-big-signal-performance/src/app/note.component.ts b/apps/signal/53-big-signal-performance/src/app/note.component.ts
index dd0033962..7927ab736 100644
--- a/apps/signal/53-big-signal-performance/src/app/note.component.ts
+++ b/apps/signal/53-big-signal-performance/src/app/note.component.ts
@@ -6,7 +6,7 @@ import { UserStore } from './user.service';
selector: 'note',
template: `
- Note: {{ userService.user().note }}
+ Note: {{ userService.note() }}
`,
changeDetection: ChangeDetectionStrategy.OnPush,
diff --git a/apps/signal/53-big-signal-performance/src/app/user-form.component.ts b/apps/signal/53-big-signal-performance/src/app/user-form.component.ts
index d0f2164ce..ccd542bfe 100644
--- a/apps/signal/53-big-signal-performance/src/app/user-form.component.ts
+++ b/apps/signal/53-big-signal-performance/src/app/user-form.component.ts
@@ -64,36 +64,30 @@ export class UserFormComponent {
userStore = inject(UserStore);
form = new FormGroup({
- name: new FormControl(this.userStore.user().name, { nonNullable: true }),
- street: new FormControl(this.userStore.user().address.street, {
+ name: new FormControl(this.userStore.name(), { nonNullable: true }),
+ street: new FormControl(this.userStore.street(), {
nonNullable: true,
}),
- zipCode: new FormControl(this.userStore.user().address.zipCode, {
+ zipCode: new FormControl(this.userStore.zipCode(), {
nonNullable: true,
}),
- city: new FormControl(this.userStore.user().address.city, {
+ city: new FormControl(this.userStore.city(), {
nonNullable: true,
}),
- note: new FormControl(this.userStore.user().note, { nonNullable: true }),
- title: new FormControl(this.userStore.user().title, { nonNullable: true }),
- salary: new FormControl(this.userStore.user().salary, {
+ note: new FormControl(this.userStore.note(), { nonNullable: true }),
+ title: new FormControl(this.userStore.title(), { nonNullable: true }),
+ salary: new FormControl(this.userStore.salary(), {
nonNullable: true,
}),
});
submit() {
- this.userStore.user.update((u) => ({
- ...u,
- name: this.form.getRawValue().name,
- address: {
- ...u.address,
- street: this.form.getRawValue().street,
- zipCode: this.form.getRawValue().zipCode,
- city: this.form.getRawValue().city,
- },
- note: this.form.getRawValue().note,
- title: this.form.getRawValue().title,
- salary: this.form.getRawValue().salary,
- }));
+ this.userStore.name.set(this.form.value.name ?? '-');
+ this.userStore.title.set(this.form.value.title ?? '_');
+ this.userStore.note.set(this.form.value.note ?? '_');
+ this.userStore.salary.set(this.form.value.salary ?? 0);
+ this.userStore.street.set(this.form.value.street ?? '_');
+ this.userStore.zipCode.set(this.form.value.zipCode ?? '_');
+ this.userStore.city.set(this.form.value.city ?? '_');
}
}
diff --git a/apps/signal/53-big-signal-performance/src/app/user.service.ts b/apps/signal/53-big-signal-performance/src/app/user.service.ts
index 4b3b7c512..53d37f52a 100644
--- a/apps/signal/53-big-signal-performance/src/app/user.service.ts
+++ b/apps/signal/53-big-signal-performance/src/app/user.service.ts
@@ -2,15 +2,11 @@ import { Injectable, signal } from '@angular/core';
@Injectable({ providedIn: 'root' })
export class UserStore {
- user = signal({
- name: 'Bob',
- address: {
- street: '',
- zipCode: '',
- city: '',
- },
- note: '',
- title: '',
- salary: 0,
- });
+ name = signal('Bob');
+ street = signal('');
+ zipCode = signal('');
+ city = signal('');
+ note = signal('');
+ title = signal('');
+ salary = signal(0);
}