update
This commit is contained in:
21
lib/notify-fanout.js
Normal file
21
lib/notify-fanout.js
Normal file
@@ -0,0 +1,21 @@
|
||||
'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 };
|
||||
Reference in New Issue
Block a user