-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
104 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/** | ||
* @name Evemit | ||
* @description Minimal and fast JavaScript event emitter for Node.js and front-end. | ||
* @author Nicolas Tallefourtane <[email protected]> | ||
* @link https://github.com/Nicolab/evemit | ||
* @license MIT https://github.com/Nicolab/evemit/blob/master/LICENSE | ||
*/ | ||
|
||
declare module 'evemit' { | ||
class Evemit { | ||
/** | ||
* Events object. | ||
*/ | ||
events: Record<string, Function[]>; | ||
|
||
/** | ||
* Evemit | ||
* | ||
* @constructor | ||
* @api public | ||
*/ | ||
constructor(); | ||
|
||
/** | ||
* Register a new event listener for a given event. | ||
* | ||
* @param {string} event Event name. | ||
* @param {function} fn Callback function (listener). | ||
* @param {*} [context] Context for function execution. | ||
* @return {Evemit} Current instance. | ||
* @api public | ||
*/ | ||
on(event: string, fn: Function, context?: any): this; | ||
|
||
/** | ||
* Add an event listener that's only called once. | ||
* | ||
* @param {string} event Event name. | ||
* @param {function} fn Callback function (listener). | ||
* @param {*} [context] Context for function execution. | ||
* @return {Evemit} Current instance. | ||
* @api public | ||
*/ | ||
once(event: string, fn: Function, context?: any): this; | ||
|
||
/** | ||
* Emit an event to all registered event listeners. | ||
* | ||
* @param {string} event Event name. | ||
* @param {*} [...arg] One or more arguments to pass to the listeners. | ||
* @return {bool} Indication, `true` if at least one listener was executed, | ||
* otherwise returns `false`. | ||
* @api public | ||
*/ | ||
emit(event: string, ...args: any[]): boolean; | ||
|
||
/** | ||
* Remove event listeners. | ||
* | ||
* @param {string} event The event to remove. | ||
* @param {function} fn The listener that we need to find. | ||
* @return {Evemit} Current instance. | ||
* @api public | ||
*/ | ||
off(event: string, fn: Function): this; | ||
|
||
/** | ||
* Get a list of assigned event listeners. | ||
* | ||
* @param {string} [event] The events that should be listed. | ||
* If not provided, all listeners are returned. | ||
* Use the property `Evemit.events` if you want to get an object like | ||
* ``` | ||
* {event1: [array of listeners], event2: [array of listeners], ...} | ||
* ``` | ||
* | ||
* @return {array} | ||
* @api public | ||
*/ | ||
listeners(event?: string): Function[]; | ||
} | ||
|
||
export = Evemit; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters