Skip to content

Commit 3cd5508

Browse files
Make SVGRender a global instance (#324)
1 parent 2f7f5be commit 3cd5508

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

src/components/GraphViewport.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { Component } from 'react';
22

3-
import { Viewport } from './../graph/';
3+
import { SVGRender, Viewport } from './../graph/';
44
import LoadingAnimation from './utils/LoadingAnimation';
55

6+
const svgRenderer = new SVGRender();
7+
68
interface GraphViewportProps {
7-
svgRenderer: any;
89
typeGraph: any;
910
displayOptions: any;
1011

@@ -83,7 +84,7 @@ export default class GraphViewport extends Component<GraphViewportProps> {
8384
this._currentTypeGraph = typeGraph;
8485
this._currentDisplayOptions = displayOptions;
8586

86-
const { svgRenderer, onSelectNode, onSelectEdge } = this.props;
87+
const { onSelectNode, onSelectEdge } = this.props;
8788
svgRenderer
8889
.renderSvg(typeGraph, displayOptions)
8990
.then((svg) => {

src/components/Voyager.tsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
useState,
1515
} from 'react';
1616

17-
import { getTypeGraph, SVGRender } from '../graph/';
17+
import { getTypeGraph } from '../graph/';
1818
import { extractTypeId, getSchema } from '../introspection';
1919
import DocExplorer from './doc-explorer/DocExplorer';
2020
import GraphViewport from './GraphViewport';
@@ -106,9 +106,6 @@ export default function Voyager(props: VoyagerProps) {
106106
const viewportRef = useRef(null);
107107
useEffect(() => viewportRef.current?.resize(), [hideDocs]);
108108

109-
// TODO: move into GraphViewport
110-
const svgRenderer = useMemo(() => new SVGRender(), []);
111-
112109
return (
113110
<ThemeProvider theme={theme}>
114111
<div className="graphql-voyager">
@@ -190,7 +187,6 @@ export default function Voyager(props: VoyagerProps) {
190187
function renderGraphViewport() {
191188
return (
192189
<GraphViewport
193-
svgRenderer={svgRenderer}
194190
typeGraph={typeGraph}
195191
displayOptions={displayOptions}
196192
selectedTypeID={selected.typeID}

0 commit comments

Comments
 (0)