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