@whatwg-node/events 0.0.3 → 0.1.0-alpha-20230515120642-be23d36

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @whatwg-node/events
2
2
 
3
+ ## 0.1.0-alpha-20230515120642-be23d36
4
+
5
+ ### Minor Changes
6
+
7
+ - [#535](https://github.com/ardatan/whatwg-node/pull/535)
8
+ [`ce067f3`](https://github.com/ardatan/whatwg-node/commit/ce067f3875430185c8177acb47c9b2d8d871f24e)
9
+ Thanks [@ardatan](https://github.com/ardatan)! - Drop Node 14 support
10
+
3
11
  ## 0.0.3
4
12
 
5
13
  ### Patch Changes
@@ -1,3 +1 @@
1
- export const Event = globalThis.Event;
2
- export const EventTarget = globalThis.EventTarget;
3
1
  export const CustomEvent = globalThis.CustomEvent;
@@ -1,3 +1 @@
1
- module.exports.Event = globalThis.Event;
2
- module.exports.EventTarget = globalThis.EventTarget;
3
1
  module.exports.CustomEvent = globalThis.CustomEvent;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  /// <reference lib="dom" />
2
2
 
3
3
  declare module "@whatwg-node/events" {
4
- export const Event: typeof globalThis.Event;
5
- export const EventTarget: typeof globalThis.EventTarget;
6
4
  export const CustomEvent: typeof globalThis.CustomEvent;
7
5
  }
@@ -1,96 +1,3 @@
1
- module.exports.Event = globalThis.Event;
2
- if (!module.exports.Event) {
3
- module.exports.Event = class Event {
4
- constructor(type, options) {
5
- this.bubbles = !!options && !!options.bubbles;
6
- this.cancelable = !!options && !!options.cancelable;
7
- this.composed = !!options && !!options.composed;
8
- this.type = type;
9
- }
10
- }
11
- }
12
-
13
- module.exports.EventTarget = globalThis.EventTarget;
14
- if (!module.exports.EventTarget) {
15
- module.exports.EventTarget = class EventTarget {
16
- constructor() {
17
- this.__listeners = new Map();
18
- }
19
- addEventListener(type, listener, options) {
20
- if (arguments.length < 2) {
21
- throw new TypeError(
22
- `TypeError: Failed to execute 'addEventListener' on 'EventTarget': 2 arguments required, but only ${arguments.length} present.`
23
- );
24
- }
25
- const __listeners = this.__listeners;
26
- const actualType = type.toString();
27
- if (!__listeners.has(actualType)) {
28
- __listeners.set(actualType, new Map());
29
- }
30
- const listenersForType = __listeners.get(actualType);
31
- if (!listenersForType.has(listener)) {
32
- // Any given listener is only registered once
33
- listenersForType.set(listener, options);
34
- }
35
- }
36
- removeEventListener(type, listener, _options) {
37
- if (arguments.length < 2) {
38
- throw new TypeError(
39
- `TypeError: Failed to execute 'addEventListener' on 'EventTarget': 2 arguments required, but only ${arguments.length} present.`
40
- );
41
- }
42
- const __listeners = this.__listeners;
43
- const actualType = type.toString();
44
- if (__listeners.has(actualType)) {
45
- const listenersForType = __listeners.get(actualType);
46
- if (listenersForType.has(listener)) {
47
- listenersForType.delete(listener);
48
- }
49
- }
50
- }
51
- dispatchEvent(event) {
52
- if (!(event instanceof module.exports.Event)) {
53
- throw new TypeError(
54
- `Failed to execute 'dispatchEvent' on 'EventTarget': parameter 1 is not of type 'Event'.`
55
- );
56
- }
57
- const type = event.type;
58
- const __listeners = this.__listeners;
59
- const listenersForType = __listeners.get(type);
60
- if (listenersForType) {
61
- for (const [listener, options] of listenersForType.entries()) {
62
- try {
63
- if (typeof listener === "function") {
64
- // Listener functions must be executed with the EventTarget as the `this` context.
65
- listener.call(this, event);
66
- } else if (listener && typeof listener.handleEvent === "function") {
67
- // Listener objects have their handleEvent method called, if they have one
68
- listener.handleEvent(event);
69
- }
70
- } catch (err) {
71
- // We need to report the error to the global error handling event,
72
- // but we do not want to break the loop that is executing the events.
73
- // Unfortunately, this is the best we can do, which isn't great, because the
74
- // native EventTarget will actually do this synchronously before moving to the next
75
- // event in the loop.
76
- setTimeout(() => {
77
- throw err;
78
- });
79
- }
80
- if (options && options.once) {
81
- // If this was registered with { once: true }, we need
82
- // to remove it now.
83
- listenersForType.delete(listener);
84
- }
85
- }
86
- }
87
- // Since there are no cancellable events on a base EventTarget,
88
- // this should always return true.
89
- return true;
90
- }
91
- }
92
- }
93
-
94
1
  module.exports.CustomEvent = globalThis.CustomEvent;
95
2
  if (!module.exports.CustomEvent) {
96
3
  module.exports.CustomEvent = class CustomEvent extends module.exports.Event {
@@ -99,4 +6,4 @@ if (!module.exports.CustomEvent) {
99
6
  this.detail = options && options.detail;
100
7
  }
101
8
  }
102
- }
9
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whatwg-node/events",
3
- "version": "0.0.3",
3
+ "version": "0.1.0-alpha-20230515120642-be23d36",
4
4
  "description": "Cross Platform Smart Event API Ponyfill",
5
5
  "repository": {
6
6
  "type": "git",