1
0
mirror of https://github.com/nolanlawson/pinafore synced 2024-12-11 09:45:24 +01:00
Pinafore-Web-Client-Frontend/routes/_utils/eventBus.js

22 lines
550 B
JavaScript
Raw Normal View History

2018-04-09 00:08:32 +02:00
import EventEmitter from 'events'
const eventBus = new EventEmitter()
// we need enough 'postedStatus' listeners for each
// visible status in a timeline
eventBus.setMaxListeners(100)
2018-04-09 00:08:32 +02: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)