Skip to content

Commit c59e8be

Browse files
committed
fix: 50 - signal-bug-in-effect
1 parent 805b53b commit c59e8be

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

apps/signal/50-bug-in-effect/src/app/app.component.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,25 @@ export class AppComponent {
4040
gpu = model(false);
4141

4242
constructor() {
43-
/*
44-
Explain for your junior team mate why this bug occurs ...
43+
/*
44+
It occurs because of the place of each signal triggered in the OR condition : the order of the trigger in the condition matter.
45+
If the triggered one is after the one who is already set as true, it will not trigger the alert because, for the condition value didn't change.
46+
Else if the triggered one is before the one who is already set as true, it will trigger the alert.
47+
We must separate the condition into three effect, a condition for each effect.
48+
49+
Want to understand the way to do it with the computed solution. Any clue ?
4550
*/
51+
52+
effect(() => {
53+
this.drive() ? alert('Price increased') : undefined;
54+
});
55+
56+
effect(() => {
57+
this.ram() ? alert('Price increased') : undefined;
58+
});
59+
4660
effect(() => {
47-
if (this.drive() || this.ram() || this.gpu()) {
48-
alert('Price increased!');
49-
}
61+
this.gpu() ? alert('Price increased') : undefined;
5062
});
5163
}
5264
}

0 commit comments

Comments
 (0)