Files
Clipboard/lib/notify-fanout.js
2026-09-12 13:59:12 +08:00

21 lines
770 B
JavaScript

'use strict';
function createSubscribers() {
const clip = new Set();
const fav = new Set();
const theme = new Set();
return {
addClip: (wc) => clip.add(wc),
addFav: (wc) => fav.add(wc),
addTheme: (wc) => theme.add(wc),
drop: (wc) => { clip.delete(wc); fav.delete(wc); theme.delete(wc); },
notifyClip: (ch, payload) => { for (const wc of clip) try { wc.send(ch, payload); } catch {} },
notifyFav: (ch, payload) => { for (const wc of fav) try { wc.send(ch, payload); } catch {} },
notifyTheme: (ch, payload) => { for (const wc of theme) try { wc.send(ch, payload); } catch {} },
get clip() { return clip; },
get fav() { return fav; },
get theme() { return theme; },
};
}
module.exports = { createSubscribers };