Some optimization of immutable object use

This commit is contained in:
Jeff Avallone 2018-02-17 16:13:19 -05:00
parent c7aca59afc
commit 13dc496a02
3 changed files with 22 additions and 18 deletions

View File

@ -13,21 +13,21 @@ class Base extends React.PureComponent {
} }
async setBBox(box, recalculate = {}) { 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) { if (!bbox.has('axisX1') || recalculate.axisX1) {
bbox = bbox.set('axisY', bbox.get('height') / 2); bbox.set('axisX1', 0);
} }
if (!bbox.has('axisX1') || recalculate.axisX1) { if (!bbox.has('axisX2') || recalculate.axisX2) {
bbox = bbox.set('axisX1', 0); bbox.set('axisX2', bbox.get('width'));
} }
});
if (!bbox.has('axisX2') || recalculate.axisX2) {
bbox = bbox.set('axisX2', bbox.get('width'));
}
this.tempBBox = bbox; // Want to get the updated bbox while setState is pending this.tempBBox = bbox; // Want to get the updated bbox while setState is pending
await this.setStateAsync({ bbox }); await this.setStateAsync({ bbox });

View File

@ -21,9 +21,11 @@ class HorizontalLayout extends Base {
} }
updateChildTransforms(childBoxes) { updateChildTransforms(childBoxes) {
return childBoxes.reduce((transforms, box, i) => ( return this.state.childTransforms.withMutations(transforms => (
transforms.set(i, `translate(${ box.offsetX } ${ box.offsetY })`) childBoxes.forEach((box, i) => (
), this.state.childTransforms); transforms.set(i, `translate(${ box.offsetX } ${ box.offsetY })`)
))
));
} }
updateConnectorPaths(childBoxes) { updateConnectorPaths(childBoxes) {

View File

@ -23,9 +23,11 @@ class VerticalLayout extends Base {
} }
updateChildTransforms(childBoxes) { updateChildTransforms(childBoxes) {
return childBoxes.reduce((transforms, box, i) => ( return this.state.childTransforms.withMutations(transforms => (
transforms.set(i, `translate(${ box.offsetX } ${ box.offsetY })`) childBoxes.forEach((box, i) => (
), this.state.childTransforms); transforms.set(i, `translate(${ box.offsetX } ${ box.offsetY })`)
))
));
} }
makeCurve(box) { makeCurve(box) {