Skip to content

Commit 164c689

Browse files
authored
Merge pull request #212 from PedroMarianoAlmeida/remove-any-from-PixelCard
Remove any from pixel card
2 parents d4ab64e + fcb95e7 commit 164c689

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

src/ts-default/Components/PixelCard/PixelCard.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,17 @@ class Pixel {
102102
}
103103
}
104104

105-
function getEffectiveSpeed(value: any, reducedMotion: any) {
105+
function getEffectiveSpeed(value: number, reducedMotion: boolean) {
106106
const min = 0;
107107
const max = 100;
108108
const throttle = 0.001;
109-
const parsed = parseInt(value, 10);
110109

111-
if (parsed <= min || reducedMotion) {
110+
if (value <= min || reducedMotion) {
112111
return min;
113-
} else if (parsed >= max) {
112+
} else if (value >= max) {
114113
return max * throttle;
115114
} else {
116-
return parsed * throttle;
115+
return value * throttle;
117116
}
118117
}
119118

@@ -182,7 +181,7 @@ export default function PixelCard({
182181
const containerRef = useRef<HTMLDivElement>(null);
183182
const canvasRef = useRef<HTMLCanvasElement>(null);
184183
const pixelsRef = useRef<Pixel[]>([]);
185-
const animationRef = useRef<any>(null);
184+
const animationRef = useRef<ReturnType<typeof requestAnimationFrame> | null>(null);
186185
const timePreviousRef = useRef(performance.now());
187186
const reducedMotion = useRef(
188187
window.matchMedia("(prefers-reduced-motion: reduce)").matches
@@ -264,7 +263,9 @@ export default function PixelCard({
264263
};
265264

266265
const handleAnimation = (name: keyof Pixel) => {
267-
cancelAnimationFrame(animationRef.current);
266+
if (animationRef.current !== null) {
267+
cancelAnimationFrame(animationRef.current);
268+
}
268269
animationRef.current = requestAnimationFrame(() => doAnimate(name));
269270
};
270271

@@ -289,8 +290,10 @@ export default function PixelCard({
289290
}
290291
return () => {
291292
observer.disconnect();
292-
cancelAnimationFrame(animationRef.current);
293-
};
293+
if (animationRef.current !== null) {
294+
cancelAnimationFrame(animationRef.current);
295+
}
296+
};
294297
// eslint-disable-next-line react-hooks/exhaustive-deps
295298
}, [finalGap, finalSpeed, finalColors, finalNoFocus]);
296299

src/ts-tailwind/Components/PixelCard/PixelCard.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,17 @@ class Pixel {
101101
}
102102
}
103103

104-
function getEffectiveSpeed(value: any, reducedMotion: any) {
104+
function getEffectiveSpeed(value: number, reducedMotion: boolean) {
105105
const min = 0;
106106
const max = 100;
107107
const throttle = 0.001;
108-
const parsed = parseInt(value, 10);
109108

110-
if (parsed <= min || reducedMotion) {
109+
if (value <= min || reducedMotion) {
111110
return min;
112-
} else if (parsed >= max) {
111+
} else if (value >= max) {
113112
return max * throttle;
114113
} else {
115-
return parsed * throttle;
114+
return value * throttle;
116115
}
117116
}
118117

@@ -181,7 +180,7 @@ export default function PixelCard({
181180
const containerRef = useRef<HTMLDivElement>(null);
182181
const canvasRef = useRef<HTMLCanvasElement>(null);
183182
const pixelsRef = useRef<Pixel[]>([]);
184-
const animationRef = useRef<any>(null);
183+
const animationRef = useRef<ReturnType<typeof requestAnimationFrame> | null>(null);
185184
const timePreviousRef = useRef(performance.now());
186185
const reducedMotion = useRef(
187186
window.matchMedia("(prefers-reduced-motion: reduce)").matches
@@ -263,7 +262,9 @@ export default function PixelCard({
263262
};
264263

265264
const handleAnimation = (name: keyof Pixel) => {
266-
cancelAnimationFrame(animationRef.current);
265+
if (animationRef.current !== null) {
266+
cancelAnimationFrame(animationRef.current);
267+
}
267268
animationRef.current = requestAnimationFrame(() => doAnimate(name));
268269
};
269270

@@ -288,7 +289,9 @@ export default function PixelCard({
288289
}
289290
return () => {
290291
observer.disconnect();
291-
cancelAnimationFrame(animationRef.current);
292+
if (animationRef.current !== null) {
293+
cancelAnimationFrame(animationRef.current);
294+
}
292295
};
293296
// eslint-disable-next-line react-hooks/exhaustive-deps
294297
}, [finalGap, finalSpeed, finalColors, finalNoFocus]);

0 commit comments

Comments
 (0)