All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.dist.EventProvider.js.map Maven / Gradle / Ivy

{"version":3,"file":"EventProvider.js","sourceRoot":"","sources":["../src/EventProvider.ts"],"names":[],"mappings":"AAAA,MAAM,aAAa;IAGlB;QACC,IAAI,CAAC,cAAc,GAAG,IAAI,GAAG,EAAE,CAAC;IACjC,CAAC;IAED,WAAW,CAAC,SAAiB,EAAE,UAA8D;QAC5F,MAAM,aAAa,GAAG,IAAI,CAAC,cAAc,CAAC;QAC1C,MAAM,cAAc,GAAG,aAAa,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAEpD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE;YACnC,aAAa,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;YAC3C,OAAO;SACP;QAED,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE;YACzC,cAAc,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;SAChC;IACF,CAAC;IAED,WAAW,CAAC,SAAiB,EAAE,UAA8D;QAC5F,MAAM,aAAa,GAAG,IAAI,CAAC,cAAc,CAAC;QAC1C,MAAM,cAAc,GAAG,aAAa,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAEpD,IAAI,CAAC,cAAc,EAAE;YACpB,OAAO;SACP;QACD,MAAM,iBAAiB,GAAG,cAAc,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAE7D,IAAI,iBAAiB,KAAK,CAAC,CAAC,EAAE;YAC7B,cAAc,CAAC,MAAM,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC;SAC5C;QAED,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE;YAChC,aAAa,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;SAChC;IACF,CAAC;IAED;;;;;;OAMG;IACH,SAAS,CAAC,SAAiB,EAAE,IAAwB;QACpD,MAAM,aAAa,GAAG,IAAI,CAAC,cAAc,CAAC;QAC1C,MAAM,cAAc,GAAG,aAAa,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAEpD,IAAI,CAAC,cAAc,EAAE;YACpB,OAAO,EAAE,CAAC;SACV;QAED,OAAO,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;YAC9B,OAAO,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC5B,CAAC,CAAC,CAAC;IACJ,CAAC;IAED;;;;;;OAMG;IACH,cAAc,CAAC,SAAiB,EAAE,IAAwB;QACzD,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC;IACrD,CAAC;IAED,iBAAiB,CAAC,SAAiB,EAAE,UAA8D;QAClG,MAAM,aAAa,GAAG,IAAI,CAAC,cAAc,CAAC;QAC1C,MAAM,cAAc,GAAG,aAAa,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAEpD,IAAI,CAAC,cAAc,EAAE;YACpB,OAAO,KAAK,CAAC;SACb;QAED,OAAO,cAAc,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IAC5C,CAAC;IAED,YAAY,CAAC,SAAiB;QAC7B,OAAO,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAC7C,CAAC;CACD;AAED,eAAe,aAAa,CAAC","sourcesContent":["class EventProvider {\n\t_eventRegistry: Map EventListenerReturn>>;\n\n\tconstructor() {\n\t\tthis._eventRegistry = new Map();\n\t}\n\n\tattachEvent(eventName: string, fnFunction: (param: EventListenerParam) => EventListenerReturn) {\n\t\tconst eventRegistry = this._eventRegistry;\n\t\tconst eventListeners = eventRegistry.get(eventName);\n\n\t\tif (!Array.isArray(eventListeners)) {\n\t\t\teventRegistry.set(eventName, [fnFunction]);\n\t\t\treturn;\n\t\t}\n\n\t\tif (!eventListeners.includes(fnFunction)) {\n\t\t\teventListeners.push(fnFunction);\n\t\t}\n\t}\n\n\tdetachEvent(eventName: string, fnFunction: (param: EventListenerParam) => EventListenerReturn) {\n\t\tconst eventRegistry = this._eventRegistry;\n\t\tconst eventListeners = eventRegistry.get(eventName);\n\n\t\tif (!eventListeners) {\n\t\t\treturn;\n\t\t}\n\t\tconst indexOfFnToDetach = eventListeners.indexOf(fnFunction);\n\n\t\tif (indexOfFnToDetach !== -1) {\n\t\t\teventListeners.splice(indexOfFnToDetach, 1);\n\t\t}\n\n\t\tif (eventListeners.length === 0) {\n\t\t\teventRegistry.delete(eventName);\n\t\t}\n\t}\n\n\t/**\n\t * Fires an event and returns the results of all event listeners as an array.\n\t *\n\t * @param eventName the event to fire\n\t * @param data optional data to pass to each event listener\n\t * @returns {Array} an array with the results of all event listeners\n\t */\n\tfireEvent(eventName: string, data: EventListenerParam) {\n\t\tconst eventRegistry = this._eventRegistry;\n\t\tconst eventListeners = eventRegistry.get(eventName);\n\n\t\tif (!eventListeners) {\n\t\t\treturn [];\n\t\t}\n\n\t\treturn eventListeners.map(fn => {\n\t\t\treturn fn.call(this, data);\n\t\t});\n\t}\n\n\t/**\n\t * Fires an event and returns a promise that will resolve once all listeners have resolved.\n\t *\n\t * @param eventName the event to fire\n\t * @param data optional data to pass to each event listener\n\t * @returns {Promise} a promise that will resolve when all listeners have resolved\n\t */\n\tfireEventAsync(eventName: string, data: EventListenerParam) {\n\t\treturn Promise.all(this.fireEvent(eventName, data));\n\t}\n\n\tisHandlerAttached(eventName: string, fnFunction: (param: EventListenerParam) => EventListenerReturn) {\n\t\tconst eventRegistry = this._eventRegistry;\n\t\tconst eventListeners = eventRegistry.get(eventName);\n\n\t\tif (!eventListeners) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn eventListeners.includes(fnFunction);\n\t}\n\n\thasListeners(eventName: string) {\n\t\treturn !!this._eventRegistry.get(eventName);\n\t}\n}\n\nexport default EventProvider;\n"]}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy