From aab03481a229d8f1a4675d7ffaf12060cefcd341 Mon Sep 17 00:00:00 2001 From: Marcel Mraz Date: Wed, 2 Apr 2025 11:34:10 +0100 Subject: [PATCH] Remove potentially unnecessary optimisation --- examples/with-script-in-browser/package.json | 3 +- .../excalidraw/lasso/lasso-worker.chunk.ts | 49 ++----------------- 2 files changed, 6 insertions(+), 46 deletions(-) diff --git a/examples/with-script-in-browser/package.json b/examples/with-script-in-browser/package.json index 3d61f1a1b..2b4311711 100644 --- a/examples/with-script-in-browser/package.json +++ b/examples/with-script-in-browser/package.json @@ -15,7 +15,8 @@ "scripts": { "start": "vite", "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" } } diff --git a/packages/excalidraw/lasso/lasso-worker.chunk.ts b/packages/excalidraw/lasso/lasso-worker.chunk.ts index 926969c58..9a2b25e4a 100644 --- a/packages/excalidraw/lasso/lasso-worker.chunk.ts +++ b/packages/excalidraw/lasso/lasso-worker.chunk.ts @@ -12,55 +12,14 @@ export const WorkerUrl: URL | undefined = import.meta.url ? new URL(import.meta.url) : 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 if (typeof window === "undefined" && typeof self !== "undefined") { self.onmessage = (event: MessageEvent) => { - if (!event.data) { - 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) { + switch (event.data.command) { case Commands.GET_LASSO_SELECTED_ELEMENT_IDS: - const result = getLassoSelectedElementIds(dataToProcess); + const result = getLassoSelectedElementIds(event.data); self.postMessage(result); break; } - } finally { - isProcessing = false; - // if new data arrived during processing, process it - // as we're done with processing the previous data - if (latestInputData) { - processInputData(); - } - } -}; + }; +}