feat(workbench): add file tree and hook up editor

This commit is contained in:
Dominic Elm
2024-07-18 23:07:04 +02:00
parent 012b5bae80
commit a7d8693d8c
17 changed files with 806 additions and 148 deletions

View File

@@ -0,0 +1,29 @@
export function bufferWatchEvents<T extends unknown[]>(timeInMs: number, cb: (events: T[]) => unknown) {
let timeoutId: number | undefined;
let events: T[] = [];
// keep track of the processing of the previous batch so we can wait for it
let processing: Promise<unknown> = Promise.resolve();
const scheduleBufferTick = () => {
timeoutId = self.setTimeout(async () => {
// we wait until the previous batch is entirely processed so events are processed in order
await processing;
if (events.length > 0) {
processing = Promise.resolve(cb(events));
}
timeoutId = undefined;
events = [];
}, timeInMs);
};
return (...args: T) => {
events.push(args);
if (!timeoutId) {
scheduleBufferTick();
}
};
}