/event-station

🚝 A versatile and robust event emitter class.

Primary LanguageLiveScriptMIT LicenseMIT

Event-Station

A versatile and robust event emitter class.

npm Version Bower Version MIT License Travis CI Build Status Codecov Coverage Status Dependencies Status DevDependencies Status

Features

Example

import EventStation from 'event-station';

class Spaceship extends EventStation {
    launch(destination) {
        this.emit('launch', destination);
    }
}

let Normandy = new Spaceship();
let Tempest = new Spaceship();

// Add two listeners via a listener map
let listeners = Normandy.on({
    launch: (dest) => console.log(`Spaceship launched! En route to ${dest}.`),
    dock: () => console.log('Spaceship docking.'),
});

// Attach the same listeners to Tempest that are on Normandy
listeners.addTo(Tempest);

// Launch Tempest when Normandy launches
Tempest.hear(Normandy, 'launch')
    .once((dest) => Tempest.launch(dest));

// Launch both ships to the Andromeda Galaxy
Normandy.launch('Messier 31');

// Stop listening to both ships
listeners.off();

View more usage examples.

Installation

Node.js via Yarn

yarn add event-station

Node.js via npm

npm install event-station --save

SystemJS via jspm

jspm install npm:event-station

Web browser via Bower

bower install event-station

Web browser via <script>

<script src="dist/event-station.min.js"></script>
<script>new EventStation();</script>

Downloads

Latest Release

Documentation

License

Copyright © 2016 Morris Allison III.
Released under the MIT license.

References

Event-Station was influenced by EventEmitter2 and Backbone.Events.