@govflanders/vl-widget-event
Advanced tools
Comparing version 1.1.2 to 1.1.3
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var eventemitter2=require("eventemitter2"),vlWidgetUtility=require("@govflanders/vl-widget-utility");!function(t){t.Self="self",t.Broadcast="broadcast"}(exports.EventScope||(exports.EventScope={}));var defaults=function(t,e){for(var n=Object.getOwnPropertyNames(e),r=0;r<n.length;r++){var o=n[r],i=Object.getOwnPropertyDescriptor(e,o);i&&i.configurable&&void 0===t[o]&&Object.defineProperty(t,o,i)}return t},_extends=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},__extends=function(){var t=function(e,n){return(t=Object.setPrototypeOf||_extends({},[])instanceof Array&&function(t,e){defaults(t,e)}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();function suppressEventEmitter2UnhandledError(){}var EventEmitterBase=function(){function t(t){this.emitter=new eventemitter2.EventEmitter2(t),this.subscribedEventBroadcasts=[],this.eventLocks={},this.emitter.on("error",suppressEventEmitter2UnhandledError)}return t.prototype.hasEventLock=function(t){return!!this.eventLocks[t.getEventId()]},t.prototype.acquireEventLock=function(t){return this.eventLocks[t.getEventId()]=!0,this},t.prototype.releaseEventLock=function(t){return delete this.eventLocks[t.getEventId()],this},t.prototype.resolveEventBroadcast=function(t){var e=null;"function"==typeof t.getEventBroadcast?e=t.getEventBroadcast():"function"==typeof t&&(e=t);return e},t.prototype.createEventBroadcast=function(){var t=this;return function(e){return t.emit(e)}},t.prototype.getEventBroadcast=function(){return void 0===this.eventBroadcast&&(this.eventBroadcast=this.createEventBroadcast()),this.eventBroadcast},t.prototype.on=function(t,e){return this.addEventListener(t,e)},t.prototype.off=function(t,e){return this.removeEventListener(t,e)},t.prototype.once=function(t,e){return this.emitter.once(t,e),this},t.prototype.addEventListener=function(t,e){for(var n=0,r=Array.isArray(t)?t:[t];n<r.length;n++){var o=r[n];this.emitter.addListener(o,e)}return this},t.prototype.removeEventListener=function(t,e){for(var n=0,r=Array.isArray(t)?t:[t];n<r.length;n++){var o=r[n];this.emitter.removeListener(o,e)}return this},t.prototype.addEventBroadcast=function(t){var e=this.resolveEventBroadcast(t);return null!==e&&-1===this.subscribedEventBroadcasts.indexOf(e)&&this.subscribedEventBroadcasts.push(e),this},t.prototype.removeEventBroadcast=function(t){var e=this.resolveEventBroadcast(t);if(null!==e){var n=this.subscribedEventBroadcasts.indexOf(e);n>-1&&this.subscribedEventBroadcasts.slice(n,1)}return this},t.prototype.emit=function(t){var e=this;return new Promise(function(n,r){if(e.hasEventLock(t))n();else{e.acquireEventLock(t);var o=[e.emitter.emitAsync(t.getEventName(),t)];t.getEventScope()===exports.EventScope.Broadcast&&e.subscribedEventBroadcasts.forEach(function(e){o.push(e(t))}),Promise.all(o).then(function(){e.releaseEventLock(t),n()}).catch(function(n){e.releaseEventLock(t),r(n)})}})},t}(),defaultEventEmitterOptions={newListener:!1,maxListeners:0},DefaultEventEmitter=function(t){function e(e){return t.call(this,Object.assign({},defaultEventEmitterOptions,e))||this}return __extends(e,t),e}(EventEmitterBase),EventSourceBase=function(){function t(){}return t.prototype.createEventEmitter=function(){return new DefaultEventEmitter},t.prototype.getEventEmitter=function(){return void 0===this.eventEmitter&&(this.eventEmitter=this.createEventEmitter()),this.eventEmitter},t.prototype.getEventBroadcast=function(){return this.getEventEmitter().getEventBroadcast()},t.prototype.on=function(t,e){return this.getEventEmitter().on(t,e),this},t.prototype.off=function(t,e){return this.getEventEmitter().off(t,e),this},t.prototype.once=function(t,e){return this.getEventEmitter().once(t,e),this},t.prototype.addEventListener=function(t,e){return this.getEventEmitter().addEventListener(t,e),this},t.prototype.removeEventListener=function(t,e){return this.getEventEmitter().removeEventListener(t,e),this},t.prototype.addEventBroadcast=function(t){return this.getEventEmitter().addEventBroadcast(t),this},t.prototype.removeEventBroadcast=function(t){return this.getEventEmitter().removeEventBroadcast(t),this},t.prototype.emit=function(t){return this.getEventEmitter().emit(t)},t}(),EventBase=function(){function t(t,e,n){void 0===n&&(n=exports.EventScope.Broadcast),this.eventId=vlWidgetUtility.Uuid.generate(),this.eventName=t,this.sender=e,this.eventScope=n}return t.prototype.getEventId=function(){return this.eventId},t.prototype.getEventScope=function(){return this.eventScope},t.prototype.getEventName=function(){return this.eventName},t.prototype.getSender=function(){return this.sender},t.prototype.rename=function(t){var e=Object.create(this);return e.eventName=t,e},t.prototype.prefix=function(t){var e=this.getEventName();return t.length>0&&(e=t+"."+e),this.rename(e)},t.prototype.suffix=function(t){var e=this.getEventName();return t.length>0&&(e=e+"."+t),this.rename(e)},t}();exports.EventEmitterBase=EventEmitterBase,exports.defaultEventEmitterOptions=defaultEventEmitterOptions,exports.DefaultEventEmitter=DefaultEventEmitter,exports.EventSourceBase=EventSourceBase,exports.EventBase=EventBase; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var eventemitter2=require("eventemitter2"),vlWidgetUtility=require("@govflanders/vl-widget-utility");!function(t){t.Self="self",t.Broadcast="broadcast"}(exports.EventScope||(exports.EventScope={}));var defaults=function(t,e){for(var n=Object.getOwnPropertyNames(e),r=0;r<n.length;r++){var o=n[r],i=Object.getOwnPropertyDescriptor(e,o);i&&i.configurable&&void 0===t[o]&&Object.defineProperty(t,o,i)}return t},_extends=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},__extends=function(){var t=function(e,n){return(t=Object.setPrototypeOf||_extends({},[])instanceof Array&&function(t,e){defaults(t,e)}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();function suppressEventEmitter2UnhandledError(){}var EventEmitterBase=function(){function t(t){this.emitter=new eventemitter2.EventEmitter2(t),this.subscribedEventBroadcasts=[],this.eventLocks={},this.emitter.on("error",suppressEventEmitter2UnhandledError)}return t.prototype.hasEventLock=function(t){return!!this.eventLocks[t.getEventId()]},t.prototype.acquireEventLock=function(t){return this.eventLocks[t.getEventId()]=!0,this},t.prototype.releaseEventLock=function(t){return delete this.eventLocks[t.getEventId()],this},t.prototype.resolveEventBroadcast=function(t){var e=null;"function"==typeof t.getEventBroadcast?e=t.getEventBroadcast():"function"==typeof t&&(e=t);return e},t.prototype.createEventBroadcast=function(){var t=this;return function(e){return t.emit(e)}},t.prototype.getEventBroadcast=function(){return void 0===this.eventBroadcast&&(this.eventBroadcast=this.createEventBroadcast()),this.eventBroadcast},t.prototype.on=function(t,e){return this.addEventListener(t,e)},t.prototype.off=function(t,e){return this.removeEventListener(t,e)},t.prototype.once=function(t,e){return this.emitter.once(t,e),this},t.prototype.addEventListener=function(t,e){for(var n=0,r=Array.isArray(t)?t:[t];n<r.length;n++){var o=r[n];this.emitter.addListener(o,e)}return this},t.prototype.removeEventListener=function(t,e){for(var n=0,r=Array.isArray(t)?t:[t];n<r.length;n++){var o=r[n];this.emitter.removeListener(o,e)}return this},t.prototype.addEventBroadcast=function(t){var e=this.resolveEventBroadcast(t);return null!==e&&-1===this.subscribedEventBroadcasts.indexOf(e)&&this.subscribedEventBroadcasts.push(e),this},t.prototype.removeEventBroadcast=function(t){var e=this.resolveEventBroadcast(t);if(null!==e){var n=this.subscribedEventBroadcasts.indexOf(e);n>-1&&this.subscribedEventBroadcasts.slice(n,1)}return this},t.prototype.emit=function(t){var e=this;return new Promise(function(n,r){if(e.hasEventLock(t))n();else{e.acquireEventLock(t);var o=[e.emitter.emitAsync(t.getEventName(),t)];t.getEventScope()===exports.EventScope.Broadcast&&e.subscribedEventBroadcasts.forEach(function(e){o.push(e(t))}),Promise.all(o).then(function(){e.releaseEventLock(t),n()}).catch(function(n){e.releaseEventLock(t),r(n)})}})},t}(),defaultEventEmitterOptions={newListener:!1,maxListeners:0},DefaultEventEmitter=function(t){function e(e){return t.call(this,Object.assign({},defaultEventEmitterOptions,e))||this}return __extends(e,t),e}(EventEmitterBase),EventSourceBase=function(){function t(){}return t.prototype.createEventEmitter=function(){return new DefaultEventEmitter},t.prototype.getEventEmitter=function(){return void 0===this.eventEmitter&&(this.eventEmitter=this.createEventEmitter()),this.eventEmitter},t.prototype.getEventBroadcast=function(){return this.getEventEmitter().getEventBroadcast()},t.prototype.on=function(t,e){return this.getEventEmitter().on(t,e),this},t.prototype.off=function(t,e){return this.getEventEmitter().off(t,e),this},t.prototype.once=function(t,e){return this.getEventEmitter().once(t,e),this},t.prototype.addEventListener=function(t,e){return this.getEventEmitter().addEventListener(t,e),this},t.prototype.removeEventListener=function(t,e){return this.getEventEmitter().removeEventListener(t,e),this},t.prototype.addEventBroadcast=function(t){return this.getEventEmitter().addEventBroadcast(t),this},t.prototype.removeEventBroadcast=function(t){return this.getEventEmitter().removeEventBroadcast(t),this},t.prototype.emit=function(t){return this.getEventEmitter().emit(t)},t}(),__extends$1=function(){var t=function(e,n){return(t=Object.setPrototypeOf||_extends({},[])instanceof Array&&function(t,e){defaults(t,e)}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),EventBase=function(){function t(t,e,n){void 0===n&&(n=exports.EventScope.Broadcast),this.eventId=vlWidgetUtility.Uuid.generate(),this.eventName=t,this.sender=e,this.eventScope=n}return t.prototype.getEventId=function(){return this.eventId},t.prototype.getEventScope=function(){return this.eventScope},t.prototype.getEventName=function(){return this.eventName},t.prototype.getSender=function(){return this.sender},t.prototype.rename=function(t){var e=Object.create(this);return e.eventName=t,e},t.prototype.prefix=function(t){var e=this.getEventName();return t.length>0&&(e=t+"."+e),this.rename(e)},t.prototype.suffix=function(t){var e=this.getEventName();return t.length>0&&(e=e+"."+t),this.rename(e)},t}(),CustomEvent=function(t){function e(e,n,r,o){void 0===o&&(o=exports.EventScope.Broadcast);var i=t.call(this,e,n,o)||this;return i.eventData=r,i}return __extends$1(e,t),e.prototype.getEventData=function(){return this.eventData},e}(EventBase);exports.EventEmitterBase=EventEmitterBase,exports.defaultEventEmitterOptions=defaultEventEmitterOptions,exports.DefaultEventEmitter=DefaultEventEmitter,exports.EventSourceBase=EventSourceBase,exports.EventBase=EventBase,exports.CustomEvent=CustomEvent; |
{ | ||
"name": "@govflanders/vl-widget-event", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"license": "MIT", | ||
@@ -27,3 +27,3 @@ "contributors": [ | ||
"dependencies": { | ||
"@govflanders/vl-widget-utility": "^1.1.2", | ||
"@govflanders/vl-widget-utility": "^1.1.3", | ||
"eventemitter2": "5.0.1" | ||
@@ -47,3 +47,3 @@ }, | ||
}, | ||
"gitHead": "3a302c23ab969147b7b40fd866ce931ce6fcf190" | ||
"gitHead": "fc6783d33d6179919fc26f81c6324d584d1a9fec" | ||
} |
@@ -133,1 +133,35 @@ import { EventScope } from './event-scope'; | ||
} | ||
/** | ||
* Implementation which provides raw data support for an event. | ||
* | ||
* The usage of this event class should be limited as it allow API's to dynamically change | ||
* the API contract. | ||
*/ | ||
export declare class CustomEvent<SenderType = any, EventDataType = any> extends EventBase<SenderType> { | ||
/** | ||
* Holds the event data in a raw format. | ||
* | ||
* @var {EventDataType|undefined} | ||
*/ | ||
protected eventData: EventDataType | undefined; | ||
/** | ||
* Create a EventBase object. | ||
* | ||
* @param {string} eventName | ||
* The event name. | ||
* @param {SenderType} sender | ||
* Sender of the event. | ||
* @param {EventDataType} [eventData=undefined] | ||
* Optional. Unstructured data which should be attached. | ||
* @param {EventScope} [eventScope=EventScope.Broadcast] | ||
* Optional. Scope of the event. Defaults to broadcast. | ||
*/ | ||
constructor(eventName: string, sender: SenderType, eventData?: EventDataType, eventScope?: EventScope); | ||
/** | ||
* Get the event data. | ||
* | ||
* @return {EventDataType|undefined} | ||
* Data attached to the event. | ||
*/ | ||
getEventData(): EventDataType | undefined; | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22640
554