@tamagui/use-debounce 2.0.0-rc.3 → 2.0.0-rc.30

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
@@ -2,24 +2,33 @@ var __create = Object.create;
2
2
  var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __getProtoOf = Object.getPrototypeOf,
6
+ __hasOwnProp = Object.prototype.hasOwnProperty;
6
7
  var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: !0 });
9
- }, __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from == "object" || typeof from == "function")
11
- for (let key of __getOwnPropNames(from))
12
- !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
- return to;
14
- };
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: !0
11
+ });
12
+ },
13
+ __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
15
+ get: () => from[key],
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ return to;
19
+ };
15
20
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
16
21
  // If the importer is in node compatibility mode or this is not an ESM
17
22
  // file that has been converted to a CommonJS file using a Babel-
18
23
  // compatible transform (i.e. "__esModule" has not been set), then set
19
24
  // "default" to the CommonJS "module.exports" for node compatibility.
20
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
21
- mod
22
- )), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
26
+ value: mod,
27
+ enumerable: !0
28
+ }) : target, mod)),
29
+ __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
30
+ value: !0
31
+ }), mod);
23
32
  var index_exports = {};
24
33
  __export(index_exports, {
25
34
  debounce: () => debounce,
@@ -29,7 +38,8 @@ __export(index_exports, {
29
38
  module.exports = __toCommonJS(index_exports);
30
39
  var React = __toESM(require("react"), 1);
31
40
  function debounce(func, wait, leading) {
32
- let timeout, isCancelled = !1;
41
+ let timeout,
42
+ isCancelled = !1;
33
43
  function debounced() {
34
44
  isCancelled = !1;
35
45
  const args = arguments;
@@ -41,7 +51,9 @@ function debounce(func, wait, leading) {
41
51
  isCancelled = !0;
42
52
  }, debounced;
43
53
  }
44
- const defaultOpts = { leading: !1 };
54
+ const defaultOpts = {
55
+ leading: !1
56
+ };
45
57
  function useDebounce(fn, wait, options = defaultOpts, mountArgs = [fn]) {
46
58
  const dbEffect = React.useRef(null);
47
59
  return React.useEffect(() => () => {
@@ -52,11 +64,10 @@ function useDebounceValue(val, amt = 0) {
52
64
  const [state, setState] = React.useState(val);
53
65
  return React.useEffect(() => {
54
66
  const tm = setTimeout(() => {
55
- setState((prev) => prev === val ? prev : val);
67
+ setState(prev => prev === val ? prev : val);
56
68
  }, amt);
57
69
  return () => {
58
70
  clearTimeout(tm);
59
71
  };
60
72
  }, [val]), state;
61
- }
62
- //# sourceMappingURL=index.js.map
73
+ }
package/dist/esm/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as React from "react";
2
2
  function debounce(func, wait, leading) {
3
- let timeout, isCancelled = !1;
3
+ let timeout,
4
+ isCancelled = !1;
4
5
  function debounced() {
5
6
  isCancelled = !1;
6
7
  const args = arguments;
@@ -12,7 +13,9 @@ function debounce(func, wait, leading) {
12
13
  isCancelled = !0;
13
14
  }, debounced;
14
15
  }
15
- const defaultOpts = { leading: !1 };
16
+ const defaultOpts = {
17
+ leading: !1
18
+ };
16
19
  function useDebounce(fn, wait, options = defaultOpts, mountArgs = [fn]) {
17
20
  const dbEffect = React.useRef(null);
18
21
  return React.useEffect(() => () => {
@@ -23,16 +26,12 @@ function useDebounceValue(val, amt = 0) {
23
26
  const [state, setState] = React.useState(val);
24
27
  return React.useEffect(() => {
25
28
  const tm = setTimeout(() => {
26
- setState((prev) => prev === val ? prev : val);
29
+ setState(prev => prev === val ? prev : val);
27
30
  }, amt);
28
31
  return () => {
29
32
  clearTimeout(tm);
30
33
  };
31
34
  }, [val]), state;
32
35
  }
33
- export {
34
- debounce,
35
- useDebounce,
36
- useDebounceValue
37
- };
36
+ export { debounce, useDebounce, useDebounceValue };
38
37
  //# sourceMappingURL=index.js.map
@@ -1,6 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/index.ts"],
4
- "mappings": "AAAA,YAAY,WAAW;AAQhB,SAAS,SACd,MACA,MACA,SAGA;AACA,MAAI,SACA,cAAc;AAElB,WAAS,YAAqB;AAC5B,kBAAc;AACd,UAAM,OAAO;AACb,IAAI,WAAW,CAAC,WACd,KAAK,MAAM,MAAM,IAAI,GAEvB,aAAa,OAAO,GACpB,UAAU,WAAW,MAAM;AACzB,gBAAU,MACJ,WAAW,eACf,KAAK,MAAM,MAAM,IAAI,GAEvB,cAAc;AAAA,IAChB,GAAG,IAAI;AAAA,EACT;AAEA,mBAAU,SAAS,MAAM;AACvB,kBAAc;AAAA,EAChB,GAEO;AACT;AAEA,MAAM,cAAc,EAAE,SAAS,GAAM;AAE9B,SAAS,YAMd,IACA,MACA,UAA4B,aAC5B,YAAmB,CAAC,EAAE,GACT;AACb,QAAM,WAAW,MAAM,OAA2B,IAAI;AAEtD,eAAM,UAAU,MACP,MAAM;AACX,aAAS,SAAS,OAAO;AAAA,EAC3B,GACC,CAAC,CAAC,GAEE,MAAM,QAAQ,OACnB,SAAS,UAAU,SAAS,IAAI,MAAM,QAAQ,OAAO,GAC9C,SAAS,UACf,CAAC,QAAQ,SAAS,GAAG,SAAS,CAAC;AACpC;AAMO,SAAS,iBAAoB,KAAQ,MAAM,GAAM;AACtD,QAAM,CAAC,OAAO,QAAQ,IAAI,MAAM,SAAS,GAAG;AAE5C,eAAM,UAAU,MAAM;AACpB,UAAM,KAAK,WAAW,MAAM;AAC1B,eAAS,CAAC,SACJ,SAAS,MAAY,OAClB,GACR;AAAA,IACH,GAAG,GAAG;AAEN,WAAO,MAAM;AACX,mBAAa,EAAE;AAAA,IACjB;AAAA,EACF,GAAG,CAAC,GAAG,CAAC,GAED;AACT;",
5
- "names": []
6
- }
1
+ {"version":3,"names":["React","debounce","func","wait","leading","timeout","isCancelled","debounced","args","arguments","apply","clearTimeout","setTimeout","cancel","defaultOpts","useDebounce","fn","options","mountArgs","dbEffect","useRef","useEffect","current","useMemo","useDebounceValue","val","amt","state","setState","useState","tm","prev"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,YAAYA,KAAA,MAAW;AAQhB,SAASC,SACdC,IAAA,EACAC,IAAA,EACAC,OAAA,EAGA;EACA,IAAIC,OAAA;IACAC,WAAA,GAAc;EAElB,SAASC,UAAA,EAAqB;IAC5BD,WAAA,GAAc;IACd,MAAME,IAAA,GAAOC,SAAA;IACTL,OAAA,IAAW,CAACC,OAAA,IACdH,IAAA,CAAKQ,KAAA,CAAM,MAAMF,IAAI,GAEvBG,YAAA,CAAaN,OAAO,GACpBA,OAAA,GAAUO,UAAA,CAAW,MAAM;MACzBP,OAAA,GAAU,MACJD,OAAA,IAAWE,WAAA,IACfJ,IAAA,CAAKQ,KAAA,CAAM,MAAMF,IAAI,GAEvBF,WAAA,GAAc;IAChB,GAAGH,IAAI;EACT;EAEA,OAAAI,SAAA,CAAUM,MAAA,GAAS,MAAM;IACvBP,WAAA,GAAc;EAChB,GAEOC,SAAA;AACT;AAEA,MAAMO,WAAA,GAAc;EAAEV,OAAA,EAAS;AAAM;AAE9B,SAASW,YAMdC,EAAA,EACAb,IAAA,EACAc,OAAA,GAA4BH,WAAA,EAC5BI,SAAA,GAAmB,CAACF,EAAE,GACT;EACb,MAAMG,QAAA,GAAWnB,KAAA,CAAMoB,MAAA,CAA2B,IAAI;EAEtD,OAAApB,KAAA,CAAMqB,SAAA,CAAU,MACP,MAAM;IACXF,QAAA,CAASG,OAAA,EAAST,MAAA,CAAO;EAC3B,GACC,EAAE,GAEEb,KAAA,CAAMuB,OAAA,CAAQ,OACnBJ,QAAA,CAASG,OAAA,GAAUrB,QAAA,CAASe,EAAA,EAAIb,IAAA,EAAMc,OAAA,CAAQb,OAAO,GAC9Ce,QAAA,CAASG,OAAA,GACf,CAACL,OAAA,CAAQb,OAAA,EAAS,GAAGc,SAAS,CAAC;AACpC;AAMO,SAASM,iBAAoBC,GAAA,EAAQC,GAAA,GAAM,GAAM;EACtD,MAAM,CAACC,KAAA,EAAOC,QAAQ,IAAI5B,KAAA,CAAM6B,QAAA,CAASJ,GAAG;EAE5C,OAAAzB,KAAA,CAAMqB,SAAA,CAAU,MAAM;IACpB,MAAMS,EAAA,GAAKlB,UAAA,CAAW,MAAM;MAC1BgB,QAAA,CAAUG,IAAA,IACJA,IAAA,KAASN,GAAA,GAAYM,IAAA,GAClBN,GACR;IACH,GAAGC,GAAG;IAEN,OAAO,MAAM;MACXf,YAAA,CAAamB,EAAE;IACjB;EACF,GAAG,CAACL,GAAG,CAAC,GAEDE,KAAA;AACT","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/use-debounce",
3
- "version": "2.0.0-rc.3",
3
+ "version": "2.0.0-rc.30",
4
4
  "gitHead": "a49cc7ea6b93ba384e77a4880ae48ac4a5635c14",
5
5
  "files": [
6
6
  "src",
@@ -16,15 +16,12 @@
16
16
  "./package.json": "./package.json",
17
17
  ".": {
18
18
  "types": "./types/index.d.ts",
19
- "react-native": {
20
- "module": "./dist/esm/index.native.js",
21
- "import": "./dist/esm/index.native.js",
22
- "require": "./dist/cjs/index.native.js"
23
- },
19
+ "react-native": "./dist/esm/index.native.js",
20
+ "browser": "./dist/esm/index.mjs",
24
21
  "module": "./dist/esm/index.mjs",
25
22
  "import": "./dist/esm/index.mjs",
26
23
  "require": "./dist/cjs/index.cjs",
27
- "default": "./dist/cjs/index.native.js"
24
+ "default": "./dist/esm/index.mjs"
28
25
  }
29
26
  },
30
27
  "publishConfig": {
@@ -37,7 +34,7 @@
37
34
  "clean:build": "tamagui-build clean:build"
38
35
  },
39
36
  "devDependencies": {
40
- "@tamagui/build": "2.0.0-rc.3",
37
+ "@tamagui/build": "2.0.0-rc.30",
41
38
  "react": ">=19"
42
39
  },
43
40
  "peerDependencies": {
@@ -4,8 +4,8 @@
4
4
  "sources": [
5
5
  "src/index.ts"
6
6
  ],
7
+ "version": 3,
7
8
  "sourcesContent": [
8
9
  "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"
9
- ],
10
- "version": 3
10
+ ]
11
11
  }