got-events
v1.3.0
Published
Simple events for simple objects. Three methods to rule'em all: `on`, `off`, `trigger`.
Downloads
2
Readme
got-events
Simple events for simple objects. Three methods to rule'em all: .on
, .off
, .trigger
. Lots of fun.
Install (coming soon)
npm install --save got-events
Usage
Three options:
- Function:
var evHandler = require('got-events')();
- Extend object:
require('got-events').extend(simpleObject);
Optionally preserving old attributes:
require('got-events').extend(simpleObject, true);
- Singleton:
var evHandler = require('got-events').singleton;
Object methods
.on(eventName, callback)
Adds a callback to an event.
eventName
: String or Array of strings.callback
: Function.
.on(eventName, callbackId, callback)
Adds a callback to an event, identified.
eventName
: String or Array of strings.callbackId
: String.callback
: Function.
.off(eventName)
Clears the event's callback list.
eventName
: String or Array of strings.
.off(eventName, callback)
Removes a callback from an event.
eventName
: String or Array of strings.callback
: Function.
.off(eventName, callbackId)
Removes an identified callback from an event.
eventName
: String or Array of strings.callbackId
: String or Array of strings.
.trigger(eventName, data)
Triggers an event with
err = null
.eventName
: String or Array of strings.data
: Anything.
.trigger(eventName, err, data...)
Triggers an event.
eventName
: String or Array of strings.err
: Error or Boolean.data...
: Anything. Every argument from here will be passed to callback.
Other features
- Wildcard event
'*'
fired on every trigger.