cyp/app/js/lib/pubsub.js
Ondrej Zara 76802bc630 queue
2019-03-22 15:35:04 +01:00

17 lines
548 B
JavaScript

let storage = new Map();
export function publish(message, publisher, data) {
console.log(message, publisher, data);
if (!storage.has(message)) { return; }
storage.get(message).forEach(listener => listener(message, publisher, data));
}
export function subscribe(message, listener) {
if (!storage.has(message)) { storage.set(message, new Set()); }
storage.get(message).add(listener);
}
export function unsubscribe(message, listener) {
if (!storage.has(message)) { storage.set(message, new Set()); }
storage.get(message).remove(listener);
}