mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-12-09 16:21:51 +00:00
Manually debounce force reload event
Remove chokidar built-in event debouncing/aggregating and replace it with a basic custom implementation with a 250ms settle delay.
This commit is contained in:
parent
94b7c754ad
commit
b3d0e30c07
@ -63,7 +63,7 @@ export class ModLoader extends EventEmitter {
|
||||
this.locators.set("dev", devLocator);
|
||||
|
||||
// If requested, restart automatically when dev mods are modified
|
||||
devLocator.fsWatcher?.on("all", () => this.forceReload());
|
||||
devLocator.fsWatcher?.on("all", this.delayedForceReload());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -115,6 +115,16 @@ export class ModLoader extends EventEmitter {
|
||||
return this.mods.find(mod => mod.metadata.id === id);
|
||||
}
|
||||
|
||||
private delayedForceReload() {
|
||||
// Debounce the force reload manually as chokidar won't aggregate events the way we want
|
||||
// NOTE: The delay chosen here (250ms) is quite arbitrary!
|
||||
let timeout: NodeJS.Timeout | undefined = undefined;
|
||||
return () => {
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(() => this.forceReload(), 250);
|
||||
};
|
||||
}
|
||||
|
||||
private async locateAllMods(): Promise<ModLocation[]> {
|
||||
// Sort locators by priority, lowest number is highest priority
|
||||
const locators = [...this.locators.entries()].sort(([, a], [, b]) => a.priority - b.priority);
|
||||
|
||||
@ -179,8 +179,6 @@ export class DevelopmentModLocator implements ModLocator {
|
||||
this.fsWatcher = chokidar.watch(this.modFiles, {
|
||||
persistent: false,
|
||||
ignoreInitial: true,
|
||||
awaitWriteFinish: true,
|
||||
atomic: true,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user