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});
|
||||
const bbox = (this._currentBBox() || Map({ width: 0, height: 0})).withMutations(bbox => {
|
||||
bbox.merge(box);
|
||||
|
||||
bbox = bbox.merge(box);
|
||||
if (!bbox.has('axisY') || recalculate.axisY) {
|
||||
bbox.set('axisY', bbox.get('height') / 2);
|
||||
}
|
||||
|
||||
if (!bbox.has('axisY') || recalculate.axisY) {
|
||||
bbox = bbox.set('axisY', bbox.get('height') / 2);
|
||||
}
|
||||
if (!bbox.has('axisX1') || recalculate.axisX1) {
|
||||
bbox.set('axisX1', 0);
|
||||
}
|
||||
|
||||
if (!bbox.has('axisX1') || recalculate.axisX1) {
|
||||
bbox = bbox.set('axisX1', 0);
|
||||
}
|
||||
|
||||
if (!bbox.has('axisX2') || recalculate.axisX2) {
|
||||
bbox = bbox.set('axisX2', bbox.get('width'));
|
||||
}
|
||||
if (!bbox.has('axisX2') || recalculate.axisX2) {
|
||||
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) => (
|
||||
transforms.set(i, `translate(${ box.offsetX } ${ box.offsetY })`)
|
||||
), this.state.childTransforms);
|
||||
return this.state.childTransforms.withMutations(transforms => (
|
||||
childBoxes.forEach((box, i) => (
|
||||
transforms.set(i, `translate(${ box.offsetX } ${ box.offsetY })`)
|
||||
))
|
||||
));
|
||||
}
|
||||
|
||||
updateConnectorPaths(childBoxes) {
|
||||
|
@ -23,9 +23,11 @@ class VerticalLayout extends Base {
|
||||
}
|
||||
|
||||
updateChildTransforms(childBoxes) {
|
||||
return childBoxes.reduce((transforms, box, i) => (
|
||||
transforms.set(i, `translate(${ box.offsetX } ${ box.offsetY })`)
|
||||
), this.state.childTransforms);
|
||||
return this.state.childTransforms.withMutations(transforms => (
|
||||
childBoxes.forEach((box, i) => (
|
||||
transforms.set(i, `translate(${ box.offsetX } ${ box.offsetY })`)
|
||||
))
|
||||
));
|
||||
}
|
||||
|
||||
makeCurve(box) {
|
||||
|
Loading…
Reference in New Issue
Block a user