File tree Expand file tree Collapse file tree
apps/signal/50-bug-in-effect/src/app Expand file tree Collapse file tree Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments