File tree Expand file tree Collapse file tree 2 files changed +75
-3
lines changed
Expand file tree Collapse file tree 2 files changed +75
-3
lines changed Original file line number Diff line number Diff line change @@ -41,7 +41,9 @@ pnpm cook checkout-impl
4141>
4242> ``` ts
4343> @Component ({
44- > template: ` {{ recipes }} ` ,
44+ > template: ` @for (recipe of recipes; track recipe.id) {
45+ > ...
46+ > } ` ,
4547> })
4648> class RecipeSearch {
4749> ngOnInit() {
@@ -54,10 +56,12 @@ pnpm cook checkout-impl
5456>
5557> ` ` ` ts
5658> @Component ({
57- > template: ` {{ recipes$ | async }} ` ,
59+ > template: ` @for (recipe of recipes$ | async; track recipe.id) {
60+ > ...
61+ > } ` ,
5862> })
5963> class RecipeSearch {
60- > recipes$ = this . _repo .search ();
64+ > recipes$ = inject ( RecipeRepository ) .search ();
6165> }
6266> ` ` `
6367
Original file line number Diff line number Diff line change 1+ ---
2+ sidebar_label : 305. Recipe Search Signals
3+ ---
4+
5+ # Recipe Search Signals
6+
7+ ## Setup
8+
9+ ``` sh
10+ pnpm cook start 305-recipe-search-signals
11+ ```
12+
13+ :::info ♻️ TDD option
14+
15+ You can choose to:
16+
17+ - go full-on TDD and implement the tests first then checkout the implementation later,
18+ - or checkout the implementation first and then implement the tests.
19+
20+ :::
21+
22+ ## 🎯 Goal: Use signals and fix tests
23+
24+ Let's go reactive with signals and see what happens.
25+
26+ ### 📝 Steps
27+
28+ #### 1. Run tests:
29+
30+ ``` sh
31+ pnpm test
32+ ```
33+
34+ #### 2. Checkout new ` RecipeSearch ` implementation.
35+
36+ ``` sh
37+ pnpm cook checkout-impl
38+ ```
39+
40+ > This will replace the RxJS reactive approach:
41+ >
42+ > ``` ts
43+ > @Component ({
44+ > template: ` @for (recipe of recipes$ | async; track recipe.id) {
45+ > ...
46+ > } ` ,
47+ > })
48+ > class RecipeSearch {
49+ > recipes$ = inject (RecipeRepository ).search ();
50+ > }
51+ > ` ` `
52+ >
53+ > with a signal-based reactive approach:
54+ >
55+ > ` ` ` ts
56+ > @Component ({
57+ > template: ` @for (recipe of recipes(); track recipe.id) {
58+ > ...
59+ > } ` ,
60+ > })
61+ > class RecipeSearch {
62+ > recipes$ = this ._repo .search ();
63+ > }
64+ > ` ` `
65+
66+ #### 3. 👀 See which tests broke.
67+
68+ #### 4. Fix tests.
You can’t perform that action at this time.
0 commit comments