@vue/reactivity 3.5.0-alpha.1 → 3.5.0-alpha.3

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @vue/reactivity v3.5.0-alpha.1
2
+ * @vue/reactivity v3.5.0-alpha.3
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
@@ -246,16 +246,14 @@ function endBatch() {
246
246
  try {
247
247
  e.trigger();
248
248
  } catch (err) {
249
- if (!error)
250
- error = err;
249
+ if (!error) error = err;
251
250
  }
252
251
  }
253
252
  e = next;
254
253
  }
255
254
  }
256
255
  batchDepth--;
257
- if (error)
258
- throw error;
256
+ if (error) throw error;
259
257
  }
260
258
  function prepareDeps(sub) {
261
259
  for (let link = sub.deps; link; link = link.nextDep) {
@@ -269,8 +267,7 @@ function cleanupDeps(sub) {
269
267
  let tail = sub.depsTail;
270
268
  for (let link = tail; link; link = link.prevDep) {
271
269
  if (link.version === -1) {
272
- if (link === tail)
273
- tail = link.prevDep;
270
+ if (link === tail) tail = link.prevDep;
274
271
  removeSub(link);
275
272
  removeDep(link);
276
273
  } else {
@@ -534,8 +531,7 @@ function addSub(link) {
534
531
  const currentTail = link.dep.subs;
535
532
  if (currentTail !== link) {
536
533
  link.prevSub = currentTail;
537
- if (currentTail)
538
- currentTail.nextSub = link;
534
+ if (currentTail) currentTail.nextSub = link;
539
535
  }
540
536
  if (link.dep.subsHead === void 0) {
541
537
  link.dep.subsHead = link;
@@ -641,8 +637,7 @@ function getDepFromReactive(object, key) {
641
637
 
642
638
  function reactiveReadArray(array) {
643
639
  const raw = toRaw(array);
644
- if (raw === array)
645
- return raw;
640
+ if (raw === array) return raw;
646
641
  track(raw, "iterate", ARRAY_ITERATE_KEY);
647
642
  return isShallow(array) ? raw : raw.map(toReactive);
648
643
  }
@@ -816,8 +811,7 @@ const builtInSymbols = new Set(
816
811
  /* @__PURE__ */ Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller").map((key) => Symbol[key]).filter(shared.isSymbol)
817
812
  );
818
813
  function hasOwnProperty(key) {
819
- if (!shared.isSymbol(key))
820
- key = String(key);
814
+ if (!shared.isSymbol(key)) key = String(key);
821
815
  const obj = toRaw(this);
822
816
  track(obj, "has", key);
823
817
  return obj.hasOwnProperty(key);
@@ -968,18 +962,18 @@ const shallowReadonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler(true
968
962
 
969
963
  const toShallow = (value) => value;
970
964
  const getProto = (v) => Reflect.getPrototypeOf(v);
971
- function get(target, key, isReadonly = false, isShallow = false) {
965
+ function get(target, key, isReadonly2 = false, isShallow2 = false) {
972
966
  target = target["__v_raw"];
973
967
  const rawTarget = toRaw(target);
974
968
  const rawKey = toRaw(key);
975
- if (!isReadonly) {
969
+ if (!isReadonly2) {
976
970
  if (shared.hasChanged(key, rawKey)) {
977
971
  track(rawTarget, "get", key);
978
972
  }
979
973
  track(rawTarget, "get", rawKey);
980
974
  }
981
975
  const { has: has2 } = getProto(rawTarget);
982
- const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
976
+ const wrap = isShallow2 ? toShallow : isReadonly2 ? toReadonly : toReactive;
983
977
  if (has2.call(rawTarget, key)) {
984
978
  return wrap(target.get(key));
985
979
  } else if (has2.call(rawTarget, rawKey)) {
@@ -988,11 +982,11 @@ function get(target, key, isReadonly = false, isShallow = false) {
988
982
  target.get(key);
989
983
  }
990
984
  }
991
- function has(key, isReadonly = false) {
985
+ function has(key, isReadonly2 = false) {
992
986
  const target = this["__v_raw"];
993
987
  const rawTarget = toRaw(target);
994
988
  const rawKey = toRaw(key);
995
- if (!isReadonly) {
989
+ if (!isReadonly2) {
996
990
  if (shared.hasChanged(key, rawKey)) {
997
991
  track(rawTarget, "has", key);
998
992
  }
@@ -1000,13 +994,15 @@ function has(key, isReadonly = false) {
1000
994
  }
1001
995
  return key === rawKey ? target.has(key) : target.has(key) || target.has(rawKey);
1002
996
  }
1003
- function size(target, isReadonly = false) {
997
+ function size(target, isReadonly2 = false) {
1004
998
  target = target["__v_raw"];
1005
- !isReadonly && track(toRaw(target), "iterate", ITERATE_KEY);
999
+ !isReadonly2 && track(toRaw(target), "iterate", ITERATE_KEY);
1006
1000
  return Reflect.get(target, "size", target);
1007
1001
  }
1008
- function add(value) {
1009
- value = toRaw(value);
1002
+ function add(value, _isShallow = false) {
1003
+ if (!_isShallow && !isShallow(value) && !isReadonly(value)) {
1004
+ value = toRaw(value);
1005
+ }
1010
1006
  const target = toRaw(this);
1011
1007
  const proto = getProto(target);
1012
1008
  const hadKey = proto.has.call(target, value);
@@ -1016,8 +1012,10 @@ function add(value) {
1016
1012
  }
1017
1013
  return this;
1018
1014
  }
1019
- function set(key, value) {
1020
- value = toRaw(value);
1015
+ function set(key, value, _isShallow = false) {
1016
+ if (!_isShallow && !isShallow(value) && !isReadonly(value)) {
1017
+ value = toRaw(value);
1018
+ }
1021
1019
  const target = toRaw(this);
1022
1020
  const { has: has2, get: get2 } = getProto(target);
1023
1021
  let hadKey = has2.call(target, key);
@@ -1063,19 +1061,19 @@ function clear() {
1063
1061
  }
1064
1062
  return result;
1065
1063
  }
1066
- function createForEach(isReadonly, isShallow) {
1064
+ function createForEach(isReadonly2, isShallow2) {
1067
1065
  return function forEach(callback, thisArg) {
1068
1066
  const observed = this;
1069
1067
  const target = observed["__v_raw"];
1070
1068
  const rawTarget = toRaw(target);
1071
- const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
1072
- !isReadonly && track(rawTarget, "iterate", ITERATE_KEY);
1069
+ const wrap = isShallow2 ? toShallow : isReadonly2 ? toReadonly : toReactive;
1070
+ !isReadonly2 && track(rawTarget, "iterate", ITERATE_KEY);
1073
1071
  return target.forEach((value, key) => {
1074
1072
  return callback.call(thisArg, wrap(value), wrap(key), observed);
1075
1073
  });
1076
1074
  };
1077
1075
  }
1078
- function createIterableMethod(method, isReadonly, isShallow) {
1076
+ function createIterableMethod(method, isReadonly2, isShallow2) {
1079
1077
  return function(...args) {
1080
1078
  const target = this["__v_raw"];
1081
1079
  const rawTarget = toRaw(target);
@@ -1083,8 +1081,8 @@ function createIterableMethod(method, isReadonly, isShallow) {
1083
1081
  const isPair = method === "entries" || method === Symbol.iterator && targetIsMap;
1084
1082
  const isKeyOnly = method === "keys" && targetIsMap;
1085
1083
  const innerIterator = target[method](...args);
1086
- const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
1087
- !isReadonly && track(
1084
+ const wrap = isShallow2 ? toShallow : isReadonly2 ? toReadonly : toReactive;
1085
+ !isReadonly2 && track(
1088
1086
  rawTarget,
1089
1087
  "iterate",
1090
1088
  isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY
@@ -1140,8 +1138,12 @@ function createInstrumentations() {
1140
1138
  return size(this);
1141
1139
  },
1142
1140
  has,
1143
- add,
1144
- set,
1141
+ add(value) {
1142
+ return add.call(this, value, true);
1143
+ },
1144
+ set(key, value) {
1145
+ return set.call(this, key, value, true);
1146
+ },
1145
1147
  delete: deleteEntry,
1146
1148
  clear,
1147
1149
  forEach: createForEach(false, true)
@@ -1207,13 +1209,13 @@ const [
1207
1209
  shallowInstrumentations,
1208
1210
  shallowReadonlyInstrumentations
1209
1211
  ] = /* @__PURE__ */ createInstrumentations();
1210
- function createInstrumentationGetter(isReadonly, shallow) {
1211
- const instrumentations = shallow ? isReadonly ? shallowReadonlyInstrumentations : shallowInstrumentations : isReadonly ? readonlyInstrumentations : mutableInstrumentations;
1212
+ function createInstrumentationGetter(isReadonly2, shallow) {
1213
+ const instrumentations = shallow ? isReadonly2 ? shallowReadonlyInstrumentations : shallowInstrumentations : isReadonly2 ? readonlyInstrumentations : mutableInstrumentations;
1212
1214
  return (target, key, receiver) => {
1213
1215
  if (key === "__v_isReactive") {
1214
- return !isReadonly;
1216
+ return !isReadonly2;
1215
1217
  } else if (key === "__v_isReadonly") {
1216
- return isReadonly;
1218
+ return isReadonly2;
1217
1219
  } else if (key === "__v_raw") {
1218
1220
  return target;
1219
1221
  }
@@ -1309,7 +1311,11 @@ function shallowReadonly(target) {
1309
1311
  function createReactiveObject(target, isReadonly2, baseHandlers, collectionHandlers, proxyMap) {
1310
1312
  if (!shared.isObject(target)) {
1311
1313
  {
1312
- warn(`value cannot be made reactive: ${String(target)}`);
1314
+ warn(
1315
+ `value cannot be made ${isReadonly2 ? "readonly" : "reactive"}: ${String(
1316
+ target
1317
+ )}`
1318
+ );
1313
1319
  }
1314
1320
  return target;
1315
1321
  }
@@ -1360,7 +1366,7 @@ const toReactive = (value) => shared.isObject(value) ? reactive(value) : value;
1360
1366
  const toReadonly = (value) => shared.isObject(value) ? readonly(value) : value;
1361
1367
 
1362
1368
  function isRef(r) {
1363
- return r ? r.__v_isRef === true : false;
1369
+ return r ? r["__v_isRef"] === true : false;
1364
1370
  }
1365
1371
  function ref(value) {
1366
1372
  return createRef(value, false);
@@ -1375,12 +1381,13 @@ function createRef(rawValue, shallow) {
1375
1381
  return new RefImpl(rawValue, shallow);
1376
1382
  }
1377
1383
  class RefImpl {
1378
- constructor(value, __v_isShallow) {
1379
- this.__v_isShallow = __v_isShallow;
1384
+ constructor(value, isShallow2) {
1380
1385
  this.dep = new Dep();
1381
- this.__v_isRef = true;
1382
- this._rawValue = __v_isShallow ? value : toRaw(value);
1383
- this._value = __v_isShallow ? value : toReactive(value);
1386
+ this["__v_isRef"] = true;
1387
+ this["__v_isShallow"] = false;
1388
+ this._rawValue = isShallow2 ? value : toRaw(value);
1389
+ this._value = isShallow2 ? value : toReactive(value);
1390
+ this["__v_isShallow"] = isShallow2;
1384
1391
  }
1385
1392
  get value() {
1386
1393
  {
@@ -1394,7 +1401,7 @@ class RefImpl {
1394
1401
  }
1395
1402
  set value(newValue) {
1396
1403
  const oldValue = this._rawValue;
1397
- const useDirectValue = this.__v_isShallow || isShallow(newValue) || isReadonly(newValue);
1404
+ const useDirectValue = this["__v_isShallow"] || isShallow(newValue) || isReadonly(newValue);
1398
1405
  newValue = useDirectValue ? newValue : toRaw(newValue);
1399
1406
  if (shared.hasChanged(newValue, oldValue)) {
1400
1407
  this._rawValue = newValue;
@@ -1444,7 +1451,7 @@ function proxyRefs(objectWithRefs) {
1444
1451
  }
1445
1452
  class CustomRefImpl {
1446
1453
  constructor(factory) {
1447
- this.__v_isRef = true;
1454
+ this["__v_isRef"] = true;
1448
1455
  const dep = this.dep = new Dep();
1449
1456
  const { get, set } = factory(dep.track.bind(dep), dep.trigger.bind(dep));
1450
1457
  this._get = get;
@@ -1475,7 +1482,7 @@ class ObjectRefImpl {
1475
1482
  this._object = _object;
1476
1483
  this._key = _key;
1477
1484
  this._defaultValue = _defaultValue;
1478
- this.__v_isRef = true;
1485
+ this["__v_isRef"] = true;
1479
1486
  }
1480
1487
  get value() {
1481
1488
  const val = this._object[this._key];
@@ -1491,8 +1498,8 @@ class ObjectRefImpl {
1491
1498
  class GetterRefImpl {
1492
1499
  constructor(_getter) {
1493
1500
  this._getter = _getter;
1494
- this.__v_isRef = true;
1495
- this.__v_isReadonly = true;
1501
+ this["__v_isRef"] = true;
1502
+ this["__v_isReadonly"] = true;
1496
1503
  }
1497
1504
  get value() {
1498
1505
  return this._getter();
@@ -1529,7 +1536,7 @@ class ComputedRefImpl {
1529
1536
  /**
1530
1537
  * @internal
1531
1538
  */
1532
- this.__v_isRef = true;
1539
+ this["__v_isRef"] = true;
1533
1540
  // A computed is also a subscriber that tracks other deps
1534
1541
  /**
1535
1542
  * @internal
@@ -1549,7 +1556,7 @@ class ComputedRefImpl {
1549
1556
  this.globalVersion = globalVersion - 1;
1550
1557
  // for backwards compat
1551
1558
  this.effect = this;
1552
- this.__v_isReadonly = !setter;
1559
+ this["__v_isReadonly"] = !setter;
1553
1560
  this.isSSR = isSSR;
1554
1561
  }
1555
1562
  /**
@@ -1614,7 +1621,8 @@ const ReactiveFlags = {
1614
1621
  "IS_REACTIVE": "__v_isReactive",
1615
1622
  "IS_READONLY": "__v_isReadonly",
1616
1623
  "IS_SHALLOW": "__v_isShallow",
1617
- "RAW": "__v_raw"
1624
+ "RAW": "__v_raw",
1625
+ "IS_REF": "__v_isRef"
1618
1626
  };
1619
1627
 
1620
1628
  exports.ARRAY_ITERATE_KEY = ARRAY_ITERATE_KEY;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @vue/reactivity v3.5.0-alpha.1
2
+ * @vue/reactivity v3.5.0-alpha.3
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
@@ -231,16 +231,14 @@ function endBatch() {
231
231
  try {
232
232
  e.trigger();
233
233
  } catch (err) {
234
- if (!error)
235
- error = err;
234
+ if (!error) error = err;
236
235
  }
237
236
  }
238
237
  e = next;
239
238
  }
240
239
  }
241
240
  batchDepth--;
242
- if (error)
243
- throw error;
241
+ if (error) throw error;
244
242
  }
245
243
  function prepareDeps(sub) {
246
244
  for (let link = sub.deps; link; link = link.nextDep) {
@@ -254,8 +252,7 @@ function cleanupDeps(sub) {
254
252
  let tail = sub.depsTail;
255
253
  for (let link = tail; link; link = link.prevDep) {
256
254
  if (link.version === -1) {
257
- if (link === tail)
258
- tail = link.prevDep;
255
+ if (link === tail) tail = link.prevDep;
259
256
  removeSub(link);
260
257
  removeDep(link);
261
258
  } else {
@@ -489,8 +486,7 @@ function addSub(link) {
489
486
  const currentTail = link.dep.subs;
490
487
  if (currentTail !== link) {
491
488
  link.prevSub = currentTail;
492
- if (currentTail)
493
- currentTail.nextSub = link;
489
+ if (currentTail) currentTail.nextSub = link;
494
490
  }
495
491
  link.dep.subs = link;
496
492
  }
@@ -582,8 +578,7 @@ function getDepFromReactive(object, key) {
582
578
 
583
579
  function reactiveReadArray(array) {
584
580
  const raw = toRaw(array);
585
- if (raw === array)
586
- return raw;
581
+ if (raw === array) return raw;
587
582
  track(raw, "iterate", ARRAY_ITERATE_KEY);
588
583
  return isShallow(array) ? raw : raw.map(toReactive);
589
584
  }
@@ -757,8 +752,7 @@ const builtInSymbols = new Set(
757
752
  /* @__PURE__ */ Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller").map((key) => Symbol[key]).filter(shared.isSymbol)
758
753
  );
759
754
  function hasOwnProperty(key) {
760
- if (!shared.isSymbol(key))
761
- key = String(key);
755
+ if (!shared.isSymbol(key)) key = String(key);
762
756
  const obj = toRaw(this);
763
757
  track(obj, "has", key);
764
758
  return obj.hasOwnProperty(key);
@@ -897,18 +891,18 @@ const shallowReadonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler(true
897
891
 
898
892
  const toShallow = (value) => value;
899
893
  const getProto = (v) => Reflect.getPrototypeOf(v);
900
- function get(target, key, isReadonly = false, isShallow = false) {
894
+ function get(target, key, isReadonly2 = false, isShallow2 = false) {
901
895
  target = target["__v_raw"];
902
896
  const rawTarget = toRaw(target);
903
897
  const rawKey = toRaw(key);
904
- if (!isReadonly) {
898
+ if (!isReadonly2) {
905
899
  if (shared.hasChanged(key, rawKey)) {
906
900
  track(rawTarget, "get", key);
907
901
  }
908
902
  track(rawTarget, "get", rawKey);
909
903
  }
910
904
  const { has: has2 } = getProto(rawTarget);
911
- const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
905
+ const wrap = isShallow2 ? toShallow : isReadonly2 ? toReadonly : toReactive;
912
906
  if (has2.call(rawTarget, key)) {
913
907
  return wrap(target.get(key));
914
908
  } else if (has2.call(rawTarget, rawKey)) {
@@ -917,11 +911,11 @@ function get(target, key, isReadonly = false, isShallow = false) {
917
911
  target.get(key);
918
912
  }
919
913
  }
920
- function has(key, isReadonly = false) {
914
+ function has(key, isReadonly2 = false) {
921
915
  const target = this["__v_raw"];
922
916
  const rawTarget = toRaw(target);
923
917
  const rawKey = toRaw(key);
924
- if (!isReadonly) {
918
+ if (!isReadonly2) {
925
919
  if (shared.hasChanged(key, rawKey)) {
926
920
  track(rawTarget, "has", key);
927
921
  }
@@ -929,13 +923,15 @@ function has(key, isReadonly = false) {
929
923
  }
930
924
  return key === rawKey ? target.has(key) : target.has(key) || target.has(rawKey);
931
925
  }
932
- function size(target, isReadonly = false) {
926
+ function size(target, isReadonly2 = false) {
933
927
  target = target["__v_raw"];
934
- !isReadonly && track(toRaw(target), "iterate", ITERATE_KEY);
928
+ !isReadonly2 && track(toRaw(target), "iterate", ITERATE_KEY);
935
929
  return Reflect.get(target, "size", target);
936
930
  }
937
- function add(value) {
938
- value = toRaw(value);
931
+ function add(value, _isShallow = false) {
932
+ if (!_isShallow && !isShallow(value) && !isReadonly(value)) {
933
+ value = toRaw(value);
934
+ }
939
935
  const target = toRaw(this);
940
936
  const proto = getProto(target);
941
937
  const hadKey = proto.has.call(target, value);
@@ -945,8 +941,10 @@ function add(value) {
945
941
  }
946
942
  return this;
947
943
  }
948
- function set(key, value) {
949
- value = toRaw(value);
944
+ function set(key, value, _isShallow = false) {
945
+ if (!_isShallow && !isShallow(value) && !isReadonly(value)) {
946
+ value = toRaw(value);
947
+ }
950
948
  const target = toRaw(this);
951
949
  const { has: has2, get: get2 } = getProto(target);
952
950
  let hadKey = has2.call(target, key);
@@ -987,19 +985,19 @@ function clear() {
987
985
  }
988
986
  return result;
989
987
  }
990
- function createForEach(isReadonly, isShallow) {
988
+ function createForEach(isReadonly2, isShallow2) {
991
989
  return function forEach(callback, thisArg) {
992
990
  const observed = this;
993
991
  const target = observed["__v_raw"];
994
992
  const rawTarget = toRaw(target);
995
- const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
996
- !isReadonly && track(rawTarget, "iterate", ITERATE_KEY);
993
+ const wrap = isShallow2 ? toShallow : isReadonly2 ? toReadonly : toReactive;
994
+ !isReadonly2 && track(rawTarget, "iterate", ITERATE_KEY);
997
995
  return target.forEach((value, key) => {
998
996
  return callback.call(thisArg, wrap(value), wrap(key), observed);
999
997
  });
1000
998
  };
1001
999
  }
1002
- function createIterableMethod(method, isReadonly, isShallow) {
1000
+ function createIterableMethod(method, isReadonly2, isShallow2) {
1003
1001
  return function(...args) {
1004
1002
  const target = this["__v_raw"];
1005
1003
  const rawTarget = toRaw(target);
@@ -1007,8 +1005,8 @@ function createIterableMethod(method, isReadonly, isShallow) {
1007
1005
  const isPair = method === "entries" || method === Symbol.iterator && targetIsMap;
1008
1006
  const isKeyOnly = method === "keys" && targetIsMap;
1009
1007
  const innerIterator = target[method](...args);
1010
- const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
1011
- !isReadonly && track(
1008
+ const wrap = isShallow2 ? toShallow : isReadonly2 ? toReadonly : toReactive;
1009
+ !isReadonly2 && track(
1012
1010
  rawTarget,
1013
1011
  "iterate",
1014
1012
  isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY
@@ -1057,8 +1055,12 @@ function createInstrumentations() {
1057
1055
  return size(this);
1058
1056
  },
1059
1057
  has,
1060
- add,
1061
- set,
1058
+ add(value) {
1059
+ return add.call(this, value, true);
1060
+ },
1061
+ set(key, value) {
1062
+ return set.call(this, key, value, true);
1063
+ },
1062
1064
  delete: deleteEntry,
1063
1065
  clear,
1064
1066
  forEach: createForEach(false, true)
@@ -1124,13 +1126,13 @@ const [
1124
1126
  shallowInstrumentations,
1125
1127
  shallowReadonlyInstrumentations
1126
1128
  ] = /* @__PURE__ */ createInstrumentations();
1127
- function createInstrumentationGetter(isReadonly, shallow) {
1128
- const instrumentations = shallow ? isReadonly ? shallowReadonlyInstrumentations : shallowInstrumentations : isReadonly ? readonlyInstrumentations : mutableInstrumentations;
1129
+ function createInstrumentationGetter(isReadonly2, shallow) {
1130
+ const instrumentations = shallow ? isReadonly2 ? shallowReadonlyInstrumentations : shallowInstrumentations : isReadonly2 ? readonlyInstrumentations : mutableInstrumentations;
1129
1131
  return (target, key, receiver) => {
1130
1132
  if (key === "__v_isReactive") {
1131
- return !isReadonly;
1133
+ return !isReadonly2;
1132
1134
  } else if (key === "__v_isReadonly") {
1133
- return isReadonly;
1135
+ return isReadonly2;
1134
1136
  } else if (key === "__v_raw") {
1135
1137
  return target;
1136
1138
  }
@@ -1265,7 +1267,7 @@ const toReactive = (value) => shared.isObject(value) ? reactive(value) : value;
1265
1267
  const toReadonly = (value) => shared.isObject(value) ? readonly(value) : value;
1266
1268
 
1267
1269
  function isRef(r) {
1268
- return r ? r.__v_isRef === true : false;
1270
+ return r ? r["__v_isRef"] === true : false;
1269
1271
  }
1270
1272
  function ref(value) {
1271
1273
  return createRef(value, false);
@@ -1280,12 +1282,13 @@ function createRef(rawValue, shallow) {
1280
1282
  return new RefImpl(rawValue, shallow);
1281
1283
  }
1282
1284
  class RefImpl {
1283
- constructor(value, __v_isShallow) {
1284
- this.__v_isShallow = __v_isShallow;
1285
+ constructor(value, isShallow2) {
1285
1286
  this.dep = new Dep();
1286
- this.__v_isRef = true;
1287
- this._rawValue = __v_isShallow ? value : toRaw(value);
1288
- this._value = __v_isShallow ? value : toReactive(value);
1287
+ this["__v_isRef"] = true;
1288
+ this["__v_isShallow"] = false;
1289
+ this._rawValue = isShallow2 ? value : toRaw(value);
1290
+ this._value = isShallow2 ? value : toReactive(value);
1291
+ this["__v_isShallow"] = isShallow2;
1289
1292
  }
1290
1293
  get value() {
1291
1294
  {
@@ -1295,7 +1298,7 @@ class RefImpl {
1295
1298
  }
1296
1299
  set value(newValue) {
1297
1300
  const oldValue = this._rawValue;
1298
- const useDirectValue = this.__v_isShallow || isShallow(newValue) || isReadonly(newValue);
1301
+ const useDirectValue = this["__v_isShallow"] || isShallow(newValue) || isReadonly(newValue);
1299
1302
  newValue = useDirectValue ? newValue : toRaw(newValue);
1300
1303
  if (shared.hasChanged(newValue, oldValue)) {
1301
1304
  this._rawValue = newValue;
@@ -1334,7 +1337,7 @@ function proxyRefs(objectWithRefs) {
1334
1337
  }
1335
1338
  class CustomRefImpl {
1336
1339
  constructor(factory) {
1337
- this.__v_isRef = true;
1340
+ this["__v_isRef"] = true;
1338
1341
  const dep = this.dep = new Dep();
1339
1342
  const { get, set } = factory(dep.track.bind(dep), dep.trigger.bind(dep));
1340
1343
  this._get = get;
@@ -1362,7 +1365,7 @@ class ObjectRefImpl {
1362
1365
  this._object = _object;
1363
1366
  this._key = _key;
1364
1367
  this._defaultValue = _defaultValue;
1365
- this.__v_isRef = true;
1368
+ this["__v_isRef"] = true;
1366
1369
  }
1367
1370
  get value() {
1368
1371
  const val = this._object[this._key];
@@ -1378,8 +1381,8 @@ class ObjectRefImpl {
1378
1381
  class GetterRefImpl {
1379
1382
  constructor(_getter) {
1380
1383
  this._getter = _getter;
1381
- this.__v_isRef = true;
1382
- this.__v_isReadonly = true;
1384
+ this["__v_isRef"] = true;
1385
+ this["__v_isReadonly"] = true;
1383
1386
  }
1384
1387
  get value() {
1385
1388
  return this._getter();
@@ -1416,7 +1419,7 @@ class ComputedRefImpl {
1416
1419
  /**
1417
1420
  * @internal
1418
1421
  */
1419
- this.__v_isRef = true;
1422
+ this["__v_isRef"] = true;
1420
1423
  // A computed is also a subscriber that tracks other deps
1421
1424
  /**
1422
1425
  * @internal
@@ -1436,7 +1439,7 @@ class ComputedRefImpl {
1436
1439
  this.globalVersion = globalVersion - 1;
1437
1440
  // for backwards compat
1438
1441
  this.effect = this;
1439
- this.__v_isReadonly = !setter;
1442
+ this["__v_isReadonly"] = !setter;
1440
1443
  this.isSSR = isSSR;
1441
1444
  }
1442
1445
  /**
@@ -1491,7 +1494,8 @@ const ReactiveFlags = {
1491
1494
  "IS_REACTIVE": "__v_isReactive",
1492
1495
  "IS_READONLY": "__v_isReadonly",
1493
1496
  "IS_SHALLOW": "__v_isShallow",
1494
- "RAW": "__v_raw"
1497
+ "RAW": "__v_raw",
1498
+ "IS_REF": "__v_isRef"
1495
1499
  };
1496
1500
 
1497
1501
  exports.ARRAY_ITERATE_KEY = ARRAY_ITERATE_KEY;
@@ -16,10 +16,16 @@ export declare enum ReactiveFlags {
16
16
  IS_REACTIVE = "__v_isReactive",
17
17
  IS_READONLY = "__v_isReadonly",
18
18
  IS_SHALLOW = "__v_isShallow",
19
- RAW = "__v_raw"
19
+ RAW = "__v_raw",
20
+ IS_REF = "__v_isRef"
20
21
  }
21
22
 
22
23
  export type UnwrapNestedRefs<T> = T extends Ref ? T : UnwrapRefSimple<T>;
24
+ declare const ReactiveMarkerSymbol: unique symbol;
25
+ export declare class ReactiveMarker {
26
+ private [ReactiveMarkerSymbol]?;
27
+ }
28
+ export type Reactive<T> = UnwrapNestedRefs<T> & (T extends readonly any[] ? ReactiveMarker : {});
23
29
  /**
24
30
  * Returns a reactive proxy of the object.
25
31
  *
@@ -35,7 +41,7 @@ export type UnwrapNestedRefs<T> = T extends Ref ? T : UnwrapRefSimple<T>;
35
41
  * @param target - The source object.
36
42
  * @see {@link https://vuejs.org/api/reactivity-core.html#reactive}
37
43
  */
38
- export declare function reactive<T extends object>(target: T): UnwrapNestedRefs<T>;
44
+ export declare function reactive<T extends object>(target: T): Reactive<T>;
39
45
  declare const ShallowReactiveMarker: unique symbol;
40
46
  export type ShallowReactive<T> = T & {
41
47
  [ShallowReactiveMarker]?: true;
@@ -493,7 +499,7 @@ export type MaybeRefOrGetter<T = any> = MaybeRef<T> | (() => T);
493
499
  * @param ref - Ref or plain value to be converted into the plain value.
494
500
  * @see {@link https://vuejs.org/api/reactivity-utilities.html#unref}
495
501
  */
496
- export declare function unref<T>(ref: MaybeRef<T> | ComputedRef<T>): T;
502
+ export declare function unref<T>(ref: MaybeRef<T> | ComputedRef<T> | ShallowRef<T>): T;
497
503
  /**
498
504
  * Normalizes values / refs / getters to values.
499
505
  * This is similar to {@link unref()}, except that it also normalizes getters.
@@ -510,13 +516,11 @@ export declare function unref<T>(ref: MaybeRef<T> | ComputedRef<T>): T;
510
516
  * @param source - A getter, an existing ref, or a non-function value.
511
517
  * @see {@link https://vuejs.org/api/reactivity-utilities.html#tovalue}
512
518
  */
513
- export declare function toValue<T>(source: MaybeRefOrGetter<T> | ComputedRef<T>): T;
519
+ export declare function toValue<T>(source: MaybeRefOrGetter<T> | ComputedRef<T> | ShallowRef<T>): T;
514
520
  /**
515
- * Returns a reactive proxy for the given object.
516
- *
517
- * If the object already is reactive, it's returned as-is. If not, a new
518
- * reactive proxy is created. Direct child properties that are refs are properly
519
- * handled, as well.
521
+ * Returns a proxy for the given object that shallowly unwraps properties that
522
+ * are refs. If the object already is reactive, it's returned as-is. If not, a
523
+ * new reactive proxy is created.
520
524
  *
521
525
  * @param objectWithRefs - Either an already-reactive object or a simple object
522
526
  * that contains refs.
@@ -593,7 +597,6 @@ export type ToRef<T> = IfAny<T, Ref<T>, [T] extends [Ref] ? T : Ref<T>>;
593
597
  export declare function toRef<T>(value: T): T extends () => infer R ? Readonly<Ref<R>> : T extends Ref ? T : Ref<UnwrapRef<T>>;
594
598
  export declare function toRef<T extends object, K extends keyof T>(object: T, key: K): ToRef<T[K]>;
595
599
  export declare function toRef<T extends object, K extends keyof T>(object: T, key: K, defaultValue: T[K]): ToRef<Exclude<T[K], undefined>>;
596
- type BaseTypes = string | number | boolean;
597
600
  /**
598
601
  * This is a special exported interface for other packages to declare
599
602
  * additional types that should bail out for ref unwrapping. For example
@@ -610,11 +613,11 @@ type BaseTypes = string | number | boolean;
610
613
  export interface RefUnwrapBailTypes {
611
614
  }
612
615
  export type ShallowUnwrapRef<T> = {
613
- [K in keyof T]: DistrubuteRef<T[K]>;
616
+ [K in keyof T]: DistributeRef<T[K]>;
614
617
  };
615
- type DistrubuteRef<T> = T extends Ref<infer V> ? V : T;
618
+ type DistributeRef<T> = T extends Ref<infer V> ? V : T;
616
619
  export type UnwrapRef<T> = T extends ShallowRef<infer V> ? V : T extends Ref<infer V> ? UnwrapRefSimple<V> : UnwrapRefSimple<T>;
617
- type UnwrapRefSimple<T> = T extends Function | BaseTypes | Ref | RefUnwrapBailTypes[keyof RefUnwrapBailTypes] | {
620
+ type UnwrapRefSimple<T> = T extends Builtin | Ref | RefUnwrapBailTypes[keyof RefUnwrapBailTypes] | {
618
621
  [RawSymbol]?: true;
619
622
  } ? T : T extends Map<infer K, infer V> ? Map<K, UnwrapRefSimple<V>> & UnwrapRef<Omit<T, keyof Map<any, any>>> : T extends WeakMap<infer K, infer V> ? WeakMap<K, UnwrapRefSimple<V>> & UnwrapRef<Omit<T, keyof WeakMap<any, any>>> : T extends Set<infer V> ? Set<UnwrapRefSimple<V>> & UnwrapRef<Omit<T, keyof Set<any>>> : T extends WeakSet<infer V> ? WeakSet<UnwrapRefSimple<V>> & UnwrapRef<Omit<T, keyof WeakSet<any>>> : T extends ReadonlyArray<any> ? {
620
623
  [K in keyof T]: UnwrapRefSimple<T[K]>;