event-station
v2.0.0
Published
A versatile and robust event emitter class.
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
- Helpers like
stopPropagation()andlistenerCount extend()any object- Global and per-instance
config()options - 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
Via npm
npm install event-stationDownloads
Latest Release
- ESM build — Imported as an ES module.
- ESM minified build — Minified ES module.
- Source map — Source map for the minified build
- Definition — Rolled-up 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-2025 Morris Allison III. Released under the MIT license.
References
Event-Station was inspired by EventEmitter2 and Backbone.Events.
