mirror of
https://github.com/genxium/DelayNoMore
synced 2024-12-29 13:08:17 +00:00
83 lines
2.6 KiB
JavaScript
83 lines
2.6 KiB
JavaScript
|
"use strict";
|
||
|
|
||
|
Object.defineProperty(exports, "__esModule", {
|
||
|
value: true
|
||
|
});
|
||
|
|
||
|
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
||
|
|
||
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||
|
|
||
|
var _events = new WeakMap();
|
||
|
|
||
|
var EventTarget = function () {
|
||
|
function EventTarget() {
|
||
|
_classCallCheck(this, EventTarget);
|
||
|
|
||
|
_events.set(this, {});
|
||
|
}
|
||
|
|
||
|
_createClass(EventTarget, [{
|
||
|
key: "addEventListener",
|
||
|
value: function addEventListener(type, listener) {
|
||
|
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
||
|
|
||
|
var events = _events.get(this);
|
||
|
|
||
|
if (!events) {
|
||
|
events = {};
|
||
|
_events.set(this, events);
|
||
|
}
|
||
|
if (!events[type]) {
|
||
|
events[type] = [];
|
||
|
}
|
||
|
events[type].push(listener);
|
||
|
|
||
|
if (options.capture) {
|
||
|
// console.warn('EventTarget.addEventListener: options.capture is not implemented.')
|
||
|
}
|
||
|
if (options.once) {
|
||
|
// console.warn('EventTarget.addEventListener: options.once is not implemented.')
|
||
|
}
|
||
|
if (options.passive) {
|
||
|
// console.warn('EventTarget.addEventListener: options.passive is not implemented.')
|
||
|
}
|
||
|
}
|
||
|
}, {
|
||
|
key: "removeEventListener",
|
||
|
value: function removeEventListener(type, listener) {
|
||
|
var events = _events.get(this);
|
||
|
|
||
|
if (events) {
|
||
|
var listeners = events[type];
|
||
|
|
||
|
if (listeners && listeners.length > 0) {
|
||
|
for (var i = listeners.length; i--; i > 0) {
|
||
|
if (listeners[i] === listener) {
|
||
|
listeners.splice(i, 1);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}, {
|
||
|
key: "dispatchEvent",
|
||
|
value: function dispatchEvent() {
|
||
|
var event = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
||
|
|
||
|
var listeners = _events.get(this)[event.type];
|
||
|
|
||
|
if (listeners) {
|
||
|
for (var i = 0; i < listeners.length; i++) {
|
||
|
listeners[i](event);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}]);
|
||
|
|
||
|
return EventTarget;
|
||
|
}();
|
||
|
|
||
|
exports.default = EventTarget;
|
||
|
module.exports = exports["default"];
|