From a3682cba037d105dd055147724538ffbe62d2dea Mon Sep 17 00:00:00 2001 From: mistic100 Date: Sun, 30 Jan 2022 17:43:53 +0100 Subject: [PATCH] Version 2.1.1 --- browser.js | 68 +++++++++++++++++++++++++++++--------------------- browser.js.map | 2 +- package.json | 2 +- 3 files changed, 41 insertions(+), 31 deletions(-) diff --git a/browser.js b/browser.js index 4680efc..ec08eb7 100644 --- a/browser.js +++ b/browser.js @@ -1,5 +1,5 @@ /*! - * uevent (v2.1.0) + * uevent (v2.1.1) * @copyright 2015-2022 Damien "Mistic" Sorel * @licence MIT */ @@ -88,32 +88,20 @@ * @param {Function} [callback] * @return {this} */ - _proto.on = function on(events, callback, once) { + _proto.on = function on(events, callback) { var _this = this; - if (once === void 0) { - once = false; - } - this.__events = this.__events || {}; if (typeof events === 'object') { for (var event in events) { if (events.hasOwnProperty(event)) { - if (once) { - events[event].__once = true; - } - this.__events[event] = this.__events[event] || []; this.__events[event].push(events[event]); } } } else { - if (once) { - callback.__once = true; - } - events.split(' ').forEach(function (event) { _this.__events[event] = _this.__events[event] || []; @@ -186,7 +174,27 @@ ; _proto.once = function once(events, callback) { - return this.on(events, callback, true); + var _this3 = this; + + this.__once = this.__once || {}; + + if (typeof events === 'object') { + for (var event in events) { + if (events.hasOwnProperty(event)) { + this.__once[event] = this.__once[event] || []; + + this.__once[event].push(events[event]); + } + } + } else { + events.split(' ').forEach(function (event) { + _this3.__once[event] = _this3.__once[event] || []; + + _this3.__once[event].push(callback); + }); + } + + return this; } /** * Trigger all handlers for an event @@ -204,15 +212,9 @@ var e = new Event_1(this, event, args); if (this.__events && event in this.__events) { - var hasOnce = false; - for (var i = 0, l = this.__events[event].length; i < l; i++) { var f = this.__events[event][i]; - if (f.__once) { - hasOnce = true; - } - if (typeof f === 'object') { f.handleEvent(e); } else { @@ -223,12 +225,24 @@ break; } } + } - if (hasOnce) { - this.__events[event] = this.__events[event].filter(function (f) { - return !f.__once; - }); + if (this.__once && event in this.__once) { + for (var _i = 0, _l = this.__once[event].length; _i < _l; _i++) { + var _f = this.__once[event][_i]; + + if (typeof _f === 'object') { + _f.handleEvent(e); + } else { + _f.call.apply(_f, [this, e].concat(args)); + } + + if (e.isPropagationStopped()) { + break; + } } + + delete this.__once[event]; } return e; @@ -254,10 +268,6 @@ for (var i = 0, l = this.__events[event].length; i < l; i++) { var f = this.__events[event][i]; - if (f.__once) { - continue; - } - if (typeof f === 'object') { e.value = f.handleEvent(e); } else { diff --git a/browser.js.map b/browser.js.map index 674dbbe..fbd8e81 100644 --- a/browser.js.map +++ b/browser.js.map @@ -1 +1 @@ -{"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.} 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, once = false) {\n this.__events = this.__events || {};\n\n if (typeof events === 'object') {\n for (const event in events) {\n if (events.hasOwnProperty(event)) {\n if (once) {\n events[event].__once = true;\n }\n this.__events[event] = this.__events[event] || [];\n this.__events[event].push(events[event]);\n }\n }\n }\n else {\n if (once) {\n callback.__once = true;\n }\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 this.__events = this.__events || {};\n\n if (typeof events === 'object') {\n for (const event in events) {\n if (events.hasOwnProperty(event) && (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 }\n }\n else if (!!events) {\n events.split(' ').forEach((event) => {\n if (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 }\n }\n });\n }\n else {\n this.__events = {};\n }\n\n return this;\n }\n\n /**\n * Add one or many event handlers that will be called only once\n * This handlers are only applicable to \"trigger\", not \"change\"\n *\n * @example\n * obj.once('event', callback)\n * obj.once('event1 event2', callback)\n * obj.once({ event1: callback1, event2: callback2 })\n *\n * @param {String|Callbacks} events\n * @param {Function} [callback]\n * @return {this}\n */\n once(events, callback) {\n return this.on(events, callback, true);\n }\n\n /**\n * Trigger all handlers for an event\n *\n * @param {String} event\n * @param {*...} [arguments]\n * @return {Event}\n */\n trigger(event /* , args... */) {\n const args = Array.prototype.slice.call(arguments, 1);\n const e = new Event(this, event, args);\n\n if (this.__events && event in this.__events) {\n let hasOnce = false;\n for (let i = 0, l = this.__events[event].length; i < l; i++) {\n let f = this.__events[event][i];\n if (f.__once) {\n hasOnce = true;\n }\n if (typeof f === 'object') {\n f.handleEvent(e);\n }\n else {\n f.call(this, e, ...args);\n }\n if (e.isPropagationStopped()) {\n break;\n }\n }\n if (hasOnce) {\n this.__events[event] = this.__events[event].filter(f => !f.__once);\n }\n }\n\n return e;\n }\n\n /**\n * Trigger all modificators for an event, each handler must return a value\n *\n * @param {String} event\n * @param {*} value\n * @param {*...} [arguments]\n * @return {*} modified value\n */\n change(event, value /* , args... */) {\n const args = Array.prototype.slice.call(arguments, 2);\n const e = new Event(this, event, args);\n e.value = value;\n\n if (this.__events && event in this.__events) {\n for (let i = 0, l = this.__events[event].length; i < l; i++) {\n const f = this.__events[event][i];\n if (f.__once) {\n continue;\n }\n if (typeof f === 'object') {\n e.value = f.handleEvent(e);\n }\n else {\n e.value = f.call(this, e, e.value, ...args);\n }\n if (e.isPropagationStopped()) {\n break;\n }\n }\n }\n\n return e.value;\n }\n\n}\n\nmodule.exports = EventEmitter;\n","const EventEmitter = require('./src/EventEmitter');\nconst Event = require('./src/Event');\n\nfunction mixin(target) {\n target = typeof target === 'function' ? target.prototype : target;\n\n ['on', 'off', 'once', 'trigger', 'change'].forEach((name) => {\n target[name] = EventEmitter.prototype[name];\n });\n\n return target;\n}\n\nmodule.exports = {\n EventEmitter: EventEmitter,\n Event : Event,\n mixin : mixin,\n};\n"],"names":["returnTrue","returnFalse","Event","target","type","args","Object","defineProperties","get","set","enumerable","isDefaultPrevented","isPropagationStopped","preventDefault","stopPropagation","EventEmitter","on","events","callback","once","__events","event","hasOwnProperty","__once","push","split","forEach","off","index","indexOf","splice","length","trigger","Array","prototype","slice","call","arguments","e","hasOnce","i","l","f","handleEvent","filter","change","value","mixin","name"],"mappings":";;;;;;;;;;;IAAA,IAAMA,UAAU,GAAG,SAAbA,UAAa,GAAM;IACrB,SAAO,IAAP;IACH,CAFD;;IAIA,IAAMC,WAAW,GAAG,SAAdA,WAAc,GAAM;IACtB,SAAO,KAAP;IACH,CAFD;;QAIMC;;IAGN;IACA;IACA;IACA;IACI,iBAAYC,MAAZ,EAAoBC,IAApB,EAA0BC,IAA1B,EAAgC;IAC5BC,IAAAA,MAAM,CAACC,gB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,CAAC,GAAGC,CAArD,EAAwDD,CAAC,EAAzD,EAA6D;IACzD,YAAME,CAAC,GAAG,KAAKtB,QAAL,CAAcC,KAAd,EAAqBmB,CAArB,CAAV;;IACA,YAAIE,CAAC,CAACnB,MAAN,EAAc;IACV;IACH;;IACD,YAAI,OAAOmB,CAAP,KAAa,QAAjB,EAA2B;IACvBJ,UAAAA,CAAC,CAACQ,KAAF,GAAUJ,CAAC,CAACC,WAAF,CAAcL,CAAd,CAAV;IACH,SAFD,MAGK;IACDA,UAAAA,CAAC,CAACQ,KAAF,GAAUJ,CAAC,CAACN,IAAF,OAAAM,CAAC,GAAM,IAAN,EAAYJ,CAAZ,EAAeA,CAAC,CAACQ,KAAjB,SAA2BzC,IAA3B,EAAX;IACH;;IACD,YAAIiC,CAAC,CAAC1B,oBAAF,EAAJ,EAA8B;IAC1B;IACH;IACJ;IACJ;;IAED,WAAO0B,CAAC,CAACQ,KAAT;IACH;;;;;IAIL,kBAAc,GAAG/B,YAAjB;;ICnLA,SAASgC,KAAT,CAAe5C,MAAf,EAAuB;IACnBA,EAAAA,MAAM,GAAG,OAAOA,MAAP,KAAkB,UAAlB,GAA+BA,MAAM,CAAC+B,SAAtC,GAAkD/B,MAA3D;IAEA,GAAC,IAAD,EAAO,KAAP,EAAc,MAAd,EAAsB,SAAtB,EAAiC,QAAjC,EAA2CuB,OAA3C,CAAmD,UAACsB,IAAD,EAAU;IACzD7C,IAAAA,MAAM,CAAC6C,IAAD,CAAN,GAAejC,cAAY,CAACmB,SAAb,CAAuBc,IAAvB,CAAf;IACH,GAFD;IAIA,SAAO7C,MAAP;IACH;;cAEa,GAAG;IACbY,EAAAA,YAAY,EAAEA,cADD;IAEbb,EAAAA,KAAK,EAASA,OAFD;IAGb6C,EAAAA,KAAK,EAASA;IAHD;;;;;;;;;;;;;;;;"} \ No newline at end of file +{"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.} 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 this.__events = this.__events || {};\n\n if (typeof events === 'object') {\n for (const event in events) {\n if (events.hasOwnProperty(event) && (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 }\n }\n else if (!!events) {\n events.split(' ').forEach((event) => {\n if (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 }\n }\n });\n }\n else {\n this.__events = {};\n }\n\n return this;\n }\n\n /**\n * Add one or many event handlers that will be called only once\n * This handlers are only applicable to \"trigger\", not \"change\"\n *\n * @example\n * obj.once('event', callback)\n * obj.once('event1 event2', callback)\n * obj.once({ event1: callback1, event2: callback2 })\n *\n * @param {String|Callbacks} events\n * @param {Function} [callback]\n * @return {this}\n */\n once(events, callback) {\n this.__once = this.__once || {};\n\n if (typeof events === 'object') {\n for (const event in events) {\n if (events.hasOwnProperty(event)) {\n this.__once[event] = this.__once[event] || [];\n this.__once[event].push(events[event]);\n }\n }\n }\n else {\n events.split(' ').forEach((event) => {\n this.__once[event] = this.__once[event] || [];\n this.__once[event].push(callback);\n });\n }\n\n return this;\n }\n\n /**\n * Trigger all handlers for an event\n *\n * @param {String} event\n * @param {*...} [arguments]\n * @return {Event}\n */\n trigger(event /* , args... */) {\n const args = Array.prototype.slice.call(arguments, 1);\n const e = new Event(this, event, args);\n\n if (this.__events && event in this.__events) {\n for (let i = 0, l = this.__events[event].length; i < l; i++) {\n const f = this.__events[event][i];\n if (typeof f === 'object') {\n f.handleEvent(e);\n }\n else {\n f.call(this, e, ...args);\n }\n if (e.isPropagationStopped()) {\n break;\n }\n }\n }\n\n if (this.__once && event in this.__once) {\n for (let i = 0, l = this.__once[event].length; i < l; i++) {\n const f = this.__once[event][i];\n if (typeof f === 'object') {\n f.handleEvent(e);\n }\n else {\n f.call(this, e, ...args);\n }\n if (e.isPropagationStopped()) {\n break;\n }\n }\n delete this.__once[event];\n }\n\n return e;\n }\n\n /**\n * Trigger all modificators for an event, each handler must return a value\n *\n * @param {String} event\n * @param {*} value\n * @param {*...} [arguments]\n * @return {*} modified value\n */\n change(event, value /* , args... */) {\n const args = Array.prototype.slice.call(arguments, 2);\n const e = new Event(this, event, args);\n e.value = value;\n\n if (this.__events && event in this.__events) {\n for (let i = 0, l = this.__events[event].length; i < l; i++) {\n const f = this.__events[event][i];\n if (typeof f === 'object') {\n e.value = f.handleEvent(e);\n }\n else {\n e.value = f.call(this, e, e.value, ...args);\n }\n if (e.isPropagationStopped()) {\n break;\n }\n }\n }\n\n return e.value;\n }\n\n}\n\nmodule.exports = EventEmitter;\n","const EventEmitter = require('./src/EventEmitter');\nconst Event = require('./src/Event');\n\nfunction mixin(target) {\n target = typeof target === 'function' ? target.prototype : target;\n\n ['on', 'off', 'once', 'trigger', 'change'].forEach((name) => {\n target[name] = EventEmitter.prototype[name];\n });\n\n return target;\n}\n\nmodule.exports = {\n EventEmitter: EventEmitter,\n Event : Event,\n mixin : mixin,\n};\n"],"names":["returnTrue","returnFalse","Event","target","type","args","Object","defineProperties","get","set","enumerable","isDefaultPrevented","isPropagationStopped","preventDefault","stopPropagation","EventEmitter","on","events","callback","__events","event","hasOwnProperty","push","split","forEach","off","index","indexOf","splice","length","once","__once","trigger","Array","prototype","slice","call","arguments","e","i","l","f","handleEvent","change","value","mixin","name"],"mappings":";;;;;;;;;;;IAAA,IAAMA,UAAU,GAAG,SAAbA,UAAa,GAAM;IACrB,SAAO,IAAP;IACH,CAFD;;IAIA,IAAMC,WAAW,GAAG,SAAdA,WAAc,GAAM;IACtB,SAAO,KAAP;IACH,CAFD;;QAIMC;;IAGN;IACA;IACA;IACA;IACI,iBAAYC,MAAZ,EAAoBC,IAApB,EAA0BC,IAA1B,EAAgC;IAC5BC,IAAAA,MAAM,CAACC,gBAAP,CAAwB,IAAxB,EAA8B;IAC1B,gBAAU;IACNC,QAAAA,GAAG,EAAS,eAAM;IACd,iBAAOL,MAAP;IACH,SAHK;IAINM,QAAAA,GAAG,EAAS,eAAM,EAJZ;IAKNC,QAAAA,UAAU,EAAE;IALN,OADgB;IAQ1B,cAAU;IACNF,QAAAA,GAAG,EAAS,eAAM;IACd,iBAAOJ,IAAP;IACH,SAHK;IAINK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CqB,OAA3C,CAAmD,UAACsB,IAAD,EAAU;IACzD3C,IAAAA,MAAM,CAAC2C,IAAD,CAAN,GAAe/B,cAAY,CAACmB,SAAb,CAAuBY,IAAvB,CAAf;IACH,GAFD;IAIA,SAAO3C,MAAP;IACH;;cAEa,GAAG;IACbY,EAAAA,YAAY,EAAEA,cADD;IAEbb,EAAAA,KAAK,EAASA,OAFD;IAGb2C,EAAAA,KAAK,EAASA;IAHD;;;;;;;;;;;;;;;;"} \ No newline at end of file diff --git a/package.json b/package.json index 901a6ef..3ed4026 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "uevent", - "version": "2.1.0", + "version": "2.1.1", "description": "Event emitter micro library", "main": "index.js", "browser": "browser.js",