-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(richtext-lexical): enable strict: true (#9394)
Thanks to @GermanJablo for doing most of the work by enabling `noImplicitAny` and `strictNullChecks` in previous PRs
- Loading branch information
Showing
25 changed files
with
197 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 24 additions & 16 deletions
40
packages/richtext-lexical/src/features/experimental_table/client/utils/useDebounce.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,35 @@ | ||
'use client' | ||
import { useMemo, useRef } from 'react' | ||
import { useCallback, useEffect, useRef } from 'react' | ||
|
||
import debounce from './debounce.js' | ||
|
||
// Define the type for debounced function that includes cancel method | ||
interface DebouncedFunction<T extends (...args: any[]) => any> { | ||
(...args: Parameters<T>): ReturnType<T> | ||
cancel: () => void | ||
} | ||
|
||
export function useDebounce<T extends (...args: never[]) => void>( | ||
fn: T, | ||
ms: number, | ||
maxWait?: number, | ||
) { | ||
const funcRef = useRef<null | T>(null) | ||
funcRef.current = fn | ||
// Update the ref type to include cancel method | ||
const debouncedRef = useRef<DebouncedFunction<T> | null>(null) | ||
|
||
useEffect(() => { | ||
debouncedRef.current = debounce(fn, ms, { maxWait }) as DebouncedFunction<T> | ||
|
||
return () => { | ||
debouncedRef.current?.cancel() | ||
} | ||
}, [fn, ms, maxWait]) | ||
|
||
const callback = useCallback((...args: Parameters<T>) => { | ||
if (debouncedRef.current) { | ||
debouncedRef.current(...args) | ||
} | ||
}, []) | ||
|
||
return useMemo( | ||
() => | ||
debounce( | ||
(...args: Parameters<T>) => { | ||
if (funcRef.current) { | ||
funcRef.current(...args) | ||
} | ||
}, | ||
ms, | ||
{ maxWait }, | ||
), | ||
[ms, maxWait], | ||
) | ||
return callback | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.