2018-04-08 23:08:32 +01:00
|
|
|
import EventEmitter from 'events'
|
|
|
|
|
|
|
|
const eventBus = new EventEmitter()
|
|
|
|
|
2018-04-13 17:46:38 +01:00
|
|
|
// we need enough 'postedStatus' listeners for each
|
|
|
|
// visible status in a timeline
|
2018-11-18 17:07:32 +00:00
|
|
|
eventBus.setMaxListeners(1000)
|
2018-04-13 17:46:38 +01:00
|
|
|
|
2018-04-08 23:08:32 +01:00
|
|
|
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)
|