Handle the case where positions might be an empty object to begin with

This commit is contained in:
Jordan Eldredge 2018-09-19 23:44:16 -07:00
parent 38f032b2c7
commit f266b60041
2 changed files with 8 additions and 7 deletions

View file

@ -63,7 +63,7 @@ class WindowManager extends React.Component {
y: Math.ceil(offsetTop + (globalOffsetTop + offset))
};
});
this.props.updateWindowPositions(windowPositions);
this.props.updateWindowPositions(windowPositions, false);
} else {
// A layout has been suplied. We will compute the bounding box and
// center the given layout.
@ -87,7 +87,7 @@ class WindowManager extends React.Component {
{}
);
this.props.updateWindowPositions(newPositions);
this.props.updateWindowPositions(newPositions, false);
}
this.props.windowsHaveBeenCentered();
};
@ -171,7 +171,7 @@ class WindowManager extends React.Component {
return diff;
}, {});
this.props.updateWindowPositions(windowPositionDiff);
this.props.updateWindowPositions(windowPositionDiff, false);
};
const removeListeners = () => {
@ -228,8 +228,8 @@ const mapStateToProps = state => ({
const mapDispatchToProps = dispatch => {
return {
updateWindowPositions: positions =>
dispatch(updateWindowPositions(positions)),
updateWindowPositions: (positions, centered) =>
dispatch(updateWindowPositions(positions, centered)),
windowsHaveBeenCentered: () => dispatch(windowsHaveBeenCentered())
};
};

View file

@ -198,10 +198,11 @@ const windows = (
}
return { ...w, ...serializedW };
}),
positions: objectMap(state.positions, (position, windowId) => {
// Note: We iterate genWindows here, since the positions object may be empty
positions: objectMap(state.genWindows, (position, windowId) => {
const serializedPosition = serializedPositions[windowId];
if (serializedPosition == null) {
return position;
return state.positions[windowId];
}
return serializedPosition;
}),