A modern event emitter implementation.
Emitter.js is an event emitter based on the nodejs EventEmitter but utilizing some of the new features in ECMAScript 6.
git clone https://github.com/jeffrose/emitter emitter
npm install emitter-js
bower install emitter-js
Emitter.js provides both an ES5 and ES6 version as part of the distribution.
Additional examples can be found in the API docs and unit tests.
// Depending on the scenario the /index may not be necessary
import Emitter from '../node_modules/emitter-js/dist/emitter';
let greeter = new Emitter();
greeter.on( 'hello', ( name ) => console.log( `Hello, ${ name }!` ) );
greeter.emit( 'hello', 'World' );
// Hello, World!
var Emitter = require( 'emitter-js' ),
greeter = new Emitter();
greeter.on( 'hello', function( name ){
console.log( 'Hello, ' + name + '!' ) );
} );
greeter.emit( 'hello', 'World' );
// Hello, World!
- Lacks domain support.
- Has a succint API with no backward compatibility aliases, e.g.
clear()
instead ofremoveAllListeners()
. - Has namespaced lifecycle event types, e.g.
:off
instead ofremoveListener
. - Does not use
console.log()
.