JSFiddle - React, Tailwind, and code Playground

by Prathameshsb

JavaScript

class EventEmitterPrat {
	listenerMap = {};

  // same as on
  subscribe(event, cb) {
    if (!this.listenerMap.hasOwnProperty()) {
      this.listenerMap[event] = new Set();
    } else {
      this.listenerMap[event].add(cb);
    }
  }

  unsubscribe(event, fn) {
    this.listener[event].delete(fn)
  }

  emit() {

  }
}

function play() {
  console.log('hello yaki!');
}

const ee = new EventEmitterPrat();
ee.subscribe('foo', play);
ee.emit();