Skip to content

Commit

Permalink
Run dev code in worker. This mitigates browsers hanging while loading…
Browse files Browse the repository at this point in the history
…/debugging the dev page.

Uses the workaround from evanw/esbuild#312 (comment) , since evanw/esbuild#2508 has not landed.
  • Loading branch information
lgarron committed Nov 30, 2022
1 parent 7afd19e commit 6a5d51c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/js/dev/index.html
@@ -1,4 +1,4 @@
<script src="./test.js" href="./test.ts" type="module"></script>
<script src="./index.js" href="./index.ts" type="module"></script>
<style>
html {
font-family: sans-serif;
Expand Down
3 changes: 3 additions & 0 deletions src/js/dev/index.ts
@@ -0,0 +1,3 @@
import { workerURL } from "./worker";

new Worker(workerURL, { type: "module" });
32 changes: 0 additions & 32 deletions src/js/dev/test.ts

This file was deleted.

39 changes: 39 additions & 0 deletions src/js/dev/worker.ts
@@ -0,0 +1,39 @@
// TODO: remove once `esbuild` supports relative URLs: https://github.com/evanw/esbuild/pull/2508
export const workerURL = import.meta.url;

if (globalThis.WorkerGlobalScope) {
(async () => {
const [
{ cube3x3x3 },
{ setKPuzzleDefString, solveState, serializeDefToTws },
] = await Promise.all([import("cubing/puzzles"), import("..")]);

await setKPuzzleDefString(
serializeDefToTws(await cube3x3x3.kpuzzle(), {
moveSubset: ["U", "L", "F", "R", "B", "D"],
startState: `EDGES
0 0 0 0 1 2 3 4 5 6 7 8
0 0 0 0 0 0 0 0 0 0 0 0
CORNERS
0 0 0 0 1 2 3 4
0 0 0 0 0 0 0 0
CENTERS
0 1 2 3 4 5
0 0 0 0 0 0`,
}),
);
(
await solveState(`ScrambleState test
EDGES
0 0 0 0 1 2 3 4 5 6 7 8
1 1 1 1 0 0 0 0 0 0 0 0
CORNERS
0 0 0 0 1 2 3 4
0 0 0 0 0 0 0 0
CENTERS
0 1 2 3 4 5
0 0 0 0 0 0
End`)
).log();
})();
}

0 comments on commit 6a5d51c

Please sign in to comment.