@w-lfpup/wctk 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/.github/workflows/browsers.macos.json +51 -0
  2. package/.github/workflows/browsers.ubuntu.json +37 -0
  3. package/.github/workflows/builds.yml +27 -0
  4. package/README.md +37 -12
  5. package/dist/events.d.ts +19 -10
  6. package/dist/events.js +8 -19
  7. package/dist/microtask.d.ts +4 -6
  8. package/dist/microtask.js +3 -8
  9. package/dist/mod.d.ts +0 -2
  10. package/dist/mod.js +0 -2
  11. package/dist/query_selector.d.ts +2 -5
  12. package/dist/query_selector.js +16 -14
  13. package/dist/subscription.d.ts +0 -1
  14. package/dist/subscription.js +6 -14
  15. package/dist/wc.d.ts +4 -4
  16. package/dist/wc.js +9 -9
  17. package/docs/events.md +16 -18
  18. package/docs/microtask.md +2 -5
  19. package/docs/query_selector.md +1 -3
  20. package/docs/wc.md +2 -4
  21. package/examples/counter/mod.js +13 -15
  22. package/examples/counter/mod.ts +20 -19
  23. package/examples/form_associated/mod.js +1 -3
  24. package/examples/form_associated/mod.ts +0 -1
  25. package/examples/form_associated/text_input.js +3 -6
  26. package/examples/form_associated/text_input.ts +7 -5
  27. package/examples/stopwatch/index.html +6 -3
  28. package/examples/stopwatch/mod.js +8 -3
  29. package/examples/stopwatch/mod.ts +6 -4
  30. package/examples/stopwatch/stopwatch.js +30 -27
  31. package/examples/stopwatch/stopwatch.ts +44 -35
  32. package/examples/tsconfig.json +1 -0
  33. package/jr.json +25 -0
  34. package/package.json +10 -6
  35. package/src/events.ts +35 -34
  36. package/src/microtask.ts +6 -17
  37. package/src/mod.ts +0 -2
  38. package/src/query_selector.ts +18 -27
  39. package/src/wc.ts +13 -12
  40. package/tests/dist/events.tests.js +60 -0
  41. package/tests/dist/microtask.tests.js +38 -0
  42. package/tests/dist/mod.js +10 -0
  43. package/tests/dist/query_selector.tests.js +43 -0
  44. package/tests/dist/wc.tests.js +41 -0
  45. package/tests/src/events.tests.ts +73 -0
  46. package/tests/src/microtask.tests.ts +54 -0
  47. package/tests/src/mod.ts +11 -0
  48. package/tests/src/query_selector.tests.ts +46 -0
  49. package/tests/src/wc.tests.ts +52 -0
  50. package/tests/tsconfig.json +8 -0
  51. package/.github/workflows/build_and_test.yml +0 -18
  52. package/dist/bind.d.ts +0 -7
  53. package/dist/bind.js +0 -14
  54. package/docs/bind.md +0 -26
  55. package/docs/subscription.md +0 -85
  56. package/src/bind.ts +0 -22
  57. package/src/subscription.ts +0 -47
@@ -1,39 +1,37 @@
1
1
  import { Wc, Events } from "wctk";
2
- /*
3
- Custom Element with state and interactivity.
4
- */
5
2
  class Counter extends HTMLElement {
6
3
  #wc = new Wc({ host: this });
7
4
  #ev = new Events({
8
- host: this,
9
5
  target: this.#wc.shadowRoot,
10
6
  connected: true,
11
- callbacks: [["click", this.#clickHandler]],
7
+ listeners: {
8
+ click: this.#clickHandler.bind(this),
9
+ },
12
10
  });
13
11
  #state = getStateFromDOM(this.#wc.shadowRoot);
14
12
  #clickHandler(e) {
15
- if (!this.#state)
16
- return;
17
13
  let increment = getIncrement(e);
18
14
  if (increment) {
19
15
  this.#state.count += increment;
20
- this.#state.el.textContent = this.#state.count.toString();
16
+ let el = this.#state.el;
17
+ if (el)
18
+ el.textContent = this.#state.count.toString();
21
19
  }
22
20
  }
23
21
  }
