Skip to content

Commit d18cf7f

Browse files
committedFeb 19, 2020
feat: DevTools - Removed useCallback.
1 parent dc30845 commit d18cf7f

File tree

1 file changed

+56
-65
lines changed
  • packages/react-devtools-shared/src/devtools/views/Components

1 file changed

+56
-65
lines changed
 

‎packages/react-devtools-shared/src/devtools/views/Components/Components.js

+56-65
Original file line numberDiff line numberDiff line change
@@ -111,73 +111,64 @@ function ComponentResizer({children}): {|children: Function|} {
111111
: RESIZE_DIRECTIONS.VERTICAL;
112112
}, [componentsWrapperRef]);
113113

114-
const onResizeStart = useCallback(() => {
115-
setIsResizing(true);
116-
}, [setIsResizing]);
117-
118-
const onResizeEnd = useCallback(() => {
119-
setIsResizing(false);
120-
}, [setIsResizing]);
121-
122-
const onResize = useCallback(
123-
e => {
124-
if (
125-
!isResizing ||
126-
componentsWrapperRef.current === null ||
127-
resizeElementRef.current === null
128-
) {
129-
return;
130-
}
131-
132-
e.preventDefault();
114+
const onResizeStart = () => setIsResizing(true);
115+
const onResizeEnd = () => setIsResizing(false);
116+
const onResize = e => {
117+
if (
118+
!isResizing ||
119+
componentsWrapperRef.current === null ||
120+
resizeElementRef.current === null
121+
) {
122+
return;
123+
}
133124

134-
const {
135-
height,
136-
width,
137-
left,
138-
top,
139-
} = componentsWrapperRef.current.getBoundingClientRect();
140-
const resizeDirection = getResizeDirection();
141-
const currentMousePosition: number =
125+
e.preventDefault();
126+
127+
const {
128+
height,
129+
width,
130+
left,
131+
top,
132+
} = componentsWrapperRef.current.getBoundingClientRect();
133+
const resizeDirection = getResizeDirection();
134+
const currentMousePosition: number =
135+
resizeDirection === RESIZE_DIRECTIONS.HORIZONTAL
136+
? e.clientX - left
137+
: e.clientY - top;
138+
const BOUNDARY_PADDING: number = 40;
139+
const boundary: {|
140+
min: number,
141+
max: number,
142+
|} = {
143+
min: BOUNDARY_PADDING,
144+
max:
142145
resizeDirection === RESIZE_DIRECTIONS.HORIZONTAL
143-
? e.clientX - left
144-
: e.clientY - top;
145-
const BOUNDARY_PADDING: number = 40;
146-
const boundary: {|
147-
min: number,
148-
max: number,
149-
|} = {
150-
min: BOUNDARY_PADDING,
151-
max:
152-
resizeDirection === RESIZE_DIRECTIONS.HORIZONTAL
153-
? width - BOUNDARY_PADDING
154-
: height - BOUNDARY_PADDING,
155-
};
156-
const isMousePositionInBounds: boolean =
157-
currentMousePosition > boundary.min &&
158-
currentMousePosition < boundary.max;
159-
160-
if (isMousePositionInBounds) {
161-
const resizedElementDimension: number =
162-
resizeDirection === RESIZE_DIRECTIONS.HORIZONTAL ? width : height;
163-
const updatedFlexBasisValue: number =
164-
(currentMousePosition / resizedElementDimension) * 100;
165-
166-
resizeElementRef.current.style.flexBasis = `${updatedFlexBasisValue}%`;
167-
168-
clearTimeout(updateLocalStorageTimeoutId.current);
169-
170-
updateLocalStorageTimeoutId.current = setTimeout(() => {
171-
if (resizeDirection === RESIZE_DIRECTIONS.HORIZONTAL) {
172-
setHorizontalPercentage(updatedFlexBasisValue);
173-
} else {
174-
setVerticalPercentage(updatedFlexBasisValue);
175-
}
176-
}, 500);
177-
}
178-
},
179-
[componentsWrapperRef, resizeElementRef, isResizing],
180-
);
146+
? width - BOUNDARY_PADDING
147+
: height - BOUNDARY_PADDING,
148+
};
149+
const isMousePositionInBounds: boolean =
150+
currentMousePosition > boundary.min &&
151+
currentMousePosition < boundary.max;
152+
153+
if (isMousePositionInBounds) {
154+
const resizedElementDimension: number =
155+
resizeDirection === RESIZE_DIRECTIONS.HORIZONTAL ? width : height;
156+
const updatedFlexBasisValue: number =
157+
(currentMousePosition / resizedElementDimension) * 100;
158+
159+
resizeElementRef.current.style.flexBasis = `${updatedFlexBasisValue}%`;
160+
161+
clearTimeout(updateLocalStorageTimeoutId.current);
162+
163+
updateLocalStorageTimeoutId.current = setTimeout(() => {
164+
if (resizeDirection === RESIZE_DIRECTIONS.HORIZONTAL) {
165+
setHorizontalPercentage(updatedFlexBasisValue);
166+
} else {
167+
setVerticalPercentage(updatedFlexBasisValue);
168+
}
169+
}, 500);
170+
}
171+
};
181172

182173
useLayoutEffect(() => {
183174
if (componentsWrapperRef.current !== null) {

0 commit comments

Comments
 (0)