33 lines
769 B
JavaScript
33 lines
769 B
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.initConfig = initConfig;
|
|
exports.getConfig = getConfig;
|
|
exports.getState = getState;
|
|
exports.setState = setState;
|
|
exports.subscribe = subscribe;
|
|
let config = null;
|
|
let state = {};
|
|
const listeners = new Set();
|
|
function initConfig(next) {
|
|
config = next;
|
|
state = {
|
|
guildId: next.initialGuildId,
|
|
isAdmin: next.isAdmin,
|
|
userLabel: next.userLabel
|
|
};
|
|
}
|
|
function getConfig() {
|
|
return config;
|
|
}
|
|
function getState() {
|
|
return state;
|
|
}
|
|
function setState(partial) {
|
|
state = { ...state, ...partial };
|
|
listeners.forEach((l) => l(state));
|
|
}
|
|
function subscribe(listener) {
|
|
listeners.add(listener);
|
|
return () => listeners.delete(listener);
|
|
}
|