Skip to content

Commit

Permalink
Use EventTarget for some reason.
Browse files Browse the repository at this point in the history
  • Loading branch information
thesoftwarephilosopher committed Aug 17, 2024
1 parent c96af62 commit 4729207
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions site/samples/sample5.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,22 @@ function TodoList() {
</div>;
}

class List {
class List extends EventTarget {

ul = <ul class='list' /> as HTMLUListElement;
#items: Item[] = [];

onchange?: () => void;

add(text: string) {
const item = new Item(this, text);
this.#items.push(item);
this.ul.append(item.li);
this.onchange?.();
this.dispatchEvent(new Event('change'));
return item;
}

rem(item: Item) {
this.#items = this.#items.filter(it => it !== item);
this.onchange?.();
this.dispatchEvent(new Event('change'));
}

clearDone() {
Expand All @@ -61,7 +59,7 @@ class List {
}

itemChanged() {
this.onchange?.();
this.dispatchEvent(new Event('change'));
}

}
Expand Down Expand Up @@ -105,7 +103,7 @@ function Counter({ list }: { list: List }) {
};

updateText();
list.onchange = updateText;
list.addEventListener('change', updateText);

return span;
}
Expand Down

0 comments on commit 4729207

Please sign in to comment.