@vueuse/shared 6.7.5 → 6.9.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/index.cjs CHANGED
@@ -166,6 +166,12 @@ function createGlobalState(stateFactory) {
166
166
  };
167
167
  }
168
168
 
169
+ function reactify(fn) {
170
+ return function(...args) {
171
+ return vueDemi.computed(() => fn.apply(this, args.map((i) => vueDemi.unref(i))));
172
+ };
173
+ }
174
+
169
175
  function tryOnScopeDispose(fn) {
170
176
  if (vueDemi.getCurrentScope()) {
171
177
  vueDemi.onScopeDispose(fn);
@@ -230,15 +236,35 @@ function createFilterWrapper(filter, fn) {
230
236
  const bypassFilter = (invoke) => {
231
237
  return invoke();
232
238
  };
233
- function debounceFilter(ms) {
239
+ function debounceFilter(ms, options = {}) {
234
240
  let timer;
241
+ let maxTimer;
235
242
  const filter = (invoke) => {
236
243
  const duration = vueDemi.unref(ms);
244
+ const maxDuration = vueDemi.unref(options.maxWait);
237
245
  if (timer)
238
246
  clearTimeout(timer);
239
- if (duration <= 0)
247
+ if (duration <= 0 || maxDuration !== void 0 && maxDuration <= 0) {
248
+ if (maxTimer) {
249
+ clearTimeout(maxTimer);
250
+ maxTimer = null;
251
+ }
240
252
  return invoke();
241
- timer = setTimeout(invoke, duration);
253
+ }
254
+ if (maxDuration && !maxTimer) {
255
+ maxTimer = setTimeout(() => {
256
+ if (timer)
257
+ clearTimeout(timer);
258
+ maxTimer = null;
259
+ invoke();
260
+ }, maxDuration);
261
+ }
262
+ timer = setTimeout(() => {
263
+ if (maxTimer)
264
+ clearTimeout(maxTimer);
265
+ maxTimer = null;
266
+ invoke();
267
+ }, duration);
242
268
  };
243
269
  return filter;
244
270
  }
@@ -348,17 +374,32 @@ function objectPick(obj, keys, omitUndefined = false) {
348
374
  }, {});
349
375
  }
350
376
 
351
- var __getOwnPropSymbols$8 = Object.getOwnPropertySymbols;
352
- var __hasOwnProp$8 = Object.prototype.hasOwnProperty;
353
- var __propIsEnum$8 = Object.prototype.propertyIsEnumerable;
377
+ function useDebounceFn(fn, ms = 200, options = {}) {
378
+ return createFilterWrapper(debounceFilter(ms, options), fn);
379
+ }
380
+
381
+ function useDebounce(value, ms = 200, options = {}) {
382
+ if (ms <= 0)
383
+ return value;
384
+ const debounced = vueDemi.ref(value.value);
385
+ const updater = useDebounceFn(() => {
386
+ debounced.value = value.value;
387
+ }, ms, options);
388
+ vueDemi.watch(value, () => updater());
389
+ return debounced;
390
+ }
391
+
392
+ var __getOwnPropSymbols$9 = Object.getOwnPropertySymbols;
393
+ var __hasOwnProp$9 = Object.prototype.hasOwnProperty;
394
+ var __propIsEnum$9 = Object.prototype.propertyIsEnumerable;
354
395
  var __objRest$5 = (source, exclude) => {
355
396
  var target = {};
356
397
  for (var prop in source)
357
- if (__hasOwnProp$8.call(source, prop) && exclude.indexOf(prop) < 0)
398
+ if (__hasOwnProp$9.call(source, prop) && exclude.indexOf(prop) < 0)
358
399
  target[prop] = source[prop];
359
- if (source != null && __getOwnPropSymbols$8)
360
- for (var prop of __getOwnPropSymbols$8(source)) {
361
- if (exclude.indexOf(prop) < 0 && __propIsEnum$8.call(source, prop))
400
+ if (source != null && __getOwnPropSymbols$9)
401
+ for (var prop of __getOwnPropSymbols$9(source)) {
402
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$9.call(source, prop))
362
403
  target[prop] = source[prop];
363
404
  }
364
405
  return target;
@@ -372,33 +413,33 @@ function watchWithFilter(source, cb, options = {}) {
372
413
  return vueDemi.watch(source, createFilterWrapper(eventFilter, cb), watchOptions);
373
414
  }
374
415
 
375
- var __defProp$6 = Object.defineProperty;
376
- var __defProps$3 = Object.defineProperties;
377
- var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
378
- var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
379
- var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
380
- var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
381
- var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
382
- var __spreadValues$6 = (a, b) => {
416
+ var __defProp$7 = Object.defineProperty;
417
+ var __defProps$4 = Object.defineProperties;
418
+ var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
419
+ var __getOwnPropSymbols$8 = Object.getOwnPropertySymbols;
420
+ var __hasOwnProp$8 = Object.prototype.hasOwnProperty;
421
+ var __propIsEnum$8 = Object.prototype.propertyIsEnumerable;
422
+ var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
423
+ var __spreadValues$7 = (a, b) => {
383
424
  for (var prop in b || (b = {}))
384
- if (__hasOwnProp$7.call(b, prop))
385
- __defNormalProp$6(a, prop, b[prop]);
386
- if (__getOwnPropSymbols$7)
387
- for (var prop of __getOwnPropSymbols$7(b)) {
388
- if (__propIsEnum$7.call(b, prop))
389
- __defNormalProp$6(a, prop, b[prop]);
425
+ if (__hasOwnProp$8.call(b, prop))
426
+ __defNormalProp$7(a, prop, b[prop]);
427
+ if (__getOwnPropSymbols$8)
428
+ for (var prop of __getOwnPropSymbols$8(b)) {
429
+ if (__propIsEnum$8.call(b, prop))
430
+ __defNormalProp$7(a, prop, b[prop]);
390
431
  }
391
432
  return a;
392
433
  };
393
- var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
434
+ var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
394
435
  var __objRest$4 = (source, exclude) => {
395
436
  var target = {};
396
437
  for (var prop in source)
397
- if (__hasOwnProp$7.call(source, prop) && exclude.indexOf(prop) < 0)
438
+ if (__hasOwnProp$8.call(source, prop) && exclude.indexOf(prop) < 0)
398
439
  target[prop] = source[prop];
399
- if (source != null && __getOwnPropSymbols$7)
400
- for (var prop of __getOwnPropSymbols$7(source)) {
401
- if (exclude.indexOf(prop) < 0 && __propIsEnum$7.call(source, prop))
440
+ if (source != null && __getOwnPropSymbols$8)
441
+ for (var prop of __getOwnPropSymbols$8(source)) {
442
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$8.call(source, prop))
402
443
  target[prop] = source[prop];
403
444
  }
404
445
  return target;
@@ -409,7 +450,7 @@ function debouncedWatch(source, cb, options = {}) {
409
450
  } = _a, watchOptions = __objRest$4(_a, [
410
451
  "debounce"
411
452
  ]);
412
- return watchWithFilter(source, cb, __spreadProps$3(__spreadValues$6({}, watchOptions), {
453
+ return watchWithFilter(source, cb, __spreadProps$4(__spreadValues$7({}, watchOptions), {
413
454
  eventFilter: debounceFilter(debounce)
414
455
  }));
415
456
  }
@@ -428,33 +469,33 @@ function get(obj, key) {
428
469
  return vueDemi.unref(obj)[key];
429
470
  }
430
471
 
431
- var __defProp$5 = Object.defineProperty;
432
- var __defProps$2 = Object.defineProperties;
433
- var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
434
- var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
435
- var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
436
- var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
437
- var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
438
- var __spreadValues$5 = (a, b) => {
472
+ var __defProp$6 = Object.defineProperty;
473
+ var __defProps$3 = Object.defineProperties;
474
+ var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
475
+ var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
476
+ var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
477
+ var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
478
+ var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
479
+ var __spreadValues$6 = (a, b) => {
439
480
  for (var prop in b || (b = {}))
440
- if (__hasOwnProp$6.call(b, prop))
441
- __defNormalProp$5(a, prop, b[prop]);
442
- if (__getOwnPropSymbols$6)
443
- for (var prop of __getOwnPropSymbols$6(b)) {
444
- if (__propIsEnum$6.call(b, prop))
445
- __defNormalProp$5(a, prop, b[prop]);
481
+ if (__hasOwnProp$7.call(b, prop))
482
+ __defNormalProp$6(a, prop, b[prop]);
483
+ if (__getOwnPropSymbols$7)
484
+ for (var prop of __getOwnPropSymbols$7(b)) {
485
+ if (__propIsEnum$7.call(b, prop))
486
+ __defNormalProp$6(a, prop, b[prop]);
446
487
  }
447
488
  return a;
448
489
  };
449
- var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
490
+ var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
450
491
  var __objRest$3 = (source, exclude) => {
451
492
  var target = {};
452
493
  for (var prop in source)
453
- if (__hasOwnProp$6.call(source, prop) && exclude.indexOf(prop) < 0)
494
+ if (__hasOwnProp$7.call(source, prop) && exclude.indexOf(prop) < 0)
454
495
  target[prop] = source[prop];
455
- if (source != null && __getOwnPropSymbols$6)
456
- for (var prop of __getOwnPropSymbols$6(source)) {
457
- if (exclude.indexOf(prop) < 0 && __propIsEnum$6.call(source, prop))
496
+ if (source != null && __getOwnPropSymbols$7)
497
+ for (var prop of __getOwnPropSymbols$7(source)) {
498
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$7.call(source, prop))
458
499
  target[prop] = source[prop];
459
500
  }
460
501
  return target;
@@ -491,7 +532,7 @@ function ignorableWatch(source, cb, options = {}) {
491
532
  };
492
533
  disposables.push(vueDemi.watch(source, () => {
493
534
  syncCounter.value++;
494
- }, __spreadProps$2(__spreadValues$5({}, watchOptions), { flush: "sync" })));
535
+ }, __spreadProps$3(__spreadValues$6({}, watchOptions), { flush: "sync" })));
495
536
  ignoreUpdates = (updater) => {
496
537
  const syncCounterPrev = syncCounter.value;
497
538
  updater();
@@ -516,25 +557,25 @@ function isDefined(v) {
516
557
  return vueDemi.unref(v) != null;
517
558
  }
518
559
 
519
- var __defProp$4 = Object.defineProperty;
520
- var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
521
- var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
522
- var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
523
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
524
- var __spreadValues$4 = (a, b) => {
560
+ var __defProp$5 = Object.defineProperty;
561
+ var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
562
+ var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
563
+ var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
564
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
565
+ var __spreadValues$5 = (a, b) => {
525
566
  for (var prop in b || (b = {}))
526
- if (__hasOwnProp$5.call(b, prop))
527
- __defNormalProp$4(a, prop, b[prop]);
528
- if (__getOwnPropSymbols$5)
529
- for (var prop of __getOwnPropSymbols$5(b)) {
530
- if (__propIsEnum$5.call(b, prop))
531
- __defNormalProp$4(a, prop, b[prop]);
567
+ if (__hasOwnProp$6.call(b, prop))
568
+ __defNormalProp$5(a, prop, b[prop]);
569
+ if (__getOwnPropSymbols$6)
570
+ for (var prop of __getOwnPropSymbols$6(b)) {
571
+ if (__propIsEnum$6.call(b, prop))
572
+ __defNormalProp$5(a, prop, b[prop]);
532
573
  }
533
574
  return a;
534
575
  };
535
576
  function makeDestructurable(obj, arr) {
536
577
  if (typeof Symbol !== "undefined") {
537
- const clone = __spreadValues$4({}, obj);
578
+ const clone = __spreadValues$5({}, obj);
538
579
  Object.defineProperty(clone, Symbol.iterator, {
539
580
  enumerable: false,
540
581
  value() {
@@ -561,33 +602,33 @@ function or(...args) {
561
602
  return vueDemi.computed(() => args.some((i) => vueDemi.unref(i)));
562
603
  }
563
604
 
564
- var __defProp$3 = Object.defineProperty;
565
- var __defProps$1 = Object.defineProperties;
566
- var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
567
- var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
568
- var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
569
- var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
570
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
571
- var __spreadValues$3 = (a, b) => {
605
+ var __defProp$4 = Object.defineProperty;
606
+ var __defProps$2 = Object.defineProperties;
607
+ var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
608
+ var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
609
+ var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
610
+ var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
611
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
612
+ var __spreadValues$4 = (a, b) => {
572
613
  for (var prop in b || (b = {}))
573
- if (__hasOwnProp$4.call(b, prop))
574
- __defNormalProp$3(a, prop, b[prop]);
575
- if (__getOwnPropSymbols$4)
576
- for (var prop of __getOwnPropSymbols$4(b)) {
577
- if (__propIsEnum$4.call(b, prop))
578
- __defNormalProp$3(a, prop, b[prop]);
614
+ if (__hasOwnProp$5.call(b, prop))
615
+ __defNormalProp$4(a, prop, b[prop]);
616
+ if (__getOwnPropSymbols$5)
617
+ for (var prop of __getOwnPropSymbols$5(b)) {
618
+ if (__propIsEnum$5.call(b, prop))
619
+ __defNormalProp$4(a, prop, b[prop]);
579
620
  }
580
621
  return a;
581
622
  };
582
- var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
623
+ var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
583
624
  var __objRest$2 = (source, exclude) => {
584
625
  var target = {};
585
626
  for (var prop in source)
586
- if (__hasOwnProp$4.call(source, prop) && exclude.indexOf(prop) < 0)
627
+ if (__hasOwnProp$5.call(source, prop) && exclude.indexOf(prop) < 0)
587
628
  target[prop] = source[prop];
588
- if (source != null && __getOwnPropSymbols$4)
589
- for (var prop of __getOwnPropSymbols$4(source)) {
590
- if (exclude.indexOf(prop) < 0 && __propIsEnum$4.call(source, prop))
629
+ if (source != null && __getOwnPropSymbols$5)
630
+ for (var prop of __getOwnPropSymbols$5(source)) {
631
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$5.call(source, prop))
591
632
  target[prop] = source[prop];
592
633
  }
593
634
  return target;
@@ -599,18 +640,12 @@ function pausableWatch(source, cb, options = {}) {
599
640
  "eventFilter"
600
641
  ]);
601
642
  const { eventFilter, pause, resume, isActive } = pausableFilter(filter);
602
- const stop = watchWithFilter(source, cb, __spreadProps$1(__spreadValues$3({}, watchOptions), {
643
+ const stop = watchWithFilter(source, cb, __spreadProps$2(__spreadValues$4({}, watchOptions), {
603
644
  eventFilter
604
645
  }));
605
646
  return { stop, pause, resume, isActive };
606
647
  }
607
648
 
608
- function reactify(fn) {
609
- return function(...args) {
610
- return vueDemi.computed(() => fn.apply(this, args.map((i) => vueDemi.unref(i))));
611
- };
612
- }
613
-
614
649
  function reactifyObject(obj, optionsOrKeys = {}) {
615
650
  let keys = [];
616
651
  if (Array.isArray(optionsOrKeys)) {
@@ -653,7 +688,7 @@ function set(...args) {
653
688
  }
654
689
  if (args.length === 3) {
655
690
  if (vueDemi.isVue2) {
656
- require("vue-demi").set(...args);
691
+ vueDemi.set(...args);
657
692
  } else {
658
693
  const [target, key, value] = args;
659
694
  target[key] = value;
@@ -668,42 +703,51 @@ function syncRef(source, targets, {
668
703
  } = {}) {
669
704
  if (!Array.isArray(targets))
670
705
  targets = [targets];
671
- return vueDemi.watch(source, (newValue) => {
672
- targets.forEach((target) => target.value = newValue);
673
- }, {
674
- flush,
675
- deep,
676
- immediate
677
- });
706
+ return vueDemi.watch(source, (newValue) => targets.forEach((target) => target.value = newValue), { flush, deep, immediate });
678
707
  }
679
708
 
680
- var __defProp$2 = Object.defineProperty;
681
- var __defProps = Object.defineProperties;
682
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
683
- var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
684
- var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
685
- var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
686
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
687
- var __spreadValues$2 = (a, b) => {
709
+ function useThrottleFn(fn, ms = 200, trailing = true, leading = true) {
710
+ return createFilterWrapper(throttleFilter(ms, trailing, leading), fn);
711
+ }
712
+
713
+ function useThrottle(value, delay = 200, trailing = true, leading = true) {
714
+ if (delay <= 0)
715
+ return value;
716
+ const throttled = vueDemi.ref(value.value);
717
+ const updater = useThrottleFn(() => {
718
+ throttled.value = value.value;
719
+ }, delay, trailing, leading);
720
+ vueDemi.watch(value, () => updater());
721
+ return throttled;
722
+ }
723
+
724
+ var __defProp$3 = Object.defineProperty;
725
+ var __defProps$1 = Object.defineProperties;
726
+ var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
727
+ var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
728
+ var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
729
+ var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
730
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
731
+ var __spreadValues$3 = (a, b) => {
688
732
  for (var prop in b || (b = {}))
689
- if (__hasOwnProp$3.call(b, prop))
690
- __defNormalProp$2(a, prop, b[prop]);
691
- if (__getOwnPropSymbols$3)
692
- for (var prop of __getOwnPropSymbols$3(b)) {
693
- if (__propIsEnum$3.call(b, prop))
694
- __defNormalProp$2(a, prop, b[prop]);
733
+ if (__hasOwnProp$4.call(b, prop))
734
+ __defNormalProp$3(a, prop, b[prop]);
735
+ if (__getOwnPropSymbols$4)
736
+ for (var prop of __getOwnPropSymbols$4(b)) {
737
+ if (__propIsEnum$4.call(b, prop))
738
+ __defNormalProp$3(a, prop, b[prop]);
695
739
  }
696
740
  return a;
697
741
  };
698
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
742
+ var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
699
743
  var __objRest$1 = (source, exclude) => {
700
744
  var target = {};
701
745
  for (var prop in source)
702
- if (__hasOwnProp$3.call(source, prop) && exclude.indexOf(prop) < 0)
746
+ if (__hasOwnProp$4.call(source, prop) && exclude.indexOf(prop) < 0)
703
747
  target[prop] = source[prop];
704
- if (source != null && __getOwnPropSymbols$3)
705
- for (var prop of __getOwnPropSymbols$3(source)) {
706
- if (exclude.indexOf(prop) < 0 && __propIsEnum$3.call(source, prop))
748
+ if (source != null && __getOwnPropSymbols$4)
749
+ for (var prop of __getOwnPropSymbols$4(source)) {
750
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$4.call(source, prop))
707
751
  target[prop] = source[prop];
708
752
  }
709
753
  return target;
@@ -718,7 +762,7 @@ function throttledWatch(source, cb, options = {}) {
718
762
  "trailing",
719
763
  "leading"
720
764
  ]);
721
- return watchWithFilter(source, cb, __spreadProps(__spreadValues$2({}, watchOptions), {
765
+ return watchWithFilter(source, cb, __spreadProps$1(__spreadValues$3({}, watchOptions), {
722
766
  eventFilter: throttleFilter(throttle, trailing, leading)
723
767
  }));
724
768
  }
@@ -753,6 +797,25 @@ function toReactive(objectRef) {
753
797
  return vueDemi.reactive(proxy);
754
798
  }
755
799
 
800
+ var __defProp$2 = Object.defineProperty;
801
+ var __defProps = Object.defineProperties;
802
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
803
+ var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
804
+ var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
805
+ var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
806
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
807
+ var __spreadValues$2 = (a, b) => {
808
+ for (var prop in b || (b = {}))
809
+ if (__hasOwnProp$3.call(b, prop))
810
+ __defNormalProp$2(a, prop, b[prop]);
811
+ if (__getOwnPropSymbols$3)
812
+ for (var prop of __getOwnPropSymbols$3(b)) {
813
+ if (__propIsEnum$3.call(b, prop))
814
+ __defNormalProp$2(a, prop, b[prop]);
815
+ }
816
+ return a;
817
+ };
818
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
756
819
  function toRefs(objectRef) {
757
820
  if (!vueDemi.isRef(objectRef))
758
821
  return vueDemi.toRefs(objectRef);
@@ -763,7 +826,13 @@ function toRefs(objectRef) {
763
826
  return objectRef.value[key];
764
827
  },
765
828
  set(v) {
766
- objectRef.value[key] = v;
829
+ if (Array.isArray(objectRef.value)) {
830
+ const copy = [...objectRef.value];
831
+ copy[key] = v;
832
+ objectRef.value = copy;
833
+ } else {
834
+ objectRef.value = __spreadProps(__spreadValues$2({}, objectRef.value), { [key]: v });
835
+ }
767
836
  }
768
837
  }));
769
838
  }
@@ -888,21 +957,6 @@ function useCounter(initialValue = 0) {
888
957
  return { count, inc, dec, get, set, reset };
889
958
  }
890
959
 
891
- function useDebounceFn(fn, ms = 200) {
892
- return createFilterWrapper(debounceFilter(ms), fn);
893
- }
894
-
895
- function useDebounce(value, ms = 200) {
896
- if (ms <= 0)
897
- return value;
898
- const debounced = vueDemi.ref(value.value);
899
- const updater = useDebounceFn(() => {
900
- debounced.value = value.value;
901
- }, ms);
902
- vueDemi.watch(value, () => updater());
903
- return debounced;
904
- }
905
-
906
960
  function useIntervalFn(cb, interval = 1e3, options = {}) {
907
961
  const {
908
962
  immediate = true,
@@ -978,21 +1032,6 @@ function useLastChanged(source, options = {}) {
978
1032
  return ms;
979
1033
  }
980
1034
 
981
- function useThrottleFn(fn, ms = 200, trailing = true, leading = true) {
982
- return createFilterWrapper(throttleFilter(ms, trailing, leading), fn);
983
- }
984
-
985
- function useThrottle(value, delay = 200, trailing = true, leading = true) {
986
- if (delay <= 0)
987
- return value;
988
- const throttled = vueDemi.ref(value.value);
989
- const updater = useThrottleFn(() => {
990
- throttled.value = value.value;
991
- }, delay, trailing, leading);
992
- vueDemi.watch(value, () => updater());
993
- return throttled;
994
- }
995
-
996
1035
  function useTimeoutFn(cb, interval, options = {}) {
997
1036
  const {
998
1037
  immediate = true
@@ -1132,9 +1171,11 @@ exports.controlledRef = controlledRef;
1132
1171
  exports.createEventHook = createEventHook;
1133
1172
  exports.createFilterWrapper = createFilterWrapper;
1134
1173
  exports.createGlobalState = createGlobalState;
1174
+ exports.createReactiveFn = reactify;
1135
1175
  exports.createSharedComposable = createSharedComposable;
1136
1176
  exports.createSingletonPromise = createSingletonPromise;
1137
1177
  exports.debounceFilter = debounceFilter;
1178
+ exports.debouncedRef = useDebounce;
1138
1179
  exports.debouncedWatch = debouncedWatch;
1139
1180
  exports.eagerComputed = eagerComputed;
1140
1181
  exports.extendRef = extendRef;
@@ -1169,6 +1210,7 @@ exports.refDefault = refDefault;
1169
1210
  exports.set = set;
1170
1211
  exports.syncRef = syncRef;
1171
1212
  exports.throttleFilter = throttleFilter;
1213
+ exports.throttledRef = useThrottle;
1172
1214
  exports.throttledWatch = throttledWatch;
1173
1215
  exports.timestamp = timestamp;
1174
1216
  exports.toReactive = toReactive;
package/index.d.ts CHANGED
@@ -119,6 +119,13 @@ interface ConfigurableEventFilter {
119
119
  */
120
120
  eventFilter?: EventFilter;
121
121
  }
122
+ interface DebounceFilterOptions {
123
+ /**
124
+ * The maximum time allowed to be delayed before it's invoked.
125
+ * In milliseconds.
126
+ */
127
+ maxWait?: number;
128
+ }
122
129
  /**
123
130
  * @internal
124
131
  */
@@ -128,8 +135,9 @@ declare const bypassFilter: EventFilter;
128
135
  * Create an EventFilter that debounce the events
129
136
  *
130
137
  * @param ms
138
+ * @param [maxWait=null]
131
139
  */
132
- declare function debounceFilter(ms: MaybeRef<number>): EventFilter<any[], any>;
140
+ declare function debounceFilter(ms: MaybeRef<number>, options?: DebounceFilterOptions): EventFilter<any[], any>;
133
141
  /**
134
142
  * Create an EventFilter that throttle the events
135
143
  *
@@ -271,6 +279,18 @@ declare type CreateGlobalStateReturn<T> = () => T;
271
279
  */
272
280
  declare function createGlobalState<T>(stateFactory: () => T): CreateGlobalStateReturn<T>;
273
281
 
282
+ declare type Reactify<T> = T extends (...args: infer A) => infer R ? (...args: {
283
+ [K in keyof A]: MaybeRef<A[K]>;
284
+ }) => ComputedRef<R> : never;
285
+ /**
286
+ * Converts plain function into a reactive function.
287
+ * The converted function accepts refs as it's arguments
288
+ * and returns a ComputedRef, with proper typing.
289
+ *
290
+ * @param fn - Source function
291
+ */
292
+ declare function reactify<T extends Function>(fn: T): Reactify<T>;
293
+
274
294
  /**
275
295
  * Make a composable function usable with multiple Vue instances.
276
296
  *
@@ -278,6 +298,13 @@ declare function createGlobalState<T>(stateFactory: () => T): CreateGlobalStateR
278
298
  */
279
299
  declare function createSharedComposable<Fn extends ((...args: any[]) => any)>(composable: Fn): Fn;
280
300
 
301
+ /**
302
+ * Debounce updates of a ref.
303
+ *
304
+ * @return A new debounced ref.
305
+ */
306
+ declare function useDebounce<T>(value: Ref<T>, ms?: number, options?: DebounceFilterOptions): Readonly<Ref<T>>;
307
+
281
308
  interface DebouncedWatchOptions<Immediate> extends WatchOptions<Immediate> {
282
309
  debounce?: MaybeRef<number>;
283
310
  }
@@ -359,18 +386,6 @@ declare function pausableWatch<T extends Readonly<WatchSource<unknown>[]>, Immed
359
386
  declare function pausableWatch<T, Immediate extends Readonly<boolean> = false>(source: WatchSource<T>, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: WatchWithFilterOptions<Immediate>): PausableWatchReturn;
360
387
  declare function pausableWatch<T extends object, Immediate extends Readonly<boolean> = false>(source: T, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: WatchWithFilterOptions<Immediate>): PausableWatchReturn;
361
388
 
362
- declare type Reactify<T> = T extends (...args: infer A) => infer R ? (...args: {
363
- [K in keyof A]: MaybeRef<A[K]>;
364
- }) => ComputedRef<R> : never;
365
- /**
366
- * Converts plain function into a reactive function.
367
- * The converted function accepts refs as it's arguments
368
- * and returns a ComputedRef, with proper typing.
369
- *
370
- * @param fn - Source function
371
- */
372
- declare function reactify<T extends Function>(fn: T): Reactify<T>;
373
-
374
389
  declare type ReactifyNested<T, Keys extends keyof T = keyof T> = {
375
390
  [K in Keys]: T[K] extends (...args: any[]) => any ? Reactify<T[K]> : T[K];
376
391
  };
@@ -428,7 +443,18 @@ interface SyncRefOptions extends ConfigurableFlushSync {
428
443
  * @param source source ref
429
444
  * @param targets
430
445
  */
431
- declare function syncRef<R extends Ref<any>>(source: R, targets: R | R[], { flush, deep, immediate, }?: SyncRefOptions): vue_demi.WatchStopHandle;
446
+ declare function syncRef<T>(source: WatchSource<T>, targets: Ref<T> | Ref<T>[], { flush, deep, immediate, }?: SyncRefOptions): vue_demi.WatchStopHandle;
447
+
448
+ /**
449
+ * Throttle execution of a function. Especially useful for rate limiting
450
+ * execution of handlers on events like resize and scroll.
451
+ *
452
+ * @param value Ref value to be watched with throttle effect
453
+ * @param delay A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.
454
+ * @param [trailing=true] if true, update the value again after the delay time is up
455
+ * @param [leading=true] if true, update the value on the leading edge of the ms timeout
456
+ */
457
+ declare function useThrottle<T>(value: Ref<T>, delay?: number, trailing?: boolean, leading?: boolean): Ref<T>;
432
458
 
433
459
  interface ThrottledWatchOptions<Immediate> extends WatchOptions<Immediate> {
434
460
  throttle?: MaybeRef<number>;
@@ -559,17 +585,16 @@ declare function useCounter(initialValue?: number): {
559
585
  reset: (val?: number) => number;
560
586
  };
561
587
 
562
- declare function useDebounce<T>(value: Ref<T>, ms?: number): Readonly<Ref<T>>;
563
-
564
588
  /**
565
589
  * Debounce execution of a function.
566
590
  *
567
591
  * @param fn A function to be executed after delay milliseconds debounced.
568
592
  * @param ms A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.
593
+ * @param opts options
569
594
  *
570
595
  * @return A new, debounce, function.
571
596
  */
572
- declare function useDebounceFn<T extends FunctionArgs>(fn: T, ms?: MaybeRef<number>): T;
597
+ declare function useDebounceFn<T extends FunctionArgs>(fn: T, ms?: MaybeRef<number>, options?: DebounceFilterOptions): T;
573
598
 
574
599
  interface IntervalOptions<Controls extends boolean> {
575
600
  /**
@@ -625,17 +650,6 @@ declare function useLastChanged(source: WatchSource, options?: UseLastChangedOpt
625
650
  declare function useLastChanged(source: WatchSource, options: UseLastChangedOptions<true>): Ref<number>;
626
651
  declare function useLastChanged(source: WatchSource, options: UseLastChangedOptions<boolean, number>): Ref<number>;
627
652
 
628
- /**
629
- * Throttle execution of a function. Especially useful for rate limiting
630
- * execution of handlers on events like resize and scroll.
631
- *
632
- * @param value Ref value to be watched with throttle effect
633
- * @param delay A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.
634
- * @param [trailing=true] if true, update the value again after the delay time is up
635
- * @param [leading=true] if true, update the value on the leading edge of the ms timeout
636
- */
637
- declare function useThrottle<T>(value: Ref<T>, delay?: number, trailing?: boolean, leading?: boolean): Ref<T>;
638
-
639
653
  /**
640
654
  * Throttle execution of a function. Especially useful for rate limiting
641
655
  * execution of handlers on events like resize and scroll.
@@ -720,4 +734,4 @@ declare function watchOnce<T, Immediate extends Readonly<boolean> = false>(sourc
720
734
  */
721
735
  declare function whenever<T>(source: WatchSource<T>, cb: WatchCallback, options?: WatchOptions): vue_demi.WatchStopHandle;
722
736
 
723
- export { ConfigurableEventFilter, ConfigurableFlush, ConfigurableFlushSync, ControlledRefOptions, CreateGlobalStateReturn, DebouncedWatchOptions, DeepMaybeRef, ElementOf, EventFilter, EventHook, EventHookOff, EventHookOn, EventHookTrigger, ExtendRefOptions, Fn, FunctionArgs, FunctionWrapperOptions, IgnorableWatchReturn, IgnoredUpdater, IntervalFnOptions, IntervalOptions, MapOldSources, MapSources, MaybeRef, Pausable, PausableWatchReturn, Reactify, ReactifyNested, ReactifyObjectOptions, RemoveableRef, ShallowUnwrapRef, SingletonPromiseReturn, Stopable, SyncRefOptions, ThrottledWatchOptions, TimeoutFnOptions, TimeoutOptions, UntilArrayInstance, UntilBaseInstance, UntilToMatchOptions, UntilValueInstance, UseLastChangedOptions, WatchAtMostOptions, WatchAtMostReturn, WatchWithFilterOptions, and, assert, biSyncRef, bypassFilter, clamp, containsProp, controlledComputed, controlledRef, createEventHook, createFilterWrapper, createGlobalState, createSharedComposable, createSingletonPromise, debounceFilter, debouncedWatch, eagerComputed, extendRef, get, identity, ignorableWatch, increaseWithUnit, invoke, isBoolean, isClient, isDef, isDefined, isFunction, isNumber, isObject, isString, isWindow, makeDestructurable, noop, not, now, objectPick, or, pausableFilter, pausableWatch, promiseTimeout, rand, reactify, reactifyObject, reactivePick, refDefault, set, syncRef, throttleFilter, throttledWatch, timestamp, toReactive, toRefs, tryOnBeforeUnmount, tryOnMounted, tryOnScopeDispose, tryOnUnmounted, until, useCounter, useDebounce, useDebounceFn, useInterval, useIntervalFn, useLastChanged, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useToggle, watchAtMost, watchOnce, watchWithFilter, whenever };
737
+ export { ConfigurableEventFilter, ConfigurableFlush, ConfigurableFlushSync, ControlledRefOptions, CreateGlobalStateReturn, DebounceFilterOptions, DebouncedWatchOptions, DeepMaybeRef, ElementOf, EventFilter, EventHook, EventHookOff, EventHookOn, EventHookTrigger, ExtendRefOptions, Fn, FunctionArgs, FunctionWrapperOptions, IgnorableWatchReturn, IgnoredUpdater, IntervalFnOptions, IntervalOptions, MapOldSources, MapSources, MaybeRef, Pausable, PausableWatchReturn, Reactify, ReactifyNested, ReactifyObjectOptions, RemoveableRef, ShallowUnwrapRef, SingletonPromiseReturn, Stopable, SyncRefOptions, ThrottledWatchOptions, TimeoutFnOptions, TimeoutOptions, UntilArrayInstance, UntilBaseInstance, UntilToMatchOptions, UntilValueInstance, UseLastChangedOptions, WatchAtMostOptions, WatchAtMostReturn, WatchWithFilterOptions, and, assert, biSyncRef, bypassFilter, clamp, containsProp, controlledComputed, controlledRef, createEventHook, createFilterWrapper, createGlobalState, reactify as createReactiveFn, createSharedComposable, createSingletonPromise, debounceFilter, useDebounce as debouncedRef, debouncedWatch, eagerComputed, extendRef, get, identity, ignorableWatch, increaseWithUnit, invoke, isBoolean, isClient, isDef, isDefined, isFunction, isNumber, isObject, isString, isWindow, makeDestructurable, noop, not, now, objectPick, or, pausableFilter, pausableWatch, promiseTimeout, rand, reactify, reactifyObject, reactivePick, refDefault, set, syncRef, throttleFilter, useThrottle as throttledRef, throttledWatch, timestamp, toReactive, toRefs, tryOnBeforeUnmount, tryOnMounted, tryOnScopeDispose, tryOnUnmounted, until, useCounter, useDebounce, useDebounceFn, useInterval, useIntervalFn, useLastChanged, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useToggle, watchAtMost, watchOnce, watchWithFilter, whenever };