UNPKG

498 BJavaScriptView Raw
1import Emitter from 'tiny-emitter';
2/**
3 * Extend given object with emitter functions `on`, `off`, `once`, `emit`
4 * @param {Object} obj
5 * @return {Object} obj
6 */
7
8export function mixin(obj) {
9 // create event emitter
10 var emitter = new Emitter(); // bind methods to obj (we don't want to expose the emitter.e Array...)
11
12 obj.on = emitter.on.bind(emitter);
13 obj.off = emitter.off.bind(emitter);
14 obj.once = emitter.once.bind(emitter);
15 obj.emit = emitter.emit.bind(emitter);
16 return obj;
17}
\No newline at end of file