pinafore/routes/_utils/eventBus.js
2018-04-08 15:08:32 -07:00

18 lines
435 B
JavaScript

import EventEmitter from 'events'
const eventBus = new EventEmitter()
if (process.browser && process.env.NODE_ENV !== 'production') {
window.eventBus = eventBus
}
export function on (eventName, component, method) {
let callback = method.bind(component)
eventBus.on(eventName, callback)
component.on('destroy', () => {
eventBus.removeListener(eventName, callback)
})
}
export const emit = eventBus.emit.bind(eventBus)