Skip to content

Commit 73f433c

Browse files
committed
When patching, apply layout outside of batching.
1 parent 5d0284a commit 73f433c

2 files changed

Lines changed: 46 additions & 44 deletions

File tree

src/component.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,7 @@ export default class CytoscapeComponent extends React.Component {
8181
const cy = this._cy;
8282
const { diff, toJson, get, forEach } = newProps;
8383

84-
// batch for peformance
85-
cy.batch(() => {
86-
patch(cy, prevProps, newProps, diff, toJson, get, forEach);
87-
});
84+
patch(cy, prevProps, newProps, diff, toJson, get, forEach);
8885

8986
if (newProps.cy != null) {
9087
newProps.cy(cy);

src/patch.js

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,53 @@ const isDiffAtKey = (json1, json2, diff, key) =>
55
diff(atKey(json1, key), atKey(json2, key));
66

77
export const patch = (cy, json1, json2, diff, toJson, get, forEach) => {
8-
// The shallow object diff() must defer to patchElements() as it must compare the
9-
// elements as an unordered set. A custom diff(), with Immutable for example,
10-
// could just use an equality check (===).
11-
if (diff === shallowObjDiff || isDiffAtKey(json1, json2, diff, 'elements')) {
12-
patchElements(
13-
cy,
14-
atKey(json1, 'elements'),
15-
atKey(json2, 'elements'),
16-
toJson,
17-
get,
18-
forEach,
19-
diff
20-
);
21-
}
22-
23-
if (isDiffAtKey(json1, json2, diff, 'stylesheet')) {
24-
patchStyle(
25-
cy,
26-
atKey(json1, 'stylesheet'),
27-
atKey(json2, 'stylesheet'),
28-
toJson
29-
);
30-
}
8+
cy.batch(() => {
9+
// The shallow object diff() must defer to patchElements() as it must compare the
10+
// elements as an unordered set. A custom diff(), with Immutable for example,
11+
// could just use an equality check (===).
12+
if (
13+
diff === shallowObjDiff ||
14+
isDiffAtKey(json1, json2, diff, 'elements')
15+
) {
16+
patchElements(
17+
cy,
18+
atKey(json1, 'elements'),
19+
atKey(json2, 'elements'),
20+
toJson,
21+
get,
22+
forEach,
23+
diff
24+
);
25+
}
3126

32-
[
33-
// simple keys that can be patched directly (key same as fn name)
34-
'zoom',
35-
'minZoom',
36-
'maxZoom',
37-
'zoomingEnabled',
38-
'userZoomingEnabled',
39-
'pan',
40-
'panningEnabled',
41-
'userPanningEnabled',
42-
'boxSelectionEnabled',
43-
'autoungrabify',
44-
'autolock',
45-
'autounselectify'
46-
].forEach(key => {
47-
if (isDiffAtKey(json1, json2, diff, key)) {
48-
patchJson(cy, key, atKey(json1, key), atKey(json2, key), toJson);
27+
if (isDiffAtKey(json1, json2, diff, 'stylesheet')) {
28+
patchStyle(
29+
cy,
30+
atKey(json1, 'stylesheet'),
31+
atKey(json2, 'stylesheet'),
32+
toJson
33+
);
4934
}
35+
36+
[
37+
// simple keys that can be patched directly (key same as fn name)
38+
'zoom',
39+
'minZoom',
40+
'maxZoom',
41+
'zoomingEnabled',
42+
'userZoomingEnabled',
43+
'pan',
44+
'panningEnabled',
45+
'userPanningEnabled',
46+
'boxSelectionEnabled',
47+
'autoungrabify',
48+
'autolock',
49+
'autounselectify'
50+
].forEach(key => {
51+
if (isDiffAtKey(json1, json2, diff, key)) {
52+
patchJson(cy, key, atKey(json1, key), atKey(json2, key), toJson);
53+
}
54+
});
5055
});
5156

5257
if (isDiffAtKey(json1, json2, diff, 'layout')) {

0 commit comments

Comments
 (0)