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 = {}) {
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 });

View File

@ -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) {

View File

@ -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) {