/
wax_boy
/
semaphore_custom
Обзор
Документация
Войти
/
wax_boy
/
semaphore_custom
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
develop
web/src/lib/PubSub.js
30 строк
620 B
Denis Gukov
refactor: rename directory web2 to web
29 окт 2022, 16:37
29 окт 2022, 16:37
d382a82
Код
Авторство
О чём код?
import Listenable from '@/lib/Listenable'; export default class PubSub { constructor() { this.topics = {}; } subscribe(topic, callback) { if (this.topics[topic] == null) { this.topics[topic] = new Listenable(); } return this.topics[topic].addListener(callback); } unsubscribe(id) { // eslint-disable-next-line no-restricted-syntax for (const topic in this.topics) { if (this.topics[topic].removeListener(id)) { break; } } } publish(topic, data) { if (!this.topics[topic]) { return; } this.topics[topic].callListeners(data); } }