Skip to content

Commit

Permalink
Merge pull request #5 from videsk/develop
Browse files Browse the repository at this point in the history
fix: reference of polyfills
  • Loading branch information
matiaslopezd authored May 26, 2023
2 parents e83335c + c0b723e commit 894bd33
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
12 changes: 6 additions & 6 deletions src/event-target.js
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -55,4 +55,4 @@ EventTarget.prototype.dispatchEvent = function (event) {
return true;
}

export default EventTarget;
export default EventTargetPolyfill;
4 changes: 2 additions & 2 deletions src/event.js
Original file line number Diff line number Diff line change
@@ -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;
16 changes: 5 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import EventTargetPolyfill from './event-target';
import EventPolyfill from "./event";

const root =
(typeof globalThis !== "undefined" && globalThis) ||
(typeof self !== "undefined" && self) ||
Expand All @@ -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;

0 comments on commit 894bd33

Please sign in to comment.