@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
  **/
@@ -270,8 +270,14 @@ class ReactiveEffect {
270
270
  }
271
271
  let batchDepth = 0;
272
272
  let batchedSub;
273
- function batch(sub) {
273
+ let batchedComputed;
274
+ function batch(sub, isComputed = false) {
274
275
  sub.flags |= 8;
276
+ if (isComputed) {
277
+ sub.next = batchedComputed;
278
+ batchedComputed = sub;
279
+ return;
280
+ }
275
281
  sub.next = batchedSub;
276
282
  batchedSub = sub;
277
283
  }
@@ -282,20 +288,22 @@ function endBatch() {
282
288
  if (--batchDepth > 0) {
283
289
  return;
284
290
  }
291
+ if (batchedComputed) {
292
+ let e = batchedComputed;
293
+ batchedComputed = void 0;
294
+ while (e) {
295
+ const next = e.next;
296
+ e.next = void 0;
297
+ e.flags &= ~8;
298
+ e = next;
299
+ }
300
+ }
285
301
  let error;
286
302
  while (batchedSub) {
287
303
  let e = batchedSub;
288
- let next;
289
- while (e) {
290
- if (!(e.flags & 1)) {
291
- e.flags &= ~8;
292
- }
293
- e = e.next;
294
- }
295
- e = batchedSub;
296
304
  batchedSub = void 0;
297
305
  while (e) {
298
- next = e.next;
306
+ const next = e.next;
299
307
  e.next = void 0;
300
308
  e.flags &= ~8;
301
309
  if (e.flags & 1) {
@@ -395,16 +403,16 @@ function removeSub(link, soft = false) {
395
403
  nextSub.prevSub = prevSub;
396
404
  link.nextSub = void 0;
397
405
  }
398
- if (dep.subs === link) {
399
- dep.subs = prevSub;
400
- }
401
406
  if (dep.subsHead === link) {
402
407
  dep.subsHead = nextSub;
403
408
  }
404
- if (!dep.subs && dep.computed) {
405
- dep.computed.flags &= ~4;
406
- for (let l = dep.computed.deps; l; l = l.nextDep) {
407
- removeSub(l, true);
409
+ if (dep.subs === link) {
410
+ dep.subs = prevSub;
411
+ if (!prevSub && dep.computed) {
412
+ dep.computed.flags &= ~4;
413
+ for (let l = dep.computed.deps; l; l = l.nextDep) {
414
+ removeSub(l, true);
415
+ }
408
416
  }
409
417
  }
410
418
  if (!soft && !--dep.sc && dep.map) {
@@ -504,7 +512,6 @@ class Dep {
504
512
  /**
505
513
  * For object property deps cleanup
506
514
  */
507
- this.target = void 0;
508
515
  this.map = void 0;
509
516
  this.key = void 0;
510
517
  /**
@@ -632,7 +639,6 @@ function track(target, type, key) {
632
639
  let dep = depsMap.get(key);
633
640
  if (!dep) {
634
641
  depsMap.set(key, dep = new Dep());
635
- dep.target = target;
636
642
  dep.map = depsMap;
637
643
  dep.key = key;
638
644
  }
@@ -679,7 +685,7 @@ function trigger(target, type, key, newValue, oldValue, oldTarget) {
679
685
  }
680
686
  });
681
687
  } else {
682
- if (key !== void 0) {
688
+ if (key !== void 0 || depsMap.has(void 0)) {
683
689
  run(depsMap.get(key));
684
690
  }
685
691
  if (isArrayIndex) {
@@ -1054,117 +1060,6 @@ const shallowReadonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler(true
1054
1060
 
1055
1061
  const toShallow = (value) => value;
1056
1062
  const getProto = (v) => Reflect.getPrototypeOf(v);
1057
- function get(target, key, isReadonly2 = false, isShallow2 = false) {
1058
- target = target["__v_raw"];
1059
- const rawTarget = toRaw(target);
1060
- const rawKey = toRaw(key);
1061
- if (!isReadonly2) {
1062
- if (shared.hasChanged(key, rawKey)) {
1063
- track(rawTarget, "get", key);
1064
- }
1065
- track(rawTarget, "get", rawKey);
1066
- }
1067
- const { has: has2 } = getProto(rawTarget);
1068
- const wrap = isShallow2 ? toShallow : isReadonly2 ? toReadonly : toReactive;
1069
- if (has2.call(rawTarget, key)) {
1070
- return wrap(target.get(key));
1071
- } else if (has2.call(rawTarget, rawKey)) {
1072
- return wrap(target.get(rawKey));
1073
- } else if (target !== rawTarget) {
1074
- target.get(key);
1075
- }
1076
- }
1077
- function has(key, isReadonly2 = false) {
1078
- const target = this["__v_raw"];
1079
- const rawTarget = toRaw(target);
1080
- const rawKey = toRaw(key);
1081
- if (!isReadonly2) {
1082
- if (shared.hasChanged(key, rawKey)) {
1083
- track(rawTarget, "has", key);
1084
- }
1085
- track(rawTarget, "has", rawKey);
1086
- }
1087
- return key === rawKey ? target.has(key) : target.has(key) || target.has(rawKey);
1088
- }
1089
- function size(target, isReadonly2 = false) {
1090
- target = target["__v_raw"];
1091
- !isReadonly2 && track(toRaw(target), "iterate", ITERATE_KEY);
1092
- return Reflect.get(target, "size", target);
1093
- }
1094
- function add(value, _isShallow = false) {
1095
- if (!_isShallow && !isShallow(value) && !isReadonly(value)) {
1096
- value = toRaw(value);
1097
- }
1098
- const target = toRaw(this);
1099
- const proto = getProto(target);
1100
- const hadKey = proto.has.call(target, value);
1101
- if (!hadKey) {
1102
- target.add(value);
1103
- trigger(target, "add", value, value);
1104
- }
1105
- return this;
1106
- }
1107
- function set(key, value, _isShallow = false) {
1108
- if (!_isShallow && !isShallow(value) && !isReadonly(value)) {
1109
- value = toRaw(value);
1110
- }
1111
- const target = toRaw(this);
1112
- const { has: has2, get: get2 } = getProto(target);
1113
- let hadKey = has2.call(target, key);
1114
- if (!hadKey) {
1115
- key = toRaw(key);
1116
- hadKey = has2.call(target, key);
1117
- } else {
1118
- checkIdentityKeys(target, has2, key);
1119
- }
1120
- const oldValue = get2.call(target, key);
1121
- target.set(key, value);
1122
- if (!hadKey) {
1123
- trigger(target, "add", key, value);
1124
- } else if (shared.hasChanged(value, oldValue)) {
1125
- trigger(target, "set", key, value, oldValue);
1126
- }
1127
- return this;
1128
- }
1129
- function deleteEntry(key) {
1130
- const target = toRaw(this);
1131
- const { has: has2, get: get2 } = getProto(target);
1132
- let hadKey = has2.call(target, key);
1133
- if (!hadKey) {
1134
- key = toRaw(key);
1135
- hadKey = has2.call(target, key);
1136
- } else {
1137
- checkIdentityKeys(target, has2, key);
1138
- }
1139
- const oldValue = get2 ? get2.call(target, key) : void 0;
1140
- const result = target.delete(key);
1141
- if (hadKey) {
1142
- trigger(target, "delete", key, void 0, oldValue);
1143
- }
1144
- return result;
1145
- }
1146
- function clear() {
1147
- const target = toRaw(this);
1148
- const hadItems = target.size !== 0;
1149
- const oldTarget = shared.isMap(target) ? new Map(target) : new Set(target) ;
1150
- const result = target.clear();
1151
- if (hadItems) {
1152
- trigger(target, "clear", void 0, void 0, oldTarget);
1153
- }
1154
- return result;
1155
- }
1156
- function createForEach(isReadonly2, isShallow2) {
1157
- return function forEach(callback, thisArg) {
1158
- const observed = this;
1159
- const target = observed["__v_raw"];
1160
- const rawTarget = toRaw(target);
1161
- const wrap = isShallow2 ? toShallow : isReadonly2 ? toReadonly : toReactive;
1162
- !isReadonly2 && track(rawTarget, "iterate", ITERATE_KEY);
1163
- return target.forEach((value, key) => {
1164
- return callback.call(thisArg, wrap(value), wrap(key), observed);
1165
- });
1166
- };
1167
- }
1168
1063
  function createIterableMethod(method, isReadonly2, isShallow2) {
1169
1064
  return function(...args) {
1170
1065
  const target = this["__v_raw"];
@@ -1207,71 +1102,134 @@ function createReadonlyMethod(type) {
1207
1102
  return type === "delete" ? false : type === "clear" ? void 0 : this;
1208
1103
  };
1209
1104
  }
1210
- function createInstrumentations() {
1211
- const mutableInstrumentations2 = {
1212
- get(key) {
1213
- return get(this, key);
1214
- },
1215
- get size() {
1216
- return size(this);
1217
- },
1218
- has,
1219
- add,
1220
- set,
1221
- delete: deleteEntry,
1222
- clear,
1223
- forEach: createForEach(false, false)
1224
- };
1225
- const shallowInstrumentations2 = {
1105
+ function createInstrumentations(readonly, shallow) {
1106
+ const instrumentations = {
1226
1107
  get(key) {
1227
- return get(this, key, false, true);
1228
- },
1229
- get size() {
1230
- return size(this);
1231
- },
1232
- has,
1233
- add(value) {
1234
- return add.call(this, value, true);
1235
- },
1236
- set(key, value) {
1237
- return set.call(this, key, value, true);
1238
- },
1239
- delete: deleteEntry,
1240
- clear,
1241
- forEach: createForEach(false, true)
1242
- };
1243
- const readonlyInstrumentations2 = {
1244
- get(key) {
1245
- return get(this, key, true);
1246
- },
1247
- get size() {
1248
- return size(this, true);
1249
- },
1250
- has(key) {
1251
- return has.call(this, key, true);
1252
- },
1253
- add: createReadonlyMethod("add"),
1254
- set: createReadonlyMethod("set"),
1255
- delete: createReadonlyMethod("delete"),
1256
- clear: createReadonlyMethod("clear"),
1257
- forEach: createForEach(true, false)
1258
- };
1259
- const shallowReadonlyInstrumentations2 = {
1260
- get(key) {
1261
- return get(this, key, true, true);
1108
+ const target = this["__v_raw"];
1109
+ const rawTarget = toRaw(target);
1110
+ const rawKey = toRaw(key);
1111
+ if (!readonly) {
1112
+ if (shared.hasChanged(key, rawKey)) {
1113
+ track(rawTarget, "get", key);
1114
+ }
1115
+ track(rawTarget, "get", rawKey);
1116
+ }
1117
+ const { has } = getProto(rawTarget);
1118
+ const wrap = shallow ? toShallow : readonly ? toReadonly : toReactive;
1119
+ if (has.call(rawTarget, key)) {
1120
+ return wrap(target.get(key));
1121
+ } else if (has.call(rawTarget, rawKey)) {
1122
+ return wrap(target.get(rawKey));
1123
+ } else if (target !== rawTarget) {
1124
+ target.get(key);
1125
+ }
1262
1126
  },
1263
1127
  get size() {
1264
- return size(this, true);
1128
+ const target = this["__v_raw"];
1129
+ !readonly && track(toRaw(target), "iterate", ITERATE_KEY);
1130
+ return Reflect.get(target, "size", target);
1265
1131
  },
1266
1132
  has(key) {
1267
- return has.call(this, key, true);
1133
+ const target = this["__v_raw"];
1134
+ const rawTarget = toRaw(target);
1135
+ const rawKey = toRaw(key);
1136
+ if (!readonly) {
1137
+ if (shared.hasChanged(key, rawKey)) {
1138
+ track(rawTarget, "has", key);
1139
+ }
1140
+ track(rawTarget, "has", rawKey);
1141
+ }
1142
+ return key === rawKey ? target.has(key) : target.has(key) || target.has(rawKey);
1268
1143
  },
1269
- add: createReadonlyMethod("add"),
1270
- set: createReadonlyMethod("set"),
1271
- delete: createReadonlyMethod("delete"),
1272
- clear: createReadonlyMethod("clear"),
1273
- forEach: createForEach(true, true)
1144
+ forEach(callback, thisArg) {
1145
+ const observed = this;
1146
+ const target = observed["__v_raw"];
1147
+ const rawTarget = toRaw(target);
1148
+ const wrap = shallow ? toShallow : readonly ? toReadonly : toReactive;
1149
+ !readonly && track(rawTarget, "iterate", ITERATE_KEY);
1150
+ return target.forEach((value, key) => {
1151
+ return callback.call(thisArg, wrap(value), wrap(key), observed);
1152
+ });
1153
+ }
1274
1154
  };
1155
+ shared.extend(
1156
+ instrumentations,
1157
+ readonly ? {
1158
+ add: createReadonlyMethod("add"),
1159
+ set: createReadonlyMethod("set"),
1160
+ delete: createReadonlyMethod("delete"),
1161
+ clear: createReadonlyMethod("clear")
1162
+ } : {
1163
+ add(value) {
1164
+ if (!shallow && !isShallow(value) && !isReadonly(value)) {
1165
+ value = toRaw(value);
1166
+ }
1167
+ const target = toRaw(this);
1168
+ const proto = getProto(target);
1169
+ const hadKey = proto.has.call(target, value);
1170
+ if (!hadKey) {
1171
+ target.add(value);
1172
+ trigger(target, "add", value, value);
1173
+ }
1174
+ return this;
1175
+ },
1176
+ set(key, value) {
1177
+ if (!shallow && !isShallow(value) && !isReadonly(value)) {
1178
+ value = toRaw(value);
1179
+ }
1180
+ const target = toRaw(this);
1181
+ const { has, get } = getProto(target);
1182
+ let hadKey = has.call(target, key);
1183
+ if (!hadKey) {
1184
+ key = toRaw(key);
1185
+ hadKey = has.call(target, key);
1186
+ } else {
1187
+ checkIdentityKeys(target, has, key);
1188
+ }
1189
+ const oldValue = get.call(target, key);
1190
+ target.set(key, value);
1191
+ if (!hadKey) {
1192
+ trigger(target, "add", key, value);
1193
+ } else if (shared.hasChanged(value, oldValue)) {
1194
+ trigger(target, "set", key, value, oldValue);
1195
+ }
1196
+ return this;
1197
+ },
1198
+ delete(key) {
1199
+ const target = toRaw(this);
1200
+ const { has, get } = getProto(target);
1201
+ let hadKey = has.call(target, key);
1202
+ if (!hadKey) {
1203
+ key = toRaw(key);
1204
+ hadKey = has.call(target, key);
1205
+ } else {
1206
+ checkIdentityKeys(target, has, key);
1207
+ }
1208
+ const oldValue = get ? get.call(target, key) : void 0;
1209
+ const result = target.delete(key);
1210
+ if (hadKey) {
1211
+ trigger(target, "delete", key, void 0, oldValue);
1212
+ }
1213
+ return result;
1214
+ },
1215
+ clear() {
1216
+ const target = toRaw(this);
1217
+ const hadItems = target.size !== 0;
1218
+ const oldTarget = shared.isMap(target) ? new Map(target) : new Set(target) ;
1219
+ const result = target.clear();
1220
+ if (hadItems) {
1221
+ trigger(
1222
+ target,
1223
+ "clear",
1224
+ void 0,
1225
+ void 0,
1226
+ oldTarget
1227
+ );
1228
+ }
1229
+ return result;
1230
+ }
1231
+ }
1232
+ );
1275
1233
  const iteratorMethods = [
1276
1234
  "keys",
1277
1235
  "values",
@@ -1279,30 +1237,12 @@ function createInstrumentations() {
1279
1237
  Symbol.iterator
1280
1238
  ];
1281
1239
  iteratorMethods.forEach((method) => {
1282
- mutableInstrumentations2[method] = createIterableMethod(method, false, false);
1283
- readonlyInstrumentations2[method] = createIterableMethod(method, true, false);
1284
- shallowInstrumentations2[method] = createIterableMethod(method, false, true);
1285
- shallowReadonlyInstrumentations2[method] = createIterableMethod(
1286
- method,
1287
- true,
1288
- true
1289
- );
1240
+ instrumentations[method] = createIterableMethod(method, readonly, shallow);
1290
1241
  });
1291
- return [
1292
- mutableInstrumentations2,
1293
- readonlyInstrumentations2,
1294
- shallowInstrumentations2,
1295
- shallowReadonlyInstrumentations2
1296
- ];
1242
+ return instrumentations;
1297
1243
  }
1298
- const [
1299
- mutableInstrumentations,
1300
- readonlyInstrumentations,
1301
- shallowInstrumentations,
1302
- shallowReadonlyInstrumentations
1303
- ] = /* @__PURE__ */ createInstrumentations();
1304
1244
  function createInstrumentationGetter(isReadonly2, shallow) {
1305
- const instrumentations = shallow ? isReadonly2 ? shallowReadonlyInstrumentations : shallowInstrumentations : isReadonly2 ? readonlyInstrumentations : mutableInstrumentations;
1245
+ const instrumentations = createInstrumentations(isReadonly2, shallow);
1306
1246
  return (target, key, receiver) => {
1307
1247
  if (key === "__v_isReactive") {
1308
1248
  return !isReadonly2;
@@ -1330,9 +1270,9 @@ const readonlyCollectionHandlers = {
1330
1270
  const shallowReadonlyCollectionHandlers = {
1331
1271
  get: /* @__PURE__ */ createInstrumentationGetter(true, true)
1332
1272
  };
1333
- function checkIdentityKeys(target, has2, key) {
1273
+ function checkIdentityKeys(target, has, key) {
1334
1274
  const rawKey = toRaw(key);
1335
- if (rawKey !== key && has2.call(target, rawKey)) {
1275
+ if (rawKey !== key && has.call(target, rawKey)) {
1336
1276
  const type = shared.toRawType(target);
1337
1277
  warn(
1338
1278
  `Reactive ${type} contains both the raw and reactive versions of the same object${type === `Map` ? ` as keys` : ``}, which can lead to inconsistencies. Avoid differentiating between the raw and reactive versions of an object and only use the reactive version if possible.`
@@ -1668,7 +1608,7 @@ class ComputedRefImpl {
1668
1608
  this.flags |= 16;
1669
1609
  if (!(this.flags & 8) && // avoid infinite self recursion
1670
1610
  activeSub !== this) {
1671
- batch(this);
1611
+ batch(this, true);
1672
1612
  return true;
1673
1613
  }
1674
1614
  }