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