Fix ll-rebuild only keeps the card that should be deleted (#2481)

* Fix ll-rebuild only keeps the card that should be deleted

* Do the same thing for stack cards. (Untested. Leeeeroyyyyy Jenkins)

* Copy then replace instead of mutating

* Use map
This commit is contained in:
Thomas Lovén 2019-01-15 18:30:33 +01:00 committed by Paulus Schoutsen
parent f943366ecd
commit 0ddc82601a
2 changed files with 11 additions and 11 deletions

View File

@ -75,15 +75,13 @@ export abstract class HuiStackCard extends LitElement implements LovelaceCard {
} }
private _rebuildCard( private _rebuildCard(
element: LovelaceCard, cardElToReplace: LovelaceCard,
config: LovelaceCardConfig config: LovelaceCardConfig
): void { ): void {
const newCard = this._createCardElement(config); const newCardEl = this._createCardElement(config);
element.replaceWith(newCard); cardElToReplace.parentElement!.replaceChild(newCardEl, cardElToReplace);
this._cards = this._cards!.splice( this._cards = this._cards!.map((curCardEl) =>
this._cards!.indexOf(element), curCardEl === cardElToReplace ? newCardEl : curCardEl
1,
newCard
); );
} }
} }

View File

@ -306,12 +306,14 @@ export class HUIView extends hassLocalizeLitMixin(LitElement) {
} }
private _rebuildCard( private _rebuildCard(
element: LovelaceCard, cardElToReplace: LovelaceCard,
config: LovelaceCardConfig config: LovelaceCardConfig
): void { ): void {
const newCard = this._createCardElement(config); const newCardEl = this._createCardElement(config);
element.parentElement!.replaceChild(newCard, element); cardElToReplace.parentElement!.replaceChild(newCardEl, cardElToReplace);
this._cards = this._cards.splice(this._cards.indexOf(element), 1, newCard); this._cards = this._cards!.map((curCardEl) =>
curCardEl === cardElToReplace ? newCardEl : curCardEl
);
} }
} }