Skip to content

Commit 60c9964

Browse files
authored
feat(c50): update challenge example (tomalaforge#868)
* feat(c50): update challenge example * feat(c50): add challenge image * feat(c50): update docs * feat(c50): update docs content
1 parent 008051c commit 60c9964

File tree

3 files changed

+51
-16
lines changed

3 files changed

+51
-16
lines changed

apps/angular/bug-effect-signal/src/app/app.component.ts

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,42 @@ import { FormsModule } from '@angular/forms';
1111
imports: [FormsModule],
1212
selector: 'app-root',
1313
template: `
14-
Show Dialog if one checkbox is checked
15-
<input type="checkbox" [(ngModel)]="name" />
16-
Name
17-
<input type="checkbox" [(ngModel)]="age" />
18-
Age
19-
<input type="checkbox" [(ngModel)]="address" />
20-
Address
14+
<section class="flex gap-5">
15+
<p>MacBook</p>
16+
<p>1999,99 €</p>
17+
</section>
18+
19+
<section>
20+
<p>Extras:</p>
21+
22+
<div>
23+
<input type="checkbox" [(ngModel)]="drive" />
24+
+500 GB drive-space
25+
</div>
26+
<div>
27+
<input type="checkbox" [(ngModel)]="ram" />
28+
+4 GB RAM
29+
</div>
30+
<div>
31+
<input type="checkbox" [(ngModel)]="gpu" />
32+
Better GPU
33+
</div>
34+
</section>
2135
`,
2236
changeDetection: ChangeDetectionStrategy.OnPush,
2337
})
2438
export class AppComponent {
25-
name = model(false);
26-
age = model(false);
27-
address = model(false);
39+
drive = model(false);
40+
ram = model(false);
41+
gpu = model(false);
2842

2943
constructor() {
44+
/*
45+
Explain for your junior team mate why this bug occurs ...
46+
*/
3047
effect(() => {
31-
if (this.name() || this.age() || this.address()) {
32-
alert('Checkbox was checked');
48+
if (this.drive() || this.ram() || this.gpu()) {
49+
alert('Price increased!');
3350
}
3451
});
3552
}

apps/angular/bug-effect-signal/src/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
<link rel="icon" type="image/x-icon" href="favicon.ico" />
99
</head>
1010
<body>
11-
<app-root></app-root>
11+
<app-root class="flex flex-col gap-5 p-10"></app-root>
1212
</body>
1313
</html>

docs/src/content/docs/challenges/angular/50-bug-effect-signal.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ description: Challenge 50 is about understanding why an effect is not triggered.
44
author: thomas-laforge
55
contributors:
66
- tomalaforge
7+
- svenson95
78
challengeNumber: 50
89
command: angular-bug-effect-signal
910
sidebar:
@@ -13,10 +14,27 @@ sidebar:
1314

1415
## Information
1516

16-
In this basic exercise, we aim to display an alert whenever at least one checkbox is checked.
17+
In this basic exercise, we aim to display an alert whenever at least one checkbox is checked. You are in the process of buying a MacBook, which can be upgraded with some extras, like more drive space, more RAM or a better GPU.
18+
19+
<img width="889" alt="Bildschirmfoto 2024-05-09 um 08 57 57" src="https://github.com/svenson95/angular-challenges/assets/46655156/d78f42a5-9064-4a33-bb8c-c0433bd6966d">
1720

1821
## Statement
1922

20-
The alert correctly triggers when clicking on each checkbox separately. However, if you first click on one checkbox and then click on a second one, the alert fails to appear. Why does this happen?
23+
The actual implementation doesn't work as expected, your task is to fix the issue. Your team exposed a bug, there is a alert to be shown if atleast one of the three checkboxes is checked. But if the first one is checked, the other two checkboxes gets checked without displaying the alert. Why does this happen?
24+
25+
The objective of this challenge is to understand the issue and fix the problem, preventing the alert from appearing when the second checkbox is clicked.
26+
27+
## Acceptance Criteria
28+
29+
To ensure this feature works properly, try this out to reproduce the bug after solving the challenge, to check if the bug is gone.
30+
31+
- Check box 1 (Alert should be shown)
32+
- Check box 2 (Alert should be shown)
33+
- Uncheck box 1
34+
- Check box 3 (Alert should be shown)
35+
- Uncheck box 2
36+
- Uncheck box 3
37+
38+
## Bonus Challenge
2139

22-
The objective of this challenge is to understand and correct the issue preventing the alert from appearing when the second checkbox is clicked.
40+
- Try to implement this feature with a `computed` signal.

0 commit comments

Comments
 (0)