Skip to content

Commit

Permalink
fix: timeoutId type (#2735)
Browse files Browse the repository at this point in the history
  • Loading branch information
shanpriyan authored Aug 1, 2022
1 parent b10f2fb commit 570aa26
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
10 changes: 6 additions & 4 deletions packages/lexical-playground/src/hooks/useReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ const getElement = (): HTMLElement => {
return element;
};

export default function useReport(): (arg0: string) => NodeJS.Timeout {
const timer = useRef<NodeJS.Timeout | null>(null);
export default function useReport(): (
arg0: string,
) => ReturnType<typeof setTimeout> {
const timer = useRef<ReturnType<typeof setTimeout> | null>(null);
const cleanup = useCallback(() => {
if (timer !== null) {
clearTimeout(timer.current as NodeJS.Timeout);
clearTimeout(timer.current as ReturnType<typeof setTimeout>);
}

if (document.body) {
Expand All @@ -52,7 +54,7 @@ export default function useReport(): (arg0: string) => NodeJS.Timeout {
// eslint-disable-next-line no-console
console.log(content);
const element = getElement();
clearTimeout(timer.current as NodeJS.Timeout);
clearTimeout(timer.current as ReturnType<typeof setTimeout>);
element.innerHTML = content;
timer.current = setTimeout(cleanup, 1000);
return timer.current;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export default function TypingPerfPlugin(): JSX.Element | null {
const report = useReport();
useEffect(() => {
let start = 0;
let timerId: NodeJS.Timeout | null;
let keyPressTimerId: number | null;
let timerId: ReturnType<typeof setTimeout> | null;
let keyPressTimerId: ReturnType<typeof setTimeout> | null;
let log: Array<DOMHighResTimeStamp> = [];
let invalidatingEvent = false;

Expand All @@ -59,7 +59,7 @@ export default function TypingPerfPlugin(): JSX.Element | null {

// We use a setTimeout(0) instead of requestAnimationFrame, due to
// inconsistencies between the sequencing of rAF in different browsers.
keyPressTimerId = window.setTimeout(measureEventEnd, 0);
keyPressTimerId = setTimeout(measureEventEnd, 0);
// Schedule a timer to report the results.
timerId = setTimeout(() => {
const total = log.reduce((a, b) => a + b, 0);
Expand Down
4 changes: 2 additions & 2 deletions packages/lexical-react/src/LexicalTreeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export function TreeView({

useEffect(() => {
if (isPlaying) {
let timeoutId: NodeJS.Timeout;
let timeoutId: ReturnType<typeof setTimeout>;

const play = () => {
const currentIndex = playingIndexRef.current;
Expand Down Expand Up @@ -122,7 +122,7 @@ export function TreeView({
play();

return () => {
window.clearTimeout(timeoutId);
clearTimeout(timeoutId);
};
}
}, [timeStampedEditorStates, isPlaying, editor, totalEditorStates]);
Expand Down

2 comments on commit 570aa26

@vercel
Copy link

@vercel vercel bot commented on 570aa26 Aug 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

lexical – ./packages/lexical-website-new

lexical.dev
lexical-git-main-fbopensource.vercel.app
lexical-fbopensource.vercel.app
lexicaljs.com
lexicaljs.org
www.lexical.dev

@vercel
Copy link

@vercel vercel bot commented on 570aa26 Aug 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

lexical-playground – ./packages/lexical-playground

lexical-playground-fbopensource.vercel.app
lexical-playground.vercel.app
playground.lexical.dev
lexical-playground-git-main-fbopensource.vercel.app

Please sign in to comment.