9d1243073b
* Add: style settings * Change: use radio instead of select for dark/light mode * Change: x -> Delete * Change: (in|ex)clusion messages * Fix: avoid extra space when there is no rule * Fix: UI in mobile * Change: delete priority * Change: use textarea for include/exclude, remove isCodeUpdated * Fix: separate toggle * Fix: minor * Fix: remove codeIsUpdated in styleman
38 lines
742 B
JavaScript
38 lines
742 B
JavaScript
/* exported EventEmitter */
|
|
'use strict';
|
|
|
|
function EventEmitter() {
|
|
const listeners = new Map();
|
|
return {
|
|
on(ev, cb, opt) {
|
|
if (!listeners.has(ev)) {
|
|
listeners.set(ev, new Map());
|
|
}
|
|
listeners.get(ev).set(cb, opt);
|
|
if (opt && opt.runNow) {
|
|
cb();
|
|
}
|
|
},
|
|
off(ev, cb) {
|
|
const cbs = listeners.get(ev);
|
|
if (cbs) {
|
|
cbs.delete(cb);
|
|
}
|
|
},
|
|
emit(ev, ...args) {
|
|
const cbs = listeners.get(ev);
|
|
if (!cbs) return;
|
|
for (const [cb, opt] of cbs.entries()) {
|
|
try {
|
|
cb(...args);
|
|
} catch (err) {
|
|
console.error(err);
|
|
}
|
|
if (opt && opt.once) {
|
|
cbs.delete(cb);
|
|
}
|
|
}
|
|
},
|
|
};
|
|
}
|