@vue/reactivity 3.6.0-alpha.7 → 3.6.0-beta.10
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/dist/reactivity.cjs.js +1778 -1881
- package/dist/reactivity.cjs.prod.js +1667 -1686
- package/dist/reactivity.d.ts +633 -633
- package/dist/reactivity.esm-browser.js +1812 -1895
- package/dist/reactivity.esm-browser.prod.js +5 -4
- package/dist/reactivity.esm-bundler.js +1776 -1889
- package/dist/reactivity.global.js +2049 -2135
- package/dist/reactivity.global.prod.js +5 -4
- package/package.json +2 -2
|
@@ -1,18 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vue/reactivity v3.6.0-
|
|
3
|
-
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
4
|
-
* @license MIT
|
|
5
|
-
**/
|
|
6
|
-
|
|
2
|
+
* @vue/reactivity v3.6.0-beta.10
|
|
3
|
+
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
4
|
+
* @license MIT
|
|
5
|
+
**/
|
|
6
|
+
//#region packages/shared/src/makeMap.ts
|
|
7
|
+
/**
|
|
8
|
+
* Make a map and return a function for checking if a key
|
|
9
|
+
* is in that map.
|
|
10
|
+
* IMPORTANT: all calls of this function must be prefixed with
|
|
11
|
+
* \/\*#\_\_PURE\_\_\*\/
|
|
12
|
+
* So that they can be tree-shaken if necessary.
|
|
13
|
+
*/
|
|
14
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
7
15
|
function makeMap(str) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
+
const map = Object.create(null);
|
|
17
|
+
for (const key of str.split(",")) map[key] = 1;
|
|
18
|
+
return (val) => val in map;
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region packages/shared/src/general.ts
|
|
22
|
+
const EMPTY_OBJ = Object.freeze({});
|
|
23
|
+
Object.freeze([]);
|
|
24
|
+
const NOOP = () => {};
|
|
16
25
|
const extend = Object.assign;
|
|
17
26
|
const hasOwnProperty$1 = Object.prototype.hasOwnProperty;
|
|
18
27
|
const hasOwn = (val, key) => hasOwnProperty$1.call(val, key);
|
|
@@ -26,44 +35,97 @@ const isObject = (val) => val !== null && typeof val === "object";
|
|
|
26
35
|
const objectToString = Object.prototype.toString;
|
|
27
36
|
const toTypeString = (value) => objectToString.call(value);
|
|
28
37
|
const toRawType = (value) => {
|
|
29
|
-
|
|
38
|
+
return toTypeString(value).slice(8, -1);
|
|
30
39
|
};
|
|
31
40
|
const isPlainObject = (val) => toTypeString(val) === "[object Object]";
|
|
32
41
|
const isIntegerKey = (key) => isString(key) && key !== "NaN" && key[0] !== "-" && "" + parseInt(key, 10) === key;
|
|
33
42
|
const cacheStringFunction = (fn) => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
});
|
|
43
|
+
const cache = Object.create(null);
|
|
44
|
+
return ((str) => {
|
|
45
|
+
return cache[str] || (cache[str] = fn(str));
|
|
46
|
+
});
|
|
39
47
|
};
|
|
48
|
+
const camelizeRE = /-(\w)/g;
|
|
49
|
+
const camelizeReplacer = (_, c) => c ? c.toUpperCase() : "";
|
|
50
|
+
cacheStringFunction((str) => str.replace(camelizeRE, camelizeReplacer));
|
|
51
|
+
const hyphenateRE = /\B([A-Z])/g;
|
|
52
|
+
cacheStringFunction((str) => str.replace(hyphenateRE, "-$1").toLowerCase());
|
|
53
|
+
/**
|
|
54
|
+
* @private
|
|
55
|
+
*/
|
|
40
56
|
const capitalize = cacheStringFunction((str) => {
|
|
41
|
-
|
|
57
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
58
|
+
});
|
|
59
|
+
cacheStringFunction((str) => {
|
|
60
|
+
return str ? `on${capitalize(str)}` : ``;
|
|
42
61
|
});
|
|
43
62
|
const hasChanged = (value, oldValue) => !Object.is(value, oldValue);
|
|
44
63
|
const def = (obj, key, value, writable = false) => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
64
|
+
Object.defineProperty(obj, key, {
|
|
65
|
+
configurable: true,
|
|
66
|
+
enumerable: false,
|
|
67
|
+
writable,
|
|
68
|
+
value
|
|
69
|
+
});
|
|
51
70
|
};
|
|
52
|
-
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region packages/reactivity/src/debug.ts
|
|
73
|
+
const triggerEventInfos = [];
|
|
74
|
+
function onTrack(sub, debugInfo) {
|
|
75
|
+
if (sub.onTrack) sub.onTrack(extend({ effect: sub }, debugInfo));
|
|
76
|
+
}
|
|
77
|
+
function onTrigger(sub) {
|
|
78
|
+
if (sub.onTrigger) {
|
|
79
|
+
const debugInfo = triggerEventInfos[triggerEventInfos.length - 1];
|
|
80
|
+
sub.onTrigger(extend({ effect: sub }, debugInfo));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function setupOnTrigger(target) {
|
|
84
|
+
Object.defineProperty(target.prototype, "onTrigger", {
|
|
85
|
+
get() {
|
|
86
|
+
return this._onTrigger;
|
|
87
|
+
},
|
|
88
|
+
set(val) {
|
|
89
|
+
if (val && !this._onTrigger) setupFlagsHandler(this);
|
|
90
|
+
this._onTrigger = val;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
function setupFlagsHandler(target) {
|
|
95
|
+
target._flags = target.flags;
|
|
96
|
+
Object.defineProperty(target, "flags", {
|
|
97
|
+
get() {
|
|
98
|
+
return target._flags;
|
|
99
|
+
},
|
|
100
|
+
set(value) {
|
|
101
|
+
if (!(target._flags & 48) && !!(value & 48)) onTrigger(this);
|
|
102
|
+
target._flags = value;
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
//#endregion
|
|
107
|
+
//#region packages/reactivity/src/warning.ts
|
|
53
108
|
function warn(msg, ...args) {
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
109
|
+
console.warn(`[Vue warn] ${msg}`, ...args);
|
|
110
|
+
}
|
|
111
|
+
//#endregion
|
|
112
|
+
//#region packages/reactivity/src/system.ts
|
|
113
|
+
const ReactiveFlags$1 = {
|
|
114
|
+
"None": 0,
|
|
115
|
+
"0": "None",
|
|
116
|
+
"Mutable": 1,
|
|
117
|
+
"1": "Mutable",
|
|
118
|
+
"Watching": 2,
|
|
119
|
+
"2": "Watching",
|
|
120
|
+
"RecursedCheck": 4,
|
|
121
|
+
"4": "RecursedCheck",
|
|
122
|
+
"Recursed": 8,
|
|
123
|
+
"8": "Recursed",
|
|
124
|
+
"Dirty": 16,
|
|
125
|
+
"16": "Dirty",
|
|
126
|
+
"Pending": 32,
|
|
127
|
+
"32": "Pending"
|
|
128
|
+
};
|
|
67
129
|
const notifyBuffer = [];
|
|
68
130
|
let batchDepth = 0;
|
|
69
131
|
let activeSub = void 0;
|
|
@@ -71,2008 +133,1863 @@ let globalVersion = 0;
|
|
|
71
133
|
let notifyIndex = 0;
|
|
72
134
|
let notifyBufferLength = 0;
|
|
73
135
|
function setActiveSub(sub) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
136
|
+
try {
|
|
137
|
+
return activeSub;
|
|
138
|
+
} finally {
|
|
139
|
+
activeSub = sub;
|
|
140
|
+
}
|
|
79
141
|
}
|
|
80
142
|
function startBatch() {
|
|
81
|
-
|
|
143
|
+
++batchDepth;
|
|
82
144
|
}
|
|
83
145
|
function endBatch() {
|
|
84
|
-
|
|
85
|
-
flush();
|
|
86
|
-
}
|
|
146
|
+
if (!--batchDepth && notifyBufferLength) flush();
|
|
87
147
|
}
|
|
88
148
|
function link(dep, sub) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
if (flags & 1 /* Mutable */) {
|
|
183
|
-
const subSubs = sub.subs;
|
|
184
|
-
if (subSubs !== void 0) {
|
|
185
|
-
link2 = subSubs;
|
|
186
|
-
if (subSubs.nextSub !== void 0) {
|
|
187
|
-
stack = { value: next, prev: stack };
|
|
188
|
-
next = link2.nextSub;
|
|
189
|
-
}
|
|
190
|
-
continue;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
if ((link2 = next) !== void 0) {
|
|
195
|
-
next = link2.nextSub;
|
|
196
|
-
continue;
|
|
197
|
-
}
|
|
198
|
-
while (stack !== void 0) {
|
|
199
|
-
link2 = stack.value;
|
|
200
|
-
stack = stack.prev;
|
|
201
|
-
if (link2 !== void 0) {
|
|
202
|
-
next = link2.nextSub;
|
|
203
|
-
continue top;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
break;
|
|
207
|
-
} while (true);
|
|
149
|
+
const prevDep = sub.depsTail;
|
|
150
|
+
if (prevDep !== void 0 && prevDep.dep === dep) return;
|
|
151
|
+
const nextDep = prevDep !== void 0 ? prevDep.nextDep : sub.deps;
|
|
152
|
+
if (nextDep !== void 0 && nextDep.dep === dep) {
|
|
153
|
+
nextDep.version = globalVersion;
|
|
154
|
+
sub.depsTail = nextDep;
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const prevSub = dep.subsTail;
|
|
158
|
+
if (prevSub !== void 0 && prevSub.version === globalVersion && prevSub.sub === sub) return;
|
|
159
|
+
const newLink = sub.depsTail = dep.subsTail = {
|
|
160
|
+
version: globalVersion,
|
|
161
|
+
dep,
|
|
162
|
+
sub,
|
|
163
|
+
prevDep,
|
|
164
|
+
nextDep,
|
|
165
|
+
prevSub,
|
|
166
|
+
nextSub: void 0
|
|
167
|
+
};
|
|
168
|
+
if (nextDep !== void 0) nextDep.prevDep = newLink;
|
|
169
|
+
if (prevDep !== void 0) prevDep.nextDep = newLink;
|
|
170
|
+
else sub.deps = newLink;
|
|
171
|
+
if (prevSub !== void 0) prevSub.nextSub = newLink;
|
|
172
|
+
else dep.subs = newLink;
|
|
173
|
+
}
|
|
174
|
+
function unlink(link, sub = link.sub) {
|
|
175
|
+
const dep = link.dep;
|
|
176
|
+
const prevDep = link.prevDep;
|
|
177
|
+
const nextDep = link.nextDep;
|
|
178
|
+
const nextSub = link.nextSub;
|
|
179
|
+
const prevSub = link.prevSub;
|
|
180
|
+
if (nextDep !== void 0) nextDep.prevDep = prevDep;
|
|
181
|
+
else sub.depsTail = prevDep;
|
|
182
|
+
if (prevDep !== void 0) prevDep.nextDep = nextDep;
|
|
183
|
+
else sub.deps = nextDep;
|
|
184
|
+
if (nextSub !== void 0) nextSub.prevSub = prevSub;
|
|
185
|
+
else dep.subsTail = prevSub;
|
|
186
|
+
if (prevSub !== void 0) prevSub.nextSub = nextSub;
|
|
187
|
+
else if ((dep.subs = nextSub) === void 0) {
|
|
188
|
+
let toRemove = dep.deps;
|
|
189
|
+
if (toRemove !== void 0) {
|
|
190
|
+
do
|
|
191
|
+
toRemove = unlink(toRemove, dep);
|
|
192
|
+
while (toRemove !== void 0);
|
|
193
|
+
dep.flags |= 16;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return nextDep;
|
|
197
|
+
}
|
|
198
|
+
function propagate(link) {
|
|
199
|
+
let next = link.nextSub;
|
|
200
|
+
let stack;
|
|
201
|
+
top: do {
|
|
202
|
+
const sub = link.sub;
|
|
203
|
+
let flags = sub.flags;
|
|
204
|
+
if (flags & 3) {
|
|
205
|
+
if (!(flags & 60)) sub.flags = flags | 32;
|
|
206
|
+
else if (!(flags & 12)) flags = 0;
|
|
207
|
+
else if (!(flags & 4)) sub.flags = flags & -9 | 32;
|
|
208
|
+
else if (!(flags & 48) && isValidLink(link, sub)) {
|
|
209
|
+
sub.flags = flags | 40;
|
|
210
|
+
flags &= 1;
|
|
211
|
+
} else flags = 0;
|
|
212
|
+
if (flags & 2) notifyBuffer[notifyBufferLength++] = sub;
|
|
213
|
+
if (flags & 1) {
|
|
214
|
+
const subSubs = sub.subs;
|
|
215
|
+
if (subSubs !== void 0) {
|
|
216
|
+
link = subSubs;
|
|
217
|
+
if (subSubs.nextSub !== void 0) {
|
|
218
|
+
stack = {
|
|
219
|
+
value: next,
|
|
220
|
+
prev: stack
|
|
221
|
+
};
|
|
222
|
+
next = link.nextSub;
|
|
223
|
+
}
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
if ((link = next) !== void 0) {
|
|
229
|
+
next = link.nextSub;
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
while (stack !== void 0) {
|
|
233
|
+
link = stack.value;
|
|
234
|
+
stack = stack.prev;
|
|
235
|
+
if (link !== void 0) {
|
|
236
|
+
next = link.nextSub;
|
|
237
|
+
continue top;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
break;
|
|
241
|
+
} while (true);
|
|
208
242
|
}
|
|
209
243
|
function startTracking(sub) {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
244
|
+
++globalVersion;
|
|
245
|
+
sub.depsTail = void 0;
|
|
246
|
+
sub.flags = sub.flags & -57 | 4;
|
|
247
|
+
return setActiveSub(sub);
|
|
214
248
|
}
|
|
215
249
|
function endTracking(sub, prevSub) {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
const depsTail = sub.depsTail;
|
|
223
|
-
let toRemove = depsTail !== void 0 ? depsTail.nextDep : sub.deps;
|
|
224
|
-
while (toRemove !== void 0) {
|
|
225
|
-
toRemove = unlink(toRemove, sub);
|
|
226
|
-
}
|
|
227
|
-
sub.flags &= -5 /* RecursedCheck */;
|
|
250
|
+
if (activeSub !== sub) warn("Active effect was not restored correctly - this is likely a Vue internal bug.");
|
|
251
|
+
activeSub = prevSub;
|
|
252
|
+
const depsTail = sub.depsTail;
|
|
253
|
+
let toRemove = depsTail !== void 0 ? depsTail.nextDep : sub.deps;
|
|
254
|
+
while (toRemove !== void 0) toRemove = unlink(toRemove, sub);
|
|
255
|
+
sub.flags &= -5;
|
|
228
256
|
}
|
|
229
257
|
function flush() {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
}
|
|
238
|
-
function checkDirty(
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
}
|
|
299
|
-
function shallowPropagate(link2) {
|
|
300
|
-
do {
|
|
301
|
-
const sub = link2.sub;
|
|
302
|
-
const nextSub = link2.nextSub;
|
|
303
|
-
const subFlags = sub.flags;
|
|
304
|
-
if ((subFlags & (32 /* Pending */ | 16 /* Dirty */)) === 32 /* Pending */) {
|
|
305
|
-
sub.flags = subFlags | 16 /* Dirty */;
|
|
306
|
-
}
|
|
307
|
-
link2 = nextSub;
|
|
308
|
-
} while (link2 !== void 0);
|
|
258
|
+
while (notifyIndex < notifyBufferLength) {
|
|
259
|
+
const effect = notifyBuffer[notifyIndex];
|
|
260
|
+
notifyBuffer[notifyIndex++] = void 0;
|
|
261
|
+
effect.notify();
|
|
262
|
+
}
|
|
263
|
+
notifyIndex = 0;
|
|
264
|
+
notifyBufferLength = 0;
|
|
265
|
+
}
|
|
266
|
+
function checkDirty(link, sub) {
|
|
267
|
+
let stack;
|
|
268
|
+
let checkDepth = 0;
|
|
269
|
+
top: do {
|
|
270
|
+
const dep = link.dep;
|
|
271
|
+
const depFlags = dep.flags;
|
|
272
|
+
let dirty = false;
|
|
273
|
+
if (sub.flags & 16) dirty = true;
|
|
274
|
+
else if ((depFlags & 17) === 17) {
|
|
275
|
+
if (dep.update()) {
|
|
276
|
+
const subs = dep.subs;
|
|
277
|
+
if (subs.nextSub !== void 0) shallowPropagate(subs);
|
|
278
|
+
dirty = true;
|
|
279
|
+
}
|
|
280
|
+
} else if ((depFlags & 33) === 33) {
|
|
281
|
+
if (link.nextSub !== void 0 || link.prevSub !== void 0) stack = {
|
|
282
|
+
value: link,
|
|
283
|
+
prev: stack
|
|
284
|
+
};
|
|
285
|
+
link = dep.deps;
|
|
286
|
+
sub = dep;
|
|
287
|
+
++checkDepth;
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
if (!dirty && link.nextDep !== void 0) {
|
|
291
|
+
link = link.nextDep;
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
while (checkDepth) {
|
|
295
|
+
--checkDepth;
|
|
296
|
+
const firstSub = sub.subs;
|
|
297
|
+
const hasMultipleSubs = firstSub.nextSub !== void 0;
|
|
298
|
+
if (hasMultipleSubs) {
|
|
299
|
+
link = stack.value;
|
|
300
|
+
stack = stack.prev;
|
|
301
|
+
} else link = firstSub;
|
|
302
|
+
if (dirty) {
|
|
303
|
+
if (sub.update()) {
|
|
304
|
+
if (hasMultipleSubs) shallowPropagate(firstSub);
|
|
305
|
+
sub = link.sub;
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
} else sub.flags &= -33;
|
|
309
|
+
sub = link.sub;
|
|
310
|
+
if (link.nextDep !== void 0) {
|
|
311
|
+
link = link.nextDep;
|
|
312
|
+
continue top;
|
|
313
|
+
}
|
|
314
|
+
dirty = false;
|
|
315
|
+
}
|
|
316
|
+
return dirty;
|
|
317
|
+
} while (true);
|
|
318
|
+
}
|
|
319
|
+
function shallowPropagate(link) {
|
|
320
|
+
do {
|
|
321
|
+
const sub = link.sub;
|
|
322
|
+
const nextSub = link.nextSub;
|
|
323
|
+
const subFlags = sub.flags;
|
|
324
|
+
if ((subFlags & 48) === 32) sub.flags = subFlags | 16;
|
|
325
|
+
link = nextSub;
|
|
326
|
+
} while (link !== void 0);
|
|
309
327
|
}
|
|
310
328
|
function isValidLink(checkLink, sub) {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
const debugInfo = triggerEventInfos[triggerEventInfos.length - 1];
|
|
337
|
-
sub.onTrigger(
|
|
338
|
-
extend(
|
|
339
|
-
{
|
|
340
|
-
effect: sub
|
|
341
|
-
},
|
|
342
|
-
debugInfo
|
|
343
|
-
)
|
|
344
|
-
);
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
function setupOnTrigger(target) {
|
|
348
|
-
Object.defineProperty(target.prototype, "onTrigger", {
|
|
349
|
-
get() {
|
|
350
|
-
return this._onTrigger;
|
|
351
|
-
},
|
|
352
|
-
set(val) {
|
|
353
|
-
if (val && !this._onTrigger) setupFlagsHandler(this);
|
|
354
|
-
this._onTrigger = val;
|
|
355
|
-
}
|
|
356
|
-
});
|
|
357
|
-
}
|
|
358
|
-
function setupFlagsHandler(target) {
|
|
359
|
-
target._flags = target.flags;
|
|
360
|
-
Object.defineProperty(target, "flags", {
|
|
361
|
-
get() {
|
|
362
|
-
return target._flags;
|
|
363
|
-
},
|
|
364
|
-
set(value) {
|
|
365
|
-
if (!(target._flags & (ReactiveFlags$1.Dirty | ReactiveFlags$1.Pending)) && !!(value & (ReactiveFlags$1.Dirty | ReactiveFlags$1.Pending))) {
|
|
366
|
-
onTrigger(this);
|
|
367
|
-
}
|
|
368
|
-
target._flags = value;
|
|
369
|
-
}
|
|
370
|
-
});
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
class Dep {
|
|
374
|
-
constructor(map, key) {
|
|
375
|
-
this.map = map;
|
|
376
|
-
this.key = key;
|
|
377
|
-
this._subs = void 0;
|
|
378
|
-
this.subsTail = void 0;
|
|
379
|
-
this.flags = ReactiveFlags$1.None;
|
|
380
|
-
}
|
|
381
|
-
get subs() {
|
|
382
|
-
return this._subs;
|
|
383
|
-
}
|
|
384
|
-
set subs(value) {
|
|
385
|
-
this._subs = value;
|
|
386
|
-
if (value === void 0) {
|
|
387
|
-
this.map.delete(this.key);
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
}
|
|
329
|
+
let link = sub.depsTail;
|
|
330
|
+
while (link !== void 0) {
|
|
331
|
+
if (link === checkLink) return true;
|
|
332
|
+
link = link.prevDep;
|
|
333
|
+
}
|
|
334
|
+
return false;
|
|
335
|
+
}
|
|
336
|
+
//#endregion
|
|
337
|
+
//#region packages/reactivity/src/dep.ts
|
|
338
|
+
var Dep = class {
|
|
339
|
+
constructor(map, key) {
|
|
340
|
+
this.map = map;
|
|
341
|
+
this.key = key;
|
|
342
|
+
this._subs = void 0;
|
|
343
|
+
this.subsTail = void 0;
|
|
344
|
+
this.flags = 0;
|
|
345
|
+
}
|
|
346
|
+
get subs() {
|
|
347
|
+
return this._subs;
|
|
348
|
+
}
|
|
349
|
+
set subs(value) {
|
|
350
|
+
this._subs = value;
|
|
351
|
+
if (value === void 0) this.map.delete(this.key);
|
|
352
|
+
}
|
|
353
|
+
};
|
|
391
354
|
const targetMap = /* @__PURE__ */ new WeakMap();
|
|
392
|
-
const ITERATE_KEY = Symbol(
|
|
393
|
-
|
|
394
|
-
);
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
355
|
+
const ITERATE_KEY = Symbol("Object iterate");
|
|
356
|
+
const MAP_KEY_ITERATE_KEY = Symbol("Map keys iterate");
|
|
357
|
+
const ARRAY_ITERATE_KEY = Symbol("Array iterate");
|
|
358
|
+
/**
|
|
359
|
+
* Tracks access to a reactive property.
|
|
360
|
+
*
|
|
361
|
+
* This will check which effect is running at the moment and record it as dep
|
|
362
|
+
* which records all effects that depend on the reactive property.
|
|
363
|
+
*
|
|
364
|
+
* @param target - Object holding the reactive property.
|
|
365
|
+
* @param type - Defines the type of access to the reactive property.
|
|
366
|
+
* @param key - Identifier of the reactive property to track.
|
|
367
|
+
*/
|
|
401
368
|
function track(target, type, key) {
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
type,
|
|
415
|
-
key
|
|
416
|
-
});
|
|
417
|
-
}
|
|
418
|
-
link(dep, activeSub);
|
|
419
|
-
}
|
|
369
|
+
if (activeSub !== void 0) {
|
|
370
|
+
let depsMap = targetMap.get(target);
|
|
371
|
+
if (!depsMap) targetMap.set(target, depsMap = /* @__PURE__ */ new Map());
|
|
372
|
+
let dep = depsMap.get(key);
|
|
373
|
+
if (!dep) depsMap.set(key, dep = new Dep(depsMap, key));
|
|
374
|
+
onTrack(activeSub, {
|
|
375
|
+
target,
|
|
376
|
+
type,
|
|
377
|
+
key
|
|
378
|
+
});
|
|
379
|
+
link(dep, activeSub);
|
|
380
|
+
}
|
|
420
381
|
}
|
|
382
|
+
/**
|
|
383
|
+
* Finds all deps associated with the target (or a specific property) and
|
|
384
|
+
* triggers the effects stored within.
|
|
385
|
+
*
|
|
386
|
+
* @param target - The reactive object.
|
|
387
|
+
* @param type - Defines the type of the operation that needs to trigger effects.
|
|
388
|
+
* @param key - Can be used to target a specific reactive property in the target object.
|
|
389
|
+
*/
|
|
421
390
|
function trigger(target, type, key, newValue, oldValue, oldTarget) {
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
} else if (isArrayIndex) {
|
|
473
|
-
run(depsMap.get("length"));
|
|
474
|
-
}
|
|
475
|
-
break;
|
|
476
|
-
case "delete":
|
|
477
|
-
if (!targetIsArray) {
|
|
478
|
-
run(depsMap.get(ITERATE_KEY));
|
|
479
|
-
if (isMap(target)) {
|
|
480
|
-
run(depsMap.get(MAP_KEY_ITERATE_KEY));
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
break;
|
|
484
|
-
case "set":
|
|
485
|
-
if (isMap(target)) {
|
|
486
|
-
run(depsMap.get(ITERATE_KEY));
|
|
487
|
-
}
|
|
488
|
-
break;
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
endBatch();
|
|
391
|
+
const depsMap = targetMap.get(target);
|
|
392
|
+
if (!depsMap) return;
|
|
393
|
+
const run = (dep) => {
|
|
394
|
+
if (dep !== void 0 && dep.subs !== void 0) {
|
|
395
|
+
triggerEventInfos.push({
|
|
396
|
+
target,
|
|
397
|
+
type,
|
|
398
|
+
key,
|
|
399
|
+
newValue,
|
|
400
|
+
oldValue,
|
|
401
|
+
oldTarget
|
|
402
|
+
});
|
|
403
|
+
propagate(dep.subs);
|
|
404
|
+
shallowPropagate(dep.subs);
|
|
405
|
+
triggerEventInfos.pop();
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
startBatch();
|
|
409
|
+
if (type === "clear") depsMap.forEach(run);
|
|
410
|
+
else {
|
|
411
|
+
const targetIsArray = isArray(target);
|
|
412
|
+
const isArrayIndex = targetIsArray && isIntegerKey(key);
|
|
413
|
+
if (targetIsArray && key === "length") {
|
|
414
|
+
const newLength = Number(newValue);
|
|
415
|
+
depsMap.forEach((dep, key) => {
|
|
416
|
+
if (key === "length" || key === ARRAY_ITERATE_KEY || !isSymbol(key) && key >= newLength) run(dep);
|
|
417
|
+
});
|
|
418
|
+
} else {
|
|
419
|
+
if (key !== void 0 || depsMap.has(void 0)) run(depsMap.get(key));
|
|
420
|
+
if (isArrayIndex) run(depsMap.get(ARRAY_ITERATE_KEY));
|
|
421
|
+
switch (type) {
|
|
422
|
+
case "add":
|
|
423
|
+
if (!targetIsArray) {
|
|
424
|
+
run(depsMap.get(ITERATE_KEY));
|
|
425
|
+
if (isMap(target)) run(depsMap.get(MAP_KEY_ITERATE_KEY));
|
|
426
|
+
} else if (isArrayIndex) run(depsMap.get("length"));
|
|
427
|
+
break;
|
|
428
|
+
case "delete":
|
|
429
|
+
if (!targetIsArray) {
|
|
430
|
+
run(depsMap.get(ITERATE_KEY));
|
|
431
|
+
if (isMap(target)) run(depsMap.get(MAP_KEY_ITERATE_KEY));
|
|
432
|
+
}
|
|
433
|
+
break;
|
|
434
|
+
case "set":
|
|
435
|
+
if (isMap(target)) run(depsMap.get(ITERATE_KEY));
|
|
436
|
+
break;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
endBatch();
|
|
493
441
|
}
|
|
494
442
|
function getDepFromReactive(object, key) {
|
|
495
|
-
|
|
496
|
-
|
|
443
|
+
const depMap = targetMap.get(object);
|
|
444
|
+
return depMap && depMap.get(key);
|
|
497
445
|
}
|
|
498
|
-
|
|
446
|
+
//#endregion
|
|
447
|
+
//#region packages/reactivity/src/arrayInstrumentations.ts
|
|
448
|
+
/**
|
|
449
|
+
* Track array iteration and return:
|
|
450
|
+
* - if input is reactive: a cloned raw array with reactive values
|
|
451
|
+
* - if input is non-reactive or shallowReactive: the original raw array
|
|
452
|
+
*/
|
|
499
453
|
function reactiveReadArray(array) {
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
454
|
+
const raw = /* @__PURE__ */ toRaw(array);
|
|
455
|
+
if (raw === array) return raw;
|
|
456
|
+
track(raw, "iterate", ARRAY_ITERATE_KEY);
|
|
457
|
+
return /* @__PURE__ */ isShallow(array) ? raw : raw.map(toReactive);
|
|
504
458
|
}
|
|
459
|
+
/**
|
|
460
|
+
* Track array iteration and return raw array
|
|
461
|
+
*/
|
|
505
462
|
function shallowReadArray(arr) {
|
|
506
|
-
|
|
507
|
-
|
|
463
|
+
track(arr = /* @__PURE__ */ toRaw(arr), "iterate", ARRAY_ITERATE_KEY);
|
|
464
|
+
return arr;
|
|
508
465
|
}
|
|
509
466
|
function toWrapped(target, item) {
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
}
|
|
513
|
-
return toReactive(item);
|
|
467
|
+
if (/* @__PURE__ */ isReadonly(target)) return /* @__PURE__ */ isReactive(target) ? toReadonly(toReactive(item)) : toReadonly(item);
|
|
468
|
+
return toReactive(item);
|
|
514
469
|
}
|
|
515
470
|
const arrayInstrumentations = {
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
},
|
|
602
|
-
shift() {
|
|
603
|
-
return noTracking(this, "shift");
|
|
604
|
-
},
|
|
605
|
-
// slice could use ARRAY_ITERATE but also seems to beg for range tracking
|
|
606
|
-
some(fn, thisArg) {
|
|
607
|
-
return apply(this, "some", fn, thisArg, void 0, arguments);
|
|
608
|
-
},
|
|
609
|
-
splice(...args) {
|
|
610
|
-
return noTracking(this, "splice", args);
|
|
611
|
-
},
|
|
612
|
-
toReversed() {
|
|
613
|
-
return reactiveReadArray(this).toReversed();
|
|
614
|
-
},
|
|
615
|
-
toSorted(comparer) {
|
|
616
|
-
return reactiveReadArray(this).toSorted(comparer);
|
|
617
|
-
},
|
|
618
|
-
toSpliced(...args) {
|
|
619
|
-
return reactiveReadArray(this).toSpliced(...args);
|
|
620
|
-
},
|
|
621
|
-
unshift(...args) {
|
|
622
|
-
return noTracking(this, "unshift", args);
|
|
623
|
-
},
|
|
624
|
-
values() {
|
|
625
|
-
return iterator(this, "values", (item) => toWrapped(this, item));
|
|
626
|
-
}
|
|
471
|
+
__proto__: null,
|
|
472
|
+
[Symbol.iterator]() {
|
|
473
|
+
return iterator(this, Symbol.iterator, (item) => toWrapped(this, item));
|
|
474
|
+
},
|
|
475
|
+
concat(...args) {
|
|
476
|
+
return reactiveReadArray(this).concat(...args.map((x) => isArray(x) ? reactiveReadArray(x) : x));
|
|
477
|
+
},
|
|
478
|
+
entries() {
|
|
479
|
+
return iterator(this, "entries", (value) => {
|
|
480
|
+
value[1] = toWrapped(this, value[1]);
|
|
481
|
+
return value;
|
|
482
|
+
});
|
|
483
|
+
},
|
|
484
|
+
every(fn, thisArg) {
|
|
485
|
+
return apply(this, "every", fn, thisArg, void 0, arguments);
|
|
486
|
+
},
|
|
487
|
+
filter(fn, thisArg) {
|
|
488
|
+
return apply(this, "filter", fn, thisArg, (v) => v.map((item) => toWrapped(this, item)), arguments);
|
|
489
|
+
},
|
|
490
|
+
find(fn, thisArg) {
|
|
491
|
+
return apply(this, "find", fn, thisArg, (item) => toWrapped(this, item), arguments);
|
|
492
|
+
},
|
|
493
|
+
findIndex(fn, thisArg) {
|
|
494
|
+
return apply(this, "findIndex", fn, thisArg, void 0, arguments);
|
|
495
|
+
},
|
|
496
|
+
findLast(fn, thisArg) {
|
|
497
|
+
return apply(this, "findLast", fn, thisArg, (item) => toWrapped(this, item), arguments);
|
|
498
|
+
},
|
|
499
|
+
findLastIndex(fn, thisArg) {
|
|
500
|
+
return apply(this, "findLastIndex", fn, thisArg, void 0, arguments);
|
|
501
|
+
},
|
|
502
|
+
forEach(fn, thisArg) {
|
|
503
|
+
return apply(this, "forEach", fn, thisArg, void 0, arguments);
|
|
504
|
+
},
|
|
505
|
+
includes(...args) {
|
|
506
|
+
return searchProxy(this, "includes", args);
|
|
507
|
+
},
|
|
508
|
+
indexOf(...args) {
|
|
509
|
+
return searchProxy(this, "indexOf", args);
|
|
510
|
+
},
|
|
511
|
+
join(separator) {
|
|
512
|
+
return reactiveReadArray(this).join(separator);
|
|
513
|
+
},
|
|
514
|
+
lastIndexOf(...args) {
|
|
515
|
+
return searchProxy(this, "lastIndexOf", args);
|
|
516
|
+
},
|
|
517
|
+
map(fn, thisArg) {
|
|
518
|
+
return apply(this, "map", fn, thisArg, void 0, arguments);
|
|
519
|
+
},
|
|
520
|
+
pop() {
|
|
521
|
+
return noTracking(this, "pop");
|
|
522
|
+
},
|
|
523
|
+
push(...args) {
|
|
524
|
+
return noTracking(this, "push", args);
|
|
525
|
+
},
|
|
526
|
+
reduce(fn, ...args) {
|
|
527
|
+
return reduce(this, "reduce", fn, args);
|
|
528
|
+
},
|
|
529
|
+
reduceRight(fn, ...args) {
|
|
530
|
+
return reduce(this, "reduceRight", fn, args);
|
|
531
|
+
},
|
|
532
|
+
shift() {
|
|
533
|
+
return noTracking(this, "shift");
|
|
534
|
+
},
|
|
535
|
+
some(fn, thisArg) {
|
|
536
|
+
return apply(this, "some", fn, thisArg, void 0, arguments);
|
|
537
|
+
},
|
|
538
|
+
splice(...args) {
|
|
539
|
+
return noTracking(this, "splice", args);
|
|
540
|
+
},
|
|
541
|
+
toReversed() {
|
|
542
|
+
return reactiveReadArray(this).toReversed();
|
|
543
|
+
},
|
|
544
|
+
toSorted(comparer) {
|
|
545
|
+
return reactiveReadArray(this).toSorted(comparer);
|
|
546
|
+
},
|
|
547
|
+
toSpliced(...args) {
|
|
548
|
+
return reactiveReadArray(this).toSpliced(...args);
|
|
549
|
+
},
|
|
550
|
+
unshift(...args) {
|
|
551
|
+
return noTracking(this, "unshift", args);
|
|
552
|
+
},
|
|
553
|
+
values() {
|
|
554
|
+
return iterator(this, "values", (item) => toWrapped(this, item));
|
|
555
|
+
}
|
|
627
556
|
};
|
|
628
557
|
function iterator(self, method, wrapValue) {
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
}
|
|
641
|
-
return iter;
|
|
558
|
+
const arr = shallowReadArray(self);
|
|
559
|
+
const iter = arr[method]();
|
|
560
|
+
if (arr !== self && !/* @__PURE__ */ isShallow(self)) {
|
|
561
|
+
iter._next = iter.next;
|
|
562
|
+
iter.next = () => {
|
|
563
|
+
const result = iter._next();
|
|
564
|
+
if (!result.done) result.value = wrapValue(result.value);
|
|
565
|
+
return result;
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
return iter;
|
|
642
569
|
}
|
|
643
570
|
const arrayProto = Array.prototype;
|
|
644
571
|
function apply(self, method, fn, thisArg, wrappedRetFn, args) {
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
}
|
|
664
|
-
const result = methodFn.call(arr, wrappedFn, thisArg);
|
|
665
|
-
return needsWrap && wrappedRetFn ? wrappedRetFn(result) : result;
|
|
572
|
+
const arr = shallowReadArray(self);
|
|
573
|
+
const needsWrap = arr !== self && !/* @__PURE__ */ isShallow(self);
|
|
574
|
+
const methodFn = arr[method];
|
|
575
|
+
if (methodFn !== arrayProto[method]) {
|
|
576
|
+
const result = methodFn.apply(self, args);
|
|
577
|
+
return needsWrap ? toReactive(result) : result;
|
|
578
|
+
}
|
|
579
|
+
let wrappedFn = fn;
|
|
580
|
+
if (arr !== self) {
|
|
581
|
+
if (needsWrap) wrappedFn = function(item, index) {
|
|
582
|
+
return fn.call(this, toWrapped(self, item), index, self);
|
|
583
|
+
};
|
|
584
|
+
else if (fn.length > 2) wrappedFn = function(item, index) {
|
|
585
|
+
return fn.call(this, item, index, self);
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
const result = methodFn.call(arr, wrappedFn, thisArg);
|
|
589
|
+
return needsWrap && wrappedRetFn ? wrappedRetFn(result) : result;
|
|
666
590
|
}
|
|
667
591
|
function reduce(self, method, fn, args) {
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
592
|
+
const arr = shallowReadArray(self);
|
|
593
|
+
const needsWrap = arr !== self && !/* @__PURE__ */ isShallow(self);
|
|
594
|
+
let wrappedFn = fn;
|
|
595
|
+
let wrapInitialAccumulator = false;
|
|
596
|
+
if (arr !== self) {
|
|
597
|
+
if (needsWrap) {
|
|
598
|
+
wrapInitialAccumulator = args.length === 0;
|
|
599
|
+
wrappedFn = function(acc, item, index) {
|
|
600
|
+
if (wrapInitialAccumulator) {
|
|
601
|
+
wrapInitialAccumulator = false;
|
|
602
|
+
acc = toWrapped(self, acc);
|
|
603
|
+
}
|
|
604
|
+
return fn.call(this, acc, toWrapped(self, item), index, self);
|
|
605
|
+
};
|
|
606
|
+
} else if (fn.length > 3) wrappedFn = function(acc, item, index) {
|
|
607
|
+
return fn.call(this, acc, item, index, self);
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
const result = arr[method](wrappedFn, ...args);
|
|
611
|
+
return wrapInitialAccumulator ? toWrapped(self, result) : result;
|
|
682
612
|
}
|
|
683
613
|
function searchProxy(self, method, args) {
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
614
|
+
const arr = /* @__PURE__ */ toRaw(self);
|
|
615
|
+
track(arr, "iterate", ARRAY_ITERATE_KEY);
|
|
616
|
+
const res = arr[method](...args);
|
|
617
|
+
if ((res === -1 || res === false) && /* @__PURE__ */ isProxy(args[0])) {
|
|
618
|
+
args[0] = /* @__PURE__ */ toRaw(args[0]);
|
|
619
|
+
return arr[method](...args);
|
|
620
|
+
}
|
|
621
|
+
return res;
|
|
692
622
|
}
|
|
693
623
|
function noTracking(self, method, args = []) {
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
}
|
|
701
|
-
|
|
624
|
+
startBatch();
|
|
625
|
+
const prevSub = setActiveSub();
|
|
626
|
+
const res = (/* @__PURE__ */ toRaw(self))[method].apply(self, args);
|
|
627
|
+
setActiveSub(prevSub);
|
|
628
|
+
endBatch();
|
|
629
|
+
return res;
|
|
630
|
+
}
|
|
631
|
+
//#endregion
|
|
632
|
+
//#region packages/reactivity/src/baseHandlers.ts
|
|
702
633
|
const isNonTrackableKeys = /* @__PURE__ */ makeMap(`__proto__,__v_isRef,__isVue`);
|
|
703
|
-
const builtInSymbols = new Set(
|
|
704
|
-
/* @__PURE__ */ Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller").map((key) => Symbol[key]).filter(isSymbol)
|
|
705
|
-
);
|
|
634
|
+
const builtInSymbols = new Set(/* @__PURE__ */ Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller").map((key) => Symbol[key]).filter(isSymbol));
|
|
706
635
|
function hasOwnProperty(key) {
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
key,
|
|
807
|
-
value,
|
|
808
|
-
isRef(target) ? target : receiver
|
|
809
|
-
);
|
|
810
|
-
if (target === toRaw(receiver)) {
|
|
811
|
-
if (!hadKey) {
|
|
812
|
-
trigger(target, "add", key, value);
|
|
813
|
-
} else if (hasChanged(value, oldValue)) {
|
|
814
|
-
trigger(target, "set", key, value, oldValue);
|
|
815
|
-
}
|
|
816
|
-
}
|
|
817
|
-
return result;
|
|
818
|
-
}
|
|
819
|
-
deleteProperty(target, key) {
|
|
820
|
-
const hadKey = hasOwn(target, key);
|
|
821
|
-
const oldValue = target[key];
|
|
822
|
-
const result = Reflect.deleteProperty(target, key);
|
|
823
|
-
if (result && hadKey) {
|
|
824
|
-
trigger(target, "delete", key, void 0, oldValue);
|
|
825
|
-
}
|
|
826
|
-
return result;
|
|
827
|
-
}
|
|
828
|
-
has(target, key) {
|
|
829
|
-
const result = Reflect.has(target, key);
|
|
830
|
-
if (!isSymbol(key) || !builtInSymbols.has(key)) {
|
|
831
|
-
track(target, "has", key);
|
|
832
|
-
}
|
|
833
|
-
return result;
|
|
834
|
-
}
|
|
835
|
-
ownKeys(target) {
|
|
836
|
-
track(
|
|
837
|
-
target,
|
|
838
|
-
"iterate",
|
|
839
|
-
isArray(target) ? "length" : ITERATE_KEY
|
|
840
|
-
);
|
|
841
|
-
return Reflect.ownKeys(target);
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
class ReadonlyReactiveHandler extends BaseReactiveHandler {
|
|
845
|
-
constructor(isShallow2 = false) {
|
|
846
|
-
super(true, isShallow2);
|
|
847
|
-
}
|
|
848
|
-
set(target, key) {
|
|
849
|
-
{
|
|
850
|
-
warn(
|
|
851
|
-
`Set operation on key "${String(key)}" failed: target is readonly.`,
|
|
852
|
-
target
|
|
853
|
-
);
|
|
854
|
-
}
|
|
855
|
-
return true;
|
|
856
|
-
}
|
|
857
|
-
deleteProperty(target, key) {
|
|
858
|
-
{
|
|
859
|
-
warn(
|
|
860
|
-
`Delete operation on key "${String(key)}" failed: target is readonly.`,
|
|
861
|
-
target
|
|
862
|
-
);
|
|
863
|
-
}
|
|
864
|
-
return true;
|
|
865
|
-
}
|
|
866
|
-
}
|
|
636
|
+
if (!isSymbol(key)) key = String(key);
|
|
637
|
+
const obj = /* @__PURE__ */ toRaw(this);
|
|
638
|
+
track(obj, "has", key);
|
|
639
|
+
return obj.hasOwnProperty(key);
|
|
640
|
+
}
|
|
641
|
+
var BaseReactiveHandler = class {
|
|
642
|
+
constructor(_isReadonly = false, _isShallow = false) {
|
|
643
|
+
this._isReadonly = _isReadonly;
|
|
644
|
+
this._isShallow = _isShallow;
|
|
645
|
+
}
|
|
646
|
+
get(target, key, receiver) {
|
|
647
|
+
if (key === "__v_skip") return target["__v_skip"];
|
|
648
|
+
const isReadonly = this._isReadonly, isShallow = this._isShallow;
|
|
649
|
+
if (key === "__v_isReactive") return !isReadonly;
|
|
650
|
+
else if (key === "__v_isReadonly") return isReadonly;
|
|
651
|
+
else if (key === "__v_isShallow") return isShallow;
|
|
652
|
+
else if (key === "__v_raw") {
|
|
653
|
+
if (receiver === (isReadonly ? isShallow ? shallowReadonlyMap : readonlyMap : isShallow ? shallowReactiveMap : reactiveMap).get(target) || Object.getPrototypeOf(target) === Object.getPrototypeOf(receiver)) return target;
|
|
654
|
+
return;
|
|
655
|
+
}
|
|
656
|
+
const targetIsArray = isArray(target);
|
|
657
|
+
if (!isReadonly) {
|
|
658
|
+
let fn;
|
|
659
|
+
if (targetIsArray && (fn = arrayInstrumentations[key])) return fn;
|
|
660
|
+
if (key === "hasOwnProperty") return hasOwnProperty;
|
|
661
|
+
}
|
|
662
|
+
const wasRef = /* @__PURE__ */ isRef(target);
|
|
663
|
+
const res = Reflect.get(target, key, wasRef ? target : receiver);
|
|
664
|
+
if (wasRef && key !== "value") return res;
|
|
665
|
+
if (isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) return res;
|
|
666
|
+
if (!isReadonly) track(target, "get", key);
|
|
667
|
+
if (isShallow) return res;
|
|
668
|
+
if (/* @__PURE__ */ isRef(res)) {
|
|
669
|
+
const value = targetIsArray && isIntegerKey(key) ? res : res.value;
|
|
670
|
+
return isReadonly && isObject(value) ? /* @__PURE__ */ readonly(value) : value;
|
|
671
|
+
}
|
|
672
|
+
if (isObject(res)) return isReadonly ? /* @__PURE__ */ readonly(res) : /* @__PURE__ */ reactive(res);
|
|
673
|
+
return res;
|
|
674
|
+
}
|
|
675
|
+
};
|
|
676
|
+
var MutableReactiveHandler = class extends BaseReactiveHandler {
|
|
677
|
+
constructor(isShallow = false) {
|
|
678
|
+
super(false, isShallow);
|
|
679
|
+
}
|
|
680
|
+
set(target, key, value, receiver) {
|
|
681
|
+
let oldValue = target[key];
|
|
682
|
+
const isArrayWithIntegerKey = isArray(target) && isIntegerKey(key);
|
|
683
|
+
if (!this._isShallow) {
|
|
684
|
+
const isOldValueReadonly = /* @__PURE__ */ isReadonly(oldValue);
|
|
685
|
+
if (!/* @__PURE__ */ isShallow(value) && !/* @__PURE__ */ isReadonly(value)) {
|
|
686
|
+
oldValue = /* @__PURE__ */ toRaw(oldValue);
|
|
687
|
+
value = /* @__PURE__ */ toRaw(value);
|
|
688
|
+
}
|
|
689
|
+
if (!isArrayWithIntegerKey && /* @__PURE__ */ isRef(oldValue) && !/* @__PURE__ */ isRef(value)) if (isOldValueReadonly) {
|
|
690
|
+
warn(`Set operation on key "${String(key)}" failed: target is readonly.`, target[key]);
|
|
691
|
+
return true;
|
|
692
|
+
} else {
|
|
693
|
+
oldValue.value = value;
|
|
694
|
+
return true;
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
const hadKey = isArrayWithIntegerKey ? Number(key) < target.length : hasOwn(target, key);
|
|
698
|
+
const result = Reflect.set(target, key, value, /* @__PURE__ */ isRef(target) ? target : receiver);
|
|
699
|
+
if (target === /* @__PURE__ */ toRaw(receiver)) {
|
|
700
|
+
if (!hadKey) trigger(target, "add", key, value);
|
|
701
|
+
else if (hasChanged(value, oldValue)) trigger(target, "set", key, value, oldValue);
|
|
702
|
+
}
|
|
703
|
+
return result;
|
|
704
|
+
}
|
|
705
|
+
deleteProperty(target, key) {
|
|
706
|
+
const hadKey = hasOwn(target, key);
|
|
707
|
+
const oldValue = target[key];
|
|
708
|
+
const result = Reflect.deleteProperty(target, key);
|
|
709
|
+
if (result && hadKey) trigger(target, "delete", key, void 0, oldValue);
|
|
710
|
+
return result;
|
|
711
|
+
}
|
|
712
|
+
has(target, key) {
|
|
713
|
+
const result = Reflect.has(target, key);
|
|
714
|
+
if (!isSymbol(key) || !builtInSymbols.has(key)) track(target, "has", key);
|
|
715
|
+
return result;
|
|
716
|
+
}
|
|
717
|
+
ownKeys(target) {
|
|
718
|
+
track(target, "iterate", isArray(target) ? "length" : ITERATE_KEY);
|
|
719
|
+
return Reflect.ownKeys(target);
|
|
720
|
+
}
|
|
721
|
+
};
|
|
722
|
+
var ReadonlyReactiveHandler = class extends BaseReactiveHandler {
|
|
723
|
+
constructor(isShallow = false) {
|
|
724
|
+
super(true, isShallow);
|
|
725
|
+
}
|
|
726
|
+
set(target, key) {
|
|
727
|
+
warn(`Set operation on key "${String(key)}" failed: target is readonly.`, target);
|
|
728
|
+
return true;
|
|
729
|
+
}
|
|
730
|
+
deleteProperty(target, key) {
|
|
731
|
+
warn(`Delete operation on key "${String(key)}" failed: target is readonly.`, target);
|
|
732
|
+
return true;
|
|
733
|
+
}
|
|
734
|
+
};
|
|
867
735
|
const mutableHandlers = /* @__PURE__ */ new MutableReactiveHandler();
|
|
868
736
|
const readonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler();
|
|
869
737
|
const shallowReactiveHandlers = /* @__PURE__ */ new MutableReactiveHandler(true);
|
|
870
738
|
const shallowReadonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler(true);
|
|
871
|
-
|
|
739
|
+
//#endregion
|
|
740
|
+
//#region packages/reactivity/src/collectionHandlers.ts
|
|
872
741
|
const toShallow = (value) => value;
|
|
873
742
|
const getProto = (v) => Reflect.getPrototypeOf(v);
|
|
874
|
-
function createIterableMethod(method,
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
};
|
|
896
|
-
},
|
|
897
|
-
// iterable protocol
|
|
898
|
-
[Symbol.iterator]() {
|
|
899
|
-
return this;
|
|
900
|
-
}
|
|
901
|
-
};
|
|
902
|
-
};
|
|
743
|
+
function createIterableMethod(method, isReadonly, isShallow) {
|
|
744
|
+
return function(...args) {
|
|
745
|
+
const target = this["__v_raw"];
|
|
746
|
+
const rawTarget = /* @__PURE__ */ toRaw(target);
|
|
747
|
+
const targetIsMap = isMap(rawTarget);
|
|
748
|
+
const isPair = method === "entries" || method === Symbol.iterator && targetIsMap;
|
|
749
|
+
const isKeyOnly = method === "keys" && targetIsMap;
|
|
750
|
+
const innerIterator = target[method](...args);
|
|
751
|
+
const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
|
|
752
|
+
!isReadonly && track(rawTarget, "iterate", isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY);
|
|
753
|
+
return extend(Object.create(innerIterator), { next() {
|
|
754
|
+
const { value, done } = innerIterator.next();
|
|
755
|
+
return done ? {
|
|
756
|
+
value,
|
|
757
|
+
done
|
|
758
|
+
} : {
|
|
759
|
+
value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
|
|
760
|
+
done
|
|
761
|
+
};
|
|
762
|
+
} });
|
|
763
|
+
};
|
|
903
764
|
}
|
|
904
765
|
function createReadonlyMethod(type) {
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
}
|
|
913
|
-
return type === "delete" ? false : type === "clear" ? void 0 : this;
|
|
914
|
-
};
|
|
766
|
+
return function(...args) {
|
|
767
|
+
{
|
|
768
|
+
const key = args[0] ? `on key "${args[0]}" ` : ``;
|
|
769
|
+
warn(`${capitalize(type)} operation ${key}failed: target is readonly.`, /* @__PURE__ */ toRaw(this));
|
|
770
|
+
}
|
|
771
|
+
return type === "delete" ? false : type === "clear" ? void 0 : this;
|
|
772
|
+
};
|
|
915
773
|
}
|
|
916
774
|
function createInstrumentations(readonly, shallow) {
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
void 0,
|
|
1036
|
-
void 0,
|
|
1037
|
-
oldTarget
|
|
1038
|
-
);
|
|
1039
|
-
}
|
|
1040
|
-
return result;
|
|
1041
|
-
}
|
|
1042
|
-
}
|
|
1043
|
-
);
|
|
1044
|
-
const iteratorMethods = [
|
|
1045
|
-
"keys",
|
|
1046
|
-
"values",
|
|
1047
|
-
"entries",
|
|
1048
|
-
Symbol.iterator
|
|
1049
|
-
];
|
|
1050
|
-
iteratorMethods.forEach((method) => {
|
|
1051
|
-
instrumentations[method] = createIterableMethod(method, readonly, shallow);
|
|
1052
|
-
});
|
|
1053
|
-
return instrumentations;
|
|
1054
|
-
}
|
|
1055
|
-
function createInstrumentationGetter(isReadonly2, shallow) {
|
|
1056
|
-
const instrumentations = createInstrumentations(isReadonly2, shallow);
|
|
1057
|
-
return (target, key, receiver) => {
|
|
1058
|
-
if (key === "__v_isReactive") {
|
|
1059
|
-
return !isReadonly2;
|
|
1060
|
-
} else if (key === "__v_isReadonly") {
|
|
1061
|
-
return isReadonly2;
|
|
1062
|
-
} else if (key === "__v_raw") {
|
|
1063
|
-
return target;
|
|
1064
|
-
}
|
|
1065
|
-
return Reflect.get(
|
|
1066
|
-
hasOwn(instrumentations, key) && key in target ? instrumentations : target,
|
|
1067
|
-
key,
|
|
1068
|
-
receiver
|
|
1069
|
-
);
|
|
1070
|
-
};
|
|
1071
|
-
}
|
|
1072
|
-
const mutableCollectionHandlers = {
|
|
1073
|
-
get: /* @__PURE__ */ createInstrumentationGetter(false, false)
|
|
1074
|
-
};
|
|
1075
|
-
const shallowCollectionHandlers = {
|
|
1076
|
-
get: /* @__PURE__ */ createInstrumentationGetter(false, true)
|
|
1077
|
-
};
|
|
1078
|
-
const readonlyCollectionHandlers = {
|
|
1079
|
-
get: /* @__PURE__ */ createInstrumentationGetter(true, false)
|
|
1080
|
-
};
|
|
1081
|
-
const shallowReadonlyCollectionHandlers = {
|
|
1082
|
-
get: /* @__PURE__ */ createInstrumentationGetter(true, true)
|
|
1083
|
-
};
|
|
775
|
+
const instrumentations = {
|
|
776
|
+
get(key) {
|
|
777
|
+
const target = this["__v_raw"];
|
|
778
|
+
const rawTarget = /* @__PURE__ */ toRaw(target);
|
|
779
|
+
const rawKey = /* @__PURE__ */ toRaw(key);
|
|
780
|
+
if (!readonly) {
|
|
781
|
+
if (hasChanged(key, rawKey)) track(rawTarget, "get", key);
|
|
782
|
+
track(rawTarget, "get", rawKey);
|
|
783
|
+
}
|
|
784
|
+
const { has } = getProto(rawTarget);
|
|
785
|
+
const wrap = shallow ? toShallow : readonly ? toReadonly : toReactive;
|
|
786
|
+
if (has.call(rawTarget, key)) return wrap(target.get(key));
|
|
787
|
+
else if (has.call(rawTarget, rawKey)) return wrap(target.get(rawKey));
|
|
788
|
+
else if (target !== rawTarget) target.get(key);
|
|
789
|
+
},
|
|
790
|
+
get size() {
|
|
791
|
+
const target = this["__v_raw"];
|
|
792
|
+
!readonly && track(/* @__PURE__ */ toRaw(target), "iterate", ITERATE_KEY);
|
|
793
|
+
return target.size;
|
|
794
|
+
},
|
|
795
|
+
has(key) {
|
|
796
|
+
const target = this["__v_raw"];
|
|
797
|
+
const rawTarget = /* @__PURE__ */ toRaw(target);
|
|
798
|
+
const rawKey = /* @__PURE__ */ toRaw(key);
|
|
799
|
+
if (!readonly) {
|
|
800
|
+
if (hasChanged(key, rawKey)) track(rawTarget, "has", key);
|
|
801
|
+
track(rawTarget, "has", rawKey);
|
|
802
|
+
}
|
|
803
|
+
return key === rawKey ? target.has(key) : target.has(key) || target.has(rawKey);
|
|
804
|
+
},
|
|
805
|
+
forEach(callback, thisArg) {
|
|
806
|
+
const observed = this;
|
|
807
|
+
const target = observed["__v_raw"];
|
|
808
|
+
const rawTarget = /* @__PURE__ */ toRaw(target);
|
|
809
|
+
const wrap = shallow ? toShallow : readonly ? toReadonly : toReactive;
|
|
810
|
+
!readonly && track(rawTarget, "iterate", ITERATE_KEY);
|
|
811
|
+
return target.forEach((value, key) => {
|
|
812
|
+
return callback.call(thisArg, wrap(value), wrap(key), observed);
|
|
813
|
+
});
|
|
814
|
+
}
|
|
815
|
+
};
|
|
816
|
+
extend(instrumentations, readonly ? {
|
|
817
|
+
add: createReadonlyMethod("add"),
|
|
818
|
+
set: createReadonlyMethod("set"),
|
|
819
|
+
delete: createReadonlyMethod("delete"),
|
|
820
|
+
clear: createReadonlyMethod("clear")
|
|
821
|
+
} : {
|
|
822
|
+
add(value) {
|
|
823
|
+
const target = /* @__PURE__ */ toRaw(this);
|
|
824
|
+
const proto = getProto(target);
|
|
825
|
+
const rawValue = /* @__PURE__ */ toRaw(value);
|
|
826
|
+
const valueToAdd = !shallow && !/* @__PURE__ */ isShallow(value) && !/* @__PURE__ */ isReadonly(value) ? rawValue : value;
|
|
827
|
+
if (!(proto.has.call(target, valueToAdd) || hasChanged(value, valueToAdd) && proto.has.call(target, value) || hasChanged(rawValue, valueToAdd) && proto.has.call(target, rawValue))) {
|
|
828
|
+
target.add(valueToAdd);
|
|
829
|
+
trigger(target, "add", valueToAdd, valueToAdd);
|
|
830
|
+
}
|
|
831
|
+
return this;
|
|
832
|
+
},
|
|
833
|
+
set(key, value) {
|
|
834
|
+
if (!shallow && !/* @__PURE__ */ isShallow(value) && !/* @__PURE__ */ isReadonly(value)) value = /* @__PURE__ */ toRaw(value);
|
|
835
|
+
const target = /* @__PURE__ */ toRaw(this);
|
|
836
|
+
const { has, get } = getProto(target);
|
|
837
|
+
let hadKey = has.call(target, key);
|
|
838
|
+
if (!hadKey) {
|
|
839
|
+
key = /* @__PURE__ */ toRaw(key);
|
|
840
|
+
hadKey = has.call(target, key);
|
|
841
|
+
} else checkIdentityKeys(target, has, key);
|
|
842
|
+
const oldValue = get.call(target, key);
|
|
843
|
+
target.set(key, value);
|
|
844
|
+
if (!hadKey) trigger(target, "add", key, value);
|
|
845
|
+
else if (hasChanged(value, oldValue)) trigger(target, "set", key, value, oldValue);
|
|
846
|
+
return this;
|
|
847
|
+
},
|
|
848
|
+
delete(key) {
|
|
849
|
+
const target = /* @__PURE__ */ toRaw(this);
|
|
850
|
+
const { has, get } = getProto(target);
|
|
851
|
+
let hadKey = has.call(target, key);
|
|
852
|
+
if (!hadKey) {
|
|
853
|
+
key = /* @__PURE__ */ toRaw(key);
|
|
854
|
+
hadKey = has.call(target, key);
|
|
855
|
+
} else checkIdentityKeys(target, has, key);
|
|
856
|
+
const oldValue = get ? get.call(target, key) : void 0;
|
|
857
|
+
const result = target.delete(key);
|
|
858
|
+
if (hadKey) trigger(target, "delete", key, void 0, oldValue);
|
|
859
|
+
return result;
|
|
860
|
+
},
|
|
861
|
+
clear() {
|
|
862
|
+
const target = /* @__PURE__ */ toRaw(this);
|
|
863
|
+
const hadItems = target.size !== 0;
|
|
864
|
+
const oldTarget = isMap(target) ? new Map(target) : new Set(target);
|
|
865
|
+
const result = target.clear();
|
|
866
|
+
if (hadItems) trigger(target, "clear", void 0, void 0, oldTarget);
|
|
867
|
+
return result;
|
|
868
|
+
}
|
|
869
|
+
});
|
|
870
|
+
[
|
|
871
|
+
"keys",
|
|
872
|
+
"values",
|
|
873
|
+
"entries",
|
|
874
|
+
Symbol.iterator
|
|
875
|
+
].forEach((method) => {
|
|
876
|
+
instrumentations[method] = createIterableMethod(method, readonly, shallow);
|
|
877
|
+
});
|
|
878
|
+
return instrumentations;
|
|
879
|
+
}
|
|
880
|
+
function createInstrumentationGetter(isReadonly, shallow) {
|
|
881
|
+
const instrumentations = createInstrumentations(isReadonly, shallow);
|
|
882
|
+
return (target, key, receiver) => {
|
|
883
|
+
if (key === "__v_isReactive") return !isReadonly;
|
|
884
|
+
else if (key === "__v_isReadonly") return isReadonly;
|
|
885
|
+
else if (key === "__v_raw") return target;
|
|
886
|
+
return Reflect.get(hasOwn(instrumentations, key) && key in target ? instrumentations : target, key, receiver);
|
|
887
|
+
};
|
|
888
|
+
}
|
|
889
|
+
const mutableCollectionHandlers = { get: /* @__PURE__ */ createInstrumentationGetter(false, false) };
|
|
890
|
+
const shallowCollectionHandlers = { get: /* @__PURE__ */ createInstrumentationGetter(false, true) };
|
|
891
|
+
const readonlyCollectionHandlers = { get: /* @__PURE__ */ createInstrumentationGetter(true, false) };
|
|
892
|
+
const shallowReadonlyCollectionHandlers = { get: /* @__PURE__ */ createInstrumentationGetter(true, true) };
|
|
1084
893
|
function checkIdentityKeys(target, has, key) {
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
894
|
+
const rawKey = /* @__PURE__ */ toRaw(key);
|
|
895
|
+
if (rawKey !== key && has.call(target, rawKey)) {
|
|
896
|
+
const type = toRawType(target);
|
|
897
|
+
warn(`Reactive ${type} contains both the raw and reactive versions of the same object${type === `Map` ? ` as keys` : ``}, which can lead to inconsistencies. Avoid differentiating between the raw and reactive versions of an object and only use the reactive version if possible.`);
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
//#endregion
|
|
901
|
+
//#region packages/reactivity/src/reactive.ts
|
|
1094
902
|
const reactiveMap = /* @__PURE__ */ new WeakMap();
|
|
1095
903
|
const shallowReactiveMap = /* @__PURE__ */ new WeakMap();
|
|
1096
904
|
const readonlyMap = /* @__PURE__ */ new WeakMap();
|
|
1097
905
|
const shallowReadonlyMap = /* @__PURE__ */ new WeakMap();
|
|
1098
906
|
function targetTypeMap(rawType) {
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
default:
|
|
1109
|
-
return 0 /* INVALID */;
|
|
1110
|
-
}
|
|
907
|
+
switch (rawType) {
|
|
908
|
+
case "Object":
|
|
909
|
+
case "Array": return 1;
|
|
910
|
+
case "Map":
|
|
911
|
+
case "Set":
|
|
912
|
+
case "WeakMap":
|
|
913
|
+
case "WeakSet": return 2;
|
|
914
|
+
default: return 0;
|
|
915
|
+
}
|
|
1111
916
|
}
|
|
1112
917
|
function getTargetType(value) {
|
|
1113
|
-
|
|
918
|
+
return value["__v_skip"] || !Object.isExtensible(value) ? 0 : targetTypeMap(toRawType(value));
|
|
1114
919
|
}
|
|
920
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1115
921
|
function reactive(target) {
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
}
|
|
1119
|
-
return createReactiveObject(
|
|
1120
|
-
target,
|
|
1121
|
-
false,
|
|
1122
|
-
mutableHandlers,
|
|
1123
|
-
mutableCollectionHandlers,
|
|
1124
|
-
reactiveMap
|
|
1125
|
-
);
|
|
922
|
+
if (/* @__PURE__ */ isReadonly(target)) return target;
|
|
923
|
+
return createReactiveObject(target, false, mutableHandlers, mutableCollectionHandlers, reactiveMap);
|
|
1126
924
|
}
|
|
925
|
+
/**
|
|
926
|
+
* Shallow version of {@link reactive}.
|
|
927
|
+
*
|
|
928
|
+
* Unlike {@link reactive}, there is no deep conversion: only root-level
|
|
929
|
+
* properties are reactive for a shallow reactive object. Property values are
|
|
930
|
+
* stored and exposed as-is - this also means properties with ref values will
|
|
931
|
+
* not be automatically unwrapped.
|
|
932
|
+
*
|
|
933
|
+
* @example
|
|
934
|
+
* ```js
|
|
935
|
+
* const state = shallowReactive({
|
|
936
|
+
* foo: 1,
|
|
937
|
+
* nested: {
|
|
938
|
+
* bar: 2
|
|
939
|
+
* }
|
|
940
|
+
* })
|
|
941
|
+
*
|
|
942
|
+
* // mutating state's own properties is reactive
|
|
943
|
+
* state.foo++
|
|
944
|
+
*
|
|
945
|
+
* // ...but does not convert nested objects
|
|
946
|
+
* isReactive(state.nested) // false
|
|
947
|
+
*
|
|
948
|
+
* // NOT reactive
|
|
949
|
+
* state.nested.bar++
|
|
950
|
+
* ```
|
|
951
|
+
*
|
|
952
|
+
* @param target - The source object.
|
|
953
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#shallowreactive}
|
|
954
|
+
*/
|
|
955
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1127
956
|
function shallowReactive(target) {
|
|
1128
|
-
|
|
1129
|
-
target,
|
|
1130
|
-
false,
|
|
1131
|
-
shallowReactiveHandlers,
|
|
1132
|
-
shallowCollectionHandlers,
|
|
1133
|
-
shallowReactiveMap
|
|
1134
|
-
);
|
|
957
|
+
return createReactiveObject(target, false, shallowReactiveHandlers, shallowCollectionHandlers, shallowReactiveMap);
|
|
1135
958
|
}
|
|
959
|
+
/**
|
|
960
|
+
* Takes an object (reactive or plain) or a ref and returns a readonly proxy to
|
|
961
|
+
* the original.
|
|
962
|
+
*
|
|
963
|
+
* A readonly proxy is deep: any nested property accessed will be readonly as
|
|
964
|
+
* well. It also has the same ref-unwrapping behavior as {@link reactive},
|
|
965
|
+
* except the unwrapped values will also be made readonly.
|
|
966
|
+
*
|
|
967
|
+
* @example
|
|
968
|
+
* ```js
|
|
969
|
+
* const original = reactive({ count: 0 })
|
|
970
|
+
*
|
|
971
|
+
* const copy = readonly(original)
|
|
972
|
+
*
|
|
973
|
+
* watchEffect(() => {
|
|
974
|
+
* // works for reactivity tracking
|
|
975
|
+
* console.log(copy.count)
|
|
976
|
+
* })
|
|
977
|
+
*
|
|
978
|
+
* // mutating original will trigger watchers relying on the copy
|
|
979
|
+
* original.count++
|
|
980
|
+
*
|
|
981
|
+
* // mutating the copy will fail and result in a warning
|
|
982
|
+
* copy.count++ // warning!
|
|
983
|
+
* ```
|
|
984
|
+
*
|
|
985
|
+
* @param target - The source object.
|
|
986
|
+
* @see {@link https://vuejs.org/api/reactivity-core.html#readonly}
|
|
987
|
+
*/
|
|
988
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1136
989
|
function readonly(target) {
|
|
1137
|
-
|
|
1138
|
-
target,
|
|
1139
|
-
true,
|
|
1140
|
-
readonlyHandlers,
|
|
1141
|
-
readonlyCollectionHandlers,
|
|
1142
|
-
readonlyMap
|
|
1143
|
-
);
|
|
990
|
+
return createReactiveObject(target, true, readonlyHandlers, readonlyCollectionHandlers, readonlyMap);
|
|
1144
991
|
}
|
|
992
|
+
/**
|
|
993
|
+
* Shallow version of {@link readonly}.
|
|
994
|
+
*
|
|
995
|
+
* Unlike {@link readonly}, there is no deep conversion: only root-level
|
|
996
|
+
* properties are made readonly. Property values are stored and exposed as-is -
|
|
997
|
+
* this also means properties with ref values will not be automatically
|
|
998
|
+
* unwrapped.
|
|
999
|
+
*
|
|
1000
|
+
* @example
|
|
1001
|
+
* ```js
|
|
1002
|
+
* const state = shallowReadonly({
|
|
1003
|
+
* foo: 1,
|
|
1004
|
+
* nested: {
|
|
1005
|
+
* bar: 2
|
|
1006
|
+
* }
|
|
1007
|
+
* })
|
|
1008
|
+
*
|
|
1009
|
+
* // mutating state's own properties will fail
|
|
1010
|
+
* state.foo++
|
|
1011
|
+
*
|
|
1012
|
+
* // ...but works on nested objects
|
|
1013
|
+
* isReadonly(state.nested) // false
|
|
1014
|
+
*
|
|
1015
|
+
* // works
|
|
1016
|
+
* state.nested.bar++
|
|
1017
|
+
* ```
|
|
1018
|
+
*
|
|
1019
|
+
* @param target - The source object.
|
|
1020
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#shallowreadonly}
|
|
1021
|
+
*/
|
|
1022
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1145
1023
|
function shallowReadonly(target) {
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
);
|
|
1162
|
-
}
|
|
1163
|
-
return target;
|
|
1164
|
-
}
|
|
1165
|
-
if (target["__v_raw"] && !(isReadonly2 && target["__v_isReactive"])) {
|
|
1166
|
-
return target;
|
|
1167
|
-
}
|
|
1168
|
-
const targetType = getTargetType(target);
|
|
1169
|
-
if (targetType === 0 /* INVALID */) {
|
|
1170
|
-
return target;
|
|
1171
|
-
}
|
|
1172
|
-
const existingProxy = proxyMap.get(target);
|
|
1173
|
-
if (existingProxy) {
|
|
1174
|
-
return existingProxy;
|
|
1175
|
-
}
|
|
1176
|
-
const proxy = new Proxy(
|
|
1177
|
-
target,
|
|
1178
|
-
targetType === 2 /* COLLECTION */ ? collectionHandlers : baseHandlers
|
|
1179
|
-
);
|
|
1180
|
-
proxyMap.set(target, proxy);
|
|
1181
|
-
return proxy;
|
|
1024
|
+
return createReactiveObject(target, true, shallowReadonlyHandlers, shallowReadonlyCollectionHandlers, shallowReadonlyMap);
|
|
1025
|
+
}
|
|
1026
|
+
function createReactiveObject(target, isReadonly, baseHandlers, collectionHandlers, proxyMap) {
|
|
1027
|
+
if (!isObject(target)) {
|
|
1028
|
+
warn(`value cannot be made ${isReadonly ? "readonly" : "reactive"}: ${String(target)}`);
|
|
1029
|
+
return target;
|
|
1030
|
+
}
|
|
1031
|
+
if (target["__v_raw"] && !(isReadonly && target["__v_isReactive"])) return target;
|
|
1032
|
+
const targetType = getTargetType(target);
|
|
1033
|
+
if (targetType === 0) return target;
|
|
1034
|
+
const existingProxy = proxyMap.get(target);
|
|
1035
|
+
if (existingProxy) return existingProxy;
|
|
1036
|
+
const proxy = new Proxy(target, targetType === 2 ? collectionHandlers : baseHandlers);
|
|
1037
|
+
proxyMap.set(target, proxy);
|
|
1038
|
+
return proxy;
|
|
1182
1039
|
}
|
|
1040
|
+
/**
|
|
1041
|
+
* Checks if an object is a proxy created by {@link reactive} or
|
|
1042
|
+
* {@link shallowReactive} (or {@link ref} in some cases).
|
|
1043
|
+
*
|
|
1044
|
+
* @example
|
|
1045
|
+
* ```js
|
|
1046
|
+
* isReactive(reactive({})) // => true
|
|
1047
|
+
* isReactive(readonly(reactive({}))) // => true
|
|
1048
|
+
* isReactive(ref({}).value) // => true
|
|
1049
|
+
* isReactive(readonly(ref({})).value) // => true
|
|
1050
|
+
* isReactive(ref(true)) // => false
|
|
1051
|
+
* isReactive(shallowRef({}).value) // => false
|
|
1052
|
+
* isReactive(shallowReactive({})) // => true
|
|
1053
|
+
* ```
|
|
1054
|
+
*
|
|
1055
|
+
* @param value - The value to check.
|
|
1056
|
+
* @see {@link https://vuejs.org/api/reactivity-utilities.html#isreactive}
|
|
1057
|
+
*/
|
|
1058
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1183
1059
|
function isReactive(value) {
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
}
|
|
1187
|
-
return !!(value && value["__v_isReactive"]);
|
|
1060
|
+
if (/* @__PURE__ */ isReadonly(value)) return /* @__PURE__ */ isReactive(value["__v_raw"]);
|
|
1061
|
+
return !!(value && value["__v_isReactive"]);
|
|
1188
1062
|
}
|
|
1063
|
+
/**
|
|
1064
|
+
* Checks whether the passed value is a readonly object. The properties of a
|
|
1065
|
+
* readonly object can change, but they can't be assigned directly via the
|
|
1066
|
+
* passed object.
|
|
1067
|
+
*
|
|
1068
|
+
* The proxies created by {@link readonly} and {@link shallowReadonly} are
|
|
1069
|
+
* both considered readonly, as is a computed ref without a set function.
|
|
1070
|
+
*
|
|
1071
|
+
* @param value - The value to check.
|
|
1072
|
+
* @see {@link https://vuejs.org/api/reactivity-utilities.html#isreadonly}
|
|
1073
|
+
*/
|
|
1074
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1189
1075
|
function isReadonly(value) {
|
|
1190
|
-
|
|
1076
|
+
return !!(value && value["__v_isReadonly"]);
|
|
1191
1077
|
}
|
|
1078
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1192
1079
|
function isShallow(value) {
|
|
1193
|
-
|
|
1080
|
+
return !!(value && value["__v_isShallow"]);
|
|
1194
1081
|
}
|
|
1082
|
+
/**
|
|
1083
|
+
* Checks if an object is a proxy created by {@link reactive},
|
|
1084
|
+
* {@link readonly}, {@link shallowReactive} or {@link shallowReadonly}.
|
|
1085
|
+
*
|
|
1086
|
+
* @param value - The value to check.
|
|
1087
|
+
* @see {@link https://vuejs.org/api/reactivity-utilities.html#isproxy}
|
|
1088
|
+
*/
|
|
1089
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1195
1090
|
function isProxy(value) {
|
|
1196
|
-
|
|
1091
|
+
return value ? !!value["__v_raw"] : false;
|
|
1197
1092
|
}
|
|
1093
|
+
/**
|
|
1094
|
+
* Returns the raw, original object of a Vue-created proxy.
|
|
1095
|
+
*
|
|
1096
|
+
* `toRaw()` can return the original object from proxies created by
|
|
1097
|
+
* {@link reactive}, {@link readonly}, {@link shallowReactive} or
|
|
1098
|
+
* {@link shallowReadonly}.
|
|
1099
|
+
*
|
|
1100
|
+
* This is an escape hatch that can be used to temporarily read without
|
|
1101
|
+
* incurring proxy access / tracking overhead or write without triggering
|
|
1102
|
+
* changes. It is **not** recommended to hold a persistent reference to the
|
|
1103
|
+
* original object. Use with caution.
|
|
1104
|
+
*
|
|
1105
|
+
* @example
|
|
1106
|
+
* ```js
|
|
1107
|
+
* const foo = {}
|
|
1108
|
+
* const reactiveFoo = reactive(foo)
|
|
1109
|
+
*
|
|
1110
|
+
* console.log(toRaw(reactiveFoo) === foo) // true
|
|
1111
|
+
* ```
|
|
1112
|
+
*
|
|
1113
|
+
* @param observed - The object for which the "raw" value is requested.
|
|
1114
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#toraw}
|
|
1115
|
+
*/
|
|
1116
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1198
1117
|
function toRaw(observed) {
|
|
1199
|
-
|
|
1200
|
-
|
|
1118
|
+
const raw = observed && observed["__v_raw"];
|
|
1119
|
+
return raw ? /* @__PURE__ */ toRaw(raw) : observed;
|
|
1201
1120
|
}
|
|
1121
|
+
/**
|
|
1122
|
+
* Marks an object so that it will never be converted to a proxy. Returns the
|
|
1123
|
+
* object itself.
|
|
1124
|
+
*
|
|
1125
|
+
* @example
|
|
1126
|
+
* ```js
|
|
1127
|
+
* const foo = markRaw({})
|
|
1128
|
+
* console.log(isReactive(reactive(foo))) // false
|
|
1129
|
+
*
|
|
1130
|
+
* // also works when nested inside other reactive objects
|
|
1131
|
+
* const bar = reactive({ foo })
|
|
1132
|
+
* console.log(isReactive(bar.foo)) // false
|
|
1133
|
+
* ```
|
|
1134
|
+
*
|
|
1135
|
+
* **Warning:** `markRaw()` together with the shallow APIs such as
|
|
1136
|
+
* {@link shallowReactive} allow you to selectively opt-out of the default
|
|
1137
|
+
* deep reactive/readonly conversion and embed raw, non-proxied objects in your
|
|
1138
|
+
* state graph.
|
|
1139
|
+
*
|
|
1140
|
+
* @param value - The object to be marked as "raw".
|
|
1141
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#markraw}
|
|
1142
|
+
*/
|
|
1202
1143
|
function markRaw(value) {
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1144
|
+
if (!hasOwn(value, "__v_skip") && Object.isExtensible(value)) def(value, "__v_skip", true);
|
|
1145
|
+
return value;
|
|
1146
|
+
}
|
|
1147
|
+
/**
|
|
1148
|
+
* Returns a reactive proxy of the given value (if possible).
|
|
1149
|
+
*
|
|
1150
|
+
* If the given value is not an object, the original value itself is returned.
|
|
1151
|
+
*
|
|
1152
|
+
* @param value - The value for which a reactive proxy shall be created.
|
|
1153
|
+
*/
|
|
1154
|
+
const toReactive = (value) => isObject(value) ? /* @__PURE__ */ reactive(value) : value;
|
|
1155
|
+
/**
|
|
1156
|
+
* Returns a readonly proxy of the given value (if possible).
|
|
1157
|
+
*
|
|
1158
|
+
* If the given value is not an object, the original value itself is returned.
|
|
1159
|
+
*
|
|
1160
|
+
* @param value - The value for which a readonly proxy shall be created.
|
|
1161
|
+
*/
|
|
1162
|
+
const toReadonly = (value) => isObject(value) ? /* @__PURE__ */ readonly(value) : value;
|
|
1163
|
+
//#endregion
|
|
1164
|
+
//#region packages/reactivity/src/ref.ts
|
|
1165
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1211
1166
|
function isRef(r) {
|
|
1212
|
-
|
|
1167
|
+
return r ? r["__v_isRef"] === true : false;
|
|
1213
1168
|
}
|
|
1169
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1214
1170
|
function ref(value) {
|
|
1215
|
-
|
|
1171
|
+
return createRef(value, toReactive);
|
|
1216
1172
|
}
|
|
1173
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1217
1174
|
function shallowRef(value) {
|
|
1218
|
-
|
|
1175
|
+
return createRef(value);
|
|
1219
1176
|
}
|
|
1220
1177
|
function createRef(rawValue, wrap) {
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1178
|
+
if (/* @__PURE__ */ isRef(rawValue)) return rawValue;
|
|
1179
|
+
return new RefImpl(rawValue, wrap);
|
|
1180
|
+
}
|
|
1181
|
+
/**
|
|
1182
|
+
* @internal
|
|
1183
|
+
*/
|
|
1184
|
+
var RefImpl = class {
|
|
1185
|
+
constructor(value, wrap) {
|
|
1186
|
+
this.subs = void 0;
|
|
1187
|
+
this.subsTail = void 0;
|
|
1188
|
+
this.flags = ReactiveFlags$1.Mutable;
|
|
1189
|
+
this.__v_isRef = true;
|
|
1190
|
+
this.__v_isShallow = false;
|
|
1191
|
+
this._oldValue = this._rawValue = wrap ? /* @__PURE__ */ toRaw(value) : value;
|
|
1192
|
+
this._value = wrap ? wrap(value) : value;
|
|
1193
|
+
this._wrap = wrap;
|
|
1194
|
+
this["__v_isShallow"] = !wrap;
|
|
1195
|
+
}
|
|
1196
|
+
get dep() {
|
|
1197
|
+
return this;
|
|
1198
|
+
}
|
|
1199
|
+
get value() {
|
|
1200
|
+
trackRef(this);
|
|
1201
|
+
if (this.flags & ReactiveFlags$1.Dirty && this.update()) {
|
|
1202
|
+
const subs = this.subs;
|
|
1203
|
+
if (subs !== void 0) shallowPropagate(subs);
|
|
1204
|
+
}
|
|
1205
|
+
return this._value;
|
|
1206
|
+
}
|
|
1207
|
+
set value(newValue) {
|
|
1208
|
+
const oldValue = this._rawValue;
|
|
1209
|
+
const useDirectValue = this["__v_isShallow"] || /* @__PURE__ */ isShallow(newValue) || /* @__PURE__ */ isReadonly(newValue);
|
|
1210
|
+
newValue = useDirectValue ? newValue : /* @__PURE__ */ toRaw(newValue);
|
|
1211
|
+
if (hasChanged(newValue, oldValue)) {
|
|
1212
|
+
this.flags |= ReactiveFlags$1.Dirty;
|
|
1213
|
+
this._rawValue = newValue;
|
|
1214
|
+
this._value = !useDirectValue && this._wrap ? this._wrap(newValue) : newValue;
|
|
1215
|
+
const subs = this.subs;
|
|
1216
|
+
if (subs !== void 0) {
|
|
1217
|
+
triggerEventInfos.push({
|
|
1218
|
+
target: this,
|
|
1219
|
+
type: "set",
|
|
1220
|
+
key: "value",
|
|
1221
|
+
newValue,
|
|
1222
|
+
oldValue
|
|
1223
|
+
});
|
|
1224
|
+
propagate(subs);
|
|
1225
|
+
if (!batchDepth) flush();
|
|
1226
|
+
triggerEventInfos.pop();
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
update() {
|
|
1231
|
+
this.flags &= ~ReactiveFlags$1.Dirty;
|
|
1232
|
+
return hasChanged(this._oldValue, this._oldValue = this._rawValue);
|
|
1233
|
+
}
|
|
1234
|
+
};
|
|
1235
|
+
/**
|
|
1236
|
+
* Force trigger effects that depends on a shallow ref. This is typically used
|
|
1237
|
+
* after making deep mutations to the inner value of a shallow ref.
|
|
1238
|
+
*
|
|
1239
|
+
* @example
|
|
1240
|
+
* ```js
|
|
1241
|
+
* const shallow = shallowRef({
|
|
1242
|
+
* greet: 'Hello, world'
|
|
1243
|
+
* })
|
|
1244
|
+
*
|
|
1245
|
+
* // Logs "Hello, world" once for the first run-through
|
|
1246
|
+
* watchEffect(() => {
|
|
1247
|
+
* console.log(shallow.value.greet)
|
|
1248
|
+
* })
|
|
1249
|
+
*
|
|
1250
|
+
* // This won't trigger the effect because the ref is shallow
|
|
1251
|
+
* shallow.value.greet = 'Hello, universe'
|
|
1252
|
+
*
|
|
1253
|
+
* // Logs "Hello, universe"
|
|
1254
|
+
* triggerRef(shallow)
|
|
1255
|
+
* ```
|
|
1256
|
+
*
|
|
1257
|
+
* @param ref - The ref whose tied effects shall be executed.
|
|
1258
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#triggerref}
|
|
1259
|
+
*/
|
|
1260
|
+
function triggerRef(ref) {
|
|
1261
|
+
const dep = ref.dep;
|
|
1262
|
+
if (dep !== void 0 && dep.subs !== void 0) {
|
|
1263
|
+
propagate(dep.subs);
|
|
1264
|
+
shallowPropagate(dep.subs);
|
|
1265
|
+
if (!batchDepth) flush();
|
|
1266
|
+
}
|
|
1302
1267
|
}
|
|
1303
1268
|
function trackRef(dep) {
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
function
|
|
1316
|
-
|
|
1269
|
+
if (activeSub !== void 0) {
|
|
1270
|
+
onTrack(activeSub, {
|
|
1271
|
+
target: dep,
|
|
1272
|
+
type: "get",
|
|
1273
|
+
key: "value"
|
|
1274
|
+
});
|
|
1275
|
+
link(dep, activeSub);
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
/**
|
|
1279
|
+
* Returns the inner value if the argument is a ref, otherwise return the
|
|
1280
|
+
* argument itself. This is a sugar function for
|
|
1281
|
+
* `val = isRef(val) ? val.value : val`.
|
|
1282
|
+
*
|
|
1283
|
+
* @example
|
|
1284
|
+
* ```js
|
|
1285
|
+
* function useFoo(x: number | Ref<number>) {
|
|
1286
|
+
* const unwrapped = unref(x)
|
|
1287
|
+
* // unwrapped is guaranteed to be number now
|
|
1288
|
+
* }
|
|
1289
|
+
* ```
|
|
1290
|
+
*
|
|
1291
|
+
* @param ref - Ref or plain value to be converted into the plain value.
|
|
1292
|
+
* @see {@link https://vuejs.org/api/reactivity-utilities.html#unref}
|
|
1293
|
+
*/
|
|
1294
|
+
function unref(ref) {
|
|
1295
|
+
return /* @__PURE__ */ isRef(ref) ? ref.value : ref;
|
|
1317
1296
|
}
|
|
1297
|
+
/**
|
|
1298
|
+
* Normalizes values / refs / getters to values.
|
|
1299
|
+
* This is similar to {@link unref}, except that it also normalizes getters.
|
|
1300
|
+
* If the argument is a getter, it will be invoked and its return value will
|
|
1301
|
+
* be returned.
|
|
1302
|
+
*
|
|
1303
|
+
* @example
|
|
1304
|
+
* ```js
|
|
1305
|
+
* toValue(1) // 1
|
|
1306
|
+
* toValue(ref(1)) // 1
|
|
1307
|
+
* toValue(() => 1) // 1
|
|
1308
|
+
* ```
|
|
1309
|
+
*
|
|
1310
|
+
* @param source - A getter, an existing ref, or a non-function value.
|
|
1311
|
+
* @see {@link https://vuejs.org/api/reactivity-utilities.html#tovalue}
|
|
1312
|
+
*/
|
|
1318
1313
|
function toValue(source) {
|
|
1319
|
-
|
|
1314
|
+
return isFunction(source) ? source() : unref(source);
|
|
1320
1315
|
}
|
|
1321
1316
|
const shallowUnwrapHandlers = {
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
}
|
|
1331
|
-
}
|
|
1317
|
+
get: (target, key, receiver) => key === "__v_raw" ? target : unref(Reflect.get(target, key, receiver)),
|
|
1318
|
+
set: (target, key, value, receiver) => {
|
|
1319
|
+
const oldValue = target[key];
|
|
1320
|
+
if (/* @__PURE__ */ isRef(oldValue) && !/* @__PURE__ */ isRef(value)) {
|
|
1321
|
+
oldValue.value = value;
|
|
1322
|
+
return true;
|
|
1323
|
+
} else return Reflect.set(target, key, value, receiver);
|
|
1324
|
+
}
|
|
1332
1325
|
};
|
|
1326
|
+
/**
|
|
1327
|
+
* Returns a proxy for the given object that shallowly unwraps properties that
|
|
1328
|
+
* are refs. If the object already is reactive, it's returned as-is. If not, a
|
|
1329
|
+
* new reactive proxy is created.
|
|
1330
|
+
*
|
|
1331
|
+
* @param objectWithRefs - Either an already-reactive object or a simple object
|
|
1332
|
+
* that contains refs.
|
|
1333
|
+
*/
|
|
1333
1334
|
function proxyRefs(objectWithRefs) {
|
|
1334
|
-
|
|
1335
|
-
}
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1335
|
+
return /* @__PURE__ */ isReactive(objectWithRefs) ? objectWithRefs : new Proxy(objectWithRefs, shallowUnwrapHandlers);
|
|
1336
|
+
}
|
|
1337
|
+
var CustomRefImpl = class {
|
|
1338
|
+
constructor(factory) {
|
|
1339
|
+
this.subs = void 0;
|
|
1340
|
+
this.subsTail = void 0;
|
|
1341
|
+
this.flags = ReactiveFlags$1.None;
|
|
1342
|
+
this["__v_isRef"] = true;
|
|
1343
|
+
this._value = void 0;
|
|
1344
|
+
const { get, set } = factory(() => trackRef(this), () => triggerRef(this));
|
|
1345
|
+
this._get = get;
|
|
1346
|
+
this._set = set;
|
|
1347
|
+
}
|
|
1348
|
+
get dep() {
|
|
1349
|
+
return this;
|
|
1350
|
+
}
|
|
1351
|
+
get value() {
|
|
1352
|
+
return this._value = this._get();
|
|
1353
|
+
}
|
|
1354
|
+
set value(newVal) {
|
|
1355
|
+
this._set(newVal);
|
|
1356
|
+
}
|
|
1357
|
+
};
|
|
1358
|
+
/**
|
|
1359
|
+
* Creates a customized ref with explicit control over its dependency tracking
|
|
1360
|
+
* and updates triggering.
|
|
1361
|
+
*
|
|
1362
|
+
* @param factory - The function that receives the `track` and `trigger` callbacks.
|
|
1363
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#customref}
|
|
1364
|
+
*/
|
|
1360
1365
|
function customRef(factory) {
|
|
1361
|
-
|
|
1366
|
+
return new CustomRefImpl(factory);
|
|
1362
1367
|
}
|
|
1368
|
+
/**
|
|
1369
|
+
* Converts a reactive object to a plain object where each property of the
|
|
1370
|
+
* resulting object is a ref pointing to the corresponding property of the
|
|
1371
|
+
* original object. Each individual ref is created using {@link toRef}.
|
|
1372
|
+
*
|
|
1373
|
+
* @param object - Reactive object to be made into an object of linked refs.
|
|
1374
|
+
* @see {@link https://vuejs.org/api/reactivity-utilities.html#torefs}
|
|
1375
|
+
*/
|
|
1376
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1363
1377
|
function toRefs(object) {
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
}
|
|
1415
|
-
get value() {
|
|
1416
|
-
return this._value = this._getter();
|
|
1417
|
-
}
|
|
1418
|
-
}
|
|
1378
|
+
const ret = isArray(object) ? new Array(object.length) : {};
|
|
1379
|
+
for (const key in object) ret[key] = propertyToRef(object, key);
|
|
1380
|
+
return ret;
|
|
1381
|
+
}
|
|
1382
|
+
var ObjectRefImpl = class {
|
|
1383
|
+
constructor(_object, key, _defaultValue) {
|
|
1384
|
+
this._object = _object;
|
|
1385
|
+
this._defaultValue = _defaultValue;
|
|
1386
|
+
this["__v_isRef"] = true;
|
|
1387
|
+
this._value = void 0;
|
|
1388
|
+
this._key = isSymbol(key) ? key : String(key);
|
|
1389
|
+
this._raw = /* @__PURE__ */ toRaw(_object);
|
|
1390
|
+
let shallow = true;
|
|
1391
|
+
let obj = _object;
|
|
1392
|
+
if (!isArray(_object) || isSymbol(this._key) || !isIntegerKey(this._key)) do
|
|
1393
|
+
shallow = !/* @__PURE__ */ isProxy(obj) || /* @__PURE__ */ isShallow(obj);
|
|
1394
|
+
while (shallow && (obj = obj["__v_raw"]));
|
|
1395
|
+
this._shallow = shallow;
|
|
1396
|
+
}
|
|
1397
|
+
get value() {
|
|
1398
|
+
let val = this._object[this._key];
|
|
1399
|
+
if (this._shallow) val = unref(val);
|
|
1400
|
+
return this._value = val === void 0 ? this._defaultValue : val;
|
|
1401
|
+
}
|
|
1402
|
+
set value(newVal) {
|
|
1403
|
+
if (this._shallow && /* @__PURE__ */ isRef(this._raw[this._key])) {
|
|
1404
|
+
const nestedRef = this._object[this._key];
|
|
1405
|
+
if (/* @__PURE__ */ isRef(nestedRef)) {
|
|
1406
|
+
nestedRef.value = newVal;
|
|
1407
|
+
return;
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
this._object[this._key] = newVal;
|
|
1411
|
+
}
|
|
1412
|
+
get dep() {
|
|
1413
|
+
return getDepFromReactive(this._raw, this._key);
|
|
1414
|
+
}
|
|
1415
|
+
};
|
|
1416
|
+
var GetterRefImpl = class {
|
|
1417
|
+
constructor(_getter) {
|
|
1418
|
+
this._getter = _getter;
|
|
1419
|
+
this["__v_isRef"] = true;
|
|
1420
|
+
this["__v_isReadonly"] = true;
|
|
1421
|
+
this._value = void 0;
|
|
1422
|
+
}
|
|
1423
|
+
get value() {
|
|
1424
|
+
return this._value = this._getter();
|
|
1425
|
+
}
|
|
1426
|
+
};
|
|
1427
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1419
1428
|
function toRef(source, key, defaultValue) {
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
} else if (isObject(source) && arguments.length > 1) {
|
|
1425
|
-
return propertyToRef(source, key, defaultValue);
|
|
1426
|
-
} else {
|
|
1427
|
-
return ref(source);
|
|
1428
|
-
}
|
|
1429
|
+
if (/* @__PURE__ */ isRef(source)) return source;
|
|
1430
|
+
else if (isFunction(source)) return new GetterRefImpl(source);
|
|
1431
|
+
else if (isObject(source) && arguments.length > 1) return propertyToRef(source, key, defaultValue);
|
|
1432
|
+
else return /* @__PURE__ */ ref(source);
|
|
1429
1433
|
}
|
|
1430
1434
|
function propertyToRef(source, key, defaultValue) {
|
|
1431
|
-
|
|
1435
|
+
return new ObjectRefImpl(source, key, defaultValue);
|
|
1432
1436
|
}
|
|
1433
|
-
|
|
1437
|
+
//#endregion
|
|
1438
|
+
//#region packages/reactivity/src/effect.ts
|
|
1434
1439
|
const EffectFlags = {
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1440
|
+
"ALLOW_RECURSE": 128,
|
|
1441
|
+
"128": "ALLOW_RECURSE",
|
|
1442
|
+
"PAUSED": 256,
|
|
1443
|
+
"256": "PAUSED",
|
|
1444
|
+
"STOP": 1024,
|
|
1445
|
+
"1024": "STOP"
|
|
1441
1446
|
};
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
if (!this.active) {
|
|
1503
|
-
return;
|
|
1504
|
-
}
|
|
1505
|
-
this.flags = 1024;
|
|
1506
|
-
let dep = this.deps;
|
|
1507
|
-
while (dep !== void 0) {
|
|
1508
|
-
dep = unlink(dep, this);
|
|
1509
|
-
}
|
|
1510
|
-
const sub = this.subs;
|
|
1511
|
-
if (sub !== void 0) {
|
|
1512
|
-
unlink(sub);
|
|
1513
|
-
}
|
|
1514
|
-
cleanup(this);
|
|
1515
|
-
}
|
|
1516
|
-
get dirty() {
|
|
1517
|
-
const flags = this.flags;
|
|
1518
|
-
if (flags & ReactiveFlags$1.Dirty) {
|
|
1519
|
-
return true;
|
|
1520
|
-
}
|
|
1521
|
-
if (flags & ReactiveFlags$1.Pending) {
|
|
1522
|
-
if (checkDirty(this.deps, this)) {
|
|
1523
|
-
this.flags = flags | ReactiveFlags$1.Dirty;
|
|
1524
|
-
return true;
|
|
1525
|
-
} else {
|
|
1526
|
-
this.flags = flags & ~ReactiveFlags$1.Pending;
|
|
1527
|
-
}
|
|
1528
|
-
}
|
|
1529
|
-
return false;
|
|
1530
|
-
}
|
|
1531
|
-
}
|
|
1532
|
-
{
|
|
1533
|
-
setupOnTrigger(ReactiveEffect);
|
|
1534
|
-
}
|
|
1447
|
+
var ReactiveEffect = class {
|
|
1448
|
+
fn() {}
|
|
1449
|
+
constructor(fn) {
|
|
1450
|
+
this.deps = void 0;
|
|
1451
|
+
this.depsTail = void 0;
|
|
1452
|
+
this.subs = void 0;
|
|
1453
|
+
this.subsTail = void 0;
|
|
1454
|
+
this.flags = 18;
|
|
1455
|
+
this.cleanups = [];
|
|
1456
|
+
this.cleanupsLength = 0;
|
|
1457
|
+
if (fn !== void 0) this.fn = fn;
|
|
1458
|
+
if (activeEffectScope) link(this, activeEffectScope);
|
|
1459
|
+
}
|
|
1460
|
+
get active() {
|
|
1461
|
+
return !(this.flags & 1024);
|
|
1462
|
+
}
|
|
1463
|
+
pause() {
|
|
1464
|
+
this.flags |= 256;
|
|
1465
|
+
}
|
|
1466
|
+
resume() {
|
|
1467
|
+
if ((this.flags &= -257) & 48) this.notify();
|
|
1468
|
+
}
|
|
1469
|
+
notify() {
|
|
1470
|
+
if (!(this.flags & 256) && this.dirty) this.run();
|
|
1471
|
+
}
|
|
1472
|
+
run() {
|
|
1473
|
+
if (!this.active) return this.fn();
|
|
1474
|
+
cleanup(this);
|
|
1475
|
+
const prevSub = startTracking(this);
|
|
1476
|
+
try {
|
|
1477
|
+
return this.fn();
|
|
1478
|
+
} finally {
|
|
1479
|
+
endTracking(this, prevSub);
|
|
1480
|
+
const flags = this.flags;
|
|
1481
|
+
if ((flags & 136) === 136) {
|
|
1482
|
+
this.flags = flags & -9;
|
|
1483
|
+
this.notify();
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
stop() {
|
|
1488
|
+
if (!this.active) return;
|
|
1489
|
+
this.flags = 1024;
|
|
1490
|
+
let dep = this.deps;
|
|
1491
|
+
while (dep !== void 0) dep = unlink(dep, this);
|
|
1492
|
+
const sub = this.subs;
|
|
1493
|
+
if (sub !== void 0) unlink(sub);
|
|
1494
|
+
cleanup(this);
|
|
1495
|
+
}
|
|
1496
|
+
get dirty() {
|
|
1497
|
+
const flags = this.flags;
|
|
1498
|
+
if (flags & 16) return true;
|
|
1499
|
+
if (flags & 32) if (checkDirty(this.deps, this)) {
|
|
1500
|
+
this.flags = flags | 16;
|
|
1501
|
+
return true;
|
|
1502
|
+
} else this.flags = flags & -33;
|
|
1503
|
+
return false;
|
|
1504
|
+
}
|
|
1505
|
+
};
|
|
1506
|
+
setupOnTrigger(ReactiveEffect);
|
|
1535
1507
|
function effect(fn, options) {
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
}
|
|
1566
|
-
const runner = e.run.bind(e);
|
|
1567
|
-
runner.effect = e;
|
|
1568
|
-
return runner;
|
|
1508
|
+
if (fn.effect instanceof ReactiveEffect) fn = fn.effect.fn;
|
|
1509
|
+
const e = new ReactiveEffect(fn);
|
|
1510
|
+
if (options) {
|
|
1511
|
+
const { onStop, scheduler } = options;
|
|
1512
|
+
if (onStop) {
|
|
1513
|
+
options.onStop = void 0;
|
|
1514
|
+
const stop = e.stop.bind(e);
|
|
1515
|
+
e.stop = () => {
|
|
1516
|
+
stop();
|
|
1517
|
+
onStop();
|
|
1518
|
+
};
|
|
1519
|
+
}
|
|
1520
|
+
if (scheduler) {
|
|
1521
|
+
options.scheduler = void 0;
|
|
1522
|
+
e.notify = () => {
|
|
1523
|
+
if (!(e.flags & 256)) scheduler();
|
|
1524
|
+
};
|
|
1525
|
+
}
|
|
1526
|
+
extend(e, options);
|
|
1527
|
+
}
|
|
1528
|
+
try {
|
|
1529
|
+
e.run();
|
|
1530
|
+
} catch (err) {
|
|
1531
|
+
e.stop();
|
|
1532
|
+
throw err;
|
|
1533
|
+
}
|
|
1534
|
+
const runner = e.run.bind(e);
|
|
1535
|
+
runner.effect = e;
|
|
1536
|
+
return runner;
|
|
1569
1537
|
}
|
|
1538
|
+
/**
|
|
1539
|
+
* Stops the effect associated with the given runner.
|
|
1540
|
+
*
|
|
1541
|
+
* @param runner - Association with the effect to stop tracking.
|
|
1542
|
+
*/
|
|
1570
1543
|
function stop(runner) {
|
|
1571
|
-
|
|
1544
|
+
runner.effect.stop();
|
|
1572
1545
|
}
|
|
1573
1546
|
const resetTrackingStack = [];
|
|
1547
|
+
/**
|
|
1548
|
+
* Temporarily pauses tracking.
|
|
1549
|
+
*/
|
|
1574
1550
|
function pauseTracking() {
|
|
1575
|
-
|
|
1576
|
-
|
|
1551
|
+
resetTrackingStack.push(activeSub);
|
|
1552
|
+
setActiveSub();
|
|
1577
1553
|
}
|
|
1554
|
+
/**
|
|
1555
|
+
* Re-enables effect tracking (if it was paused).
|
|
1556
|
+
*/
|
|
1578
1557
|
function enableTracking() {
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
break;
|
|
1588
|
-
}
|
|
1589
|
-
}
|
|
1590
|
-
}
|
|
1558
|
+
if (!(activeSub === void 0)) resetTrackingStack.push(activeSub);
|
|
1559
|
+
else {
|
|
1560
|
+
resetTrackingStack.push(void 0);
|
|
1561
|
+
for (let i = resetTrackingStack.length - 1; i >= 0; i--) if (resetTrackingStack[i] !== void 0) {
|
|
1562
|
+
setActiveSub(resetTrackingStack[i]);
|
|
1563
|
+
break;
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1591
1566
|
}
|
|
1567
|
+
/**
|
|
1568
|
+
* Resets the previous global effect tracking state.
|
|
1569
|
+
*/
|
|
1592
1570
|
function resetTracking() {
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
);
|
|
1597
|
-
}
|
|
1598
|
-
if (resetTrackingStack.length) {
|
|
1599
|
-
setActiveSub(resetTrackingStack.pop());
|
|
1600
|
-
} else {
|
|
1601
|
-
setActiveSub();
|
|
1602
|
-
}
|
|
1571
|
+
if (resetTrackingStack.length === 0) warn("resetTracking() was called when there was no active tracking to reset.");
|
|
1572
|
+
if (resetTrackingStack.length) setActiveSub(resetTrackingStack.pop());
|
|
1573
|
+
else setActiveSub();
|
|
1603
1574
|
}
|
|
1604
1575
|
function cleanup(sub) {
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
sub.cleanupsLength = 0;
|
|
1611
|
-
}
|
|
1576
|
+
const l = sub.cleanupsLength;
|
|
1577
|
+
if (l) {
|
|
1578
|
+
for (let i = 0; i < l; i++) sub.cleanups[i]();
|
|
1579
|
+
sub.cleanupsLength = 0;
|
|
1580
|
+
}
|
|
1612
1581
|
}
|
|
1582
|
+
/**
|
|
1583
|
+
* Registers a cleanup function for the current active effect.
|
|
1584
|
+
* The cleanup function is called right before the next effect run, or when the
|
|
1585
|
+
* effect is stopped.
|
|
1586
|
+
*
|
|
1587
|
+
* Throws a warning if there is no current active effect. The warning can be
|
|
1588
|
+
* suppressed by passing `true` to the second argument.
|
|
1589
|
+
*
|
|
1590
|
+
* @param fn - the cleanup function to be registered
|
|
1591
|
+
* @param failSilently - if `true`, will not throw warning when called without
|
|
1592
|
+
* an active effect.
|
|
1593
|
+
*/
|
|
1613
1594
|
function onEffectCleanup(fn, failSilently = false) {
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
} else if (!failSilently) {
|
|
1617
|
-
warn(
|
|
1618
|
-
`onEffectCleanup() was called when there was no active effect to associate with.`
|
|
1619
|
-
);
|
|
1620
|
-
}
|
|
1595
|
+
if (activeSub instanceof ReactiveEffect) activeSub.cleanups[activeSub.cleanupsLength++] = () => cleanupEffect(fn);
|
|
1596
|
+
else if (!failSilently) warn("onEffectCleanup() was called when there was no active effect to associate with.");
|
|
1621
1597
|
}
|
|
1622
1598
|
function cleanupEffect(fn) {
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
}
|
|
1630
|
-
|
|
1599
|
+
const prevSub = setActiveSub();
|
|
1600
|
+
try {
|
|
1601
|
+
fn();
|
|
1602
|
+
} finally {
|
|
1603
|
+
setActiveSub(prevSub);
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
//#endregion
|
|
1607
|
+
//#region packages/reactivity/src/effectScope.ts
|
|
1631
1608
|
let activeEffectScope;
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
dep = dep.nextDep;
|
|
1709
|
-
node.stop();
|
|
1710
|
-
} else {
|
|
1711
|
-
dep = unlink(dep, this);
|
|
1712
|
-
}
|
|
1713
|
-
}
|
|
1714
|
-
cleanup(this);
|
|
1715
|
-
}
|
|
1716
|
-
}
|
|
1609
|
+
var EffectScope = class {
|
|
1610
|
+
constructor(detached = false) {
|
|
1611
|
+
this.deps = void 0;
|
|
1612
|
+
this.depsTail = void 0;
|
|
1613
|
+
this.subs = void 0;
|
|
1614
|
+
this.subsTail = void 0;
|
|
1615
|
+
this.flags = 0;
|
|
1616
|
+
this.cleanups = [];
|
|
1617
|
+
this.cleanupsLength = 0;
|
|
1618
|
+
if (!detached && activeEffectScope) link(this, activeEffectScope);
|
|
1619
|
+
}
|
|
1620
|
+
get active() {
|
|
1621
|
+
return !(this.flags & 1024);
|
|
1622
|
+
}
|
|
1623
|
+
pause() {
|
|
1624
|
+
if (!(this.flags & 256)) {
|
|
1625
|
+
this.flags |= 256;
|
|
1626
|
+
for (let link = this.deps; link !== void 0; link = link.nextDep) {
|
|
1627
|
+
const dep = link.dep;
|
|
1628
|
+
if ("pause" in dep) dep.pause();
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
/**
|
|
1633
|
+
* Resumes the effect scope, including all child scopes and effects.
|
|
1634
|
+
*/
|
|
1635
|
+
resume() {
|
|
1636
|
+
const flags = this.flags;
|
|
1637
|
+
if (flags & 256) {
|
|
1638
|
+
this.flags = flags & -257;
|
|
1639
|
+
for (let link = this.deps; link !== void 0; link = link.nextDep) {
|
|
1640
|
+
const dep = link.dep;
|
|
1641
|
+
if ("resume" in dep) dep.resume();
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1645
|
+
run(fn) {
|
|
1646
|
+
const prevScope = activeEffectScope;
|
|
1647
|
+
try {
|
|
1648
|
+
activeEffectScope = this;
|
|
1649
|
+
return fn();
|
|
1650
|
+
} finally {
|
|
1651
|
+
activeEffectScope = prevScope;
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
stop() {
|
|
1655
|
+
if (!this.active) return;
|
|
1656
|
+
this.flags = 1024;
|
|
1657
|
+
this.reset();
|
|
1658
|
+
const sub = this.subs;
|
|
1659
|
+
if (sub !== void 0) unlink(sub);
|
|
1660
|
+
}
|
|
1661
|
+
/**
|
|
1662
|
+
* @internal
|
|
1663
|
+
*/
|
|
1664
|
+
reset() {
|
|
1665
|
+
let dep = this.deps;
|
|
1666
|
+
while (dep !== void 0) {
|
|
1667
|
+
const node = dep.dep;
|
|
1668
|
+
if ("stop" in node) {
|
|
1669
|
+
dep = dep.nextDep;
|
|
1670
|
+
node.stop();
|
|
1671
|
+
} else dep = unlink(dep, this);
|
|
1672
|
+
}
|
|
1673
|
+
cleanup(this);
|
|
1674
|
+
}
|
|
1675
|
+
};
|
|
1676
|
+
/**
|
|
1677
|
+
* Creates an effect scope object which can capture the reactive effects (i.e.
|
|
1678
|
+
* computed and watchers) created within it so that these effects can be
|
|
1679
|
+
* disposed together. For detailed use cases of this API, please consult its
|
|
1680
|
+
* corresponding {@link https://github.com/vuejs/rfcs/blob/master/active-rfcs/0041-reactivity-effect-scope.md | RFC}.
|
|
1681
|
+
*
|
|
1682
|
+
* @param detached - Can be used to create a "detached" effect scope.
|
|
1683
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#effectscope}
|
|
1684
|
+
*/
|
|
1717
1685
|
function effectScope(detached) {
|
|
1718
|
-
|
|
1686
|
+
return new EffectScope(detached);
|
|
1719
1687
|
}
|
|
1688
|
+
/**
|
|
1689
|
+
* Returns the current active effect scope if there is one.
|
|
1690
|
+
*
|
|
1691
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#getcurrentscope}
|
|
1692
|
+
*/
|
|
1720
1693
|
function getCurrentScope() {
|
|
1721
|
-
|
|
1694
|
+
return activeEffectScope;
|
|
1722
1695
|
}
|
|
1723
1696
|
function setCurrentScope(scope) {
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1697
|
+
try {
|
|
1698
|
+
return activeEffectScope;
|
|
1699
|
+
} finally {
|
|
1700
|
+
activeEffectScope = scope;
|
|
1701
|
+
}
|
|
1729
1702
|
}
|
|
1703
|
+
/**
|
|
1704
|
+
* Registers a dispose callback on the current active effect scope. The
|
|
1705
|
+
* callback will be invoked when the associated effect scope is stopped.
|
|
1706
|
+
*
|
|
1707
|
+
* @param fn - The callback function to attach to the scope's cleanup.
|
|
1708
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#onscopedispose}
|
|
1709
|
+
*/
|
|
1730
1710
|
function onScopeDispose(fn, failSilently = false) {
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
} else if (!failSilently) {
|
|
1734
|
-
warn(
|
|
1735
|
-
`onScopeDispose() is called when there is no active effect scope to be associated with.`
|
|
1736
|
-
);
|
|
1737
|
-
}
|
|
1738
|
-
}
|
|
1739
|
-
|
|
1740
|
-
class ComputedRefImpl {
|
|
1741
|
-
constructor(fn, setter) {
|
|
1742
|
-
this.fn = fn;
|
|
1743
|
-
this.setter = setter;
|
|
1744
|
-
/**
|
|
1745
|
-
* @internal
|
|
1746
|
-
*/
|
|
1747
|
-
this._value = void 0;
|
|
1748
|
-
this.subs = void 0;
|
|
1749
|
-
this.subsTail = void 0;
|
|
1750
|
-
this.deps = void 0;
|
|
1751
|
-
this.depsTail = void 0;
|
|
1752
|
-
this.flags = ReactiveFlags$1.Mutable | ReactiveFlags$1.Dirty;
|
|
1753
|
-
/**
|
|
1754
|
-
* @internal
|
|
1755
|
-
*/
|
|
1756
|
-
this.__v_isRef = true;
|
|
1757
|
-
this["__v_isReadonly"] = !setter;
|
|
1758
|
-
}
|
|
1759
|
-
// TODO isolatedDeclarations "__v_isReadonly"
|
|
1760
|
-
// for backwards compat
|
|
1761
|
-
get effect() {
|
|
1762
|
-
return this;
|
|
1763
|
-
}
|
|
1764
|
-
// for backwards compat
|
|
1765
|
-
get dep() {
|
|
1766
|
-
return this;
|
|
1767
|
-
}
|
|
1768
|
-
/**
|
|
1769
|
-
* @internal
|
|
1770
|
-
* for backwards compat
|
|
1771
|
-
*/
|
|
1772
|
-
get _dirty() {
|
|
1773
|
-
const flags = this.flags;
|
|
1774
|
-
if (flags & ReactiveFlags$1.Dirty) {
|
|
1775
|
-
return true;
|
|
1776
|
-
}
|
|
1777
|
-
if (flags & ReactiveFlags$1.Pending) {
|
|
1778
|
-
if (checkDirty(this.deps, this)) {
|
|
1779
|
-
this.flags = flags | ReactiveFlags$1.Dirty;
|
|
1780
|
-
return true;
|
|
1781
|
-
} else {
|
|
1782
|
-
this.flags = flags & ~ReactiveFlags$1.Pending;
|
|
1783
|
-
}
|
|
1784
|
-
}
|
|
1785
|
-
return false;
|
|
1786
|
-
}
|
|
1787
|
-
/**
|
|
1788
|
-
* @internal
|
|
1789
|
-
* for backwards compat
|
|
1790
|
-
*/
|
|
1791
|
-
set _dirty(v) {
|
|
1792
|
-
if (v) {
|
|
1793
|
-
this.flags |= ReactiveFlags$1.Dirty;
|
|
1794
|
-
} else {
|
|
1795
|
-
this.flags &= ~(ReactiveFlags$1.Dirty | ReactiveFlags$1.Pending);
|
|
1796
|
-
}
|
|
1797
|
-
}
|
|
1798
|
-
get value() {
|
|
1799
|
-
const flags = this.flags;
|
|
1800
|
-
if (flags & ReactiveFlags$1.Dirty || flags & ReactiveFlags$1.Pending && checkDirty(this.deps, this)) {
|
|
1801
|
-
if (this.update()) {
|
|
1802
|
-
const subs = this.subs;
|
|
1803
|
-
if (subs !== void 0) {
|
|
1804
|
-
shallowPropagate(subs);
|
|
1805
|
-
}
|
|
1806
|
-
}
|
|
1807
|
-
} else if (flags & ReactiveFlags$1.Pending) {
|
|
1808
|
-
this.flags = flags & ~ReactiveFlags$1.Pending;
|
|
1809
|
-
}
|
|
1810
|
-
if (activeSub !== void 0) {
|
|
1811
|
-
{
|
|
1812
|
-
onTrack(activeSub, {
|
|
1813
|
-
target: this,
|
|
1814
|
-
type: "get",
|
|
1815
|
-
key: "value"
|
|
1816
|
-
});
|
|
1817
|
-
}
|
|
1818
|
-
link(this, activeSub);
|
|
1819
|
-
} else if (activeEffectScope !== void 0) {
|
|
1820
|
-
link(this, activeEffectScope);
|
|
1821
|
-
}
|
|
1822
|
-
return this._value;
|
|
1823
|
-
}
|
|
1824
|
-
set value(newValue) {
|
|
1825
|
-
if (this.setter) {
|
|
1826
|
-
this.setter(newValue);
|
|
1827
|
-
} else {
|
|
1828
|
-
warn("Write operation failed: computed value is readonly");
|
|
1829
|
-
}
|
|
1830
|
-
}
|
|
1831
|
-
update() {
|
|
1832
|
-
const prevSub = startTracking(this);
|
|
1833
|
-
try {
|
|
1834
|
-
const oldValue = this._value;
|
|
1835
|
-
const newValue = this.fn(oldValue);
|
|
1836
|
-
if (hasChanged(oldValue, newValue)) {
|
|
1837
|
-
this._value = newValue;
|
|
1838
|
-
return true;
|
|
1839
|
-
}
|
|
1840
|
-
return false;
|
|
1841
|
-
} finally {
|
|
1842
|
-
endTracking(this, prevSub);
|
|
1843
|
-
}
|
|
1844
|
-
}
|
|
1845
|
-
}
|
|
1846
|
-
{
|
|
1847
|
-
setupOnTrigger(ComputedRefImpl);
|
|
1711
|
+
if (activeEffectScope !== void 0) activeEffectScope.cleanups[activeEffectScope.cleanupsLength++] = fn;
|
|
1712
|
+
else if (!failSilently) warn("onScopeDispose() is called when there is no active effect scope to be associated with.");
|
|
1848
1713
|
}
|
|
1714
|
+
//#endregion
|
|
1715
|
+
//#region packages/reactivity/src/computed.ts
|
|
1716
|
+
/**
|
|
1717
|
+
* @private exported by @vue/reactivity for Vue core use, but not exported from
|
|
1718
|
+
* the main vue package
|
|
1719
|
+
*/
|
|
1720
|
+
var ComputedRefImpl = class {
|
|
1721
|
+
get effect() {
|
|
1722
|
+
return this;
|
|
1723
|
+
}
|
|
1724
|
+
get dep() {
|
|
1725
|
+
return this;
|
|
1726
|
+
}
|
|
1727
|
+
/**
|
|
1728
|
+
* @internal
|
|
1729
|
+
* for backwards compat
|
|
1730
|
+
*/
|
|
1731
|
+
get _dirty() {
|
|
1732
|
+
const flags = this.flags;
|
|
1733
|
+
if (flags & ReactiveFlags$1.Dirty) return true;
|
|
1734
|
+
if (flags & ReactiveFlags$1.Pending) if (checkDirty(this.deps, this)) {
|
|
1735
|
+
this.flags = flags | ReactiveFlags$1.Dirty;
|
|
1736
|
+
return true;
|
|
1737
|
+
} else this.flags = flags & ~ReactiveFlags$1.Pending;
|
|
1738
|
+
return false;
|
|
1739
|
+
}
|
|
1740
|
+
/**
|
|
1741
|
+
* @internal
|
|
1742
|
+
* for backwards compat
|
|
1743
|
+
*/
|
|
1744
|
+
set _dirty(v) {
|
|
1745
|
+
if (v) this.flags |= ReactiveFlags$1.Dirty;
|
|
1746
|
+
else this.flags &= ~(ReactiveFlags$1.Dirty | ReactiveFlags$1.Pending);
|
|
1747
|
+
}
|
|
1748
|
+
constructor(fn, setter) {
|
|
1749
|
+
this.fn = fn;
|
|
1750
|
+
this.setter = setter;
|
|
1751
|
+
this._value = void 0;
|
|
1752
|
+
this.subs = void 0;
|
|
1753
|
+
this.subsTail = void 0;
|
|
1754
|
+
this.deps = void 0;
|
|
1755
|
+
this.depsTail = void 0;
|
|
1756
|
+
this.flags = ReactiveFlags$1.Mutable | ReactiveFlags$1.Dirty;
|
|
1757
|
+
this.__v_isRef = true;
|
|
1758
|
+
this["__v_isReadonly"] = !setter;
|
|
1759
|
+
}
|
|
1760
|
+
get value() {
|
|
1761
|
+
const flags = this.flags;
|
|
1762
|
+
if (flags & ReactiveFlags$1.Dirty || flags & ReactiveFlags$1.Pending && checkDirty(this.deps, this)) {
|
|
1763
|
+
if (this.update()) {
|
|
1764
|
+
const subs = this.subs;
|
|
1765
|
+
if (subs !== void 0) shallowPropagate(subs);
|
|
1766
|
+
}
|
|
1767
|
+
} else if (flags & ReactiveFlags$1.Pending) this.flags = flags & ~ReactiveFlags$1.Pending;
|
|
1768
|
+
if (activeSub !== void 0) {
|
|
1769
|
+
onTrack(activeSub, {
|
|
1770
|
+
target: this,
|
|
1771
|
+
type: "get",
|
|
1772
|
+
key: "value"
|
|
1773
|
+
});
|
|
1774
|
+
link(this, activeSub);
|
|
1775
|
+
} else if (activeEffectScope !== void 0) link(this, activeEffectScope);
|
|
1776
|
+
return this._value;
|
|
1777
|
+
}
|
|
1778
|
+
set value(newValue) {
|
|
1779
|
+
if (this.setter) this.setter(newValue);
|
|
1780
|
+
else warn("Write operation failed: computed value is readonly");
|
|
1781
|
+
}
|
|
1782
|
+
update() {
|
|
1783
|
+
const prevSub = startTracking(this);
|
|
1784
|
+
try {
|
|
1785
|
+
const oldValue = this._value;
|
|
1786
|
+
const newValue = this.fn(oldValue);
|
|
1787
|
+
if (hasChanged(oldValue, newValue)) {
|
|
1788
|
+
this._value = newValue;
|
|
1789
|
+
return true;
|
|
1790
|
+
}
|
|
1791
|
+
return false;
|
|
1792
|
+
} finally {
|
|
1793
|
+
endTracking(this, prevSub);
|
|
1794
|
+
}
|
|
1795
|
+
}
|
|
1796
|
+
};
|
|
1797
|
+
setupOnTrigger(ComputedRefImpl);
|
|
1798
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1849
1799
|
function computed(getterOrOptions, debugOptions, isSSR = false) {
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1800
|
+
let getter;
|
|
1801
|
+
let setter;
|
|
1802
|
+
if (isFunction(getterOrOptions)) getter = getterOrOptions;
|
|
1803
|
+
else {
|
|
1804
|
+
getter = getterOrOptions.get;
|
|
1805
|
+
setter = getterOrOptions.set;
|
|
1806
|
+
}
|
|
1807
|
+
const cRef = new ComputedRefImpl(getter, setter);
|
|
1808
|
+
if (debugOptions && !isSSR) {
|
|
1809
|
+
cRef.onTrack = debugOptions.onTrack;
|
|
1810
|
+
cRef.onTrigger = debugOptions.onTrigger;
|
|
1811
|
+
}
|
|
1812
|
+
return cRef;
|
|
1813
|
+
}
|
|
1814
|
+
//#endregion
|
|
1815
|
+
//#region packages/reactivity/src/constants.ts
|
|
1866
1816
|
const TrackOpTypes = {
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1817
|
+
"GET": "get",
|
|
1818
|
+
"HAS": "has",
|
|
1819
|
+
"ITERATE": "iterate"
|
|
1870
1820
|
};
|
|
1871
1821
|
const TriggerOpTypes = {
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1822
|
+
"SET": "set",
|
|
1823
|
+
"ADD": "add",
|
|
1824
|
+
"DELETE": "delete",
|
|
1825
|
+
"CLEAR": "clear"
|
|
1876
1826
|
};
|
|
1877
1827
|
const ReactiveFlags = {
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1828
|
+
"SKIP": "__v_skip",
|
|
1829
|
+
"IS_REACTIVE": "__v_isReactive",
|
|
1830
|
+
"IS_READONLY": "__v_isReadonly",
|
|
1831
|
+
"IS_SHALLOW": "__v_isShallow",
|
|
1832
|
+
"RAW": "__v_raw",
|
|
1833
|
+
"IS_REF": "__v_isRef"
|
|
1884
1834
|
};
|
|
1885
|
-
|
|
1835
|
+
//#endregion
|
|
1836
|
+
//#region packages/reactivity/src/watch.ts
|
|
1886
1837
|
const WatchErrorCodes = {
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1838
|
+
"WATCH_GETTER": 2,
|
|
1839
|
+
"2": "WATCH_GETTER",
|
|
1840
|
+
"WATCH_CALLBACK": 3,
|
|
1841
|
+
"3": "WATCH_CALLBACK",
|
|
1842
|
+
"WATCH_CLEANUP": 4,
|
|
1843
|
+
"4": "WATCH_CLEANUP"
|
|
1893
1844
|
};
|
|
1894
1845
|
const INITIAL_WATCHER_VALUE = {};
|
|
1895
1846
|
let activeWatcher = void 0;
|
|
1847
|
+
/**
|
|
1848
|
+
* Returns the current active effect if there is one.
|
|
1849
|
+
*/
|
|
1896
1850
|
function getCurrentWatcher() {
|
|
1897
|
-
|
|
1851
|
+
return activeWatcher;
|
|
1898
1852
|
}
|
|
1853
|
+
/**
|
|
1854
|
+
* Registers a cleanup callback on the current active effect. This
|
|
1855
|
+
* registered cleanup callback will be invoked right before the
|
|
1856
|
+
* associated effect re-runs.
|
|
1857
|
+
*
|
|
1858
|
+
* @param cleanupFn - The callback function to attach to the effect's cleanup.
|
|
1859
|
+
* @param failSilently - if `true`, will not throw warning when called without
|
|
1860
|
+
* an active effect.
|
|
1861
|
+
* @param owner - The effect that this cleanup function should be attached to.
|
|
1862
|
+
* By default, the current active effect.
|
|
1863
|
+
*/
|
|
1899
1864
|
function onWatcherCleanup(cleanupFn, failSilently = false, owner = activeWatcher) {
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
if (!this.cb) {
|
|
1996
|
-
return;
|
|
1997
|
-
}
|
|
1998
|
-
const { immediate, deep, call } = this.options;
|
|
1999
|
-
if (initialRun && !immediate) {
|
|
2000
|
-
return;
|
|
2001
|
-
}
|
|
2002
|
-
if (deep || this.forceTrigger || (this.isMultiSource ? newValue.some((v, i) => hasChanged(v, oldValue[i])) : hasChanged(newValue, oldValue))) {
|
|
2003
|
-
cleanup(this);
|
|
2004
|
-
const currentWatcher = activeWatcher;
|
|
2005
|
-
activeWatcher = this;
|
|
2006
|
-
try {
|
|
2007
|
-
const args = [
|
|
2008
|
-
newValue,
|
|
2009
|
-
// pass undefined as the old value when it's changed for the first time
|
|
2010
|
-
oldValue === INITIAL_WATCHER_VALUE ? void 0 : this.isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE ? [] : oldValue,
|
|
2011
|
-
this.boundCleanup
|
|
2012
|
-
];
|
|
2013
|
-
call ? call(this.cb, 3, args) : (
|
|
2014
|
-
// @ts-expect-error
|
|
2015
|
-
this.cb(...args)
|
|
2016
|
-
);
|
|
2017
|
-
} finally {
|
|
2018
|
-
activeWatcher = currentWatcher;
|
|
2019
|
-
}
|
|
2020
|
-
}
|
|
2021
|
-
}
|
|
2022
|
-
}
|
|
1865
|
+
if (owner) {
|
|
1866
|
+
const { call } = owner.options;
|
|
1867
|
+
if (call) owner.cleanups[owner.cleanupsLength++] = () => call(cleanupFn, 4);
|
|
1868
|
+
else owner.cleanups[owner.cleanupsLength++] = cleanupFn;
|
|
1869
|
+
} else if (!failSilently) warn("onWatcherCleanup() was called when there was no active watcher to associate with.");
|
|
1870
|
+
}
|
|
1871
|
+
var WatcherEffect = class extends ReactiveEffect {
|
|
1872
|
+
constructor(source, cb, options = EMPTY_OBJ) {
|
|
1873
|
+
const { deep, once, call, onWarn } = options;
|
|
1874
|
+
let getter;
|
|
1875
|
+
let forceTrigger = false;
|
|
1876
|
+
let isMultiSource = false;
|
|
1877
|
+
if (/* @__PURE__ */ isRef(source)) {
|
|
1878
|
+
getter = () => source.value;
|
|
1879
|
+
forceTrigger = /* @__PURE__ */ isShallow(source);
|
|
1880
|
+
} else if (/* @__PURE__ */ isReactive(source)) {
|
|
1881
|
+
getter = () => reactiveGetter(source, deep);
|
|
1882
|
+
forceTrigger = true;
|
|
1883
|
+
} else if (isArray(source)) {
|
|
1884
|
+
isMultiSource = true;
|
|
1885
|
+
forceTrigger = source.some((s) => /* @__PURE__ */ isReactive(s) || /* @__PURE__ */ isShallow(s));
|
|
1886
|
+
getter = () => source.map((s) => {
|
|
1887
|
+
if (/* @__PURE__ */ isRef(s)) return s.value;
|
|
1888
|
+
else if (/* @__PURE__ */ isReactive(s)) return reactiveGetter(s, deep);
|
|
1889
|
+
else if (isFunction(s)) return call ? call(s, 2) : s();
|
|
1890
|
+
else warnInvalidSource(s, onWarn);
|
|
1891
|
+
});
|
|
1892
|
+
} else if (isFunction(source)) if (cb) getter = call ? () => call(source, 2) : source;
|
|
1893
|
+
else getter = () => {
|
|
1894
|
+
if (this.cleanupsLength) {
|
|
1895
|
+
const prevSub = setActiveSub();
|
|
1896
|
+
try {
|
|
1897
|
+
cleanup(this);
|
|
1898
|
+
} finally {
|
|
1899
|
+
setActiveSub(prevSub);
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1902
|
+
const currentEffect = activeWatcher;
|
|
1903
|
+
activeWatcher = this;
|
|
1904
|
+
try {
|
|
1905
|
+
return call ? call(source, 3, [this.boundCleanup]) : source(this.boundCleanup);
|
|
1906
|
+
} finally {
|
|
1907
|
+
activeWatcher = currentEffect;
|
|
1908
|
+
}
|
|
1909
|
+
};
|
|
1910
|
+
else {
|
|
1911
|
+
getter = NOOP;
|
|
1912
|
+
warnInvalidSource(source, onWarn);
|
|
1913
|
+
}
|
|
1914
|
+
if (cb && deep) {
|
|
1915
|
+
const baseGetter = getter;
|
|
1916
|
+
const depth = deep === true ? Infinity : deep;
|
|
1917
|
+
getter = () => traverse(baseGetter(), depth);
|
|
1918
|
+
}
|
|
1919
|
+
super(getter);
|
|
1920
|
+
this.cb = cb;
|
|
1921
|
+
this.options = options;
|
|
1922
|
+
this.boundCleanup = (fn) => onWatcherCleanup(fn, false, this);
|
|
1923
|
+
this.forceTrigger = forceTrigger;
|
|
1924
|
+
this.isMultiSource = isMultiSource;
|
|
1925
|
+
if (once && cb) {
|
|
1926
|
+
const _cb = cb;
|
|
1927
|
+
cb = (...args) => {
|
|
1928
|
+
_cb(...args);
|
|
1929
|
+
this.stop();
|
|
1930
|
+
};
|
|
1931
|
+
}
|
|
1932
|
+
this.cb = cb;
|
|
1933
|
+
this.oldValue = isMultiSource ? new Array(source.length).fill(INITIAL_WATCHER_VALUE) : INITIAL_WATCHER_VALUE;
|
|
1934
|
+
this.onTrack = options.onTrack;
|
|
1935
|
+
this.onTrigger = options.onTrigger;
|
|
1936
|
+
}
|
|
1937
|
+
run(initialRun = false) {
|
|
1938
|
+
const oldValue = this.oldValue;
|
|
1939
|
+
const newValue = this.oldValue = super.run();
|
|
1940
|
+
if (!this.cb) return;
|
|
1941
|
+
const { immediate, deep, call } = this.options;
|
|
1942
|
+
if (initialRun && !immediate) return;
|
|
1943
|
+
if (deep || this.forceTrigger || (this.isMultiSource ? newValue.some((v, i) => hasChanged(v, oldValue[i])) : hasChanged(newValue, oldValue))) {
|
|
1944
|
+
cleanup(this);
|
|
1945
|
+
const currentWatcher = activeWatcher;
|
|
1946
|
+
activeWatcher = this;
|
|
1947
|
+
try {
|
|
1948
|
+
const args = [
|
|
1949
|
+
newValue,
|
|
1950
|
+
oldValue === INITIAL_WATCHER_VALUE ? void 0 : this.isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE ? [] : oldValue,
|
|
1951
|
+
this.boundCleanup
|
|
1952
|
+
];
|
|
1953
|
+
call ? call(this.cb, 3, args) : this.cb(...args);
|
|
1954
|
+
} finally {
|
|
1955
|
+
activeWatcher = currentWatcher;
|
|
1956
|
+
}
|
|
1957
|
+
}
|
|
1958
|
+
}
|
|
1959
|
+
};
|
|
2023
1960
|
function reactiveGetter(source, deep) {
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
return traverse(source);
|
|
1961
|
+
if (deep) return source;
|
|
1962
|
+
if (/* @__PURE__ */ isShallow(source) || deep === false || deep === 0) return traverse(source, 1);
|
|
1963
|
+
return traverse(source);
|
|
2028
1964
|
}
|
|
2029
1965
|
function warnInvalidSource(s, onWarn) {
|
|
2030
|
-
|
|
2031
|
-
`Invalid watch source: `,
|
|
2032
|
-
s,
|
|
2033
|
-
`A watch source can only be a getter/effect function, a ref, a reactive object, or an array of these types.`
|
|
2034
|
-
);
|
|
1966
|
+
(onWarn || warn)(`Invalid watch source: `, s, "A watch source can only be a getter/effect function, a ref, a reactive object, or an array of these types.");
|
|
2035
1967
|
}
|
|
2036
1968
|
function watch(source, cb, options = EMPTY_OBJ) {
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
1969
|
+
const effect = new WatcherEffect(source, cb, options);
|
|
1970
|
+
effect.run(true);
|
|
1971
|
+
const stop = effect.stop.bind(effect);
|
|
1972
|
+
stop.pause = effect.pause.bind(effect);
|
|
1973
|
+
stop.resume = effect.resume.bind(effect);
|
|
1974
|
+
stop.stop = stop;
|
|
1975
|
+
return stop;
|
|
2044
1976
|
}
|
|
2045
1977
|
function traverse(value, depth = Infinity, seen) {
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
traverse(v, depth, seen);
|
|
2064
|
-
});
|
|
2065
|
-
} else if (isPlainObject(value)) {
|
|
2066
|
-
for (const key in value) {
|
|
2067
|
-
traverse(value[key], depth, seen);
|
|
2068
|
-
}
|
|
2069
|
-
for (const key of Object.getOwnPropertySymbols(value)) {
|
|
2070
|
-
if (Object.prototype.propertyIsEnumerable.call(value, key)) {
|
|
2071
|
-
traverse(value[key], depth, seen);
|
|
2072
|
-
}
|
|
2073
|
-
}
|
|
2074
|
-
}
|
|
2075
|
-
return value;
|
|
2076
|
-
}
|
|
2077
|
-
|
|
1978
|
+
if (depth <= 0 || !isObject(value) || value["__v_skip"]) return value;
|
|
1979
|
+
seen = seen || /* @__PURE__ */ new Map();
|
|
1980
|
+
if ((seen.get(value) || 0) >= depth) return value;
|
|
1981
|
+
seen.set(value, depth);
|
|
1982
|
+
depth--;
|
|
1983
|
+
if (/* @__PURE__ */ isRef(value)) traverse(value.value, depth, seen);
|
|
1984
|
+
else if (isArray(value)) for (let i = 0; i < value.length; i++) traverse(value[i], depth, seen);
|
|
1985
|
+
else if (isSet(value) || isMap(value)) value.forEach((v) => {
|
|
1986
|
+
traverse(v, depth, seen);
|
|
1987
|
+
});
|
|
1988
|
+
else if (isPlainObject(value)) {
|
|
1989
|
+
for (const key in value) traverse(value[key], depth, seen);
|
|
1990
|
+
for (const key of Object.getOwnPropertySymbols(value)) if (Object.prototype.propertyIsEnumerable.call(value, key)) traverse(value[key], depth, seen);
|
|
1991
|
+
}
|
|
1992
|
+
return value;
|
|
1993
|
+
}
|
|
1994
|
+
//#endregion
|
|
2078
1995
|
export { ARRAY_ITERATE_KEY, EffectFlags, EffectScope, ITERATE_KEY, MAP_KEY_ITERATE_KEY, ReactiveEffect, ReactiveFlags, TrackOpTypes, TriggerOpTypes, WatchErrorCodes, WatcherEffect, computed, customRef, effect, effectScope, enableTracking, getCurrentScope, getCurrentWatcher, isProxy, isReactive, isReadonly, isRef, isShallow, markRaw, onEffectCleanup, onScopeDispose, onWatcherCleanup, pauseTracking, proxyRefs, reactive, reactiveReadArray, readonly, ref, resetTracking, setActiveSub, setCurrentScope, shallowReactive, shallowReadArray, shallowReadonly, shallowRef, stop, toRaw, toReactive, toReadonly, toRef, toRefs, toValue, track, traverse, trigger, triggerRef, unref, watch };
|