Skip to content

Commit

Permalink
fix(compas): merge file change paths on debounced calls
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkdev98 committed Sep 18, 2023
1 parent 20a8151 commit 30f464d
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/compas/src/main/development/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ export class State {
* glob: string,
* integration: import("./integrations/base.js").BaseIntegration,
* debounceDelay: number,
* existingTimeout?: NodeJS.Timeout
* existingTimeout?: NodeJS.Timeout,
* accumulatedPaths?: string[],
* }[]}
*/
this.fileChangeRegister = [];
Expand Down Expand Up @@ -315,7 +316,7 @@ export class State {
* glob, added to {@link State#fileChangeRegister}, and call with the specified
* debounce-delay.
*
* @param paths
* @param {string[]} paths
*/
emitFileChange(paths) {
debugPrint(`State#emitFileChange :: ${JSON.stringify(paths)}}`);
Expand All @@ -326,13 +327,21 @@ export class State {
`State#emitFileChange :: Matched ${registerItem.glob} for ${registerItem.integration.name} debouncing with ${registerItem.debounceDelay}.`,
);

// Merge all paths from debounced matches
registerItem.accumulatedPaths ??= [];
registerItem.accumulatedPaths.push(...paths);

if (registerItem.existingTimeout) {
registerItem.existingTimeout.refresh();
} else {
registerItem.existingTimeout = setTimeout(() => {
// Reset paths for debounced matches
const accumulatedPaths = registerItem.accumulatedPaths ?? [];
registerItem.accumulatedPaths = [];

registerItem.integration.state.runTask(
"Integration#onFileChaged",
registerItem.integration.onFileChanged(paths),
registerItem.integration.onFileChanged(accumulatedPaths),
);
}, registerItem.debounceDelay);
}
Expand Down

0 comments on commit 30f464d

Please sign in to comment.