@vue/reactivity 3.5.11 → 3.5.13

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,9 +1,9 @@
1
1
  /**
2
- * @vue/reactivity v3.5.11
2
+ * @vue/reactivity v3.5.13
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
6
- import { hasChanged, extend, isArray, isIntegerKey, isSymbol, isMap, hasOwn, isObject, makeMap, capitalize, toRawType, def, isFunction, EMPTY_OBJ, isSet, isPlainObject, NOOP, remove } from '@vue/shared';
6
+ import { hasChanged, extend, isArray, isIntegerKey, isSymbol, isMap, hasOwn, isObject, makeMap, toRawType, capitalize, def, isFunction, EMPTY_OBJ, isSet, isPlainObject, NOOP, remove } from '@vue/shared';
7
7
 
8
8
  function warn(msg, ...args) {
9
9
  console.warn(`[Vue warn] ${msg}`, ...args);
@@ -98,17 +98,21 @@ class EffectScope {
98
98
  }
99
99
  stop(fromParent) {
100
100
  if (this._active) {
101
+ this._active = false;
101
102
  let i, l;
102
103
  for (i = 0, l = this.effects.length; i < l; i++) {
103
104
  this.effects[i].stop();
104
105
  }
106
+ this.effects.length = 0;
105
107
  for (i = 0, l = this.cleanups.length; i < l; i++) {
106
108
  this.cleanups[i]();
107
109
  }
110
+ this.cleanups.length = 0;
108
111
  if (this.scopes) {
109
112
  for (i = 0, l = this.scopes.length; i < l; i++) {
110
113
  this.scopes[i].stop(true);
111
114
  }
115
+ this.scopes.length = 0;
112
116
  }
113
117
  if (!this.detached && this.parent && !fromParent) {
114
118
  const last = this.parent.scopes.pop();
@@ -118,7 +122,6 @@ class EffectScope {
118
122
  }
119
123
  }
120
124
  this.parent = void 0;
121
- this._active = false;
122
125
  }
123
126
  }
124
127
  }
@@ -399,16 +402,16 @@ function removeSub(link, soft = false) {
399
402
  nextSub.prevSub = prevSub;
400
403
  link.nextSub = void 0;
401
404
  }
402
- if (dep.subs === link) {
403
- dep.subs = prevSub;
404
- }
405
405
  if (!!(process.env.NODE_ENV !== "production") && dep.subsHead === link) {
406
406
  dep.subsHead = nextSub;
407
407
  }
408
- if (!dep.subs && dep.computed) {
409
- dep.computed.flags &= ~4;
410
- for (let l = dep.computed.deps; l; l = l.nextDep) {
411
- removeSub(l, true);
408
+ if (dep.subs === link) {
409
+ dep.subs = prevSub;
410
+ if (!prevSub && dep.computed) {
411
+ dep.computed.flags &= ~4;
412
+ for (let l = dep.computed.deps; l; l = l.nextDep) {
413
+ removeSub(l, true);
414
+ }
412
415
  }
413
416
  }
414
417
  if (!soft && !--dep.sc && dep.map) {
@@ -685,7 +688,7 @@ function trigger(target, type, key, newValue, oldValue, oldTarget) {
685
688
  }
686
689
  });
687
690
  } else {
688
- if (key !== void 0) {
691
+ if (key !== void 0 || depsMap.has(void 0)) {
689
692
  run(depsMap.get(key));
690
693
  }
691
694
  if (isArrayIndex) {
@@ -917,6 +920,7 @@ class BaseReactiveHandler {
917
920
  this._isShallow = _isShallow;
918
921
  }
919
922
  get(target, key, receiver) {
923
+ if (key === "__v_skip") return target["__v_skip"];
920
924
  const isReadonly2 = this._isReadonly, isShallow2 = this._isShallow;
921
925
  if (key === "__v_isReactive") {
922
926
  return !isReadonly2;
@@ -1060,117 +1064,6 @@ const shallowReadonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler(true
1060
1064
 
1061
1065
  const toShallow = (value) => value;
1062
1066
  const getProto = (v) => Reflect.getPrototypeOf(v);
1063
- function get(target, key, isReadonly2 = false, isShallow2 = false) {
1064
- target = target["__v_raw"];
1065
- const rawTarget = toRaw(target);
1066
- const rawKey = toRaw(key);
1067
- if (!isReadonly2) {
1068
- if (hasChanged(key, rawKey)) {
1069
- track(rawTarget, "get", key);
1070
- }
1071
- track(rawTarget, "get", rawKey);
1072
- }
1073
- const { has: has2 } = getProto(rawTarget);
1074
- const wrap = isShallow2 ? toShallow : isReadonly2 ? toReadonly : toReactive;
1075
- if (has2.call(rawTarget, key)) {
1076
- return wrap(target.get(key));
1077
- } else if (has2.call(rawTarget, rawKey)) {
1078
- return wrap(target.get(rawKey));
1079
- } else if (target !== rawTarget) {
1080
- target.get(key);
1081
- }
1082
- }
1083
- function has(key, isReadonly2 = false) {
1084
- const target = this["__v_raw"];
1085
- const rawTarget = toRaw(target);
1086
- const rawKey = toRaw(key);
1087
- if (!isReadonly2) {
1088
- if (hasChanged(key, rawKey)) {
1089
- track(rawTarget, "has", key);
1090
- }
1091
- track(rawTarget, "has", rawKey);
1092
- }
1093
- return key === rawKey ? target.has(key) : target.has(key) || target.has(rawKey);
1094
- }
1095
- function size(target, isReadonly2 = false) {
1096
- target = target["__v_raw"];
1097
- !isReadonly2 && track(toRaw(target), "iterate", ITERATE_KEY);
1098
- return Reflect.get(target, "size", target);
1099
- }
1100
- function add(value, _isShallow = false) {
1101
- if (!_isShallow && !isShallow(value) && !isReadonly(value)) {
1102
- value = toRaw(value);
1103
- }
1104
- const target = toRaw(this);
1105
- const proto = getProto(target);
1106
- const hadKey = proto.has.call(target, value);
1107
- if (!hadKey) {
1108
- target.add(value);
1109
- trigger(target, "add", value, value);
1110
- }
1111
- return this;
1112
- }
1113
- function set(key, value, _isShallow = false) {
1114
- if (!_isShallow && !isShallow(value) && !isReadonly(value)) {
1115
- value = toRaw(value);
1116
- }
1117
- const target = toRaw(this);
1118
- const { has: has2, get: get2 } = getProto(target);
1119
- let hadKey = has2.call(target, key);
1120
- if (!hadKey) {
1121
- key = toRaw(key);
1122
- hadKey = has2.call(target, key);
1123
- } else if (!!(process.env.NODE_ENV !== "production")) {
1124
- checkIdentityKeys(target, has2, key);
1125
- }
1126
- const oldValue = get2.call(target, key);
1127
- target.set(key, value);
1128
- if (!hadKey) {
1129
- trigger(target, "add", key, value);
1130
- } else if (hasChanged(value, oldValue)) {
1131
- trigger(target, "set", key, value, oldValue);
1132
- }
1133
- return this;
1134
- }
1135
- function deleteEntry(key) {
1136
- const target = toRaw(this);
1137
- const { has: has2, get: get2 } = getProto(target);
1138
- let hadKey = has2.call(target, key);
1139
- if (!hadKey) {
1140
- key = toRaw(key);
1141
- hadKey = has2.call(target, key);
1142
- } else if (!!(process.env.NODE_ENV !== "production")) {
1143
- checkIdentityKeys(target, has2, key);
1144
- }
1145
- const oldValue = get2 ? get2.call(target, key) : void 0;
1146
- const result = target.delete(key);
1147
- if (hadKey) {
1148
- trigger(target, "delete", key, void 0, oldValue);
1149
- }
1150
- return result;
1151
- }
1152
- function clear() {
1153
- const target = toRaw(this);
1154
- const hadItems = target.size !== 0;
1155
- const oldTarget = !!(process.env.NODE_ENV !== "production") ? isMap(target) ? new Map(target) : new Set(target) : void 0;
1156
- const result = target.clear();
1157
- if (hadItems) {
1158
- trigger(target, "clear", void 0, void 0, oldTarget);
1159
- }
1160
- return result;
1161
- }
1162
- function createForEach(isReadonly2, isShallow2) {
1163
- return function forEach(callback, thisArg) {
1164
- const observed = this;
1165
- const target = observed["__v_raw"];
1166
- const rawTarget = toRaw(target);
1167
- const wrap = isShallow2 ? toShallow : isReadonly2 ? toReadonly : toReactive;
1168
- !isReadonly2 && track(rawTarget, "iterate", ITERATE_KEY);
1169
- return target.forEach((value, key) => {
1170
- return callback.call(thisArg, wrap(value), wrap(key), observed);
1171
- });
1172
- };
1173
- }
1174
1067
  function createIterableMethod(method, isReadonly2, isShallow2) {
1175
1068
  return function(...args) {
1176
1069
  const target = this["__v_raw"];
@@ -1213,71 +1106,134 @@ function createReadonlyMethod(type) {
1213
1106
  return type === "delete" ? false : type === "clear" ? void 0 : this;
1214
1107
  };
1215
1108
  }
1216
- function createInstrumentations() {
1217
- const mutableInstrumentations2 = {
1218
- get(key) {
1219
- return get(this, key);
1220
- },
1221
- get size() {
1222
- return size(this);
1223
- },
1224
- has,
1225
- add,
1226
- set,
1227
- delete: deleteEntry,
1228
- clear,
1229
- forEach: createForEach(false, false)
1230
- };
1231
- const shallowInstrumentations2 = {
1232
- get(key) {
1233
- return get(this, key, false, true);
1234
- },
1235
- get size() {
1236
- return size(this);
1237
- },
1238
- has,
1239
- add(value) {
1240
- return add.call(this, value, true);
1241
- },
1242
- set(key, value) {
1243
- return set.call(this, key, value, true);
1244
- },
1245
- delete: deleteEntry,
1246
- clear,
1247
- forEach: createForEach(false, true)
1248
- };
1249
- const readonlyInstrumentations2 = {
1250
- get(key) {
1251
- return get(this, key, true);
1252
- },
1253
- get size() {
1254
- return size(this, true);
1255
- },
1256
- has(key) {
1257
- return has.call(this, key, true);
1258
- },
1259
- add: createReadonlyMethod("add"),
1260
- set: createReadonlyMethod("set"),
1261
- delete: createReadonlyMethod("delete"),
1262
- clear: createReadonlyMethod("clear"),
1263
- forEach: createForEach(true, false)
1264
- };
1265
- const shallowReadonlyInstrumentations2 = {
1109
+ function createInstrumentations(readonly, shallow) {
1110
+ const instrumentations = {
1266
1111
  get(key) {
1267
- return get(this, key, true, true);
1112
+ const target = this["__v_raw"];
1113
+ const rawTarget = toRaw(target);
1114
+ const rawKey = toRaw(key);
1115
+ if (!readonly) {
1116
+ if (hasChanged(key, rawKey)) {
1117
+ track(rawTarget, "get", key);
1118
+ }
1119
+ track(rawTarget, "get", rawKey);
1120
+ }
1121
+ const { has } = getProto(rawTarget);
1122
+ const wrap = shallow ? toShallow : readonly ? toReadonly : toReactive;
1123
+ if (has.call(rawTarget, key)) {
1124
+ return wrap(target.get(key));
1125
+ } else if (has.call(rawTarget, rawKey)) {
1126
+ return wrap(target.get(rawKey));
1127
+ } else if (target !== rawTarget) {
1128
+ target.get(key);
1129
+ }
1268
1130
  },
1269
1131
  get size() {
1270
- return size(this, true);
1132
+ const target = this["__v_raw"];
1133
+ !readonly && track(toRaw(target), "iterate", ITERATE_KEY);
1134
+ return Reflect.get(target, "size", target);
1271
1135
  },
1272
1136
  has(key) {
1273
- return has.call(this, key, true);
1137
+ const target = this["__v_raw"];
1138
+ const rawTarget = toRaw(target);
1139
+ const rawKey = toRaw(key);
1140
+ if (!readonly) {
1141
+ if (hasChanged(key, rawKey)) {
1142
+ track(rawTarget, "has", key);
1143
+ }
1144
+ track(rawTarget, "has", rawKey);
1145
+ }
1146
+ return key === rawKey ? target.has(key) : target.has(key) || target.has(rawKey);
1274
1147
  },
1275
- add: createReadonlyMethod("add"),
1276
- set: createReadonlyMethod("set"),
1277
- delete: createReadonlyMethod("delete"),
1278
- clear: createReadonlyMethod("clear"),
1279
- forEach: createForEach(true, true)
1148
+ forEach(callback, thisArg) {
1149
+ const observed = this;
1150
+ const target = observed["__v_raw"];
1151
+ const rawTarget = toRaw(target);
1152
+ const wrap = shallow ? toShallow : readonly ? toReadonly : toReactive;
1153
+ !readonly && track(rawTarget, "iterate", ITERATE_KEY);
1154
+ return target.forEach((value, key) => {
1155
+ return callback.call(thisArg, wrap(value), wrap(key), observed);
1156
+ });
1157
+ }
1280
1158
  };
1159
+ extend(
1160
+ instrumentations,
1161
+ readonly ? {
1162
+ add: createReadonlyMethod("add"),
1163
+ set: createReadonlyMethod("set"),
1164
+ delete: createReadonlyMethod("delete"),
1165
+ clear: createReadonlyMethod("clear")
1166
+ } : {
1167
+ add(value) {
1168
+ if (!shallow && !isShallow(value) && !isReadonly(value)) {
1169
+ value = toRaw(value);
1170
+ }
1171
+ const target = toRaw(this);
1172
+ const proto = getProto(target);
1173
+ const hadKey = proto.has.call(target, value);
1174
+ if (!hadKey) {
1175
+ target.add(value);
1176
+ trigger(target, "add", value, value);
1177
+ }
1178
+ return this;
1179
+ },
1180
+ set(key, value) {
1181
+ if (!shallow && !isShallow(value) && !isReadonly(value)) {
1182
+ value = toRaw(value);
1183
+ }
1184
+ const target = toRaw(this);
1185
+ const { has, get } = getProto(target);
1186
+ let hadKey = has.call(target, key);
1187
+ if (!hadKey) {
1188
+ key = toRaw(key);
1189
+ hadKey = has.call(target, key);
1190
+ } else if (!!(process.env.NODE_ENV !== "production")) {
1191
+ checkIdentityKeys(target, has, key);
1192
+ }
1193
+ const oldValue = get.call(target, key);
1194
+ target.set(key, value);
1195
+ if (!hadKey) {
1196
+ trigger(target, "add", key, value);
1197
+ } else if (hasChanged(value, oldValue)) {
1198
+ trigger(target, "set", key, value, oldValue);
1199
+ }
1200
+ return this;
1201
+ },
1202
+ delete(key) {
1203
+ const target = toRaw(this);
1204
+ const { has, get } = getProto(target);
1205
+ let hadKey = has.call(target, key);
1206
+ if (!hadKey) {
1207
+ key = toRaw(key);
1208
+ hadKey = has.call(target, key);
1209
+ } else if (!!(process.env.NODE_ENV !== "production")) {
1210
+ checkIdentityKeys(target, has, key);
1211
+ }
1212
+ const oldValue = get ? get.call(target, key) : void 0;
1213
+ const result = target.delete(key);
1214
+ if (hadKey) {
1215
+ trigger(target, "delete", key, void 0, oldValue);
1216
+ }
1217
+ return result;
1218
+ },
1219
+ clear() {
1220
+ const target = toRaw(this);
1221
+ const hadItems = target.size !== 0;
1222
+ const oldTarget = !!(process.env.NODE_ENV !== "production") ? isMap(target) ? new Map(target) : new Set(target) : void 0;
1223
+ const result = target.clear();
1224
+ if (hadItems) {
1225
+ trigger(
1226
+ target,
1227
+ "clear",
1228
+ void 0,
1229
+ void 0,
1230
+ oldTarget
1231
+ );
1232
+ }
1233
+ return result;
1234
+ }
1235
+ }
1236
+ );
1281
1237
  const iteratorMethods = [
1282
1238
  "keys",
1283
1239
  "values",
@@ -1285,30 +1241,12 @@ function createInstrumentations() {
1285
1241
  Symbol.iterator
1286
1242
  ];
1287
1243
  iteratorMethods.forEach((method) => {
1288
- mutableInstrumentations2[method] = createIterableMethod(method, false, false);
1289
- readonlyInstrumentations2[method] = createIterableMethod(method, true, false);
1290
- shallowInstrumentations2[method] = createIterableMethod(method, false, true);
1291
- shallowReadonlyInstrumentations2[method] = createIterableMethod(
1292
- method,
1293
- true,
1294
- true
1295
- );
1244
+ instrumentations[method] = createIterableMethod(method, readonly, shallow);
1296
1245
  });
1297
- return [
1298
- mutableInstrumentations2,
1299
- readonlyInstrumentations2,
1300
- shallowInstrumentations2,
1301
- shallowReadonlyInstrumentations2
1302
- ];
1246
+ return instrumentations;
1303
1247
  }
1304
- const [
1305
- mutableInstrumentations,
1306
- readonlyInstrumentations,
1307
- shallowInstrumentations,
1308
- shallowReadonlyInstrumentations
1309
- ] = /* @__PURE__ */ createInstrumentations();
1310
1248
  function createInstrumentationGetter(isReadonly2, shallow) {
1311
- const instrumentations = shallow ? isReadonly2 ? shallowReadonlyInstrumentations : shallowInstrumentations : isReadonly2 ? readonlyInstrumentations : mutableInstrumentations;
1249
+ const instrumentations = createInstrumentations(isReadonly2, shallow);
1312
1250
  return (target, key, receiver) => {
1313
1251
  if (key === "__v_isReactive") {
1314
1252
  return !isReadonly2;
@@ -1336,9 +1274,9 @@ const readonlyCollectionHandlers = {
1336
1274
  const shallowReadonlyCollectionHandlers = {
1337
1275
  get: /* @__PURE__ */ createInstrumentationGetter(true, true)
1338
1276
  };
1339
- function checkIdentityKeys(target, has2, key) {
1277
+ function checkIdentityKeys(target, has, key) {
1340
1278
  const rawKey = toRaw(key);
1341
- if (rawKey !== key && has2.call(target, rawKey)) {
1279
+ if (rawKey !== key && has.call(target, rawKey)) {
1342
1280
  const type = toRawType(target);
1343
1281
  warn(
1344
1282
  `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.`
@@ -1841,7 +1779,7 @@ function watch(source, cb, options = EMPTY_OBJ) {
1841
1779
  const scope = getCurrentScope();
1842
1780
  const watchHandle = () => {
1843
1781
  effect.stop();
1844
- if (scope) {
1782
+ if (scope && scope.active) {
1845
1783
  remove(scope.effects, effect);
1846
1784
  }
1847
1785
  };