@mantine-vue/hooks 3.2.0 → 3.4.0
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/cjs/index.cjs +10 -9
- package/cjs/index.cjs.map +1 -1
- package/esm/index.mjs +10 -9
- package/esm/index.mjs.map +1 -1
- package/package.json +1 -1
package/esm/index.mjs
CHANGED
|
@@ -272,11 +272,14 @@ function useDebouncedValue(value, wait, options = {}) {
|
|
|
272
272
|
let timeout;
|
|
273
273
|
let cooldown = false;
|
|
274
274
|
let latestValue = toValue(value);
|
|
275
|
-
const
|
|
275
|
+
const clearTimer = () => {
|
|
276
276
|
if (timeout) {
|
|
277
277
|
clearTimeout(timeout);
|
|
278
278
|
timeout = void 0;
|
|
279
279
|
}
|
|
280
|
+
};
|
|
281
|
+
const cancel = () => {
|
|
282
|
+
clearTimer();
|
|
280
283
|
cooldown = false;
|
|
281
284
|
};
|
|
282
285
|
const flush = () => {
|
|
@@ -287,6 +290,7 @@ function useDebouncedValue(value, wait, options = {}) {
|
|
|
287
290
|
};
|
|
288
291
|
watch(() => toValue(value), (nextValue) => {
|
|
289
292
|
latestValue = nextValue;
|
|
293
|
+
clearTimer();
|
|
290
294
|
if (!cooldown && options.leading) {
|
|
291
295
|
cooldown = true;
|
|
292
296
|
debounced.value = nextValue;
|
|
@@ -294,14 +298,11 @@ function useDebouncedValue(value, wait, options = {}) {
|
|
|
294
298
|
cooldown = false;
|
|
295
299
|
timeout = void 0;
|
|
296
300
|
}, wait);
|
|
297
|
-
} else {
|
|
298
|
-
|
|
299
|
-
timeout =
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
debounced.value = nextValue;
|
|
303
|
-
}, wait);
|
|
304
|
-
}
|
|
301
|
+
} else timeout = setTimeout(() => {
|
|
302
|
+
cooldown = false;
|
|
303
|
+
timeout = void 0;
|
|
304
|
+
debounced.value = nextValue;
|
|
305
|
+
}, wait);
|
|
305
306
|
});
|
|
306
307
|
onBeforeUnmount(cancel);
|
|
307
308
|
return [
|