mirror of
https://github.com/jhbruhn/respira.git
synced 2026-01-27 02:13:41 +00:00
fix: Address PR review comments
- Remove redundant useMemo wrapper in usePatternValidation Inline the calculation logic directly in useMemo instead of useCallback + useMemo pattern for better clarity and efficiency - Remove unnecessary 'Early return' comment in usePatternRotationUpload The return statement is self-explanatory
This commit is contained in:
parent
c905c4f5f7
commit
e63a96b024
2 changed files with 4 additions and 12 deletions
|
|
@ -119,7 +119,7 @@ export function usePatternRotationUpload({
|
||||||
pesData, // Original unrotated pattern for caching
|
pesData, // Original unrotated pattern for caching
|
||||||
);
|
);
|
||||||
|
|
||||||
return; // Early return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// No rotation case
|
// No rotation case
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { useCallback, useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
import type { PesPatternData } from "../formats/import/pesImporter";
|
import type { PesPatternData } from "../formats/import/pesImporter";
|
||||||
import type { MachineInfo } from "../types/machine";
|
import type { MachineInfo } from "../types/machine";
|
||||||
import { calculateRotatedBounds } from "../utils/rotationUtils";
|
import { calculateRotatedBounds } from "../utils/rotationUtils";
|
||||||
|
|
@ -31,8 +31,8 @@ export function usePatternValidation({
|
||||||
patternOffset,
|
patternOffset,
|
||||||
patternRotation,
|
patternRotation,
|
||||||
}: UsePatternValidationParams): PatternBoundsCheckResult {
|
}: UsePatternValidationParams): PatternBoundsCheckResult {
|
||||||
// Check if pattern (with offset and rotation) fits within hoop bounds
|
// Memoize the bounds check calculation to avoid unnecessary recalculations
|
||||||
const checkPatternFitsInHoop = useCallback((): PatternBoundsCheckResult => {
|
return useMemo((): PatternBoundsCheckResult => {
|
||||||
if (!pesData || !machineInfo) {
|
if (!pesData || !machineInfo) {
|
||||||
return { fits: true, error: null };
|
return { fits: true, error: null };
|
||||||
}
|
}
|
||||||
|
|
@ -94,12 +94,4 @@ export function usePatternValidation({
|
||||||
|
|
||||||
return { fits: true, error: null };
|
return { fits: true, error: null };
|
||||||
}, [pesData, machineInfo, patternOffset, patternRotation]);
|
}, [pesData, machineInfo, patternOffset, patternRotation]);
|
||||||
|
|
||||||
// Memoize the result to avoid unnecessary recalculations
|
|
||||||
const boundsCheck = useMemo(
|
|
||||||
() => checkPatternFitsInHoop(),
|
|
||||||
[checkPatternFitsInHoop],
|
|
||||||
);
|
|
||||||
|
|
||||||
return boundsCheck;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue