From a035c7bd16c700eaf16822e916ecfc9eebce7510 Mon Sep 17 00:00:00 2001 From: Jackson Date: Thu, 22 Jul 2021 14:07:49 -0500 Subject: [PATCH] update bundled files --- dist/eventra.js | 58 +++++++++++++++++++++++++++++++++++++++++---- dist/eventra.min.js | 2 +- 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/dist/eventra.js b/dist/eventra.js index 0b2a430..c33ad67 100644 --- a/dist/eventra.js +++ b/dist/eventra.js @@ -17,13 +17,25 @@ class Eventra { constructor() { this._listeners = new ListenerArray_1.default({ mode: "recurring" }); this._singularListeners = new ListenerArray_1.default({ mode: "once" }); + /** + * Alias for `Eventra.on` + */ this.addListener = this.on; + /** + * Alias for `Eventra.removeListener` + */ this.off = this.removeListener; } + /** + * Synchronously calls each of the listeners registered for the event, in the order they were registered, passing the supplied arguments to each. + */ emit(event, ...args) { this._listeners.executeEvent(event, ...args); this._singularListeners.executeEvent(event, ...args); } + /** + * Returns an array listing the events for which the emitter has registered listeners. + */ eventNames() { let finalNamesArray = []; this._listeners.storage.map((val, key) => { @@ -36,11 +48,17 @@ class Eventra { }); return finalNamesArray; } + /** + * Returns the number of listeners listening to the event. + */ listenerCount(eventName) { const recurring = this._listeners.countListeners(eventName); const singular = this._singularListeners.countListeners(eventName); return (recurring + singular); } + /** + * Returns a copy of the array of listeners for the event. + */ listeners(eventName) { let recurring = this._listeners.fetchListeners(eventName); let singular = this._singularListeners.fetchListeners(eventName); @@ -49,22 +67,49 @@ class Eventra { singular }; } + /** + * Adds the listener function to the end of the listeners array for the event. + * + * Returns a reference to the eventra instance, so that calls can be chained. + */ on(eventName, listener) { this._listeners.add(eventName, listener); - return; + return this; } + /** + * Adds a one-time listener function for the event. + * The next time the event is triggered, this listener is removed and then invoked. + * + * Returns a reference to the eventra instance, so that calls can be chained. + */ once(eventName, listener) { this._singularListeners.add(eventName, listener); - return; + return this; } + /** + * Adds the listener function to the beginning of the listeners array for the event. + * + * Returns a reference to the eventra instance, so that calls can be chained. + */ prependListener(eventName, listener) { this._listeners.prepend(eventName, listener); - return; + return this; } + /** + * Adds a one-time listener function for the event to the beginning of the listeners array. + * The next time the event is triggered, this listener is removed, and then invoked. + * + * Returns a reference to the eventra instance, so that calls can be chained. + */ prependOnceListener(eventName, listener) { this._singularListeners.prepend(eventName, listener); - return; + return this; } + /** + * Removes all listeners, or those of the specified event(s). + * + * Returns a reference to the eventra instance, so that calls can be chained. + */ removeAllListeners(...eventName) { const listeners = [...eventName]; listeners.map(en => { @@ -73,6 +118,11 @@ class Eventra { }); return this; } + /** + * Removes the specified listener from the listener array for the event. + * + * Returns a reference to the eventra instance, so that calls can be chained. + */ removeListener(eventName, listener) { this._listeners.removeListener(eventName, listener); this._singularListeners.removeListener(eventName, listener); diff --git a/dist/eventra.min.js b/dist/eventra.min.js index ec1d74a..1544cfd 100644 --- a/dist/eventra.min.js +++ b/dist/eventra.min.js @@ -1 +1 @@ -var Eventra;(()=>{"use strict";var t={568:function(t,e,r){var s=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.Eventra=void 0;const n=s(r(351));e.Eventra=class{constructor(){this._listeners=new n.default({mode:"recurring"}),this._singularListeners=new n.default({mode:"once"}),this.addListener=this.on,this.off=this.removeListener}emit(t,...e){this._listeners.executeEvent(t,...e),this._singularListeners.executeEvent(t,...e)}eventNames(){let t=[];return this._listeners.storage.map(((e,r)=>{t.includes(r)||t.push(r)})),this._singularListeners.storage.map(((e,r)=>{t.includes(r)||t.push(r)})),t}listenerCount(t){return this._listeners.countListeners(t)+this._singularListeners.countListeners(t)}listeners(t){return{recurring:this._listeners.fetchListeners(t),singular:this._singularListeners.fetchListeners(t)}}on(t,e){this._listeners.add(t,e)}once(t,e){this._singularListeners.add(t,e)}prependListener(t,e){this._listeners.prepend(t,e)}prependOnceListener(t,e){this._singularListeners.prepend(t,e)}removeAllListeners(...t){return[...t].map((t=>{this._listeners.removeEvent(t),this._singularListeners.removeEvent(t)})),this}removeListener(t,e){return this._listeners.removeListener(t,e),this._singularListeners.removeListener(t,e),this}}},351:function(t,e,r){var s=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const n=s(r(286));e.default=class{constructor(t){this._internalStorage=new n.default,this._options=t||{mode:"recurring"}}get mode(){return this._options.mode}get storage(){return this._internalStorage}_updateInternalStorage(t){t&&(this._internalStorage=t)}_cloneInternalStorage(){return this._internalStorage.clone()}add(t,e){let r=this._cloneInternalStorage(),s=r.get(t);return s?(s.push(e),this._updateInternalStorage(r),this):(r.set(t,[e]),this._updateInternalStorage(r),this)}prepend(t,e){let r=this._cloneInternalStorage(),s=r.get(t);return s?(s.unshift(e),this._updateInternalStorage(r),this):(r.set(t,[e]),this._updateInternalStorage(r),this)}removeListener(t,e){let r=this._cloneInternalStorage(),s=r.get(t);if(!s)return this;if(!s.includes(e))return this;if(1==s.length)return r.delete(t),this._updateInternalStorage(r),this;const n=s.indexOf(e);return n>-1&&s.splice(n,1),this._updateInternalStorage(r),this}removeEvent(t){let e=this._cloneInternalStorage();return e.get(t)?(e.delete(t),this._updateInternalStorage(e),this):this}countListeners(t){const e=this._internalStorage.get(t);return e?e.length:0}fetchListeners(t){return this._internalStorage.get(t)||[]}executeEvent(t,...e){let r=this._cloneInternalStorage(),s=r.get(t);return s?(s.map(((t,r)=>{t(...e)})),"once"==this.mode&&r.delete(t),this._updateInternalStorage(r),this):this}}},286:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Collection=void 0;class r extends Map{get(t){return super.get(t)}set(t,e){return super.set(t,e)}has(t){return super.has(t)}delete(t){return super.delete(t)}clear(){return super.clear()}hasAll(...t){return t.every((t=>super.has(t)))}hasAny(...t){return t.some((t=>super.has(t)))}first(t){if(void 0===t)return this.values().next().value;if(t<0)return this.last(-1*t);t=Math.min(this.size,t);const e=this.values();return Array.from({length:t},(()=>e.next().value))}firstKey(t){if(void 0===t)return this.keys().next().value;if(t<0)return this.lastKey(-1*t);t=Math.min(this.size,t);const e=this.keys();return Array.from({length:t},(()=>e.next().value))}last(t){const e=[...this.values()];return void 0===t?e[e.length-1]:t<0?this.first(-1*t):t?e.slice(-t):[]}lastKey(t){const e=[...this.keys()];return void 0===t?e[e.length-1]:t<0?this.firstKey(-1*t):t?e.slice(-t):[]}random(t){const e=[...this.values()];return void 0===t?e[Math.floor(Math.random()*e.length)]:e.length&&t?Array.from({length:Math.min(t,e.length)},(()=>e.splice(Math.floor(Math.random()*e.length),1)[0])):[]}randomKey(t){const e=[...this.keys()];return void 0===t?e[Math.floor(Math.random()*e.length)]:e.length&&t?Array.from({length:Math.min(t,e.length)},(()=>e.splice(Math.floor(Math.random()*e.length),1)[0])):[]}find(t,e){void 0!==e&&(t=t.bind(e));for(const[e,r]of this)if(t(r,e,this))return r}findKey(t,e){void 0!==e&&(t=t.bind(e));for(const[e,r]of this)if(t(r,e,this))return e}sweep(t,e){void 0!==e&&(t=t.bind(e));const r=this.size;for(const[e,r]of this)t(r,e,this)&&this.delete(e);return r-this.size}filter(t,e){void 0!==e&&(t=t.bind(e));const r=new this.constructor[Symbol.species];for(const[e,s]of this)t(s,e,this)&&r.set(e,s);return r}partition(t,e){void 0!==e&&(t=t.bind(e));const r=[new this.constructor[Symbol.species],new this.constructor[Symbol.species]];for(const[e,s]of this)t(s,e,this)?r[0].set(e,s):r[1].set(e,s);return r}flatMap(t,e){const r=this.map(t,e);return(new this.constructor[Symbol.species]).concat(...r)}map(t,e){void 0!==e&&(t=t.bind(e));const r=this.entries();return Array.from({length:this.size},(()=>{const[e,s]=r.next().value;return t(s,e,this)}))}mapValues(t,e){void 0!==e&&(t=t.bind(e));const r=new this.constructor[Symbol.species];for(const[e,s]of this)r.set(e,t(s,e,this));return r}some(t,e){void 0!==e&&(t=t.bind(e));for(const[e,r]of this)if(t(r,e,this))return!0;return!1}every(t,e){void 0!==e&&(t=t.bind(e));for(const[e,r]of this)if(!t(r,e,this))return!1;return!0}reduce(t,e){let r;if(void 0!==e){r=e;for(const[e,s]of this)r=t(r,s,e,this);return r}let s=!0;for(const[e,n]of this)s?(r=n,s=!1):r=t(r,n,e,this);if(s)throw new TypeError("Reduce of empty collection with no initial value");return r}each(t,e){return this.forEach(t,e),this}tap(t,e){return void 0!==e&&(t=t.bind(e)),t(this),this}clone(){return new this.constructor[Symbol.species](this)}concat(...t){const e=this.clone();for(const r of t)for(const[t,s]of r)e.set(t,s);return e}equals(t){if(!t)return!1;if(this===t)return!0;if(this.size!==t.size)return!1;for(const[e,r]of this)if(!t.has(e)||r!==t.get(e))return!1;return!0}sort(t=r.defaultSort){const e=[...this.entries()];e.sort(((e,r)=>t(e[1],r[1],e[0],r[0]))),super.clear();for(const[t,r]of e)super.set(t,r);return this}intersect(t){const e=new this.constructor[Symbol.species];for(const[r,s]of t)this.has(r)&&e.set(r,s);return e}difference(t){const e=new this.constructor[Symbol.species];for(const[r,s]of t)this.has(r)||e.set(r,s);for(const[r,s]of this)t.has(r)||e.set(r,s);return e}sorted(t=r.defaultSort){return new this.constructor[Symbol.species](this).sort(((e,r,s,n)=>t(e,r,s,n)))}static defaultSort(t,e){return Number(t>e)||Number(t===e)-1}}e.Collection=r,r.default=r,e.default=r}},e={},r=function r(s){var n=e[s];if(void 0!==n)return n.exports;var i=e[s]={exports:{}};return t[s].call(i.exports,i,i.exports,r),i.exports}(568);Eventra=r})(); \ No newline at end of file +var Eventra;(()=>{"use strict";var t={568:function(t,e,r){var s=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.Eventra=void 0;const n=s(r(351));e.Eventra=class{constructor(){this._listeners=new n.default({mode:"recurring"}),this._singularListeners=new n.default({mode:"once"}),this.addListener=this.on,this.off=this.removeListener}emit(t,...e){this._listeners.executeEvent(t,...e),this._singularListeners.executeEvent(t,...e)}eventNames(){let t=[];return this._listeners.storage.map(((e,r)=>{t.includes(r)||t.push(r)})),this._singularListeners.storage.map(((e,r)=>{t.includes(r)||t.push(r)})),t}listenerCount(t){return this._listeners.countListeners(t)+this._singularListeners.countListeners(t)}listeners(t){return{recurring:this._listeners.fetchListeners(t),singular:this._singularListeners.fetchListeners(t)}}on(t,e){return this._listeners.add(t,e),this}once(t,e){return this._singularListeners.add(t,e),this}prependListener(t,e){return this._listeners.prepend(t,e),this}prependOnceListener(t,e){return this._singularListeners.prepend(t,e),this}removeAllListeners(...t){return[...t].map((t=>{this._listeners.removeEvent(t),this._singularListeners.removeEvent(t)})),this}removeListener(t,e){return this._listeners.removeListener(t,e),this._singularListeners.removeListener(t,e),this}}},351:function(t,e,r){var s=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const n=s(r(286));e.default=class{constructor(t){this._internalStorage=new n.default,this._options=t||{mode:"recurring"}}get mode(){return this._options.mode}get storage(){return this._internalStorage}_updateInternalStorage(t){t&&(this._internalStorage=t)}_cloneInternalStorage(){return this._internalStorage.clone()}add(t,e){let r=this._cloneInternalStorage(),s=r.get(t);return s?(s.push(e),this._updateInternalStorage(r),this):(r.set(t,[e]),this._updateInternalStorage(r),this)}prepend(t,e){let r=this._cloneInternalStorage(),s=r.get(t);return s?(s.unshift(e),this._updateInternalStorage(r),this):(r.set(t,[e]),this._updateInternalStorage(r),this)}removeListener(t,e){let r=this._cloneInternalStorage(),s=r.get(t);if(!s)return this;if(!s.includes(e))return this;if(1==s.length)return r.delete(t),this._updateInternalStorage(r),this;const n=s.indexOf(e);return n>-1&&s.splice(n,1),this._updateInternalStorage(r),this}removeEvent(t){let e=this._cloneInternalStorage();return e.get(t)?(e.delete(t),this._updateInternalStorage(e),this):this}countListeners(t){const e=this._internalStorage.get(t);return e?e.length:0}fetchListeners(t){return this._internalStorage.get(t)||[]}executeEvent(t,...e){let r=this._cloneInternalStorage(),s=r.get(t);return s?(s.map(((t,r)=>{t(...e)})),"once"==this.mode&&r.delete(t),this._updateInternalStorage(r),this):this}}},286:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Collection=void 0;class r extends Map{get(t){return super.get(t)}set(t,e){return super.set(t,e)}has(t){return super.has(t)}delete(t){return super.delete(t)}clear(){return super.clear()}hasAll(...t){return t.every((t=>super.has(t)))}hasAny(...t){return t.some((t=>super.has(t)))}first(t){if(void 0===t)return this.values().next().value;if(t<0)return this.last(-1*t);t=Math.min(this.size,t);const e=this.values();return Array.from({length:t},(()=>e.next().value))}firstKey(t){if(void 0===t)return this.keys().next().value;if(t<0)return this.lastKey(-1*t);t=Math.min(this.size,t);const e=this.keys();return Array.from({length:t},(()=>e.next().value))}last(t){const e=[...this.values()];return void 0===t?e[e.length-1]:t<0?this.first(-1*t):t?e.slice(-t):[]}lastKey(t){const e=[...this.keys()];return void 0===t?e[e.length-1]:t<0?this.firstKey(-1*t):t?e.slice(-t):[]}random(t){const e=[...this.values()];return void 0===t?e[Math.floor(Math.random()*e.length)]:e.length&&t?Array.from({length:Math.min(t,e.length)},(()=>e.splice(Math.floor(Math.random()*e.length),1)[0])):[]}randomKey(t){const e=[...this.keys()];return void 0===t?e[Math.floor(Math.random()*e.length)]:e.length&&t?Array.from({length:Math.min(t,e.length)},(()=>e.splice(Math.floor(Math.random()*e.length),1)[0])):[]}find(t,e){void 0!==e&&(t=t.bind(e));for(const[e,r]of this)if(t(r,e,this))return r}findKey(t,e){void 0!==e&&(t=t.bind(e));for(const[e,r]of this)if(t(r,e,this))return e}sweep(t,e){void 0!==e&&(t=t.bind(e));const r=this.size;for(const[e,r]of this)t(r,e,this)&&this.delete(e);return r-this.size}filter(t,e){void 0!==e&&(t=t.bind(e));const r=new this.constructor[Symbol.species];for(const[e,s]of this)t(s,e,this)&&r.set(e,s);return r}partition(t,e){void 0!==e&&(t=t.bind(e));const r=[new this.constructor[Symbol.species],new this.constructor[Symbol.species]];for(const[e,s]of this)t(s,e,this)?r[0].set(e,s):r[1].set(e,s);return r}flatMap(t,e){const r=this.map(t,e);return(new this.constructor[Symbol.species]).concat(...r)}map(t,e){void 0!==e&&(t=t.bind(e));const r=this.entries();return Array.from({length:this.size},(()=>{const[e,s]=r.next().value;return t(s,e,this)}))}mapValues(t,e){void 0!==e&&(t=t.bind(e));const r=new this.constructor[Symbol.species];for(const[e,s]of this)r.set(e,t(s,e,this));return r}some(t,e){void 0!==e&&(t=t.bind(e));for(const[e,r]of this)if(t(r,e,this))return!0;return!1}every(t,e){void 0!==e&&(t=t.bind(e));for(const[e,r]of this)if(!t(r,e,this))return!1;return!0}reduce(t,e){let r;if(void 0!==e){r=e;for(const[e,s]of this)r=t(r,s,e,this);return r}let s=!0;for(const[e,n]of this)s?(r=n,s=!1):r=t(r,n,e,this);if(s)throw new TypeError("Reduce of empty collection with no initial value");return r}each(t,e){return this.forEach(t,e),this}tap(t,e){return void 0!==e&&(t=t.bind(e)),t(this),this}clone(){return new this.constructor[Symbol.species](this)}concat(...t){const e=this.clone();for(const r of t)for(const[t,s]of r)e.set(t,s);return e}equals(t){if(!t)return!1;if(this===t)return!0;if(this.size!==t.size)return!1;for(const[e,r]of this)if(!t.has(e)||r!==t.get(e))return!1;return!0}sort(t=r.defaultSort){const e=[...this.entries()];e.sort(((e,r)=>t(e[1],r[1],e[0],r[0]))),super.clear();for(const[t,r]of e)super.set(t,r);return this}intersect(t){const e=new this.constructor[Symbol.species];for(const[r,s]of t)this.has(r)&&e.set(r,s);return e}difference(t){const e=new this.constructor[Symbol.species];for(const[r,s]of t)this.has(r)||e.set(r,s);for(const[r,s]of this)t.has(r)||e.set(r,s);return e}sorted(t=r.defaultSort){return new this.constructor[Symbol.species](this).sort(((e,r,s,n)=>t(e,r,s,n)))}static defaultSort(t,e){return Number(t>e)||Number(t===e)-1}}e.Collection=r,r.default=r,e.default=r}},e={},r=function r(s){var n=e[s];if(void 0!==n)return n.exports;var i=e[s]={exports:{}};return t[s].call(i.exports,i,i.exports,r),i.exports}(568);Eventra=r})(); \ No newline at end of file