Turn event bus into a class

This commit is contained in:
Phan An 2017-12-10 22:14:18 +01:00
parent 98b1252c68
commit 60d95e95de
2 changed files with 7 additions and 12 deletions

View file

@ -16,7 +16,6 @@ new Vue({
el: '#app',
render: h => h(App),
created () {
event.init()
http.init()
}
})

View file

@ -53,21 +53,15 @@ export function isMediaSessionSupported () {
*
* @type {Object}
*/
const event = {
bus: null,
init () {
if (!this.bus) {
this.bus = new Vue()
}
return this
},
class EventBus {
constructor () {
this.bus = new Vue()
}
emit (name, ...args) {
this.bus.$emit(name, ...args)
return this
},
}
on () {
if (arguments.length === 2) {
@ -80,4 +74,6 @@ const event = {
}
}
const event = new EventBus()
export { event }