24
22
  function getStateFromDOM(shadowRoot) {
25
23
  let slot = shadowRoot.querySelector("slot");
24
+ let el;
26
25
  if (slot)
27
- for (let el of slot.assignedNodes()) {
28
- if (el instanceof HTMLSpanElement) {
29
- return { el, count: parseInt(el.textContent ?? "0") };
30
- }
26
+ for (let slotted of slot.assignedNodes()) {
27
+ if (slotted instanceof HTMLSpanElement)
28
+ el = slotted;
31
29
  }
30
+ return { el, count: parseInt(el?.textContent ?? "0") };
32
31
  }
33
32
  function getIncrement(e) {
34
- let { target } = e;
35
- if (target instanceof HTMLButtonElement) {
36
- return target.hasAttribute("increase") ? 1 : -1;
33
+ if (e.target instanceof HTMLButtonElement) {
34
+ return e.target.hasAttribute("increase") ? 1 : -1;
37
35
  }
38
36
  }
39
37
  customElements.define("counter-wc", Counter);
@@ -1,50 +1,51 @@
1
+ /*
2
+ Custom Element with state and interactivity.
3
+ */
4
+
1
5
  import { Wc, Events } from "wctk";
2
6
 
3
7
  interface State {
4
- el: HTMLSpanElement;
8
+ el: HTMLSpanElement | undefined;
5
9
  count: number;
6
10
  }
7
11
 
8
- /*
9
- Custom Element with state and interactivity.
10
- */
11
12
  class Counter extends HTMLElement {
12
13
  #wc = new Wc({ host: this });
13
14
 
14
15
  #ev = new Events({
15
- host: this,
16
16
  target: this.#wc.shadowRoot,
17
17
  connected: true,
18
- callbacks: [["click", this.#clickHandler]],
18
+ listeners: {
19
+ click: this.#clickHandler.bind(this),
20
+ },
19
21
  });
20
22
 
21
- #state?: State = getStateFromDOM(this.#wc.shadowRoot);
22
-
23
- #clickHandler(e: Event) {
24
- if (!this.#state) return;
23
+ #state: State = getStateFromDOM(this.#wc.shadowRoot);
25
24
 
25
+ #clickHandler(e: PointerEvent) {
26
26
  let increment = getIncrement(e);
27
27
  if (increment) {
28
28
  this.#state.count += increment;
29
- this.#state.el.textContent = this.#state.count.toString();
29
+ let el = this.#state.el;
30
+ if (el) el.textContent = this.#state.count.toString();
30
31
  }
31
32
  }
32
33
  }
33
34
 
34
- function getStateFromDOM(shadowRoot: ShadowRoot) {
35
+ function getStateFromDOM(shadowRoot: ShadowRoot): State {
35
36
  let slot = shadowRoot.querySelector("slot");
37
+ let el: HTMLSpanElement | undefined;
36
38
  if (slot)
37
- for (let el of slot.assignedNodes()) {
38
- if (el instanceof HTMLSpanElement) {
39
- return { el, count: parseInt(el.textContent ?? "0") };
40
- }
39
+ for (let slotted of slot.assignedNodes()) {
40
+ if (slotted instanceof HTMLSpanElement) el = slotted;
41
41
  }
42
+
43
+ return { el, count: parseInt(el?.textContent ?? "0") };
42
44
  }
43
45
 
44
46
  function getIncrement(e: Event) {
45
- let { target } = e;
46
- if (target instanceof HTMLButtonElement) {
47
- return target.hasAttribute("increase") ? 1 : -1;
47
+ if (e.target instanceof HTMLButtonElement) {
48
+ return e.target.hasAttribute("increase") ? 1 : -1;
48
49
  }
49
50
  }
50
51
 
@@ -7,7 +7,5 @@ document.addEventListener("submit", function (e) {
7
7
  e.preventDefault();
8
8
  let formdata = new FormData(e.target);
9
9
  if (results)
10
- results.textContent = JSON.stringify(
11
- // @ts-expect-error
12
- Object.fromEntries(formdata), undefined, " ");
10
+ results.textContent = JSON.stringify(Object.fromEntries(formdata), undefined, " ");
13
11
  });
@@ -13,7 +13,6 @@ document.addEventListener("submit", function (e: SubmitEvent) {
13
13
 
14
14
  if (results)
15
15
  results.textContent = JSON.stringify(
16
- // @ts-expect-error
17
16
  Object.fromEntries(formdata),
18
17
  undefined,
19
18
  " ",
@@ -1,22 +1,19 @@
1
1
  import { Wc, Events } from "wctk";
2
- /*
3
- Form associated custom element.
4
- */
5
2
  export class TextInput extends HTMLElement {
6
3
  static formAssociated = true;
7
4
  #wc = new Wc({ host: this });
8
5
  #ev = new Events({
9
- host: this,
10
6
  target: this.#wc.shadowRoot,
11
7
  connected: true,
12
- callbacks: [["change", this.#changeHandler]],
8
+ listeners: {
9
+ change: this.#changeHandler.bind(this),
10
+ },
13
11
  });
14
12
  #changeHandler(event) {
15
13
  let { target } = event;
16
14
  if (target instanceof HTMLInputElement)
17
15
  this.#wc.setFormValue(target.value);
18
16
  }
19
- // lifecycle method
20
17
  formStateRestoreCallback(state) {
21
18
  let input = this.#wc.shadowRoot.querySelector("input");
22
19
  if (input)
@@ -1,20 +1,22 @@
1
- import { Wc, Events } from "wctk";
2
-
3
1
  /*
4
2
  Form associated custom element.
5
3
  */
4
+
5
+ import { Wc, Events } from "wctk";
6
+
6
7
  export class TextInput extends HTMLElement {
7
8
  static formAssociated = true;
8
9
 
9
10
  #wc = new Wc({ host: this });
10
11
  #ev = new Events({
11
- host: this,
12
12
  target: this.#wc.shadowRoot,
13
13
  connected: true,
14
- callbacks: [["change", this.#changeHandler]],
14
+ listeners: {
15
+ change: this.#changeHandler.bind(this),
16
+ },
15
17
  });
16
18
 
17
- #changeHandler(event: Event) {
19
+ #changeHandler(event: Event): void {
18
20
  let { target } = event;
19
21
  if (target instanceof HTMLInputElement)
20
22
  this.#wc.setFormValue(target.value);
@@ -14,9 +14,6 @@
14
14
  </head>
15
15
  <body>
16
16
  <main>
17
- <button start>|></button>
18
- <button>| |</button>
19
-
20
17
  <!-- web component -->
21
18
  <stopwatch-wc>
22
19
  <template shadowrootmode="closed">
@@ -24,6 +21,12 @@
24
21
  <span>117.00</span>
25
22
  </template>
26
23
  </stopwatch-wc>
24
+
25
+ <section>
26
+ <button start>|></button>
27
+ <button pause>| |</button>
28
+ <button stop>[ ]</button>
29
+ </section>
27
30
  </main>
28
31
  </body>
29
32
  </html>
@@ -2,7 +2,12 @@ import { Stopwatch } from "./stopwatch.js";
2
2
  customElements.define("stopwatch-wc", Stopwatch);
3
3
  const stopwatch = document.querySelector("stopwatch-wc");
4
4
  document.addEventListener("click", function (e) {
5
- if (stopwatch && e.target instanceof HTMLButtonElement) {
6
- e.target.hasAttribute("start") ? stopwatch.start() : stopwatch.pause();
7
- }
5
+ if (!(stopwatch && e.target instanceof HTMLButtonElement))
6
+ return;
7
+ if (e.target.hasAttribute("start"))
8
+ stopwatch.start();
9
+ if (e.target.hasAttribute("pause"))
10
+ stopwatch.pause();
11
+ if (e.target.hasAttribute("stop"))
12
+ stopwatch.stop();
8
13
  });
@@ -4,8 +4,10 @@ customElements.define("stopwatch-wc", Stopwatch);
4
4
 
5
5
  const stopwatch = document.querySelector<Stopwatch>("stopwatch-wc");
6
6
 
7
- document.addEventListener("click", function (e: Event) {
8
- if (stopwatch && e.target instanceof HTMLButtonElement) {
9
- e.target.hasAttribute("start") ? stopwatch.start() : stopwatch.pause();
10
- }
7
+ document.addEventListener("click", function (e: PointerEvent) {
8
+ if (!(stopwatch && e.target instanceof HTMLButtonElement)) return;
9
+
10
+ if (e.target.hasAttribute("start")) stopwatch.start();
11
+ if (e.target.hasAttribute("pause")) stopwatch.pause();
12
+ if (e.target.hasAttribute("stop")) stopwatch.stop();
11
13
  });
@@ -1,45 +1,48 @@
1
1
  import { Wc, Microtask } from "wctk";
2
- /*
3
- Custom Element with performant and "asynchronous" renders
4
- on the microtask queue.
5
- */
6
2
  export class Stopwatch extends HTMLElement {
7
3
  #wc = new Wc({ host: this });
8
- #rc = new Microtask({ host: this, callback: this.#render });
9
- #boundUpdate = this.#update.bind(this);
4
+ #rc = new Microtask(this.#render.bind(this));
10
5
  #state = getStateFromShadowDOM(this.#wc.shadowRoot);
11
6
  #render() {
12
- if (this.#state)
13
- this.#state.el.textContent = this.#state.count.toFixed(2);
7
+ let { el } = this.#state;
8
+ if (el)
9
+ el.textContent = this.#state.count.toFixed(2);
14
10
  }
15
- #update(timestamp) {
16
- if (!this.#state)
17
- return;
18
- this.#state.receipt = requestAnimationFrame(this.#boundUpdate);
19
- this.#state.count += (timestamp - this.#state.prevTimestamp) * 0.001;
20
- this.#state.prevTimestamp = timestamp;
21
- // push render to microtask queue
11
+ #update = this.#undboundUpdate.bind(this);
12
+ #undboundUpdate(now) {
13
+ this.#state.count += (now - this.#state.prevTimestamp) * 0.001;
14
+ this.#state.prevTimestamp = now;
15
+ this.#state.receipt = window.requestAnimationFrame(this.#update);
22
16
  this.#rc.queue();
23
17
  }
24
18
  start() {
25
- if (!this.#state || this.#state?.receipt)
19
+ if (this.#state.receipt)
26
20
  return;
27
- this.#state.receipt = requestAnimationFrame(this.#boundUpdate);
28
21
  this.#state.prevTimestamp = performance.now();
22
+ this.#state.receipt = window.requestAnimationFrame(this.#update);
29
23
  }
30
24
  pause() {
31
- if (this.#state && this.#state.receipt)
32
- this.#state.receipt = cancelAnimationFrame(this.#state.receipt);
25
+ let { receipt } = this.#state;
26
+ if (receipt)
27
+ window.cancelAnimationFrame(receipt);
28
+ this.#state.receipt = undefined;
29
+ }
30
+ stop() {
31
+ this.pause();
32
+ this.#state.count = 0;
33
+ this.#rc.queue();
33
34
  }
34
35
  }
35
36
  function getStateFromShadowDOM(shadowRoot) {
36
37
  let el = shadowRoot.querySelector("span");
37
- if (el instanceof HTMLSpanElement) {
38
- return {
39
- el,
40
- count: parseInt(el.textContent ?? "0"),
41
- receipt: 0,
42
- prevTimestamp: performance.now(),
43
- };
44
- }
38
+ let count = parseInt(el?.textContent ?? "0");
39
+ if (Number.isNaN(count))
40
+ count = 0;
41
+ let prevTimestamp = performance.now();
42
+ return {
43
+ count,
44
+ el,
45
+ prevTimestamp,
46
+ receipt: undefined,
47
+ };
45
48
  }
@@ -1,61 +1,70 @@
1
- import { Bind, Wc, Microtask } from "wctk";
1
+ /*
2
+ Custom Element with performant and "asynchronous" renders
3
+ on the microtask queue.
4
+ */
5
+
6
+ // This example uses window.requestAnimationFrame.
7
+ // Multiple stopwatches means multiple animation frame requests.
8
+ // This is not terribly performant but it's a quick way to get
9
+ // accurate timestamp data for a stopwatch.
10
+
11
+ import { Wc, Microtask } from "wctk";
2
12
 
3
13
  interface State {
4
- receipt: number | void;
5
14
  count: number;
15
+ el: HTMLSpanElement | null;
6
16
  prevTimestamp: DOMHighResTimeStamp;
7
- el: HTMLSpanElement;
17
+ receipt: number | void;
8
18
  }
9
19
 
10
- /*
11
- Custom Element with performant and "asynchronous" renders
12
- on the microtask queue.
13
- */
14
20
  export class Stopwatch extends HTMLElement {
15
21
  #wc = new Wc({ host: this });
16
- #rc = new Microtask({ host: this, callback: this.#render });
17
-
18
- #boundUpdate = this.#update.bind(this);
19
- #state?: State = getStateFromShadowDOM(this.#wc.shadowRoot);
22
+ #rc = new Microtask(this.#render.bind(this));
23
+ #state: State = getStateFromShadowDOM(this.#wc.shadowRoot);
20
24
 
21
25
  #render() {
22
- if (this.#state)
23
- this.#state.el.textContent = this.#state.count.toFixed(2);
26
+ let { el } = this.#state;
27
+ if (el) el.textContent = this.#state.count.toFixed(2);
24
28
  }
25
29
 
26
- #update(timestamp: DOMHighResTimeStamp) {
27
- if (!this.#state) return;
28
-
29
- this.#state.receipt = requestAnimationFrame(this.#boundUpdate);
30
-
31
- this.#state.count += (timestamp - this.#state.prevTimestamp) * 0.001;
32
- this.#state.prevTimestamp = timestamp;
33
-
34
- // push render to microtask queue
30
+ #update = this.#undboundUpdate.bind(this);
31
+ #undboundUpdate(now: DOMHighResTimeStamp) {
32
+ this.#state.count += (now - this.#state.prevTimestamp) * 0.001;
33
+ this.#state.prevTimestamp = now;
34
+ this.#state.receipt = window.requestAnimationFrame(this.#update);
35
35
  this.#rc.queue();
36
36
  }
37
37
 
38
38
  start() {
39
- if (!this.#state || this.#state?.receipt) return;
39
+ if (this.#state.receipt) return;
40
40
 
41
- this.#state.receipt = requestAnimationFrame(this.#boundUpdate);
42
41
  this.#state.prevTimestamp = performance.now();
42
+ this.#state.receipt = window.requestAnimationFrame(this.#update);
43
43
  }
44
44
 
45
45
  pause() {
46
- if (this.#state && this.#state.receipt)
47
- this.#state.receipt = cancelAnimationFrame(this.#state.receipt);
46
+ let { receipt } = this.#state;
47
+ if (receipt) window.cancelAnimationFrame(receipt);
48
+ this.#state.receipt = undefined;
49
+ }
50
+
51
+ stop() {
52
+ this.pause();
53
+ this.#state.count = 0;
54
+ this.#rc.queue();
48
55
  }
49
56
  }
50
57
 
51
- function getStateFromShadowDOM(shadowRoot: ShadowRoot): State | undefined {
58
+ function getStateFromShadowDOM(shadowRoot: ShadowRoot): State {
52
59
  let el = shadowRoot.querySelector("span");
53
- if (el instanceof HTMLSpanElement) {
54
- return {
55
- el,
56
- count: parseInt(el.textContent ?? "0"),
57
- receipt: 0,
58
- prevTimestamp: performance.now(),
59
- };
60
- }
60
+ let count = parseInt(el?.textContent ?? "0");
61
+ if (Number.isNaN(count)) count = 0;
62
+ let prevTimestamp = performance.now();
63
+
64
+ return {
65
+ count,
66
+ el,
67
+ prevTimestamp,
68
+ receipt: undefined,
69
+ };
61
70
  }
@@ -2,6 +2,7 @@
2
2
  "extends": "../tsconfig.json",
3
3
  "compilerOptions": {
4
4
  "declaration": false,
5
+ "removeComments": true,
5
6
  "paths": {
6
7
  "wctk": ["../dist/mod.d.ts"],
7
8
  "wctk/*": ["../dist/"]
package/jr.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "jackrabbit_url": "http://localhost:4000",
3
+ "run_asynchronously": false,
4
+ "webdrivers": [
5
+ {
6
+ "command": "safaridriver -p 4001",
7
+ "title": "Safari",
8
+ "timeout_ms": 20000,
9
+ "webdriver_url": "http://localhost:4001"
10
+ },
11
+ {
12
+ "command": "geckodriver -p 4001",
13
+ "title": "Firefox",
14
+ "timeout_ms": 20000,
15
+ "webdriver_url": "http://localhost:4001",
16
+ "capabilities": {
17
+ "alwaysMatch": {
18
+ "moz:firefoxOptions": {
19
+ "args": ["-headless"]
20
+ }
21
+ }
22
+ }
23
+ }
24
+ ]
25
+ }
package/package.json CHANGED
@@ -2,18 +2,22 @@
2
2
  "name": "@w-lfpup/wctk",
3
3
  "type": "module",
4
4
  "main": "dist/mod.js",
5
- "description": "A bare-metal web component toolkit",
5
+ "description": "A bare-metal toolkit for web components",
6
6
  "license": "BSD-3-Clause",
7
- "version": "0.1.0",
7
+ "version": "0.2.1",
8
8
  "scripts": {
9
- "prepare": "npm run build && npm run build:examples",
10
- "build": "npx tsc --project ./src",
9
+ "prepare": "npm run build",
10
+ "build": "npm run build:src && npm run build:tests && npm run build:examples",
11
+ "build:src": "npx tsc --project ./src",
12
+ "build:tests": "npx tsc --project ./tests",
11
13
  "build:examples": "npx tsc --project ./examples",
14
+ "test": "npx jackrabbit_webdriver jr.json tests/dist/mod.js",
12
15
  "format": "prettier --write ./"
13
16
  },
14
17
  "devDependencies": {
15
- "prettier": "^3.3.0",
16
- "typescript": "^5.4.5"
18
+ "@w-lfpup/jackrabbit": "^0.3.2",
19
+ "prettier": "^3.8.3",
20
+ "typescript": "^6.0.2"
17
21
  },
18
22
  "repository": {
19
23
  "type": "git",
package/src/events.ts CHANGED
@@ -1,32 +1,49 @@
1
- export type Callbacks = Array<[string, EventListenerOrEventListenerObject]>;
1
+ interface GenericEventListener<E> {
2
+ (evt: E): void;
3
+ }
2
4
 
3
- export interface EventsInterface {
4
- connect(): void;
5
- disconnect(): void;
5
+ interface GenericEventListenerObject<E> {
6
+ handleEvent(object: E): void;
6
7
  }
7
8
 
8
- export interface EventElementInterface {
9
- addEventListener: EventTarget["addEventListener"];
10
- removeEventListener: EventTarget["removeEventListener"];
9
+ type GenericCallbacks<E> =
10
+ | GenericEventListener<E>
11
+ | GenericEventListenerObject<E>;
12
+
13
+ type EventMap = Partial<{
14
+ [Property in keyof GlobalEventHandlersEventMap]: GenericCallbacks<
15
+ GlobalEventHandlersEventMap[Property]
16
+ >;
17
+ }>;
18
+
19
+ type Callbacks = Array<[string, EventListenerOrEventListenerObject]>;
20
+
21
+ interface EventElementInterface {
22
+ addEventListener: Element["addEventListener"];
23
+ removeEventListener: Element["removeEventListener"];
11
24
  }
12
25
 
13
26
  export interface EventParamsInterface {
14
- host: EventElementInterface;
27
+ listeners: EventMap;
15
28
  connected?: boolean;
16
- target?: EventElementInterface;
17
- callbacks: Callbacks;
29
+ target: EventElementInterface;
30
+ }
31
+
32
+ export interface EventsInterface {
33
+ connect(): void;
34
+ disconnect(): void;
18
35
  }
19
36
 
20
37
  export class Events implements EventsInterface {
21
38
  #connected: boolean = false;
22
- #callbacks: Callbacks = [];
39
+ #listeners: Callbacks = [];
23
40
  #target: EventElementInterface;
24
41
 
25
42
  constructor(params: EventParamsInterface) {
26
- const { host, target, callbacks, connected } = params;
43
+ const { target, listeners, connected } = params;
27
44
 
28
- this.#target = target ?? host;
29
- this.#callbacks = getBoundCallbacks(host, callbacks);
45
+ this.#target = target;
46
+ this.#listeners = Object.entries(listeners) as Callbacks;
30
47
 
31
48
  if (connected) this.connect();
32
49
  }
@@ -35,8 +52,8 @@ export class Events implements EventsInterface {
35
52
  if (this.#connected) return;
36
53
  this.#connected = true;
37
54
 
38
- for (let [name, callback] of this.#callbacks) {
39
- this.#target.addEventListener(name, callback);
55
+ for (let [name, listener] of this.#listeners) {
56
+ this.#target.addEventListener(name, listener);
40
57
  }
41
58
  }
42
59
 
@@ -44,24 +61,8 @@ export class Events implements EventsInterface {
44
61
  if (!this.#connected) return;
45
62
  this.#connected = false;
46
63
 
47
- for (let [name, callback] of this.#callbacks) {
48
- this.#target.removeEventListener(name, callback);
64
+ for (let [name, listener] of this.#listeners) {
65
+ this.#target.removeEventListener(name, listener);
49
66
  }
50
67
  }
51
68
  }
52
-
53
- function getBoundCallbacks(host: Object, callbacks: Callbacks): Callbacks {
54
- let boundCallbacks: Callbacks = [];
55
- for (let [name, callback] of callbacks) {
56
- if (
57
- callback instanceof Function &&
58
- !callback.hasOwnProperty("prototype")
59
- ) {
60
- callback = callback.bind(host);
61
- }
62
-
63
- boundCallbacks.push([name, callback]);
64
- }
65
-
66
- return boundCallbacks;
67
- }
package/src/microtask.ts CHANGED
@@ -1,30 +1,19 @@
1
- export interface MicrotaskParamsInterface {
2
- host: Object;
3
- callback: Function;
4
- }
5
-
6
1
  export interface MicrotaskInterface {
7
2
  queue(): void;
8
3
  }
9
4
 
5
+ type Callback = () => void;
6
+
10
7
  export class Microtask implements MicrotaskInterface {
11
8
  #queued = false;
12
- #callback: Function;
13
-
14
- constructor(params: MicrotaskParamsInterface) {
15
- let { host, callback } = params;
9
+ #callback: Callback;
10
+ queue = this.#queue.bind(this);
16
11
 
17
- this.queue = this.queue.bind(this);
12
+ constructor(callback: Callback) {
18
13
  this.#callback = callback;
19
- if (
20
- callback instanceof Function &&
21
- !callback.hasOwnProperty("prototype")
22
- ) {
23
- this.#callback = callback.bind(host);
24
- }
25
14
  }
26
15
 
27
- queue() {
16
+ #queue() {
28
17
  if (this.#queued) return;
29
18
  this.#queued = true;
30
19
 
package/src/mod.ts CHANGED
@@ -1,6 +1,4 @@
1
- export * from "./bind.js";
2
1
  export * from "./events.js";
3
2
  export * from "./microtask.js";
4
- export * from "./subscription.js";
5
3
  export * from "./query_selector.js";
6
4
  export * from "./wc.js";