Skip to content

Commit ca083c7

Browse files
committed
Setup web worker for ELK
1 parent e8e59f9 commit ca083c7

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

rust/cubesql/cubesql/egraph-debug-template/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"@types/react-dom": "18.0.11",
2424
"prettier": "3.3.3",
2525
"react-scripts": "5.0.1",
26-
"typescript": "4.9.5"
26+
"typescript": "4.9.5",
27+
"web-worker": "1.3.0"
2728
},
2829
"eslintConfig": {
2930
"extends": [

rust/cubesql/cubesql/egraph-debug-template/src/index.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createRoot } from 'react-dom/client';
2-
import ELK from 'elkjs/lib/elk.bundled.js';
2+
import ELK from 'elkjs';
33
import type { ElkNode, LayoutOptions } from 'elkjs';
44
import { useCallback, useState, useEffect, useMemo } from 'react';
55
import ReactFlow, {
@@ -97,6 +97,18 @@ const initialNodes = data.combos
9797
.concat(data.nodes.map(toRegularNode));
9898
const initialEdges = data.edges.map(toEdge);
9999

100+
const elk = new ELK({
101+
workerFactory: function (_url) {
102+
// TODO something is broken with bundling and web-worker
103+
return new Worker(
104+
new URL(
105+
'../node_modules/elkjs/lib/elk-worker.min.js',
106+
import.meta.url,
107+
),
108+
);
109+
},
110+
});
111+
100112
async function layout(
101113
options: LayoutOptions,
102114
nodes: Array<Node>,
@@ -200,7 +212,8 @@ async function layout(
200212
});
201213
}
202214

203-
const elk = new ELK();
215+
// TODO add throbber while waiting for layout
216+
// TODO add queue to be able to cancel request before sending it to worker
204217
const { children } = await elk.layout(graph);
205218

206219
if (abortSignal.aborted) {

0 commit comments

Comments
 (0)