Some optimization of immutable object use
This commit is contained in:
parent
c7aca59afc
commit
13dc496a02
@ -13,21 +13,21 @@ class Base extends React.PureComponent {
|
||||
}
|
||||
|
||||
async setBBox(box, recalculate = {}) {
|
||||
let bbox = this._currentBBox() || Map({ width: 0, height: 0});
|
||||
|
||||
bbox = bbox.merge(box);
|
||||
const bbox = (this._currentBBox() || Map({ width: 0, height: 0})).withMutations(bbox => {
|
||||
bbox.merge(box);
|
||||
|
||||
if (!bbox.has('axisY') || recalculate.axisY) {
|
||||
bbox = bbox.set('axisY', bbox.get('height') / 2);
|
||||
bbox.set('axisY', bbox.get('height') / 2);
|
||||
}
|
||||
|
||||
if (!bbox.has('axisX1') || recalculate.axisX1) {
|
||||
bbox = bbox.set('axisX1', 0);
|
||||
bbox.set('axisX1', 0);
|
||||
}
|
||||
|
||||
if (!bbox.has('axisX2') || recalculate.axisX2) {
|
||||
bbox = bbox.set('axisX2', bbox.get('width'));
|
||||
bbox.set('axisX2', bbox.get('width'));
|
||||
}
|
||||
});
|
||||
|
||||
this.tempBBox = bbox; // Want to get the updated bbox while setState is pending
|
||||
await this.setStateAsync({ bbox });
|
||||
|
@ -21,9 +21,11 @@ class HorizontalLayout extends Base {
|
||||
}
|
||||
|
||||
updateChildTransforms(childBoxes) {
|
||||
return childBoxes.reduce((transforms, box, i) => (
|
||||
return this.state.childTransforms.withMutations(transforms => (
|
||||
childBoxes.forEach((box, i) => (
|
||||
transforms.set(i, `translate(${ box.offsetX } ${ box.offsetY })`)
|
||||
), this.state.childTransforms);
|
||||
))
|
||||
));
|
||||
}
|
||||
|
||||
updateConnectorPaths(childBoxes) {
|
||||
|
@ -23,9 +23,11 @@ class VerticalLayout extends Base {
|
||||
}
|
||||
|
||||
updateChildTransforms(childBoxes) {
|
||||
return childBoxes.reduce((transforms, box, i) => (
|
||||
return this.state.childTransforms.withMutations(transforms => (
|
||||
childBoxes.forEach((box, i) => (
|
||||
transforms.set(i, `translate(${ box.offsetX } ${ box.offsetY })`)
|
||||
), this.state.childTransforms);
|
||||
))
|
||||
));
|
||||
}
|
||||
|
||||
makeCurve(box) {
|
||||
|
Loading…
Reference in New Issue
Block a user