mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
ui: optimize: debounced reload
This commit is contained in:
1 parent
c5d165617e
commit
13e561c51a
5 files changed
+32
-28
No files matched your search
@@ -49,7 +49,8 @@
|
||||
"semver": "^7.3.7",
|
||||
"serialize-javascript": "^6.0.0",
|
||||
"superagent": "^8.0.0",
|
||||
"thirty-two": "^1.0.2"
|
||||
"thirty-two": "^1.0.2",
|
||||
"ws": "^8.9.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/adm-zip": "^0.4.34",
|
||||
|
||||
@@ -38,8 +38,7 @@ export function resolveConfig(plugin: any, config: any) {
|
||||
Context.service('loader');
|
||||
|
||||
export class Loader {
|
||||
static readonly kUpdate = Symbol.for('koishi.loader.update');
|
||||
static readonly kRecord = Symbol.for('koishi.loader.record');
|
||||
static readonly Record = Symbol.for('loader.record');
|
||||
|
||||
public app: Context;
|
||||
public config: Context.Config;
|
||||
@@ -47,19 +46,18 @@ export class Loader {
|
||||
public cache: Record<string, string> = Object.create(null);
|
||||
|
||||
unloadPlugin(ctx: Context, key: string) {
|
||||
const fork = ctx.state[Loader.kRecord][key];
|
||||
const fork = ctx.state[Loader.Record][key];
|
||||
if (fork) {
|
||||
fork.dispose();
|
||||
delete ctx.state[Loader.kRecord][key];
|
||||
delete ctx.state[Loader.Record][key];
|
||||
logger.info('unload plugin %c', key);
|
||||
}
|
||||
}
|
||||
|
||||
async reloadPlugin(parent: Context, key: string, config: any, asName = '') {
|
||||
let fork = parent.state[Loader.kRecord]?.[key];
|
||||
let fork = parent.state[Loader.Record]?.[key];
|
||||
if (fork) {
|
||||
logger.info('reload plugin %c', key);
|
||||
fork[Loader.kUpdate] = true;
|
||||
fork.update(config);
|
||||
} else {
|
||||
logger.info('apply plugin %c', key);
|
||||
@@ -70,8 +68,8 @@ export class Loader {
|
||||
// fork = parent.plugin(plugin, this.interpolate(config));
|
||||
fork = parent.plugin(plugin, config);
|
||||
if (!fork) return;
|
||||
parent.state[Loader.kRecord] ||= Object.create(null);
|
||||
parent.state[Loader.kRecord][key] = fork;
|
||||
parent.state[Loader.Record] ||= Object.create(null);
|
||||
parent.state[Loader.Record][key] = fork;
|
||||
}
|
||||
return fork;
|
||||
}
|
||||
@@ -121,7 +119,7 @@ Context.service('loader');
|
||||
const loader = new Loader();
|
||||
app.loader = loader;
|
||||
loader.app = app;
|
||||
app.state[Loader.kRecord] = Object.create(null);
|
||||
app.state[Loader.Record] = Object.create(null);
|
||||
|
||||
export async function load() {
|
||||
addon(path.resolve(__dirname, '..'), true);
|
||||
|
||||
@@ -49,7 +49,7 @@ export default class Watcher extends Service {
|
||||
if (process.env.WATCH_ROOT) roots.push(process.env.WATCH_ROOT);
|
||||
this.watcher = watch(roots, {
|
||||
...this.config,
|
||||
ignored: ['node_modules', '.git', 'logs', '.cache']
|
||||
ignored: ['node_modules', '.git', 'logs', '.cache', '.yarn']
|
||||
.map((i) => `**/${i}/**`).concat('**/tsconfig.tsbuildinfo'),
|
||||
});
|
||||
logger.info(`Start watching changes in ${this.root}`);
|
||||
|
||||
Reference in new issue
Block a user