@vue/reactivity 3.5.10 → 3.5.12

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.10
2
+ * @vue/reactivity v3.5.12
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
@@ -255,8 +255,14 @@ class ReactiveEffect {
255
255
  }
256
256
  let batchDepth = 0;
257
257
  let batchedSub;
258
- function batch(sub) {
258
+ let batchedComputed;
259
+ function batch(sub, isComputed = false) {
259
260
  sub.flags |= 8;
261
+ if (isComputed) {
262
+ sub.next = batchedComputed;
263
+ batchedComputed = sub;
264
+ return;
265
+ }
260
266
  sub.next = batchedSub;
261
267
  batchedSub = sub;
262
268
  }
@@ -267,20 +273,22 @@ function endBatch() {
267
273
  if (--batchDepth > 0) {
268
274
  return;
269
275
  }
276
+ if (batchedComputed) {
277
+ let e = batchedComputed;
278
+ batchedComputed = void 0;
279
+ while (e) {
280
+ const next = e.next;
281
+ e.next = void 0;
282
+ e.flags &= ~8;
283
+ e = next;
284
+ }
285
+ }
270
286
  let error;
271
287
  while (batchedSub) {
272
288
  let e = batchedSub;
273
- let next;
274
- while (e) {
275
- if (!(e.flags & 1)) {
276
- e.flags &= ~8;
277
- }
278
- e = e.next;
279
- }
280
- e = batchedSub;
281
289
  batchedSub = void 0;
282
290
  while (e) {
283
- next = e.next;
291
+ const next = e.next;
284
292
  e.next = void 0;
285
293
  e.flags &= ~8;
286
294
  if (e.flags & 1) {
@@ -382,11 +390,11 @@ function removeSub(link, soft = false) {
382
390
  }
383
391
  if (dep.subs === link) {
384
392
  dep.subs = prevSub;
385
- }
386
- if (!dep.subs && dep.computed) {
387
- dep.computed.flags &= ~4;
388
- for (let l = dep.computed.deps; l; l = l.nextDep) {
389
- removeSub(l, true);
393
+ if (!prevSub && dep.computed) {
394
+ dep.computed.flags &= ~4;
395
+ for (let l = dep.computed.deps; l; l = l.nextDep) {
396
+ removeSub(l, true);
397
+ }
390
398
  }
391
399
  }
392
400
  if (!soft && !--dep.sc && dep.map) {
@@ -482,7 +490,6 @@ class Dep {
482
490
  /**
483
491
  * For object property deps cleanup
484
492
  */
485
- this.target = void 0;
486
493
  this.map = void 0;
487
494
  this.key = void 0;
488
495
  /**
@@ -581,7 +588,6 @@ function track(target, type, key) {
581
588
  let dep = depsMap.get(key);
582
589
  if (!dep) {
583
590
  depsMap.set(key, dep = new Dep());
584
- dep.target = target;
585
591
  dep.map = depsMap;
586
592
  dep.key = key;
587
593
  }
@@ -617,7 +623,7 @@ function trigger(target, type, key, newValue, oldValue, oldTarget) {
617
623
  }
618
624
  });
619
625
  } else {
620
- if (key !== void 0) {
626
+ if (key !== void 0 || depsMap.has(void 0)) {
621
627
  run(depsMap.get(key));
622
628
  }
623
629
  if (isArrayIndex) {
@@ -980,112 +986,6 @@ const shallowReadonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler(true
980
986
 
981
987
  const toShallow = (value) => value;
982
988
  const getProto = (v) => Reflect.getPrototypeOf(v);
983
- function get(target, key, isReadonly2 = false, isShallow2 = false) {
984
- target = target["__v_raw"];
985
- const rawTarget = toRaw(target);
986
- const rawKey = toRaw(key);
987
- if (!isReadonly2) {
988
- if (shared.hasChanged(key, rawKey)) {
989
- track(rawTarget, "get", key);
990
- }
991
- track(rawTarget, "get", rawKey);
992
- }
993
- const { has: has2 } = getProto(rawTarget);
994
- const wrap = isShallow2 ? toShallow : isReadonly2 ? toReadonly : toReactive;
995
- if (has2.call(rawTarget, key)) {
996
- return wrap(target.get(key));
997
- } else if (has2.call(rawTarget, rawKey)) {
998
- return wrap(target.get(rawKey));
999
- } else if (target !== rawTarget) {
1000
- target.get(key);
1001
- }
1002
- }
1003
- function has(key, isReadonly2 = false) {
1004
- const target = this["__v_raw"];
1005
- const rawTarget = toRaw(target);
1006
- const rawKey = toRaw(key);
1007
- if (!isReadonly2) {
1008
- if (shared.hasChanged(key, rawKey)) {
1009
- track(rawTarget, "has", key);
1010
- }
1011
- track(rawTarget, "has", rawKey);
1012
- }
1013
- return key === rawKey ? target.has(key) : target.has(key) || target.has(rawKey);
1014
- }
1015
- function size(target, isReadonly2 = false) {
1016
- target = target["__v_raw"];
1017
- !isReadonly2 && track(toRaw(target), "iterate", ITERATE_KEY);
1018
- return Reflect.get(target, "size", target);
1019
- }
1020
- function add(value, _isShallow = false) {
1021
- if (!_isShallow && !isShallow(value) && !isReadonly(value)) {
1022
- value = toRaw(value);
1023
- }
1024
- const target = toRaw(this);
1025
- const proto = getProto(target);
1026
- const hadKey = proto.has.call(target, value);
1027
- if (!hadKey) {
1028
- target.add(value);
1029
- trigger(target, "add", value, value);
1030
- }
1031
- return this;
1032
- }
1033
- function set(key, value, _isShallow = false) {
1034
- if (!_isShallow && !isShallow(value) && !isReadonly(value)) {
1035
- value = toRaw(value);
1036
- }
1037
- const target = toRaw(this);
1038
- const { has: has2, get: get2 } = getProto(target);
1039
- let hadKey = has2.call(target, key);
1040
- if (!hadKey) {
1041
- key = toRaw(key);
1042
- hadKey = has2.call(target, key);
1043
- }
1044
- const oldValue = get2.call(target, key);
1045
- target.set(key, value);
1046
- if (!hadKey) {
1047
- trigger(target, "add", key, value);
1048
- } else if (shared.hasChanged(value, oldValue)) {
1049
- trigger(target, "set", key, value);
1050
- }
1051
- return this;
1052
- }
1053
- function deleteEntry(key) {
1054
- const target = toRaw(this);
1055
- const { has: has2, get: get2 } = getProto(target);
1056
- let hadKey = has2.call(target, key);
1057
- if (!hadKey) {
1058
- key = toRaw(key);
1059
- hadKey = has2.call(target, key);
1060
- }
1061
- get2 ? get2.call(target, key) : void 0;
1062
- const result = target.delete(key);
1063
- if (hadKey) {
1064
- trigger(target, "delete", key, void 0);
1065
- }
1066
- return result;
1067
- }
1068
- function clear() {
1069
- const target = toRaw(this);
1070
- const hadItems = target.size !== 0;
1071
- const result = target.clear();
1072
- if (hadItems) {
1073
- trigger(target, "clear", void 0, void 0);
1074
- }
1075
- return result;
1076
- }
1077
- function createForEach(isReadonly2, isShallow2) {
1078
- return function forEach(callback, thisArg) {
1079
- const observed = this;
1080
- const target = observed["__v_raw"];
1081
- const rawTarget = toRaw(target);
1082
- const wrap = isShallow2 ? toShallow : isReadonly2 ? toReadonly : toReactive;
1083
- !isReadonly2 && track(rawTarget, "iterate", ITERATE_KEY);
1084
- return target.forEach((value, key) => {
1085
- return callback.call(thisArg, wrap(value), wrap(key), observed);
1086
- });
1087
- };
1088
- }
1089
989
  function createIterableMethod(method, isReadonly2, isShallow2) {
1090
990
  return function(...args) {
1091
991
  const target = this["__v_raw"];
@@ -1121,71 +1021,127 @@ function createReadonlyMethod(type) {
1121
1021
  return type === "delete" ? false : type === "clear" ? void 0 : this;
1122
1022
  };
1123
1023
  }
1124
- function createInstrumentations() {
1125
- const mutableInstrumentations2 = {
1126
- get(key) {
1127
- return get(this, key);
1128
- },
1129
- get size() {
1130
- return size(this);
1131
- },
1132
- has,
1133
- add,
1134
- set,
1135
- delete: deleteEntry,
1136
- clear,
1137
- forEach: createForEach(false, false)
1138
- };
1139
- const shallowInstrumentations2 = {
1024
+ function createInstrumentations(readonly, shallow) {
1025
+ const instrumentations = {
1140
1026
  get(key) {
1141
- return get(this, key, false, true);
1142
- },
1143
- get size() {
1144
- return size(this);
1145
- },
1146
- has,
1147
- add(value) {
1148
- return add.call(this, value, true);
1149
- },
1150
- set(key, value) {
1151
- return set.call(this, key, value, true);
1152
- },
1153
- delete: deleteEntry,
1154
- clear,
1155
- forEach: createForEach(false, true)
1156
- };
1157
- const readonlyInstrumentations2 = {
1158
- get(key) {
1159
- return get(this, key, true);
1160
- },
1161
- get size() {
1162
- return size(this, true);
1163
- },
1164
- has(key) {
1165
- return has.call(this, key, true);
1166
- },
1167
- add: createReadonlyMethod("add"),
1168
- set: createReadonlyMethod("set"),
1169
- delete: createReadonlyMethod("delete"),
1170
- clear: createReadonlyMethod("clear"),
1171
- forEach: createForEach(true, false)
1172
- };
1173
- const shallowReadonlyInstrumentations2 = {
1174
- get(key) {
1175
- return get(this, key, true, true);
1027
+ const target = this["__v_raw"];
1028
+ const rawTarget = toRaw(target);
1029
+ const rawKey = toRaw(key);
1030
+ if (!readonly) {
1031
+ if (shared.hasChanged(key, rawKey)) {
1032
+ track(rawTarget, "get", key);
1033
+ }
1034
+ track(rawTarget, "get", rawKey);
1035
+ }
1036
+ const { has } = getProto(rawTarget);
1037
+ const wrap = shallow ? toShallow : readonly ? toReadonly : toReactive;
1038
+ if (has.call(rawTarget, key)) {
1039
+ return wrap(target.get(key));
1040
+ } else if (has.call(rawTarget, rawKey)) {
1041
+ return wrap(target.get(rawKey));
1042
+ } else if (target !== rawTarget) {
1043
+ target.get(key);
1044
+ }
1176
1045
  },
1177
1046
  get size() {
1178
- return size(this, true);
1047
+ const target = this["__v_raw"];
1048
+ !readonly && track(toRaw(target), "iterate", ITERATE_KEY);
1049
+ return Reflect.get(target, "size", target);
1179
1050
  },
1180
1051
  has(key) {
1181
- return has.call(this, key, true);
1052
+ const target = this["__v_raw"];
1053
+ const rawTarget = toRaw(target);
1054
+ const rawKey = toRaw(key);
1055
+ if (!readonly) {
1056
+ if (shared.hasChanged(key, rawKey)) {
1057
+ track(rawTarget, "has", key);
1058
+ }
1059
+ track(rawTarget, "has", rawKey);
1060
+ }
1061
+ return key === rawKey ? target.has(key) : target.has(key) || target.has(rawKey);
1182
1062
  },
1183
- add: createReadonlyMethod("add"),
1184
- set: createReadonlyMethod("set"),
1185
- delete: createReadonlyMethod("delete"),
1186
- clear: createReadonlyMethod("clear"),
1187
- forEach: createForEach(true, true)
1063
+ forEach(callback, thisArg) {
1064
+ const observed = this;
1065
+ const target = observed["__v_raw"];
1066
+ const rawTarget = toRaw(target);
1067
+ const wrap = shallow ? toShallow : readonly ? toReadonly : toReactive;
1068
+ !readonly && track(rawTarget, "iterate", ITERATE_KEY);
1069
+ return target.forEach((value, key) => {
1070
+ return callback.call(thisArg, wrap(value), wrap(key), observed);
1071
+ });
1072
+ }
1188
1073
  };
1074
+ shared.extend(
1075
+ instrumentations,
1076
+ readonly ? {
1077
+ add: createReadonlyMethod("add"),
1078
+ set: createReadonlyMethod("set"),
1079
+ delete: createReadonlyMethod("delete"),
1080
+ clear: createReadonlyMethod("clear")
1081
+ } : {
1082
+ add(value) {
1083
+ if (!shallow && !isShallow(value) && !isReadonly(value)) {
1084
+ value = toRaw(value);
1085
+ }
1086
+ const target = toRaw(this);
1087
+ const proto = getProto(target);
1088
+ const hadKey = proto.has.call(target, value);
1089
+ if (!hadKey) {
1090
+ target.add(value);
1091
+ trigger(target, "add", value, value);
1092
+ }
1093
+ return this;
1094
+ },
1095
+ set(key, value) {
1096
+ if (!shallow && !isShallow(value) && !isReadonly(value)) {
1097
+ value = toRaw(value);
1098
+ }
1099
+ const target = toRaw(this);
1100
+ const { has, get } = getProto(target);
1101
+ let hadKey = has.call(target, key);
1102
+ if (!hadKey) {
1103
+ key = toRaw(key);
1104
+ hadKey = has.call(target, key);
1105
+ }
1106
+ const oldValue = get.call(target, key);
1107
+ target.set(key, value);
1108
+ if (!hadKey) {
1109
+ trigger(target, "add", key, value);
1110
+ } else if (shared.hasChanged(value, oldValue)) {
1111
+ trigger(target, "set", key, value);
1112
+ }
1113
+ return this;
1114
+ },
1115
+ delete(key) {
1116
+ const target = toRaw(this);
1117
+ const { has, get } = getProto(target);
1118
+ let hadKey = has.call(target, key);
1119
+ if (!hadKey) {
1120
+ key = toRaw(key);
1121
+ hadKey = has.call(target, key);
1122
+ }
1123
+ get ? get.call(target, key) : void 0;
1124
+ const result = target.delete(key);
1125
+ if (hadKey) {
1126
+ trigger(target, "delete", key, void 0);
1127
+ }
1128
+ return result;
1129
+ },
1130
+ clear() {
1131
+ const target = toRaw(this);
1132
+ const hadItems = target.size !== 0;
1133
+ const result = target.clear();
1134
+ if (hadItems) {
1135
+ trigger(
1136
+ target,
1137
+ "clear",
1138
+ void 0,
1139
+ void 0);
1140
+ }
1141
+ return result;
1142
+ }
1143
+ }
1144
+ );
1189
1145
  const iteratorMethods = [
1190
1146
  "keys",
1191
1147
  "values",
@@ -1193,30 +1149,12 @@ function createInstrumentations() {
1193
1149
  Symbol.iterator
1194
1150
  ];
1195
1151
  iteratorMethods.forEach((method) => {
1196
- mutableInstrumentations2[method] = createIterableMethod(method, false, false);
1197
- readonlyInstrumentations2[method] = createIterableMethod(method, true, false);
1198
- shallowInstrumentations2[method] = createIterableMethod(method, false, true);
1199
- shallowReadonlyInstrumentations2[method] = createIterableMethod(
1200
- method,
1201
- true,
1202
- true
1203
- );
1152
+ instrumentations[method] = createIterableMethod(method, readonly, shallow);
1204
1153
  });
1205
- return [
1206
- mutableInstrumentations2,
1207
- readonlyInstrumentations2,
1208
- shallowInstrumentations2,
1209
- shallowReadonlyInstrumentations2
1210
- ];
1154
+ return instrumentations;
1211
1155
  }
1212
- const [
1213
- mutableInstrumentations,
1214
- readonlyInstrumentations,
1215
- shallowInstrumentations,
1216
- shallowReadonlyInstrumentations
1217
- ] = /* @__PURE__ */ createInstrumentations();
1218
1156
  function createInstrumentationGetter(isReadonly2, shallow) {
1219
- const instrumentations = shallow ? isReadonly2 ? shallowReadonlyInstrumentations : shallowInstrumentations : isReadonly2 ? readonlyInstrumentations : mutableInstrumentations;
1157
+ const instrumentations = createInstrumentations(isReadonly2, shallow);
1220
1158
  return (target, key, receiver) => {
1221
1159
  if (key === "__v_isReactive") {
1222
1160
  return !isReadonly2;
@@ -1548,7 +1486,7 @@ class ComputedRefImpl {
1548
1486
  this.flags |= 16;
1549
1487
  if (!(this.flags & 8) && // avoid infinite self recursion
1550
1488
  activeSub !== this) {
1551
- batch(this);
1489
+ batch(this, true);
1552
1490
  return true;
1553
1491
  }
1554
1492
  }
@@ -79,7 +79,7 @@ export type ShallowReactive<T> = T & {
79
79
  export declare function shallowReactive<T extends object>(target: T): ShallowReactive<T>;
80
80
  type Primitive = string | number | boolean | bigint | symbol | undefined | null;
81
81
  type Builtin = Primitive | Function | Date | Error | RegExp;
82
- export type DeepReadonly<T> = T extends Builtin ? T : T extends Map<infer K, infer V> ? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>> : T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>> : T extends WeakMap<infer K, infer V> ? WeakMap<DeepReadonly<K>, DeepReadonly<V>> : T extends Set<infer U> ? ReadonlySet<DeepReadonly<U>> : T extends ReadonlySet<infer U> ? ReadonlySet<DeepReadonly<U>> : T extends WeakSet<infer U> ? WeakSet<DeepReadonly<U>> : T extends Promise<infer U> ? Promise<DeepReadonly<U>> : T extends Ref<infer U> ? Readonly<Ref<DeepReadonly<U>>> : T extends {} ? {
82
+ export type DeepReadonly<T> = T extends Builtin ? T : T extends Map<infer K, infer V> ? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>> : T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>> : T extends WeakMap<infer K, infer V> ? WeakMap<DeepReadonly<K>, DeepReadonly<V>> : T extends Set<infer U> ? ReadonlySet<DeepReadonly<U>> : T extends ReadonlySet<infer U> ? ReadonlySet<DeepReadonly<U>> : T extends WeakSet<infer U> ? WeakSet<DeepReadonly<U>> : T extends Promise<infer U> ? Promise<DeepReadonly<U>> : T extends Ref<infer U, unknown> ? Readonly<Ref<DeepReadonly<U>>> : T extends {} ? {
83
83
  readonly [K in keyof T]: DeepReadonly<T[K]>;
84
84
  } : Readonly<T>;
85
85
  /**
@@ -625,8 +625,8 @@ export interface RefUnwrapBailTypes {
625
625
  export type ShallowUnwrapRef<T> = {
626
626
  [K in keyof T]: DistributeRef<T[K]>;
627
627
  };
628
- type DistributeRef<T> = T extends Ref<infer V> ? V : T;
629
- export type UnwrapRef<T> = T extends ShallowRef<infer V, infer _> ? V : T extends Ref<infer V, infer _> ? UnwrapRefSimple<V> : UnwrapRefSimple<T>;
628
+ type DistributeRef<T> = T extends Ref<infer V, unknown> ? V : T;
629
+ export type UnwrapRef<T> = T extends ShallowRef<infer V, unknown> ? V : T extends Ref<infer V, unknown> ? UnwrapRefSimple<V> : UnwrapRefSimple<T>;
630
630
  type UnwrapRefSimple<T> = T extends Builtin | Ref | RefUnwrapBailTypes[keyof RefUnwrapBailTypes] | {
631
631
  [RawSymbol]?: true;
632
632
  } ? 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> ? {