mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Remove potentially unnecessary optimisation
This commit is contained in:
parent
1beab4f5c0
commit
aab03481a2
2 changed files with 6 additions and 46 deletions
|
@ -15,7 +15,8 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "vite",
|
"start": "vite",
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"build:preview": "yarn build && vite preview --port 5002",
|
"preview": "vite preview --port 5002",
|
||||||
|
"build:preview": "yarn build && yarn preview",
|
||||||
"build:package": "yarn workspace @excalidraw/excalidraw run build:esm"
|
"build:package": "yarn workspace @excalidraw/excalidraw run build:esm"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,55 +12,14 @@ export const WorkerUrl: URL | undefined = import.meta.url
|
||||||
? new URL(import.meta.url)
|
? new URL(import.meta.url)
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
// variables to track processing state and latest input data
|
|
||||||
// for "backpressure" purposes
|
|
||||||
let isProcessing: boolean = false;
|
|
||||||
let latestInputData: LassoWorkerInput | null = null;
|
|
||||||
|
|
||||||
// run only in the worker context
|
// run only in the worker context
|
||||||
if (typeof window === "undefined" && typeof self !== "undefined") {
|
if (typeof window === "undefined" && typeof self !== "undefined") {
|
||||||
self.onmessage = (event: MessageEvent<LassoWorkerInput>) => {
|
self.onmessage = (event: MessageEvent<LassoWorkerInput>) => {
|
||||||
if (!event.data) {
|
switch (event.data.command) {
|
||||||
self.postMessage({
|
|
||||||
error: "No data received",
|
|
||||||
selectedElementIds: [],
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
latestInputData = event.data;
|
|
||||||
|
|
||||||
if (!isProcessing) {
|
|
||||||
processInputData();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// function to process the latest data
|
|
||||||
const processInputData = () => {
|
|
||||||
// If no data to process, return
|
|
||||||
if (!latestInputData) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// capture the current data to process and reset latestData
|
|
||||||
const dataToProcess = latestInputData;
|
|
||||||
latestInputData = null; // reset to avoid re-processing the same data
|
|
||||||
isProcessing = true;
|
|
||||||
|
|
||||||
try {
|
|
||||||
switch (dataToProcess.command) {
|
|
||||||
case Commands.GET_LASSO_SELECTED_ELEMENT_IDS:
|
case Commands.GET_LASSO_SELECTED_ELEMENT_IDS:
|
||||||
const result = getLassoSelectedElementIds(dataToProcess);
|
const result = getLassoSelectedElementIds(event.data);
|
||||||
self.postMessage(result);
|
self.postMessage(result);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} finally {
|
};
|
||||||
isProcessing = false;
|
}
|
||||||
// if new data arrived during processing, process it
|
|
||||||
// as we're done with processing the previous data
|
|
||||||
if (latestInputData) {
|
|
||||||
processInputData();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue