https://github.com/jeffrose/emitter
A modern event emitter implementation.
https://github.com/jeffrose/emitter
ecmascript event-emitter eventemitter javascript
Last synced: 3 months ago
JSON representation
A modern event emitter implementation.
- Host: GitHub
- URL: https://github.com/jeffrose/emitter
- Owner: jeffrose
- License: apache-2.0
- Created: 2015-03-19T18:40:53.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2019-06-18T19:27:22.000Z (almost 7 years ago)
- Last Synced: 2026-01-23T10:33:51.174Z (5 months ago)
- Topics: ecmascript, event-emitter, eventemitter, javascript
- Language: JavaScript
- Homepage:
- Size: 519 KB
- Stars: 3
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Emitter
> A modern event emitter implementation.
Emitter.js is an event emitter based on the nodejs [EventEmitter](https://nodejs.org/api/events.html) but utilizing some of the new [features](https://github.com/lukehoban/es6features) in [ECMAScript](http://www.ecmascript.org/) 6.
## Installation
### Git
`git clone https://github.com/jeffrose/emitter emitter`
### NPM
`npm install emitter-js`
### Bower
`bower install emitter-js`
## Documentation
* [API](docs/API.md)
* [CHANGES](docs/CHANGES.md)
* [ROADMAP](docs/ROADMAP.md)
* [UPGRADE](docs/UPGRADE.md)
## Usage
Emitter.js provides both an ES5 and ES6 version as part of the distribution.
Additional examples can be found in the [API](docs/API.md) docs and unit tests.
### ECMAScript 6
```javascript
// 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!
```
### ECMAScript 5
```javascript
var Emitter = require( 'emitter-js' ),
greeter = new Emitter();
greeter.on( 'hello', function( name ){
console.log( 'Hello, ' + name + '!' ) );
} );
greeter.emit( 'hello', 'World' );
// Hello, World!
```
## Differences from `EventEmitter`
### Emitter.js...
* Lacks [domain](https://nodejs.org/api/domain.html) support.
* Has a succint API with no backward compatibility aliases, e.g. `clear()` instead of `removeAllListeners()`.
* Has namespaced lifecycle event types, e.g. `:off` instead of `removeListener`.
* Does not use `console.log()`.