@vue/reactivity 3.5.17 → 3.6.0-alpha.2
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 +973 -896
- package/dist/reactivity.cjs.prod.js +786 -751
- package/dist/reactivity.d.ts +245 -209
- package/dist/reactivity.esm-browser.js +971 -903
- package/dist/reactivity.esm-browser.prod.js +2 -2
- package/dist/reactivity.esm-bundler.js +979 -900
- package/dist/reactivity.global.js +973 -902
- package/dist/reactivity.global.prod.js +2 -2
- package/package.json +2 -2
package/dist/reactivity.cjs.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vue/reactivity v3.
|
|
2
|
+
* @vue/reactivity v3.6.0-alpha.2
|
|
3
3
|
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
4
4
|
* @license MIT
|
|
5
5
|
**/
|
|
@@ -13,633 +13,343 @@ function warn(msg, ...args) {
|
|
|
13
13
|
console.warn(`[Vue warn] ${msg}`, ...args);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
this._isPaused = false;
|
|
37
|
-
this.parent = activeEffectScope;
|
|
38
|
-
if (!detached && activeEffectScope) {
|
|
39
|
-
this.index = (activeEffectScope.scopes || (activeEffectScope.scopes = [])).push(
|
|
40
|
-
this
|
|
41
|
-
) - 1;
|
|
42
|
-
}
|
|
16
|
+
var ReactiveFlags$1 = /* @__PURE__ */ ((ReactiveFlags2) => {
|
|
17
|
+
ReactiveFlags2[ReactiveFlags2["None"] = 0] = "None";
|
|
18
|
+
ReactiveFlags2[ReactiveFlags2["Mutable"] = 1] = "Mutable";
|
|
19
|
+
ReactiveFlags2[ReactiveFlags2["Watching"] = 2] = "Watching";
|
|
20
|
+
ReactiveFlags2[ReactiveFlags2["RecursedCheck"] = 4] = "RecursedCheck";
|
|
21
|
+
ReactiveFlags2[ReactiveFlags2["Recursed"] = 8] = "Recursed";
|
|
22
|
+
ReactiveFlags2[ReactiveFlags2["Dirty"] = 16] = "Dirty";
|
|
23
|
+
ReactiveFlags2[ReactiveFlags2["Pending"] = 32] = "Pending";
|
|
24
|
+
return ReactiveFlags2;
|
|
25
|
+
})(ReactiveFlags$1 || {});
|
|
26
|
+
const notifyBuffer = [];
|
|
27
|
+
let batchDepth = 0;
|
|
28
|
+
let activeSub = void 0;
|
|
29
|
+
let notifyIndex = 0;
|
|
30
|
+
let notifyBufferLength = 0;
|
|
31
|
+
function setActiveSub(sub) {
|
|
32
|
+
try {
|
|
33
|
+
return activeSub;
|
|
34
|
+
} finally {
|
|
35
|
+
activeSub = sub;
|
|
43
36
|
}
|
|
44
|
-
|
|
45
|
-
|
|
37
|
+
}
|
|
38
|
+
function startBatch() {
|
|
39
|
+
++batchDepth;
|
|
40
|
+
}
|
|
41
|
+
function endBatch() {
|
|
42
|
+
if (!--batchDepth && notifyBufferLength) {
|
|
43
|
+
flush();
|
|
46
44
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
for (i = 0, l = this.scopes.length; i < l; i++) {
|
|
53
|
-
this.scopes[i].pause();
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
for (i = 0, l = this.effects.length; i < l; i++) {
|
|
57
|
-
this.effects[i].pause();
|
|
58
|
-
}
|
|
59
|
-
}
|
|
45
|
+
}
|
|
46
|
+
function link(dep, sub) {
|
|
47
|
+
const prevDep = sub.depsTail;
|
|
48
|
+
if (prevDep !== void 0 && prevDep.dep === dep) {
|
|
49
|
+
return;
|
|
60
50
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
let i, l;
|
|
69
|
-
if (this.scopes) {
|
|
70
|
-
for (i = 0, l = this.scopes.length; i < l; i++) {
|
|
71
|
-
this.scopes[i].resume();
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
for (i = 0, l = this.effects.length; i < l; i++) {
|
|
75
|
-
this.effects[i].resume();
|
|
76
|
-
}
|
|
77
|
-
}
|
|
51
|
+
let nextDep = void 0;
|
|
52
|
+
const recursedCheck = sub.flags & 4 /* RecursedCheck */;
|
|
53
|
+
if (recursedCheck) {
|
|
54
|
+
nextDep = prevDep !== void 0 ? prevDep.nextDep : sub.deps;
|
|
55
|
+
if (nextDep !== void 0 && nextDep.dep === dep) {
|
|
56
|
+
sub.depsTail = nextDep;
|
|
57
|
+
return;
|
|
78
58
|
}
|
|
79
59
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
60
|
+
const prevSub = dep.subsTail;
|
|
61
|
+
const newLink = sub.depsTail = dep.subsTail = {
|
|
62
|
+
dep,
|
|
63
|
+
sub,
|
|
64
|
+
prevDep,
|
|
65
|
+
nextDep,
|
|
66
|
+
prevSub,
|
|
67
|
+
nextSub: void 0
|
|
68
|
+
};
|
|
69
|
+
if (nextDep !== void 0) {
|
|
70
|
+
nextDep.prevDep = newLink;
|
|
92
71
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
on() {
|
|
98
|
-
if (++this._on === 1) {
|
|
99
|
-
this.prevScope = activeEffectScope;
|
|
100
|
-
activeEffectScope = this;
|
|
101
|
-
}
|
|
72
|
+
if (prevDep !== void 0) {
|
|
73
|
+
prevDep.nextDep = newLink;
|
|
74
|
+
} else {
|
|
75
|
+
sub.deps = newLink;
|
|
102
76
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
off() {
|
|
108
|
-
if (this._on > 0 && --this._on === 0) {
|
|
109
|
-
activeEffectScope = this.prevScope;
|
|
110
|
-
this.prevScope = void 0;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
stop(fromParent) {
|
|
114
|
-
if (this._active) {
|
|
115
|
-
this._active = false;
|
|
116
|
-
let i, l;
|
|
117
|
-
for (i = 0, l = this.effects.length; i < l; i++) {
|
|
118
|
-
this.effects[i].stop();
|
|
119
|
-
}
|
|
120
|
-
this.effects.length = 0;
|
|
121
|
-
for (i = 0, l = this.cleanups.length; i < l; i++) {
|
|
122
|
-
this.cleanups[i]();
|
|
123
|
-
}
|
|
124
|
-
this.cleanups.length = 0;
|
|
125
|
-
if (this.scopes) {
|
|
126
|
-
for (i = 0, l = this.scopes.length; i < l; i++) {
|
|
127
|
-
this.scopes[i].stop(true);
|
|
128
|
-
}
|
|
129
|
-
this.scopes.length = 0;
|
|
130
|
-
}
|
|
131
|
-
if (!this.detached && this.parent && !fromParent) {
|
|
132
|
-
const last = this.parent.scopes.pop();
|
|
133
|
-
if (last && last !== this) {
|
|
134
|
-
this.parent.scopes[this.index] = last;
|
|
135
|
-
last.index = this.index;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
this.parent = void 0;
|
|
139
|
-
}
|
|
77
|
+
if (prevSub !== void 0) {
|
|
78
|
+
prevSub.nextSub = newLink;
|
|
79
|
+
} else {
|
|
80
|
+
dep.subs = newLink;
|
|
140
81
|
}
|
|
141
82
|
}
|
|
142
|
-
function
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
warn(
|
|
153
|
-
`onScopeDispose() is called when there is no active effect scope to be associated with.`
|
|
154
|
-
);
|
|
83
|
+
function unlink(link2, sub = link2.sub) {
|
|
84
|
+
const dep = link2.dep;
|
|
85
|
+
const prevDep = link2.prevDep;
|
|
86
|
+
const nextDep = link2.nextDep;
|
|
87
|
+
const nextSub = link2.nextSub;
|
|
88
|
+
const prevSub = link2.prevSub;
|
|
89
|
+
if (nextDep !== void 0) {
|
|
90
|
+
nextDep.prevDep = prevDep;
|
|
91
|
+
} else {
|
|
92
|
+
sub.depsTail = prevDep;
|
|
155
93
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
"ACTIVE": 1,
|
|
161
|
-
"1": "ACTIVE",
|
|
162
|
-
"RUNNING": 2,
|
|
163
|
-
"2": "RUNNING",
|
|
164
|
-
"TRACKING": 4,
|
|
165
|
-
"4": "TRACKING",
|
|
166
|
-
"NOTIFIED": 8,
|
|
167
|
-
"8": "NOTIFIED",
|
|
168
|
-
"DIRTY": 16,
|
|
169
|
-
"16": "DIRTY",
|
|
170
|
-
"ALLOW_RECURSE": 32,
|
|
171
|
-
"32": "ALLOW_RECURSE",
|
|
172
|
-
"PAUSED": 64,
|
|
173
|
-
"64": "PAUSED",
|
|
174
|
-
"EVALUATED": 128,
|
|
175
|
-
"128": "EVALUATED"
|
|
176
|
-
};
|
|
177
|
-
const pausedQueueEffects = /* @__PURE__ */ new WeakSet();
|
|
178
|
-
class ReactiveEffect {
|
|
179
|
-
constructor(fn) {
|
|
180
|
-
this.fn = fn;
|
|
181
|
-
/**
|
|
182
|
-
* @internal
|
|
183
|
-
*/
|
|
184
|
-
this.deps = void 0;
|
|
185
|
-
/**
|
|
186
|
-
* @internal
|
|
187
|
-
*/
|
|
188
|
-
this.depsTail = void 0;
|
|
189
|
-
/**
|
|
190
|
-
* @internal
|
|
191
|
-
*/
|
|
192
|
-
this.flags = 1 | 4;
|
|
193
|
-
/**
|
|
194
|
-
* @internal
|
|
195
|
-
*/
|
|
196
|
-
this.next = void 0;
|
|
197
|
-
/**
|
|
198
|
-
* @internal
|
|
199
|
-
*/
|
|
200
|
-
this.cleanup = void 0;
|
|
201
|
-
this.scheduler = void 0;
|
|
202
|
-
if (activeEffectScope && activeEffectScope.active) {
|
|
203
|
-
activeEffectScope.effects.push(this);
|
|
204
|
-
}
|
|
94
|
+
if (prevDep !== void 0) {
|
|
95
|
+
prevDep.nextDep = nextDep;
|
|
96
|
+
} else {
|
|
97
|
+
sub.deps = nextDep;
|
|
205
98
|
}
|
|
206
|
-
|
|
207
|
-
|
|
99
|
+
if (nextSub !== void 0) {
|
|
100
|
+
nextSub.prevSub = prevSub;
|
|
101
|
+
} else {
|
|
102
|
+
dep.subsTail = prevSub;
|
|
208
103
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
104
|
+
if (prevSub !== void 0) {
|
|
105
|
+
prevSub.nextSub = nextSub;
|
|
106
|
+
} else if ((dep.subs = nextSub) === void 0) {
|
|
107
|
+
let toRemove = dep.deps;
|
|
108
|
+
if (toRemove !== void 0) {
|
|
109
|
+
do {
|
|
110
|
+
toRemove = unlink(toRemove, dep);
|
|
111
|
+
} while (toRemove !== void 0);
|
|
112
|
+
dep.flags |= 16 /* Dirty */;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return nextDep;
|
|
116
|
+
}
|
|
117
|
+
function propagate(link2) {
|
|
118
|
+
let next = link2.nextSub;
|
|
119
|
+
let stack;
|
|
120
|
+
top: do {
|
|
121
|
+
const sub = link2.sub;
|
|
122
|
+
let flags = sub.flags;
|
|
123
|
+
if (flags & (1 /* Mutable */ | 2 /* Watching */)) {
|
|
124
|
+
if (!(flags & (4 /* RecursedCheck */ | 8 /* Recursed */ | 16 /* Dirty */ | 32 /* Pending */))) {
|
|
125
|
+
sub.flags = flags | 32 /* Pending */;
|
|
126
|
+
} else if (!(flags & (4 /* RecursedCheck */ | 8 /* Recursed */))) {
|
|
127
|
+
flags = 0 /* None */;
|
|
128
|
+
} else if (!(flags & 4 /* RecursedCheck */)) {
|
|
129
|
+
sub.flags = flags & -9 /* Recursed */ | 32 /* Pending */;
|
|
130
|
+
} else if (!(flags & (16 /* Dirty */ | 32 /* Pending */)) && isValidLink(link2, sub)) {
|
|
131
|
+
sub.flags = flags | 8 /* Recursed */ | 32 /* Pending */;
|
|
132
|
+
flags &= 1 /* Mutable */;
|
|
133
|
+
} else {
|
|
134
|
+
flags = 0 /* None */;
|
|
215
135
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* @internal
|
|
220
|
-
*/
|
|
221
|
-
notify() {
|
|
222
|
-
if (this.flags & 2 && !(this.flags & 32)) {
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
if (!(this.flags & 8)) {
|
|
226
|
-
batch(this);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
run() {
|
|
230
|
-
if (!(this.flags & 1)) {
|
|
231
|
-
return this.fn();
|
|
232
|
-
}
|
|
233
|
-
this.flags |= 2;
|
|
234
|
-
cleanupEffect(this);
|
|
235
|
-
prepareDeps(this);
|
|
236
|
-
const prevEffect = activeSub;
|
|
237
|
-
const prevShouldTrack = shouldTrack;
|
|
238
|
-
activeSub = this;
|
|
239
|
-
shouldTrack = true;
|
|
240
|
-
try {
|
|
241
|
-
return this.fn();
|
|
242
|
-
} finally {
|
|
243
|
-
if (activeSub !== this) {
|
|
244
|
-
warn(
|
|
245
|
-
"Active effect was not restored correctly - this is likely a Vue internal bug."
|
|
246
|
-
);
|
|
136
|
+
if (flags & 2 /* Watching */) {
|
|
137
|
+
notifyBuffer[notifyBufferLength++] = sub;
|
|
247
138
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
139
|
+
if (flags & 1 /* Mutable */) {
|
|
140
|
+
const subSubs = sub.subs;
|
|
141
|
+
if (subSubs !== void 0) {
|
|
142
|
+
link2 = subSubs;
|
|
143
|
+
if (subSubs.nextSub !== void 0) {
|
|
144
|
+
stack = { value: next, prev: stack };
|
|
145
|
+
next = link2.nextSub;
|
|
146
|
+
}
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
258
149
|
}
|
|
259
|
-
this.deps = this.depsTail = void 0;
|
|
260
|
-
cleanupEffect(this);
|
|
261
|
-
this.onStop && this.onStop();
|
|
262
|
-
this.flags &= -2;
|
|
263
150
|
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
pausedQueueEffects.add(this);
|
|
268
|
-
} else if (this.scheduler) {
|
|
269
|
-
this.scheduler();
|
|
270
|
-
} else {
|
|
271
|
-
this.runIfDirty();
|
|
151
|
+
if ((link2 = next) !== void 0) {
|
|
152
|
+
next = link2.nextSub;
|
|
153
|
+
continue;
|
|
272
154
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
155
|
+
while (stack !== void 0) {
|
|
156
|
+
link2 = stack.value;
|
|
157
|
+
stack = stack.prev;
|
|
158
|
+
if (link2 !== void 0) {
|
|
159
|
+
next = link2.nextSub;
|
|
160
|
+
continue top;
|
|
161
|
+
}
|
|
280
162
|
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
return isDirty(this);
|
|
284
|
-
}
|
|
163
|
+
break;
|
|
164
|
+
} while (true);
|
|
285
165
|
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
sub.flags |= 8;
|
|
291
|
-
if (isComputed) {
|
|
292
|
-
sub.next = batchedComputed;
|
|
293
|
-
batchedComputed = sub;
|
|
294
|
-
return;
|
|
295
|
-
}
|
|
296
|
-
sub.next = batchedSub;
|
|
297
|
-
batchedSub = sub;
|
|
298
|
-
}
|
|
299
|
-
function startBatch() {
|
|
300
|
-
batchDepth++;
|
|
166
|
+
function startTracking(sub) {
|
|
167
|
+
sub.depsTail = void 0;
|
|
168
|
+
sub.flags = sub.flags & -57 | 4 /* RecursedCheck */;
|
|
169
|
+
return setActiveSub(sub);
|
|
301
170
|
}
|
|
302
|
-
function
|
|
303
|
-
if (
|
|
304
|
-
|
|
171
|
+
function endTracking(sub, prevSub) {
|
|
172
|
+
if (activeSub !== sub) {
|
|
173
|
+
warn(
|
|
174
|
+
"Active effect was not restored correctly - this is likely a Vue internal bug."
|
|
175
|
+
);
|
|
305
176
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
177
|
+
activeSub = prevSub;
|
|
178
|
+
const depsTail = sub.depsTail;
|
|
179
|
+
let toRemove = depsTail !== void 0 ? depsTail.nextDep : sub.deps;
|
|
180
|
+
while (toRemove !== void 0) {
|
|
181
|
+
toRemove = unlink(toRemove, sub);
|
|
182
|
+
}
|
|
183
|
+
sub.flags &= -5 /* RecursedCheck */;
|
|
184
|
+
}
|
|
185
|
+
function flush() {
|
|
186
|
+
while (notifyIndex < notifyBufferLength) {
|
|
187
|
+
const effect = notifyBuffer[notifyIndex];
|
|
188
|
+
notifyBuffer[notifyIndex++] = void 0;
|
|
189
|
+
effect.notify();
|
|
190
|
+
}
|
|
191
|
+
notifyIndex = 0;
|
|
192
|
+
notifyBufferLength = 0;
|
|
193
|
+
}
|
|
194
|
+
function checkDirty(link2, sub) {
|
|
195
|
+
let stack;
|
|
196
|
+
let checkDepth = 0;
|
|
197
|
+
top: do {
|
|
198
|
+
const dep = link2.dep;
|
|
199
|
+
const depFlags = dep.flags;
|
|
200
|
+
let dirty = false;
|
|
201
|
+
if (sub.flags & 16 /* Dirty */) {
|
|
202
|
+
dirty = true;
|
|
203
|
+
} else if ((depFlags & (1 /* Mutable */ | 16 /* Dirty */)) === (1 /* Mutable */ | 16 /* Dirty */)) {
|
|
204
|
+
if (dep.update()) {
|
|
205
|
+
const subs = dep.subs;
|
|
206
|
+
if (subs.nextSub !== void 0) {
|
|
207
|
+
shallowPropagate(subs);
|
|
330
208
|
}
|
|
209
|
+
dirty = true;
|
|
331
210
|
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
211
|
+
} else if ((depFlags & (1 /* Mutable */ | 32 /* Pending */)) === (1 /* Mutable */ | 32 /* Pending */)) {
|
|
212
|
+
if (link2.nextSub !== void 0 || link2.prevSub !== void 0) {
|
|
213
|
+
stack = { value: link2, prev: stack };
|
|
214
|
+
}
|
|
215
|
+
link2 = dep.deps;
|
|
216
|
+
sub = dep;
|
|
217
|
+
++checkDepth;
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
if (!dirty && link2.nextDep !== void 0) {
|
|
221
|
+
link2 = link2.nextDep;
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
while (checkDepth) {
|
|
225
|
+
--checkDepth;
|
|
226
|
+
const firstSub = sub.subs;
|
|
227
|
+
const hasMultipleSubs = firstSub.nextSub !== void 0;
|
|
228
|
+
if (hasMultipleSubs) {
|
|
229
|
+
link2 = stack.value;
|
|
230
|
+
stack = stack.prev;
|
|
231
|
+
} else {
|
|
232
|
+
link2 = firstSub;
|
|
233
|
+
}
|
|
234
|
+
if (dirty) {
|
|
235
|
+
if (sub.update()) {
|
|
236
|
+
if (hasMultipleSubs) {
|
|
237
|
+
shallowPropagate(firstSub);
|
|
238
|
+
}
|
|
239
|
+
sub = link2.sub;
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
} else {
|
|
243
|
+
sub.flags &= -33 /* Pending */;
|
|
244
|
+
}
|
|
245
|
+
sub = link2.sub;
|
|
246
|
+
if (link2.nextDep !== void 0) {
|
|
247
|
+
link2 = link2.nextDep;
|
|
248
|
+
continue top;
|
|
249
|
+
}
|
|
250
|
+
dirty = false;
|
|
251
|
+
}
|
|
252
|
+
return dirty;
|
|
253
|
+
} while (true);
|
|
254
|
+
}
|
|
255
|
+
function shallowPropagate(link2) {
|
|
256
|
+
do {
|
|
257
|
+
const sub = link2.sub;
|
|
258
|
+
const nextSub = link2.nextSub;
|
|
259
|
+
const subFlags = sub.flags;
|
|
260
|
+
if ((subFlags & (32 /* Pending */ | 16 /* Dirty */)) === 32 /* Pending */) {
|
|
261
|
+
sub.flags = subFlags | 16 /* Dirty */;
|
|
262
|
+
}
|
|
263
|
+
link2 = nextSub;
|
|
264
|
+
} while (link2 !== void 0);
|
|
265
|
+
}
|
|
266
|
+
function isValidLink(checkLink, sub) {
|
|
267
|
+
const depsTail = sub.depsTail;
|
|
268
|
+
if (depsTail !== void 0) {
|
|
269
|
+
let link2 = sub.deps;
|
|
270
|
+
do {
|
|
271
|
+
if (link2 === checkLink) {
|
|
272
|
+
return true;
|
|
273
|
+
}
|
|
274
|
+
if (link2 === depsTail) {
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
277
|
+
link2 = link2.nextDep;
|
|
278
|
+
} while (link2 !== void 0);
|
|
342
279
|
}
|
|
280
|
+
return false;
|
|
343
281
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
}
|
|
357
|
-
link.dep.activeLink = link.prevActiveLink;
|
|
358
|
-
link.prevActiveLink = void 0;
|
|
359
|
-
link = prev;
|
|
282
|
+
|
|
283
|
+
const triggerEventInfos = [];
|
|
284
|
+
function onTrack(sub, debugInfo) {
|
|
285
|
+
if (sub.onTrack) {
|
|
286
|
+
sub.onTrack(
|
|
287
|
+
shared.extend(
|
|
288
|
+
{
|
|
289
|
+
effect: sub
|
|
290
|
+
},
|
|
291
|
+
debugInfo
|
|
292
|
+
)
|
|
293
|
+
);
|
|
360
294
|
}
|
|
361
|
-
sub.deps = head;
|
|
362
|
-
sub.depsTail = tail;
|
|
363
295
|
}
|
|
364
|
-
function
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
296
|
+
function onTrigger(sub) {
|
|
297
|
+
if (sub.onTrigger) {
|
|
298
|
+
const debugInfo = triggerEventInfos[triggerEventInfos.length - 1];
|
|
299
|
+
sub.onTrigger(
|
|
300
|
+
shared.extend(
|
|
301
|
+
{
|
|
302
|
+
effect: sub
|
|
303
|
+
},
|
|
304
|
+
debugInfo
|
|
305
|
+
)
|
|
306
|
+
);
|
|
372
307
|
}
|
|
373
|
-
return false;
|
|
374
308
|
}
|
|
375
|
-
function
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
computed.globalVersion = globalVersion;
|
|
384
|
-
if (!computed.isSSR && computed.flags & 128 && (!computed.deps && !computed._dirty || !isDirty(computed))) {
|
|
385
|
-
return;
|
|
386
|
-
}
|
|
387
|
-
computed.flags |= 2;
|
|
388
|
-
const dep = computed.dep;
|
|
389
|
-
const prevSub = activeSub;
|
|
390
|
-
const prevShouldTrack = shouldTrack;
|
|
391
|
-
activeSub = computed;
|
|
392
|
-
shouldTrack = true;
|
|
393
|
-
try {
|
|
394
|
-
prepareDeps(computed);
|
|
395
|
-
const value = computed.fn(computed._value);
|
|
396
|
-
if (dep.version === 0 || shared.hasChanged(value, computed._value)) {
|
|
397
|
-
computed.flags |= 128;
|
|
398
|
-
computed._value = value;
|
|
399
|
-
dep.version++;
|
|
309
|
+
function setupOnTrigger(target) {
|
|
310
|
+
Object.defineProperty(target.prototype, "onTrigger", {
|
|
311
|
+
get() {
|
|
312
|
+
return this._onTrigger;
|
|
313
|
+
},
|
|
314
|
+
set(val) {
|
|
315
|
+
if (val && !this._onTrigger) setupFlagsHandler(this);
|
|
316
|
+
this._onTrigger = val;
|
|
400
317
|
}
|
|
401
|
-
}
|
|
402
|
-
dep.version++;
|
|
403
|
-
throw err;
|
|
404
|
-
} finally {
|
|
405
|
-
activeSub = prevSub;
|
|
406
|
-
shouldTrack = prevShouldTrack;
|
|
407
|
-
cleanupDeps(computed);
|
|
408
|
-
computed.flags &= -3;
|
|
409
|
-
}
|
|
318
|
+
});
|
|
410
319
|
}
|
|
411
|
-
function
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
}
|
|
421
|
-
if (dep.subsHead === link) {
|
|
422
|
-
dep.subsHead = nextSub;
|
|
423
|
-
}
|
|
424
|
-
if (dep.subs === link) {
|
|
425
|
-
dep.subs = prevSub;
|
|
426
|
-
if (!prevSub && dep.computed) {
|
|
427
|
-
dep.computed.flags &= -5;
|
|
428
|
-
for (let l = dep.computed.deps; l; l = l.nextDep) {
|
|
429
|
-
removeSub(l, true);
|
|
320
|
+
function setupFlagsHandler(target) {
|
|
321
|
+
target._flags = target.flags;
|
|
322
|
+
Object.defineProperty(target, "flags", {
|
|
323
|
+
get() {
|
|
324
|
+
return target._flags;
|
|
325
|
+
},
|
|
326
|
+
set(value) {
|
|
327
|
+
if (!(target._flags & (ReactiveFlags$1.Dirty | ReactiveFlags$1.Pending)) && !!(value & (ReactiveFlags$1.Dirty | ReactiveFlags$1.Pending))) {
|
|
328
|
+
onTrigger(this);
|
|
430
329
|
}
|
|
330
|
+
target._flags = value;
|
|
431
331
|
}
|
|
432
|
-
}
|
|
433
|
-
if (!soft && !--dep.sc && dep.map) {
|
|
434
|
-
dep.map.delete(dep.key);
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
function removeDep(link) {
|
|
438
|
-
const { prevDep, nextDep } = link;
|
|
439
|
-
if (prevDep) {
|
|
440
|
-
prevDep.nextDep = nextDep;
|
|
441
|
-
link.prevDep = void 0;
|
|
442
|
-
}
|
|
443
|
-
if (nextDep) {
|
|
444
|
-
nextDep.prevDep = prevDep;
|
|
445
|
-
link.nextDep = void 0;
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
function effect(fn, options) {
|
|
449
|
-
if (fn.effect instanceof ReactiveEffect) {
|
|
450
|
-
fn = fn.effect.fn;
|
|
451
|
-
}
|
|
452
|
-
const e = new ReactiveEffect(fn);
|
|
453
|
-
if (options) {
|
|
454
|
-
shared.extend(e, options);
|
|
455
|
-
}
|
|
456
|
-
try {
|
|
457
|
-
e.run();
|
|
458
|
-
} catch (err) {
|
|
459
|
-
e.stop();
|
|
460
|
-
throw err;
|
|
461
|
-
}
|
|
462
|
-
const runner = e.run.bind(e);
|
|
463
|
-
runner.effect = e;
|
|
464
|
-
return runner;
|
|
465
|
-
}
|
|
466
|
-
function stop(runner) {
|
|
467
|
-
runner.effect.stop();
|
|
468
|
-
}
|
|
469
|
-
let shouldTrack = true;
|
|
470
|
-
const trackStack = [];
|
|
471
|
-
function pauseTracking() {
|
|
472
|
-
trackStack.push(shouldTrack);
|
|
473
|
-
shouldTrack = false;
|
|
474
|
-
}
|
|
475
|
-
function enableTracking() {
|
|
476
|
-
trackStack.push(shouldTrack);
|
|
477
|
-
shouldTrack = true;
|
|
478
|
-
}
|
|
479
|
-
function resetTracking() {
|
|
480
|
-
const last = trackStack.pop();
|
|
481
|
-
shouldTrack = last === void 0 ? true : last;
|
|
482
|
-
}
|
|
483
|
-
function onEffectCleanup(fn, failSilently = false) {
|
|
484
|
-
if (activeSub instanceof ReactiveEffect) {
|
|
485
|
-
activeSub.cleanup = fn;
|
|
486
|
-
} else if (!failSilently) {
|
|
487
|
-
warn(
|
|
488
|
-
`onEffectCleanup() was called when there was no active effect to associate with.`
|
|
489
|
-
);
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
function cleanupEffect(e) {
|
|
493
|
-
const { cleanup } = e;
|
|
494
|
-
e.cleanup = void 0;
|
|
495
|
-
if (cleanup) {
|
|
496
|
-
const prevSub = activeSub;
|
|
497
|
-
activeSub = void 0;
|
|
498
|
-
try {
|
|
499
|
-
cleanup();
|
|
500
|
-
} finally {
|
|
501
|
-
activeSub = prevSub;
|
|
502
|
-
}
|
|
503
|
-
}
|
|
332
|
+
});
|
|
504
333
|
}
|
|
505
334
|
|
|
506
|
-
let globalVersion = 0;
|
|
507
|
-
class Link {
|
|
508
|
-
constructor(sub, dep) {
|
|
509
|
-
this.sub = sub;
|
|
510
|
-
this.dep = dep;
|
|
511
|
-
this.version = dep.version;
|
|
512
|
-
this.nextDep = this.prevDep = this.nextSub = this.prevSub = this.prevActiveLink = void 0;
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
335
|
class Dep {
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
this.
|
|
519
|
-
this.
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
*/
|
|
523
|
-
this.activeLink = void 0;
|
|
524
|
-
/**
|
|
525
|
-
* Doubly linked list representing the subscribing effects (tail)
|
|
526
|
-
*/
|
|
527
|
-
this.subs = void 0;
|
|
528
|
-
/**
|
|
529
|
-
* For object property deps cleanup
|
|
530
|
-
*/
|
|
531
|
-
this.map = void 0;
|
|
532
|
-
this.key = void 0;
|
|
533
|
-
/**
|
|
534
|
-
* Subscriber counter
|
|
535
|
-
*/
|
|
536
|
-
this.sc = 0;
|
|
537
|
-
/**
|
|
538
|
-
* @internal
|
|
539
|
-
*/
|
|
540
|
-
this.__v_skip = true;
|
|
541
|
-
{
|
|
542
|
-
this.subsHead = void 0;
|
|
543
|
-
}
|
|
336
|
+
constructor(map, key) {
|
|
337
|
+
this.map = map;
|
|
338
|
+
this.key = key;
|
|
339
|
+
this._subs = void 0;
|
|
340
|
+
this.subsTail = void 0;
|
|
341
|
+
this.flags = ReactiveFlags$1.None;
|
|
544
342
|
}
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
return;
|
|
548
|
-
}
|
|
549
|
-
let link = this.activeLink;
|
|
550
|
-
if (link === void 0 || link.sub !== activeSub) {
|
|
551
|
-
link = this.activeLink = new Link(activeSub, this);
|
|
552
|
-
if (!activeSub.deps) {
|
|
553
|
-
activeSub.deps = activeSub.depsTail = link;
|
|
554
|
-
} else {
|
|
555
|
-
link.prevDep = activeSub.depsTail;
|
|
556
|
-
activeSub.depsTail.nextDep = link;
|
|
557
|
-
activeSub.depsTail = link;
|
|
558
|
-
}
|
|
559
|
-
addSub(link);
|
|
560
|
-
} else if (link.version === -1) {
|
|
561
|
-
link.version = this.version;
|
|
562
|
-
if (link.nextDep) {
|
|
563
|
-
const next = link.nextDep;
|
|
564
|
-
next.prevDep = link.prevDep;
|
|
565
|
-
if (link.prevDep) {
|
|
566
|
-
link.prevDep.nextDep = next;
|
|
567
|
-
}
|
|
568
|
-
link.prevDep = activeSub.depsTail;
|
|
569
|
-
link.nextDep = void 0;
|
|
570
|
-
activeSub.depsTail.nextDep = link;
|
|
571
|
-
activeSub.depsTail = link;
|
|
572
|
-
if (activeSub.deps === link) {
|
|
573
|
-
activeSub.deps = next;
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
if (activeSub.onTrack) {
|
|
578
|
-
activeSub.onTrack(
|
|
579
|
-
shared.extend(
|
|
580
|
-
{
|
|
581
|
-
effect: activeSub
|
|
582
|
-
},
|
|
583
|
-
debugInfo
|
|
584
|
-
)
|
|
585
|
-
);
|
|
586
|
-
}
|
|
587
|
-
return link;
|
|
588
|
-
}
|
|
589
|
-
trigger(debugInfo) {
|
|
590
|
-
this.version++;
|
|
591
|
-
globalVersion++;
|
|
592
|
-
this.notify(debugInfo);
|
|
343
|
+
get subs() {
|
|
344
|
+
return this._subs;
|
|
593
345
|
}
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
for (let head = this.subsHead; head; head = head.nextSub) {
|
|
599
|
-
if (head.sub.onTrigger && !(head.sub.flags & 8)) {
|
|
600
|
-
head.sub.onTrigger(
|
|
601
|
-
shared.extend(
|
|
602
|
-
{
|
|
603
|
-
effect: head.sub
|
|
604
|
-
},
|
|
605
|
-
debugInfo
|
|
606
|
-
)
|
|
607
|
-
);
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
for (let link = this.subs; link; link = link.prevSub) {
|
|
612
|
-
if (link.sub.notify()) {
|
|
613
|
-
;
|
|
614
|
-
link.sub.dep.notify();
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
} finally {
|
|
618
|
-
endBatch();
|
|
346
|
+
set subs(value) {
|
|
347
|
+
this._subs = value;
|
|
348
|
+
if (value === void 0) {
|
|
349
|
+
this.map.delete(this.key);
|
|
619
350
|
}
|
|
620
351
|
}
|
|
621
352
|
}
|
|
622
|
-
function addSub(link) {
|
|
623
|
-
link.dep.sc++;
|
|
624
|
-
if (link.sub.flags & 4) {
|
|
625
|
-
const computed = link.dep.computed;
|
|
626
|
-
if (computed && !link.dep.subs) {
|
|
627
|
-
computed.flags |= 4 | 16;
|
|
628
|
-
for (let l = computed.deps; l; l = l.nextDep) {
|
|
629
|
-
addSub(l);
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
const currentTail = link.dep.subs;
|
|
633
|
-
if (currentTail !== link) {
|
|
634
|
-
link.prevSub = currentTail;
|
|
635
|
-
if (currentTail) currentTail.nextSub = link;
|
|
636
|
-
}
|
|
637
|
-
if (link.dep.subsHead === void 0) {
|
|
638
|
-
link.dep.subsHead = link;
|
|
639
|
-
}
|
|
640
|
-
link.dep.subs = link;
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
353
|
const targetMap = /* @__PURE__ */ new WeakMap();
|
|
644
354
|
const ITERATE_KEY = Symbol(
|
|
645
355
|
"Object iterate"
|
|
@@ -651,36 +361,34 @@ const ARRAY_ITERATE_KEY = Symbol(
|
|
|
651
361
|
"Array iterate"
|
|
652
362
|
);
|
|
653
363
|
function track(target, type, key) {
|
|
654
|
-
if (
|
|
364
|
+
if (activeSub !== void 0) {
|
|
655
365
|
let depsMap = targetMap.get(target);
|
|
656
366
|
if (!depsMap) {
|
|
657
367
|
targetMap.set(target, depsMap = /* @__PURE__ */ new Map());
|
|
658
368
|
}
|
|
659
369
|
let dep = depsMap.get(key);
|
|
660
370
|
if (!dep) {
|
|
661
|
-
depsMap.set(key, dep = new Dep());
|
|
662
|
-
dep.map = depsMap;
|
|
663
|
-
dep.key = key;
|
|
371
|
+
depsMap.set(key, dep = new Dep(depsMap, key));
|
|
664
372
|
}
|
|
665
373
|
{
|
|
666
|
-
|
|
374
|
+
onTrack(activeSub, {
|
|
667
375
|
target,
|
|
668
376
|
type,
|
|
669
377
|
key
|
|
670
378
|
});
|
|
671
379
|
}
|
|
380
|
+
link(dep, activeSub);
|
|
672
381
|
}
|
|
673
382
|
}
|
|
674
383
|
function trigger(target, type, key, newValue, oldValue, oldTarget) {
|
|
675
384
|
const depsMap = targetMap.get(target);
|
|
676
385
|
if (!depsMap) {
|
|
677
|
-
globalVersion++;
|
|
678
386
|
return;
|
|
679
387
|
}
|
|
680
388
|
const run = (dep) => {
|
|
681
|
-
if (dep) {
|
|
389
|
+
if (dep !== void 0 && dep.subs !== void 0) {
|
|
682
390
|
{
|
|
683
|
-
|
|
391
|
+
triggerEventInfos.push({
|
|
684
392
|
target,
|
|
685
393
|
type,
|
|
686
394
|
key,
|
|
@@ -689,6 +397,11 @@ function trigger(target, type, key, newValue, oldValue, oldTarget) {
|
|
|
689
397
|
oldTarget
|
|
690
398
|
});
|
|
691
399
|
}
|
|
400
|
+
propagate(dep.subs);
|
|
401
|
+
shallowPropagate(dep.subs);
|
|
402
|
+
{
|
|
403
|
+
triggerEventInfos.pop();
|
|
404
|
+
}
|
|
692
405
|
}
|
|
693
406
|
};
|
|
694
407
|
startBatch();
|
|
@@ -913,11 +626,11 @@ function searchProxy(self, method, args) {
|
|
|
913
626
|
return res;
|
|
914
627
|
}
|
|
915
628
|
function noTracking(self, method, args = []) {
|
|
916
|
-
pauseTracking();
|
|
917
629
|
startBatch();
|
|
630
|
+
const prevSub = setActiveSub();
|
|
918
631
|
const res = toRaw(self)[method].apply(self, args);
|
|
632
|
+
setActiveSub(prevSub);
|
|
919
633
|
endBatch();
|
|
920
|
-
resetTracking();
|
|
921
634
|
return res;
|
|
922
635
|
}
|
|
923
636
|
|
|
@@ -963,14 +676,18 @@ class BaseReactiveHandler {
|
|
|
963
676
|
return hasOwnProperty;
|
|
964
677
|
}
|
|
965
678
|
}
|
|
679
|
+
const wasRef = isRef(target);
|
|
966
680
|
const res = Reflect.get(
|
|
967
681
|
target,
|
|
968
682
|
key,
|
|
969
683
|
// if this is a proxy wrapping a ref, return methods using the raw ref
|
|
970
684
|
// as receiver so that we don't have to call `toRaw` on the ref in all
|
|
971
685
|
// its class methods
|
|
972
|
-
|
|
686
|
+
wasRef ? target : receiver
|
|
973
687
|
);
|
|
688
|
+
if (wasRef && key !== "value") {
|
|
689
|
+
return res;
|
|
690
|
+
}
|
|
974
691
|
if (shared.isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) {
|
|
975
692
|
return res;
|
|
976
693
|
}
|
|
@@ -1422,33 +1139,47 @@ function isRef(r) {
|
|
|
1422
1139
|
return r ? r["__v_isRef"] === true : false;
|
|
1423
1140
|
}
|
|
1424
1141
|
function ref(value) {
|
|
1425
|
-
return createRef(value,
|
|
1142
|
+
return createRef(value, toReactive);
|
|
1426
1143
|
}
|
|
1427
1144
|
function shallowRef(value) {
|
|
1428
|
-
return createRef(value
|
|
1145
|
+
return createRef(value);
|
|
1429
1146
|
}
|
|
1430
|
-
function createRef(rawValue,
|
|
1147
|
+
function createRef(rawValue, wrap) {
|
|
1431
1148
|
if (isRef(rawValue)) {
|
|
1432
1149
|
return rawValue;
|
|
1433
1150
|
}
|
|
1434
|
-
return new RefImpl(rawValue,
|
|
1151
|
+
return new RefImpl(rawValue, wrap);
|
|
1435
1152
|
}
|
|
1436
1153
|
class RefImpl {
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
this
|
|
1440
|
-
this
|
|
1441
|
-
this.
|
|
1442
|
-
|
|
1443
|
-
|
|
1154
|
+
// TODO isolatedDeclarations "__v_isShallow"
|
|
1155
|
+
constructor(value, wrap) {
|
|
1156
|
+
this.subs = void 0;
|
|
1157
|
+
this.subsTail = void 0;
|
|
1158
|
+
this.flags = ReactiveFlags$1.Mutable;
|
|
1159
|
+
/**
|
|
1160
|
+
* @internal
|
|
1161
|
+
*/
|
|
1162
|
+
this.__v_isRef = true;
|
|
1163
|
+
// TODO isolatedDeclarations "__v_isRef"
|
|
1164
|
+
/**
|
|
1165
|
+
* @internal
|
|
1166
|
+
*/
|
|
1167
|
+
this.__v_isShallow = false;
|
|
1168
|
+
this._oldValue = this._rawValue = wrap ? toRaw(value) : value;
|
|
1169
|
+
this._value = wrap ? wrap(value) : value;
|
|
1170
|
+
this._wrap = wrap;
|
|
1171
|
+
this["__v_isShallow"] = !wrap;
|
|
1172
|
+
}
|
|
1173
|
+
get dep() {
|
|
1174
|
+
return this;
|
|
1444
1175
|
}
|
|
1445
1176
|
get value() {
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
}
|
|
1177
|
+
trackRef(this);
|
|
1178
|
+
if (this.flags & ReactiveFlags$1.Dirty && this.update()) {
|
|
1179
|
+
const subs = this.subs;
|
|
1180
|
+
if (subs !== void 0) {
|
|
1181
|
+
shallowPropagate(subs);
|
|
1182
|
+
}
|
|
1452
1183
|
}
|
|
1453
1184
|
return this._value;
|
|
1454
1185
|
}
|
|
@@ -1457,191 +1188,539 @@ class RefImpl {
|
|
|
1457
1188
|
const useDirectValue = this["__v_isShallow"] || isShallow(newValue) || isReadonly(newValue);
|
|
1458
1189
|
newValue = useDirectValue ? newValue : toRaw(newValue);
|
|
1459
1190
|
if (shared.hasChanged(newValue, oldValue)) {
|
|
1191
|
+
this.flags |= ReactiveFlags$1.Dirty;
|
|
1460
1192
|
this._rawValue = newValue;
|
|
1461
|
-
this._value = useDirectValue ? newValue :
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1193
|
+
this._value = !useDirectValue && this._wrap ? this._wrap(newValue) : newValue;
|
|
1194
|
+
const subs = this.subs;
|
|
1195
|
+
if (subs !== void 0) {
|
|
1196
|
+
{
|
|
1197
|
+
triggerEventInfos.push({
|
|
1198
|
+
target: this,
|
|
1199
|
+
type: "set",
|
|
1200
|
+
key: "value",
|
|
1201
|
+
newValue,
|
|
1202
|
+
oldValue
|
|
1203
|
+
});
|
|
1204
|
+
}
|
|
1205
|
+
propagate(subs);
|
|
1206
|
+
if (!batchDepth) {
|
|
1207
|
+
flush();
|
|
1208
|
+
}
|
|
1209
|
+
{
|
|
1210
|
+
triggerEventInfos.pop();
|
|
1211
|
+
}
|
|
1470
1212
|
}
|
|
1471
1213
|
}
|
|
1472
1214
|
}
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1215
|
+
update() {
|
|
1216
|
+
this.flags &= ~ReactiveFlags$1.Dirty;
|
|
1217
|
+
return shared.hasChanged(this._oldValue, this._oldValue = this._rawValue);
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
function triggerRef(ref2) {
|
|
1221
|
+
const dep = ref2.dep;
|
|
1222
|
+
if (dep !== void 0 && dep.subs !== void 0) {
|
|
1223
|
+
propagate(dep.subs);
|
|
1224
|
+
shallowPropagate(dep.subs);
|
|
1225
|
+
if (!batchDepth) {
|
|
1226
|
+
flush();
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
function trackRef(dep) {
|
|
1231
|
+
if (activeSub !== void 0) {
|
|
1232
|
+
{
|
|
1233
|
+
onTrack(activeSub, {
|
|
1234
|
+
target: dep,
|
|
1235
|
+
type: "get",
|
|
1236
|
+
key: "value"
|
|
1237
|
+
});
|
|
1238
|
+
}
|
|
1239
|
+
link(dep, activeSub);
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
function unref(ref2) {
|
|
1243
|
+
return isRef(ref2) ? ref2.value : ref2;
|
|
1244
|
+
}
|
|
1245
|
+
function toValue(source) {
|
|
1246
|
+
return shared.isFunction(source) ? source() : unref(source);
|
|
1247
|
+
}
|
|
1248
|
+
const shallowUnwrapHandlers = {
|
|
1249
|
+
get: (target, key, receiver) => key === "__v_raw" ? target : unref(Reflect.get(target, key, receiver)),
|
|
1250
|
+
set: (target, key, value, receiver) => {
|
|
1251
|
+
const oldValue = target[key];
|
|
1252
|
+
if (isRef(oldValue) && !isRef(value)) {
|
|
1253
|
+
oldValue.value = value;
|
|
1254
|
+
return true;
|
|
1255
|
+
} else {
|
|
1256
|
+
return Reflect.set(target, key, value, receiver);
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
};
|
|
1260
|
+
function proxyRefs(objectWithRefs) {
|
|
1261
|
+
return isReactive(objectWithRefs) ? objectWithRefs : new Proxy(objectWithRefs, shallowUnwrapHandlers);
|
|
1262
|
+
}
|
|
1263
|
+
class CustomRefImpl {
|
|
1264
|
+
constructor(factory) {
|
|
1265
|
+
this.subs = void 0;
|
|
1266
|
+
this.subsTail = void 0;
|
|
1267
|
+
this.flags = ReactiveFlags$1.None;
|
|
1268
|
+
this["__v_isRef"] = true;
|
|
1269
|
+
this._value = void 0;
|
|
1270
|
+
const { get, set } = factory(
|
|
1271
|
+
() => trackRef(this),
|
|
1272
|
+
() => triggerRef(this)
|
|
1273
|
+
);
|
|
1274
|
+
this._get = get;
|
|
1275
|
+
this._set = set;
|
|
1276
|
+
}
|
|
1277
|
+
get dep() {
|
|
1278
|
+
return this;
|
|
1279
|
+
}
|
|
1280
|
+
get value() {
|
|
1281
|
+
return this._value = this._get();
|
|
1282
|
+
}
|
|
1283
|
+
set value(newVal) {
|
|
1284
|
+
this._set(newVal);
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
function customRef(factory) {
|
|
1288
|
+
return new CustomRefImpl(factory);
|
|
1289
|
+
}
|
|
1290
|
+
function toRefs(object) {
|
|
1291
|
+
const ret = shared.isArray(object) ? new Array(object.length) : {};
|
|
1292
|
+
for (const key in object) {
|
|
1293
|
+
ret[key] = propertyToRef(object, key);
|
|
1294
|
+
}
|
|
1295
|
+
return ret;
|
|
1296
|
+
}
|
|
1297
|
+
class ObjectRefImpl {
|
|
1298
|
+
constructor(_object, _key, _defaultValue) {
|
|
1299
|
+
this._object = _object;
|
|
1300
|
+
this._key = _key;
|
|
1301
|
+
this._defaultValue = _defaultValue;
|
|
1302
|
+
this["__v_isRef"] = true;
|
|
1303
|
+
this._value = void 0;
|
|
1304
|
+
}
|
|
1305
|
+
get value() {
|
|
1306
|
+
const val = this._object[this._key];
|
|
1307
|
+
return this._value = val === void 0 ? this._defaultValue : val;
|
|
1308
|
+
}
|
|
1309
|
+
set value(newVal) {
|
|
1310
|
+
this._object[this._key] = newVal;
|
|
1311
|
+
}
|
|
1312
|
+
get dep() {
|
|
1313
|
+
return getDepFromReactive(toRaw(this._object), this._key);
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
class GetterRefImpl {
|
|
1317
|
+
constructor(_getter) {
|
|
1318
|
+
this._getter = _getter;
|
|
1319
|
+
this["__v_isRef"] = true;
|
|
1320
|
+
this["__v_isReadonly"] = true;
|
|
1321
|
+
this._value = void 0;
|
|
1322
|
+
}
|
|
1323
|
+
get value() {
|
|
1324
|
+
return this._value = this._getter();
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
function toRef(source, key, defaultValue) {
|
|
1328
|
+
if (isRef(source)) {
|
|
1329
|
+
return source;
|
|
1330
|
+
} else if (shared.isFunction(source)) {
|
|
1331
|
+
return new GetterRefImpl(source);
|
|
1332
|
+
} else if (shared.isObject(source) && arguments.length > 1) {
|
|
1333
|
+
return propertyToRef(source, key, defaultValue);
|
|
1334
|
+
} else {
|
|
1335
|
+
return ref(source);
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
function propertyToRef(source, key, defaultValue) {
|
|
1339
|
+
const val = source[key];
|
|
1340
|
+
return isRef(val) ? val : new ObjectRefImpl(source, key, defaultValue);
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
const EffectFlags = {
|
|
1344
|
+
"ALLOW_RECURSE": 128,
|
|
1345
|
+
"128": "ALLOW_RECURSE",
|
|
1346
|
+
"PAUSED": 256,
|
|
1347
|
+
"256": "PAUSED",
|
|
1348
|
+
"STOP": 1024,
|
|
1349
|
+
"1024": "STOP"
|
|
1350
|
+
};
|
|
1351
|
+
class ReactiveEffect {
|
|
1352
|
+
constructor(fn) {
|
|
1353
|
+
this.deps = void 0;
|
|
1354
|
+
this.depsTail = void 0;
|
|
1355
|
+
this.subs = void 0;
|
|
1356
|
+
this.subsTail = void 0;
|
|
1357
|
+
this.flags = ReactiveFlags$1.Watching | ReactiveFlags$1.Dirty;
|
|
1358
|
+
/**
|
|
1359
|
+
* @internal
|
|
1360
|
+
*/
|
|
1361
|
+
this.cleanups = [];
|
|
1362
|
+
/**
|
|
1363
|
+
* @internal
|
|
1364
|
+
*/
|
|
1365
|
+
this.cleanupsLength = 0;
|
|
1366
|
+
if (fn !== void 0) {
|
|
1367
|
+
this.fn = fn;
|
|
1368
|
+
}
|
|
1369
|
+
if (activeEffectScope) {
|
|
1370
|
+
link(this, activeEffectScope);
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
// @ts-expect-error
|
|
1374
|
+
fn() {
|
|
1375
|
+
}
|
|
1376
|
+
get active() {
|
|
1377
|
+
return !(this.flags & 1024);
|
|
1378
|
+
}
|
|
1379
|
+
pause() {
|
|
1380
|
+
this.flags |= 256;
|
|
1381
|
+
}
|
|
1382
|
+
resume() {
|
|
1383
|
+
const flags = this.flags &= -257;
|
|
1384
|
+
if (flags & (ReactiveFlags$1.Dirty | ReactiveFlags$1.Pending)) {
|
|
1385
|
+
this.notify();
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
notify() {
|
|
1389
|
+
if (!(this.flags & 256) && this.dirty) {
|
|
1390
|
+
this.run();
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
run() {
|
|
1394
|
+
if (!this.active) {
|
|
1395
|
+
return this.fn();
|
|
1396
|
+
}
|
|
1397
|
+
cleanup(this);
|
|
1398
|
+
const prevSub = startTracking(this);
|
|
1399
|
+
try {
|
|
1400
|
+
return this.fn();
|
|
1401
|
+
} finally {
|
|
1402
|
+
endTracking(this, prevSub);
|
|
1403
|
+
const flags = this.flags;
|
|
1404
|
+
if ((flags & (ReactiveFlags$1.Recursed | 128)) === (ReactiveFlags$1.Recursed | 128)) {
|
|
1405
|
+
this.flags = flags & ~ReactiveFlags$1.Recursed;
|
|
1406
|
+
this.notify();
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
stop() {
|
|
1411
|
+
if (!this.active) {
|
|
1412
|
+
return;
|
|
1413
|
+
}
|
|
1414
|
+
this.flags = 1024;
|
|
1415
|
+
let dep = this.deps;
|
|
1416
|
+
while (dep !== void 0) {
|
|
1417
|
+
dep = unlink(dep, this);
|
|
1418
|
+
}
|
|
1419
|
+
const sub = this.subs;
|
|
1420
|
+
if (sub !== void 0) {
|
|
1421
|
+
unlink(sub);
|
|
1422
|
+
}
|
|
1423
|
+
cleanup(this);
|
|
1424
|
+
}
|
|
1425
|
+
get dirty() {
|
|
1426
|
+
const flags = this.flags;
|
|
1427
|
+
if (flags & ReactiveFlags$1.Dirty) {
|
|
1428
|
+
return true;
|
|
1429
|
+
}
|
|
1430
|
+
if (flags & ReactiveFlags$1.Pending) {
|
|
1431
|
+
if (checkDirty(this.deps, this)) {
|
|
1432
|
+
this.flags = flags | ReactiveFlags$1.Dirty;
|
|
1433
|
+
return true;
|
|
1434
|
+
} else {
|
|
1435
|
+
this.flags = flags & ~ReactiveFlags$1.Pending;
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
return false;
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
{
|
|
1442
|
+
setupOnTrigger(ReactiveEffect);
|
|
1443
|
+
}
|
|
1444
|
+
function effect(fn, options) {
|
|
1445
|
+
if (fn.effect instanceof ReactiveEffect) {
|
|
1446
|
+
fn = fn.effect.fn;
|
|
1447
|
+
}
|
|
1448
|
+
const e = new ReactiveEffect(fn);
|
|
1449
|
+
if (options) {
|
|
1450
|
+
const { onStop, scheduler } = options;
|
|
1451
|
+
if (onStop) {
|
|
1452
|
+
options.onStop = void 0;
|
|
1453
|
+
const stop2 = e.stop.bind(e);
|
|
1454
|
+
e.stop = () => {
|
|
1455
|
+
stop2();
|
|
1456
|
+
onStop();
|
|
1457
|
+
};
|
|
1458
|
+
}
|
|
1459
|
+
if (scheduler) {
|
|
1460
|
+
options.scheduler = void 0;
|
|
1461
|
+
e.notify = () => {
|
|
1462
|
+
if (!(e.flags & 256)) {
|
|
1463
|
+
scheduler();
|
|
1464
|
+
}
|
|
1465
|
+
};
|
|
1466
|
+
}
|
|
1467
|
+
shared.extend(e, options);
|
|
1468
|
+
}
|
|
1469
|
+
try {
|
|
1470
|
+
e.run();
|
|
1471
|
+
} catch (err) {
|
|
1472
|
+
e.stop();
|
|
1473
|
+
throw err;
|
|
1484
1474
|
}
|
|
1475
|
+
const runner = e.run.bind(e);
|
|
1476
|
+
runner.effect = e;
|
|
1477
|
+
return runner;
|
|
1485
1478
|
}
|
|
1486
|
-
function
|
|
1487
|
-
|
|
1479
|
+
function stop(runner) {
|
|
1480
|
+
runner.effect.stop();
|
|
1488
1481
|
}
|
|
1489
|
-
|
|
1490
|
-
|
|
1482
|
+
const resetTrackingStack = [];
|
|
1483
|
+
function pauseTracking() {
|
|
1484
|
+
resetTrackingStack.push(activeSub);
|
|
1485
|
+
setActiveSub();
|
|
1491
1486
|
}
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1487
|
+
function enableTracking() {
|
|
1488
|
+
const isPaused = activeSub === void 0;
|
|
1489
|
+
if (!isPaused) {
|
|
1490
|
+
resetTrackingStack.push(activeSub);
|
|
1491
|
+
} else {
|
|
1492
|
+
resetTrackingStack.push(void 0);
|
|
1493
|
+
for (let i = resetTrackingStack.length - 1; i >= 0; i--) {
|
|
1494
|
+
if (resetTrackingStack[i] !== void 0) {
|
|
1495
|
+
setActiveSub(resetTrackingStack[i]);
|
|
1496
|
+
break;
|
|
1497
|
+
}
|
|
1501
1498
|
}
|
|
1502
1499
|
}
|
|
1503
|
-
};
|
|
1504
|
-
function proxyRefs(objectWithRefs) {
|
|
1505
|
-
return isReactive(objectWithRefs) ? objectWithRefs : new Proxy(objectWithRefs, shallowUnwrapHandlers);
|
|
1506
1500
|
}
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
const { get, set } = factory(dep.track.bind(dep), dep.trigger.bind(dep));
|
|
1513
|
-
this._get = get;
|
|
1514
|
-
this._set = set;
|
|
1515
|
-
}
|
|
1516
|
-
get value() {
|
|
1517
|
-
return this._value = this._get();
|
|
1501
|
+
function resetTracking() {
|
|
1502
|
+
if (resetTrackingStack.length === 0) {
|
|
1503
|
+
warn(
|
|
1504
|
+
`resetTracking() was called when there was no active tracking to reset.`
|
|
1505
|
+
);
|
|
1518
1506
|
}
|
|
1519
|
-
|
|
1520
|
-
|
|
1507
|
+
if (resetTrackingStack.length) {
|
|
1508
|
+
setActiveSub(resetTrackingStack.pop());
|
|
1509
|
+
} else {
|
|
1510
|
+
setActiveSub();
|
|
1521
1511
|
}
|
|
1522
1512
|
}
|
|
1523
|
-
function
|
|
1524
|
-
|
|
1513
|
+
function cleanup(sub) {
|
|
1514
|
+
const l = sub.cleanupsLength;
|
|
1515
|
+
if (l) {
|
|
1516
|
+
for (let i = 0; i < l; i++) {
|
|
1517
|
+
sub.cleanups[i]();
|
|
1518
|
+
}
|
|
1519
|
+
sub.cleanupsLength = 0;
|
|
1520
|
+
}
|
|
1525
1521
|
}
|
|
1526
|
-
function
|
|
1527
|
-
if (
|
|
1528
|
-
|
|
1522
|
+
function onEffectCleanup(fn, failSilently = false) {
|
|
1523
|
+
if (activeSub instanceof ReactiveEffect) {
|
|
1524
|
+
activeSub.cleanups[activeSub.cleanupsLength++] = () => cleanupEffect(fn);
|
|
1525
|
+
} else if (!failSilently) {
|
|
1526
|
+
warn(
|
|
1527
|
+
`onEffectCleanup() was called when there was no active effect to associate with.`
|
|
1528
|
+
);
|
|
1529
1529
|
}
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1530
|
+
}
|
|
1531
|
+
function cleanupEffect(fn) {
|
|
1532
|
+
const prevSub = setActiveSub();
|
|
1533
|
+
try {
|
|
1534
|
+
fn();
|
|
1535
|
+
} finally {
|
|
1536
|
+
setActiveSub(prevSub);
|
|
1533
1537
|
}
|
|
1534
|
-
return ret;
|
|
1535
1538
|
}
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
this.
|
|
1541
|
-
this
|
|
1542
|
-
this.
|
|
1539
|
+
|
|
1540
|
+
let activeEffectScope;
|
|
1541
|
+
class EffectScope {
|
|
1542
|
+
constructor(detached = false) {
|
|
1543
|
+
this.deps = void 0;
|
|
1544
|
+
this.depsTail = void 0;
|
|
1545
|
+
this.subs = void 0;
|
|
1546
|
+
this.subsTail = void 0;
|
|
1547
|
+
this.flags = 0;
|
|
1548
|
+
/**
|
|
1549
|
+
* @internal
|
|
1550
|
+
*/
|
|
1551
|
+
this.cleanups = [];
|
|
1552
|
+
/**
|
|
1553
|
+
* @internal
|
|
1554
|
+
*/
|
|
1555
|
+
this.cleanupsLength = 0;
|
|
1556
|
+
if (!detached && activeEffectScope) {
|
|
1557
|
+
link(this, activeEffectScope);
|
|
1558
|
+
}
|
|
1543
1559
|
}
|
|
1544
|
-
get
|
|
1545
|
-
|
|
1546
|
-
return this._value = val === void 0 ? this._defaultValue : val;
|
|
1560
|
+
get active() {
|
|
1561
|
+
return !(this.flags & 1024);
|
|
1547
1562
|
}
|
|
1548
|
-
|
|
1549
|
-
this.
|
|
1563
|
+
pause() {
|
|
1564
|
+
if (!(this.flags & 256)) {
|
|
1565
|
+
this.flags |= 256;
|
|
1566
|
+
for (let link2 = this.deps; link2 !== void 0; link2 = link2.nextDep) {
|
|
1567
|
+
const dep = link2.dep;
|
|
1568
|
+
if ("pause" in dep) {
|
|
1569
|
+
dep.pause();
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1550
1573
|
}
|
|
1551
|
-
|
|
1552
|
-
|
|
1574
|
+
/**
|
|
1575
|
+
* Resumes the effect scope, including all child scopes and effects.
|
|
1576
|
+
*/
|
|
1577
|
+
resume() {
|
|
1578
|
+
const flags = this.flags;
|
|
1579
|
+
if (flags & 256) {
|
|
1580
|
+
this.flags = flags & -257;
|
|
1581
|
+
for (let link2 = this.deps; link2 !== void 0; link2 = link2.nextDep) {
|
|
1582
|
+
const dep = link2.dep;
|
|
1583
|
+
if ("resume" in dep) {
|
|
1584
|
+
dep.resume();
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1553
1588
|
}
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1589
|
+
run(fn) {
|
|
1590
|
+
const prevScope = activeEffectScope;
|
|
1591
|
+
try {
|
|
1592
|
+
activeEffectScope = this;
|
|
1593
|
+
return fn();
|
|
1594
|
+
} finally {
|
|
1595
|
+
activeEffectScope = prevScope;
|
|
1596
|
+
}
|
|
1561
1597
|
}
|
|
1562
|
-
|
|
1563
|
-
|
|
1598
|
+
stop() {
|
|
1599
|
+
if (!this.active) {
|
|
1600
|
+
return;
|
|
1601
|
+
}
|
|
1602
|
+
this.flags = 1024;
|
|
1603
|
+
let dep = this.deps;
|
|
1604
|
+
while (dep !== void 0) {
|
|
1605
|
+
const node = dep.dep;
|
|
1606
|
+
if ("stop" in node) {
|
|
1607
|
+
dep = dep.nextDep;
|
|
1608
|
+
node.stop();
|
|
1609
|
+
} else {
|
|
1610
|
+
dep = unlink(dep, this);
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
const sub = this.subs;
|
|
1614
|
+
if (sub !== void 0) {
|
|
1615
|
+
unlink(sub);
|
|
1616
|
+
}
|
|
1617
|
+
cleanup(this);
|
|
1564
1618
|
}
|
|
1565
1619
|
}
|
|
1566
|
-
function
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
return
|
|
1620
|
+
function effectScope(detached) {
|
|
1621
|
+
return new EffectScope(detached);
|
|
1622
|
+
}
|
|
1623
|
+
function getCurrentScope() {
|
|
1624
|
+
return activeEffectScope;
|
|
1625
|
+
}
|
|
1626
|
+
function setCurrentScope(scope) {
|
|
1627
|
+
try {
|
|
1628
|
+
return activeEffectScope;
|
|
1629
|
+
} finally {
|
|
1630
|
+
activeEffectScope = scope;
|
|
1575
1631
|
}
|
|
1576
1632
|
}
|
|
1577
|
-
function
|
|
1578
|
-
|
|
1579
|
-
|
|
1633
|
+
function onScopeDispose(fn, failSilently = false) {
|
|
1634
|
+
if (activeEffectScope !== void 0) {
|
|
1635
|
+
activeEffectScope.cleanups[activeEffectScope.cleanupsLength++] = fn;
|
|
1636
|
+
} else if (!failSilently) {
|
|
1637
|
+
warn(
|
|
1638
|
+
`onScopeDispose() is called when there is no active effect scope to be associated with.`
|
|
1639
|
+
);
|
|
1640
|
+
}
|
|
1580
1641
|
}
|
|
1581
1642
|
|
|
1582
1643
|
class ComputedRefImpl {
|
|
1583
|
-
constructor(fn, setter
|
|
1644
|
+
constructor(fn, setter) {
|
|
1584
1645
|
this.fn = fn;
|
|
1585
1646
|
this.setter = setter;
|
|
1586
1647
|
/**
|
|
1587
1648
|
* @internal
|
|
1588
1649
|
*/
|
|
1589
1650
|
this._value = void 0;
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
*/
|
|
1593
|
-
this.dep = new Dep(this);
|
|
1594
|
-
/**
|
|
1595
|
-
* @internal
|
|
1596
|
-
*/
|
|
1597
|
-
this.__v_isRef = true;
|
|
1598
|
-
// TODO isolatedDeclarations "__v_isReadonly"
|
|
1599
|
-
// A computed is also a subscriber that tracks other deps
|
|
1600
|
-
/**
|
|
1601
|
-
* @internal
|
|
1602
|
-
*/
|
|
1651
|
+
this.subs = void 0;
|
|
1652
|
+
this.subsTail = void 0;
|
|
1603
1653
|
this.deps = void 0;
|
|
1604
|
-
/**
|
|
1605
|
-
* @internal
|
|
1606
|
-
*/
|
|
1607
1654
|
this.depsTail = void 0;
|
|
1655
|
+
this.flags = ReactiveFlags$1.Mutable | ReactiveFlags$1.Dirty;
|
|
1608
1656
|
/**
|
|
1609
1657
|
* @internal
|
|
1610
1658
|
*/
|
|
1611
|
-
this.
|
|
1612
|
-
/**
|
|
1613
|
-
* @internal
|
|
1614
|
-
*/
|
|
1615
|
-
this.globalVersion = globalVersion - 1;
|
|
1616
|
-
/**
|
|
1617
|
-
* @internal
|
|
1618
|
-
*/
|
|
1619
|
-
this.next = void 0;
|
|
1620
|
-
// for backwards compat
|
|
1621
|
-
this.effect = this;
|
|
1659
|
+
this.__v_isRef = true;
|
|
1622
1660
|
this["__v_isReadonly"] = !setter;
|
|
1623
|
-
|
|
1661
|
+
}
|
|
1662
|
+
// TODO isolatedDeclarations "__v_isReadonly"
|
|
1663
|
+
// for backwards compat
|
|
1664
|
+
get effect() {
|
|
1665
|
+
return this;
|
|
1666
|
+
}
|
|
1667
|
+
// for backwards compat
|
|
1668
|
+
get dep() {
|
|
1669
|
+
return this;
|
|
1624
1670
|
}
|
|
1625
1671
|
/**
|
|
1626
1672
|
* @internal
|
|
1673
|
+
* for backwards compat
|
|
1627
1674
|
*/
|
|
1628
|
-
|
|
1629
|
-
this.flags
|
|
1630
|
-
if (
|
|
1631
|
-
activeSub !== this) {
|
|
1632
|
-
batch(this, true);
|
|
1675
|
+
get _dirty() {
|
|
1676
|
+
const flags = this.flags;
|
|
1677
|
+
if (flags & ReactiveFlags$1.Dirty) {
|
|
1633
1678
|
return true;
|
|
1634
1679
|
}
|
|
1680
|
+
if (flags & ReactiveFlags$1.Pending) {
|
|
1681
|
+
if (checkDirty(this.deps, this)) {
|
|
1682
|
+
this.flags = flags | ReactiveFlags$1.Dirty;
|
|
1683
|
+
return true;
|
|
1684
|
+
} else {
|
|
1685
|
+
this.flags = flags & ~ReactiveFlags$1.Pending;
|
|
1686
|
+
}
|
|
1687
|
+
}
|
|
1688
|
+
return false;
|
|
1689
|
+
}
|
|
1690
|
+
/**
|
|
1691
|
+
* @internal
|
|
1692
|
+
* for backwards compat
|
|
1693
|
+
*/
|
|
1694
|
+
set _dirty(v) {
|
|
1695
|
+
if (v) {
|
|
1696
|
+
this.flags |= ReactiveFlags$1.Dirty;
|
|
1697
|
+
} else {
|
|
1698
|
+
this.flags &= ~(ReactiveFlags$1.Dirty | ReactiveFlags$1.Pending);
|
|
1699
|
+
}
|
|
1635
1700
|
}
|
|
1636
1701
|
get value() {
|
|
1637
|
-
const
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1702
|
+
const flags = this.flags;
|
|
1703
|
+
if (flags & ReactiveFlags$1.Dirty || flags & ReactiveFlags$1.Pending && checkDirty(this.deps, this)) {
|
|
1704
|
+
if (this.update()) {
|
|
1705
|
+
const subs = this.subs;
|
|
1706
|
+
if (subs !== void 0) {
|
|
1707
|
+
shallowPropagate(subs);
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
} else if (flags & ReactiveFlags$1.Pending) {
|
|
1711
|
+
this.flags = flags & ~ReactiveFlags$1.Pending;
|
|
1712
|
+
}
|
|
1713
|
+
if (activeSub !== void 0) {
|
|
1714
|
+
{
|
|
1715
|
+
onTrack(activeSub, {
|
|
1716
|
+
target: this,
|
|
1717
|
+
type: "get",
|
|
1718
|
+
key: "value"
|
|
1719
|
+
});
|
|
1720
|
+
}
|
|
1721
|
+
link(this, activeSub);
|
|
1722
|
+
} else if (activeEffectScope !== void 0) {
|
|
1723
|
+
link(this, activeEffectScope);
|
|
1645
1724
|
}
|
|
1646
1725
|
return this._value;
|
|
1647
1726
|
}
|
|
@@ -1652,6 +1731,23 @@ class ComputedRefImpl {
|
|
|
1652
1731
|
warn("Write operation failed: computed value is readonly");
|
|
1653
1732
|
}
|
|
1654
1733
|
}
|
|
1734
|
+
update() {
|
|
1735
|
+
const prevSub = startTracking(this);
|
|
1736
|
+
try {
|
|
1737
|
+
const oldValue = this._value;
|
|
1738
|
+
const newValue = this.fn(oldValue);
|
|
1739
|
+
if (shared.hasChanged(oldValue, newValue)) {
|
|
1740
|
+
this._value = newValue;
|
|
1741
|
+
return true;
|
|
1742
|
+
}
|
|
1743
|
+
return false;
|
|
1744
|
+
} finally {
|
|
1745
|
+
endTracking(this, prevSub);
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
}
|
|
1749
|
+
{
|
|
1750
|
+
setupOnTrigger(ComputedRefImpl);
|
|
1655
1751
|
}
|
|
1656
1752
|
function computed(getterOrOptions, debugOptions, isSSR = false) {
|
|
1657
1753
|
let getter;
|
|
@@ -1662,7 +1758,7 @@ function computed(getterOrOptions, debugOptions, isSSR = false) {
|
|
|
1662
1758
|
getter = getterOrOptions.get;
|
|
1663
1759
|
setter = getterOrOptions.set;
|
|
1664
1760
|
}
|
|
1665
|
-
const cRef = new ComputedRefImpl(getter, setter
|
|
1761
|
+
const cRef = new ComputedRefImpl(getter, setter);
|
|
1666
1762
|
if (debugOptions && !isSSR) {
|
|
1667
1763
|
cRef.onTrack = debugOptions.onTrack;
|
|
1668
1764
|
cRef.onTrigger = debugOptions.onTrigger;
|
|
@@ -1699,177 +1795,155 @@ const WatchErrorCodes = {
|
|
|
1699
1795
|
"4": "WATCH_CLEANUP"
|
|
1700
1796
|
};
|
|
1701
1797
|
const INITIAL_WATCHER_VALUE = {};
|
|
1702
|
-
const cleanupMap = /* @__PURE__ */ new WeakMap();
|
|
1703
1798
|
let activeWatcher = void 0;
|
|
1704
1799
|
function getCurrentWatcher() {
|
|
1705
1800
|
return activeWatcher;
|
|
1706
1801
|
}
|
|
1707
1802
|
function onWatcherCleanup(cleanupFn, failSilently = false, owner = activeWatcher) {
|
|
1708
1803
|
if (owner) {
|
|
1709
|
-
|
|
1710
|
-
if (
|
|
1711
|
-
|
|
1804
|
+
const { call } = owner.options;
|
|
1805
|
+
if (call) {
|
|
1806
|
+
owner.cleanups[owner.cleanupsLength++] = () => call(cleanupFn, 4);
|
|
1807
|
+
} else {
|
|
1808
|
+
owner.cleanups[owner.cleanupsLength++] = cleanupFn;
|
|
1809
|
+
}
|
|
1712
1810
|
} else if (!failSilently) {
|
|
1713
1811
|
warn(
|
|
1714
1812
|
`onWatcherCleanup() was called when there was no active watcher to associate with.`
|
|
1715
1813
|
);
|
|
1716
1814
|
}
|
|
1717
1815
|
}
|
|
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
|
-
forceTrigger = source.some((s) => isReactive(s) || isShallow(s));
|
|
1748
|
-
getter = () => source.map((s) => {
|
|
1749
|
-
if (isRef(s)) {
|
|
1750
|
-
return s.value;
|
|
1751
|
-
} else if (isReactive(s)) {
|
|
1752
|
-
return reactiveGetter(s);
|
|
1753
|
-
} else if (shared.isFunction(s)) {
|
|
1754
|
-
return call ? call(s, 2) : s();
|
|
1816
|
+
class WatcherEffect extends ReactiveEffect {
|
|
1817
|
+
constructor(source, cb, options = shared.EMPTY_OBJ) {
|
|
1818
|
+
const { deep, once, call, onWarn } = options;
|
|
1819
|
+
let getter;
|
|
1820
|
+
let forceTrigger = false;
|
|
1821
|
+
let isMultiSource = false;
|
|
1822
|
+
if (isRef(source)) {
|
|
1823
|
+
getter = () => source.value;
|
|
1824
|
+
forceTrigger = isShallow(source);
|
|
1825
|
+
} else if (isReactive(source)) {
|
|
1826
|
+
getter = () => reactiveGetter(source, deep);
|
|
1827
|
+
forceTrigger = true;
|
|
1828
|
+
} else if (shared.isArray(source)) {
|
|
1829
|
+
isMultiSource = true;
|
|
1830
|
+
forceTrigger = source.some((s) => isReactive(s) || isShallow(s));
|
|
1831
|
+
getter = () => source.map((s) => {
|
|
1832
|
+
if (isRef(s)) {
|
|
1833
|
+
return s.value;
|
|
1834
|
+
} else if (isReactive(s)) {
|
|
1835
|
+
return reactiveGetter(s, deep);
|
|
1836
|
+
} else if (shared.isFunction(s)) {
|
|
1837
|
+
return call ? call(s, 2) : s();
|
|
1838
|
+
} else {
|
|
1839
|
+
warnInvalidSource(s, onWarn);
|
|
1840
|
+
}
|
|
1841
|
+
});
|
|
1842
|
+
} else if (shared.isFunction(source)) {
|
|
1843
|
+
if (cb) {
|
|
1844
|
+
getter = call ? () => call(source, 2) : source;
|
|
1755
1845
|
} else {
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1846
|
+
getter = () => {
|
|
1847
|
+
if (this.cleanupsLength) {
|
|
1848
|
+
const prevSub = setActiveSub();
|
|
1849
|
+
try {
|
|
1850
|
+
cleanup(this);
|
|
1851
|
+
} finally {
|
|
1852
|
+
setActiveSub(prevSub);
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1855
|
+
const currentEffect = activeWatcher;
|
|
1856
|
+
activeWatcher = this;
|
|
1766
1857
|
try {
|
|
1767
|
-
|
|
1858
|
+
return call ? call(source, 3, [
|
|
1859
|
+
this.boundCleanup
|
|
1860
|
+
]) : source(this.boundCleanup);
|
|
1768
1861
|
} finally {
|
|
1769
|
-
|
|
1862
|
+
activeWatcher = currentEffect;
|
|
1770
1863
|
}
|
|
1771
|
-
}
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1864
|
+
};
|
|
1865
|
+
}
|
|
1866
|
+
} else {
|
|
1867
|
+
getter = shared.NOOP;
|
|
1868
|
+
warnInvalidSource(source, onWarn);
|
|
1869
|
+
}
|
|
1870
|
+
if (cb && deep) {
|
|
1871
|
+
const baseGetter = getter;
|
|
1872
|
+
const depth = deep === true ? Infinity : deep;
|
|
1873
|
+
getter = () => traverse(baseGetter(), depth);
|
|
1874
|
+
}
|
|
1875
|
+
super(getter);
|
|
1876
|
+
this.cb = cb;
|
|
1877
|
+
this.options = options;
|
|
1878
|
+
this.boundCleanup = (fn) => onWatcherCleanup(fn, false, this);
|
|
1879
|
+
this.forceTrigger = forceTrigger;
|
|
1880
|
+
this.isMultiSource = isMultiSource;
|
|
1881
|
+
if (once && cb) {
|
|
1882
|
+
const _cb = cb;
|
|
1883
|
+
cb = (...args) => {
|
|
1884
|
+
_cb(...args);
|
|
1885
|
+
this.stop();
|
|
1779
1886
|
};
|
|
1780
1887
|
}
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
const baseGetter = getter;
|
|
1787
|
-
const depth = deep === true ? Infinity : deep;
|
|
1788
|
-
getter = () => traverse(baseGetter(), depth);
|
|
1789
|
-
}
|
|
1790
|
-
const scope = getCurrentScope();
|
|
1791
|
-
const watchHandle = () => {
|
|
1792
|
-
effect.stop();
|
|
1793
|
-
if (scope && scope.active) {
|
|
1794
|
-
shared.remove(scope.effects, effect);
|
|
1888
|
+
this.cb = cb;
|
|
1889
|
+
this.oldValue = isMultiSource ? new Array(source.length).fill(INITIAL_WATCHER_VALUE) : INITIAL_WATCHER_VALUE;
|
|
1890
|
+
{
|
|
1891
|
+
this.onTrack = options.onTrack;
|
|
1892
|
+
this.onTrigger = options.onTrigger;
|
|
1795
1893
|
}
|
|
1796
|
-
};
|
|
1797
|
-
if (once && cb) {
|
|
1798
|
-
const _cb = cb;
|
|
1799
|
-
cb = (...args) => {
|
|
1800
|
-
_cb(...args);
|
|
1801
|
-
watchHandle();
|
|
1802
|
-
};
|
|
1803
1894
|
}
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1895
|
+
run(initialRun = false) {
|
|
1896
|
+
const oldValue = this.oldValue;
|
|
1897
|
+
const newValue = this.oldValue = super.run();
|
|
1898
|
+
if (!this.cb) {
|
|
1807
1899
|
return;
|
|
1808
1900
|
}
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
if (cleanup) {
|
|
1813
|
-
cleanup();
|
|
1814
|
-
}
|
|
1815
|
-
const currentWatcher = activeWatcher;
|
|
1816
|
-
activeWatcher = effect;
|
|
1817
|
-
try {
|
|
1818
|
-
const args = [
|
|
1819
|
-
newValue,
|
|
1820
|
-
// pass undefined as the old value when it's changed for the first time
|
|
1821
|
-
oldValue === INITIAL_WATCHER_VALUE ? void 0 : isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE ? [] : oldValue,
|
|
1822
|
-
boundCleanup
|
|
1823
|
-
];
|
|
1824
|
-
oldValue = newValue;
|
|
1825
|
-
call ? call(cb, 3, args) : (
|
|
1826
|
-
// @ts-expect-error
|
|
1827
|
-
cb(...args)
|
|
1828
|
-
);
|
|
1829
|
-
} finally {
|
|
1830
|
-
activeWatcher = currentWatcher;
|
|
1831
|
-
}
|
|
1832
|
-
}
|
|
1833
|
-
} else {
|
|
1834
|
-
effect.run();
|
|
1901
|
+
const { immediate, deep, call } = this.options;
|
|
1902
|
+
if (initialRun && !immediate) {
|
|
1903
|
+
return;
|
|
1835
1904
|
}
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
call(
|
|
1848
|
-
|
|
1849
|
-
|
|
1905
|
+
if (deep || this.forceTrigger || (this.isMultiSource ? newValue.some((v, i) => shared.hasChanged(v, oldValue[i])) : shared.hasChanged(newValue, oldValue))) {
|
|
1906
|
+
cleanup(this);
|
|
1907
|
+
const currentWatcher = activeWatcher;
|
|
1908
|
+
activeWatcher = this;
|
|
1909
|
+
try {
|
|
1910
|
+
const args = [
|
|
1911
|
+
newValue,
|
|
1912
|
+
// pass undefined as the old value when it's changed for the first time
|
|
1913
|
+
oldValue === INITIAL_WATCHER_VALUE ? void 0 : this.isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE ? [] : oldValue,
|
|
1914
|
+
this.boundCleanup
|
|
1915
|
+
];
|
|
1916
|
+
call ? call(this.cb, 3, args) : (
|
|
1917
|
+
// @ts-expect-error
|
|
1918
|
+
this.cb(...args)
|
|
1919
|
+
);
|
|
1920
|
+
} finally {
|
|
1921
|
+
activeWatcher = currentWatcher;
|
|
1850
1922
|
}
|
|
1851
|
-
cleanupMap.delete(effect);
|
|
1852
|
-
}
|
|
1853
|
-
};
|
|
1854
|
-
{
|
|
1855
|
-
effect.onTrack = options.onTrack;
|
|
1856
|
-
effect.onTrigger = options.onTrigger;
|
|
1857
|
-
}
|
|
1858
|
-
if (cb) {
|
|
1859
|
-
if (immediate) {
|
|
1860
|
-
job(true);
|
|
1861
|
-
} else {
|
|
1862
|
-
oldValue = effect.run();
|
|
1863
1923
|
}
|
|
1864
|
-
} else if (scheduler) {
|
|
1865
|
-
scheduler(job.bind(null, true), true);
|
|
1866
|
-
} else {
|
|
1867
|
-
effect.run();
|
|
1868
1924
|
}
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1925
|
+
}
|
|
1926
|
+
function reactiveGetter(source, deep) {
|
|
1927
|
+
if (deep) return source;
|
|
1928
|
+
if (isShallow(source) || deep === false || deep === 0)
|
|
1929
|
+
return traverse(source, 1);
|
|
1930
|
+
return traverse(source);
|
|
1931
|
+
}
|
|
1932
|
+
function warnInvalidSource(s, onWarn) {
|
|
1933
|
+
(onWarn || warn)(
|
|
1934
|
+
`Invalid watch source: `,
|
|
1935
|
+
s,
|
|
1936
|
+
`A watch source can only be a getter/effect function, a ref, a reactive object, or an array of these types.`
|
|
1937
|
+
);
|
|
1938
|
+
}
|
|
1939
|
+
function watch(source, cb, options = shared.EMPTY_OBJ) {
|
|
1940
|
+
const effect = new WatcherEffect(source, cb, options);
|
|
1941
|
+
effect.run(true);
|
|
1942
|
+
const stop = effect.stop.bind(effect);
|
|
1943
|
+
stop.pause = effect.pause.bind(effect);
|
|
1944
|
+
stop.resume = effect.resume.bind(effect);
|
|
1945
|
+
stop.stop = stop;
|
|
1946
|
+
return stop;
|
|
1873
1947
|
}
|
|
1874
1948
|
function traverse(value, depth = Infinity, seen) {
|
|
1875
1949
|
if (depth <= 0 || !shared.isObject(value) || value["__v_skip"]) {
|
|
@@ -1914,6 +1988,7 @@ exports.ReactiveFlags = ReactiveFlags;
|
|
|
1914
1988
|
exports.TrackOpTypes = TrackOpTypes;
|
|
1915
1989
|
exports.TriggerOpTypes = TriggerOpTypes;
|
|
1916
1990
|
exports.WatchErrorCodes = WatchErrorCodes;
|
|
1991
|
+
exports.WatcherEffect = WatcherEffect;
|
|
1917
1992
|
exports.computed = computed;
|
|
1918
1993
|
exports.customRef = customRef;
|
|
1919
1994
|
exports.effect = effect;
|
|
@@ -1937,6 +2012,8 @@ exports.reactiveReadArray = reactiveReadArray;
|
|
|
1937
2012
|
exports.readonly = readonly;
|
|
1938
2013
|
exports.ref = ref;
|
|
1939
2014
|
exports.resetTracking = resetTracking;
|
|
2015
|
+
exports.setActiveSub = setActiveSub;
|
|
2016
|
+
exports.setCurrentScope = setCurrentScope;
|
|
1940
2017
|
exports.shallowReactive = shallowReactive;
|
|
1941
2018
|
exports.shallowReadArray = shallowReadArray;
|
|
1942
2019
|
exports.shallowReadonly = shallowReadonly;
|