event-station
v1.1.4
Published
A versatile and robust event emitter class.
Downloads
3
Maintainers
Readme
A versatile and robust event emitter class.
Features
- Versatile API that's flexible and consistent
- Cross-emitter listening, allowing for easier management of many listeners
- Regular expression listeners
- Asynchronous Listeners with
emitAsync()
- Listener modifiers; a fluent interface for modifying listeners
- Set callbacks and contexts with
calling()
andusing()
- Migration via
moveTo()
,addTo()
, andremoveFrom()
- Remove listeners from all emitters with
off()
- Limit occurrences with
occur()
pause()
,resume()
, andisPaused()
- Create evented
race()
andall()
promises - Duplication with
clone()
- Set callbacks and contexts with
- Browser environment compatible
- Competitive and consistent performance
- Rx compatible with
toObservable()
- Helpers like
stopPropagation()
andlistenerCount
extend()
any object- Global and per-instance
config()
options - Over 200 tests with 100% code coverage
- Written in TypeScript
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();
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
- ES5 Build
- Compatible with AMD and CommonJS module loaders
- Assigns an
EventStation
global when not imported as a module
- ES6 Build
- For use with an ES6 module loader
- jsnext Build
- ES5 compatible objects as an ES module. See the Rollup Wiki for details.
- ES5 Minified Build
- ES5 Build minified with UglifyJS 2
- Source Map
- The source map for the minified build
- Definition
- Generated TypeScript definition
Documentation
- Usage documentation
- This guide will explain the general usage of Event-Station.
- Module definition
- The associated definition file can be used as an API reference.
License
Copyright © 2016 Morris Allison III. Released under the MIT license.
References
Event-Station was influenced by EventEmitter2 and Backbone.Events.