core: storage: 热重载

This commit is contained in:
undefined committed 2021-01-21 22:48:18 +08:00
1 parent 99ac6e545d
commit 8c8dcb89eb
5 files changed
+24 -12

No files matched your search

+8 -3
View File
@@ -36,9 +36,10 @@ export function getMany(keys: string[]): any[] {
return keys.map((key) => cache[key]);
}
export async function set<K extends keyof SystemKeys>(_id: K, value: SystemKeys[K]): Promise<SystemKeys[K]>
export async function set<K>(_id: string, value: K): Promise<K>
export async function set(_id: string, value: any) {
export async function set<K extends keyof SystemKeys>(_id: K, value: SystemKeys[K], boardcast?: boolean): Promise<SystemKeys[K]>
export async function set<K>(_id: string, value: K, boardcast?: boolean): Promise<K>
export async function set(_id: string, value: any, boardcast = true) {
if (boardcast) bus.boardcast('system/setting', { [_id]: value });
const res = await coll.findOneAndUpdate(
{ _id },
{ $set: { value } },
@@ -69,6 +70,10 @@ export async function runConfig() {
bus.emit('database/config');
}
bus.on('system/setting', (args) => {
for (const key in args) set(key, args[key], false);
});
global.Hydro.model.system = {
runConfig,
get,