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