All files / src/components eventbus.js

0% Statements 0/18
0% Branches 0/14
0% Functions 0/6
0% Lines 0/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48                                                                                               
'use strict'
import Vue from 'vue';
 
Vue.config.devtools = true;
class EventBus extends Vue {
 
    $getEventsBound() {
        return this.eventsBound;
    }
 
    // Override Vue's $emit to call a logger for any event emitted.
    $emit(event, ...args) {
        console.ls.log("Emitting -> ", event, ...args);
        if(this.eventsBound != undefined && this.eventsBound[event] != undefined) {
            this.eventsBound[event].forEach(element => {
                // element[0](...args);
            });
        }
        return super.$emit(event, ...args);
    }
    // Override Vue's $on to call a logger for any event bound.
    $on(event, ...args) {
        this.eventsBound = this.eventsBound || {};
        this.eventsBound[event] = this.eventsBound[event] || [];
        this.eventsBound[event].push(args);
        console.ls.log("Binding -> ", event, ...args);
        return super.$on(event, ...args);
    }
 
    // Override Vue's $emit to call a logger for any event bound.
    $off(event, ...args) {
        this.eventsBound = this.eventsBound || {};
        if(this.eventsBound[event] != undefined ) {
            this.eventsBound[event] = this.eventsBound[event].filter((arg) => {
                args.indexOf(arg) == -1;
            });
        }
        console.ls.log("Remove Binding -> ", event, ...args);
        return super.$off(event, ...args);
    }
}
 
window.EventBus = window.EventBus || (new EventBus({
    name: "EventBus"
}));
 
export default window.EventBus;