1 line
15 KiB
Text
1 line
15 KiB
Text
|
{"version":3,"file":"browser.js","sources":["src/Event.js","src/EventEmitter.js","index.js"],"sourcesContent":["const returnTrue = () => {\n return true;\n};\n\nconst returnFalse = () => {\n return false;\n};\n\nclass Event {\n\n /**\n * @param {*} target\n * @param {String} type\n * @param {Array} args\n */\n constructor(target, type, args) {\n Object.defineProperties(this, {\n 'target': {\n get : () => {\n return target;\n },\n set : () => {},\n enumerable: true\n },\n 'type' : {\n get : () => {\n return type;\n },\n set : () => {},\n enumerable: true\n },\n 'args' : {\n get : () => {\n return args;\n },\n set : () => {},\n enumerable: true\n }\n });\n\n this.isDefaultPrevented = returnFalse;\n this.isPropagationStopped = returnFalse;\n }\n\n preventDefault() {\n this.isDefaultPrevented = returnTrue;\n }\n\n stopPropagation() {\n this.isPropagationStopped = returnTrue;\n }\n\n}\n\nmodule.exports = Event;\n","const Event = require('./Event');\n\n/**\n * @typedef {Object.<String, Function>} Callbacks\n */\n\nclass EventEmitter {\n\n /**\n * Add one or many event handlers\n *\n * @example\n * obj.on('event', callback)\n * obj.on('event', listener) // listener has an `handleEvent` method\n * obj.on('event1 event2', callback)\n * obj.on({ event1: callback1, event2: callback2 })\n *\n * @param {String|Callbacks} events\n * @param {Function} [callback]\n * @return {this}\n */\n on(events, callback) {\n this.__events = this.__events || {};\n\n if (typeof events === 'object') {\n for (const event in events) {\n if (events.hasOwnProperty(event)) {\n this.__events[event] = this.__events[event] || [];\n this.__events[event].push(events[event]);\n }\n }\n }\n else {\n events.split(' ').forEach((event) => {\n this.__events[event] = this.__events[event] || [];\n this.__events[event].push(callback);\n });\n }\n\n return this;\n }\n\n /**\n * Remove one or many or all event handlers\n *\n * @example\n * obj.off('event')\n * obj.off('event', callback)\n * obj.off('event1 event2')\n * obj.off({ event1: callback1, event2: callback2 })\n * obj.off()\n *\n * @param {String|Callbacks} [events]\n * @param {Function} [callback]\n * @return {this}\n */\n off(events, callback) {\n if (typeof events === 'object') {\n for (const event in events) {\n if (events.hasOwnProperty(event)) {\n if (this.__events && (event in this.__events)) {\n const index = this.__events[event].indexOf(events[event]);\n if (index !== -1) this.__events[event].splice(index, 1);\n }\n if (this.__once && (event in this.__once)) {\n const index = this.__once[event].indexOf(events[event]);\n if (index !== -1) this.__once[event].splice(index, 1);\n }\n }\n }\n }\n else if (!!events) {\n events.split(' ').forEach((event) => {\n if (this.__events && (event in this.__events)) {\n if (callback) {\n const index = this.__events[event].indexOf(callback);\n if (index !== -1) this.__events[event].splice(index, 1);\n }\n else {\n this.__events[event].length = 0;\n
|