Simple events bus in VueJS

I've been using a global events bus in my web applications for years now and I love this patern. It's a quick (and non intrusive) way of making parts of our application talk to each other.

In a VueJS context tho it's less often needed because the Vuex store is doing a great job. Nevertheless, sometimes you encounter situations where it's hard to implement something into data, for this I have this events bus :

It simply uses the VueJS events management system which works very well. No need to implement your own.

Side note: I often like to document all the events implemented in my app on top of this file, making this file a reference.

Here is an example of how it is used :

import Mediator from 'Mediator.js'

// subscribe to an event
Mediator.on('MY_EVENT', (data) => {
    console.log(data);
});

// publish an event
Mediator.emit('MY_EVENT', {myData:'cool'});

Try out my latest game !

Screenshot of solitaire game