0.0.13 • Published 7 years ago
@1k/emitter v0.0.13
@1k/emitter
A tiny (less than 1k) event emitter.
Install
npm
npm install @1k/emitter --saveUsage
var Emitter = require('@1k/emitter');
var emitter = new Emitter();
emitter.on('some-event', function (arg1, arg2, arg3) {
//
});
emitter.emit('some-event', 'arg1 value', 'arg2 value', 'arg3 value');Instance Methods
on(event, cb, ctx)
Subscribe to an event
event- the name of the event to subscribe tocb- the function to call when event is emittedctx- (OPTIONAL) - the context to bind the event cb to
once(event, cb, ctx)
Subscribe to an event only once
event- the name of the event to subscribe tocb- the function to call when event is emittedctx- (optional) - the context to bind the event cb to
off(event, cb)
Unsubscribe from an event or all events. If no cb is provided, it unsubscribes you from all events.
event- the name of the event to unsubscribe fromcb- the function used when binding to the event
emit(event, arguments...)
Trigger a named event
event- the event name to emitarguments...- any number of arguments to pass to the event subscribers