Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cfal/emit.js
An event emitter replacement with no dependencies. Can be plugged in anywhere a node EventEmitter or flux Dispatcher is required.
https://github.com/cfal/emit.js
Last synced: 23 days ago
JSON representation
An event emitter replacement with no dependencies. Can be plugged in anywhere a node EventEmitter or flux Dispatcher is required.
- Host: GitHub
- URL: https://github.com/cfal/emit.js
- Owner: cfal
- Created: 2016-02-19T21:51:09.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-05-17T06:39:21.000Z (over 8 years ago)
- Last Synced: 2024-11-17T01:18:59.575Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 4.88 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# emitjs
An event emitter replacement with no dependencies.
Can be plugged in anywhere a node EventEmitter or flux Dispatcher is required.## Usage
```
// Import emit.js
var Emitter = require('emitjs');// Create and use as a multi-event emitter
var obj = new Emitter();var callback = function() {
// Do things!
};// Register callback for 'event' using on().
// The function call returns an optional unsubscribe function.
offCallback = obj.on('event', callback);// Trigger 'event'
obj.emit('event');// Remove using .off()
obj.off('event', callback);// .. or remove using the callback from .on()
offCallback();// Create and use as a single-event emitter
var single = new Emitter();// Register callback
singleOffCallback = single.on(callback);// Emit an event and trigger the callback
single.emit();// Remove the callback like above
single.off(callback) //..or singleOffCallback();```
## API (Multi Event)
### .on(event, subscriber [, subscriber, subscriber, ..])
### .subscribe(event, subscriber [, subscriber, subscriber, ..])
### .addListener(event, subscriber [, subscriber, subscriber, ..])
### .register(event, subscriber [, subscriber, subscriber, ..])Add subscriber(s) for event.
Returns a function that will remove the added subscriber(s) when called.### .one(event, subscriber [, subscriber, subscriber, ..])
### .once(event, subscriber [, subscriber, subscriber, ..])Add subscriber(s) for event, firing only once.
Returns a function that will remove the added subscriber(s) when called.### .emit(event [, arg, arg, ..])
### .dispatch(event[, arg, arg, ..])Emit event with the provided arguments.
### .off(event, subscriber [, subscriber, subscriber, ..])
### .unsubscribe(event, subscriber [, subscriber, subscriber, ..])
### .unregister(event, subscriber [, subscriber, subscriber, ..])
### .removeListener(event, subscriber [, subscriber, subscriber, ..])Remove the provided subscribers for event.
### .off(event)
Remove all subscribers for event.
## API (Single Event)
### .on(subscriber [, subscriber, subscriber, ..])
### .subscribe(subscriber [, subscriber, subscriber, ..])
### .addListener(subscriber [, subscriber, subscriber, ..])
### .register(subscriber [, subscriber, subscriber, ..])Add subscriber(s).
Returns a function that will remove the added subscriber(s) when called.### .one(subscriber [, subscriber, subscriber, ..])
### .once(subscriber [, subscriber, subscriber, ..])Add subscriber(s), firing only once.
Returns a function that will remove the added subscriber(s) when called.### .emit([arg, arg, ..])
### .dispatch([arg, arg, ..])Emit event with the provided arguments.
### .off(subscriber [, subscriber, subscriber, ..])
### .unsubscribe(subscriber [, subscriber, subscriber, ..])
### .unregister(subscriber [, subscriber, subscriber, ..])
### .removeListener(subscriber [, subscriber, subscriber, ..])Remove the provided subscribers.
### .off()
Remove all subscribers.