Skip to content
This repository was archived by the owner on May 11, 2021. It is now read-only.

aelliott1485/emitter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

emitter Build Status

This Event Emitter module allows one or more functions to be attached to named events and those named events to be emitted.

Check out the Code Review for feedback by community members.

This was originally created in 2018.


Installation

First, clone the repository:

$ git clone https://github.com/aelliott1485/emitter.git

Then go into the local directory for the repository:

$ cd emitter

Next install the dependencies (e.g. test frameworks)

$ npm install

Then the tests can be run to ensure it works as expected:

$ npm test

Example:

var emitter = new EventEmitter();
//register the handler function (defined below)
emitter.on('sent', receive);
//later, emit the event and pass data, which will be sent to the handler function(s)
emitter.emit('sent', {"foo": "bar"});

function receive(data) {
  //handle data
}

API

emitter.emit(eventName[, ...args])

Emits a named event with any number of arguments.

emitter.on(eventName, callback)

Registers a handler function to be called whenever the named event is emitted.

emitter.once(eventName, callback)

Registers a handler function to only be called the first time the named event is emitted.

emitter.off(eventName[, callback])

Removes a specific previously-registered event handler and/or all previously-registered event handlers.

About

Event Emitter module

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors