Giter Site home page Giter Site logo

emitter.mjs's Introduction

Emitter.mjs

CodeQL Test Pass Coverage Status JavaScript Style Guide Conventional Commits

Using the observer pattern, define listeners in your class

Which is?

The Observer is a behavioral design pattern that allows you to define a signature mechanism to notify multiple objects about any events that happen to the object they are watching.

Interfaces

/**
 * @constructor
 * @throws {TypeError} Invalid maxListeners
 */
Emitter(maxListeners?: number = 10)
// Getters
eventNames(): string[]
maxListeners(): number
// Setters
/**
 * This is a useful default that helps finding memory leaks. The value must be contained in [0,+โˆž) and can be set to Infinity (or 0) to indicate an unlimited number of listeners.
 * @throws {TypeError} Invalid maxListeners
 */
maxListeners(maxListeners?: number = 10): void // https://nodejs.org/api/events.html#emittersetmaxlistenersn
/**
 * @method
 * @throws {TypeError} Invalid eventName
 */
emit(eventName: string, ...args: any[]): Promise<boolean>

/**
 * @method
 * @throws {TypeError} Invalid eventName
 * @throws {TypeError} Invalid listener
 * @throws {Error} Memory leak detected
 */
addListener(eventName: string, callback: Function): Emitter

/**
 * @method
 * @throws {TypeError} Invalid eventName
 * @throws {TypeError} Invalid listener
 */
listenerCount(eventName: string, callback?: Function): number

/**
 * @method
 * @throws {TypeError} Invalid eventName
 */
listeners(eventName: string): Function[]

/**
 * @method
 * @throws {TypeError} Invalid eventName
 * @throws {TypeError} Invalid listener
 */
off(eventName: string, callback: Function): Emitter // Alias for removeListener

/**
 * @method
 * @throws {TypeError} Invalid eventName
 * @throws {TypeError} Invalid listener
 * @throws {Error} Memory leak detected
 */
on(eventName: string, callback: Function): Emitter // Alias for addListener

/**
 * @method
 * @throws {TypeError} Invalid eventName
 * @throws {TypeError} Invalid listener
 * @throws {Error} Memory leak detected
 */
once(eventName: string, callback: Function): Emitter

/**
 * @method
 * @throws {TypeError} Invalid eventName
 * @throws {TypeError} Invalid listener
 * @throws {Error} Memory leak detected
 */
prependListener(eventName: string, callback: Function): Emitter

/**
 * @method
 * @throws {TypeError} Invalid eventName
 * @throws {TypeError} Invalid listener
 * @throws {Error} Memory leak detected
 */
prependOnceListener(eventName: string, callback: Function): Emitter

/**
 * @method
 * @throws {TypeError} Invalid eventName
 */
removeAllListeners(eventName?: string): Emitter

/**
 * @method
 * @throws {TypeError} Invalid eventName
 * @throws {TypeError} Invalid listener
 */
removeListener(eventName: string, callback: Function): Emitter

/**
 * @method
 * @throws {TypeError} Invalid eventName
 */
rawListeners(eventName: string): Function[]

Specifications

We strive to maintain complete code coverage in tests. With that, we provide all the necessary use cases for a good understanding of how this module works. See: test/Emitter.spec.js

emitter.mjs's People

Contributors

jadsonlucena avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.