diff --git a/examples/basket/basketStorage.js b/examples/basket/basketStorage.js index d6a44fe..600cafd 100644 --- a/examples/basket/basketStorage.js +++ b/examples/basket/basketStorage.js @@ -19,6 +19,11 @@ export class BasketStorage extends EventTarget { getItems() { return this.items } + removeItem(item) { + this.items = this.items.filter(i => i != item) + console.log("this.items: ", this.items); + this.dispatchEvent(new CustomEvent("updated", { detail: { item } })) + } } const basketStorage = BasketStorage.getInstance(); diff --git a/examples/basket/main.js b/examples/basket/main.js index 25f7104..213bb8d 100644 --- a/examples/basket/main.js +++ b/examples/basket/main.js @@ -15,6 +15,7 @@ export class Basket extends LitElement { connectedCallback() { super.connectedCallback(); basketStorage.addEventListener("updated", (i) => { + console.log("Updated"); this.items = basketStorage.getItems() }) } @@ -30,6 +31,10 @@ export class Basket extends LitElement { searchNode.value = "" } + remove(i) { + basketStorage.removeItem(i) + } + render() { return html`
@@ -39,7 +44,7 @@ export class Basket extends LitElement {
${this.items ? html`${this.items.map(i => { - return html`
${i}
` + return html`
${i}
` })}` : html`

No items

`}