@tamagui/use-debounce 1.0.1-beta.77 → 1.0.1-beta.80

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 CHANGED
File without changes
File without changes
package/dist/esm/index.js CHANGED
File without changes
File without changes
package/dist/jsx/index.js CHANGED
@@ -58,3 +58,4 @@ export {
58
58
  useDebounce,
59
59
  useDebounceValue
60
60
  };
61
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 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\n): A & {\n cancel: () => void\n} {\n let timeout: any\n let isCancelled = false\n\n function debounced(this: any) {\n isCancelled = false\n let context = this\n let 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 let 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;AACd,QAAI,UAAU;AACd,QAAI,OAAO;AACX,QAAI,WAAW,CAAC,SAAS;AACvB,WAAK,MAAM,SAAS,IAAI;AAAA,IAC1B;AACA,iBAAa,OAAO;AACpB,cAAU,WAAW,WAAY;AAC/B,gBAAU;AACV,UAAI,CAAC,WAAW,CAAC,aAAa;AAC5B,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;AAxDjB;AAyDM,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,QAAI,KAAK,WAAW,MAAM;AACxB,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
+ "names": []
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/use-debounce",
3
- "version": "1.0.1-beta.77",
3
+ "version": "1.0.1-beta.80",
4
4
  "types": "./types/index.d.ts",
5
5
  "main": "dist/cjs",
6
6
  "module": "dist/esm",
@@ -17,7 +17,7 @@
17
17
  "clean:build": "tamagui-build clean:build"
18
18
  },
19
19
  "devDependencies": {
20
- "@tamagui/build": "^1.0.1-beta.77",
20
+ "@tamagui/build": "^1.0.1-beta.80",
21
21
  "react": "*"
22
22
  },
23
23
  "peerDependencies": {
package/types/index.d.ts CHANGED
File without changes
File without changes