@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,5 +1,5 @@
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
  **/
@@ -96,17 +96,21 @@ class EffectScope {
96
96
  }
97
97
  stop(fromParent) {
98
98
  if (this._active) {
99
+ this._active = false;
99
100
  let i, l;
100
101
  for (i = 0, l = this.effects.length; i < l; i++) {
101
102
  this.effects[i].stop();
102
103
  }
104
+ this.effects.length = 0;
103
105
  for (i = 0, l = this.cleanups.length; i < l; i++) {
104
106
  this.cleanups[i]();
105
107
  }
108
+ this.cleanups.length = 0;
106
109
  if (this.scopes) {
107
110
  for (i = 0, l = this.scopes.length; i < l; i++) {
108
111
  this.scopes[i].stop(true);
109
112
  }
113
+ this.scopes.length = 0;
110
114
  }
111
115
  if (!this.detached && this.parent && !fromParent) {
112
116
  const last = this.parent.scopes.pop();
@@ -116,7 +120,6 @@ class EffectScope {
116
120
  }
117
121
  }
118
122
  this.parent = void 0;
119
- this._active = false;
120
123
  }
121
124
  }
122
125
  }
@@ -390,11 +393,11 @@ function removeSub(link, soft = false) {
390
393
  }
391
394
  if (dep.subs === link) {
392
395
  dep.subs = prevSub;
393
- }
394
- if (!dep.subs && dep.computed) {
395
- dep.computed.flags &= ~4;
396
- for (let l = dep.computed.deps; l; l = l.nextDep) {
397
- removeSub(l, true);
396
+ if (!prevSub && dep.computed) {
397
+ dep.computed.flags &= ~4;
398
+ for (let l = dep.computed.deps; l; l = l.nextDep) {
399
+ removeSub(l, true);
400
+ }
398
401
  }
399
402
  }
400
403
  if (!soft && !--dep.sc && dep.map) {
@@ -623,7 +626,7 @@ function trigger(target, type, key, newValue, oldValue, oldTarget) {
623
626
  }
624
627
  });
