debian-mirror-gitlab/app/assets/javascripts/helpers/event_hub_factory.js

21 lines
409 B
JavaScript
Raw Normal View History

2020-05-24 23:13:21 +05:30
import mitt from 'mitt';
export default () => {
const emitter = mitt();
emitter.once = (event, handler) => {
const wrappedHandler = evt => {
handler(evt);
emitter.off(event, wrappedHandler);
};
emitter.on(event, wrappedHandler);
};
emitter.$on = emitter.on;
emitter.$once = emitter.once;
emitter.$off = emitter.off;
emitter.$emit = emitter.emit;
return emitter;
};