@tamagui/use-debounce 2.7.7 → 3.0.0-beta.643.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.cjs +65 -73
- package/dist/cjs/index.native.cjs +92 -0
- package/dist/cjs/index.native.js +69 -77
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/esm/index.js +47 -47
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +47 -47
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/index.native.js +51 -52
- package/dist/esm/index.native.js.map +1 -1
- package/package.json +2 -2
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
|
|
1
2
|
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -5,90 +6,81 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
5
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
8
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
for (var name in all) __defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true
|
|
12
|
+
});
|
|
12
13
|
};
|
|
13
14
|
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
|
+
get: () => from[key],
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
21
22
|
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
-
value: mod,
|
|
29
|
-
enumerable: true
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
30
26
|
}) : target, mod));
|
|
31
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
-
value: true
|
|
33
|
-
}), mod);
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
34
28
|
var index_exports = {};
|
|
35
29
|
__export(index_exports, {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
30
|
+
debounce: () => debounce,
|
|
31
|
+
useDebounce: () => useDebounce,
|
|
32
|
+
useDebounceValue: () => useDebounceValue
|
|
39
33
|
});
|
|
40
34
|
module.exports = __toCommonJS(index_exports);
|
|
41
35
|
var React = __toESM(require("react"), 1);
|
|
42
36
|
function debounce(func, wait, leading) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
37
|
+
let timeout;
|
|
38
|
+
let isCancelled = false;
|
|
39
|
+
function debounced() {
|
|
40
|
+
isCancelled = false;
|
|
41
|
+
const args = arguments;
|
|
42
|
+
if (leading && !timeout) {
|
|
43
|
+
func.apply(this, args);
|
|
44
|
+
}
|
|
45
|
+
clearTimeout(timeout);
|
|
46
|
+
timeout = setTimeout(() => {
|
|
47
|
+
timeout = null;
|
|
48
|
+
if (!(leading || isCancelled)) {
|
|
49
|
+
func.apply(this, args);
|
|
50
|
+
}
|
|
51
|
+
isCancelled = false;
|
|
52
|
+
}, wait);
|
|
53
|
+
}
|
|
54
|
+
debounced.cancel = () => {
|
|
55
|
+
isCancelled = true;
|
|
56
|
+
};
|
|
57
|
+
return debounced;
|
|
64
58
|
}
|
|
65
|
-
const defaultOpts = {
|
|
66
|
-
leading: false
|
|
67
|
-
};
|
|
59
|
+
const defaultOpts = { leading: false };
|
|
68
60
|
function useDebounce(fn, wait, options = defaultOpts, mountArgs = [fn]) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
61
|
+
const dbEffect = React.useRef(null);
|
|
62
|
+
React.useEffect(() => {
|
|
63
|
+
return () => {
|
|
64
|
+
dbEffect.current?.cancel();
|
|
65
|
+
};
|
|
66
|
+
}, []);
|
|
67
|
+
return React.useMemo(() => {
|
|
68
|
+
dbEffect.current = debounce(fn, wait, options.leading);
|
|
69
|
+
return dbEffect.current;
|
|
70
|
+
}, [options.leading, ...mountArgs]);
|
|
79
71
|
}
|
|
80
72
|
function useDebounceValue(val, amt = 0) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
73
|
+
const [state, setState] = React.useState(val);
|
|
74
|
+
React.useEffect(() => {
|
|
75
|
+
const tm = setTimeout(() => {
|
|
76
|
+
setState((prev) => {
|
|
77
|
+
if (prev === val) return prev;
|
|
78
|
+
return val;
|
|
79
|
+
});
|
|
80
|
+
}, amt);
|
|
81
|
+
return () => {
|
|
82
|
+
clearTimeout(tm);
|
|
83
|
+
};
|
|
84
|
+
}, [val]);
|
|
85
|
+
return state;
|
|
86
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __export = (target, all) => {
|
|
11
|
+
for (var name in all) __defProp(target, name, {
|
|
12
|
+
get: all[name],
|
|
13
|
+
enumerable: true
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
19
|
+
get: () => from[key],
|
|
20
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: true
|
|
28
|
+
}) : target, mod));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var index_exports = {};
|
|
31
|
+
__export(index_exports, {
|
|
32
|
+
debounce: () => debounce,
|
|
33
|
+
useDebounce: () => useDebounce,
|
|
34
|
+
useDebounceValue: () => useDebounceValue
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(index_exports);
|
|
37
|
+
var React = __toESM(require("react"), 1);
|
|
38
|
+
function debounce(func, wait, leading) {
|
|
39
|
+
var timeout;
|
|
40
|
+
var isCancelled = false;
|
|
41
|
+
function debounced() {
|
|
42
|
+
var _this = this;
|
|
43
|
+
isCancelled = false;
|
|
44
|
+
var args = arguments;
|
|
45
|
+
if (leading && !timeout) {
|
|
46
|
+
func.apply(this, args);
|
|
47
|
+
}
|
|
48
|
+
clearTimeout(timeout);
|
|
49
|
+
timeout = setTimeout(function() {
|
|
50
|
+
timeout = null;
|
|
51
|
+
if (!(leading || isCancelled)) {
|
|
52
|
+
func.apply(_this, args);
|
|
53
|
+
}
|
|
54
|
+
isCancelled = false;
|
|
55
|
+
}, wait);
|
|
56
|
+
}
|
|
57
|
+
debounced.cancel = function() {
|
|
58
|
+
isCancelled = true;
|
|
59
|
+
};
|
|
60
|
+
return debounced;
|
|
61
|
+
}
|
|
62
|
+
var defaultOpts = { leading: false };
|
|
63
|
+
function useDebounce(fn, wait) {
|
|
64
|
+
var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : defaultOpts, mountArgs = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : [fn];
|
|
65
|
+
var dbEffect = React.useRef(null);
|
|
66
|
+
React.useEffect(function() {
|
|
67
|
+
return function() {
|
|
68
|
+
var _dbEffect_current;
|
|
69
|
+
(_dbEffect_current = dbEffect.current) === null || _dbEffect_current === void 0 ? void 0 : _dbEffect_current.cancel();
|
|
70
|
+
};
|
|
71
|
+
}, []);
|
|
72
|
+
return React.useMemo(function() {
|
|
73
|
+
dbEffect.current = debounce(fn, wait, options.leading);
|
|
74
|
+
return dbEffect.current;
|
|
75
|
+
}, [options.leading, ...mountArgs]);
|
|
76
|
+
}
|
|
77
|
+
function useDebounceValue(val) {
|
|
78
|
+
var amt = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0;
|
|
79
|
+
var [state, setState] = React.useState(val);
|
|
80
|
+
React.useEffect(function() {
|
|
81
|
+
var tm = setTimeout(function() {
|
|
82
|
+
setState(function(prev) {
|
|
83
|
+
if (prev === val) return prev;
|
|
84
|
+
return val;
|
|
85
|
+
});
|
|
86
|
+
}, amt);
|
|
87
|
+
return function() {
|
|
88
|
+
clearTimeout(tm);
|
|
89
|
+
};
|
|
90
|
+
}, [val]);
|
|
91
|
+
return state;
|
|
92
|
+
}
|
package/dist/cjs/index.native.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
|
|
3
4
|
var __create = Object.create;
|
|
4
5
|
var __defProp = Object.defineProperty;
|
|
5
6
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -7,96 +8,87 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
7
8
|
var __getProtoOf = Object.getPrototypeOf;
|
|
8
9
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
10
|
var __export = (target, all) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
for (var name in all) __defProp(target, name, {
|
|
12
|
+
get: all[name],
|
|
13
|
+
enumerable: true
|
|
14
|
+
});
|
|
14
15
|
};
|
|
15
16
|
var __copyProps = (to, from, except, desc) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
19
|
+
get: () => from[key],
|
|
20
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
23
24
|
};
|
|
24
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
28
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
29
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
30
|
-
value: mod,
|
|
31
|
-
enumerable: true
|
|
25
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: true
|
|
32
28
|
}) : target, mod));
|
|
33
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
34
|
-
value: true
|
|
35
|
-
}), mod);
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
36
30
|
var index_exports = {};
|
|
37
31
|
__export(index_exports, {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
32
|
+
debounce: () => debounce,
|
|
33
|
+
useDebounce: () => useDebounce,
|
|
34
|
+
useDebounceValue: () => useDebounceValue
|
|
41
35
|
});
|
|
42
36
|
module.exports = __toCommonJS(index_exports);
|
|
43
37
|
var React = __toESM(require("react"), 1);
|
|
44
38
|
function debounce(func, wait, leading) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
39
|
+
var timeout;
|
|
40
|
+
var isCancelled = false;
|
|
41
|
+
function debounced() {
|
|
42
|
+
var _this = this;
|
|
43
|
+
isCancelled = false;
|
|
44
|
+
var args = arguments;
|
|
45
|
+
if (leading && !timeout) {
|
|
46
|
+
func.apply(this, args);
|
|
47
|
+
}
|
|
48
|
+
clearTimeout(timeout);
|
|
49
|
+
timeout = setTimeout(function() {
|
|
50
|
+
timeout = null;
|
|
51
|
+
if (!(leading || isCancelled)) {
|
|
52
|
+
func.apply(_this, args);
|
|
53
|
+
}
|
|
54
|
+
isCancelled = false;
|
|
55
|
+
}, wait);
|
|
56
|
+
}
|
|
57
|
+
debounced.cancel = function() {
|
|
58
|
+
isCancelled = true;
|
|
59
|
+
};
|
|
60
|
+
return debounced;
|
|
67
61
|
}
|
|
68
|
-
var defaultOpts = {
|
|
69
|
-
leading: false
|
|
70
|
-
};
|
|
62
|
+
var defaultOpts = { leading: false };
|
|
71
63
|
function useDebounce(fn, wait) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}, [options.leading, ...mountArgs]);
|
|
64
|
+
var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : defaultOpts, mountArgs = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : [fn];
|
|
65
|
+
var dbEffect = React.useRef(null);
|
|
66
|
+
React.useEffect(function() {
|
|
67
|
+
return function() {
|
|
68
|
+
var _dbEffect_current;
|
|
69
|
+
(_dbEffect_current = dbEffect.current) === null || _dbEffect_current === void 0 ? void 0 : _dbEffect_current.cancel();
|
|
70
|
+
};
|
|
71
|
+
}, []);
|
|
72
|
+
return React.useMemo(function() {
|
|
73
|
+
dbEffect.current = debounce(fn, wait, options.leading);
|
|
74
|
+
return dbEffect.current;
|
|
75
|
+
}, [options.leading, ...mountArgs]);
|
|
85
76
|
}
|
|
86
77
|
function useDebounceValue(val) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
78
|
+
var amt = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0;
|
|
79
|
+
var [state, setState] = React.useState(val);
|
|
80
|
+
React.useEffect(function() {
|
|
81
|
+
var tm = setTimeout(function() {
|
|
82
|
+
setState(function(prev) {
|
|
83
|
+
if (prev === val) return prev;
|
|
84
|
+
return val;
|
|
85
|
+
});
|
|
86
|
+
}, amt);
|
|
87
|
+
return function() {
|
|
88
|
+
clearTimeout(tm);
|
|
89
|
+
};
|
|
90
|
+
}, [val]);
|
|
91
|
+
return state;
|
|
101
92
|
}
|
|
93
|
+
|
|
102
94
|
//# sourceMappingURL=index.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.native.js","names":[],"sources":["cjs/index.native.js"],"sourcesContent":["\"use strict\";\nvar __create = Object.create;\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __getProtoOf = Object.getPrototypeOf;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(\n // If the importer is in node compatibility mode or this is not an ESM\n // file that has been converted to a CommonJS file using a Babel-\n // compatible transform (i.e. \"__esModule\" has not been set), then set\n // \"default\" to the CommonJS \"module.exports\" for node compatibility.\n isNodeMode || !mod || !mod.__esModule ? __defProp(target, \"default\", { value: mod, enumerable: true }) : target,\n mod\n));\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar index_exports = {};\n__export(index_exports, {\n debounce: () => debounce,\n useDebounce: () => useDebounce,\n useDebounceValue: () => useDebounceValue\n});\nmodule.exports = __toCommonJS(index_exports);\nvar React = __toESM(require(\"react\"), 1);\nfunction debounce(func, wait, leading) {\n var timeout;\n var isCancelled = false;\n function debounced() {\n var _this = this;\n isCancelled = false;\n var args = arguments;\n if (leading && !timeout) {\n func.apply(this, args);\n }\n clearTimeout(timeout);\n timeout = setTimeout(function() {\n timeout = null;\n if (!(leading || isCancelled)) {\n func.apply(_this, args);\n }\n isCancelled = false;\n }, wait);\n }\n debounced.cancel = function() {\n isCancelled = true;\n };\n return debounced;\n}\nvar defaultOpts = {\n leading: false\n};\nfunction useDebounce(fn, wait) {\n var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : defaultOpts, mountArgs = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : [\n fn\n ];\n var dbEffect = React.useRef(null);\n React.useEffect(function() {\n return function() {\n var _dbEffect_current;\n (_dbEffect_current = dbEffect.current) === null || _dbEffect_current === void 0 ? void 0 : _dbEffect_current.cancel();\n };\n }, []);\n return React.useMemo(function() {\n dbEffect.current = debounce(fn, wait, options.leading);\n return dbEffect.current;\n }, [\n options.leading,\n ...mountArgs\n ]);\n}\nfunction useDebounceValue(val) {\n var amt = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0;\n var [state, setState] = React.useState(val);\n React.useEffect(function() {\n var tm = setTimeout(function() {\n setState(function(prev) {\n if (prev === val) return prev;\n return val;\n });\n }, amt);\n return function() {\n clearTimeout(tm);\n };\n }, [\n val\n ]);\n return state;\n}\n//# sourceMappingURL=index.js.map\n"],"mappings":";;;;A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ist/esm/index.js
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
+
|
|
2
3
|
function debounce(func, wait, leading) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
4
|
+
let timeout;
|
|
5
|
+
let isCancelled = false;
|
|
6
|
+
function debounced() {
|
|
7
|
+
isCancelled = false;
|
|
8
|
+
const args = arguments;
|
|
9
|
+
if (leading && !timeout) {
|
|
10
|
+
func.apply(this, args);
|
|
11
|
+
}
|
|
12
|
+
clearTimeout(timeout);
|
|
13
|
+
timeout = setTimeout(() => {
|
|
14
|
+
timeout = null;
|
|
15
|
+
if (!(leading || isCancelled)) {
|
|
16
|
+
func.apply(this, args);
|
|
17
|
+
}
|
|
18
|
+
isCancelled = false;
|
|
19
|
+
}, wait);
|
|
20
|
+
}
|
|
21
|
+
debounced.cancel = () => {
|
|
22
|
+
isCancelled = true;
|
|
23
|
+
};
|
|
24
|
+
return debounced;
|
|
24
25
|
}
|
|
25
|
-
const defaultOpts = {
|
|
26
|
-
leading: false
|
|
27
|
-
};
|
|
26
|
+
const defaultOpts = { leading: false };
|
|
28
27
|
function useDebounce(fn, wait, options = defaultOpts, mountArgs = [fn]) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
28
|
+
const dbEffect = React.useRef(null);
|
|
29
|
+
React.useEffect(() => {
|
|
30
|
+
return () => {
|
|
31
|
+
dbEffect.current?.cancel();
|
|
32
|
+
};
|
|
33
|
+
}, []);
|
|
34
|
+
return React.useMemo(() => {
|
|
35
|
+
dbEffect.current = debounce(fn, wait, options.leading);
|
|
36
|
+
return dbEffect.current;
|
|
37
|
+
}, [options.leading, ...mountArgs]);
|
|
39
38
|
}
|
|
40
39
|
function useDebounceValue(val, amt = 0) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
40
|
+
const [state, setState] = React.useState(val);
|
|
41
|
+
React.useEffect(() => {
|
|
42
|
+
const tm = setTimeout(() => {
|
|
43
|
+
setState((prev) => {
|
|
44
|
+
if (prev === val) return prev;
|
|
45
|
+
return val;
|
|
46
|
+
});
|
|
47
|
+
}, amt);
|
|
48
|
+
return () => {
|
|
49
|
+
clearTimeout(tm);
|
|
50
|
+
};
|
|
51
|
+
}, [val]);
|
|
52
|
+
return state;
|
|
54
53
|
}
|
|
54
|
+
|
|
55
55
|
export { debounce, useDebounce, useDebounceValue };
|
|
56
56
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["esm/index.js"],"sourcesContent":["import * as React from \"react\";\nfunction debounce(func, wait, leading) {\n let timeout;\n let isCancelled = false;\n function debounced() {\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 debounced.cancel = () => {\n isCancelled = true;\n };\n return debounced;\n}\nconst defaultOpts = { leading: false };\nfunction useDebounce(fn, wait, options = defaultOpts, mountArgs = [fn]) {\n const dbEffect = React.useRef(null);\n React.useEffect(() => {\n return () => {\n dbEffect.current?.cancel();\n };\n }, []);\n return React.useMemo(() => {\n dbEffect.current = debounce(fn, wait, options.leading);\n return dbEffect.current;\n }, [options.leading, ...mountArgs]);\n}\nfunction useDebounceValue(val, amt = 0) {\n const [state, setState] = React.useState(val);\n React.useEffect(() => {\n const tm = setTimeout(() => {\n setState((prev) => {\n if (prev === val) return prev;\n return val;\n });\n }, amt);\n return () => {\n clearTimeout(tm);\n };\n }, [val]);\n return state;\n}\nexport {\n debounce,\n useDebounce,\n useDebounceValue\n};\n//# sourceMappingURL=index.js.map\n"],"mappings":";;;AACA,SAAS,SAAS,MAAM,MAAM,SAAS;CACrC,IAAI;CACJ,IAAI,cAAc;CAClB,SAAS,YAAY;EACnB,cAAc;EACd,MAAM,OAAO;EACb,IAAI,WAAW,CAAC,SAAS;GACvB,KAAK,MAAM,MAAM,IAAI;EACvB;EACA,aAAa,OAAO;EACpB,UAAU,iBAAiB;GACzB,UAAU;GACV,IAAI,EAAE,WAAW,cAAc;IAC7B,KAAK,MAAM,MAAM,IAAI;GACvB;GACA,cAAc;EAChB,GAAG,IAAI;CACT;CACA,UAAU,eAAe;EACvB,cAAc;CAChB;CACA,OAAO;AACT;AACA,MAAM,cAAc,EAAE,SAAS,MAAM;AACrC,SAAS,YAAY,IAAI,MAAM,UAAU,aAAa,YAAY,CAAC,EAAE,GAAG;CACtE,MAAM,WAAW,MAAM,OAAO,IAAI;CAClC,MAAM,gBAAgB;EACpB,aAAa;GACX,SAAS,SAAS,OAAO;EAC3B;CACF,GAAG,CAAC,CAAC;CACL,OAAO,MAAM,cAAc;EACzB,SAAS,UAAU,SAAS,IAAI,MAAM,QAAQ,OAAO;EACrD,OAAO,SAAS;CAClB,GAAG,CAAC,QAAQ,SAAS,GAAG,SAAS,CAAC;AACpC;AACA,SAAS,iBAAiB,KAAK,MAAM,GAAG;CACtC,MAAM,CAAC,OAAO,YAAY,MAAM,SAAS,GAAG;CAC5C,MAAM,gBAAgB;EACpB,MAAM,KAAK,iBAAiB;GAC1B,UAAU,SAAS;IACjB,IAAI,SAAS,KAAK,OAAO;IACzB,OAAO;GACT,CAAC;EACH,GAAG,GAAG;EACN,aAAa;GACX,aAAa,EAAE;EACjB;CACF,GAAG,CAAC,GAAG,CAAC;CACR,OAAO;AACT"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
+
|
|
2
3
|
function debounce(func, wait, leading) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
4
|
+
let timeout;
|
|
5
|
+
let isCancelled = false;
|
|
6
|
+
function debounced() {
|
|
7
|
+
isCancelled = false;
|
|
8
|
+
const args = arguments;
|
|
9
|
+
if (leading && !timeout) {
|
|
10
|
+
func.apply(this, args);
|
|
11
|
+
}
|
|
12
|
+
clearTimeout(timeout);
|
|
13
|
+
timeout = setTimeout(() => {
|
|
14
|
+
timeout = null;
|
|
15
|
+
if (!(leading || isCancelled)) {
|
|
16
|
+
func.apply(this, args);
|
|
17
|
+
}
|
|
18
|
+
isCancelled = false;
|
|
19
|
+
}, wait);
|
|
20
|
+
}
|
|
21
|
+
debounced.cancel = () => {
|
|
22
|
+
isCancelled = true;
|
|
23
|
+
};
|
|
24
|
+
return debounced;
|
|
24
25
|
}
|
|
25
|
-
const defaultOpts = {
|
|
26
|
-
leading: false
|
|
27
|
-
};
|
|
26
|
+
const defaultOpts = { leading: false };
|
|
28
27
|
function useDebounce(fn, wait, options = defaultOpts, mountArgs = [fn]) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
28
|
+
const dbEffect = React.useRef(null);
|
|
29
|
+
React.useEffect(() => {
|
|
30
|
+
return () => {
|
|
31
|
+
dbEffect.current?.cancel();
|
|
32
|
+
};
|
|
33
|
+
}, []);
|
|
34
|
+
return React.useMemo(() => {
|
|
35
|
+
dbEffect.current = debounce(fn, wait, options.leading);
|
|
36
|
+
return dbEffect.current;
|
|
37
|
+
}, [options.leading, ...mountArgs]);
|
|
39
38
|
}
|
|
40
39
|
function useDebounceValue(val, amt = 0) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
40
|
+
const [state, setState] = React.useState(val);
|
|
41
|
+
React.useEffect(() => {
|
|
42
|
+
const tm = setTimeout(() => {
|
|
43
|
+
setState((prev) => {
|
|
44
|
+
if (prev === val) return prev;
|
|
45
|
+
return val;
|
|
46
|
+
});
|
|
47
|
+
}, amt);
|
|
48
|
+
return () => {
|
|
49
|
+
clearTimeout(tm);
|
|
50
|
+
};
|
|
51
|
+
}, [val]);
|
|
52
|
+
return state;
|
|
54
53
|
}
|
|
54
|
+
|
|
55
55
|
export { debounce, useDebounce, useDebounceValue };
|
|
56
56
|
//# sourceMappingURL=index.mjs.map
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["esm/index.js"],"sourcesContent":["import * as React from \"react\";\nfunction debounce(func, wait, leading) {\n let timeout;\n let isCancelled = false;\n function debounced() {\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 debounced.cancel = () => {\n isCancelled = true;\n };\n return debounced;\n}\nconst defaultOpts = { leading: false };\nfunction useDebounce(fn, wait, options = defaultOpts, mountArgs = [fn]) {\n const dbEffect = React.useRef(null);\n React.useEffect(() => {\n return () => {\n dbEffect.current?.cancel();\n };\n }, []);\n return React.useMemo(() => {\n dbEffect.current = debounce(fn, wait, options.leading);\n return dbEffect.current;\n }, [options.leading, ...mountArgs]);\n}\nfunction useDebounceValue(val, amt = 0) {\n const [state, setState] = React.useState(val);\n React.useEffect(() => {\n const tm = setTimeout(() => {\n setState((prev) => {\n if (prev === val) return prev;\n return val;\n });\n }, amt);\n return () => {\n clearTimeout(tm);\n };\n }, [val]);\n return state;\n}\nexport {\n debounce,\n useDebounce,\n useDebounceValue\n};\n//# sourceMappingURL=index.js.map\n"],"mappings":";;;AACA,SAAS,SAAS,MAAM,MAAM,SAAS;CACrC,IAAI;CACJ,IAAI,cAAc;CAClB,SAAS,YAAY;EACnB,cAAc;EACd,MAAM,OAAO;EACb,IAAI,WAAW,CAAC,SAAS;GACvB,KAAK,MAAM,MAAM,IAAI;EACvB;EACA,aAAa,OAAO;EACpB,UAAU,iBAAiB;GACzB,UAAU;GACV,IAAI,EAAE,WAAW,cAAc;IAC7B,KAAK,MAAM,MAAM,IAAI;GACvB;GACA,cAAc;EAChB,GAAG,IAAI;CACT;CACA,UAAU,eAAe;EACvB,cAAc;CAChB;CACA,OAAO;AACT;AACA,MAAM,cAAc,EAAE,SAAS,MAAM;AACrC,SAAS,YAAY,IAAI,MAAM,UAAU,aAAa,YAAY,CAAC,EAAE,GAAG;CACtE,MAAM,WAAW,MAAM,OAAO,IAAI;CAClC,MAAM,gBAAgB;EACpB,aAAa;GACX,SAAS,SAAS,OAAO;EAC3B;CACF,GAAG,CAAC,CAAC;CACL,OAAO,MAAM,cAAc;EACzB,SAAS,UAAU,SAAS,IAAI,MAAM,QAAQ,OAAO;EACrD,OAAO,SAAS;CAClB,GAAG,CAAC,QAAQ,SAAS,GAAG,SAAS,CAAC;AACpC;AACA,SAAS,iBAAiB,KAAK,MAAM,GAAG;CACtC,MAAM,CAAC,OAAO,YAAY,MAAM,SAAS,GAAG;CAC5C,MAAM,gBAAgB;EACpB,MAAM,KAAK,iBAAiB;GAC1B,UAAU,SAAS;IACjB,IAAI,SAAS,KAAK,OAAO;IACzB,OAAO;GACT,CAAC;EACH,GAAG,GAAG;EACN,aAAa;GACX,aAAa,EAAE;EACjB;CACF,GAAG,CAAC,GAAG,CAAC;CACR,OAAO;AACT"}
|
package/dist/esm/index.native.js
CHANGED
|
@@ -1,61 +1,60 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
+
|
|
2
3
|
function debounce(func, wait, leading) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
4
|
+
var timeout;
|
|
5
|
+
var isCancelled = false;
|
|
6
|
+
function debounced() {
|
|
7
|
+
var _this = this;
|
|
8
|
+
isCancelled = false;
|
|
9
|
+
var args = arguments;
|
|
10
|
+
if (leading && !timeout) {
|
|
11
|
+
func.apply(this, args);
|
|
12
|
+
}
|
|
13
|
+
clearTimeout(timeout);
|
|
14
|
+
timeout = setTimeout(function() {
|
|
15
|
+
timeout = null;
|
|
16
|
+
if (!(leading || isCancelled)) {
|
|
17
|
+
func.apply(_this, args);
|
|
18
|
+
}
|
|
19
|
+
isCancelled = false;
|
|
20
|
+
}, wait);
|
|
21
|
+
}
|
|
22
|
+
debounced.cancel = function() {
|
|
23
|
+
isCancelled = true;
|
|
24
|
+
};
|
|
25
|
+
return debounced;
|
|
25
26
|
}
|
|
26
|
-
var defaultOpts = {
|
|
27
|
-
leading: false
|
|
28
|
-
};
|
|
27
|
+
var defaultOpts = { leading: false };
|
|
29
28
|
function useDebounce(fn, wait) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}, [options.leading, ...mountArgs]);
|
|
29
|
+
var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : defaultOpts, mountArgs = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : [fn];
|
|
30
|
+
var dbEffect = React.useRef(null);
|
|
31
|
+
React.useEffect(function() {
|
|
32
|
+
return function() {
|
|
33
|
+
var _dbEffect_current;
|
|
34
|
+
(_dbEffect_current = dbEffect.current) === null || _dbEffect_current === void 0 ? void 0 : _dbEffect_current.cancel();
|
|
35
|
+
};
|
|
36
|
+
}, []);
|
|
37
|
+
return React.useMemo(function() {
|
|
38
|
+
dbEffect.current = debounce(fn, wait, options.leading);
|
|
39
|
+
return dbEffect.current;
|
|
40
|
+
}, [options.leading, ...mountArgs]);
|
|
43
41
|
}
|
|
44
42
|
function useDebounceValue(val) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
43
|
+
var amt = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0;
|
|
44
|
+
var [state, setState] = React.useState(val);
|
|
45
|
+
React.useEffect(function() {
|
|
46
|
+
var tm = setTimeout(function() {
|
|
47
|
+
setState(function(prev) {
|
|
48
|
+
if (prev === val) return prev;
|
|
49
|
+
return val;
|
|
50
|
+
});
|
|
51
|
+
}, amt);
|
|
52
|
+
return function() {
|
|
53
|
+
clearTimeout(tm);
|
|
54
|
+
};
|
|
55
|
+
}, [val]);
|
|
56
|
+
return state;
|
|
59
57
|
}
|
|
58
|
+
|
|
60
59
|
export { debounce, useDebounce, useDebounceValue };
|
|
61
60
|
//# sourceMappingURL=index.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.native.js","names":[],"sources":["esm/index.native.js"],"sourcesContent":["import * as React from \"react\";\nfunction debounce(func, wait, leading) {\n var timeout;\n var isCancelled = false;\n function debounced() {\n var _this = this;\n isCancelled = false;\n var args = arguments;\n if (leading && !timeout) {\n func.apply(this, args);\n }\n clearTimeout(timeout);\n timeout = setTimeout(function() {\n timeout = null;\n if (!(leading || isCancelled)) {\n func.apply(_this, args);\n }\n isCancelled = false;\n }, wait);\n }\n debounced.cancel = function() {\n isCancelled = true;\n };\n return debounced;\n}\nvar defaultOpts = {\n leading: false\n};\nfunction useDebounce(fn, wait) {\n var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : defaultOpts, mountArgs = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : [\n fn\n ];\n var dbEffect = React.useRef(null);\n React.useEffect(function() {\n return function() {\n var _dbEffect_current;\n (_dbEffect_current = dbEffect.current) === null || _dbEffect_current === void 0 ? void 0 : _dbEffect_current.cancel();\n };\n }, []);\n return React.useMemo(function() {\n dbEffect.current = debounce(fn, wait, options.leading);\n return dbEffect.current;\n }, [\n options.leading,\n ...mountArgs\n ]);\n}\nfunction useDebounceValue(val) {\n var amt = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0;\n var [state, setState] = React.useState(val);\n React.useEffect(function() {\n var tm = setTimeout(function() {\n setState(function(prev) {\n if (prev === val) return prev;\n return val;\n });\n }, amt);\n return function() {\n clearTimeout(tm);\n };\n }, [\n val\n ]);\n return state;\n}\nexport {\n debounce,\n useDebounce,\n useDebounceValue\n};\n//# sourceMappingURL=index.js.map\n"],"mappings":";;;AACA,SAAS,SAAS,MAAM,MAAM,SAAS;CACrC,IAAI;CACJ,I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AW;GAChB,aAAa,EAAE;EACjB;CACF,GAAG,CACD,GACF,CAAC;CACD,OAAO;AACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/use-debounce",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-beta.643.1",
|
|
4
4
|
"gitHead": "a49cc7ea6b93ba384e77a4880ae48ac4a5635c14",
|
|
5
5
|
"files": [
|
|
6
6
|
"src",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"clean:build": "tamagui-build clean:build"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@tamagui/build": "
|
|
37
|
+
"@tamagui/build": "3.0.0-beta.643.1",
|
|
38
38
|
"react": ">=19"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|