Skip to content

Commit

Permalink
Don't re-render the graph when the DOT source is unchanged
Browse files Browse the repository at this point in the history
This significantly improves the response time of the UI, since the
graph does not need to be re-rendered for simple UI state changes such
as opening a dialog.
  • Loading branch information
magjac committed Aug 29, 2018
1 parent 8b29d05 commit d0c44e9
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class Graph extends React.Component {
this.pendingUpdate = false;
this.rendering = false;
this.prevFit = null;
this.prevDotSrc = '';
}

componentDidMount() {
Expand Down Expand Up @@ -90,6 +91,9 @@ class Graph extends React.Component {
if (this.props.dotSrc.length === 0) {
return;
}
if (this.props.dotSrc === this.prevDotSrc) {
return;
}
if (this.rendering) {
this.pendingUpdate = true;
return;
Expand All @@ -106,6 +110,7 @@ class Graph extends React.Component {
}
this.prevFit = this.props.fit;
}
this.prevDotSrc = this.props.dotSrc;
this.rendering = true;
this.graphviz
.width(width)
Expand Down

0 comments on commit d0c44e9

Please sign in to comment.