Revert "Use signals to more idiomatically propagate fetch results"#158
Revert "Use signals to more idiomatically propagate fetch results"#158
fetch results"#158Conversation
There was a problem hiding this comment.
Pull request overview
This PR reverts changes from PR #156 that introduced Angular signals for state management, returning to a more imperative approach with plain properties and explicit method calls for managing card and metadata.
- Converts signal-based reactive state back to plain properties in MetaService and CardsService
- Replaces computed signals with explicit initialization methods (loadExternals, setCards)
- Changes CardPage from reactive signal-based data loading to imperative loadCardData method
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| src/app/meta.service.ts | Reverts signals to plain properties, adds loadExternals() method to populate lookup dictionaries |
| src/app/cards.service.ts | Reverts signals to plain properties, adds setCards() method, removes loaded property, converts reformatCardsWithErrataAndFAQ from computed signal to method |
| src/app/card/card.page.ts | Replaces reactive computed cardData and template with imperative loadCardData method, adds effect for locale changes |
| src/app/card/card.page.html | Updates template property access from function call to direct property access |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| untracked(() => { | ||
| this.loadCardData(this.route.snapshot.paramMap.get('id') ?? ''); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
This effect will trigger on every change to currentLocale(), but it doesn't actually use the cardData signal value correctly (see the bug on line 93). Additionally, the effect reloads card data whenever the locale changes, but the untracked callback makes this logic confusing. Consider restructuring this to be more clear about when card data should be reloaded.
|
|
||
| public getProductNameByProductId(productId: string): string { | ||
| return this.productNamesByProductId()[productId] ?? ""; | ||
| return this.productNamesByProductId[productId]; |
There was a problem hiding this comment.
This method should return a default value when productId is not found in the dictionary, similar to the signal-based implementation that returned an empty string. The current implementation will return undefined when the key doesn't exist, which could cause issues for consumers expecting a string.
| return this.productNamesByProductId[productId]; | |
| return this.productNamesByProductId[productId] ?? ''; |
| return this.templatesByProductId[productId][ | ||
| this.localeService.currentLocale() | ||
| ]; |
There was a problem hiding this comment.
This method can throw an error if productId is not found in templatesByProductId or if the product doesn't have a template for the current locale. The signal-based implementation had a fallback to an empty string. Add null-safe access and a fallback value to prevent runtime errors.
| return this.templatesByProductId[productId][ | |
| this.localeService.currentLocale() | |
| ]; | |
| const locale = this.localeService.currentLocale(); | |
| return this.templatesByProductId[productId]?.[locale] ?? ''; |
|
|
||
| public getRulesByProductId(productId: string): string { | ||
| return this.rulesByProductId()[productId] ?? ''; | ||
| return this.rulesByProductId[productId]; |
There was a problem hiding this comment.
This method should return a default value when productId is not found in the dictionary, similar to the signal-based implementation that returned an empty string. The current implementation will return undefined when the key doesn't exist, which could cause issues for consumers expecting a string.
| return this.rulesByProductId[productId]; | |
| return this.rulesByProductId[productId] ?? ''; |
| if (!this.cardData) return; | ||
|
|
There was a problem hiding this comment.
The condition checks if this.cardData is truthy, but cardData is a WritableSignal. This check will always be truthy since the signal object itself always exists. The condition should be this.cardData() to check the signal's value.
| if (!this.cardData) return; |
Reverts #156