style(blackjack): format code for better readability
This commit is contained in:
parent
acdbea5a99
commit
deac128935
9 changed files with 139 additions and 121 deletions
|
@ -35,30 +35,30 @@ import { Card } from '../../models/blackjack.model';
|
|||
export class DealerHandComponent implements OnChanges {
|
||||
@Input() cards: Card[] = [];
|
||||
cardsWithState: (Card & { isNew: boolean; id: string })[] = [];
|
||||
|
||||
|
||||
private lastCardCount = 0;
|
||||
|
||||
|
||||
ngOnChanges(changes: SimpleChanges): void {
|
||||
if (changes['cards']) {
|
||||
this.updateCardsWithState();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private updateCardsWithState(): void {
|
||||
const newCards = this.cards.length > this.lastCardCount;
|
||||
|
||||
|
||||
this.cardsWithState = this.cards.map((card, index) => {
|
||||
// Consider a card new if it's added after the initial state and is the latest card
|
||||
const isNew = newCards && index >= this.lastCardCount;
|
||||
|
||||
|
||||
return {
|
||||
...card,
|
||||
isNew,
|
||||
// Generate a unique ID to help Angular track the cards
|
||||
id: `${card.suit}-${card.rank}-${index}`
|
||||
id: `${card.suit}-${card.rank}-${index}`,
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
this.lastCardCount = this.cards.length;
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue