Skip to content

Instantly share code, notes, and snippets.

@tmdesigned
tmdesigned / EventBus.js
Created October 6, 2018 12:17 — 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) );