625
628
  } else {
626
- if (key !== void 0) {
629
+ if (key !== void 0 || depsMap.has(void 0)) {
627
630
  run(depsMap.get(key));
628
631
  }
629
632
  if (isArrayIndex) {
@@ -855,6 +858,7 @@ class BaseReactiveHandler {
855
858
  this._isShallow = _isShallow;
856
859
  }
857
860
  get(target, key, receiver) {
861
+ if (key === "__v_skip") return target["__v_skip"];
858
862
  const isReadonly2 = this._isReadonly, isShallow2 = this._isShallow;
859
863
  if (key === "__v_isReactive") {
860
864
  return !isReadonly2;
@@ -986,112 +990,6 @@ const shallowReadonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler(true
986
990
 
987
991
  const toShallow = (value) => value;
988
992
  const getProto = (v) => Reflect.getPrototypeOf(v);
989
- function get(target, key, isReadonly2 = false, isShallow2 = false) {
990
- target = target["__v_raw"];
991
- const rawTarget = toRaw(target);
992
- const rawKey = toRaw(key);
993
- if (!isReadonly2) {
994
- if (shared.hasChanged(key, rawKey)) {
995
- track(rawTarget, "get", key);
996
- }
997
- track(rawTarget, "get", rawKey);
998
- }
999
- const { has: has2 } = getProto(rawTarget);
1000
- const wrap = isShallow2 ? toShallow : isReadonly2 ? toReadonly : toReactive;
1001
- if (has2.call(rawTarget, key)) {
1002
- return wrap(target.get(key));
1003
- } else if (has2.call(rawTarget, rawKey)) {
1004
- return wrap(target.get(rawKey));
1005
- } else if (target !== rawTarget) {
1006
- target.get(key);
1007
- }
1008
- }
1009
- function has(key, isReadonly2 = false) {
1010
- const target = this["__v_raw"];
1011
- const rawTarget = toRaw(target);
1012
- const rawKey = toRaw(key);
1013
- if (!isReadonly2) {
1014
- if (shared.hasChanged(key, rawKey)) {
1015
- track(rawTarget, "has", key);
1016
- }
1017
- track(rawTarget, "has", rawKey);
1018
- }
1019
- return key === rawKey ? target.has(key) : target.has(key) || target.has(rawKey);
1020
- }
1021
- function size(target, isReadonly2 = false) {
1022
- target = target["__v_raw"];
1023
- !isReadonly2 && track(toRaw(target), "iterate", ITERATE_KEY);
1024
- return Reflect.get(target, "size", target);
1025
- }
1026
- function add(value, _isShallow = false) {
1027
- if (!_isShallow && !isShallow(value) && !isReadonly(value)) {
1028
- value = toRaw(value);
1029
- }
1030
- const target = toRaw(this);
1031
- const proto = getProto(target);
1032
- const hadKey = proto.has.call(target, value);
1033
- if (!hadKey) {
1034
- target.add(value);
1035
- trigger(target, "add", value, value);
1036
- }
1037
- return this;
1038
- }
1039
- function set(key, value, _isShallow = false) {
1040
- if (!_isShallow && !isShallow(value) && !isReadonly(value)) {
1041
- value = toRaw(value);
1042
- }
1043
- const target = toRaw(this);
1044
- const { has: has2, get: get2 } = getProto(target);
1045
- let hadKey = has2.call(target, key);
1046
- if (!hadKey) {
1047
- key = toRaw(key);
1048
- hadKey = has2.call(target, key);
1049
- }
1050
- const oldValue = get2.call(target, key);
1051
- target.set(key, value);
1052
- if (!hadKey) {
1053
- trigger(target, "add", key, value);
1054
- } else if (shared.hasChanged(value, oldValue)) {
1055
- trigger(target, "set", key, value);
1056
- }
1057
- return this;
1058
- }
1059
- function deleteEntry(key) {
1060
- const target = toRaw(this);
1061
- const { has: has2, get: get2 } = getProto(target);
1062
- let hadKey = has2.call(target, key);
1063
- if (!hadKey) {
1064
- key = toRaw(key);
1065
- hadKey = has2.call(target, key);
1066
- }
1067
- get2 ? get2.call(target, key) : void 0;
1068
- const result = target.delete(key);
1069
- if (hadKey) {
1070
- trigger(target, "delete", key, void 0);
1071
- }
1072
- return result;
1073
- }
1074
- function clear() {
1075
- const target = toRaw(this);
1076
- const hadItems = target.size !== 0;
1077
- const result = target.clear();
1078
- if (hadItems) {
1079
- trigger(target, "clear", void 0, void 0);
1080
- }
1081
- return result;
1082
- }
1083
- function createForEach(isReadonly2, isShallow2) {
1084
- return function forEach(callback, thisArg) {
1085
- const observed = this;
1086
- const target = observed["__v_raw"];
1087
- const rawTarget = toRaw(target);
1088
- const wrap = isShallow2 ? toShallow : isReadonly2 ? toReadonly : toReactive;
1089
- !isReadonly2 && track(rawTarget, "iterate", ITERATE_KEY);
1090
- return target.forEach((value, key) => {
1091
- return callback.call(thisArg, wrap(value), wrap(key), observed);
1092
- });
1093
- };
1094
- }
1095
993
  function createIterableMethod(method, isReadonly2, isShallow2) {
1096
994
  return function(...args) {
1097
995
  const target = this["__v_raw"];
@@ -1127,71 +1025,127 @@ function createReadonlyMethod(type) {
1127
1025
  return type === "delete" ? false : type === "clear" ? void 0 : this;
1128
1026
  };
1129
1027
  }
1130
- function createInstrumentations() {
1131
- const mutableInstrumentations2 = {
1132
- get(key) {
1133
- return get(this, key);
1134
- },
1135
- get size() {
1136
- return size(this);
1137
- },
1138
- has,
1139
- add,
1140
- set,
1141
- delete: deleteEntry,
1142
- clear,
1143
- forEach: createForEach(false, false)
1144
- };
1145
- const shallowInstrumentations2 = {
1146
- get(key) {
1147
- return get(this, key, false, true);
1148
- },
1149
- get size() {
1150
- return size(this);
1151
- },
1152
- has,
1153
- add(value) {
1154
- return add.call(this, value, true);
1155
- },
1156
- set(key, value) {
1157
- return set.call(this, key, value, true);
1158
- },
1159
- delete: deleteEntry,
1160
- clear,
1161
- forEach: createForEach(false, true)
1162
- };
1163
- const readonlyInstrumentations2 = {
1028
+ function createInstrumentations(readonly, shallow) {
1029
+ const instrumentations = {
1164
1030
  get(key) {
1165
- return get(this, key, true);
1166
- },
1167
- get size() {
1168
- return size(this, true);
1169
- },
1170
- has(key) {
1171
- return has.call(this, key, true);
1172
- },
1173
- add: createReadonlyMethod("add"),
1174
- set: createReadonlyMethod("set"),
1175
- delete: createReadonlyMethod("delete"),
1176
- clear: createReadonlyMethod("clear"),
1177
- forEach: createForEach(true, false)
1178
- };
1179
- const shallowReadonlyInstrumentations2 = {
1180
- get(key) {
1181
- return get(this, key, true, true);
1031
+ const target = this["__v_raw"];
1032
+ const rawTarget = toRaw(target);
1033
+ const rawKey = toRaw(key);
1034
+ if (!readonly) {
1035
+ if (shared.hasChanged(key, rawKey)) {
1036
+ track(rawTarget, "get", key);
1037
+ }
1038
+ track(rawTarget, "get", rawKey);
1039
+ }
1040
+ const { has } = getProto(rawTarget);
1041
+ const wrap = shallow ? toShallow : readonly ? toReadonly : toReactive;
1042
+ if (has.call(rawTarget, key)) {
1043
+ return wrap(target.get(key));
1044
+ } else if (has.call(rawTarget, rawKey)) {
1045
+ return wrap(target.get(rawKey));
1046
+ } else if (target !== rawTarget) {
1047
+ target.get(key);
1048
+ }
1182
1049
  },
1183
1050
  get size() {
1184
- return size(this, true);
1051
+ const target = this["__v_raw"];
1052
+ !readonly && track(toRaw(target), "iterate", ITERATE_KEY);
1053
+ return Reflect.get(target, "size", target);
1185
1054
  },
1186
1055
  has(key) {
1187
- return has.call(this, key, true);
1056
+ const target = this["__v_raw"];
1057
+ const rawTarget = toRaw(target);
1058
+ const rawKey = toRaw(key);
1059
+ if (!readonly) {
1060
+ if (shared.hasChanged(key, rawKey)) {
1061
+ track(rawTarget, "has", key);
1062
+ }
1063
+ track(rawTarget, "has", rawKey);
1064
+ }
1065
+ return key === rawKey ? target.has(key) : target.has(key) || target.has(rawKey);
1188
1066
  },
1189
- add: createReadonlyMethod("add"),
1190
- set: createReadonlyMethod("set"),
1191
- delete: createReadonlyMethod("delete"),
1192
- clear: createReadonlyMethod("clear"),
1193
- forEach: createForEach(true, true)
1067
+ forEach(callback, thisArg) {
1068
+ const observed = this;
1069
+ const target = observed["__v_raw"];
1070
+ const rawTarget = toRaw(target);
1071
+ const wrap = shallow ? toShallow : readonly ? toReadonly : toReactive;
1072
+ !readonly && track(rawTarget, "iterate", ITERATE_KEY);
1073
+ return target.forEach((value, key) => {
1074
+ return callback.call(thisArg, wrap(value), wrap(key), observed);
1075
+ });
1076
+ }
1194
1077
  };
1078
+ shared.extend(
1079
+ instrumentations,
1080
+ readonly ? {
1081
+ add: createReadonlyMethod("add"),
1082
+ set: createReadonlyMethod("set"),
1083
+ delete: createReadonlyMethod("delete"),
1084
+ clear: createReadonlyMethod("clear")
1085
+ } : {
1086
+ add(value) {
1087
+ if (!shallow && !isShallow(value) && !isReadonly(value)) {
1088
+ value = toRaw(value);
1089
+ }
1090
+ const target = toRaw(this);
1091
+ const proto = getProto(target);
1092
+ const hadKey = proto.has.call(target, value);
1093
+ if (!hadKey) {
1094
+ target.add(value);
1095
+ trigger(target, "add", value, value);
1096
+ }
1097
+ return this;
1098
+ },
1099
+ set(key, value) {
1100
+ if (!shallow && !isShallow(value) && !isReadonly(value)) {
1101
+ value = toRaw(value);
1102
+ }
1103
+ const target = toRaw(this);
1104
+ const { has, get } = getProto(target);
1105
+ let hadKey = has.call(target, key);
1106
+ if (!hadKey) {
1107
+ key = toRaw(key);
1108
+ hadKey = has.call(target, key);
1109
+ }
1110
+ const oldValue = get.call(target, key);
1111
+ target.set(key, value);
1112
+ if (!hadKey) {
1113
+ trigger(target, "add", key, value);
1114
+ } else if (shared.hasChanged(value, oldValue)) {
1115
+ trigger(target, "set", key, value);
1116
+ }
1117
+ return this;
1118
+ },
1119
+ delete(key) {
1120
+ const target = toRaw(this);
1121
+ const { has, get } = getProto(target);
1122
+ let hadKey = has.call(target, key);
1123
+ if (!hadKey) {
1124
+ key = toRaw(key);
1125
+ hadKey = has.call(target, key);
1126
+ }
1127
+ get ? get.call(target, key) : void 0;
1128
+ const result = target.delete(key);
1129
+ if (hadKey) {
1130
+ trigger(target, "delete", key, void 0);
1131
+ }
1132
+ return result;
1133
+ },
1134
+ clear() {
1135
+ const target = toRaw(this);
1136
+ const hadItems = target.size !== 0;
1137
+ const result = target.clear();
1138
+ if (hadItems) {
1139
+ trigger(
1140
+ target,
1141
+ "clear",
1142
+ void 0,
1143
+ void 0);
1144
+ }
1145
+ return result;
1146
+ }
1147
+ }
1148
+ );
1195
1149
  const iteratorMethods = [
1196
1150
  "keys",
1197
1151
  "values",
@@ -1199,30 +1153,12 @@ function createInstrumentations() {
1199
1153
  Symbol.iterator
1200
1154
  ];
1201
1155
  iteratorMethods.forEach((method) => {
1202
- mutableInstrumentations2[method] = createIterableMethod(method, false, false);
1203
- readonlyInstrumentations2[method] = createIterableMethod(method, true, false);
1204
- shallowInstrumentations2[method] = createIterableMethod(method, false, true);
1205
- shallowReadonlyInstrumentations2[method] = createIterableMethod(
1206
- method,
1207
- true,
1208
- true
1209
- );
1156
+ instrumentations[method] = createIterableMethod(method, readonly, shallow);
1210
1157
  });
1211
- return [
1212
- mutableInstrumentations2,
1213
- readonlyInstrumentations2,
1214
- shallowInstrumentations2,
1215
- shallowReadonlyInstrumentations2
1216
- ];
1158
+ return instrumentations;
1217
1159
  }
1218
- const [
1219
- mutableInstrumentations,
1220
- readonlyInstrumentations,
1221
- shallowInstrumentations,
1222
- shallowReadonlyInstrumentations
1223
- ] = /* @__PURE__ */ createInstrumentations();
1224
1160
  function createInstrumentationGetter(isReadonly2, shallow) {
1225
- const instrumentations = shallow ? isReadonly2 ? shallowReadonlyInstrumentations : shallowInstrumentations : isReadonly2 ? readonlyInstrumentations : mutableInstrumentations;
1161
+ const instrumentations = createInstrumentations(isReadonly2, shallow);
1226
1162
  return (target, key, receiver) => {
1227
1163
  if (key === "__v_isReactive") {
1228
1164
  return !isReadonly2;
@@ -1691,7 +1627,7 @@ function watch(source, cb, options = shared.EMPTY_OBJ) {
1691
1627
  const scope = getCurrentScope();
1692
1628
  const watchHandle = () => {
1693
1629
  effect.stop();
1694
- if (scope) {
1630
+ if (scope && scope.active) {
1695
1631
  shared.remove(scope.effects, effect);
1696
1632
  }
1697
1633
  };