Skip to content

Commit 6163ad2

Browse files
committed
Faster bounds clone
1 parent 9137b6b commit 6163ad2

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lib/utils/positionFns.es6

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ export function getBoundPosition(draggable, clientX, clientY) {
66
// If no bounds, short-circuit and move on
77
if (!draggable.props.bounds) return [clientX, clientY];
88

9-
let bounds = JSON.parse(JSON.stringify(draggable.props.bounds));
9+
// Clone new bounds
10+
let bounds = cloneBounds(draggable.props.bounds);
1011
let node = ReactDOM.findDOMNode(draggable);
1112

1213
if (typeof bounds === 'string') {
@@ -63,3 +64,13 @@ export function getControlPosition(e) {
6364
clientY: position.clientY
6465
};
6566
}
67+
68+
// A lot faster than stringify/parse
69+
function cloneBounds(bounds) {
70+
return {
71+
left: bounds.left,
72+
top: bounds.top,
73+
right: bounds.right,
74+
bottom: bounds.bottom
75+
};
76+
}

0 commit comments

Comments
 (0)