2018-12-04 14:44:13 +00:00
|
|
|
import EventEmitter from 'events-light'
|
2018-04-08 23:08:32 +01:00
|
|
|
|
|
|
|
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)
|