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 | 2x 2x 2x 2x 2x 2x 2x | export class EventBus { constructor() { this.store = new Map() } on(type, handler) { const handlers = this.store.get(type) const added = handlers && handlers.push(handler) Eif (!added) { this.store.set(type, [handler]) } } off(type, handler) { const handlers = this.store.get(type) const index = handlers.indexOf(handler) if (handlers && index > -1) { handlers.splice(index, 1) } } emit(type, payload) { this.store .get(type) .slice() .map((handler) => handler(payload)) } } |