Simple events bus mixin
import events from 'uc-events'
const MyClass = function() {
this.events = {};
this.on('event', this.method, this);
this.emit('event');
}
MyClass.prototype = Object.assign({},
events,
{
method: function() {
console.log('Event fired');
}
}
)
Adds the event handler
to the event
. You can use context
to set this
context for the handler. Returns the class instance so you can chain the calls.
Same as the above but fires only once.
Removes the event handler
to the event
. You should pass the context
if you subscribed to the event with context. Returns the class instance so you can chain the calls.
Emits the event
- events - object, this is the events handlers storage
License MIT
© velocityzen