forked from Jibo-Revival-Group/JiboOs
101 lines
3.2 KiB
JavaScript
101 lines
3.2 KiB
JavaScript
/**
|
|
* @description Interface for an event handler function
|
|
* @interface jibo.globalEvents.GlobalEvent~Handler
|
|
* @prop [data] Type
|
|
*/
|
|
|
|
/**
|
|
* @class GlobalEvent
|
|
* @description Typed global event for globalEvents module (`jibo.globalEvents`).
|
|
* In addition to subscribing to events, allows a special meta-subscribe
|
|
* event which fires whenever a listener is added and when the last listener
|
|
* is removed.
|
|
* ```
|
|
* event = new GlobalEvent<T>('name');
|
|
* function handler = (data) => {
|
|
* // data is of type asrResult
|
|
* // the ASR service has finished listening a cloud result
|
|
* // and all subscribed listeners will be removed
|
|
* }
|
|
* event.on(handler);
|
|
* // special meta-events like...
|
|
* event.onNoListeners( () => {
|
|
* // no listeners are subscribed to this event
|
|
* });
|
|
* // When finished with event listening
|
|
* event.removeLastListener();
|
|
* ```
|
|
* @memberof jibo.globalEvents
|
|
*/
|
|
|
|
/**
|
|
* Subscribes a handler for once no other listeners are subscribed.
|
|
* @method jibo.globalEvents.GlobalEvent#onNoListeners
|
|
* @return {jibo.globalEvents.GlobalEvent} This
|
|
*/
|
|
|
|
/**
|
|
* Emit that we have no subscribed listeners to all handlers.
|
|
* @method jibo.globalEvents.GlobalEvent#emitNoListeners
|
|
*/
|
|
|
|
/**
|
|
* Subscribes a handler for every time another listener subscribes.
|
|
* @method jibo.globalEvents.GlobalEvent#onAddedListener
|
|
* @return {jibo.globalEvents.GlobalEvent} This.
|
|
*/
|
|
|
|
/**
|
|
* Emit that we added a subscriber to the typed event.
|
|
* @method jibo.globalEvents.GlobalEvent#emitAddListener
|
|
*/
|
|
|
|
/**
|
|
* Subscribes a handler function to this event (same as `addListener`)
|
|
* @method jibo.globalEvents.GlobalEvent#on
|
|
* @return {jibo.globalEvents.GlobalEvent} This.
|
|
*/
|
|
|
|
/**
|
|
* Subscribes a handler function to only the next event
|
|
* @method jibo.globalEvents.GlobalEvent#once
|
|
* @return {jibo.globalEvents.GlobalEvent} This.
|
|
*/
|
|
|
|
/**
|
|
* Subscribes a handler function to this event (same as `on`)
|
|
* @method jibo.globalEvents.GlobalEvent#addListener
|
|
* @return {jibo.globalEvents.GlobalEvent} This.
|
|
*/
|
|
|
|
/**
|
|
* Unsubscribes a handler function from this event
|
|
* @method jibo.globalEvents.GlobalEvent#removeListener
|
|
* @param {jibo.globalEvents.GlobalEvent~Handler} handler Handler to unsubscribe.
|
|
* @return {jibo.globalEvents.GlobalEvent} This.
|
|
*/
|
|
|
|
/**
|
|
* Unsubscribes a handler function from this event (alias removeListener)
|
|
* @method jibo.globalEvents.GlobalEvent#off
|
|
* @param {jibo.globalEvents.GlobalEvent~Handler} handler Handler to unsubscribe.
|
|
* @return {jibo.globalEvents.GlobalEvent} This.
|
|
*/
|
|
|
|
/**
|
|
* Unsubscribes all handler functions from this event
|
|
* @method jibo.globalEvents.GlobalEvent#removeAllListeners
|
|
* @return {jibo.globalEvents.GlobalEvent} This.
|
|
*/
|
|
|
|
/**
|
|
* Unsubscribes oldest added subscriber
|
|
* @method jibo.globalEvents.GlobalEvent#removeFirstListener
|
|
* @return {jibo.globalEvents.GlobalEvent} This.
|
|
*/
|
|
|
|
/**
|
|
* Unsubscribes most recently added subscriber
|
|
* @method jibo.globalEvents.GlobalEvent#removeLastListener
|
|
* @return {jibo.globalEvents.GlobalEvent} This.
|
|
*/ |