Skip to content

Instantly share code, notes, and snippets.

@chobitV
chobitV / EventBus.js
Created September 20, 2018 19:46 — forked from PierfrancescoSoffritti/eventBus.js
A simple implementation of an event bus in Javascript
function EventBus() {
const eventCallbacksPairs = [];
this.subscribe = function( eventType, callback ) {
const eventCallbacksPair = findEventCallbacksPair(eventType);
if(eventCallbacksPair)
eventCallbacksPair.callbacks.push(callback);
else
eventCallbacksPairs.push( new EventCallbacksPair(eventType, callback) );