Skip to content

Commit 2e8e4f0

Browse files
committed
Implement cleanup for layout effect
This should allow changing nodes multiple times without waiting for every zoom animation
1 parent 7321871 commit 2e8e4f0

File tree

1 file changed

+22
-0
lines changed
  • rust/cubesql/cubesql/egraph-debug-template/src

1 file changed

+22
-0
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ async function layout(
6363
fitView,
6464
navHistory,
6565
showOnlySelected,
66+
abortSignal,
6667
) {
6768
const defaultOptions = {
6869
'elk.algorithm': 'layered',
@@ -143,6 +144,10 @@ async function layout(
143144
const elk = new ELK();
144145
const { children } = await elk.layout(graph);
145146

147+
if (abortSignal.aborted) {
148+
return;
149+
}
150+
146151
// By mutating the children in-place we saves ourselves from creating a
147152
// needless copy of the nodes array.
148153
const flatChildren = [];
@@ -153,9 +158,21 @@ async function layout(
153158

154159
setNodes(flatChildren);
155160
setEdges(edges);
161+
162+
if (abortSignal.aborted) {
163+
return;
164+
}
156165
window.requestAnimationFrame(() => {
166+
if (abortSignal.aborted) {
167+
return;
168+
}
169+
157170
if (navHistory?.length) {
158171
setTimeout(() => {
172+
if (abortSignal.aborted) {
173+
return;
174+
}
175+
159176
zoomTo(fitView, navHistory);
160177
}, 500);
161178
} else {
@@ -390,6 +407,8 @@ const LayoutFlow = () => {
390407
);
391408

392409
useEffect(() => {
410+
const ac = new AbortController();
411+
393412
layout(
394413
{},
395414
jsonClone(preNodes),
@@ -399,7 +418,10 @@ const LayoutFlow = () => {
399418
fitView,
400419
navHistory,
401420
showOnlySelected,
421+
ac.signal,
402422
);
423+
424+
return () => ac.abort();
403425
}, [
404426
preNodes,
405427
setNodes,

0 commit comments

Comments
 (0)