Skip to content

Commit

Permalink
Faster bounds clone
Browse files Browse the repository at this point in the history
  • Loading branch information
STRML committed Feb 10, 2016
1 parent 9137b6b commit 6163ad2
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/utils/positionFns.es6
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export function getBoundPosition(draggable, clientX, clientY) {
// If no bounds, short-circuit and move on
if (!draggable.props.bounds) return [clientX, clientY];

let bounds = JSON.parse(JSON.stringify(draggable.props.bounds));
// Clone new bounds
let bounds = cloneBounds(draggable.props.bounds);
let node = ReactDOM.findDOMNode(draggable);

if (typeof bounds === 'string') {
Expand Down Expand Up @@ -63,3 +64,13 @@ export function getControlPosition(e) {
clientY: position.clientY
};
}

// A lot faster than stringify/parse
function cloneBounds(bounds) {
return {
left: bounds.left,
top: bounds.top,
right: bounds.right,
bottom: bounds.bottom
};
}

0 comments on commit 6163ad2

Please sign in to comment.