Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit 06e4971

Browse files
committed
fix(watch): queue builds
1 parent b085223 commit 06e4971

File tree

1 file changed

+21
-24
lines changed

1 file changed

+21
-24
lines changed

src/watch.ts

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -178,37 +178,34 @@ export function buildUpdate(event: string, filePath: string, context: BuildConte
178178
}
179179

180180
export function queueWatchUpdatesForBuild(event: string, filePath: string, context: BuildContext) {
181-
if (queuedWatchEventsMap.get(filePath)) {
182-
183-
const changedFile: ChangedFile = {
184-
event: event,
185-
filePath: filePath,
186-
ext: extname(filePath).toLowerCase()
187-
};
181+
const changedFile: ChangedFile = {
182+
event: event,
183+
filePath: filePath,
184+
ext: extname(filePath).toLowerCase()
185+
};
188186

189-
queuedWatchEventsMap.set(filePath, changedFile);
187+
queuedWatchEventsMap.set(filePath, changedFile);
190188

191-
// debounce our build update incase there are multiple files
192-
clearTimeout(queuedWatchEventsTimerId);
189+
// debounce our build update incase there are multiple files
190+
clearTimeout(queuedWatchEventsTimerId);
193191

194-
// run this code in a few milliseconds if another hasn't come in behind it
195-
queuedWatchEventsTimerId = setTimeout(() => {
192+
// run this code in a few milliseconds if another hasn't come in behind it
193+
queuedWatchEventsTimerId = setTimeout(() => {
196194

197-
// figure out what actually needs to be rebuilt
198-
const queuedChangeFileList: ChangedFile[] = [];
199-
queuedWatchEventsMap.forEach(changedFile => queuedChangeFileList.push(changedFile));
195+
// figure out what actually needs to be rebuilt
196+
const queuedChangeFileList: ChangedFile[] = [];
197+
queuedWatchEventsMap.forEach(changedFile => queuedChangeFileList.push(changedFile));
200198

201-
const changedFiles = runBuildUpdate(context, queuedChangeFileList);
199+
const changedFiles = runBuildUpdate(context, queuedChangeFileList);
202200

203-
// clear out all the files that are queued up for the build update
204-
queuedWatchEventsMap.clear();
201+
// clear out all the files that are queued up for the build update
202+
queuedWatchEventsMap.clear();
205203

206-
if (changedFiles && changedFiles.length) {
207-
// cool, we've got some build updating to do ;)
208-
buildTask.buildUpdate(changedFiles, context);
209-
}
210-
}, BUILD_UPDATE_DEBOUNCE_MS);
211-
}
204+
if (changedFiles && changedFiles.length) {
205+
// cool, we've got some build updating to do ;)
206+
queueOrRunBuildUpdate(changedFiles, context);
207+
}
208+
}, BUILD_UPDATE_DEBOUNCE_MS);
212209

213210
return Promise.resolve();
214211
}

0 commit comments

Comments
 (0)