Skip to content

Commit 9709f5a

Browse files
committed
Avoid unnecessary state update by Graph focus before blurring
1 parent fc5af60 commit 9709f5a

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

src/Graph.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -259,12 +259,12 @@ class Graph extends React.Component {
259259
}
260260

261261
handleClickDiv(d, i, nodes) {
262+
this.props.onFocus();
262263
document.activeElement.blur();
263264
var event = d3_event;
264265
event.preventDefault();
265266
event.stopPropagation();
266267
this.unSelectComponents();
267-
this.props.onFocus();
268268
}
269269

270270
handleKeyDownDocument(d, i, nodes) {
@@ -347,6 +347,7 @@ class Graph extends React.Component {
347347
}
348348

349349
handleClickNode(d, i, nodes) {
350+
this.props.onFocus();
350351
document.activeElement.blur();
351352
var event = d3_event;
352353
event.preventDefault();
@@ -355,10 +356,10 @@ class Graph extends React.Component {
355356
let extendSelection = event.ctrlKey || event.shiftKey;
356357
this.selectComponents(d3_select(nodes[i]), extendSelection);
357358
}
358-
this.props.onFocus();
359359
}
360360

361361
handleDblClickNode(d, i, nodes) {
362+
this.props.onFocus();
362363
document.activeElement.blur();
363364
var event = d3_event;
364365
event.preventDefault();
@@ -375,10 +376,10 @@ class Graph extends React.Component {
375376
this.props.onTextChange(this.dotGraph.dotSrc);
376377
}
377378
this.isDrawingEdge = false;
378-
this.props.onFocus();
379379
}
380380

381381
handleRightClickNode(d, i, nodes) {
382+
this.props.onFocus();
382383
document.activeElement.blur();
383384
var event = d3_event;
384385
event.preventDefault();
@@ -397,39 +398,37 @@ class Graph extends React.Component {
397398
this.graphviz
398399
.drawEdge(x0, y0, x0, y0, this.latestEdgeAttributes);
399400
this.isDrawingEdge = true;
400-
this.props.onFocus();
401401
}
402402

403403
handleClickEdge(d, i, nodes) {
404+
this.props.onFocus();
404405
document.activeElement.blur();
405406
var event = d3_event;
406407
event.preventDefault();
407408
event.stopPropagation();
408409
let extendSelection = event.ctrlKey || event.shiftKey;
409410
this.selectComponents(d3_select(nodes[i]), extendSelection);
410-
this.props.onFocus();
411411
}
412412

413413
handleRightClickDiv(d, i, nodes) {
414+
this.props.onFocus();
414415
document.activeElement.blur();
415416
var event = d3_event;
416417
event.preventDefault();
417418
event.stopPropagation();
418419
this.unSelectComponents();
419-
this.props.onFocus();
420420
}
421421

422422
handleMouseDownSvg(d, i, nodes) {
423+
this.props.onFocus();
423424
document.activeElement.blur();
424425
var event = d3_event;
425426
if (event.which !== 1) {
426-
this.props.onFocus();
427427
return;
428428
}
429429
event.preventDefault();
430430
event.stopPropagation();
431431
if (this.selectArea) {
432-
this.props.onFocus();
433432
return;
434433
}
435434
var [x0, y0] = d3_mouse(this.graph0.node());
@@ -444,7 +443,6 @@ class Graph extends React.Component {
444443
.attr("stroke", '#0000dd')
445444
.style('stroke-width', 0.5)
446445
.style('fill-opacity', 0.3);
447-
this.props.onFocus();
448446
}
449447

450448
handleMouseMoveSvg(d, i, nodes) {
@@ -467,6 +465,7 @@ class Graph extends React.Component {
467465
}
468466

469467
handleMouseUpSvg(d, i, nodes) {
468+
this.props.onFocus();
470469
document.activeElement.blur();
471470
var event = d3_event;
472471
if (event.which === 1 && this.selectArea) {
@@ -481,7 +480,6 @@ class Graph extends React.Component {
481480
let height = Math.abs(y1 - y0);
482481
if (width === 0 && height === 0) {
483482
this.selectArea = null;
484-
this.props.onFocus();
485483
return;
486484
}
487485
let components = this.graph0.selectAll('.node,.edge');
@@ -505,7 +503,6 @@ class Graph extends React.Component {
505503
this.insertNodeWithLatestAttributes(x0, y0);
506504
}
507505
}
508-
this.props.onFocus();
509506
}
510507

511508
selectComponents(components, extendSelection=false) {

0 commit comments

Comments
 (0)