@tamagui/use-debounce 1.0.1-rc.8 → 1.0.1
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/dist/cjs/index.js +0 -0
- package/dist/cjs/index.js.map +0 -0
- package/dist/esm/index.js +0 -0
- package/dist/esm/index.js.map +0 -0
- package/dist/jsx/index.js +3 -2
- package/dist/jsx/index.js.map +2 -2
- package/package.json +3 -3
package/dist/cjs/index.js
CHANGED
|
File without changes
|
package/dist/cjs/index.js.map
CHANGED
|
File without changes
|
package/dist/esm/index.js
CHANGED
|
File without changes
|
package/dist/esm/index.js.map
CHANGED
|
File without changes
|
package/dist/jsx/index.js
CHANGED
|
@@ -12,7 +12,7 @@ function debounce(func, wait, leading) {
|
|
|
12
12
|
clearTimeout(timeout);
|
|
13
13
|
timeout = setTimeout(function() {
|
|
14
14
|
timeout = null;
|
|
15
|
-
if (!leading
|
|
15
|
+
if (!(leading || isCancelled)) {
|
|
16
16
|
func.apply(context, args);
|
|
17
17
|
}
|
|
18
18
|
isCancelled = false;
|
|
@@ -28,7 +28,8 @@ function useDebounce(fn, wait, options = defaultOpts, mountArgs = []) {
|
|
|
28
28
|
const dbEffect = useRef(null);
|
|
29
29
|
useEffect(() => {
|
|
30
30
|
return () => {
|
|
31
|
-
|
|
31
|
+
var _a;
|
|
32
|
+
(_a = dbEffect.current) == null ? void 0 : _a.cancel();
|
|
32
33
|
};
|
|
33
34
|
}, []);
|
|
34
35
|
return useMemo(() => {
|
package/dist/jsx/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["import { useEffect, useMemo, useRef, useState } from 'react'\n\ntype DebounceSettings = {\n leading?: boolean\n}\n\nexport function debounce<A extends Function>(\n func: A,\n wait?: number,\n leading?: boolean
|
|
5
|
-
"mappings": "AAAA
|
|
4
|
+
"sourcesContent": ["import { useEffect, useMemo, useRef, useState } from 'react'\n\ntype DebounceSettings = {\n leading?: boolean\n}\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 // eslint-disable-next-line @typescript-eslint/no-this-alias\n const context = this\n const args = arguments\n if (leading && !timeout) {\n func.apply(context, args)\n }\n clearTimeout(timeout)\n timeout = setTimeout(function () {\n timeout = null\n if (!(leading || isCancelled)) {\n func.apply(context, 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[] = [],\n): DebouncedFn {\n const dbEffect = useRef<DebouncedFn | null>(null)\n\n useEffect(() => {\n return () => {\n dbEffect.current?.cancel()\n }\n }, [])\n\n return 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] = useState(val)\n\n 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"],
|
|
5
|
+
"mappings": "AAAA;AAMO,kBACL,MACA,MACA,SAGA;AACA,MAAI;AACJ,MAAI,cAAc;AAElB,uBAA8B;AAC5B,kBAAc;AAEd,UAAM,UAAU;AAChB,UAAM,OAAO;AACb,QAAI,WAAW,CAAC,SAAS;AACvB,WAAK,MAAM,SAAS,IAAI;AAAA,IAC1B;AACA,iBAAa,OAAO;AACpB,cAAU,WAAW,WAAY;AAC/B,gBAAU;AACV,UAAI,CAAE,YAAW,cAAc;AAC7B,aAAK,MAAM,SAAS,IAAI;AAAA,MAC1B;AACA,oBAAc;AAAA,IAChB,GAAG,IAAI;AAAA,EACT;AAEA,YAAU,SAAS,MAAM;AACvB,kBAAc;AAAA,EAChB;AAEA,SAAO;AACT;AAEA,MAAM,cAAc,EAAE,SAAS,MAAM;AAE9B,qBAML,IACA,MACA,UAA4B,aAC5B,YAAmB,CAAC,GACP;AACb,QAAM,WAAW,OAA2B,IAAI;AAEhD,YAAU,MAAM;AACd,WAAO,MAAM;AAzDjB;AA0DM,qBAAS,YAAT,mBAAkB;AAAA,IACpB;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SAAO,QAAQ,MAAM;AACnB,aAAS,UAAU,SAAS,IAAI,MAAM,QAAQ,OAAO;AACrD,WAAO,SAAS;AAAA,EAClB,GAAG,CAAC,QAAQ,SAAS,GAAG,SAAS,CAAC;AACpC;AAMO,0BAA6B,KAAQ,MAAM,GAAM;AACtD,QAAM,CAAC,OAAO,YAAY,SAAS,GAAG;AAEtC,YAAU,MAAM;AACd,UAAM,KAAK,WAAW,MAAM;AAC1B,eAAS,CAAC,SAAS;AACjB,YAAI,SAAS;AAAK,iBAAO;AACzB,eAAO;AAAA,MACT,CAAC;AAAA,IACH,GAAG,GAAG;AAEN,WAAO,MAAM;AACX,mBAAa,EAAE;AAAA,IACjB;AAAA,EACF,GAAG,CAAC,GAAG,CAAC;AAER,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/use-debounce",
|
|
3
|
-
"version": "1.0.1
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"types": "./types/index.d.ts",
|
|
5
5
|
"main": "dist/cjs",
|
|
6
6
|
"module": "dist/esm",
|
|
@@ -18,11 +18,11 @@
|
|
|
18
18
|
"clean:build": "tamagui-build clean:build"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@tamagui/build": "^1.0.1
|
|
21
|
+
"@tamagui/build": "^1.0.1",
|
|
22
22
|
"react": "^18.2.0"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"react": "
|
|
25
|
+
"react": "*"
|
|
26
26
|
},
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public"
|