Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/GraphArea.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,17 @@ function Graph({

useEffect(() => {
const handleResize = () => setContainerDim(ref.current);
let graph = null;
if (ref.current) {
setContainerDim(ref.current);
window.addEventListener('resize', handleResize);
setInstance(initialiseNewGraph());
graph = initialiseNewGraph();
setInstance(graph);
}
return () => window.removeEventListener('resize', handleResize);
return () => {
window.removeEventListener('resize', handleResize);
if (graph) graph.dispose();
};
}, [ref]);

// Update theme when darkMode changes
Expand Down
4 changes: 3 additions & 1 deletion src/component/TabBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ const TabBar = ({ superState, dispatcher }) => {
const [tabToClose, setTabToClose] = useState(null);

const closeTab = (i) => {
localStorageManager.remove(superState.graphs[i] ? superState.graphs[i].graphID : null);
const graph = superState.graphs[i];
if (graph && graph.instance) graph.instance.dispose();
localStorageManager.remove(graph ? graph.graphID : null);
dispatcher({ type: T.REMOVE_GRAPH, payload: i });
if (!superState.curGraphIndex && superState.graphs.length === 1) {
dispatcher({ type: T.SET_CUR_INSTANCE, payload: null });
Expand Down
9 changes: 9 additions & 0 deletions src/graph-builder/graph-core/1-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,15 @@ class CoreGraph {
}
}

dispose() {
if (!this.cy) return;
if (this.autoSaveIntervalId !== null) clearTimeout(this.autoSaveIntervalId);
this.autoSaveIntervalId = null;
this.cy.destroy();
this.cy = null;
this.dispatcher = null;
}

reset() {
this.resetAllComp();
this.resetAllAction();
Expand Down