@feng3d/reactivity 1.0.4 → 1.0.6
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.
- package/LICENSE +21 -21
- package/README.md +158 -158
- package/dist/assets/RobotoMono-Medium-DVgDz_OO.woff2 +0 -0
- package/dist/assets/RobotoMono-Regular-BPoF81uy.woff2 +0 -0
- package/dist/assets/index-a2qCSG5V.css +629 -0
- package/dist/assets/index.html-Dyp3udP2.js +200 -0
- package/dist/assets/modulepreload-polyfill-DaKOjhqt.js +37 -0
- package/dist/assets/package-9zMEdmDL.js +2540 -0
- package/dist/assets/src//345/244/215/346/235/202/346/203/205/345/206/265/345/217/226/345/200/274/index.html-a69uOZEV.js +59 -0
- package/dist/assets/src//346/225/260/347/273/204/index.html-CaZ_5kCZ.js +43 -0
- package/dist/docs/.nojekyll +1 -0
- package/dist/docs/assets/hierarchy.js +1 -0
- package/dist/docs/assets/highlight.css +92 -0
- package/dist/docs/assets/icons.js +18 -0
- package/dist/docs/assets/icons.svg +1 -0
- package/dist/docs/assets/main.js +60 -0
- package/dist/docs/assets/navigation.js +1 -0
- package/dist/docs/assets/search.js +1 -0
- package/dist/docs/assets/style.css +1640 -0
- package/dist/docs/classes/ComputedReactivity.html +72 -0
- package/dist/docs/classes/EffectReactivity.html +62 -0
- package/dist/docs/classes/EffectScope.html +40 -0
- package/dist/docs/classes/Reactivity.html +35 -0
- package/dist/docs/classes/RefReactivity.html +57 -0
- package/dist/docs/functions/batchRun.html +15 -0
- package/dist/docs/functions/computed.html +5 -0
- package/dist/docs/functions/effect.html +11 -0
- package/dist/docs/functions/effectScope.html +5 -0
- package/dist/docs/functions/forceTrack.html +6 -0
- package/dist/docs/functions/getCurrentScope.html +4 -0
- package/dist/docs/functions/isProxy.html +5 -0
- package/dist/docs/functions/isReactive.html +5 -0
- package/dist/docs/functions/isRef.html +5 -0
- package/dist/docs/functions/noTrack.html +6 -0
- package/dist/docs/functions/onScopeDispose.html +6 -0
- package/dist/docs/functions/reactive.html +19 -0
- package/dist/docs/functions/ref.html +13 -0
- package/dist/docs/functions/toRaw.html +4 -0
- package/dist/docs/hierarchy.html +1 -0
- package/dist/docs/index.html +129 -0
- package/dist/docs/interfaces/Computed.html +9 -0
- package/dist/docs/interfaces/Effect.html +8 -0
- package/dist/docs/interfaces/Ref.html +9 -0
- package/dist/docs/modules.html +1 -0
- package/dist/docs/types/Reactive.html +3 -0
- package/dist/docs/types/UnReadonly.html +3 -0
- package/dist/files/RobotoMono-Medium.woff2 +0 -0
- package/dist/files/RobotoMono-Regular.woff2 +0 -0
- package/dist/files/ic_code_black_24dp.svg +4 -0
- package/dist/files/ic_search_black_24dp.svg +4 -0
- package/dist/files/main.css +629 -0
- package/dist/files/thumbnails.svg +7 -0
- package/dist/files.json +7 -0
- package/dist/index.html +84 -0
- package/dist/index.js +735 -156
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +735 -156
- package/dist/index.umd.cjs.map +1 -1
- package/dist/screenshots//345/244/215/346/235/202/346/203/205/345/206/265/345/217/226/345/200/274.jpg +0 -0
- package/dist/screenshots//346/225/260/347/273/204.jpg +0 -0
- package/dist/src//345/244/215/346/235/202/346/203/205/345/206/265/345/217/226/345/200/274/index.html +70 -0
- package/dist/src//346/225/260/347/273/204/index.html +65 -0
- package/dist/tags.json +2 -0
- package/lib/Reactivity.d.ts +47 -13
- package/lib/Reactivity.d.ts.map +1 -1
- package/lib/arrayInstrumentations.d.ts +10 -0
- package/lib/arrayInstrumentations.d.ts.map +1 -1
- package/lib/baseHandlers.d.ts +3 -1
- package/lib/baseHandlers.d.ts.map +1 -1
- package/lib/batch.d.ts +17 -5
- package/lib/batch.d.ts.map +1 -1
- package/lib/collectionHandlers.d.ts +21 -0
- package/lib/collectionHandlers.d.ts.map +1 -1
- package/lib/computed.d.ts +75 -27
- package/lib/computed.d.ts.map +1 -1
- package/lib/effect.d.ts +25 -0
- package/lib/effect.d.ts.map +1 -1
- package/lib/effectScope.d.ts +129 -0
- package/lib/effectScope.d.ts.map +1 -0
- package/lib/index.d.ts +6 -5
- package/lib/index.d.ts.map +1 -1
- package/lib/property.d.ts.map +1 -1
- package/lib/reactive.d.ts +63 -14
- package/lib/reactive.d.ts.map +1 -1
- package/lib/ref.d.ts +66 -4
- package/lib/ref.d.ts.map +1 -1
- package/lib/shared/constants.d.ts +7 -7
- package/lib/shared/constants.d.ts.map +1 -1
- package/lib/shared/general.d.ts +1 -1
- package/lib/shared/general.d.ts.map +1 -1
- package/package.json +71 -66
- package/src/Reactivity.ts +168 -126
- package/src/arrayInstrumentations.ts +801 -448
- package/src/baseHandlers.ts +312 -220
- package/src/batch.ts +118 -91
- package/src/collectionHandlers.ts +486 -298
- package/src/computed.ts +253 -204
- package/src/effect.ts +146 -108
- package/src/effectScope.ts +294 -0
- package/src/index.ts +9 -8
- package/src/property.ts +231 -225
- package/src/reactive.ts +186 -130
- package/src/ref.ts +150 -88
- package/src/shared/constants.ts +41 -41
- package/src/shared/general.ts +109 -109
- package/tsconfig.json +19 -19
|
@@ -0,0 +1,2540 @@
|
|
|
1
|
+
class Reactivity {
|
|
2
|
+
constructor() {
|
|
3
|
+
this._parents = /* @__PURE__ */ new Map();
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* 获取当前节点值。
|
|
7
|
+
*
|
|
8
|
+
* 取值时将会建立与父节点的依赖关系。
|
|
9
|
+
* 当其他响应式节点访问此值时,会自动建立依赖关系。
|
|
10
|
+
*/
|
|
11
|
+
get value() {
|
|
12
|
+
this.track();
|
|
13
|
+
return this._value;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* 建立依赖关系。
|
|
17
|
+
*
|
|
18
|
+
* 当其他节点访问当前节点的值时,会调用此方法。
|
|
19
|
+
* 将当前节点与访问者(父节点)建立依赖关系。
|
|
20
|
+
*
|
|
21
|
+
* 如果当前没有活动的响应式节点,或者不应该跟踪依赖,则不会建立依赖关系。
|
|
22
|
+
*/
|
|
23
|
+
track() {
|
|
24
|
+
if (!Reactivity.activeReactivity || !_shouldTrack) return;
|
|
25
|
+
const parent = Reactivity.activeReactivity;
|
|
26
|
+
if (parent) {
|
|
27
|
+
this._parents.set(parent, parent._version);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* 触发更新。
|
|
32
|
+
*
|
|
33
|
+
* 当节点值发生变化时,会调用此方法。
|
|
34
|
+
* 通知所有依赖此节点的父节点进行更新。
|
|
35
|
+
*
|
|
36
|
+
* 更新过程:
|
|
37
|
+
* 1. 遍历所有父节点
|
|
38
|
+
* 2. 检查父节点的版本号是否匹配
|
|
39
|
+
* 3. 触发父节点的更新
|
|
40
|
+
* 4. 将当前节点添加到父节点的失效子节点集合中
|
|
41
|
+
*/
|
|
42
|
+
trigger() {
|
|
43
|
+
this._parents.forEach((version, parent) => {
|
|
44
|
+
if (parent._version !== version) return;
|
|
45
|
+
parent.trigger();
|
|
46
|
+
parent._children.set(this, this._value);
|
|
47
|
+
});
|
|
48
|
+
this._parents.clear();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function forceTrack(fn) {
|
|
52
|
+
const preShouldTrack = _shouldTrack;
|
|
53
|
+
_shouldTrack = true;
|
|
54
|
+
const result = fn();
|
|
55
|
+
_shouldTrack = preShouldTrack;
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
function noTrack(fn) {
|
|
59
|
+
const preShouldTrack = _shouldTrack;
|
|
60
|
+
_shouldTrack = false;
|
|
61
|
+
const result = fn();
|
|
62
|
+
_shouldTrack = preShouldTrack;
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
let _shouldTrack = true;
|
|
66
|
+
function batch$1(dep, isRunning) {
|
|
67
|
+
if (isRunning) {
|
|
68
|
+
_isRunedDeps.push(dep);
|
|
69
|
+
} else {
|
|
70
|
+
_needEffectDeps.push(dep);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function batchRun(fn) {
|
|
74
|
+
_batchDepth++;
|
|
75
|
+
const result = fn();
|
|
76
|
+
if (--_batchDepth > 0) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (_isRunedDeps.length > 0) {
|
|
80
|
+
_isRunedDeps.forEach((dep) => {
|
|
81
|
+
dep._children.forEach((version, node) => {
|
|
82
|
+
node._parents.set(dep, dep._version);
|
|
83
|
+
});
|
|
84
|
+
dep._children.clear();
|
|
85
|
+
});
|
|
86
|
+
_isRunedDeps.length = 0;
|
|
87
|
+
}
|
|
88
|
+
if (_needEffectDeps.length > 0) {
|
|
89
|
+
_needEffectDeps.forEach((dep) => {
|
|
90
|
+
const pre = Reactivity.activeReactivity;
|
|
91
|
+
Reactivity.activeReactivity = null;
|
|
92
|
+
dep.runIfDirty();
|
|
93
|
+
Reactivity.activeReactivity = pre;
|
|
94
|
+
});
|
|
95
|
+
_needEffectDeps.length = 0;
|
|
96
|
+
}
|
|
97
|
+
return result;
|
|
98
|
+
}
|
|
99
|
+
let _batchDepth = 0;
|
|
100
|
+
const _needEffectDeps = [];
|
|
101
|
+
const _isRunedDeps = [];
|
|
102
|
+
function computed$1(func) {
|
|
103
|
+
return new ComputedReactivity(func);
|
|
104
|
+
}
|
|
105
|
+
class ComputedReactivity extends Reactivity {
|
|
106
|
+
/**
|
|
107
|
+
* 创建计算反应式节点。
|
|
108
|
+
*
|
|
109
|
+
* @param func 计算函数,可以访问其他响应式数据,并返回计算结果
|
|
110
|
+
*/
|
|
111
|
+
constructor(func) {
|
|
112
|
+
super();
|
|
113
|
+
this.__v_isRef = true;
|
|
114
|
+
this._children = /* @__PURE__ */ new Map();
|
|
115
|
+
this._isDirty = true;
|
|
116
|
+
this._version = -1;
|
|
117
|
+
this._func = func;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* 获取计算属性的值。
|
|
121
|
+
*
|
|
122
|
+
* 取值时会:
|
|
123
|
+
* 1. 检查是否需要重新计算
|
|
124
|
+
* 2. 建立与父节点的依赖关系
|
|
125
|
+
* 3. 返回当前值
|
|
126
|
+
*/
|
|
127
|
+
get value() {
|
|
128
|
+
this.runIfDirty();
|
|
129
|
+
this.track();
|
|
130
|
+
return this._value;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* 触发更新。
|
|
134
|
+
*
|
|
135
|
+
* 当依赖发生变化时,会调用此方法。
|
|
136
|
+
* 如果当前正在执行计算,会将更新延迟到计算完成后。
|
|
137
|
+
* 否则,立即通知所有父节点进行更新。
|
|
138
|
+
*/
|
|
139
|
+
trigger() {
|
|
140
|
+
if (Reactivity.activeReactivity === this) {
|
|
141
|
+
batch$1(this, Reactivity.activeReactivity === this);
|
|
142
|
+
}
|
|
143
|
+
super.trigger();
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* 执行计算。
|
|
147
|
+
*
|
|
148
|
+
* 执行计算函数,更新当前值。
|
|
149
|
+
* 在计算过程中会:
|
|
150
|
+
* 1. 强制启用依赖跟踪
|
|
151
|
+
* 2. 保存并设置当前活动节点
|
|
152
|
+
* 3. 执行计算函数
|
|
153
|
+
* 4. 恢复活动节点
|
|
154
|
+
*/
|
|
155
|
+
run() {
|
|
156
|
+
forceTrack(() => {
|
|
157
|
+
const parentReactiveNode = Reactivity.activeReactivity;
|
|
158
|
+
Reactivity.activeReactivity = this;
|
|
159
|
+
this._version++;
|
|
160
|
+
this._value = this._func(this._value);
|
|
161
|
+
Reactivity.activeReactivity = parentReactiveNode;
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* 检查并执行计算。
|
|
166
|
+
*
|
|
167
|
+
* 检查当前节点是否需要重新计算:
|
|
168
|
+
* 1. 如果脏标记为 true,需要重新计算
|
|
169
|
+
* 2. 如果子节点发生变化,需要重新计算
|
|
170
|
+
*
|
|
171
|
+
* 重新计算后会清除脏标记。
|
|
172
|
+
*/
|
|
173
|
+
runIfDirty() {
|
|
174
|
+
this._isDirty = this._isDirty || this.isChildrenChanged();
|
|
175
|
+
if (this._isDirty) {
|
|
176
|
+
this._isDirty = false;
|
|
177
|
+
this.run();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* 检查子节点是否发生变化。
|
|
182
|
+
*
|
|
183
|
+
* 遍历所有子节点,检查它们的值是否发生变化。
|
|
184
|
+
* 如果发生变化,返回 true,否则返回 false。
|
|
185
|
+
*
|
|
186
|
+
* 在检查过程中会:
|
|
187
|
+
* 1. 临时禁用依赖跟踪
|
|
188
|
+
* 2. 检查每个子节点的值
|
|
189
|
+
* 3. 如果子节点没有变化,重新建立依赖关系
|
|
190
|
+
* 4. 清空子节点集合
|
|
191
|
+
*
|
|
192
|
+
* @returns 是否有子节点发生变化
|
|
193
|
+
*/
|
|
194
|
+
isChildrenChanged() {
|
|
195
|
+
if (this._children.size === 0) return false;
|
|
196
|
+
let isChanged = false;
|
|
197
|
+
const preReactiveNode = Reactivity.activeReactivity;
|
|
198
|
+
Reactivity.activeReactivity = null;
|
|
199
|
+
this._children.forEach((value, node) => {
|
|
200
|
+
if (isChanged) return;
|
|
201
|
+
if (node.value !== value) {
|
|
202
|
+
isChanged = true;
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
Reactivity.activeReactivity = preReactiveNode;
|
|
207
|
+
if (!isChanged) {
|
|
208
|
+
this._children.forEach((version, node) => {
|
|
209
|
+
node._parents.set(this, this._version);
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
this._children.clear();
|
|
213
|
+
return isChanged;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
var ReactiveFlags = /* @__PURE__ */ ((ReactiveFlags2) => {
|
|
217
|
+
ReactiveFlags2["IS_REACTIVE"] = "__v_isReactive";
|
|
218
|
+
ReactiveFlags2["RAW"] = "__v_raw";
|
|
219
|
+
ReactiveFlags2["IS_REF"] = "__v_isRef";
|
|
220
|
+
return ReactiveFlags2;
|
|
221
|
+
})(ReactiveFlags || {});
|
|
222
|
+
var TargetType = /* @__PURE__ */ ((TargetType2) => {
|
|
223
|
+
TargetType2[TargetType2["INVALID"] = 0] = "INVALID";
|
|
224
|
+
TargetType2[TargetType2["COMMON"] = 1] = "COMMON";
|
|
225
|
+
TargetType2[TargetType2["COLLECTION"] = 2] = "COLLECTION";
|
|
226
|
+
return TargetType2;
|
|
227
|
+
})(TargetType || {});
|
|
228
|
+
var TrackOpTypes = /* @__PURE__ */ ((TrackOpTypes2) => {
|
|
229
|
+
TrackOpTypes2["GET"] = "get";
|
|
230
|
+
TrackOpTypes2["HAS"] = "has";
|
|
231
|
+
TrackOpTypes2["ITERATE"] = "iterate";
|
|
232
|
+
return TrackOpTypes2;
|
|
233
|
+
})(TrackOpTypes || {});
|
|
234
|
+
var TriggerOpTypes = /* @__PURE__ */ ((TriggerOpTypes2) => {
|
|
235
|
+
TriggerOpTypes2["SET"] = "set";
|
|
236
|
+
TriggerOpTypes2["ADD"] = "add";
|
|
237
|
+
TriggerOpTypes2["DELETE"] = "delete";
|
|
238
|
+
TriggerOpTypes2["CLEAR"] = "clear";
|
|
239
|
+
return TriggerOpTypes2;
|
|
240
|
+
})(TriggerOpTypes || {});
|
|
241
|
+
const ITERATE_KEY$1 = Symbol("");
|
|
242
|
+
const MAP_KEY_ITERATE_KEY$1 = Symbol("");
|
|
243
|
+
const ARRAY_ITERATE_KEY$1 = Symbol("");
|
|
244
|
+
globalThis.__DEV__ ?? (globalThis.__DEV__ = true);
|
|
245
|
+
const isObject$1 = (val) => val !== null && typeof val === "object";
|
|
246
|
+
const isArray$1 = Array.isArray;
|
|
247
|
+
const isSymbol$1 = (val) => typeof val === "symbol";
|
|
248
|
+
const isString$1 = (val) => typeof val === "string";
|
|
249
|
+
const isIntegerKey$1 = (key) => isString$1(key) && key !== "NaN" && key[0] !== "-" && `${parseInt(key, 10)}` === key;
|
|
250
|
+
const isMap$1 = (val) => toTypeString$1(val) === "[object Map]";
|
|
251
|
+
const hasOwn$1 = (val, key) => Object.prototype.hasOwnProperty.call(val, key);
|
|
252
|
+
const hasChanged$1 = (value, oldValue) => !Object.is(value, oldValue);
|
|
253
|
+
function targetTypeMap$1(rawType) {
|
|
254
|
+
switch (rawType) {
|
|
255
|
+
case "Object":
|
|
256
|
+
case "Array":
|
|
257
|
+
return TargetType.COMMON;
|
|
258
|
+
case "Map":
|
|
259
|
+
case "Set":
|
|
260
|
+
case "WeakMap":
|
|
261
|
+
case "WeakSet":
|
|
262
|
+
return TargetType.COLLECTION;
|
|
263
|
+
default:
|
|
264
|
+
return TargetType.COMMON;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
function getTargetType$1(value) {
|
|
268
|
+
if (!Object.isExtensible(value)) return TargetType.INVALID;
|
|
269
|
+
return targetTypeMap$1(toRawType$1(value));
|
|
270
|
+
}
|
|
271
|
+
const toTypeString$1 = (value) => Object.prototype.toString.call(value);
|
|
272
|
+
const toRawType$1 = (value) => (
|
|
273
|
+
// 从类似 "[object RawType]" 的字符串中提取 "RawType"
|
|
274
|
+
toTypeString$1(value).slice(8, -1)
|
|
275
|
+
);
|
|
276
|
+
function toRaw$1(observed) {
|
|
277
|
+
const raw = observed && observed[ReactiveFlags.RAW];
|
|
278
|
+
return raw ? toRaw$1(raw) : observed;
|
|
279
|
+
}
|
|
280
|
+
// @__NO_SIDE_EFFECTS__
|
|
281
|
+
function makeMap$1(str) {
|
|
282
|
+
const map = /* @__PURE__ */ Object.create(null);
|
|
283
|
+
for (const key of str.split(",")) map[key] = 1;
|
|
284
|
+
return (val) => val in map;
|
|
285
|
+
}
|
|
286
|
+
const _EffectReactivity = class _EffectReactivity extends ComputedReactivity {
|
|
287
|
+
constructor(func) {
|
|
288
|
+
super(func);
|
|
289
|
+
this._isEnable = true;
|
|
290
|
+
this.runIfDirty();
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* 暂停效果。
|
|
294
|
+
*
|
|
295
|
+
* 暂停后,当依赖发生变化时不会自动执行。
|
|
296
|
+
*/
|
|
297
|
+
pause() {
|
|
298
|
+
this._isEnable = false;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* 恢复效果。
|
|
302
|
+
*
|
|
303
|
+
* 恢复后,当依赖发生变化时会自动执行。
|
|
304
|
+
*/
|
|
305
|
+
resume() {
|
|
306
|
+
if (this._isEnable) return;
|
|
307
|
+
this._isEnable = true;
|
|
308
|
+
if (_EffectReactivity.pausedQueueEffects.has(this)) {
|
|
309
|
+
_EffectReactivity.pausedQueueEffects.delete(this);
|
|
310
|
+
this.trigger();
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* 停止效果。
|
|
315
|
+
*
|
|
316
|
+
* 停止后,效果将不再响应依赖的变化。
|
|
317
|
+
*/
|
|
318
|
+
stop() {
|
|
319
|
+
this._isEnable = false;
|
|
320
|
+
_EffectReactivity.pausedQueueEffects.delete(this);
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* 触发效果执行。
|
|
324
|
+
*
|
|
325
|
+
* 当依赖发生变化时,会调用此方法。
|
|
326
|
+
*/
|
|
327
|
+
trigger() {
|
|
328
|
+
batchRun(() => {
|
|
329
|
+
super.trigger();
|
|
330
|
+
if (this._isEnable) {
|
|
331
|
+
batch$1(this, Reactivity.activeReactivity === this);
|
|
332
|
+
} else {
|
|
333
|
+
_EffectReactivity.pausedQueueEffects.add(this);
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* 执行当前节点。
|
|
339
|
+
*
|
|
340
|
+
* 当暂停时将会直接执行被包装的函数。
|
|
341
|
+
*/
|
|
342
|
+
run() {
|
|
343
|
+
if (this._isEnable) {
|
|
344
|
+
super.run();
|
|
345
|
+
} else {
|
|
346
|
+
this._func(this._value);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
_EffectReactivity.pausedQueueEffects = /* @__PURE__ */ new WeakSet();
|
|
351
|
+
let EffectReactivity = _EffectReactivity;
|
|
352
|
+
function property(target, key) {
|
|
353
|
+
let depsMap = PropertyReactivity._targetMap.get(target);
|
|
354
|
+
if (!depsMap) {
|
|
355
|
+
depsMap = /* @__PURE__ */ new Map();
|
|
356
|
+
PropertyReactivity._targetMap.set(target, depsMap);
|
|
357
|
+
}
|
|
358
|
+
let dep = depsMap.get(key);
|
|
359
|
+
if (!dep) {
|
|
360
|
+
dep = new PropertyReactivity(target, key);
|
|
361
|
+
depsMap.set(key, dep);
|
|
362
|
+
}
|
|
363
|
+
return dep;
|
|
364
|
+
}
|
|
365
|
+
const _PropertyReactivity = class _PropertyReactivity extends Reactivity {
|
|
366
|
+
/**
|
|
367
|
+
* 获取当前节点值。
|
|
368
|
+
*
|
|
369
|
+
* 取值时将会建立与父节点的依赖关系。
|
|
370
|
+
*/
|
|
371
|
+
get value() {
|
|
372
|
+
this.track();
|
|
373
|
+
return this._value;
|
|
374
|
+
}
|
|
375
|
+
set value(v) {
|
|
376
|
+
if (this._key === "length") {
|
|
377
|
+
v = this._target["length"];
|
|
378
|
+
} else if (isSymbol$1(this._key)) {
|
|
379
|
+
v = ~~this._value + 1;
|
|
380
|
+
}
|
|
381
|
+
if (v === this._value) return;
|
|
382
|
+
this.trigger();
|
|
383
|
+
this._value = v;
|
|
384
|
+
}
|
|
385
|
+
constructor(target, key) {
|
|
386
|
+
super();
|
|
387
|
+
this._target = target;
|
|
388
|
+
this._key = key;
|
|
389
|
+
if (target instanceof Map || target instanceof WeakMap) {
|
|
390
|
+
this._value = target.get(key);
|
|
391
|
+
} else if (target instanceof Set || target instanceof WeakSet) {
|
|
392
|
+
this._value = target.has(key);
|
|
393
|
+
} else {
|
|
394
|
+
this._value = target[key];
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
triggerIfChanged() {
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* 追踪属性的变化。
|
|
401
|
+
*
|
|
402
|
+
* 当属性被访问时,将会追踪属性的变化。
|
|
403
|
+
*
|
|
404
|
+
* @param target 目标对象。
|
|
405
|
+
* @param key 属性名。
|
|
406
|
+
* @returns
|
|
407
|
+
*/
|
|
408
|
+
static track(target, type, key) {
|
|
409
|
+
if (!Reactivity.activeReactivity) return;
|
|
410
|
+
const dep = property(target, key);
|
|
411
|
+
dep.track();
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* 触发属性的变化。
|
|
415
|
+
*
|
|
416
|
+
* @param target 目标对象。
|
|
417
|
+
* @param type 操作类型。
|
|
418
|
+
* @param key 属性名。
|
|
419
|
+
* @param newValue 新值。
|
|
420
|
+
* @param oldValue 旧值。
|
|
421
|
+
* @returns
|
|
422
|
+
*/
|
|
423
|
+
static trigger(target, type, key, newValue, oldValue) {
|
|
424
|
+
const depsMap = this._targetMap.get(target);
|
|
425
|
+
if (!depsMap) return;
|
|
426
|
+
const run = (dep) => {
|
|
427
|
+
if (dep) {
|
|
428
|
+
dep.value = newValue;
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
batchRun(() => {
|
|
432
|
+
if (type === TriggerOpTypes.CLEAR) {
|
|
433
|
+
depsMap.forEach(run);
|
|
434
|
+
} else {
|
|
435
|
+
const targetIsArray = isArray$1(target);
|
|
436
|
+
const isArrayIndex = targetIsArray && isIntegerKey$1(key);
|
|
437
|
+
if (targetIsArray && key === "length") {
|
|
438
|
+
const newLength = Number(newValue);
|
|
439
|
+
depsMap.forEach((dep, key2) => {
|
|
440
|
+
if (key2 === "length" || key2 === ARRAY_ITERATE_KEY$1 || !isSymbol$1(key2) && key2 >= newLength) {
|
|
441
|
+
run(dep);
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
} else {
|
|
445
|
+
if (key !== void 0 || depsMap.has(void 0)) {
|
|
446
|
+
run(depsMap.get(key));
|
|
447
|
+
}
|
|
448
|
+
if (isArrayIndex) {
|
|
449
|
+
run(depsMap.get(ARRAY_ITERATE_KEY$1));
|
|
450
|
+
}
|
|
451
|
+
switch (type) {
|
|
452
|
+
case TriggerOpTypes.ADD:
|
|
453
|
+
if (!targetIsArray) {
|
|
454
|
+
run(depsMap.get(ITERATE_KEY$1));
|
|
455
|
+
if (isMap$1(target)) {
|
|
456
|
+
run(depsMap.get(MAP_KEY_ITERATE_KEY$1));
|
|
457
|
+
}
|
|
458
|
+
} else if (isArrayIndex) {
|
|
459
|
+
run(depsMap.get("length"));
|
|
460
|
+
}
|
|
461
|
+
break;
|
|
462
|
+
case TriggerOpTypes.DELETE:
|
|
463
|
+
if (!targetIsArray) {
|
|
464
|
+
run(depsMap.get(ITERATE_KEY$1));
|
|
465
|
+
if (isMap$1(target)) {
|
|
466
|
+
run(depsMap.get(MAP_KEY_ITERATE_KEY$1));
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
break;
|
|
470
|
+
case TriggerOpTypes.SET:
|
|
471
|
+
if (isMap$1(target)) {
|
|
472
|
+
run(depsMap.get(ITERATE_KEY$1));
|
|
473
|
+
}
|
|
474
|
+
break;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
_PropertyReactivity._targetMap = /* @__PURE__ */ new WeakMap();
|
|
482
|
+
let PropertyReactivity = _PropertyReactivity;
|
|
483
|
+
const arrayInstrumentations$1 = {
|
|
484
|
+
__proto__: null,
|
|
485
|
+
/**
|
|
486
|
+
* 返回一个迭代器,用于遍历数组的响应式值。
|
|
487
|
+
*
|
|
488
|
+
* 实现了以下功能:
|
|
489
|
+
* 1. 创建数组的迭代器
|
|
490
|
+
* 2. 自动将迭代的值转换为响应式
|
|
491
|
+
* 3. 自动追踪数组的访问
|
|
492
|
+
*
|
|
493
|
+
* @returns 数组的迭代器
|
|
494
|
+
*/
|
|
495
|
+
[Symbol.iterator]() {
|
|
496
|
+
return iterator$1(this, Symbol.iterator, toReactive$1);
|
|
497
|
+
},
|
|
498
|
+
/**
|
|
499
|
+
* 连接数组并返回新数组。
|
|
500
|
+
*
|
|
501
|
+
* 实现了以下功能:
|
|
502
|
+
* 1. 处理响应式数组的连接
|
|
503
|
+
* 2. 自动将参数中的数组转换为响应式
|
|
504
|
+
* 3. 保持原始值的引用
|
|
505
|
+
*
|
|
506
|
+
* @param args 要连接的数组或值
|
|
507
|
+
* @returns 连接后的新数组
|
|
508
|
+
*/
|
|
509
|
+
concat(...args) {
|
|
510
|
+
return reactiveReadArray$1(this).concat(
|
|
511
|
+
...args.map((x) => isArray$1(x) ? reactiveReadArray$1(x) : x)
|
|
512
|
+
);
|
|
513
|
+
},
|
|
514
|
+
/**
|
|
515
|
+
* 返回一个迭代器,用于遍历数组的键值对。
|
|
516
|
+
*
|
|
517
|
+
* 实现了以下功能:
|
|
518
|
+
* 1. 创建数组的键值对迭代器
|
|
519
|
+
* 2. 自动将值转换为响应式
|
|
520
|
+
* 3. 自动追踪数组的访问
|
|
521
|
+
*
|
|
522
|
+
* @returns 数组的键值对迭代器
|
|
523
|
+
*/
|
|
524
|
+
entries() {
|
|
525
|
+
return iterator$1(this, "entries", (value) => {
|
|
526
|
+
value[1] = toReactive$1(value[1]);
|
|
527
|
+
return value;
|
|
528
|
+
});
|
|
529
|
+
},
|
|
530
|
+
/**
|
|
531
|
+
* 测试数组中的所有元素是否都通过了指定函数的测试。
|
|
532
|
+
*
|
|
533
|
+
* 实现了以下功能:
|
|
534
|
+
* 1. 遍历数组元素
|
|
535
|
+
* 2. 对每个元素执行测试函数
|
|
536
|
+
* 3. 自动追踪数组的访问
|
|
537
|
+
* 4. 处理响应式值的测试
|
|
538
|
+
*
|
|
539
|
+
* @param fn 测试函数
|
|
540
|
+
* @param thisArg 测试函数的 this 值
|
|
541
|
+
* @returns 如果所有元素都通过测试则返回 true,否则返回 false
|
|
542
|
+
*/
|
|
543
|
+
every(fn, thisArg) {
|
|
544
|
+
return apply$1(this, "every", fn, thisArg, void 0, arguments);
|
|
545
|
+
},
|
|
546
|
+
/**
|
|
547
|
+
* 创建一个新数组,包含通过指定函数测试的所有元素。
|
|
548
|
+
*
|
|
549
|
+
* 实现了以下功能:
|
|
550
|
+
* 1. 遍历数组元素
|
|
551
|
+
* 2. 对每个元素执行测试函数
|
|
552
|
+
* 3. 自动追踪数组的访问
|
|
553
|
+
* 4. 自动将结果转换为响应式
|
|
554
|
+
*
|
|
555
|
+
* @param fn 测试函数
|
|
556
|
+
* @param thisArg 测试函数的 this 值
|
|
557
|
+
* @returns 包含通过测试的元素的新数组
|
|
558
|
+
*/
|
|
559
|
+
filter(fn, thisArg) {
|
|
560
|
+
return apply$1(this, "filter", fn, thisArg, (v) => v.map(toReactive$1), arguments);
|
|
561
|
+
},
|
|
562
|
+
/**
|
|
563
|
+
* 返回数组中满足指定测试函数的第一个元素。
|
|
564
|
+
*
|
|
565
|
+
* 实现了以下功能:
|
|
566
|
+
* 1. 遍历数组元素
|
|
567
|
+
* 2. 对每个元素执行测试函数
|
|
568
|
+
* 3. 自动追踪数组的访问
|
|
569
|
+
* 4. 自动将结果转换为响应式
|
|
570
|
+
*
|
|
571
|
+
* @param fn 测试函数
|
|
572
|
+
* @param thisArg 测试函数的 this 值
|
|
573
|
+
* @returns 第一个满足测试的元素,如果没有则返回 undefined
|
|
574
|
+
*/
|
|
575
|
+
find(fn, thisArg) {
|
|
576
|
+
return apply$1(this, "find", fn, thisArg, toReactive$1, arguments);
|
|
577
|
+
},
|
|
578
|
+
/**
|
|
579
|
+
* 返回数组中满足指定测试函数的第一个元素的索引。
|
|
580
|
+
*
|
|
581
|
+
* 实现了以下功能:
|
|
582
|
+
* 1. 遍历数组元素
|
|
583
|
+
* 2. 对每个元素执行测试函数
|
|
584
|
+
* 3. 自动追踪数组的访问
|
|
585
|
+
* 4. 处理响应式值的查找
|
|
586
|
+
*
|
|
587
|
+
* @param fn 测试函数
|
|
588
|
+
* @param thisArg 测试函数的 this 值
|
|
589
|
+
* @returns 第一个满足测试的元素的索引,如果没有则返回 -1
|
|
590
|
+
*/
|
|
591
|
+
findIndex(fn, thisArg) {
|
|
592
|
+
return apply$1(this, "findIndex", fn, thisArg, void 0, arguments);
|
|
593
|
+
},
|
|
594
|
+
/**
|
|
595
|
+
* 返回数组中满足指定测试函数的最后一个元素。
|
|
596
|
+
*
|
|
597
|
+
* 实现了以下功能:
|
|
598
|
+
* 1. 从后向前遍历数组元素
|
|
599
|
+
* 2. 对每个元素执行测试函数
|
|
600
|
+
* 3. 自动追踪数组的访问
|
|
601
|
+
* 4. 自动将结果转换为响应式
|
|
602
|
+
*
|
|
603
|
+
* @param fn 测试函数
|
|
604
|
+
* @param thisArg 测试函数的 this 值
|
|
605
|
+
* @returns 最后一个满足测试的元素,如果没有则返回 undefined
|
|
606
|
+
*/
|
|
607
|
+
findLast(fn, thisArg) {
|
|
608
|
+
return apply$1(this, "findLast", fn, thisArg, toReactive$1, arguments);
|
|
609
|
+
},
|
|
610
|
+
/**
|
|
611
|
+
* 返回数组中满足指定测试函数的最后一个元素的索引。
|
|
612
|
+
*
|
|
613
|
+
* 实现了以下功能:
|
|
614
|
+
* 1. 从后向前遍历数组元素
|
|
615
|
+
* 2. 对每个元素执行测试函数
|
|
616
|
+
* 3. 自动追踪数组的访问
|
|
617
|
+
* 4. 处理响应式值的查找
|
|
618
|
+
*
|
|
619
|
+
* @param fn 测试函数
|
|
620
|
+
* @param thisArg 测试函数的 this 值
|
|
621
|
+
* @returns 最后一个满足测试的元素的索引,如果没有则返回 -1
|
|
622
|
+
*/
|
|
623
|
+
findLastIndex(fn, thisArg) {
|
|
624
|
+
return apply$1(this, "findLastIndex", fn, thisArg, void 0, arguments);
|
|
625
|
+
},
|
|
626
|
+
// flat, flatMap 可以从 ARRAY_ITERATE 中受益,但实现起来不太直接
|
|
627
|
+
/**
|
|
628
|
+
* 对数组中的每个元素执行指定函数。
|
|
629
|
+
*
|
|
630
|
+
* 实现了以下功能:
|
|
631
|
+
* 1. 遍历数组元素
|
|
632
|
+
* 2. 对每个元素执行回调函数
|
|
633
|
+
* 3. 自动追踪数组的访问
|
|
634
|
+
* 4. 处理响应式值的遍历
|
|
635
|
+
*
|
|
636
|
+
* @param fn 回调函数
|
|
637
|
+
* @param thisArg 回调函数的 this 值
|
|
638
|
+
*/
|
|
639
|
+
forEach(fn, thisArg) {
|
|
640
|
+
return apply$1(this, "forEach", fn, thisArg, void 0, arguments);
|
|
641
|
+
},
|
|
642
|
+
/**
|
|
643
|
+
* 判断数组是否包含指定元素。
|
|
644
|
+
*
|
|
645
|
+
* 实现了以下功能:
|
|
646
|
+
* 1. 处理响应式值的查找
|
|
647
|
+
* 2. 自动追踪数组的访问
|
|
648
|
+
* 3. 处理代理对象的查找
|
|
649
|
+
*
|
|
650
|
+
* @param args 要查找的元素
|
|
651
|
+
* @returns 如果数组包含该元素则返回 true,否则返回 false
|
|
652
|
+
*/
|
|
653
|
+
includes(...args) {
|
|
654
|
+
return searchProxy$1(this, "includes", args);
|
|
655
|
+
},
|
|
656
|
+
/**
|
|
657
|
+
* 返回数组中指定元素第一次出现的索引。
|
|
658
|
+
*
|
|
659
|
+
* 实现了以下功能:
|
|
660
|
+
* 1. 处理响应式值的查找
|
|
661
|
+
* 2. 自动追踪数组的访问
|
|
662
|
+
* 3. 处理代理对象的查找
|
|
663
|
+
*
|
|
664
|
+
* @param args 要查找的元素
|
|
665
|
+
* @returns 元素第一次出现的索引,如果没有则返回 -1
|
|
666
|
+
*/
|
|
667
|
+
indexOf(...args) {
|
|
668
|
+
return searchProxy$1(this, "indexOf", args);
|
|
669
|
+
},
|
|
670
|
+
/**
|
|
671
|
+
* 将数组的所有元素连接成一个字符串。
|
|
672
|
+
*
|
|
673
|
+
* 实现了以下功能:
|
|
674
|
+
* 1. 处理响应式数组的连接
|
|
675
|
+
* 2. 自动追踪数组的访问
|
|
676
|
+
* 3. 保持原始值的引用
|
|
677
|
+
*
|
|
678
|
+
* @param separator 分隔符
|
|
679
|
+
* @returns 连接后的字符串
|
|
680
|
+
*/
|
|
681
|
+
join(separator) {
|
|
682
|
+
return reactiveReadArray$1(this).join(separator);
|
|
683
|
+
},
|
|
684
|
+
// keys() 迭代器只读取 length,不需要优化
|
|
685
|
+
/**
|
|
686
|
+
* 返回数组中指定元素最后一次出现的索引。
|
|
687
|
+
*
|
|
688
|
+
* 实现了以下功能:
|
|
689
|
+
* 1. 处理响应式值的查找
|
|
690
|
+
* 2. 自动追踪数组的访问
|
|
691
|
+
* 3. 处理代理对象的查找
|
|
692
|
+
*
|
|
693
|
+
* @param args 要查找的元素
|
|
694
|
+
* @returns 元素最后一次出现的索引,如果没有则返回 -1
|
|
695
|
+
*/
|
|
696
|
+
lastIndexOf(...args) {
|
|
697
|
+
return searchProxy$1(this, "lastIndexOf", args);
|
|
698
|
+
},
|
|
699
|
+
/**
|
|
700
|
+
* 创建一个新数组,包含对原数组每个元素调用指定函数的结果。
|
|
701
|
+
*
|
|
702
|
+
* 实现了以下功能:
|
|
703
|
+
* 1. 遍历数组元素
|
|
704
|
+
* 2. 对每个元素执行映射函数
|
|
705
|
+
* 3. 自动追踪数组的访问
|
|
706
|
+
* 4. 处理响应式值的映射
|
|
707
|
+
*
|
|
708
|
+
* @param fn 映射函数
|
|
709
|
+
* @param thisArg 映射函数的 this 值
|
|
710
|
+
* @returns 包含映射结果的新数组
|
|
711
|
+
*/
|
|
712
|
+
map(fn, thisArg) {
|
|
713
|
+
return apply$1(this, "map", fn, thisArg, void 0, arguments);
|
|
714
|
+
},
|
|
715
|
+
/**
|
|
716
|
+
* 移除数组的最后一个元素并返回该元素。
|
|
717
|
+
*
|
|
718
|
+
* 实现了以下功能:
|
|
719
|
+
* 1. 移除最后一个元素
|
|
720
|
+
* 2. 避免跟踪长度变化
|
|
721
|
+
* 3. 处理响应式值的移除
|
|
722
|
+
*
|
|
723
|
+
* @returns 被移除的元素
|
|
724
|
+
*/
|
|
725
|
+
pop() {
|
|
726
|
+
return noTracking$1(this, "pop");
|
|
727
|
+
},
|
|
728
|
+
/**
|
|
729
|
+
* 向数组末尾添加一个或多个元素。
|
|
730
|
+
*
|
|
731
|
+
* 实现了以下功能:
|
|
732
|
+
* 1. 添加新元素
|
|
733
|
+
* 2. 避免跟踪长度变化
|
|
734
|
+
* 3. 处理响应式值的添加
|
|
735
|
+
*
|
|
736
|
+
* @param args 要添加的元素
|
|
737
|
+
* @returns 数组的新长度
|
|
738
|
+
*/
|
|
739
|
+
push(...args) {
|
|
740
|
+
return noTracking$1(this, "push", args);
|
|
741
|
+
},
|
|
742
|
+
/**
|
|
743
|
+
* 对数组中的每个元素执行累加器函数。
|
|
744
|
+
*
|
|
745
|
+
* 实现了以下功能:
|
|
746
|
+
* 1. 从左到右遍历数组元素
|
|
747
|
+
* 2. 对每个元素执行累加器函数
|
|
748
|
+
* 3. 自动追踪数组的访问
|
|
749
|
+
* 4. 处理响应式值的累加
|
|
750
|
+
*
|
|
751
|
+
* @param fn 累加器函数
|
|
752
|
+
* @param args 初始值(可选)
|
|
753
|
+
* @returns 累加的结果
|
|
754
|
+
*/
|
|
755
|
+
reduce(fn, ...args) {
|
|
756
|
+
return reduce$1(this, "reduce", fn, args);
|
|
757
|
+
},
|
|
758
|
+
/**
|
|
759
|
+
* 从右到左对数组中的每个元素执行累加器函数。
|
|
760
|
+
*
|
|
761
|
+
* 实现了以下功能:
|
|
762
|
+
* 1. 从右到左遍历数组元素
|
|
763
|
+
* 2. 对每个元素执行累加器函数
|
|
764
|
+
* 3. 自动追踪数组的访问
|
|
765
|
+
* 4. 处理响应式值的累加
|
|
766
|
+
*
|
|
767
|
+
* @param fn 累加器函数
|
|
768
|
+
* @param args 初始值(可选)
|
|
769
|
+
* @returns 累加的结果
|
|
770
|
+
*/
|
|
771
|
+
reduceRight(fn, ...args) {
|
|
772
|
+
return reduce$1(this, "reduceRight", fn, args);
|
|
773
|
+
},
|
|
774
|
+
/**
|
|
775
|
+
* 移除数组的第一个元素并返回该元素。
|
|
776
|
+
*
|
|
777
|
+
* 实现了以下功能:
|
|
778
|
+
* 1. 移除第一个元素
|
|
779
|
+
* 2. 避免跟踪长度变化
|
|
780
|
+
* 3. 处理响应式值的移除
|
|
781
|
+
*
|
|
782
|
+
* @returns 被移除的元素
|
|
783
|
+
*/
|
|
784
|
+
shift() {
|
|
785
|
+
return noTracking$1(this, "shift");
|
|
786
|
+
},
|
|
787
|
+
// slice 可以使用 ARRAY_ITERATE,但似乎也需要范围追踪
|
|
788
|
+
/**
|
|
789
|
+
* 测试数组中的某些元素是否通过了指定函数的测试。
|
|
790
|
+
*
|
|
791
|
+
* 实现了以下功能:
|
|
792
|
+
* 1. 遍历数组元素
|
|
793
|
+
* 2. 对每个元素执行测试函数
|
|
794
|
+
* 3. 自动追踪数组的访问
|
|
795
|
+
* 4. 处理响应式值的测试
|
|
796
|
+
*
|
|
797
|
+
* @param fn 测试函数
|
|
798
|
+
* @param thisArg 测试函数的 this 值
|
|
799
|
+
* @returns 如果有元素通过测试则返回 true,否则返回 false
|
|
800
|
+
*/
|
|
801
|
+
some(fn, thisArg) {
|
|
802
|
+
return apply$1(this, "some", fn, thisArg, void 0, arguments);
|
|
803
|
+
},
|
|
804
|
+
/**
|
|
805
|
+
* 通过删除或替换现有元素或添加新元素来修改数组。
|
|
806
|
+
*
|
|
807
|
+
* 实现了以下功能:
|
|
808
|
+
* 1. 修改数组内容
|
|
809
|
+
* 2. 避免跟踪长度变化
|
|
810
|
+
* 3. 处理响应式值的修改
|
|
811
|
+
*
|
|
812
|
+
* @param args 要删除的起始索引、要删除的元素数量和要添加的元素
|
|
813
|
+
* @returns 包含被删除元素的新数组
|
|
814
|
+
*/
|
|
815
|
+
splice(...args) {
|
|
816
|
+
return noTracking$1(this, "splice", args);
|
|
817
|
+
},
|
|
818
|
+
/**
|
|
819
|
+
* 返回一个新数组,包含原数组的反转副本。
|
|
820
|
+
*
|
|
821
|
+
* 实现了以下功能:
|
|
822
|
+
* 1. 创建数组的反转副本
|
|
823
|
+
* 2. 自动将结果转换为响应式
|
|
824
|
+
* 3. 保持原始值的引用
|
|
825
|
+
*
|
|
826
|
+
* @returns 反转后的新数组
|
|
827
|
+
*/
|
|
828
|
+
toReversed() {
|
|
829
|
+
return reactiveReadArray$1(this).toReversed();
|
|
830
|
+
},
|
|
831
|
+
/**
|
|
832
|
+
* 返回一个新数组,包含原数组的排序副本。
|
|
833
|
+
*
|
|
834
|
+
* 实现了以下功能:
|
|
835
|
+
* 1. 创建数组的排序副本
|
|
836
|
+
* 2. 自动将结果转换为响应式
|
|
837
|
+
* 3. 保持原始值的引用
|
|
838
|
+
*
|
|
839
|
+
* @param comparer 比较函数
|
|
840
|
+
* @returns 排序后的新数组
|
|
841
|
+
*/
|
|
842
|
+
toSorted(comparer) {
|
|
843
|
+
return reactiveReadArray$1(this).toSorted(comparer);
|
|
844
|
+
},
|
|
845
|
+
/**
|
|
846
|
+
* 返回一个新数组,包含原数组的切片副本。
|
|
847
|
+
*
|
|
848
|
+
* 实现了以下功能:
|
|
849
|
+
* 1. 创建数组的切片副本
|
|
850
|
+
* 2. 自动将结果转换为响应式
|
|
851
|
+
* 3. 保持原始值的引用
|
|
852
|
+
*
|
|
853
|
+
* @param args 起始索引和结束索引
|
|
854
|
+
* @returns 切片后的新数组
|
|
855
|
+
*/
|
|
856
|
+
toSpliced(...args) {
|
|
857
|
+
return reactiveReadArray$1(this).toSpliced(...args);
|
|
858
|
+
},
|
|
859
|
+
/**
|
|
860
|
+
* 向数组开头添加一个或多个元素。
|
|
861
|
+
*
|
|
862
|
+
* 实现了以下功能:
|
|
863
|
+
* 1. 添加新元素
|
|
864
|
+
* 2. 避免跟踪长度变化
|
|
865
|
+
* 3. 处理响应式值的添加
|
|
866
|
+
*
|
|
867
|
+
* @param args 要添加的元素
|
|
868
|
+
* @returns 数组的新长度
|
|
869
|
+
*/
|
|
870
|
+
unshift(...args) {
|
|
871
|
+
return noTracking$1(this, "unshift", args);
|
|
872
|
+
},
|
|
873
|
+
/**
|
|
874
|
+
* 返回一个迭代器,用于遍历数组的值。
|
|
875
|
+
*
|
|
876
|
+
* 实现了以下功能:
|
|
877
|
+
* 1. 创建数组的值迭代器
|
|
878
|
+
* 2. 自动将迭代的值转换为响应式
|
|
879
|
+
* 3. 自动追踪数组的访问
|
|
880
|
+
*
|
|
881
|
+
* @returns 数组的值迭代器
|
|
882
|
+
*/
|
|
883
|
+
values() {
|
|
884
|
+
return iterator$1(this, "values", toReactive$1);
|
|
885
|
+
}
|
|
886
|
+
};
|
|
887
|
+
function iterator$1(self, method, wrapValue) {
|
|
888
|
+
const arr = shallowReadArray$1(self);
|
|
889
|
+
const iter = arr[method]();
|
|
890
|
+
if (arr !== self) {
|
|
891
|
+
iter._next = iter.next;
|
|
892
|
+
iter.next = () => {
|
|
893
|
+
const result = iter._next();
|
|
894
|
+
if (result.value) {
|
|
895
|
+
result.value = wrapValue(result.value);
|
|
896
|
+
}
|
|
897
|
+
return result;
|
|
898
|
+
};
|
|
899
|
+
}
|
|
900
|
+
return iter;
|
|
901
|
+
}
|
|
902
|
+
function shallowReadArray$1(arr) {
|
|
903
|
+
PropertyReactivity.track(arr = toRaw$1(arr), TrackOpTypes.ITERATE, ARRAY_ITERATE_KEY$1);
|
|
904
|
+
return arr;
|
|
905
|
+
}
|
|
906
|
+
function reactiveReadArray$1(array) {
|
|
907
|
+
const raw = toRaw$1(array);
|
|
908
|
+
if (raw === array) return raw;
|
|
909
|
+
PropertyReactivity.track(raw, TrackOpTypes.ITERATE, ARRAY_ITERATE_KEY$1);
|
|
910
|
+
return raw.map(toReactive$1);
|
|
911
|
+
}
|
|
912
|
+
function apply$1(self, method, fn, thisArg, wrappedRetFn, args) {
|
|
913
|
+
const arr = shallowReadArray$1(self);
|
|
914
|
+
const needsWrap = arr !== self;
|
|
915
|
+
const methodFn = arr[method];
|
|
916
|
+
if (methodFn !== Array.prototype[method]) {
|
|
917
|
+
const result2 = methodFn.apply(self, args);
|
|
918
|
+
return needsWrap ? toReactive$1(result2) : result2;
|
|
919
|
+
}
|
|
920
|
+
let wrappedFn = fn;
|
|
921
|
+
if (arr !== self) {
|
|
922
|
+
if (needsWrap) {
|
|
923
|
+
wrappedFn = function(item, index) {
|
|
924
|
+
return fn.call(this, toReactive$1(item), index, self);
|
|
925
|
+
};
|
|
926
|
+
} else if (fn.length > 2) {
|
|
927
|
+
wrappedFn = function(item, index) {
|
|
928
|
+
return fn.call(this, item, index, self);
|
|
929
|
+
};
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
const result = methodFn.call(arr, wrappedFn, thisArg);
|
|
933
|
+
return needsWrap && wrappedRetFn ? wrappedRetFn(result) : result;
|
|
934
|
+
}
|
|
935
|
+
function reduce$1(self, method, fn, args) {
|
|
936
|
+
const arr = shallowReadArray$1(self);
|
|
937
|
+
let wrappedFn = fn;
|
|
938
|
+
if (arr !== self) {
|
|
939
|
+
wrappedFn = function(acc, item, index) {
|
|
940
|
+
return fn.call(this, acc, toReactive$1(item), index, self);
|
|
941
|
+
};
|
|
942
|
+
}
|
|
943
|
+
return arr[method](wrappedFn, ...args);
|
|
944
|
+
}
|
|
945
|
+
function searchProxy$1(self, method, args) {
|
|
946
|
+
const arr = toRaw$1(self);
|
|
947
|
+
PropertyReactivity.track(arr, TrackOpTypes.ITERATE, ARRAY_ITERATE_KEY$1);
|
|
948
|
+
const res = arr[method](...args);
|
|
949
|
+
if ((res === -1 || res === false) && isProxy$1(args[0])) {
|
|
950
|
+
args[0] = toRaw$1(args[0]);
|
|
951
|
+
return arr[method](...args);
|
|
952
|
+
}
|
|
953
|
+
return res;
|
|
954
|
+
}
|
|
955
|
+
function noTracking$1(self, method, args = []) {
|
|
956
|
+
const res = batchRun(
|
|
957
|
+
() => noTrack(
|
|
958
|
+
() => toRaw$1(self)[method].apply(self, args)
|
|
959
|
+
)
|
|
960
|
+
);
|
|
961
|
+
return res;
|
|
962
|
+
}
|
|
963
|
+
var _a, _b;
|
|
964
|
+
function ref$1(value) {
|
|
965
|
+
if (isRef$1(value)) {
|
|
966
|
+
return value;
|
|
967
|
+
}
|
|
968
|
+
return new RefReactivity(value);
|
|
969
|
+
}
|
|
970
|
+
function isRef$1(r) {
|
|
971
|
+
return r ? r[ReactiveFlags.IS_REF] === true : false;
|
|
972
|
+
}
|
|
973
|
+
class RefReactivity extends (_b = Reactivity, _a = ReactiveFlags.IS_REF, _b) {
|
|
974
|
+
/**
|
|
975
|
+
* 创建引用反应式节点。
|
|
976
|
+
*
|
|
977
|
+
* @param value 要包装的值
|
|
978
|
+
*/
|
|
979
|
+
constructor(value) {
|
|
980
|
+
super();
|
|
981
|
+
this[_a] = true;
|
|
982
|
+
this._rawValue = toRaw$1(value);
|
|
983
|
+
this._value = toReactive$1(value);
|
|
984
|
+
}
|
|
985
|
+
/**
|
|
986
|
+
* 获取引用的值。
|
|
987
|
+
*
|
|
988
|
+
* 取值时会:
|
|
989
|
+
* 1. 建立依赖关系
|
|
990
|
+
* 2. 返回当前值
|
|
991
|
+
*/
|
|
992
|
+
get value() {
|
|
993
|
+
this.track();
|
|
994
|
+
return this._value;
|
|
995
|
+
}
|
|
996
|
+
/**
|
|
997
|
+
* 设置引用的值。
|
|
998
|
+
*
|
|
999
|
+
* 设置值时会:
|
|
1000
|
+
* 1. 比较新旧值是否发生变化
|
|
1001
|
+
* 2. 如果值发生变化,则:
|
|
1002
|
+
* - 触发更新通知
|
|
1003
|
+
* - 更新原始值
|
|
1004
|
+
* - 更新响应式值
|
|
1005
|
+
*
|
|
1006
|
+
* @param v 要设置的新值
|
|
1007
|
+
*/
|
|
1008
|
+
set value(v) {
|
|
1009
|
+
const oldValue = this._rawValue;
|
|
1010
|
+
const newValue = toRaw$1(v);
|
|
1011
|
+
if (!hasChanged$1(oldValue, newValue)) return;
|
|
1012
|
+
batchRun(() => {
|
|
1013
|
+
this.trigger();
|
|
1014
|
+
this._rawValue = newValue;
|
|
1015
|
+
this._value = toReactive$1(newValue);
|
|
1016
|
+
});
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
let BaseReactiveHandler$1 = class BaseReactiveHandler {
|
|
1020
|
+
/**
|
|
1021
|
+
* 获取对象的属性值。
|
|
1022
|
+
*
|
|
1023
|
+
* 实现了以下功能:
|
|
1024
|
+
* 1. 响应式对象标识检查
|
|
1025
|
+
* 2. 原始对象获取
|
|
1026
|
+
* 3. 数组方法拦截
|
|
1027
|
+
* 4. 属性依赖追踪
|
|
1028
|
+
* 5. 值的自动解包
|
|
1029
|
+
* 6. 对象的自动响应式转换
|
|
1030
|
+
*
|
|
1031
|
+
* @param target 被代理的原始对象
|
|
1032
|
+
* @param key 要获取的属性名
|
|
1033
|
+
* @param receiver 代理对象本身
|
|
1034
|
+
* @returns 获取到的属性值
|
|
1035
|
+
*/
|
|
1036
|
+
get(target, key, receiver) {
|
|
1037
|
+
if (key === ReactiveFlags.IS_REACTIVE) {
|
|
1038
|
+
return true;
|
|
1039
|
+
} else if (key === ReactiveFlags.RAW) {
|
|
1040
|
+
if (receiver === reactiveMap$1.get(target) || Object.getPrototypeOf(target) === Object.getPrototypeOf(receiver)) {
|
|
1041
|
+
return target;
|
|
1042
|
+
}
|
|
1043
|
+
return;
|
|
1044
|
+
}
|
|
1045
|
+
const targetIsArray = isArray$1(target);
|
|
1046
|
+
let fn;
|
|
1047
|
+
if (targetIsArray && (fn = arrayInstrumentations$1[key])) {
|
|
1048
|
+
return fn;
|
|
1049
|
+
}
|
|
1050
|
+
if (key === "hasOwnProperty") {
|
|
1051
|
+
return hasOwnProperty$2;
|
|
1052
|
+
}
|
|
1053
|
+
const res = Reflect.get(
|
|
1054
|
+
target,
|
|
1055
|
+
key,
|
|
1056
|
+
isRef$1(target) ? target : receiver
|
|
1057
|
+
);
|
|
1058
|
+
if (isSymbol$1(key) ? builtInSymbols$1.has(key) : isNonTrackableKeys$1(key)) {
|
|
1059
|
+
return res;
|
|
1060
|
+
}
|
|
1061
|
+
PropertyReactivity.track(target, TrackOpTypes.GET, key);
|
|
1062
|
+
if (isRef$1(res)) {
|
|
1063
|
+
return targetIsArray && isIntegerKey$1(key) ? res : res.value;
|
|
1064
|
+
}
|
|
1065
|
+
if (isObject$1(res)) {
|
|
1066
|
+
return reactive$1(res);
|
|
1067
|
+
}
|
|
1068
|
+
return res;
|
|
1069
|
+
}
|
|
1070
|
+
};
|
|
1071
|
+
let MutableReactiveHandler$1 = class MutableReactiveHandler extends BaseReactiveHandler$1 {
|
|
1072
|
+
/**
|
|
1073
|
+
* 设置对象的属性值。
|
|
1074
|
+
*
|
|
1075
|
+
* 实现了以下功能:
|
|
1076
|
+
* 1. 值的原始化处理
|
|
1077
|
+
* 2. ref 值的特殊处理
|
|
1078
|
+
* 3. 属性变更通知
|
|
1079
|
+
* 4. 数组长度的特殊处理
|
|
1080
|
+
*
|
|
1081
|
+
* @param target 被代理的原始对象
|
|
1082
|
+
* @param key 要设置的属性名
|
|
1083
|
+
* @param value 要设置的新值
|
|
1084
|
+
* @param receiver 代理对象本身
|
|
1085
|
+
* @returns 设置是否成功
|
|
1086
|
+
*/
|
|
1087
|
+
set(target, key, value, receiver) {
|
|
1088
|
+
let oldValue = target[key];
|
|
1089
|
+
oldValue = toRaw$1(oldValue);
|
|
1090
|
+
value = toRaw$1(value);
|
|
1091
|
+
if (!isArray$1(target) && isRef$1(oldValue) && !isRef$1(value)) {
|
|
1092
|
+
oldValue.value = value;
|
|
1093
|
+
return true;
|
|
1094
|
+
}
|
|
1095
|
+
const hadKey = isArray$1(target) && isIntegerKey$1(key) ? Number(key) < target.length : hasOwn$1(target, key);
|
|
1096
|
+
const result = Reflect.set(
|
|
1097
|
+
target,
|
|
1098
|
+
key,
|
|
1099
|
+
value,
|
|
1100
|
+
isRef$1(target) ? target : receiver
|
|
1101
|
+
);
|
|
1102
|
+
if (target === toRaw$1(receiver)) {
|
|
1103
|
+
if (!hadKey) {
|
|
1104
|
+
PropertyReactivity.trigger(target, TriggerOpTypes.ADD, key, value);
|
|
1105
|
+
} else if (hasChanged$1(value, oldValue)) {
|
|
1106
|
+
PropertyReactivity.trigger(target, TriggerOpTypes.SET, key, value, oldValue);
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
return result;
|
|
1110
|
+
}
|
|
1111
|
+
/**
|
|
1112
|
+
* 删除对象的属性。
|
|
1113
|
+
*
|
|
1114
|
+
* 实现了以下功能:
|
|
1115
|
+
* 1. 属性删除操作
|
|
1116
|
+
* 2. 删除后的变更通知
|
|
1117
|
+
*
|
|
1118
|
+
* @param target 被代理的原始对象
|
|
1119
|
+
* @param key 要删除的属性名
|
|
1120
|
+
* @returns 删除是否成功
|
|
1121
|
+
*/
|
|
1122
|
+
deleteProperty(target, key) {
|
|
1123
|
+
const hadKey = hasOwn$1(target, key);
|
|
1124
|
+
const oldValue = target[key];
|
|
1125
|
+
const result = Reflect.deleteProperty(target, key);
|
|
1126
|
+
if (result && hadKey) {
|
|
1127
|
+
PropertyReactivity.trigger(target, TriggerOpTypes.DELETE, key, void 0, oldValue);
|
|
1128
|
+
}
|
|
1129
|
+
return result;
|
|
1130
|
+
}
|
|
1131
|
+
/**
|
|
1132
|
+
* 检查对象是否包含某个属性。
|
|
1133
|
+
*
|
|
1134
|
+
* 实现了以下功能:
|
|
1135
|
+
* 1. 属性存在性检查
|
|
1136
|
+
* 2. 属性访问依赖追踪
|
|
1137
|
+
*
|
|
1138
|
+
* @param target 被代理的原始对象
|
|
1139
|
+
* @param key 要检查的属性名
|
|
1140
|
+
* @returns 属性是否存在
|
|
1141
|
+
*/
|
|
1142
|
+
has(target, key) {
|
|
1143
|
+
const result = Reflect.has(target, key);
|
|
1144
|
+
if (!isSymbol$1(key) || !builtInSymbols$1.has(key)) {
|
|
1145
|
+
PropertyReactivity.track(target, TrackOpTypes.HAS, key);
|
|
1146
|
+
}
|
|
1147
|
+
return result;
|
|
1148
|
+
}
|
|
1149
|
+
/**
|
|
1150
|
+
* 获取对象的所有属性名。
|
|
1151
|
+
*
|
|
1152
|
+
* 实现了以下功能:
|
|
1153
|
+
* 1. 属性遍历
|
|
1154
|
+
* 2. 遍历操作的依赖追踪
|
|
1155
|
+
*
|
|
1156
|
+
* @param target 被代理的原始对象
|
|
1157
|
+
* @returns 对象的所有属性名数组
|
|
1158
|
+
*/
|
|
1159
|
+
ownKeys(target) {
|
|
1160
|
+
PropertyReactivity.track(
|
|
1161
|
+
target,
|
|
1162
|
+
TrackOpTypes.ITERATE,
|
|
1163
|
+
isArray$1(target) ? "length" : ITERATE_KEY$1
|
|
1164
|
+
);
|
|
1165
|
+
return Reflect.ownKeys(target);
|
|
1166
|
+
}
|
|
1167
|
+
};
|
|
1168
|
+
const mutableHandlers$1 = new MutableReactiveHandler$1();
|
|
1169
|
+
function hasOwnProperty$2(key) {
|
|
1170
|
+
if (!isSymbol$1(key)) key = String(key);
|
|
1171
|
+
const obj = toRaw$1(this);
|
|
1172
|
+
PropertyReactivity.track(obj, TrackOpTypes.HAS, key);
|
|
1173
|
+
return obj.hasOwnProperty(key);
|
|
1174
|
+
}
|
|
1175
|
+
const builtInSymbols$1 = new Set(
|
|
1176
|
+
/* @__PURE__ */ Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller").map((key) => Symbol[key]).filter(isSymbol$1)
|
|
1177
|
+
);
|
|
1178
|
+
const isNonTrackableKeys$1 = /* @__PURE__ */ makeMap$1(`__proto__,__v_isRef,__isVue`);
|
|
1179
|
+
const mutableCollectionHandlers$1 = {
|
|
1180
|
+
get: createInstrumentationGetter$1()
|
|
1181
|
+
};
|
|
1182
|
+
function createInstrumentationGetter$1() {
|
|
1183
|
+
const instrumentations = createInstrumentations$1();
|
|
1184
|
+
return (target, key, receiver) => {
|
|
1185
|
+
if (key === ReactiveFlags.IS_REACTIVE) {
|
|
1186
|
+
return true;
|
|
1187
|
+
} else if (key === ReactiveFlags.RAW) {
|
|
1188
|
+
return target;
|
|
1189
|
+
}
|
|
1190
|
+
return Reflect.get(
|
|
1191
|
+
hasOwn$1(instrumentations, key) && key in target ? instrumentations : target,
|
|
1192
|
+
key,
|
|
1193
|
+
receiver
|
|
1194
|
+
);
|
|
1195
|
+
};
|
|
1196
|
+
}
|
|
1197
|
+
function createInstrumentations$1() {
|
|
1198
|
+
const instrumentations = {
|
|
1199
|
+
/**
|
|
1200
|
+
* 获取 Map 中的值。
|
|
1201
|
+
*
|
|
1202
|
+
* 实现了以下功能:
|
|
1203
|
+
* 1. 支持原始键和响应式键的查找
|
|
1204
|
+
* 2. 自动追踪键的访问
|
|
1205
|
+
* 3. 自动将返回值转换为响应式
|
|
1206
|
+
*
|
|
1207
|
+
* @param key 要查找的键
|
|
1208
|
+
* @returns 找到的值,如果不存在则返回 undefined
|
|
1209
|
+
*/
|
|
1210
|
+
get(key) {
|
|
1211
|
+
const target = this[ReactiveFlags.RAW];
|
|
1212
|
+
const rawTarget = toRaw$1(target);
|
|
1213
|
+
const rawKey = toRaw$1(key);
|
|
1214
|
+
if (hasChanged$1(key, rawKey)) {
|
|
1215
|
+
PropertyReactivity.track(rawTarget, TrackOpTypes.GET, key);
|
|
1216
|
+
}
|
|
1217
|
+
PropertyReactivity.track(rawTarget, TrackOpTypes.GET, rawKey);
|
|
1218
|
+
const { has } = getProto$1(rawTarget);
|
|
1219
|
+
const wrap = toReactive$1;
|
|
1220
|
+
if (has.call(rawTarget, key)) {
|
|
1221
|
+
return wrap(target.get(key));
|
|
1222
|
+
} else if (has.call(rawTarget, rawKey)) {
|
|
1223
|
+
return wrap(target.get(rawKey));
|
|
1224
|
+
} else if (target !== rawTarget) {
|
|
1225
|
+
target.get(key);
|
|
1226
|
+
}
|
|
1227
|
+
},
|
|
1228
|
+
/**
|
|
1229
|
+
* 获取集合的大小。
|
|
1230
|
+
*
|
|
1231
|
+
* 实现了以下功能:
|
|
1232
|
+
* 1. 追踪集合大小的访问
|
|
1233
|
+
* 2. 返回集合的实际大小
|
|
1234
|
+
*/
|
|
1235
|
+
get size() {
|
|
1236
|
+
const target = this[ReactiveFlags.RAW];
|
|
1237
|
+
PropertyReactivity.track(toRaw$1(target), TrackOpTypes.ITERATE, ITERATE_KEY$1);
|
|
1238
|
+
return Reflect.get(target, "size", target);
|
|
1239
|
+
},
|
|
1240
|
+
/**
|
|
1241
|
+
* 检查集合是否包含某个值。
|
|
1242
|
+
*
|
|
1243
|
+
* 实现了以下功能:
|
|
1244
|
+
* 1. 支持原始键和响应式键的检查
|
|
1245
|
+
* 2. 自动追踪键的检查
|
|
1246
|
+
*
|
|
1247
|
+
* @param key 要检查的键
|
|
1248
|
+
* @returns 如果集合包含该键则返回 true,否则返回 false
|
|
1249
|
+
*/
|
|
1250
|
+
has(key) {
|
|
1251
|
+
const target = this[ReactiveFlags.RAW];
|
|
1252
|
+
const rawTarget = toRaw$1(target);
|
|
1253
|
+
const rawKey = toRaw$1(key);
|
|
1254
|
+
if (hasChanged$1(key, rawKey)) {
|
|
1255
|
+
PropertyReactivity.track(rawTarget, TrackOpTypes.HAS, key);
|
|
1256
|
+
}
|
|
1257
|
+
PropertyReactivity.track(rawTarget, TrackOpTypes.HAS, rawKey);
|
|
1258
|
+
return key === rawKey ? target.has(key) : target.has(key) || target.has(rawKey);
|
|
1259
|
+
},
|
|
1260
|
+
/**
|
|
1261
|
+
* 遍历集合中的所有元素。
|
|
1262
|
+
*
|
|
1263
|
+
* 实现了以下功能:
|
|
1264
|
+
* 1. 追踪集合的遍历操作
|
|
1265
|
+
* 2. 自动将遍历的值转换为响应式
|
|
1266
|
+
* 3. 保持回调函数的 this 上下文
|
|
1267
|
+
*
|
|
1268
|
+
* @param callback 遍历回调函数
|
|
1269
|
+
* @param thisArg 回调函数的 this 值
|
|
1270
|
+
*/
|
|
1271
|
+
forEach(callback, thisArg) {
|
|
1272
|
+
const observed = this;
|
|
1273
|
+
const target = observed[ReactiveFlags.RAW];
|
|
1274
|
+
const rawTarget = toRaw$1(target);
|
|
1275
|
+
const wrap = toReactive$1;
|
|
1276
|
+
PropertyReactivity.track(rawTarget, TrackOpTypes.ITERATE, ITERATE_KEY$1);
|
|
1277
|
+
return target.forEach(
|
|
1278
|
+
(value, key) => (
|
|
1279
|
+
// 重要:确保回调函数
|
|
1280
|
+
// 1. 使用响应式 map 作为 this 和第三个参数
|
|
1281
|
+
// 2. 接收到的值应该是相应的响应式/只读版本
|
|
1282
|
+
callback.call(thisArg, wrap(value), wrap(key), observed)
|
|
1283
|
+
)
|
|
1284
|
+
);
|
|
1285
|
+
},
|
|
1286
|
+
/**
|
|
1287
|
+
* 向 Set 中添加值。
|
|
1288
|
+
*
|
|
1289
|
+
* 实现了以下功能:
|
|
1290
|
+
* 1. 自动将值转换为原始值
|
|
1291
|
+
* 2. 避免重复添加
|
|
1292
|
+
* 3. 触发添加操作的通知
|
|
1293
|
+
*
|
|
1294
|
+
* @param value 要添加的值
|
|
1295
|
+
* @returns 集合本身,支持链式调用
|
|
1296
|
+
*/
|
|
1297
|
+
add(value) {
|
|
1298
|
+
value = toRaw$1(value);
|
|
1299
|
+
const target = toRaw$1(this);
|
|
1300
|
+
const proto = getProto$1(target);
|
|
1301
|
+
const hadKey = proto.has.call(target, value);
|
|
1302
|
+
if (!hadKey) {
|
|
1303
|
+
target.add(value);
|
|
1304
|
+
PropertyReactivity.trigger(target, TriggerOpTypes.ADD, value, value);
|
|
1305
|
+
}
|
|
1306
|
+
return this;
|
|
1307
|
+
},
|
|
1308
|
+
/**
|
|
1309
|
+
* 设置 Map 中的值。
|
|
1310
|
+
*
|
|
1311
|
+
* 实现了以下功能:
|
|
1312
|
+
* 1. 自动将值转换为原始值
|
|
1313
|
+
* 2. 支持原始键和响应式键的设置
|
|
1314
|
+
* 3. 触发添加或修改操作的通知
|
|
1315
|
+
*
|
|
1316
|
+
* @param key 要设置的键
|
|
1317
|
+
* @param value 要设置的值
|
|
1318
|
+
* @returns 集合本身,支持链式调用
|
|
1319
|
+
*/
|
|
1320
|
+
set(key, value) {
|
|
1321
|
+
value = toRaw$1(value);
|
|
1322
|
+
const target = toRaw$1(this);
|
|
1323
|
+
const { has, get } = getProto$1(target);
|
|
1324
|
+
let hadKey = has.call(target, key);
|
|
1325
|
+
if (!hadKey) {
|
|
1326
|
+
key = toRaw$1(key);
|
|
1327
|
+
hadKey = has.call(target, key);
|
|
1328
|
+
}
|
|
1329
|
+
const oldValue = get.call(target, key);
|
|
1330
|
+
target.set(key, value);
|
|
1331
|
+
if (!hadKey) {
|
|
1332
|
+
PropertyReactivity.trigger(target, TriggerOpTypes.ADD, key, value);
|
|
1333
|
+
} else if (hasChanged$1(value, oldValue)) {
|
|
1334
|
+
PropertyReactivity.trigger(target, TriggerOpTypes.SET, key, value, oldValue);
|
|
1335
|
+
}
|
|
1336
|
+
return this;
|
|
1337
|
+
},
|
|
1338
|
+
/**
|
|
1339
|
+
* 从集合中删除值。
|
|
1340
|
+
*
|
|
1341
|
+
* 实现了以下功能:
|
|
1342
|
+
* 1. 支持原始键和响应式键的删除
|
|
1343
|
+
* 2. 触发删除操作的通知
|
|
1344
|
+
*
|
|
1345
|
+
* @param key 要删除的键
|
|
1346
|
+
* @returns 如果删除成功则返回 true,否则返回 false
|
|
1347
|
+
*/
|
|
1348
|
+
delete(key) {
|
|
1349
|
+
const target = toRaw$1(this);
|
|
1350
|
+
const { has, get } = getProto$1(target);
|
|
1351
|
+
let hadKey = has.call(target, key);
|
|
1352
|
+
if (!hadKey) {
|
|
1353
|
+
key = toRaw$1(key);
|
|
1354
|
+
hadKey = has.call(target, key);
|
|
1355
|
+
}
|
|
1356
|
+
const oldValue = get ? get.call(target, key) : void 0;
|
|
1357
|
+
const result = target.delete(key);
|
|
1358
|
+
if (hadKey) {
|
|
1359
|
+
PropertyReactivity.trigger(target, TriggerOpTypes.DELETE, key, void 0, oldValue);
|
|
1360
|
+
}
|
|
1361
|
+
return result;
|
|
1362
|
+
},
|
|
1363
|
+
/**
|
|
1364
|
+
* 清空集合。
|
|
1365
|
+
*
|
|
1366
|
+
* 实现了以下功能:
|
|
1367
|
+
* 1. 清空集合中的所有元素
|
|
1368
|
+
* 2. 触发清空操作的通知
|
|
1369
|
+
* 3. 在开发模式下保存旧值用于调试
|
|
1370
|
+
*
|
|
1371
|
+
* @returns 如果清空成功则返回 true,否则返回 false
|
|
1372
|
+
*/
|
|
1373
|
+
clear() {
|
|
1374
|
+
const target = toRaw$1(this);
|
|
1375
|
+
const hadItems = target.size !== 0;
|
|
1376
|
+
const oldTarget = void 0;
|
|
1377
|
+
const result = target.clear();
|
|
1378
|
+
if (hadItems) {
|
|
1379
|
+
PropertyReactivity.trigger(
|
|
1380
|
+
target,
|
|
1381
|
+
TriggerOpTypes.CLEAR,
|
|
1382
|
+
void 0,
|
|
1383
|
+
void 0,
|
|
1384
|
+
oldTarget
|
|
1385
|
+
);
|
|
1386
|
+
}
|
|
1387
|
+
return result;
|
|
1388
|
+
}
|
|
1389
|
+
};
|
|
1390
|
+
const iteratorMethods = [
|
|
1391
|
+
"keys",
|
|
1392
|
+
"values",
|
|
1393
|
+
"entries",
|
|
1394
|
+
Symbol.iterator
|
|
1395
|
+
];
|
|
1396
|
+
iteratorMethods.forEach((method) => {
|
|
1397
|
+
instrumentations[method] = createIterableMethod$1(method);
|
|
1398
|
+
});
|
|
1399
|
+
return instrumentations;
|
|
1400
|
+
}
|
|
1401
|
+
function createIterableMethod$1(method) {
|
|
1402
|
+
return function(...args) {
|
|
1403
|
+
const target = this[ReactiveFlags.RAW];
|
|
1404
|
+
const rawTarget = toRaw$1(target);
|
|
1405
|
+
const targetIsMap = isMap$1(rawTarget);
|
|
1406
|
+
const isPair = method === "entries" || method === Symbol.iterator && targetIsMap;
|
|
1407
|
+
const isKeyOnly = method === "keys" && targetIsMap;
|
|
1408
|
+
const innerIterator = target[method](...args);
|
|
1409
|
+
const wrap = toReactive$1;
|
|
1410
|
+
PropertyReactivity.track(
|
|
1411
|
+
rawTarget,
|
|
1412
|
+
TrackOpTypes.ITERATE,
|
|
1413
|
+
isKeyOnly ? MAP_KEY_ITERATE_KEY$1 : ITERATE_KEY$1
|
|
1414
|
+
);
|
|
1415
|
+
return {
|
|
1416
|
+
// 迭代器协议
|
|
1417
|
+
next() {
|
|
1418
|
+
const { value, done } = innerIterator.next();
|
|
1419
|
+
return done ? { value, done } : {
|
|
1420
|
+
value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
|
|
1421
|
+
done
|
|
1422
|
+
};
|
|
1423
|
+
},
|
|
1424
|
+
// 可迭代协议
|
|
1425
|
+
[Symbol.iterator]() {
|
|
1426
|
+
return this;
|
|
1427
|
+
}
|
|
1428
|
+
};
|
|
1429
|
+
};
|
|
1430
|
+
}
|
|
1431
|
+
const getProto$1 = (v) => Reflect.getPrototypeOf(v);
|
|
1432
|
+
function reactive$1(target) {
|
|
1433
|
+
if (!isObject$1(target)) {
|
|
1434
|
+
return target;
|
|
1435
|
+
}
|
|
1436
|
+
if (target[ReactiveFlags.RAW]) {
|
|
1437
|
+
return target;
|
|
1438
|
+
}
|
|
1439
|
+
const targetType = getTargetType$1(target);
|
|
1440
|
+
if (targetType === TargetType.INVALID) {
|
|
1441
|
+
return target;
|
|
1442
|
+
}
|
|
1443
|
+
const existingProxy = reactiveMap$1.get(target);
|
|
1444
|
+
if (existingProxy) {
|
|
1445
|
+
return existingProxy;
|
|
1446
|
+
}
|
|
1447
|
+
const proxy = new Proxy(
|
|
1448
|
+
target,
|
|
1449
|
+
targetType === TargetType.COLLECTION ? mutableCollectionHandlers$1 : mutableHandlers$1
|
|
1450
|
+
);
|
|
1451
|
+
reactiveMap$1.set(target, proxy);
|
|
1452
|
+
return proxy;
|
|
1453
|
+
}
|
|
1454
|
+
const reactiveMap$1 = /* @__PURE__ */ new WeakMap();
|
|
1455
|
+
const toReactive$1 = (value) => {
|
|
1456
|
+
if (isObject$1(value)) {
|
|
1457
|
+
return reactive$1(value);
|
|
1458
|
+
}
|
|
1459
|
+
return value;
|
|
1460
|
+
};
|
|
1461
|
+
function isProxy$1(value) {
|
|
1462
|
+
return value ? !!value[ReactiveFlags.RAW] : false;
|
|
1463
|
+
}
|
|
1464
|
+
/**
|
|
1465
|
+
* @vue/shared v3.5.14
|
|
1466
|
+
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
1467
|
+
* @license MIT
|
|
1468
|
+
**/
|
|
1469
|
+
/*! #__NO_SIDE_EFFECTS__ */
|
|
1470
|
+
// @__NO_SIDE_EFFECTS__
|
|
1471
|
+
function makeMap(str) {
|
|
1472
|
+
const map = /* @__PURE__ */ Object.create(null);
|
|
1473
|
+
for (const key of str.split(",")) map[key] = 1;
|
|
1474
|
+
return (val) => val in map;
|
|
1475
|
+
}
|
|
1476
|
+
const extend = Object.assign;
|
|
1477
|
+
const hasOwnProperty$1 = Object.prototype.hasOwnProperty;
|
|
1478
|
+
const hasOwn = (val, key) => hasOwnProperty$1.call(val, key);
|
|
1479
|
+
const isArray = Array.isArray;
|
|
1480
|
+
const isMap = (val) => toTypeString(val) === "[object Map]";
|
|
1481
|
+
const isFunction = (val) => typeof val === "function";
|
|
1482
|
+
const isString = (val) => typeof val === "string";
|
|
1483
|
+
const isSymbol = (val) => typeof val === "symbol";
|
|
1484
|
+
const isObject = (val) => val !== null && typeof val === "object";
|
|
1485
|
+
const objectToString = Object.prototype.toString;
|
|
1486
|
+
const toTypeString = (value) => objectToString.call(value);
|
|
1487
|
+
const toRawType = (value) => {
|
|
1488
|
+
return toTypeString(value).slice(8, -1);
|
|
1489
|
+
};
|
|
1490
|
+
const isIntegerKey = (key) => isString(key) && key !== "NaN" && key[0] !== "-" && "" + parseInt(key, 10) === key;
|
|
1491
|
+
const hasChanged = (value, oldValue) => !Object.is(value, oldValue);
|
|
1492
|
+
/**
|
|
1493
|
+
* @vue/reactivity v3.5.14
|
|
1494
|
+
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
1495
|
+
* @license MIT
|
|
1496
|
+
**/
|
|
1497
|
+
let activeSub;
|
|
1498
|
+
let batchDepth = 0;
|
|
1499
|
+
let batchedSub;
|
|
1500
|
+
let batchedComputed;
|
|
1501
|
+
function batch(sub, isComputed = false) {
|
|
1502
|
+
sub.flags |= 8;
|
|
1503
|
+
if (isComputed) {
|
|
1504
|
+
sub.next = batchedComputed;
|
|
1505
|
+
batchedComputed = sub;
|
|
1506
|
+
return;
|
|
1507
|
+
}
|
|
1508
|
+
sub.next = batchedSub;
|
|
1509
|
+
batchedSub = sub;
|
|
1510
|
+
}
|
|
1511
|
+
function startBatch() {
|
|
1512
|
+
batchDepth++;
|
|
1513
|
+
}
|
|
1514
|
+
function endBatch() {
|
|
1515
|
+
if (--batchDepth > 0) {
|
|
1516
|
+
return;
|
|
1517
|
+
}
|
|
1518
|
+
if (batchedComputed) {
|
|
1519
|
+
let e = batchedComputed;
|
|
1520
|
+
batchedComputed = void 0;
|
|
1521
|
+
while (e) {
|
|
1522
|
+
const next = e.next;
|
|
1523
|
+
e.next = void 0;
|
|
1524
|
+
e.flags &= -9;
|
|
1525
|
+
e = next;
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
let error;
|
|
1529
|
+
while (batchedSub) {
|
|
1530
|
+
let e = batchedSub;
|
|
1531
|
+
batchedSub = void 0;
|
|
1532
|
+
while (e) {
|
|
1533
|
+
const next = e.next;
|
|
1534
|
+
e.next = void 0;
|
|
1535
|
+
e.flags &= -9;
|
|
1536
|
+
if (e.flags & 1) {
|
|
1537
|
+
try {
|
|
1538
|
+
;
|
|
1539
|
+
e.trigger();
|
|
1540
|
+
} catch (err) {
|
|
1541
|
+
if (!error) error = err;
|
|
1542
|
+
}
|
|
1543
|
+
}
|
|
1544
|
+
e = next;
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
if (error) throw error;
|
|
1548
|
+
}
|
|
1549
|
+
function prepareDeps(sub) {
|
|
1550
|
+
for (let link = sub.deps; link; link = link.nextDep) {
|
|
1551
|
+
link.version = -1;
|
|
1552
|
+
link.prevActiveLink = link.dep.activeLink;
|
|
1553
|
+
link.dep.activeLink = link;
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1556
|
+
function cleanupDeps(sub) {
|
|
1557
|
+
let head;
|
|
1558
|
+
let tail = sub.depsTail;
|
|
1559
|
+
let link = tail;
|
|
1560
|
+
while (link) {
|
|
1561
|
+
const prev = link.prevDep;
|
|
1562
|
+
if (link.version === -1) {
|
|
1563
|
+
if (link === tail) tail = prev;
|
|
1564
|
+
removeSub(link);
|
|
1565
|
+
removeDep(link);
|
|
1566
|
+
} else {
|
|
1567
|
+
head = link;
|
|
1568
|
+
}
|
|
1569
|
+
link.dep.activeLink = link.prevActiveLink;
|
|
1570
|
+
link.prevActiveLink = void 0;
|
|
1571
|
+
link = prev;
|
|
1572
|
+
}
|
|
1573
|
+
sub.deps = head;
|
|
1574
|
+
sub.depsTail = tail;
|
|
1575
|
+
}
|
|
1576
|
+
function isDirty(sub) {
|
|
1577
|
+
for (let link = sub.deps; link; link = link.nextDep) {
|
|
1578
|
+
if (link.dep.version !== link.version || link.dep.computed && (refreshComputed(link.dep.computed) || link.dep.version !== link.version)) {
|
|
1579
|
+
return true;
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
if (sub._dirty) {
|
|
1583
|
+
return true;
|
|
1584
|
+
}
|
|
1585
|
+
return false;
|
|
1586
|
+
}
|
|
1587
|
+
function refreshComputed(computed2) {
|
|
1588
|
+
if (computed2.flags & 4 && !(computed2.flags & 16)) {
|
|
1589
|
+
return;
|
|
1590
|
+
}
|
|
1591
|
+
computed2.flags &= -17;
|
|
1592
|
+
if (computed2.globalVersion === globalVersion) {
|
|
1593
|
+
return;
|
|
1594
|
+
}
|
|
1595
|
+
computed2.globalVersion = globalVersion;
|
|
1596
|
+
if (!computed2.isSSR && computed2.flags & 128 && (!computed2.deps && !computed2._dirty || !isDirty(computed2))) {
|
|
1597
|
+
return;
|
|
1598
|
+
}
|
|
1599
|
+
computed2.flags |= 2;
|
|
1600
|
+
const dep = computed2.dep;
|
|
1601
|
+
const prevSub = activeSub;
|
|
1602
|
+
const prevShouldTrack = shouldTrack;
|
|
1603
|
+
activeSub = computed2;
|
|
1604
|
+
shouldTrack = true;
|
|
1605
|
+
try {
|
|
1606
|
+
prepareDeps(computed2);
|
|
1607
|
+
const value = computed2.fn(computed2._value);
|
|
1608
|
+
if (dep.version === 0 || hasChanged(value, computed2._value)) {
|
|
1609
|
+
computed2.flags |= 128;
|
|
1610
|
+
computed2._value = value;
|
|
1611
|
+
dep.version++;
|
|
1612
|
+
}
|
|
1613
|
+
} catch (err) {
|
|
1614
|
+
dep.version++;
|
|
1615
|
+
throw err;
|
|
1616
|
+
} finally {
|
|
1617
|
+
activeSub = prevSub;
|
|
1618
|
+
shouldTrack = prevShouldTrack;
|
|
1619
|
+
cleanupDeps(computed2);
|
|
1620
|
+
computed2.flags &= -3;
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
function removeSub(link, soft = false) {
|
|
1624
|
+
const { dep, prevSub, nextSub } = link;
|
|
1625
|
+
if (prevSub) {
|
|
1626
|
+
prevSub.nextSub = nextSub;
|
|
1627
|
+
link.prevSub = void 0;
|
|
1628
|
+
}
|
|
1629
|
+
if (nextSub) {
|
|
1630
|
+
nextSub.prevSub = prevSub;
|
|
1631
|
+
link.nextSub = void 0;
|
|
1632
|
+
}
|
|
1633
|
+
if (dep.subs === link) {
|
|
1634
|
+
dep.subs = prevSub;
|
|
1635
|
+
if (!prevSub && dep.computed) {
|
|
1636
|
+
dep.computed.flags &= -5;
|
|
1637
|
+
for (let l = dep.computed.deps; l; l = l.nextDep) {
|
|
1638
|
+
removeSub(l, true);
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
if (!soft && !--dep.sc && dep.map) {
|
|
1643
|
+
dep.map.delete(dep.key);
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
1646
|
+
function removeDep(link) {
|
|
1647
|
+
const { prevDep, nextDep } = link;
|
|
1648
|
+
if (prevDep) {
|
|
1649
|
+
prevDep.nextDep = nextDep;
|
|
1650
|
+
link.prevDep = void 0;
|
|
1651
|
+
}
|
|
1652
|
+
if (nextDep) {
|
|
1653
|
+
nextDep.prevDep = prevDep;
|
|
1654
|
+
link.nextDep = void 0;
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
1657
|
+
let shouldTrack = true;
|
|
1658
|
+
const trackStack = [];
|
|
1659
|
+
function pauseTracking() {
|
|
1660
|
+
trackStack.push(shouldTrack);
|
|
1661
|
+
shouldTrack = false;
|
|
1662
|
+
}
|
|
1663
|
+
function resetTracking() {
|
|
1664
|
+
const last = trackStack.pop();
|
|
1665
|
+
shouldTrack = last === void 0 ? true : last;
|
|
1666
|
+
}
|
|
1667
|
+
let globalVersion = 0;
|
|
1668
|
+
class Link {
|
|
1669
|
+
constructor(sub, dep) {
|
|
1670
|
+
this.sub = sub;
|
|
1671
|
+
this.dep = dep;
|
|
1672
|
+
this.version = dep.version;
|
|
1673
|
+
this.nextDep = this.prevDep = this.nextSub = this.prevSub = this.prevActiveLink = void 0;
|
|
1674
|
+
}
|
|
1675
|
+
}
|
|
1676
|
+
class Dep {
|
|
1677
|
+
constructor(computed2) {
|
|
1678
|
+
this.computed = computed2;
|
|
1679
|
+
this.version = 0;
|
|
1680
|
+
this.activeLink = void 0;
|
|
1681
|
+
this.subs = void 0;
|
|
1682
|
+
this.map = void 0;
|
|
1683
|
+
this.key = void 0;
|
|
1684
|
+
this.sc = 0;
|
|
1685
|
+
}
|
|
1686
|
+
track(debugInfo) {
|
|
1687
|
+
if (!activeSub || !shouldTrack || activeSub === this.computed) {
|
|
1688
|
+
return;
|
|
1689
|
+
}
|
|
1690
|
+
let link = this.activeLink;
|
|
1691
|
+
if (link === void 0 || link.sub !== activeSub) {
|
|
1692
|
+
link = this.activeLink = new Link(activeSub, this);
|
|
1693
|
+
if (!activeSub.deps) {
|
|
1694
|
+
activeSub.deps = activeSub.depsTail = link;
|
|
1695
|
+
} else {
|
|
1696
|
+
link.prevDep = activeSub.depsTail;
|
|
1697
|
+
activeSub.depsTail.nextDep = link;
|
|
1698
|
+
activeSub.depsTail = link;
|
|
1699
|
+
}
|
|
1700
|
+
addSub(link);
|
|
1701
|
+
} else if (link.version === -1) {
|
|
1702
|
+
link.version = this.version;
|
|
1703
|
+
if (link.nextDep) {
|
|
1704
|
+
const next = link.nextDep;
|
|
1705
|
+
next.prevDep = link.prevDep;
|
|
1706
|
+
if (link.prevDep) {
|
|
1707
|
+
link.prevDep.nextDep = next;
|
|
1708
|
+
}
|
|
1709
|
+
link.prevDep = activeSub.depsTail;
|
|
1710
|
+
link.nextDep = void 0;
|
|
1711
|
+
activeSub.depsTail.nextDep = link;
|
|
1712
|
+
activeSub.depsTail = link;
|
|
1713
|
+
if (activeSub.deps === link) {
|
|
1714
|
+
activeSub.deps = next;
|
|
1715
|
+
}
|
|
1716
|
+
}
|
|
1717
|
+
}
|
|
1718
|
+
return link;
|
|
1719
|
+
}
|
|
1720
|
+
trigger(debugInfo) {
|
|
1721
|
+
this.version++;
|
|
1722
|
+
globalVersion++;
|
|
1723
|
+
this.notify(debugInfo);
|
|
1724
|
+
}
|
|
1725
|
+
notify(debugInfo) {
|
|
1726
|
+
startBatch();
|
|
1727
|
+
try {
|
|
1728
|
+
if (false) ;
|
|
1729
|
+
for (let link = this.subs; link; link = link.prevSub) {
|
|
1730
|
+
if (link.sub.notify()) {
|
|
1731
|
+
;
|
|
1732
|
+
link.sub.dep.notify();
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
} finally {
|
|
1736
|
+
endBatch();
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
}
|
|
1740
|
+
function addSub(link) {
|
|
1741
|
+
link.dep.sc++;
|
|
1742
|
+
if (link.sub.flags & 4) {
|
|
1743
|
+
const computed2 = link.dep.computed;
|
|
1744
|
+
if (computed2 && !link.dep.subs) {
|
|
1745
|
+
computed2.flags |= 4 | 16;
|
|
1746
|
+
for (let l = computed2.deps; l; l = l.nextDep) {
|
|
1747
|
+
addSub(l);
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
const currentTail = link.dep.subs;
|
|
1751
|
+
if (currentTail !== link) {
|
|
1752
|
+
link.prevSub = currentTail;
|
|
1753
|
+
if (currentTail) currentTail.nextSub = link;
|
|
1754
|
+
}
|
|
1755
|
+
link.dep.subs = link;
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1758
|
+
const targetMap = /* @__PURE__ */ new WeakMap();
|
|
1759
|
+
const ITERATE_KEY = Symbol(
|
|
1760
|
+
""
|
|
1761
|
+
);
|
|
1762
|
+
const MAP_KEY_ITERATE_KEY = Symbol(
|
|
1763
|
+
""
|
|
1764
|
+
);
|
|
1765
|
+
const ARRAY_ITERATE_KEY = Symbol(
|
|
1766
|
+
""
|
|
1767
|
+
);
|
|
1768
|
+
function track(target, type, key) {
|
|
1769
|
+
if (shouldTrack && activeSub) {
|
|
1770
|
+
let depsMap = targetMap.get(target);
|
|
1771
|
+
if (!depsMap) {
|
|
1772
|
+
targetMap.set(target, depsMap = /* @__PURE__ */ new Map());
|
|
1773
|
+
}
|
|
1774
|
+
let dep = depsMap.get(key);
|
|
1775
|
+
if (!dep) {
|
|
1776
|
+
depsMap.set(key, dep = new Dep());
|
|
1777
|
+
dep.map = depsMap;
|
|
1778
|
+
dep.key = key;
|
|
1779
|
+
}
|
|
1780
|
+
{
|
|
1781
|
+
dep.track();
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
}
|
|
1785
|
+
function trigger(target, type, key, newValue, oldValue, oldTarget) {
|
|
1786
|
+
const depsMap = targetMap.get(target);
|
|
1787
|
+
if (!depsMap) {
|
|
1788
|
+
globalVersion++;
|
|
1789
|
+
return;
|
|
1790
|
+
}
|
|
1791
|
+
const run = (dep) => {
|
|
1792
|
+
if (dep) {
|
|
1793
|
+
{
|
|
1794
|
+
dep.trigger();
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1797
|
+
};
|
|
1798
|
+
startBatch();
|
|
1799
|
+
if (type === "clear") {
|
|
1800
|
+
depsMap.forEach(run);
|
|
1801
|
+
} else {
|
|
1802
|
+
const targetIsArray = isArray(target);
|
|
1803
|
+
const isArrayIndex = targetIsArray && isIntegerKey(key);
|
|
1804
|
+
if (targetIsArray && key === "length") {
|
|
1805
|
+
const newLength = Number(newValue);
|
|
1806
|
+
depsMap.forEach((dep, key2) => {
|
|
1807
|
+
if (key2 === "length" || key2 === ARRAY_ITERATE_KEY || !isSymbol(key2) && key2 >= newLength) {
|
|
1808
|
+
run(dep);
|
|
1809
|
+
}
|
|
1810
|
+
});
|
|
1811
|
+
} else {
|
|
1812
|
+
if (key !== void 0 || depsMap.has(void 0)) {
|
|
1813
|
+
run(depsMap.get(key));
|
|
1814
|
+
}
|
|
1815
|
+
if (isArrayIndex) {
|
|
1816
|
+
run(depsMap.get(ARRAY_ITERATE_KEY));
|
|
1817
|
+
}
|
|
1818
|
+
switch (type) {
|
|
1819
|
+
case "add":
|
|
1820
|
+
if (!targetIsArray) {
|
|
1821
|
+
run(depsMap.get(ITERATE_KEY));
|
|
1822
|
+
if (isMap(target)) {
|
|
1823
|
+
run(depsMap.get(MAP_KEY_ITERATE_KEY));
|
|
1824
|
+
}
|
|
1825
|
+
} else if (isArrayIndex) {
|
|
1826
|
+
run(depsMap.get("length"));
|
|
1827
|
+
}
|
|
1828
|
+
break;
|
|
1829
|
+
case "delete":
|
|
1830
|
+
if (!targetIsArray) {
|
|
1831
|
+
run(depsMap.get(ITERATE_KEY));
|
|
1832
|
+
if (isMap(target)) {
|
|
1833
|
+
run(depsMap.get(MAP_KEY_ITERATE_KEY));
|
|
1834
|
+
}
|
|
1835
|
+
}
|
|
1836
|
+
break;
|
|
1837
|
+
case "set":
|
|
1838
|
+
if (isMap(target)) {
|
|
1839
|
+
run(depsMap.get(ITERATE_KEY));
|
|
1840
|
+
}
|
|
1841
|
+
break;
|
|
1842
|
+
}
|
|
1843
|
+
}
|
|
1844
|
+
}
|
|
1845
|
+
endBatch();
|
|
1846
|
+
}
|
|
1847
|
+
function reactiveReadArray(array) {
|
|
1848
|
+
const raw = toRaw(array);
|
|
1849
|
+
if (raw === array) return raw;
|
|
1850
|
+
track(raw, "iterate", ARRAY_ITERATE_KEY);
|
|
1851
|
+
return isShallow(array) ? raw : raw.map(toReactive);
|
|
1852
|
+
}
|
|
1853
|
+
function shallowReadArray(arr) {
|
|
1854
|
+
track(arr = toRaw(arr), "iterate", ARRAY_ITERATE_KEY);
|
|
1855
|
+
return arr;
|
|
1856
|
+
}
|
|
1857
|
+
const arrayInstrumentations = {
|
|
1858
|
+
__proto__: null,
|
|
1859
|
+
[Symbol.iterator]() {
|
|
1860
|
+
return iterator(this, Symbol.iterator, toReactive);
|
|
1861
|
+
},
|
|
1862
|
+
concat(...args) {
|
|
1863
|
+
return reactiveReadArray(this).concat(
|
|
1864
|
+
...args.map((x) => isArray(x) ? reactiveReadArray(x) : x)
|
|
1865
|
+
);
|
|
1866
|
+
},
|
|
1867
|
+
entries() {
|
|
1868
|
+
return iterator(this, "entries", (value) => {
|
|
1869
|
+
value[1] = toReactive(value[1]);
|
|
1870
|
+
return value;
|
|
1871
|
+
});
|
|
1872
|
+
},
|
|
1873
|
+
every(fn, thisArg) {
|
|
1874
|
+
return apply(this, "every", fn, thisArg, void 0, arguments);
|
|
1875
|
+
},
|
|
1876
|
+
filter(fn, thisArg) {
|
|
1877
|
+
return apply(this, "filter", fn, thisArg, (v) => v.map(toReactive), arguments);
|
|
1878
|
+
},
|
|
1879
|
+
find(fn, thisArg) {
|
|
1880
|
+
return apply(this, "find", fn, thisArg, toReactive, arguments);
|
|
1881
|
+
},
|
|
1882
|
+
findIndex(fn, thisArg) {
|
|
1883
|
+
return apply(this, "findIndex", fn, thisArg, void 0, arguments);
|
|
1884
|
+
},
|
|
1885
|
+
findLast(fn, thisArg) {
|
|
1886
|
+
return apply(this, "findLast", fn, thisArg, toReactive, arguments);
|
|
1887
|
+
},
|
|
1888
|
+
findLastIndex(fn, thisArg) {
|
|
1889
|
+
return apply(this, "findLastIndex", fn, thisArg, void 0, arguments);
|
|
1890
|
+
},
|
|
1891
|
+
// flat, flatMap could benefit from ARRAY_ITERATE but are not straight-forward to implement
|
|
1892
|
+
forEach(fn, thisArg) {
|
|
1893
|
+
return apply(this, "forEach", fn, thisArg, void 0, arguments);
|
|
1894
|
+
},
|
|
1895
|
+
includes(...args) {
|
|
1896
|
+
return searchProxy(this, "includes", args);
|
|
1897
|
+
},
|
|
1898
|
+
indexOf(...args) {
|
|
1899
|
+
return searchProxy(this, "indexOf", args);
|
|
1900
|
+
},
|
|
1901
|
+
join(separator) {
|
|
1902
|
+
return reactiveReadArray(this).join(separator);
|
|
1903
|
+
},
|
|
1904
|
+
// keys() iterator only reads `length`, no optimisation required
|
|
1905
|
+
lastIndexOf(...args) {
|
|
1906
|
+
return searchProxy(this, "lastIndexOf", args);
|
|
1907
|
+
},
|
|
1908
|
+
map(fn, thisArg) {
|
|
1909
|
+
return apply(this, "map", fn, thisArg, void 0, arguments);
|
|
1910
|
+
},
|
|
1911
|
+
pop() {
|
|
1912
|
+
return noTracking(this, "pop");
|
|
1913
|
+
},
|
|
1914
|
+
push(...args) {
|
|
1915
|
+
return noTracking(this, "push", args);
|
|
1916
|
+
},
|
|
1917
|
+
reduce(fn, ...args) {
|
|
1918
|
+
return reduce(this, "reduce", fn, args);
|
|
1919
|
+
},
|
|
1920
|
+
reduceRight(fn, ...args) {
|
|
1921
|
+
return reduce(this, "reduceRight", fn, args);
|
|
1922
|
+
},
|
|
1923
|
+
shift() {
|
|
1924
|
+
return noTracking(this, "shift");
|
|
1925
|
+
},
|
|
1926
|
+
// slice could use ARRAY_ITERATE but also seems to beg for range tracking
|
|
1927
|
+
some(fn, thisArg) {
|
|
1928
|
+
return apply(this, "some", fn, thisArg, void 0, arguments);
|
|
1929
|
+
},
|
|
1930
|
+
splice(...args) {
|
|
1931
|
+
return noTracking(this, "splice", args);
|
|
1932
|
+
},
|
|
1933
|
+
toReversed() {
|
|
1934
|
+
return reactiveReadArray(this).toReversed();
|
|
1935
|
+
},
|
|
1936
|
+
toSorted(comparer) {
|
|
1937
|
+
return reactiveReadArray(this).toSorted(comparer);
|
|
1938
|
+
},
|
|
1939
|
+
toSpliced(...args) {
|
|
1940
|
+
return reactiveReadArray(this).toSpliced(...args);
|
|
1941
|
+
},
|
|
1942
|
+
unshift(...args) {
|
|
1943
|
+
return noTracking(this, "unshift", args);
|
|
1944
|
+
},
|
|
1945
|
+
values() {
|
|
1946
|
+
return iterator(this, "values", toReactive);
|
|
1947
|
+
}
|
|
1948
|
+
};
|
|
1949
|
+
function iterator(self, method, wrapValue) {
|
|
1950
|
+
const arr = shallowReadArray(self);
|
|
1951
|
+
const iter = arr[method]();
|
|
1952
|
+
if (arr !== self && !isShallow(self)) {
|
|
1953
|
+
iter._next = iter.next;
|
|
1954
|
+
iter.next = () => {
|
|
1955
|
+
const result = iter._next();
|
|
1956
|
+
if (result.value) {
|
|
1957
|
+
result.value = wrapValue(result.value);
|
|
1958
|
+
}
|
|
1959
|
+
return result;
|
|
1960
|
+
};
|
|
1961
|
+
}
|
|
1962
|
+
return iter;
|
|
1963
|
+
}
|
|
1964
|
+
const arrayProto = Array.prototype;
|
|
1965
|
+
function apply(self, method, fn, thisArg, wrappedRetFn, args) {
|
|
1966
|
+
const arr = shallowReadArray(self);
|
|
1967
|
+
const needsWrap = arr !== self && !isShallow(self);
|
|
1968
|
+
const methodFn = arr[method];
|
|
1969
|
+
if (methodFn !== arrayProto[method]) {
|
|
1970
|
+
const result2 = methodFn.apply(self, args);
|
|
1971
|
+
return needsWrap ? toReactive(result2) : result2;
|
|
1972
|
+
}
|
|
1973
|
+
let wrappedFn = fn;
|
|
1974
|
+
if (arr !== self) {
|
|
1975
|
+
if (needsWrap) {
|
|
1976
|
+
wrappedFn = function(item, index) {
|
|
1977
|
+
return fn.call(this, toReactive(item), index, self);
|
|
1978
|
+
};
|
|
1979
|
+
} else if (fn.length > 2) {
|
|
1980
|
+
wrappedFn = function(item, index) {
|
|
1981
|
+
return fn.call(this, item, index, self);
|
|
1982
|
+
};
|
|
1983
|
+
}
|
|
1984
|
+
}
|
|
1985
|
+
const result = methodFn.call(arr, wrappedFn, thisArg);
|
|
1986
|
+
return needsWrap && wrappedRetFn ? wrappedRetFn(result) : result;
|
|
1987
|
+
}
|
|
1988
|
+
function reduce(self, method, fn, args) {
|
|
1989
|
+
const arr = shallowReadArray(self);
|
|
1990
|
+
let wrappedFn = fn;
|
|
1991
|
+
if (arr !== self) {
|
|
1992
|
+
if (!isShallow(self)) {
|
|
1993
|
+
wrappedFn = function(acc, item, index) {
|
|
1994
|
+
return fn.call(this, acc, toReactive(item), index, self);
|
|
1995
|
+
};
|
|
1996
|
+
} else if (fn.length > 3) {
|
|
1997
|
+
wrappedFn = function(acc, item, index) {
|
|
1998
|
+
return fn.call(this, acc, item, index, self);
|
|
1999
|
+
};
|
|
2000
|
+
}
|
|
2001
|
+
}
|
|
2002
|
+
return arr[method](wrappedFn, ...args);
|
|
2003
|
+
}
|
|
2004
|
+
function searchProxy(self, method, args) {
|
|
2005
|
+
const arr = toRaw(self);
|
|
2006
|
+
track(arr, "iterate", ARRAY_ITERATE_KEY);
|
|
2007
|
+
const res = arr[method](...args);
|
|
2008
|
+
if ((res === -1 || res === false) && isProxy(args[0])) {
|
|
2009
|
+
args[0] = toRaw(args[0]);
|
|
2010
|
+
return arr[method](...args);
|
|
2011
|
+
}
|
|
2012
|
+
return res;
|
|
2013
|
+
}
|
|
2014
|
+
function noTracking(self, method, args = []) {
|
|
2015
|
+
pauseTracking();
|
|
2016
|
+
startBatch();
|
|
2017
|
+
const res = toRaw(self)[method].apply(self, args);
|
|
2018
|
+
endBatch();
|
|
2019
|
+
resetTracking();
|
|
2020
|
+
return res;
|
|
2021
|
+
}
|
|
2022
|
+
const isNonTrackableKeys = /* @__PURE__ */ makeMap(`__proto__,__v_isRef,__isVue`);
|
|
2023
|
+
const builtInSymbols = new Set(
|
|
2024
|
+
/* @__PURE__ */ Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller").map((key) => Symbol[key]).filter(isSymbol)
|
|
2025
|
+
);
|
|
2026
|
+
function hasOwnProperty(key) {
|
|
2027
|
+
if (!isSymbol(key)) key = String(key);
|
|
2028
|
+
const obj = toRaw(this);
|
|
2029
|
+
track(obj, "has", key);
|
|
2030
|
+
return obj.hasOwnProperty(key);
|
|
2031
|
+
}
|
|
2032
|
+
class BaseReactiveHandler2 {
|
|
2033
|
+
constructor(_isReadonly = false, _isShallow = false) {
|
|
2034
|
+
this._isReadonly = _isReadonly;
|
|
2035
|
+
this._isShallow = _isShallow;
|
|
2036
|
+
}
|
|
2037
|
+
get(target, key, receiver) {
|
|
2038
|
+
if (key === "__v_skip") return target["__v_skip"];
|
|
2039
|
+
const isReadonly2 = this._isReadonly, isShallow2 = this._isShallow;
|
|
2040
|
+
if (key === "__v_isReactive") {
|
|
2041
|
+
return !isReadonly2;
|
|
2042
|
+
} else if (key === "__v_isReadonly") {
|
|
2043
|
+
return isReadonly2;
|
|
2044
|
+
} else if (key === "__v_isShallow") {
|
|
2045
|
+
return isShallow2;
|
|
2046
|
+
} else if (key === "__v_raw") {
|
|
2047
|
+
if (receiver === (isReadonly2 ? isShallow2 ? shallowReadonlyMap : readonlyMap : isShallow2 ? shallowReactiveMap : reactiveMap).get(target) || // receiver is not the reactive proxy, but has the same prototype
|
|
2048
|
+
// this means the receiver is a user proxy of the reactive proxy
|
|
2049
|
+
Object.getPrototypeOf(target) === Object.getPrototypeOf(receiver)) {
|
|
2050
|
+
return target;
|
|
2051
|
+
}
|
|
2052
|
+
return;
|
|
2053
|
+
}
|
|
2054
|
+
const targetIsArray = isArray(target);
|
|
2055
|
+
if (!isReadonly2) {
|
|
2056
|
+
let fn;
|
|
2057
|
+
if (targetIsArray && (fn = arrayInstrumentations[key])) {
|
|
2058
|
+
return fn;
|
|
2059
|
+
}
|
|
2060
|
+
if (key === "hasOwnProperty") {
|
|
2061
|
+
return hasOwnProperty;
|
|
2062
|
+
}
|
|
2063
|
+
}
|
|
2064
|
+
const res = Reflect.get(
|
|
2065
|
+
target,
|
|
2066
|
+
key,
|
|
2067
|
+
// if this is a proxy wrapping a ref, return methods using the raw ref
|
|
2068
|
+
// as receiver so that we don't have to call `toRaw` on the ref in all
|
|
2069
|
+
// its class methods
|
|
2070
|
+
isRef(target) ? target : receiver
|
|
2071
|
+
);
|
|
2072
|
+
if (isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) {
|
|
2073
|
+
return res;
|
|
2074
|
+
}
|
|
2075
|
+
if (!isReadonly2) {
|
|
2076
|
+
track(target, "get", key);
|
|
2077
|
+
}
|
|
2078
|
+
if (isShallow2) {
|
|
2079
|
+
return res;
|
|
2080
|
+
}
|
|
2081
|
+
if (isRef(res)) {
|
|
2082
|
+
return targetIsArray && isIntegerKey(key) ? res : res.value;
|
|
2083
|
+
}
|
|
2084
|
+
if (isObject(res)) {
|
|
2085
|
+
return isReadonly2 ? readonly(res) : reactive(res);
|
|
2086
|
+
}
|
|
2087
|
+
return res;
|
|
2088
|
+
}
|
|
2089
|
+
}
|
|
2090
|
+
class MutableReactiveHandler2 extends BaseReactiveHandler2 {
|
|
2091
|
+
constructor(isShallow2 = false) {
|
|
2092
|
+
super(false, isShallow2);
|
|
2093
|
+
}
|
|
2094
|
+
set(target, key, value, receiver) {
|
|
2095
|
+
let oldValue = target[key];
|
|
2096
|
+
if (!this._isShallow) {
|
|
2097
|
+
const isOldValueReadonly = isReadonly(oldValue);
|
|
2098
|
+
if (!isShallow(value) && !isReadonly(value)) {
|
|
2099
|
+
oldValue = toRaw(oldValue);
|
|
2100
|
+
value = toRaw(value);
|
|
2101
|
+
}
|
|
2102
|
+
if (!isArray(target) && isRef(oldValue) && !isRef(value)) {
|
|
2103
|
+
if (isOldValueReadonly) {
|
|
2104
|
+
return false;
|
|
2105
|
+
} else {
|
|
2106
|
+
oldValue.value = value;
|
|
2107
|
+
return true;
|
|
2108
|
+
}
|
|
2109
|
+
}
|
|
2110
|
+
}
|
|
2111
|
+
const hadKey = isArray(target) && isIntegerKey(key) ? Number(key) < target.length : hasOwn(target, key);
|
|
2112
|
+
const result = Reflect.set(
|
|
2113
|
+
target,
|
|
2114
|
+
key,
|
|
2115
|
+
value,
|
|
2116
|
+
isRef(target) ? target : receiver
|
|
2117
|
+
);
|
|
2118
|
+
if (target === toRaw(receiver)) {
|
|
2119
|
+
if (!hadKey) {
|
|
2120
|
+
trigger(target, "add", key, value);
|
|
2121
|
+
} else if (hasChanged(value, oldValue)) {
|
|
2122
|
+
trigger(target, "set", key, value);
|
|
2123
|
+
}
|
|
2124
|
+
}
|
|
2125
|
+
return result;
|
|
2126
|
+
}
|
|
2127
|
+
deleteProperty(target, key) {
|
|
2128
|
+
const hadKey = hasOwn(target, key);
|
|
2129
|
+
target[key];
|
|
2130
|
+
const result = Reflect.deleteProperty(target, key);
|
|
2131
|
+
if (result && hadKey) {
|
|
2132
|
+
trigger(target, "delete", key, void 0);
|
|
2133
|
+
}
|
|
2134
|
+
return result;
|
|
2135
|
+
}
|
|
2136
|
+
has(target, key) {
|
|
2137
|
+
const result = Reflect.has(target, key);
|
|
2138
|
+
if (!isSymbol(key) || !builtInSymbols.has(key)) {
|
|
2139
|
+
track(target, "has", key);
|
|
2140
|
+
}
|
|
2141
|
+
return result;
|
|
2142
|
+
}
|
|
2143
|
+
ownKeys(target) {
|
|
2144
|
+
track(
|
|
2145
|
+
target,
|
|
2146
|
+
"iterate",
|
|
2147
|
+
isArray(target) ? "length" : ITERATE_KEY
|
|
2148
|
+
);
|
|
2149
|
+
return Reflect.ownKeys(target);
|
|
2150
|
+
}
|
|
2151
|
+
}
|
|
2152
|
+
class ReadonlyReactiveHandler extends BaseReactiveHandler2 {
|
|
2153
|
+
constructor(isShallow2 = false) {
|
|
2154
|
+
super(true, isShallow2);
|
|
2155
|
+
}
|
|
2156
|
+
set(target, key) {
|
|
2157
|
+
return true;
|
|
2158
|
+
}
|
|
2159
|
+
deleteProperty(target, key) {
|
|
2160
|
+
return true;
|
|
2161
|
+
}
|
|
2162
|
+
}
|
|
2163
|
+
const mutableHandlers = /* @__PURE__ */ new MutableReactiveHandler2();
|
|
2164
|
+
const readonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler();
|
|
2165
|
+
const toShallow = (value) => value;
|
|
2166
|
+
const getProto = (v) => Reflect.getPrototypeOf(v);
|
|
2167
|
+
function createIterableMethod(method, isReadonly2, isShallow2) {
|
|
2168
|
+
return function(...args) {
|
|
2169
|
+
const target = this["__v_raw"];
|
|
2170
|
+
const rawTarget = toRaw(target);
|
|
2171
|
+
const targetIsMap = isMap(rawTarget);
|
|
2172
|
+
const isPair = method === "entries" || method === Symbol.iterator && targetIsMap;
|
|
2173
|
+
const isKeyOnly = method === "keys" && targetIsMap;
|
|
2174
|
+
const innerIterator = target[method](...args);
|
|
2175
|
+
const wrap = isShallow2 ? toShallow : isReadonly2 ? toReadonly : toReactive;
|
|
2176
|
+
!isReadonly2 && track(
|
|
2177
|
+
rawTarget,
|
|
2178
|
+
"iterate",
|
|
2179
|
+
isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY
|
|
2180
|
+
);
|
|
2181
|
+
return {
|
|
2182
|
+
// iterator protocol
|
|
2183
|
+
next() {
|
|
2184
|
+
const { value, done } = innerIterator.next();
|
|
2185
|
+
return done ? { value, done } : {
|
|
2186
|
+
value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
|
|
2187
|
+
done
|
|
2188
|
+
};
|
|
2189
|
+
},
|
|
2190
|
+
// iterable protocol
|
|
2191
|
+
[Symbol.iterator]() {
|
|
2192
|
+
return this;
|
|
2193
|
+
}
|
|
2194
|
+
};
|
|
2195
|
+
};
|
|
2196
|
+
}
|
|
2197
|
+
function createReadonlyMethod(type) {
|
|
2198
|
+
return function(...args) {
|
|
2199
|
+
return type === "delete" ? false : type === "clear" ? void 0 : this;
|
|
2200
|
+
};
|
|
2201
|
+
}
|
|
2202
|
+
function createInstrumentations(readonly2, shallow) {
|
|
2203
|
+
const instrumentations = {
|
|
2204
|
+
get(key) {
|
|
2205
|
+
const target = this["__v_raw"];
|
|
2206
|
+
const rawTarget = toRaw(target);
|
|
2207
|
+
const rawKey = toRaw(key);
|
|
2208
|
+
if (!readonly2) {
|
|
2209
|
+
if (hasChanged(key, rawKey)) {
|
|
2210
|
+
track(rawTarget, "get", key);
|
|
2211
|
+
}
|
|
2212
|
+
track(rawTarget, "get", rawKey);
|
|
2213
|
+
}
|
|
2214
|
+
const { has } = getProto(rawTarget);
|
|
2215
|
+
const wrap = shallow ? toShallow : readonly2 ? toReadonly : toReactive;
|
|
2216
|
+
if (has.call(rawTarget, key)) {
|
|
2217
|
+
return wrap(target.get(key));
|
|
2218
|
+
} else if (has.call(rawTarget, rawKey)) {
|
|
2219
|
+
return wrap(target.get(rawKey));
|
|
2220
|
+
} else if (target !== rawTarget) {
|
|
2221
|
+
target.get(key);
|
|
2222
|
+
}
|
|
2223
|
+
},
|
|
2224
|
+
get size() {
|
|
2225
|
+
const target = this["__v_raw"];
|
|
2226
|
+
!readonly2 && track(toRaw(target), "iterate", ITERATE_KEY);
|
|
2227
|
+
return Reflect.get(target, "size", target);
|
|
2228
|
+
},
|
|
2229
|
+
has(key) {
|
|
2230
|
+
const target = this["__v_raw"];
|
|
2231
|
+
const rawTarget = toRaw(target);
|
|
2232
|
+
const rawKey = toRaw(key);
|
|
2233
|
+
if (!readonly2) {
|
|
2234
|
+
if (hasChanged(key, rawKey)) {
|
|
2235
|
+
track(rawTarget, "has", key);
|
|
2236
|
+
}
|
|
2237
|
+
track(rawTarget, "has", rawKey);
|
|
2238
|
+
}
|
|
2239
|
+
return key === rawKey ? target.has(key) : target.has(key) || target.has(rawKey);
|
|
2240
|
+
},
|
|
2241
|
+
forEach(callback, thisArg) {
|
|
2242
|
+
const observed = this;
|
|
2243
|
+
const target = observed["__v_raw"];
|
|
2244
|
+
const rawTarget = toRaw(target);
|
|
2245
|
+
const wrap = shallow ? toShallow : readonly2 ? toReadonly : toReactive;
|
|
2246
|
+
!readonly2 && track(rawTarget, "iterate", ITERATE_KEY);
|
|
2247
|
+
return target.forEach((value, key) => {
|
|
2248
|
+
return callback.call(thisArg, wrap(value), wrap(key), observed);
|
|
2249
|
+
});
|
|
2250
|
+
}
|
|
2251
|
+
};
|
|
2252
|
+
extend(
|
|
2253
|
+
instrumentations,
|
|
2254
|
+
readonly2 ? {
|
|
2255
|
+
add: createReadonlyMethod("add"),
|
|
2256
|
+
set: createReadonlyMethod("set"),
|
|
2257
|
+
delete: createReadonlyMethod("delete"),
|
|
2258
|
+
clear: createReadonlyMethod("clear")
|
|
2259
|
+
} : {
|
|
2260
|
+
add(value) {
|
|
2261
|
+
if (!shallow && !isShallow(value) && !isReadonly(value)) {
|
|
2262
|
+
value = toRaw(value);
|
|
2263
|
+
}
|
|
2264
|
+
const target = toRaw(this);
|
|
2265
|
+
const proto = getProto(target);
|
|
2266
|
+
const hadKey = proto.has.call(target, value);
|
|
2267
|
+
if (!hadKey) {
|
|
2268
|
+
target.add(value);
|
|
2269
|
+
trigger(target, "add", value, value);
|
|
2270
|
+
}
|
|
2271
|
+
return this;
|
|
2272
|
+
},
|
|
2273
|
+
set(key, value) {
|
|
2274
|
+
if (!shallow && !isShallow(value) && !isReadonly(value)) {
|
|
2275
|
+
value = toRaw(value);
|
|
2276
|
+
}
|
|
2277
|
+
const target = toRaw(this);
|
|
2278
|
+
const { has, get } = getProto(target);
|
|
2279
|
+
let hadKey = has.call(target, key);
|
|
2280
|
+
if (!hadKey) {
|
|
2281
|
+
key = toRaw(key);
|
|
2282
|
+
hadKey = has.call(target, key);
|
|
2283
|
+
}
|
|
2284
|
+
const oldValue = get.call(target, key);
|
|
2285
|
+
target.set(key, value);
|
|
2286
|
+
if (!hadKey) {
|
|
2287
|
+
trigger(target, "add", key, value);
|
|
2288
|
+
} else if (hasChanged(value, oldValue)) {
|
|
2289
|
+
trigger(target, "set", key, value);
|
|
2290
|
+
}
|
|
2291
|
+
return this;
|
|
2292
|
+
},
|
|
2293
|
+
delete(key) {
|
|
2294
|
+
const target = toRaw(this);
|
|
2295
|
+
const { has, get } = getProto(target);
|
|
2296
|
+
let hadKey = has.call(target, key);
|
|
2297
|
+
if (!hadKey) {
|
|
2298
|
+
key = toRaw(key);
|
|
2299
|
+
hadKey = has.call(target, key);
|
|
2300
|
+
}
|
|
2301
|
+
get ? get.call(target, key) : void 0;
|
|
2302
|
+
const result = target.delete(key);
|
|
2303
|
+
if (hadKey) {
|
|
2304
|
+
trigger(target, "delete", key, void 0);
|
|
2305
|
+
}
|
|
2306
|
+
return result;
|
|
2307
|
+
},
|
|
2308
|
+
clear() {
|
|
2309
|
+
const target = toRaw(this);
|
|
2310
|
+
const hadItems = target.size !== 0;
|
|
2311
|
+
const result = target.clear();
|
|
2312
|
+
if (hadItems) {
|
|
2313
|
+
trigger(
|
|
2314
|
+
target,
|
|
2315
|
+
"clear",
|
|
2316
|
+
void 0,
|
|
2317
|
+
void 0
|
|
2318
|
+
);
|
|
2319
|
+
}
|
|
2320
|
+
return result;
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
);
|
|
2324
|
+
const iteratorMethods = [
|
|
2325
|
+
"keys",
|
|
2326
|
+
"values",
|
|
2327
|
+
"entries",
|
|
2328
|
+
Symbol.iterator
|
|
2329
|
+
];
|
|
2330
|
+
iteratorMethods.forEach((method) => {
|
|
2331
|
+
instrumentations[method] = createIterableMethod(method, readonly2, shallow);
|
|
2332
|
+
});
|
|
2333
|
+
return instrumentations;
|
|
2334
|
+
}
|
|
2335
|
+
function createInstrumentationGetter(isReadonly2, shallow) {
|
|
2336
|
+
const instrumentations = createInstrumentations(isReadonly2, shallow);
|
|
2337
|
+
return (target, key, receiver) => {
|
|
2338
|
+
if (key === "__v_isReactive") {
|
|
2339
|
+
return !isReadonly2;
|
|
2340
|
+
} else if (key === "__v_isReadonly") {
|
|
2341
|
+
return isReadonly2;
|
|
2342
|
+
} else if (key === "__v_raw") {
|
|
2343
|
+
return target;
|
|
2344
|
+
}
|
|
2345
|
+
return Reflect.get(
|
|
2346
|
+
hasOwn(instrumentations, key) && key in target ? instrumentations : target,
|
|
2347
|
+
key,
|
|
2348
|
+
receiver
|
|
2349
|
+
);
|
|
2350
|
+
};
|
|
2351
|
+
}
|
|
2352
|
+
const mutableCollectionHandlers = {
|
|
2353
|
+
get: /* @__PURE__ */ createInstrumentationGetter(false, false)
|
|
2354
|
+
};
|
|
2355
|
+
const readonlyCollectionHandlers = {
|
|
2356
|
+
get: /* @__PURE__ */ createInstrumentationGetter(true, false)
|
|
2357
|
+
};
|
|
2358
|
+
const reactiveMap = /* @__PURE__ */ new WeakMap();
|
|
2359
|
+
const shallowReactiveMap = /* @__PURE__ */ new WeakMap();
|
|
2360
|
+
const readonlyMap = /* @__PURE__ */ new WeakMap();
|
|
2361
|
+
const shallowReadonlyMap = /* @__PURE__ */ new WeakMap();
|
|
2362
|
+
function targetTypeMap(rawType) {
|
|
2363
|
+
switch (rawType) {
|
|
2364
|
+
case "Object":
|
|
2365
|
+
case "Array":
|
|
2366
|
+
return 1;
|
|
2367
|
+
case "Map":
|
|
2368
|
+
case "Set":
|
|
2369
|
+
case "WeakMap":
|
|
2370
|
+
case "WeakSet":
|
|
2371
|
+
return 2;
|
|
2372
|
+
default:
|
|
2373
|
+
return 0;
|
|
2374
|
+
}
|
|
2375
|
+
}
|
|
2376
|
+
function getTargetType(value) {
|
|
2377
|
+
return value["__v_skip"] || !Object.isExtensible(value) ? 0 : targetTypeMap(toRawType(value));
|
|
2378
|
+
}
|
|
2379
|
+
function reactive(target) {
|
|
2380
|
+
if (isReadonly(target)) {
|
|
2381
|
+
return target;
|
|
2382
|
+
}
|
|
2383
|
+
return createReactiveObject(
|
|
2384
|
+
target,
|
|
2385
|
+
false,
|
|
2386
|
+
mutableHandlers,
|
|
2387
|
+
mutableCollectionHandlers,
|
|
2388
|
+
reactiveMap
|
|
2389
|
+
);
|
|
2390
|
+
}
|
|
2391
|
+
function readonly(target) {
|
|
2392
|
+
return createReactiveObject(
|
|
2393
|
+
target,
|
|
2394
|
+
true,
|
|
2395
|
+
readonlyHandlers,
|
|
2396
|
+
readonlyCollectionHandlers,
|
|
2397
|
+
readonlyMap
|
|
2398
|
+
);
|
|
2399
|
+
}
|
|
2400
|
+
function createReactiveObject(target, isReadonly2, baseHandlers, collectionHandlers, proxyMap) {
|
|
2401
|
+
if (!isObject(target)) {
|
|
2402
|
+
return target;
|
|
2403
|
+
}
|
|
2404
|
+
if (target["__v_raw"] && !(isReadonly2 && target["__v_isReactive"])) {
|
|
2405
|
+
return target;
|
|
2406
|
+
}
|
|
2407
|
+
const targetType = getTargetType(target);
|
|
2408
|
+
if (targetType === 0) {
|
|
2409
|
+
return target;
|
|
2410
|
+
}
|
|
2411
|
+
const existingProxy = proxyMap.get(target);
|
|
2412
|
+
if (existingProxy) {
|
|
2413
|
+
return existingProxy;
|
|
2414
|
+
}
|
|
2415
|
+
const proxy = new Proxy(
|
|
2416
|
+
target,
|
|
2417
|
+
targetType === 2 ? collectionHandlers : baseHandlers
|
|
2418
|
+
);
|
|
2419
|
+
proxyMap.set(target, proxy);
|
|
2420
|
+
return proxy;
|
|
2421
|
+
}
|
|
2422
|
+
function isReadonly(value) {
|
|
2423
|
+
return !!(value && value["__v_isReadonly"]);
|
|
2424
|
+
}
|
|
2425
|
+
function isShallow(value) {
|
|
2426
|
+
return !!(value && value["__v_isShallow"]);
|
|
2427
|
+
}
|
|
2428
|
+
function isProxy(value) {
|
|
2429
|
+
return value ? !!value["__v_raw"] : false;
|
|
2430
|
+
}
|
|
2431
|
+
function toRaw(observed) {
|
|
2432
|
+
const raw = observed && observed["__v_raw"];
|
|
2433
|
+
return raw ? toRaw(raw) : observed;
|
|
2434
|
+
}
|
|
2435
|
+
const toReactive = (value) => isObject(value) ? reactive(value) : value;
|
|
2436
|
+
const toReadonly = (value) => isObject(value) ? readonly(value) : value;
|
|
2437
|
+
function isRef(r) {
|
|
2438
|
+
return r ? r["__v_isRef"] === true : false;
|
|
2439
|
+
}
|
|
2440
|
+
function ref(value) {
|
|
2441
|
+
return createRef(value, false);
|
|
2442
|
+
}
|
|
2443
|
+
function createRef(rawValue, shallow) {
|
|
2444
|
+
if (isRef(rawValue)) {
|
|
2445
|
+
return rawValue;
|
|
2446
|
+
}
|
|
2447
|
+
return new RefImpl(rawValue, shallow);
|
|
2448
|
+
}
|
|
2449
|
+
class RefImpl {
|
|
2450
|
+
constructor(value, isShallow2) {
|
|
2451
|
+
this.dep = new Dep();
|
|
2452
|
+
this["__v_isRef"] = true;
|
|
2453
|
+
this["__v_isShallow"] = false;
|
|
2454
|
+
this._rawValue = isShallow2 ? value : toRaw(value);
|
|
2455
|
+
this._value = isShallow2 ? value : toReactive(value);
|
|
2456
|
+
this["__v_isShallow"] = isShallow2;
|
|
2457
|
+
}
|
|
2458
|
+
get value() {
|
|
2459
|
+
{
|
|
2460
|
+
this.dep.track();
|
|
2461
|
+
}
|
|
2462
|
+
return this._value;
|
|
2463
|
+
}
|
|
2464
|
+
set value(newValue) {
|
|
2465
|
+
const oldValue = this._rawValue;
|
|
2466
|
+
const useDirectValue = this["__v_isShallow"] || isShallow(newValue) || isReadonly(newValue);
|
|
2467
|
+
newValue = useDirectValue ? newValue : toRaw(newValue);
|
|
2468
|
+
if (hasChanged(newValue, oldValue)) {
|
|
2469
|
+
this._rawValue = newValue;
|
|
2470
|
+
this._value = useDirectValue ? newValue : toReactive(newValue);
|
|
2471
|
+
{
|
|
2472
|
+
this.dep.trigger();
|
|
2473
|
+
}
|
|
2474
|
+
}
|
|
2475
|
+
}
|
|
2476
|
+
}
|
|
2477
|
+
class ComputedRefImpl {
|
|
2478
|
+
constructor(fn, setter, isSSR) {
|
|
2479
|
+
this.fn = fn;
|
|
2480
|
+
this.setter = setter;
|
|
2481
|
+
this._value = void 0;
|
|
2482
|
+
this.dep = new Dep(this);
|
|
2483
|
+
this.__v_isRef = true;
|
|
2484
|
+
this.deps = void 0;
|
|
2485
|
+
this.depsTail = void 0;
|
|
2486
|
+
this.flags = 16;
|
|
2487
|
+
this.globalVersion = globalVersion - 1;
|
|
2488
|
+
this.next = void 0;
|
|
2489
|
+
this.effect = this;
|
|
2490
|
+
this["__v_isReadonly"] = !setter;
|
|
2491
|
+
this.isSSR = isSSR;
|
|
2492
|
+
}
|
|
2493
|
+
/**
|
|
2494
|
+
* @internal
|
|
2495
|
+
*/
|
|
2496
|
+
notify() {
|
|
2497
|
+
this.flags |= 16;
|
|
2498
|
+
if (!(this.flags & 8) && // avoid infinite self recursion
|
|
2499
|
+
activeSub !== this) {
|
|
2500
|
+
batch(this, true);
|
|
2501
|
+
return true;
|
|
2502
|
+
}
|
|
2503
|
+
}
|
|
2504
|
+
get value() {
|
|
2505
|
+
const link = this.dep.track();
|
|
2506
|
+
refreshComputed(this);
|
|
2507
|
+
if (link) {
|
|
2508
|
+
link.version = this.dep.version;
|
|
2509
|
+
}
|
|
2510
|
+
return this._value;
|
|
2511
|
+
}
|
|
2512
|
+
set value(newValue) {
|
|
2513
|
+
if (this.setter) {
|
|
2514
|
+
this.setter(newValue);
|
|
2515
|
+
}
|
|
2516
|
+
}
|
|
2517
|
+
}
|
|
2518
|
+
function computed(getterOrOptions, debugOptions, isSSR = false) {
|
|
2519
|
+
let getter;
|
|
2520
|
+
let setter;
|
|
2521
|
+
if (isFunction(getterOrOptions)) {
|
|
2522
|
+
getter = getterOrOptions;
|
|
2523
|
+
} else {
|
|
2524
|
+
getter = getterOrOptions.get;
|
|
2525
|
+
setter = getterOrOptions.set;
|
|
2526
|
+
}
|
|
2527
|
+
const cRef = new ComputedRefImpl(getter, setter, isSSR);
|
|
2528
|
+
return cRef;
|
|
2529
|
+
}
|
|
2530
|
+
const dependencies = { "@feng3d/reactivity": "1.0.6", "@vue/reactivity": "^3.5.14" };
|
|
2531
|
+
const pkg = {
|
|
2532
|
+
dependencies
|
|
2533
|
+
};
|
|
2534
|
+
export {
|
|
2535
|
+
computed$1 as a,
|
|
2536
|
+
ref$1 as b,
|
|
2537
|
+
computed as c,
|
|
2538
|
+
pkg as p,
|
|
2539
|
+
ref as r
|
|
2540
|
+
};
|