debian-mirror-gitlab/app/assets/javascripts/helpers/event_hub_factory.js
2020-05-25 16:23:42 +05:30

20 lines
409 B
JavaScript

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;
};