Skip to content

Commit 30f464d

Browse files
committed
fix(compas): merge file change paths on debounced calls
1 parent 20a8151 commit 30f464d

File tree

1 file changed

+12
-3
lines changed
  • packages/compas/src/main/development

1 file changed

+12
-3
lines changed

packages/compas/src/main/development/state.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ export class State {
7272
* glob: string,
7373
* integration: import("./integrations/base.js").BaseIntegration,
7474
* debounceDelay: number,
75-
* existingTimeout?: NodeJS.Timeout
75+
* existingTimeout?: NodeJS.Timeout,
76+
* accumulatedPaths?: string[],
7677
* }[]}
7778
*/
7879
this.fileChangeRegister = [];
@@ -315,7 +316,7 @@ export class State {
315316
* glob, added to {@link State#fileChangeRegister}, and call with the specified
316317
* debounce-delay.
317318
*
318-
* @param paths
319+
* @param {string[]} paths
319320
*/
320321
emitFileChange(paths) {
321322
debugPrint(`State#emitFileChange :: ${JSON.stringify(paths)}}`);
@@ -326,13 +327,21 @@ export class State {
326327
`State#emitFileChange :: Matched ${registerItem.glob} for ${registerItem.integration.name} debouncing with ${registerItem.debounceDelay}.`,
327328
);
328329

330+
// Merge all paths from debounced matches
331+
registerItem.accumulatedPaths ??= [];
332+
registerItem.accumulatedPaths.push(...paths);
333+
329334
if (registerItem.existingTimeout) {
330335
registerItem.existingTimeout.refresh();
331336
} else {
332337
registerItem.existingTimeout = setTimeout(() => {
338+
// Reset paths for debounced matches
339+
const accumulatedPaths = registerItem.accumulatedPaths ?? [];
340+
registerItem.accumulatedPaths = [];
341+
333342
registerItem.integration.state.runTask(
334343
"Integration#onFileChaged",
335-
registerItem.integration.onFileChanged(paths),
344+
registerItem.integration.onFileChanged(accumulatedPaths),
336345
);
337346
}, registerItem.debounceDelay);
338347
}

0 commit comments

Comments
 (0)