Skip to content

Commit

Permalink
fix: 馃悰 Performance and regression
Browse files Browse the repository at this point in the history
  • Loading branch information
prc5 committed Oct 23, 2023
1 parent 2777107 commit 11c0f41
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 21 deletions.
7 changes: 5 additions & 2 deletions src/components/transform-component/transform-component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const TransformComponent: React.FC<Props> = ({
wrapperProps = {},
contentProps = {},
}: Props) => {
const { init } = useContext(Context);
const { init, cleanupWindowEvents } = useContext(Context);

const wrapperRef = useRef<HTMLDivElement | null>(null);
const contentRef = useRef<HTMLDivElement | null>(null);
Expand All @@ -33,9 +33,12 @@ export const TransformComponent: React.FC<Props> = ({
const wrapper = wrapperRef.current;
const content = contentRef.current;
if (wrapper !== null && content !== null && init) {
init(wrapper, content);
init?.(wrapper, content);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
return () => {
cleanupWindowEvents?.();
};
}, []);

Check warning on line 42 in src/components/transform-component/transform-component.tsx

View workflow job for this annotation

GitHub Actions / Run tests

React Hook useEffect has missing dependencies: 'cleanupWindowEvents' and 'init'. Either include them or remove the dependency array

return (
Expand Down
3 changes: 0 additions & 3 deletions src/components/transform-wrapper/transform-wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ export const TransformWrapper = React.forwardRef(

useEffect(() => {
instance.update(props);
return () => {
instance.cleanupWindowEvents();
};
}, [instance, props]);

return <Context.Provider value={instance}>{content}</Context.Provider>;
Expand Down
15 changes: 2 additions & 13 deletions src/core/bounds/bounds.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,26 +170,15 @@ export function getMouseBoundedPosition(
paddingY = paddingValueY;
}

const rubberbandX = rubberbandIfOutOfBounds(
positionX,
minPositionX,
maxPositionX,
);
const rubberbandY = rubberbandIfOutOfBounds(
positionY,
minPositionY,
maxPositionY,
);

const x = boundLimiter(
rubberbandX,
positionX,
minPositionX - paddingX,
maxPositionX + paddingX,
limitToBounds,
);

const y = boundLimiter(
rubberbandY,
positionY,
minPositionY - paddingY,
maxPositionY + paddingY,
limitToBounds,
Expand Down
6 changes: 3 additions & 3 deletions src/core/instance.core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ export class ZoomPanPinch {
const keysPressed = this.isPressingKeys(this.setup.panning.activationKeys);
if (!keysPressed) return;

if(event.button == 0 && !this.setup.panning.allowLeftClickPan) return;
if(event.button == 1 && !this.setup.panning.allowMiddleClickPan) return;
if(event.button == 2 && !this.setup.panning.allowRightClickPan) return;
if (event.button === 0 && !this.setup.panning.allowLeftClickPan) return;
if (event.button === 1 && !this.setup.panning.allowMiddleClickPan) return;
if (event.button === 2 && !this.setup.panning.allowRightClickPan) return;

event.preventDefault();
event.stopPropagation();
Expand Down

0 comments on commit 11c0f41

Please sign in to comment.