@vue/reactivity 3.1.0 → 3.1.4

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.
@@ -201,34 +201,38 @@ const get = /*#__PURE__*/ createGetter();
201
201
  const shallowGet = /*#__PURE__*/ createGetter(false, true);
202
202
  const readonlyGet = /*#__PURE__*/ createGetter(true);
203
203
  const shallowReadonlyGet = /*#__PURE__*/ createGetter(true, true);
204
- const arrayInstrumentations = {};
205
- ['includes', 'indexOf', 'lastIndexOf'].forEach(key => {
206
- const method = Array.prototype[key];
207
- arrayInstrumentations[key] = function (...args) {
208
- const arr = toRaw(this);
209
- for (let i = 0, l = this.length; i < l; i++) {
210
- track(arr, "get" /* GET */, i + '');
211
- }
212
- // we run the method using the original args first (which may be reactive)
213
- const res = method.apply(arr, args);
214
- if (res === -1 || res === false) {
215
- // if that didn't work, run it again using raw values.
216
- return method.apply(arr, args.map(toRaw));
217
- }
218
- else {
204
+ const arrayInstrumentations = /*#__PURE__*/ createArrayInstrumentations();
205
+ function createArrayInstrumentations() {
206
+ const instrumentations = {};
207
+ ['includes', 'indexOf', 'lastIndexOf'].forEach(key => {
208
+ const method = Array.prototype[key];
209
+ instrumentations[key] = function (...args) {
210
+ const arr = toRaw(this);
211
+ for (let i = 0, l = this.length; i < l; i++) {
212
+ track(arr, "get" /* GET */, i + '');
213
+ }
214
+ // we run the method using the original args first (which may be reactive)
215
+ const res = method.apply(arr, args);
216
+ if (res === -1 || res === false) {
217
+ // if that didn't work, run it again using raw values.
218
+ return method.apply(arr, args.map(toRaw));
219
+ }
220
+ else {
221
+ return res;
222
+ }
223
+ };
224
+ });
225
+ ['push', 'pop', 'shift', 'unshift', 'splice'].forEach(key => {
226
+ const method = Array.prototype[key];
227
+ instrumentations[key] = function (...args) {
228
+ pauseTracking();
229
+ const res = method.apply(this, args);
230
+ resetTracking();
219
231
  return res;
220
- }
221
- };
222
- });
223
- ['push', 'pop', 'shift', 'unshift', 'splice'].forEach(key => {
224
- const method = Array.prototype[key];
225
- arrayInstrumentations[key] = function (...args) {
226
- pauseTracking();
227
- const res = method.apply(this, args);
228
- resetTracking();
229
- return res;
230
- };
231
- });
232
+ };
233
+ });
234
+ return instrumentations;
235
+ }
232
236
  function createGetter(isReadonly = false, shallow = false) {
233
237
  return function get(target, key, receiver) {
234
238
  if (key === "__v_isReactive" /* IS_REACTIVE */) {
@@ -347,14 +351,14 @@ const readonlyHandlers = {
347
351
  return true;
348
352
  }
349
353
  };
350
- const shallowReactiveHandlers = shared.extend({}, mutableHandlers, {
354
+ const shallowReactiveHandlers = /*#__PURE__*/ shared.extend({}, mutableHandlers, {
351
355
  get: shallowGet,
352
356
  set: shallowSet
353
357
  });
354
358
  // Props handlers are special in the sense that it should not unwrap top-level
355
359
  // refs (in order to allow refs to be explicitly passed down), but should
356
360
  // retain the reactivity of the normal readonly object.
357
- const shallowReadonlyHandlers = shared.extend({}, readonlyHandlers, {
361
+ const shallowReadonlyHandlers = /*#__PURE__*/ shared.extend({}, readonlyHandlers, {
358
362
  get: shallowReadonlyGet
359
363
  });
360
364
 
@@ -524,73 +528,82 @@ function createReadonlyMethod(type) {
524
528
  return type === "delete" /* DELETE */ ? false : this;
525
529
  };
526
530
  }
527
- const mutableInstrumentations = {
528
- get(key) {
529
- return get$1(this, key);
530
- },
531
- get size() {
532
- return size(this);
533
- },
534
- has: has$1,
535
- add,
536
- set: set$1,
537
- delete: deleteEntry,
538
- clear,
539
- forEach: createForEach(false, false)
540
- };
541
- const shallowInstrumentations = {
542
- get(key) {
543
- return get$1(this, key, false, true);
544
- },
545
- get size() {
546
- return size(this);
547
- },
548
- has: has$1,
549
- add,
550
- set: set$1,
551
- delete: deleteEntry,
552
- clear,
553
- forEach: createForEach(false, true)
554
- };
555
- const readonlyInstrumentations = {
556
- get(key) {
557
- return get$1(this, key, true);
558
- },
559
- get size() {
560
- return size(this, true);
561
- },
562
- has(key) {
563
- return has$1.call(this, key, true);
564
- },
565
- add: createReadonlyMethod("add" /* ADD */),
566
- set: createReadonlyMethod("set" /* SET */),
567
- delete: createReadonlyMethod("delete" /* DELETE */),
568
- clear: createReadonlyMethod("clear" /* CLEAR */),
569
- forEach: createForEach(true, false)
570
- };
571
- const shallowReadonlyInstrumentations = {
572
- get(key) {
573
- return get$1(this, key, true, true);
574
- },
575
- get size() {
576
- return size(this, true);
577
- },
578
- has(key) {
579
- return has$1.call(this, key, true);
580
- },
581
- add: createReadonlyMethod("add" /* ADD */),
582
- set: createReadonlyMethod("set" /* SET */),
583
- delete: createReadonlyMethod("delete" /* DELETE */),
584
- clear: createReadonlyMethod("clear" /* CLEAR */),
585
- forEach: createForEach(true, true)
586
- };
587
- const iteratorMethods = ['keys', 'values', 'entries', Symbol.iterator];
588
- iteratorMethods.forEach(method => {
589
- mutableInstrumentations[method] = createIterableMethod(method, false, false);
590
- readonlyInstrumentations[method] = createIterableMethod(method, true, false);
591
- shallowInstrumentations[method] = createIterableMethod(method, false, true);
592
- shallowReadonlyInstrumentations[method] = createIterableMethod(method, true, true);
593
- });
531
+ function createInstrumentations() {
532
+ const mutableInstrumentations = {
533
+ get(key) {
534
+ return get$1(this, key);
535
+ },
536
+ get size() {
537
+ return size(this);
538
+ },
539
+ has: has$1,
540
+ add,
541
+ set: set$1,
542
+ delete: deleteEntry,
543
+ clear,
544
+ forEach: createForEach(false, false)
545
+ };
546
+ const shallowInstrumentations = {
547
+ get(key) {
548
+ return get$1(this, key, false, true);
549
+ },
550
+ get size() {
551
+ return size(this);
552
+ },
553
+ has: has$1,
554
+ add,
555
+ set: set$1,
556
+ delete: deleteEntry,
557
+ clear,
558
+ forEach: createForEach(false, true)
559
+ };
560
+ const readonlyInstrumentations = {
561
+ get(key) {
562
+ return get$1(this, key, true);
563
+ },
564
+ get size() {
565
+ return size(this, true);
566
+ },
567
+ has(key) {
568
+ return has$1.call(this, key, true);
569
+ },
570
+ add: createReadonlyMethod("add" /* ADD */),
571
+ set: createReadonlyMethod("set" /* SET */),
572
+ delete: createReadonlyMethod("delete" /* DELETE */),
573
+ clear: createReadonlyMethod("clear" /* CLEAR */),
574
+ forEach: createForEach(true, false)
575
+ };
576
+ const shallowReadonlyInstrumentations = {
577
+ get(key) {
578
+ return get$1(this, key, true, true);
579
+ },
580
+ get size() {
581
+ return size(this, true);
582
+ },
583
+ has(key) {
584
+ return has$1.call(this, key, true);
585
+ },
586
+ add: createReadonlyMethod("add" /* ADD */),
587
+ set: createReadonlyMethod("set" /* SET */),
588
+ delete: createReadonlyMethod("delete" /* DELETE */),
589
+ clear: createReadonlyMethod("clear" /* CLEAR */),
590
+ forEach: createForEach(true, true)
591
+ };
592
+ const iteratorMethods = ['keys', 'values', 'entries', Symbol.iterator];
593
+ iteratorMethods.forEach(method => {
594
+ mutableInstrumentations[method] = createIterableMethod(method, false, false);
595
+ readonlyInstrumentations[method] = createIterableMethod(method, true, false);
596
+ shallowInstrumentations[method] = createIterableMethod(method, false, true);
597
+ shallowReadonlyInstrumentations[method] = createIterableMethod(method, true, true);
598
+ });
599
+ return [
600
+ mutableInstrumentations,
601
+ readonlyInstrumentations,
602
+ shallowInstrumentations,
603
+ shallowReadonlyInstrumentations
604
+ ];
605
+ }
606
+ const [mutableInstrumentations, readonlyInstrumentations, shallowInstrumentations, shallowReadonlyInstrumentations] = /* #__PURE__*/ createInstrumentations();
594
607
  function createInstrumentationGetter(isReadonly, shallow) {
595
608
  const instrumentations = shallow
596
609
  ? isReadonly
@@ -615,16 +628,16 @@ function createInstrumentationGetter(isReadonly, shallow) {
615
628
  };
616
629
  }
617
630
  const mutableCollectionHandlers = {
618
- get: createInstrumentationGetter(false, false)
631
+ get: /*#__PURE__*/ createInstrumentationGetter(false, false)
619
632
  };
620
633
  const shallowCollectionHandlers = {
621
- get: createInstrumentationGetter(false, true)
634
+ get: /*#__PURE__*/ createInstrumentationGetter(false, true)
622
635
  };
623
636
  const readonlyCollectionHandlers = {
624
- get: createInstrumentationGetter(true, false)
637
+ get: /*#__PURE__*/ createInstrumentationGetter(true, false)
625
638
  };
626
639
  const shallowReadonlyCollectionHandlers = {
627
- get: createInstrumentationGetter(true, true)
640
+ get: /*#__PURE__*/ createInstrumentationGetter(true, true)
628
641
  };
629
642
  function checkIdentityKeys(target, has, key) {
630
643
  const rawKey = toRaw(key);
@@ -750,7 +763,7 @@ function shallowRef(value) {
750
763
  return createRef(value, true);
751
764
  }
752
765
  class RefImpl {
753
- constructor(_rawValue, _shallow = false) {
766
+ constructor(_rawValue, _shallow) {
754
767
  this._rawValue = _rawValue;
755
768
  this._shallow = _shallow;
756
769
  this.__v_isRef = true;
@@ -182,34 +182,38 @@ const get = /*#__PURE__*/ createGetter();
182
182
  const shallowGet = /*#__PURE__*/ createGetter(false, true);
183
183
  const readonlyGet = /*#__PURE__*/ createGetter(true);
184
184
  const shallowReadonlyGet = /*#__PURE__*/ createGetter(true, true);
185
- const arrayInstrumentations = {};
186
- ['includes', 'indexOf', 'lastIndexOf'].forEach(key => {
187
- const method = Array.prototype[key];
188
- arrayInstrumentations[key] = function (...args) {
189
- const arr = toRaw(this);
190
- for (let i = 0, l = this.length; i < l; i++) {
191
- track(arr, "get" /* GET */, i + '');
192
- }
193
- // we run the method using the original args first (which may be reactive)
194
- const res = method.apply(arr, args);
195
- if (res === -1 || res === false) {
196
- // if that didn't work, run it again using raw values.
197
- return method.apply(arr, args.map(toRaw));
198
- }
199
- else {
185
+ const arrayInstrumentations = /*#__PURE__*/ createArrayInstrumentations();
186
+ function createArrayInstrumentations() {
187
+ const instrumentations = {};
188
+ ['includes', 'indexOf', 'lastIndexOf'].forEach(key => {
189
+ const method = Array.prototype[key];
190
+ instrumentations[key] = function (...args) {
191
+ const arr = toRaw(this);
192
+ for (let i = 0, l = this.length; i < l; i++) {
193
+ track(arr, "get" /* GET */, i + '');
194
+ }
195
+ // we run the method using the original args first (which may be reactive)
196
+ const res = method.apply(arr, args);
197
+ if (res === -1 || res === false) {
198
+ // if that didn't work, run it again using raw values.
199
+ return method.apply(arr, args.map(toRaw));
200
+ }
201
+ else {
202
+ return res;
203
+ }
204
+ };
205
+ });
206
+ ['push', 'pop', 'shift', 'unshift', 'splice'].forEach(key => {
207
+ const method = Array.prototype[key];
208
+ instrumentations[key] = function (...args) {
209
+ pauseTracking();
210
+ const res = method.apply(this, args);
211
+ resetTracking();
200
212
  return res;
201
- }
202
- };
203
- });
204
- ['push', 'pop', 'shift', 'unshift', 'splice'].forEach(key => {
205
- const method = Array.prototype[key];
206
- arrayInstrumentations[key] = function (...args) {
207
- pauseTracking();
208
- const res = method.apply(this, args);
209
- resetTracking();
210
- return res;
211
- };
212
- });
213
+ };
214
+ });
215
+ return instrumentations;
216
+ }
213
217
  function createGetter(isReadonly = false, shallow = false) {
214
218
  return function get(target, key, receiver) {
215
219
  if (key === "__v_isReactive" /* IS_REACTIVE */) {
@@ -322,14 +326,14 @@ const readonlyHandlers = {
322
326
  return true;
323
327
  }
324
328
  };
325
- const shallowReactiveHandlers = shared.extend({}, mutableHandlers, {
329
+ const shallowReactiveHandlers = /*#__PURE__*/ shared.extend({}, mutableHandlers, {
326
330
  get: shallowGet,
327
331
  set: shallowSet
328
332
  });
329
333
  // Props handlers are special in the sense that it should not unwrap top-level
330
334
  // refs (in order to allow refs to be explicitly passed down), but should
331
335
  // retain the reactivity of the normal readonly object.
332
- const shallowReadonlyHandlers = shared.extend({}, readonlyHandlers, {
336
+ const shallowReadonlyHandlers = /*#__PURE__*/ shared.extend({}, readonlyHandlers, {
333
337
  get: shallowReadonlyGet
334
338
  });
335
339
 
@@ -485,73 +489,82 @@ function createReadonlyMethod(type) {
485
489
  return type === "delete" /* DELETE */ ? false : this;
486
490
  };
487
491
  }
488
- const mutableInstrumentations = {
489
- get(key) {
490
- return get$1(this, key);
491
- },
492
- get size() {
493
- return size(this);
494
- },
495
- has: has$1,
496
- add,
497
- set: set$1,
498
- delete: deleteEntry,
499
- clear,
500
- forEach: createForEach(false, false)
501
- };
502
- const shallowInstrumentations = {
503
- get(key) {
504
- return get$1(this, key, false, true);
505
- },
506
- get size() {
507
- return size(this);
508
- },
509
- has: has$1,
510
- add,
511
- set: set$1,
512
- delete: deleteEntry,
513
- clear,
514
- forEach: createForEach(false, true)
515
- };
516
- const readonlyInstrumentations = {
517
- get(key) {
518
- return get$1(this, key, true);
519
- },
520
- get size() {
521
- return size(this, true);
522
- },
523
- has(key) {
524
- return has$1.call(this, key, true);
525
- },
526
- add: createReadonlyMethod("add" /* ADD */),
527
- set: createReadonlyMethod("set" /* SET */),
528
- delete: createReadonlyMethod("delete" /* DELETE */),
529
- clear: createReadonlyMethod("clear" /* CLEAR */),
530
- forEach: createForEach(true, false)
531
- };
532
- const shallowReadonlyInstrumentations = {
533
- get(key) {
534
- return get$1(this, key, true, true);
535
- },
536
- get size() {
537
- return size(this, true);
538
- },
539
- has(key) {
540
- return has$1.call(this, key, true);
541
- },
542
- add: createReadonlyMethod("add" /* ADD */),
543
- set: createReadonlyMethod("set" /* SET */),
544
- delete: createReadonlyMethod("delete" /* DELETE */),
545
- clear: createReadonlyMethod("clear" /* CLEAR */),
546
- forEach: createForEach(true, true)
547
- };
548
- const iteratorMethods = ['keys', 'values', 'entries', Symbol.iterator];
549
- iteratorMethods.forEach(method => {
550
- mutableInstrumentations[method] = createIterableMethod(method, false, false);
551
- readonlyInstrumentations[method] = createIterableMethod(method, true, false);
552
- shallowInstrumentations[method] = createIterableMethod(method, false, true);
553
- shallowReadonlyInstrumentations[method] = createIterableMethod(method, true, true);
554
- });
492
+ function createInstrumentations() {
493
+ const mutableInstrumentations = {
494
+ get(key) {
495
+ return get$1(this, key);
496
+ },
497
+ get size() {
498
+ return size(this);
499
+ },
500
+ has: has$1,
501
+ add,
502
+ set: set$1,
503
+ delete: deleteEntry,
504
+ clear,
505
+ forEach: createForEach(false, false)
506
+ };
507
+ const shallowInstrumentations = {
508
+ get(key) {
509
+ return get$1(this, key, false, true);
510
+ },
511
+ get size() {
512
+ return size(this);
513
+ },
514
+ has: has$1,
515
+ add,
516
+ set: set$1,
517
+ delete: deleteEntry,
518
+ clear,
519
+ forEach: createForEach(false, true)
520
+ };
521
+ const readonlyInstrumentations = {
522
+ get(key) {
523
+ return get$1(this, key, true);
524
+ },
525
+ get size() {
526
+ return size(this, true);
527
+ },
528
+ has(key) {
529
+ return has$1.call(this, key, true);
530
+ },
531
+ add: createReadonlyMethod("add" /* ADD */),
532
+ set: createReadonlyMethod("set" /* SET */),
533
+ delete: createReadonlyMethod("delete" /* DELETE */),
534
+ clear: createReadonlyMethod("clear" /* CLEAR */),
535
+ forEach: createForEach(true, false)
536
+ };
537
+ const shallowReadonlyInstrumentations = {
538
+ get(key) {
539
+ return get$1(this, key, true, true);
540
+ },
541
+ get size() {
542
+ return size(this, true);
543
+ },
544
+ has(key) {
545
+ return has$1.call(this, key, true);
546
+ },
547
+ add: createReadonlyMethod("add" /* ADD */),
548
+ set: createReadonlyMethod("set" /* SET */),
549
+ delete: createReadonlyMethod("delete" /* DELETE */),
550
+ clear: createReadonlyMethod("clear" /* CLEAR */),
551
+ forEach: createForEach(true, true)
552
+ };
553
+ const iteratorMethods = ['keys', 'values', 'entries', Symbol.iterator];
554
+ iteratorMethods.forEach(method => {
555
+ mutableInstrumentations[method] = createIterableMethod(method, false, false);
556
+ readonlyInstrumentations[method] = createIterableMethod(method, true, false);
557
+ shallowInstrumentations[method] = createIterableMethod(method, false, true);
558
+ shallowReadonlyInstrumentations[method] = createIterableMethod(method, true, true);
559
+ });
560
+ return [
561
+ mutableInstrumentations,
562
+ readonlyInstrumentations,
563
+ shallowInstrumentations,
564
+ shallowReadonlyInstrumentations
565
+ ];
566
+ }
567
+ const [mutableInstrumentations, readonlyInstrumentations, shallowInstrumentations, shallowReadonlyInstrumentations] = /* #__PURE__*/ createInstrumentations();
555
568
  function createInstrumentationGetter(isReadonly, shallow) {
556
569
  const instrumentations = shallow
557
570
  ? isReadonly
@@ -576,16 +589,16 @@ function createInstrumentationGetter(isReadonly, shallow) {
576
589
  };
577
590
  }
578
591
  const mutableCollectionHandlers = {
579
- get: createInstrumentationGetter(false, false)
592
+ get: /*#__PURE__*/ createInstrumentationGetter(false, false)
580
593
  };
581
594
  const shallowCollectionHandlers = {
582
- get: createInstrumentationGetter(false, true)
595
+ get: /*#__PURE__*/ createInstrumentationGetter(false, true)
583
596
  };
584
597
  const readonlyCollectionHandlers = {
585
- get: createInstrumentationGetter(true, false)
598
+ get: /*#__PURE__*/ createInstrumentationGetter(true, false)
586
599
  };
587
600
  const shallowReadonlyCollectionHandlers = {
588
- get: createInstrumentationGetter(true, true)
601
+ get: /*#__PURE__*/ createInstrumentationGetter(true, true)
589
602
  };
590
603
 
591
604
  const reactiveMap = new WeakMap();
@@ -697,7 +710,7 @@ function shallowRef(value) {
697
710
  return createRef(value, true);
698
711
  }
699
712
  class RefImpl {
700
- constructor(_rawValue, _shallow = false) {
713
+ constructor(_rawValue, _shallow) {
701
714
  this._rawValue = _rawValue;
702
715
  this._shallow = _shallow;
703
716
  this.__v_isRef = true;
@@ -295,7 +295,7 @@ export declare const enum TriggerOpTypes {
295
295
 
296
296
  export declare function triggerRef(ref: Ref): void;
297
297
 
298
- export declare function unref<T>(ref: T): T extends Ref<infer V> ? V : T;
298
+ export declare function unref<T>(ref: T | Ref<T>): T;
299
299
 
300
300
  export declare type UnwrapNestedRefs<T> = T extends Ref ? T : UnwrapRef<T>;
301
301