From c0b723ec71b39e8ca5d72ac81f50a43c99c94296 Mon Sep 17 00:00:00 2001 From: Matias L Date: Fri, 26 May 2023 01:25:17 -0400 Subject: [PATCH] fix: reference of polyfills --- src/event-target.js | 12 ++++++------ src/event.js | 4 ++-- src/index.js | 16 +++++----------- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/event-target.js b/src/event-target.js index 0d04ce7..ce88d77 100644 --- a/src/event-target.js +++ b/src/event-target.js @@ -1,10 +1,10 @@ -function EventTarget() { +function EventTargetPolyfill() { this.__listeners = new Map(); } -EventTarget.prototype = Object.create(Object.prototype); +EventTargetPolyfill.prototype = Object.create(Object.prototype); -EventTarget.prototype.addEventListener = function (type, listener, options) { +EventTargetPolyfill.prototype.addEventListener = function (type, listener, options) { if (arguments.length < 2) throw new TypeError(`Failed to execute 'addEventListener' on 'EventTarget': 2 arguments required, but only ${arguments.length} present.`); const actualType = type.toString(); @@ -14,7 +14,7 @@ EventTarget.prototype.addEventListener = function (type, listener, options) { if (!listenersForType.has(listener)) listenersForType.set(listener, options); } -EventTarget.prototype.removeEventListener = function (type, listener, options) { +EventTargetPolyfill.prototype.removeEventListener = function (type, listener, options) { if (arguments.length < 2) throw new TypeError(`Failed to execute 'removeEventListener' on 'EventTarget': 2 arguments required, but only ${arguments.length} present.`); const actualType = type.toString(); @@ -24,7 +24,7 @@ EventTarget.prototype.removeEventListener = function (type, listener, options) { if (listenersForType.has(listener)) listenersForType.delete(listener); } -EventTarget.prototype.dispatchEvent = function (event) { +EventTargetPolyfill.prototype.dispatchEvent = function (event) { if (!(event instanceof Event)) throw new TypeError( `Failed to execute 'dispatchEvent' on 'EventTarget': parameter 1 is not of type 'Event'.`); const type = event.type; @@ -55,4 +55,4 @@ EventTarget.prototype.dispatchEvent = function (event) { return true; } -export default EventTarget; +export default EventTargetPolyfill; diff --git a/src/event.js b/src/event.js index 778c75d..345d491 100644 --- a/src/event.js +++ b/src/event.js @@ -1,8 +1,8 @@ -function Event (type, options) { +function EventPolyfill (type, options) { this.bubbles = !!options && !!options.bubbles; this.cancelable = !!options && !!options.cancelable; this.composed = !!options && !!options.composed; this.type = type; } -export default Event; +export default EventPolyfill; diff --git a/src/index.js b/src/index.js index 15e236b..6c399ab 100644 --- a/src/index.js +++ b/src/index.js @@ -1,3 +1,6 @@ +import EventTargetPolyfill from './event-target'; +import EventPolyfill from "./event"; + const root = (typeof globalThis !== "undefined" && globalThis) || (typeof self !== "undefined" && self) || @@ -21,14 +24,5 @@ const polyfillEventTarget = () => { return false; } -if (polyfillEvent()) { - import('./event').then(module => { - root.Event = module.default; - }); -} - -if (polyfillEventTarget()) { - import('./event-target').then(module => { - root.EventTarget = module.default; - }); -} +if (polyfillEvent()) root.Event = EventPolyfill; +if (polyfillEventTarget()) root.EventTarget = EventTargetPolyfill;