@tamagui/use-debounce 1.124.17 → 1.124.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/types/index.d.ts +10 -12
- package/types/index.d.ts.map +20 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/use-debounce",
|
|
3
|
-
"version": "1.124.
|
|
3
|
+
"version": "1.124.18",
|
|
4
4
|
"types": "./types/index.d.ts",
|
|
5
5
|
"main": "dist/cjs",
|
|
6
6
|
"module": "dist/esm",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@tamagui/build": "1.124.
|
|
34
|
+
"@tamagui/build": "1.124.18",
|
|
35
35
|
"react": "*"
|
|
36
36
|
},
|
|
37
37
|
"publishConfig": {
|
package/types/index.d.ts
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
type DebounceSettings = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export declare function useDebounce<A extends (...args: any) => any | undefined | null, DebouncedFn extends A & {
|
|
8
|
-
cancel: () => void;
|
|
9
|
-
}>(fn: A, wait: number, options?: DebounceSettings, mountArgs?: any[]): DebouncedFn;
|
|
1
|
+
type DebounceSettings = { leading?: boolean };
|
|
2
|
+
export declare function debounce<A extends Function>(func: A, wait?: number, leading?: boolean): A & { cancel: () => void };
|
|
3
|
+
export declare function useDebounce<
|
|
4
|
+
A extends (...args: any) => any | undefined | null,
|
|
5
|
+
DebouncedFn extends A & { cancel: () => void }
|
|
6
|
+
>(fn: A, wait: number, options?: DebounceSettings, mountArgs?: any[]): DebouncedFn;
|
|
10
7
|
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
* Returns a value once it stops changing after "amt" time.
|
|
9
|
+
* Note: you may need to memo or this will keep re-rendering
|
|
10
|
+
*/
|
|
14
11
|
export declare function useDebounceValue<A>(val: A, amt?: number): A;
|
|
15
12
|
export {};
|
|
13
|
+
|
|
16
14
|
//# sourceMappingURL=index.d.ts.map
|
package/types/index.d.ts.map
CHANGED
|
@@ -1 +1,20 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"mappings": "KAEK,mBAAmB,EACtB,kBACD;AAID,OAAO,iBAAS,SAAS,UAAU,UACjCA,MAAM,GACNC,eACAC,oBACC,IAAI,EACL,mBACD;AA6BD,OAAO,iBAAS;CACd,WAAW,GAAG,gCAAgC;CAC9C,oBAAoB,IAAI,EACtB,mBACD;EAEDC,IAAI,GACJC,cACAC,UAAS,kBACTC,oBACC;;;;;AAmBH,OAAO,iBAAS,iBAAiB,GAAGC,KAAK,GAAG,eAAU",
|
|
3
|
+
"names": [
|
|
4
|
+
"func: A",
|
|
5
|
+
"wait?: number",
|
|
6
|
+
"leading?: boolean",
|
|
7
|
+
"fn: A",
|
|
8
|
+
"wait: number",
|
|
9
|
+
"options: DebounceSettings",
|
|
10
|
+
"mountArgs: any[]",
|
|
11
|
+
"val: A"
|
|
12
|
+
],
|
|
13
|
+
"sources": [
|
|
14
|
+
"src/index.ts"
|
|
15
|
+
],
|
|
16
|
+
"sourcesContent": [
|
|
17
|
+
"import * as React from 'react'\n\ntype DebounceSettings = {\n leading?: boolean\n}\n\n// TODO doesn't return value of the function called :/\n\nexport function debounce<A extends Function>(\n func: A,\n wait?: number,\n leading?: boolean\n): A & {\n cancel: () => void\n} {\n let timeout: any\n let isCancelled = false\n\n function debounced(this: any) {\n isCancelled = false\n const args = arguments\n if (leading && !timeout) {\n func.apply(this, args)\n }\n clearTimeout(timeout)\n timeout = setTimeout(() => {\n timeout = null\n if (!(leading || isCancelled)) {\n func.apply(this, args)\n }\n isCancelled = false\n }, wait)\n }\n\n debounced.cancel = () => {\n isCancelled = true\n }\n\n return debounced as any\n}\n\nconst defaultOpts = { leading: false }\n\nexport function useDebounce<\n A extends (...args: any) => any | undefined | null,\n DebouncedFn extends A & {\n cancel: () => void\n },\n>(\n fn: A,\n wait: number,\n options: DebounceSettings = defaultOpts,\n mountArgs: any[] = [fn]\n): DebouncedFn {\n const dbEffect = React.useRef<DebouncedFn | null>(null)\n\n React.useEffect(() => {\n return () => {\n dbEffect.current?.cancel()\n }\n }, [])\n\n return React.useMemo(() => {\n dbEffect.current = debounce(fn, wait, options.leading) as unknown as DebouncedFn\n return dbEffect.current\n }, [options.leading, ...mountArgs])\n}\n\n/**\n * Returns a value once it stops changing after \"amt\" time.\n * Note: you may need to memo or this will keep re-rendering\n */\nexport function useDebounceValue<A>(val: A, amt = 0): A {\n const [state, setState] = React.useState(val)\n\n React.useEffect(() => {\n const tm = setTimeout(() => {\n setState((prev) => {\n if (prev === val) return prev\n return val\n })\n }, amt)\n\n return () => {\n clearTimeout(tm)\n }\n }, [val])\n\n return state\n}\n"
|
|
18
|
+
],
|
|
19
|
+
"version": 3
|
|
20
|
+
}
|