@vue-mini/core 1.0.3 → 1.1.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/vue-mini.cjs.js +1100 -618
- package/dist/vue-mini.cjs.prod.js +2 -2
- package/dist/vue-mini.d.ts +15 -19
- package/dist/vue-mini.esm-bundler.js +71 -236
- package/package.json +2 -2
package/dist/vue-mini.cjs.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* vue-mini v1.
|
|
2
|
+
* vue-mini v1.1.1
|
|
3
3
|
* https://github.com/vue-mini/vue-mini
|
|
4
4
|
* (c) 2019-present Yang Mingshan
|
|
5
5
|
* @license MIT
|
|
@@ -7,23 +7,33 @@
|
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* @vue/shared v3.
|
|
10
|
+
* @vue/shared v3.5.7
|
|
11
11
|
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
12
12
|
* @license MIT
|
|
13
13
|
**/
|
|
14
14
|
/*! #__NO_SIDE_EFFECTS__ */
|
|
15
15
|
// @__NO_SIDE_EFFECTS__
|
|
16
|
-
function makeMap(str
|
|
17
|
-
const
|
|
18
|
-
|
|
16
|
+
function makeMap(str) {
|
|
17
|
+
const map = /* @__PURE__ */ Object.create(null);
|
|
18
|
+
for (const key of str.split(",")) map[key] = 1;
|
|
19
|
+
return (val) => val in map;
|
|
19
20
|
}
|
|
20
|
-
|
|
21
|
+
|
|
22
|
+
const EMPTY_OBJ$1 = Object.freeze({}) ;
|
|
23
|
+
const NOOP = () => {
|
|
21
24
|
};
|
|
22
25
|
const extend$1 = Object.assign;
|
|
26
|
+
const remove = (arr, el) => {
|
|
27
|
+
const i = arr.indexOf(el);
|
|
28
|
+
if (i > -1) {
|
|
29
|
+
arr.splice(i, 1);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
23
32
|
const hasOwnProperty$1 = Object.prototype.hasOwnProperty;
|
|
24
33
|
const hasOwn = (val, key) => hasOwnProperty$1.call(val, key);
|
|
25
34
|
const isArray$1 = Array.isArray;
|
|
26
|
-
const isMap
|
|
35
|
+
const isMap = (val) => toTypeString(val) === "[object Map]";
|
|
36
|
+
const isSet = (val) => toTypeString(val) === "[object Set]";
|
|
27
37
|
const isFunction$1 = (val) => typeof val === "function";
|
|
28
38
|
const isString = (val) => typeof val === "string";
|
|
29
39
|
const isSymbol = (val) => typeof val === "symbol";
|
|
@@ -33,6 +43,7 @@ const toTypeString = (value) => objectToString.call(value);
|
|
|
33
43
|
const toRawType = (value) => {
|
|
34
44
|
return toTypeString(value).slice(8, -1);
|
|
35
45
|
};
|
|
46
|
+
const isPlainObject$1 = (val) => toTypeString(val) === "[object Object]";
|
|
36
47
|
const isIntegerKey = (key) => isString(key) && key !== "NaN" && key[0] !== "-" && "" + parseInt(key, 10) === key;
|
|
37
48
|
const cacheStringFunction = (fn) => {
|
|
38
49
|
const cache = /* @__PURE__ */ Object.create(null);
|
|
@@ -44,7 +55,7 @@ const cacheStringFunction = (fn) => {
|
|
|
44
55
|
const capitalize = cacheStringFunction((str) => {
|
|
45
56
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
46
57
|
});
|
|
47
|
-
const hasChanged
|
|
58
|
+
const hasChanged = (value, oldValue) => !Object.is(value, oldValue);
|
|
48
59
|
const def = (obj, key, value, writable = false) => {
|
|
49
60
|
Object.defineProperty(obj, key, {
|
|
50
61
|
configurable: true,
|
|
@@ -55,7 +66,7 @@ const def = (obj, key, value, writable = false) => {
|
|
|
55
66
|
};
|
|
56
67
|
|
|
57
68
|
/**
|
|
58
|
-
* @vue/reactivity v3.
|
|
69
|
+
* @vue/reactivity v3.5.7
|
|
59
70
|
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
60
71
|
* @license MIT
|
|
61
72
|
**/
|
|
@@ -80,6 +91,7 @@ class EffectScope {
|
|
|
80
91
|
* @internal
|
|
81
92
|
*/
|
|
82
93
|
this.cleanups = [];
|
|
94
|
+
this._isPaused = false;
|
|
83
95
|
this.parent = activeEffectScope;
|
|
84
96
|
if (!detached && activeEffectScope) {
|
|
85
97
|
this.index = (activeEffectScope.scopes || (activeEffectScope.scopes = [])).push(
|
|
@@ -90,6 +102,39 @@ class EffectScope {
|
|
|
90
102
|
get active() {
|
|
91
103
|
return this._active;
|
|
92
104
|
}
|
|
105
|
+
pause() {
|
|
106
|
+
if (this._active) {
|
|
107
|
+
this._isPaused = true;
|
|
108
|
+
let i, l;
|
|
109
|
+
if (this.scopes) {
|
|
110
|
+
for (i = 0, l = this.scopes.length; i < l; i++) {
|
|
111
|
+
this.scopes[i].pause();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
for (i = 0, l = this.effects.length; i < l; i++) {
|
|
115
|
+
this.effects[i].pause();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Resumes the effect scope, including all child scopes and effects.
|
|
121
|
+
*/
|
|
122
|
+
resume() {
|
|
123
|
+
if (this._active) {
|
|
124
|
+
if (this._isPaused) {
|
|
125
|
+
this._isPaused = false;
|
|
126
|
+
let i, l;
|
|
127
|
+
if (this.scopes) {
|
|
128
|
+
for (i = 0, l = this.scopes.length; i < l; i++) {
|
|
129
|
+
this.scopes[i].resume();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
for (i = 0, l = this.effects.length; i < l; i++) {
|
|
133
|
+
this.effects[i].resume();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
93
138
|
run(fn) {
|
|
94
139
|
if (this._active) {
|
|
95
140
|
const currentEffectScope = activeEffectScope;
|
|
@@ -146,155 +191,299 @@ class EffectScope {
|
|
|
146
191
|
function effectScope(detached) {
|
|
147
192
|
return new EffectScope(detached);
|
|
148
193
|
}
|
|
149
|
-
function recordEffectScope(effect, scope = activeEffectScope) {
|
|
150
|
-
if (scope && scope.active) {
|
|
151
|
-
scope.effects.push(effect);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
194
|
function getCurrentScope() {
|
|
155
195
|
return activeEffectScope;
|
|
156
196
|
}
|
|
157
|
-
function onScopeDispose(fn) {
|
|
197
|
+
function onScopeDispose(fn, failSilently = false) {
|
|
158
198
|
if (activeEffectScope) {
|
|
159
199
|
activeEffectScope.cleanups.push(fn);
|
|
160
|
-
} else {
|
|
200
|
+
} else if (!failSilently) {
|
|
161
201
|
warn(
|
|
162
202
|
`onScopeDispose() is called when there is no active effect scope to be associated with.`
|
|
163
203
|
);
|
|
164
204
|
}
|
|
165
205
|
}
|
|
166
206
|
|
|
167
|
-
let
|
|
207
|
+
let activeSub;
|
|
208
|
+
const pausedQueueEffects = /* @__PURE__ */ new WeakSet();
|
|
168
209
|
class ReactiveEffect {
|
|
169
|
-
constructor(fn
|
|
210
|
+
constructor(fn) {
|
|
170
211
|
this.fn = fn;
|
|
171
|
-
this.trigger = trigger;
|
|
172
|
-
this.scheduler = scheduler;
|
|
173
|
-
this.active = true;
|
|
174
|
-
this.deps = [];
|
|
175
212
|
/**
|
|
176
213
|
* @internal
|
|
177
214
|
*/
|
|
178
|
-
this.
|
|
215
|
+
this.deps = void 0;
|
|
179
216
|
/**
|
|
180
217
|
* @internal
|
|
181
218
|
*/
|
|
182
|
-
this.
|
|
219
|
+
this.depsTail = void 0;
|
|
183
220
|
/**
|
|
184
221
|
* @internal
|
|
185
222
|
*/
|
|
186
|
-
this.
|
|
223
|
+
this.flags = 1 | 4;
|
|
187
224
|
/**
|
|
188
225
|
* @internal
|
|
189
226
|
*/
|
|
190
|
-
this.
|
|
227
|
+
this.next = void 0;
|
|
191
228
|
/**
|
|
192
229
|
* @internal
|
|
193
230
|
*/
|
|
194
|
-
this.
|
|
195
|
-
|
|
231
|
+
this.cleanup = void 0;
|
|
232
|
+
this.scheduler = void 0;
|
|
233
|
+
if (activeEffectScope && activeEffectScope.active) {
|
|
234
|
+
activeEffectScope.effects.push(this);
|
|
235
|
+
}
|
|
196
236
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
break;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
if (this._dirtyLevel === 1) {
|
|
211
|
-
this._dirtyLevel = 0;
|
|
237
|
+
pause() {
|
|
238
|
+
this.flags |= 64;
|
|
239
|
+
}
|
|
240
|
+
resume() {
|
|
241
|
+
if (this.flags & 64) {
|
|
242
|
+
this.flags &= ~64;
|
|
243
|
+
if (pausedQueueEffects.has(this)) {
|
|
244
|
+
pausedQueueEffects.delete(this);
|
|
245
|
+
this.trigger();
|
|
212
246
|
}
|
|
213
|
-
resetTracking();
|
|
214
247
|
}
|
|
215
|
-
return this._dirtyLevel >= 4;
|
|
216
248
|
}
|
|
217
|
-
|
|
218
|
-
|
|
249
|
+
/**
|
|
250
|
+
* @internal
|
|
251
|
+
*/
|
|
252
|
+
notify() {
|
|
253
|
+
if (this.flags & 2 && !(this.flags & 32)) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
if (!(this.flags & 8)) {
|
|
257
|
+
batch(this);
|
|
258
|
+
}
|
|
219
259
|
}
|
|
220
260
|
run() {
|
|
221
|
-
this.
|
|
222
|
-
if (!this.active) {
|
|
261
|
+
if (!(this.flags & 1)) {
|
|
223
262
|
return this.fn();
|
|
224
263
|
}
|
|
225
|
-
|
|
226
|
-
|
|
264
|
+
this.flags |= 2;
|
|
265
|
+
cleanupEffect(this);
|
|
266
|
+
prepareDeps(this);
|
|
267
|
+
const prevEffect = activeSub;
|
|
268
|
+
const prevShouldTrack = shouldTrack;
|
|
269
|
+
activeSub = this;
|
|
270
|
+
shouldTrack = true;
|
|
227
271
|
try {
|
|
228
|
-
shouldTrack = true;
|
|
229
|
-
activeEffect = this;
|
|
230
|
-
this._runnings++;
|
|
231
|
-
preCleanupEffect(this);
|
|
232
272
|
return this.fn();
|
|
233
273
|
} finally {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
274
|
+
if (activeSub !== this) {
|
|
275
|
+
warn(
|
|
276
|
+
"Active effect was not restored correctly - this is likely a Vue internal bug."
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
cleanupDeps(this);
|
|
280
|
+
activeSub = prevEffect;
|
|
281
|
+
shouldTrack = prevShouldTrack;
|
|
282
|
+
this.flags &= ~2;
|
|
238
283
|
}
|
|
239
284
|
}
|
|
240
285
|
stop() {
|
|
241
|
-
if (this.
|
|
242
|
-
|
|
243
|
-
|
|
286
|
+
if (this.flags & 1) {
|
|
287
|
+
for (let link = this.deps; link; link = link.nextDep) {
|
|
288
|
+
removeSub(link);
|
|
289
|
+
}
|
|
290
|
+
this.deps = this.depsTail = void 0;
|
|
291
|
+
cleanupEffect(this);
|
|
244
292
|
this.onStop && this.onStop();
|
|
245
|
-
this.
|
|
293
|
+
this.flags &= ~1;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
trigger() {
|
|
297
|
+
if (this.flags & 64) {
|
|
298
|
+
pausedQueueEffects.add(this);
|
|
299
|
+
} else if (this.scheduler) {
|
|
300
|
+
this.scheduler();
|
|
301
|
+
} else {
|
|
302
|
+
this.runIfDirty();
|
|
246
303
|
}
|
|
247
304
|
}
|
|
305
|
+
/**
|
|
306
|
+
* @internal
|
|
307
|
+
*/
|
|
308
|
+
runIfDirty() {
|
|
309
|
+
if (isDirty(this)) {
|
|
310
|
+
this.run();
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
get dirty() {
|
|
314
|
+
return isDirty(this);
|
|
315
|
+
}
|
|
248
316
|
}
|
|
249
|
-
|
|
250
|
-
|
|
317
|
+
let batchDepth = 0;
|
|
318
|
+
let batchedSub;
|
|
319
|
+
function batch(sub) {
|
|
320
|
+
sub.flags |= 8;
|
|
321
|
+
sub.next = batchedSub;
|
|
322
|
+
batchedSub = sub;
|
|
251
323
|
}
|
|
252
|
-
function
|
|
253
|
-
|
|
254
|
-
effect2._depsLength = 0;
|
|
324
|
+
function startBatch() {
|
|
325
|
+
batchDepth++;
|
|
255
326
|
}
|
|
256
|
-
function
|
|
257
|
-
if (
|
|
258
|
-
|
|
259
|
-
|
|
327
|
+
function endBatch() {
|
|
328
|
+
if (--batchDepth > 0) {
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
let error;
|
|
332
|
+
while (batchedSub) {
|
|
333
|
+
let e = batchedSub;
|
|
334
|
+
batchedSub = void 0;
|
|
335
|
+
while (e) {
|
|
336
|
+
const next = e.next;
|
|
337
|
+
e.next = void 0;
|
|
338
|
+
e.flags &= ~8;
|
|
339
|
+
if (e.flags & 1) {
|
|
340
|
+
try {
|
|
341
|
+
;
|
|
342
|
+
e.trigger();
|
|
343
|
+
} catch (err) {
|
|
344
|
+
if (!error) error = err;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
e = next;
|
|
260
348
|
}
|
|
261
|
-
|
|
349
|
+
}
|
|
350
|
+
if (error) throw error;
|
|
351
|
+
}
|
|
352
|
+
function prepareDeps(sub) {
|
|
353
|
+
for (let link = sub.deps; link; link = link.nextDep) {
|
|
354
|
+
link.version = -1;
|
|
355
|
+
link.prevActiveLink = link.dep.activeLink;
|
|
356
|
+
link.dep.activeLink = link;
|
|
262
357
|
}
|
|
263
358
|
}
|
|
264
|
-
function
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
359
|
+
function cleanupDeps(sub) {
|
|
360
|
+
let head;
|
|
361
|
+
let tail = sub.depsTail;
|
|
362
|
+
let link = tail;
|
|
363
|
+
while (link) {
|
|
364
|
+
const prev = link.prevDep;
|
|
365
|
+
if (link.version === -1) {
|
|
366
|
+
if (link === tail) tail = prev;
|
|
367
|
+
removeSub(link);
|
|
368
|
+
removeDep(link);
|
|
369
|
+
} else {
|
|
370
|
+
head = link;
|
|
371
|
+
}
|
|
372
|
+
link.dep.activeLink = link.prevActiveLink;
|
|
373
|
+
link.prevActiveLink = void 0;
|
|
374
|
+
link = prev;
|
|
375
|
+
}
|
|
376
|
+
sub.deps = head;
|
|
377
|
+
sub.depsTail = tail;
|
|
378
|
+
}
|
|
379
|
+
function isDirty(sub) {
|
|
380
|
+
for (let link = sub.deps; link; link = link.nextDep) {
|
|
381
|
+
if (link.dep.version !== link.version || link.dep.computed && (refreshComputed(link.dep.computed) || link.dep.version !== link.version)) {
|
|
382
|
+
return true;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
if (sub._dirty) {
|
|
386
|
+
return true;
|
|
387
|
+
}
|
|
388
|
+
return false;
|
|
389
|
+
}
|
|
390
|
+
function refreshComputed(computed) {
|
|
391
|
+
if (computed.flags & 4 && !(computed.flags & 16)) {
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
computed.flags &= ~16;
|
|
395
|
+
if (computed.globalVersion === globalVersion) {
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
computed.globalVersion = globalVersion;
|
|
399
|
+
const dep = computed.dep;
|
|
400
|
+
computed.flags |= 2;
|
|
401
|
+
if (dep.version > 0 && !computed.isSSR && computed.deps && !isDirty(computed)) {
|
|
402
|
+
computed.flags &= ~2;
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
const prevSub = activeSub;
|
|
406
|
+
const prevShouldTrack = shouldTrack;
|
|
407
|
+
activeSub = computed;
|
|
408
|
+
shouldTrack = true;
|
|
409
|
+
try {
|
|
410
|
+
prepareDeps(computed);
|
|
411
|
+
const value = computed.fn(computed._value);
|
|
412
|
+
if (dep.version === 0 || hasChanged(value, computed._value)) {
|
|
413
|
+
computed._value = value;
|
|
414
|
+
dep.version++;
|
|
415
|
+
}
|
|
416
|
+
} catch (err) {
|
|
417
|
+
dep.version++;
|
|
418
|
+
throw err;
|
|
419
|
+
} finally {
|
|
420
|
+
activeSub = prevSub;
|
|
421
|
+
shouldTrack = prevShouldTrack;
|
|
422
|
+
cleanupDeps(computed);
|
|
423
|
+
computed.flags &= ~2;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
function removeSub(link, fromComputed = false) {
|
|
427
|
+
const { dep, prevSub, nextSub } = link;
|
|
428
|
+
if (prevSub) {
|
|
429
|
+
prevSub.nextSub = nextSub;
|
|
430
|
+
link.prevSub = void 0;
|
|
431
|
+
}
|
|
432
|
+
if (nextSub) {
|
|
433
|
+
nextSub.prevSub = prevSub;
|
|
434
|
+
link.nextSub = void 0;
|
|
435
|
+
}
|
|
436
|
+
if (dep.subs === link) {
|
|
437
|
+
dep.subs = prevSub;
|
|
438
|
+
}
|
|
439
|
+
if (dep.subsHead === link) {
|
|
440
|
+
dep.subsHead = nextSub;
|
|
441
|
+
}
|
|
442
|
+
if (!dep.subs) {
|
|
443
|
+
if (dep.computed) {
|
|
444
|
+
dep.computed.flags &= ~4;
|
|
445
|
+
for (let l = dep.computed.deps; l; l = l.nextDep) {
|
|
446
|
+
removeSub(l, true);
|
|
447
|
+
}
|
|
448
|
+
} else if (dep.map && !fromComputed) {
|
|
449
|
+
dep.map.delete(dep.key);
|
|
450
|
+
if (!dep.map.size) targetMap.delete(dep.target);
|
|
270
451
|
}
|
|
271
452
|
}
|
|
272
453
|
}
|
|
454
|
+
function removeDep(link) {
|
|
455
|
+
const { prevDep, nextDep } = link;
|
|
456
|
+
if (prevDep) {
|
|
457
|
+
prevDep.nextDep = nextDep;
|
|
458
|
+
link.prevDep = void 0;
|
|
459
|
+
}
|
|
460
|
+
if (nextDep) {
|
|
461
|
+
nextDep.prevDep = prevDep;
|
|
462
|
+
link.nextDep = void 0;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
273
465
|
function effect(fn, options) {
|
|
274
466
|
if (fn.effect instanceof ReactiveEffect) {
|
|
275
467
|
fn = fn.effect.fn;
|
|
276
468
|
}
|
|
277
|
-
const
|
|
278
|
-
if (_effect.dirty) {
|
|
279
|
-
_effect.run();
|
|
280
|
-
}
|
|
281
|
-
});
|
|
469
|
+
const e = new ReactiveEffect(fn);
|
|
282
470
|
if (options) {
|
|
283
|
-
extend$1(
|
|
284
|
-
if (options.scope) recordEffectScope(_effect, options.scope);
|
|
471
|
+
extend$1(e, options);
|
|
285
472
|
}
|
|
286
|
-
|
|
287
|
-
|
|
473
|
+
try {
|
|
474
|
+
e.run();
|
|
475
|
+
} catch (err) {
|
|
476
|
+
e.stop();
|
|
477
|
+
throw err;
|
|
288
478
|
}
|
|
289
|
-
const runner =
|
|
290
|
-
runner.effect =
|
|
479
|
+
const runner = e.run.bind(e);
|
|
480
|
+
runner.effect = e;
|
|
291
481
|
return runner;
|
|
292
482
|
}
|
|
293
483
|
function stop(runner) {
|
|
294
484
|
runner.effect.stop();
|
|
295
485
|
}
|
|
296
486
|
let shouldTrack = true;
|
|
297
|
-
let pauseScheduleStack = 0;
|
|
298
487
|
const trackStack = [];
|
|
299
488
|
function pauseTracking() {
|
|
300
489
|
trackStack.push(shouldTrack);
|
|
@@ -304,192 +493,434 @@ function resetTracking() {
|
|
|
304
493
|
const last = trackStack.pop();
|
|
305
494
|
shouldTrack = last === void 0 ? true : last;
|
|
306
495
|
}
|
|
307
|
-
function
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
496
|
+
function cleanupEffect(e) {
|
|
497
|
+
const { cleanup } = e;
|
|
498
|
+
e.cleanup = void 0;
|
|
499
|
+
if (cleanup) {
|
|
500
|
+
const prevSub = activeSub;
|
|
501
|
+
activeSub = void 0;
|
|
502
|
+
try {
|
|
503
|
+
cleanup();
|
|
504
|
+
} finally {
|
|
505
|
+
activeSub = prevSub;
|
|
506
|
+
}
|
|
314
507
|
}
|
|
315
508
|
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
509
|
+
|
|
510
|
+
let globalVersion = 0;
|
|
511
|
+
class Link {
|
|
512
|
+
constructor(sub, dep) {
|
|
513
|
+
this.sub = sub;
|
|
514
|
+
this.dep = dep;
|
|
515
|
+
this.version = dep.version;
|
|
516
|
+
this.nextDep = this.prevDep = this.nextSub = this.prevSub = this.prevActiveLink = void 0;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
class Dep {
|
|
520
|
+
constructor(computed) {
|
|
521
|
+
this.computed = computed;
|
|
522
|
+
this.version = 0;
|
|
523
|
+
/**
|
|
524
|
+
* Link between this dep and the current active effect
|
|
525
|
+
*/
|
|
526
|
+
this.activeLink = void 0;
|
|
527
|
+
/**
|
|
528
|
+
* Doubly linked list representing the subscribing effects (tail)
|
|
529
|
+
*/
|
|
530
|
+
this.subs = void 0;
|
|
531
|
+
/**
|
|
532
|
+
* For object property deps cleanup
|
|
533
|
+
*/
|
|
534
|
+
this.target = void 0;
|
|
535
|
+
this.map = void 0;
|
|
536
|
+
this.key = void 0;
|
|
537
|
+
{
|
|
538
|
+
this.subsHead = void 0;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
track(debugInfo) {
|
|
542
|
+
if (!activeSub || !shouldTrack || activeSub === this.computed) {
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
let link = this.activeLink;
|
|
546
|
+
if (link === void 0 || link.sub !== activeSub) {
|
|
547
|
+
link = this.activeLink = new Link(activeSub, this);
|
|
548
|
+
if (!activeSub.deps) {
|
|
549
|
+
activeSub.deps = activeSub.depsTail = link;
|
|
550
|
+
} else {
|
|
551
|
+
link.prevDep = activeSub.depsTail;
|
|
552
|
+
activeSub.depsTail.nextDep = link;
|
|
553
|
+
activeSub.depsTail = link;
|
|
554
|
+
}
|
|
555
|
+
if (activeSub.flags & 4) {
|
|
556
|
+
addSub(link);
|
|
557
|
+
}
|
|
558
|
+
} else if (link.version === -1) {
|
|
559
|
+
link.version = this.version;
|
|
560
|
+
if (link.nextDep) {
|
|
561
|
+
const next = link.nextDep;
|
|
562
|
+
next.prevDep = link.prevDep;
|
|
563
|
+
if (link.prevDep) {
|
|
564
|
+
link.prevDep.nextDep = next;
|
|
565
|
+
}
|
|
566
|
+
link.prevDep = activeSub.depsTail;
|
|
567
|
+
link.nextDep = void 0;
|
|
568
|
+
activeSub.depsTail.nextDep = link;
|
|
569
|
+
activeSub.depsTail = link;
|
|
570
|
+
if (activeSub.deps === link) {
|
|
571
|
+
activeSub.deps = next;
|
|
572
|
+
}
|
|
324
573
|
}
|
|
325
|
-
effect2.deps[effect2._depsLength++] = dep;
|
|
326
|
-
} else {
|
|
327
|
-
effect2._depsLength++;
|
|
328
574
|
}
|
|
329
|
-
{
|
|
330
|
-
|
|
575
|
+
if (activeSub.onTrack) {
|
|
576
|
+
activeSub.onTrack(
|
|
577
|
+
extend$1(
|
|
578
|
+
{
|
|
579
|
+
effect: activeSub
|
|
580
|
+
},
|
|
581
|
+
debugInfo
|
|
582
|
+
)
|
|
583
|
+
);
|
|
331
584
|
}
|
|
585
|
+
return link;
|
|
332
586
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
587
|
+
trigger(debugInfo) {
|
|
588
|
+
this.version++;
|
|
589
|
+
globalVersion++;
|
|
590
|
+
this.notify(debugInfo);
|
|
591
|
+
}
|
|
592
|
+
notify(debugInfo) {
|
|
593
|
+
startBatch();
|
|
594
|
+
try {
|
|
595
|
+
if (!!("development" !== "production")) {
|
|
596
|
+
for (let head = this.subsHead; head; head = head.nextSub) {
|
|
597
|
+
if (head.sub.onTrigger && !(head.sub.flags & 8)) {
|
|
598
|
+
head.sub.onTrigger(
|
|
599
|
+
extend$1(
|
|
600
|
+
{
|
|
601
|
+
effect: head.sub
|
|
602
|
+
},
|
|
603
|
+
debugInfo
|
|
604
|
+
)
|
|
605
|
+
);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
347
608
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
queueEffectSchedulers.push(effect2.scheduler);
|
|
609
|
+
for (let link = this.subs; link; link = link.prevSub) {
|
|
610
|
+
if (link.sub.notify()) {
|
|
611
|
+
;
|
|
612
|
+
link.sub.dep.notify();
|
|
353
613
|
}
|
|
354
614
|
}
|
|
615
|
+
} finally {
|
|
616
|
+
endBatch();
|
|
355
617
|
}
|
|
356
618
|
}
|
|
357
|
-
resetScheduling();
|
|
358
619
|
}
|
|
359
|
-
|
|
360
|
-
const
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
}
|
|
366
|
-
|
|
620
|
+
function addSub(link) {
|
|
621
|
+
const computed = link.dep.computed;
|
|
622
|
+
if (computed && !link.dep.subs) {
|
|
623
|
+
computed.flags |= 4 | 16;
|
|
624
|
+
for (let l = computed.deps; l; l = l.nextDep) {
|
|
625
|
+
addSub(l);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
const currentTail = link.dep.subs;
|
|
629
|
+
if (currentTail !== link) {
|
|
630
|
+
link.prevSub = currentTail;
|
|
631
|
+
if (currentTail) currentTail.nextSub = link;
|
|
632
|
+
}
|
|
633
|
+
if (link.dep.subsHead === void 0) {
|
|
634
|
+
link.dep.subsHead = link;
|
|
635
|
+
}
|
|
636
|
+
link.dep.subs = link;
|
|
637
|
+
}
|
|
367
638
|
const targetMap = /* @__PURE__ */ new WeakMap();
|
|
368
|
-
const ITERATE_KEY = Symbol(
|
|
369
|
-
|
|
639
|
+
const ITERATE_KEY = Symbol(
|
|
640
|
+
"Object iterate"
|
|
641
|
+
);
|
|
642
|
+
const MAP_KEY_ITERATE_KEY = Symbol(
|
|
643
|
+
"Map keys iterate"
|
|
644
|
+
);
|
|
645
|
+
const ARRAY_ITERATE_KEY = Symbol(
|
|
646
|
+
"Array iterate"
|
|
647
|
+
);
|
|
370
648
|
function track(target, type, key) {
|
|
371
|
-
if (shouldTrack &&
|
|
649
|
+
if (shouldTrack && activeSub) {
|
|
372
650
|
let depsMap = targetMap.get(target);
|
|
373
651
|
if (!depsMap) {
|
|
374
652
|
targetMap.set(target, depsMap = /* @__PURE__ */ new Map());
|
|
375
653
|
}
|
|
376
654
|
let dep = depsMap.get(key);
|
|
377
655
|
if (!dep) {
|
|
378
|
-
depsMap.set(key, dep =
|
|
656
|
+
depsMap.set(key, dep = new Dep());
|
|
657
|
+
dep.target = target;
|
|
658
|
+
dep.map = depsMap;
|
|
659
|
+
dep.key = key;
|
|
379
660
|
}
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
dep,
|
|
383
|
-
{
|
|
661
|
+
{
|
|
662
|
+
dep.track({
|
|
384
663
|
target,
|
|
385
664
|
type,
|
|
386
665
|
key
|
|
387
|
-
}
|
|
388
|
-
|
|
666
|
+
});
|
|
667
|
+
}
|
|
389
668
|
}
|
|
390
669
|
}
|
|
391
670
|
function trigger(target, type, key, newValue, oldValue, oldTarget) {
|
|
392
671
|
const depsMap = targetMap.get(target);
|
|
393
672
|
if (!depsMap) {
|
|
673
|
+
globalVersion++;
|
|
394
674
|
return;
|
|
395
675
|
}
|
|
396
|
-
|
|
397
|
-
if (type === "clear") {
|
|
398
|
-
deps = [...depsMap.values()];
|
|
399
|
-
} else if (key === "length" && isArray$1(target)) {
|
|
400
|
-
const newLength = Number(newValue);
|
|
401
|
-
depsMap.forEach((dep, key2) => {
|
|
402
|
-
if (key2 === "length" || !isSymbol(key2) && key2 >= newLength) {
|
|
403
|
-
deps.push(dep);
|
|
404
|
-
}
|
|
405
|
-
});
|
|
406
|
-
} else {
|
|
407
|
-
if (key !== void 0) {
|
|
408
|
-
deps.push(depsMap.get(key));
|
|
409
|
-
}
|
|
410
|
-
switch (type) {
|
|
411
|
-
case "add":
|
|
412
|
-
if (!isArray$1(target)) {
|
|
413
|
-
deps.push(depsMap.get(ITERATE_KEY));
|
|
414
|
-
if (isMap$1(target)) {
|
|
415
|
-
deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
|
|
416
|
-
}
|
|
417
|
-
} else if (isIntegerKey(key)) {
|
|
418
|
-
deps.push(depsMap.get("length"));
|
|
419
|
-
}
|
|
420
|
-
break;
|
|
421
|
-
case "delete":
|
|
422
|
-
if (!isArray$1(target)) {
|
|
423
|
-
deps.push(depsMap.get(ITERATE_KEY));
|
|
424
|
-
if (isMap$1(target)) {
|
|
425
|
-
deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
break;
|
|
429
|
-
case "set":
|
|
430
|
-
if (isMap$1(target)) {
|
|
431
|
-
deps.push(depsMap.get(ITERATE_KEY));
|
|
432
|
-
}
|
|
433
|
-
break;
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
pauseScheduling();
|
|
437
|
-
for (const dep of deps) {
|
|
676
|
+
const run = (dep) => {
|
|
438
677
|
if (dep) {
|
|
439
|
-
|
|
440
|
-
dep
|
|
441
|
-
4,
|
|
442
|
-
{
|
|
678
|
+
{
|
|
679
|
+
dep.trigger({
|
|
443
680
|
target,
|
|
444
681
|
type,
|
|
445
682
|
key,
|
|
446
683
|
newValue,
|
|
447
684
|
oldValue,
|
|
448
685
|
oldTarget
|
|
449
|
-
}
|
|
450
|
-
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
};
|
|
690
|
+
startBatch();
|
|
691
|
+
if (type === "clear") {
|
|
692
|
+
depsMap.forEach(run);
|
|
693
|
+
} else {
|
|
694
|
+
const targetIsArray = isArray$1(target);
|
|
695
|
+
const isArrayIndex = targetIsArray && isIntegerKey(key);
|
|
696
|
+
if (targetIsArray && key === "length") {
|
|
697
|
+
const newLength = Number(newValue);
|
|
698
|
+
depsMap.forEach((dep, key2) => {
|
|
699
|
+
if (key2 === "length" || key2 === ARRAY_ITERATE_KEY || !isSymbol(key2) && key2 >= newLength) {
|
|
700
|
+
run(dep);
|
|
701
|
+
}
|
|
702
|
+
});
|
|
703
|
+
} else {
|
|
704
|
+
if (key !== void 0) {
|
|
705
|
+
run(depsMap.get(key));
|
|
706
|
+
}
|
|
707
|
+
if (isArrayIndex) {
|
|
708
|
+
run(depsMap.get(ARRAY_ITERATE_KEY));
|
|
709
|
+
}
|
|
710
|
+
switch (type) {
|
|
711
|
+
case "add":
|
|
712
|
+
if (!targetIsArray) {
|
|
713
|
+
run(depsMap.get(ITERATE_KEY));
|
|
714
|
+
if (isMap(target)) {
|
|
715
|
+
run(depsMap.get(MAP_KEY_ITERATE_KEY));
|
|
716
|
+
}
|
|
717
|
+
} else if (isArrayIndex) {
|
|
718
|
+
run(depsMap.get("length"));
|
|
719
|
+
}
|
|
720
|
+
break;
|
|
721
|
+
case "delete":
|
|
722
|
+
if (!targetIsArray) {
|
|
723
|
+
run(depsMap.get(ITERATE_KEY));
|
|
724
|
+
if (isMap(target)) {
|
|
725
|
+
run(depsMap.get(MAP_KEY_ITERATE_KEY));
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
break;
|
|
729
|
+
case "set":
|
|
730
|
+
if (isMap(target)) {
|
|
731
|
+
run(depsMap.get(ITERATE_KEY));
|
|
732
|
+
}
|
|
733
|
+
break;
|
|
734
|
+
}
|
|
451
735
|
}
|
|
452
736
|
}
|
|
453
|
-
|
|
737
|
+
endBatch();
|
|
454
738
|
}
|
|
455
739
|
function getDepFromReactive(object, key) {
|
|
456
|
-
|
|
457
|
-
return
|
|
740
|
+
var _a;
|
|
741
|
+
return (_a = targetMap.get(object)) == null ? void 0 : _a.get(key);
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
function reactiveReadArray(array) {
|
|
745
|
+
const raw = toRaw(array);
|
|
746
|
+
if (raw === array) return raw;
|
|
747
|
+
track(raw, "iterate", ARRAY_ITERATE_KEY);
|
|
748
|
+
return isShallow(array) ? raw : raw.map(toReactive);
|
|
749
|
+
}
|
|
750
|
+
function shallowReadArray(arr) {
|
|
751
|
+
track(arr = toRaw(arr), "iterate", ARRAY_ITERATE_KEY);
|
|
752
|
+
return arr;
|
|
753
|
+
}
|
|
754
|
+
const arrayInstrumentations = {
|
|
755
|
+
__proto__: null,
|
|
756
|
+
[Symbol.iterator]() {
|
|
757
|
+
return iterator(this, Symbol.iterator, toReactive);
|
|
758
|
+
},
|
|
759
|
+
concat(...args) {
|
|
760
|
+
return reactiveReadArray(this).concat(
|
|
761
|
+
...args.map((x) => isArray$1(x) ? reactiveReadArray(x) : x)
|
|
762
|
+
);
|
|
763
|
+
},
|
|
764
|
+
entries() {
|
|
765
|
+
return iterator(this, "entries", (value) => {
|
|
766
|
+
value[1] = toReactive(value[1]);
|
|
767
|
+
return value;
|
|
768
|
+
});
|
|
769
|
+
},
|
|
770
|
+
every(fn, thisArg) {
|
|
771
|
+
return apply(this, "every", fn, thisArg, void 0, arguments);
|
|
772
|
+
},
|
|
773
|
+
filter(fn, thisArg) {
|
|
774
|
+
return apply(this, "filter", fn, thisArg, (v) => v.map(toReactive), arguments);
|
|
775
|
+
},
|
|
776
|
+
find(fn, thisArg) {
|
|
777
|
+
return apply(this, "find", fn, thisArg, toReactive, arguments);
|
|
778
|
+
},
|
|
779
|
+
findIndex(fn, thisArg) {
|
|
780
|
+
return apply(this, "findIndex", fn, thisArg, void 0, arguments);
|
|
781
|
+
},
|
|
782
|
+
findLast(fn, thisArg) {
|
|
783
|
+
return apply(this, "findLast", fn, thisArg, toReactive, arguments);
|
|
784
|
+
},
|
|
785
|
+
findLastIndex(fn, thisArg) {
|
|
786
|
+
return apply(this, "findLastIndex", fn, thisArg, void 0, arguments);
|
|
787
|
+
},
|
|
788
|
+
// flat, flatMap could benefit from ARRAY_ITERATE but are not straight-forward to implement
|
|
789
|
+
forEach(fn, thisArg) {
|
|
790
|
+
return apply(this, "forEach", fn, thisArg, void 0, arguments);
|
|
791
|
+
},
|
|
792
|
+
includes(...args) {
|
|
793
|
+
return searchProxy(this, "includes", args);
|
|
794
|
+
},
|
|
795
|
+
indexOf(...args) {
|
|
796
|
+
return searchProxy(this, "indexOf", args);
|
|
797
|
+
},
|
|
798
|
+
join(separator) {
|
|
799
|
+
return reactiveReadArray(this).join(separator);
|
|
800
|
+
},
|
|
801
|
+
// keys() iterator only reads `length`, no optimisation required
|
|
802
|
+
lastIndexOf(...args) {
|
|
803
|
+
return searchProxy(this, "lastIndexOf", args);
|
|
804
|
+
},
|
|
805
|
+
map(fn, thisArg) {
|
|
806
|
+
return apply(this, "map", fn, thisArg, void 0, arguments);
|
|
807
|
+
},
|
|
808
|
+
pop() {
|
|
809
|
+
return noTracking(this, "pop");
|
|
810
|
+
},
|
|
811
|
+
push(...args) {
|
|
812
|
+
return noTracking(this, "push", args);
|
|
813
|
+
},
|
|
814
|
+
reduce(fn, ...args) {
|
|
815
|
+
return reduce(this, "reduce", fn, args);
|
|
816
|
+
},
|
|
817
|
+
reduceRight(fn, ...args) {
|
|
818
|
+
return reduce(this, "reduceRight", fn, args);
|
|
819
|
+
},
|
|
820
|
+
shift() {
|
|
821
|
+
return noTracking(this, "shift");
|
|
822
|
+
},
|
|
823
|
+
// slice could use ARRAY_ITERATE but also seems to beg for range tracking
|
|
824
|
+
some(fn, thisArg) {
|
|
825
|
+
return apply(this, "some", fn, thisArg, void 0, arguments);
|
|
826
|
+
},
|
|
827
|
+
splice(...args) {
|
|
828
|
+
return noTracking(this, "splice", args);
|
|
829
|
+
},
|
|
830
|
+
toReversed() {
|
|
831
|
+
return reactiveReadArray(this).toReversed();
|
|
832
|
+
},
|
|
833
|
+
toSorted(comparer) {
|
|
834
|
+
return reactiveReadArray(this).toSorted(comparer);
|
|
835
|
+
},
|
|
836
|
+
toSpliced(...args) {
|
|
837
|
+
return reactiveReadArray(this).toSpliced(...args);
|
|
838
|
+
},
|
|
839
|
+
unshift(...args) {
|
|
840
|
+
return noTracking(this, "unshift", args);
|
|
841
|
+
},
|
|
842
|
+
values() {
|
|
843
|
+
return iterator(this, "values", toReactive);
|
|
844
|
+
}
|
|
845
|
+
};
|
|
846
|
+
function iterator(self, method, wrapValue) {
|
|
847
|
+
const arr = shallowReadArray(self);
|
|
848
|
+
const iter = arr[method]();
|
|
849
|
+
if (arr !== self && !isShallow(self)) {
|
|
850
|
+
iter._next = iter.next;
|
|
851
|
+
iter.next = () => {
|
|
852
|
+
const result = iter._next();
|
|
853
|
+
if (result.value) {
|
|
854
|
+
result.value = wrapValue(result.value);
|
|
855
|
+
}
|
|
856
|
+
return result;
|
|
857
|
+
};
|
|
858
|
+
}
|
|
859
|
+
return iter;
|
|
860
|
+
}
|
|
861
|
+
const arrayProto = Array.prototype;
|
|
862
|
+
function apply(self, method, fn, thisArg, wrappedRetFn, args) {
|
|
863
|
+
const arr = shallowReadArray(self);
|
|
864
|
+
const needsWrap = arr !== self && !isShallow(self);
|
|
865
|
+
const methodFn = arr[method];
|
|
866
|
+
if (methodFn !== arrayProto[method]) {
|
|
867
|
+
const result2 = methodFn.apply(self, args);
|
|
868
|
+
return needsWrap ? toReactive(result2) : result2;
|
|
869
|
+
}
|
|
870
|
+
let wrappedFn = fn;
|
|
871
|
+
if (arr !== self) {
|
|
872
|
+
if (needsWrap) {
|
|
873
|
+
wrappedFn = function(item, index) {
|
|
874
|
+
return fn.call(this, toReactive(item), index, self);
|
|
875
|
+
};
|
|
876
|
+
} else if (fn.length > 2) {
|
|
877
|
+
wrappedFn = function(item, index) {
|
|
878
|
+
return fn.call(this, item, index, self);
|
|
879
|
+
};
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
const result = methodFn.call(arr, wrappedFn, thisArg);
|
|
883
|
+
return needsWrap && wrappedRetFn ? wrappedRetFn(result) : result;
|
|
884
|
+
}
|
|
885
|
+
function reduce(self, method, fn, args) {
|
|
886
|
+
const arr = shallowReadArray(self);
|
|
887
|
+
let wrappedFn = fn;
|
|
888
|
+
if (arr !== self) {
|
|
889
|
+
if (!isShallow(self)) {
|
|
890
|
+
wrappedFn = function(acc, item, index) {
|
|
891
|
+
return fn.call(this, acc, toReactive(item), index, self);
|
|
892
|
+
};
|
|
893
|
+
} else if (fn.length > 3) {
|
|
894
|
+
wrappedFn = function(acc, item, index) {
|
|
895
|
+
return fn.call(this, acc, item, index, self);
|
|
896
|
+
};
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
return arr[method](wrappedFn, ...args);
|
|
900
|
+
}
|
|
901
|
+
function searchProxy(self, method, args) {
|
|
902
|
+
const arr = toRaw(self);
|
|
903
|
+
track(arr, "iterate", ARRAY_ITERATE_KEY);
|
|
904
|
+
const res = arr[method](...args);
|
|
905
|
+
if ((res === -1 || res === false) && isProxy(args[0])) {
|
|
906
|
+
args[0] = toRaw(args[0]);
|
|
907
|
+
return arr[method](...args);
|
|
908
|
+
}
|
|
909
|
+
return res;
|
|
910
|
+
}
|
|
911
|
+
function noTracking(self, method, args = []) {
|
|
912
|
+
pauseTracking();
|
|
913
|
+
startBatch();
|
|
914
|
+
const res = toRaw(self)[method].apply(self, args);
|
|
915
|
+
endBatch();
|
|
916
|
+
resetTracking();
|
|
917
|
+
return res;
|
|
458
918
|
}
|
|
459
919
|
|
|
460
920
|
const isNonTrackableKeys = /* @__PURE__ */ makeMap(`__proto__,__v_isRef,__isVue`);
|
|
461
921
|
const builtInSymbols = new Set(
|
|
462
922
|
/* @__PURE__ */ Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller").map((key) => Symbol[key]).filter(isSymbol)
|
|
463
923
|
);
|
|
464
|
-
const arrayInstrumentations = /* @__PURE__ */ createArrayInstrumentations();
|
|
465
|
-
function createArrayInstrumentations() {
|
|
466
|
-
const instrumentations = {};
|
|
467
|
-
["includes", "indexOf", "lastIndexOf"].forEach((key) => {
|
|
468
|
-
instrumentations[key] = function(...args) {
|
|
469
|
-
const arr = toRaw(this);
|
|
470
|
-
for (let i = 0, l = this.length; i < l; i++) {
|
|
471
|
-
track(arr, "get", i + "");
|
|
472
|
-
}
|
|
473
|
-
const res = arr[key](...args);
|
|
474
|
-
if (res === -1 || res === false) {
|
|
475
|
-
return arr[key](...args.map(toRaw));
|
|
476
|
-
} else {
|
|
477
|
-
return res;
|
|
478
|
-
}
|
|
479
|
-
};
|
|
480
|
-
});
|
|
481
|
-
["push", "pop", "shift", "unshift", "splice"].forEach((key) => {
|
|
482
|
-
instrumentations[key] = function(...args) {
|
|
483
|
-
pauseTracking();
|
|
484
|
-
pauseScheduling();
|
|
485
|
-
const res = toRaw(this)[key].apply(this, args);
|
|
486
|
-
resetScheduling();
|
|
487
|
-
resetTracking();
|
|
488
|
-
return res;
|
|
489
|
-
};
|
|
490
|
-
});
|
|
491
|
-
return instrumentations;
|
|
492
|
-
}
|
|
493
924
|
function hasOwnProperty(key) {
|
|
494
925
|
if (!isSymbol(key)) key = String(key);
|
|
495
926
|
const obj = toRaw(this);
|
|
@@ -519,14 +950,22 @@ class BaseReactiveHandler {
|
|
|
519
950
|
}
|
|
520
951
|
const targetIsArray = isArray$1(target);
|
|
521
952
|
if (!isReadonly2) {
|
|
522
|
-
|
|
523
|
-
|
|
953
|
+
let fn;
|
|
954
|
+
if (targetIsArray && (fn = arrayInstrumentations[key])) {
|
|
955
|
+
return fn;
|
|
524
956
|
}
|
|
525
957
|
if (key === "hasOwnProperty") {
|
|
526
958
|
return hasOwnProperty;
|
|
527
959
|
}
|
|
528
960
|
}
|
|
529
|
-
const res = Reflect.get(
|
|
961
|
+
const res = Reflect.get(
|
|
962
|
+
target,
|
|
963
|
+
key,
|
|
964
|
+
// if this is a proxy wrapping a ref, return methods using the raw ref
|
|
965
|
+
// as receiver so that we don't have to call `toRaw` on the ref in all
|
|
966
|
+
// its class methods
|
|
967
|
+
isRef(target) ? target : receiver
|
|
968
|
+
);
|
|
530
969
|
if (isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) {
|
|
531
970
|
return res;
|
|
532
971
|
}
|
|
@@ -567,11 +1006,16 @@ class MutableReactiveHandler extends BaseReactiveHandler {
|
|
|
567
1006
|
}
|
|
568
1007
|
}
|
|
569
1008
|
const hadKey = isArray$1(target) && isIntegerKey(key) ? Number(key) < target.length : hasOwn(target, key);
|
|
570
|
-
const result = Reflect.set(
|
|
1009
|
+
const result = Reflect.set(
|
|
1010
|
+
target,
|
|
1011
|
+
key,
|
|
1012
|
+
value,
|
|
1013
|
+
isRef(target) ? target : receiver
|
|
1014
|
+
);
|
|
571
1015
|
if (target === toRaw(receiver)) {
|
|
572
1016
|
if (!hadKey) {
|
|
573
1017
|
trigger(target, "add", key, value);
|
|
574
|
-
} else if (hasChanged
|
|
1018
|
+
} else if (hasChanged(value, oldValue)) {
|
|
575
1019
|
trigger(target, "set", key, value, oldValue);
|
|
576
1020
|
}
|
|
577
1021
|
}
|
|
@@ -627,9 +1071,7 @@ class ReadonlyReactiveHandler extends BaseReactiveHandler {
|
|
|
627
1071
|
}
|
|
628
1072
|
const mutableHandlers = /* @__PURE__ */ new MutableReactiveHandler();
|
|
629
1073
|
const readonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler();
|
|
630
|
-
const shallowReactiveHandlers = /* @__PURE__ */ new MutableReactiveHandler(
|
|
631
|
-
true
|
|
632
|
-
);
|
|
1074
|
+
const shallowReactiveHandlers = /* @__PURE__ */ new MutableReactiveHandler(true);
|
|
633
1075
|
const shallowReadonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler(true);
|
|
634
1076
|
|
|
635
1077
|
const toShallow = (value) => value;
|
|
@@ -639,7 +1081,7 @@ function get(target, key, isReadonly2 = false, isShallow2 = false) {
|
|
|
639
1081
|
const rawTarget = toRaw(target);
|
|
640
1082
|
const rawKey = toRaw(key);
|
|
641
1083
|
if (!isReadonly2) {
|
|
642
|
-
if (hasChanged
|
|
1084
|
+
if (hasChanged(key, rawKey)) {
|
|
643
1085
|
track(rawTarget, "get", key);
|
|
644
1086
|
}
|
|
645
1087
|
track(rawTarget, "get", rawKey);
|
|
@@ -659,7 +1101,7 @@ function has(key, isReadonly2 = false) {
|
|
|
659
1101
|
const rawTarget = toRaw(target);
|
|
660
1102
|
const rawKey = toRaw(key);
|
|
661
1103
|
if (!isReadonly2) {
|
|
662
|
-
if (hasChanged
|
|
1104
|
+
if (hasChanged(key, rawKey)) {
|
|
663
1105
|
track(rawTarget, "has", key);
|
|
664
1106
|
}
|
|
665
1107
|
track(rawTarget, "has", rawKey);
|
|
@@ -701,7 +1143,7 @@ function set(key, value, _isShallow = false) {
|
|
|
701
1143
|
target.set(key, value);
|
|
702
1144
|
if (!hadKey) {
|
|
703
1145
|
trigger(target, "add", key, value);
|
|
704
|
-
} else if (hasChanged
|
|
1146
|
+
} else if (hasChanged(value, oldValue)) {
|
|
705
1147
|
trigger(target, "set", key, value, oldValue);
|
|
706
1148
|
}
|
|
707
1149
|
return this;
|
|
@@ -726,7 +1168,7 @@ function deleteEntry(key) {
|
|
|
726
1168
|
function clear() {
|
|
727
1169
|
const target = toRaw(this);
|
|
728
1170
|
const hadItems = target.size !== 0;
|
|
729
|
-
const oldTarget = isMap
|
|
1171
|
+
const oldTarget = isMap(target) ? new Map(target) : new Set(target) ;
|
|
730
1172
|
const result = target.clear();
|
|
731
1173
|
if (hadItems) {
|
|
732
1174
|
trigger(target, "clear", void 0, void 0, oldTarget);
|
|
@@ -749,7 +1191,7 @@ function createIterableMethod(method, isReadonly2, isShallow2) {
|
|
|
749
1191
|
return function(...args) {
|
|
750
1192
|
const target = this["__v_raw"];
|
|
751
1193
|
const rawTarget = toRaw(target);
|
|
752
|
-
const targetIsMap = isMap
|
|
1194
|
+
const targetIsMap = isMap(rawTarget);
|
|
753
1195
|
const isPair = method === "entries" || method === Symbol.iterator && targetIsMap;
|
|
754
1196
|
const isKeyOnly = method === "keys" && targetIsMap;
|
|
755
1197
|
const innerIterator = target[method](...args);
|
|
@@ -1029,7 +1471,7 @@ function toRaw(observed) {
|
|
|
1029
1471
|
return raw ? toRaw(raw) : observed;
|
|
1030
1472
|
}
|
|
1031
1473
|
function markRaw(value) {
|
|
1032
|
-
if (Object.isExtensible(value)) {
|
|
1474
|
+
if (!hasOwn(value, "__v_skip") && Object.isExtensible(value)) {
|
|
1033
1475
|
def(value, "__v_skip", true);
|
|
1034
1476
|
}
|
|
1035
1477
|
return value;
|
|
@@ -1037,111 +1479,8 @@ function markRaw(value) {
|
|
|
1037
1479
|
const toReactive = (value) => isObject$1(value) ? reactive(value) : value;
|
|
1038
1480
|
const toReadonly = (value) => isObject$1(value) ? readonly(value) : value;
|
|
1039
1481
|
|
|
1040
|
-
const COMPUTED_SIDE_EFFECT_WARN = `Computed is still dirty after getter evaluation, likely because a computed is mutating its own dependency in its getter. State mutations in computed getters should be avoided. Check the docs for more details: https://vuejs.org/guide/essentials/computed.html#getters-should-be-side-effect-free`;
|
|
1041
|
-
class ComputedRefImpl {
|
|
1042
|
-
constructor(getter, _setter, isReadonly, isSSR) {
|
|
1043
|
-
this.getter = getter;
|
|
1044
|
-
this._setter = _setter;
|
|
1045
|
-
this.dep = void 0;
|
|
1046
|
-
this.__v_isRef = true;
|
|
1047
|
-
this["__v_isReadonly"] = false;
|
|
1048
|
-
this.effect = new ReactiveEffect(
|
|
1049
|
-
() => getter(this._value),
|
|
1050
|
-
() => triggerRefValue(
|
|
1051
|
-
this,
|
|
1052
|
-
this.effect._dirtyLevel === 2 ? 2 : 3
|
|
1053
|
-
)
|
|
1054
|
-
);
|
|
1055
|
-
this.effect.computed = this;
|
|
1056
|
-
this.effect.active = this._cacheable = !isSSR;
|
|
1057
|
-
this["__v_isReadonly"] = isReadonly;
|
|
1058
|
-
}
|
|
1059
|
-
get value() {
|
|
1060
|
-
const self = toRaw(this);
|
|
1061
|
-
if ((!self._cacheable || self.effect.dirty) && hasChanged$1(self._value, self._value = self.effect.run())) {
|
|
1062
|
-
triggerRefValue(self, 4);
|
|
1063
|
-
}
|
|
1064
|
-
trackRefValue(self);
|
|
1065
|
-
if (self.effect._dirtyLevel >= 2) {
|
|
1066
|
-
if (this._warnRecursive) {
|
|
1067
|
-
warn(COMPUTED_SIDE_EFFECT_WARN, `
|
|
1068
|
-
|
|
1069
|
-
getter: `, this.getter);
|
|
1070
|
-
}
|
|
1071
|
-
triggerRefValue(self, 2);
|
|
1072
|
-
}
|
|
1073
|
-
return self._value;
|
|
1074
|
-
}
|
|
1075
|
-
set value(newValue) {
|
|
1076
|
-
this._setter(newValue);
|
|
1077
|
-
}
|
|
1078
|
-
// #region polyfill _dirty for backward compatibility third party code for Vue <= 3.3.x
|
|
1079
|
-
get _dirty() {
|
|
1080
|
-
return this.effect.dirty;
|
|
1081
|
-
}
|
|
1082
|
-
set _dirty(v) {
|
|
1083
|
-
this.effect.dirty = v;
|
|
1084
|
-
}
|
|
1085
|
-
// #endregion
|
|
1086
|
-
}
|
|
1087
|
-
function computed(getterOrOptions, debugOptions, isSSR = false) {
|
|
1088
|
-
let getter;
|
|
1089
|
-
let setter;
|
|
1090
|
-
const onlyGetter = isFunction$1(getterOrOptions);
|
|
1091
|
-
if (onlyGetter) {
|
|
1092
|
-
getter = getterOrOptions;
|
|
1093
|
-
setter = () => {
|
|
1094
|
-
warn("Write operation failed: computed value is readonly");
|
|
1095
|
-
} ;
|
|
1096
|
-
} else {
|
|
1097
|
-
getter = getterOrOptions.get;
|
|
1098
|
-
setter = getterOrOptions.set;
|
|
1099
|
-
}
|
|
1100
|
-
const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter, isSSR);
|
|
1101
|
-
if (debugOptions && !isSSR) {
|
|
1102
|
-
cRef.effect.onTrack = debugOptions.onTrack;
|
|
1103
|
-
cRef.effect.onTrigger = debugOptions.onTrigger;
|
|
1104
|
-
}
|
|
1105
|
-
return cRef;
|
|
1106
|
-
}
|
|
1107
|
-
|
|
1108
|
-
function trackRefValue(ref2) {
|
|
1109
|
-
var _a;
|
|
1110
|
-
if (shouldTrack && activeEffect) {
|
|
1111
|
-
ref2 = toRaw(ref2);
|
|
1112
|
-
trackEffect(
|
|
1113
|
-
activeEffect,
|
|
1114
|
-
(_a = ref2.dep) != null ? _a : ref2.dep = createDep(
|
|
1115
|
-
() => ref2.dep = void 0,
|
|
1116
|
-
ref2 instanceof ComputedRefImpl ? ref2 : void 0
|
|
1117
|
-
),
|
|
1118
|
-
{
|
|
1119
|
-
target: ref2,
|
|
1120
|
-
type: "get",
|
|
1121
|
-
key: "value"
|
|
1122
|
-
}
|
|
1123
|
-
);
|
|
1124
|
-
}
|
|
1125
|
-
}
|
|
1126
|
-
function triggerRefValue(ref2, dirtyLevel = 4, newVal, oldVal) {
|
|
1127
|
-
ref2 = toRaw(ref2);
|
|
1128
|
-
const dep = ref2.dep;
|
|
1129
|
-
if (dep) {
|
|
1130
|
-
triggerEffects(
|
|
1131
|
-
dep,
|
|
1132
|
-
dirtyLevel,
|
|
1133
|
-
{
|
|
1134
|
-
target: ref2,
|
|
1135
|
-
type: "set",
|
|
1136
|
-
key: "value",
|
|
1137
|
-
newValue: newVal,
|
|
1138
|
-
oldValue: oldVal
|
|
1139
|
-
}
|
|
1140
|
-
);
|
|
1141
|
-
}
|
|
1142
|
-
}
|
|
1143
1482
|
function isRef(r) {
|
|
1144
|
-
return
|
|
1483
|
+
return r ? r["__v_isRef"] === true : false;
|
|
1145
1484
|
}
|
|
1146
1485
|
function ref(value) {
|
|
1147
1486
|
return createRef(value, false);
|
|
@@ -1156,30 +1495,54 @@ function createRef(rawValue, shallow) {
|
|
|
1156
1495
|
return new RefImpl(rawValue, shallow);
|
|
1157
1496
|
}
|
|
1158
1497
|
class RefImpl {
|
|
1159
|
-
constructor(value,
|
|
1160
|
-
this.
|
|
1161
|
-
this
|
|
1162
|
-
this
|
|
1163
|
-
this._rawValue =
|
|
1164
|
-
this._value =
|
|
1498
|
+
constructor(value, isShallow2) {
|
|
1499
|
+
this.dep = new Dep();
|
|
1500
|
+
this["__v_isRef"] = true;
|
|
1501
|
+
this["__v_isShallow"] = false;
|
|
1502
|
+
this._rawValue = isShallow2 ? value : toRaw(value);
|
|
1503
|
+
this._value = isShallow2 ? value : toReactive(value);
|
|
1504
|
+
this["__v_isShallow"] = isShallow2;
|
|
1165
1505
|
}
|
|
1166
1506
|
get value() {
|
|
1167
|
-
|
|
1507
|
+
{
|
|
1508
|
+
this.dep.track({
|
|
1509
|
+
target: this,
|
|
1510
|
+
type: "get",
|
|
1511
|
+
key: "value"
|
|
1512
|
+
});
|
|
1513
|
+
}
|
|
1168
1514
|
return this._value;
|
|
1169
1515
|
}
|
|
1170
|
-
set value(
|
|
1171
|
-
const
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
this._rawValue =
|
|
1176
|
-
this._value = useDirectValue ?
|
|
1177
|
-
|
|
1516
|
+
set value(newValue) {
|
|
1517
|
+
const oldValue = this._rawValue;
|
|
1518
|
+
const useDirectValue = this["__v_isShallow"] || isShallow(newValue) || isReadonly(newValue);
|
|
1519
|
+
newValue = useDirectValue ? newValue : toRaw(newValue);
|
|
1520
|
+
if (hasChanged(newValue, oldValue)) {
|
|
1521
|
+
this._rawValue = newValue;
|
|
1522
|
+
this._value = useDirectValue ? newValue : toReactive(newValue);
|
|
1523
|
+
{
|
|
1524
|
+
this.dep.trigger({
|
|
1525
|
+
target: this,
|
|
1526
|
+
type: "set",
|
|
1527
|
+
key: "value",
|
|
1528
|
+
newValue,
|
|
1529
|
+
oldValue
|
|
1530
|
+
});
|
|
1531
|
+
}
|
|
1178
1532
|
}
|
|
1179
1533
|
}
|
|
1180
1534
|
}
|
|
1181
1535
|
function triggerRef(ref2) {
|
|
1182
|
-
|
|
1536
|
+
if (ref2.dep) {
|
|
1537
|
+
{
|
|
1538
|
+
ref2.dep.trigger({
|
|
1539
|
+
target: ref2,
|
|
1540
|
+
type: "set",
|
|
1541
|
+
key: "value",
|
|
1542
|
+
newValue: ref2._value
|
|
1543
|
+
});
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1183
1546
|
}
|
|
1184
1547
|
function unref(ref2) {
|
|
1185
1548
|
return isRef(ref2) ? ref2.value : ref2;
|
|
@@ -1188,7 +1551,7 @@ function toValue(source) {
|
|
|
1188
1551
|
return isFunction$1(source) ? source() : unref(source);
|
|
1189
1552
|
}
|
|
1190
1553
|
const shallowUnwrapHandlers = {
|
|
1191
|
-
get: (target, key, receiver) => unref(Reflect.get(target, key, receiver)),
|
|
1554
|
+
get: (target, key, receiver) => key === "__v_raw" ? target : unref(Reflect.get(target, key, receiver)),
|
|
1192
1555
|
set: (target, key, value, receiver) => {
|
|
1193
1556
|
const oldValue = target[key];
|
|
1194
1557
|
if (isRef(oldValue) && !isRef(value)) {
|
|
@@ -1204,17 +1567,15 @@ function proxyRefs(objectWithRefs) {
|
|
|
1204
1567
|
}
|
|
1205
1568
|
class CustomRefImpl {
|
|
1206
1569
|
constructor(factory) {
|
|
1207
|
-
this
|
|
1208
|
-
this.
|
|
1209
|
-
const
|
|
1210
|
-
|
|
1211
|
-
() => triggerRefValue(this)
|
|
1212
|
-
);
|
|
1570
|
+
this["__v_isRef"] = true;
|
|
1571
|
+
this._value = void 0;
|
|
1572
|
+
const dep = this.dep = new Dep();
|
|
1573
|
+
const { get, set } = factory(dep.track.bind(dep), dep.trigger.bind(dep));
|
|
1213
1574
|
this._get = get;
|
|
1214
1575
|
this._set = set;
|
|
1215
1576
|
}
|
|
1216
1577
|
get value() {
|
|
1217
|
-
return this._get();
|
|
1578
|
+
return this._value = this._get();
|
|
1218
1579
|
}
|
|
1219
1580
|
set value(newVal) {
|
|
1220
1581
|
this._set(newVal);
|
|
@@ -1238,11 +1599,12 @@ class ObjectRefImpl {
|
|
|
1238
1599
|
this._object = _object;
|
|
1239
1600
|
this._key = _key;
|
|
1240
1601
|
this._defaultValue = _defaultValue;
|
|
1241
|
-
this
|
|
1602
|
+
this["__v_isRef"] = true;
|
|
1603
|
+
this._value = void 0;
|
|
1242
1604
|
}
|
|
1243
1605
|
get value() {
|
|
1244
1606
|
const val = this._object[this._key];
|
|
1245
|
-
return val === void 0 ? this._defaultValue : val;
|
|
1607
|
+
return this._value = val === void 0 ? this._defaultValue : val;
|
|
1246
1608
|
}
|
|
1247
1609
|
set value(newVal) {
|
|
1248
1610
|
this._object[this._key] = newVal;
|
|
@@ -1254,11 +1616,12 @@ class ObjectRefImpl {
|
|
|
1254
1616
|
class GetterRefImpl {
|
|
1255
1617
|
constructor(_getter) {
|
|
1256
1618
|
this._getter = _getter;
|
|
1257
|
-
this
|
|
1258
|
-
this
|
|
1619
|
+
this["__v_isRef"] = true;
|
|
1620
|
+
this["__v_isReadonly"] = true;
|
|
1621
|
+
this._value = void 0;
|
|
1259
1622
|
}
|
|
1260
1623
|
get value() {
|
|
1261
|
-
return this._getter();
|
|
1624
|
+
return this._value = this._getter();
|
|
1262
1625
|
}
|
|
1263
1626
|
}
|
|
1264
1627
|
function toRef(source, key, defaultValue) {
|
|
@@ -1277,6 +1640,93 @@ function propertyToRef(source, key, defaultValue) {
|
|
|
1277
1640
|
return isRef(val) ? val : new ObjectRefImpl(source, key, defaultValue);
|
|
1278
1641
|
}
|
|
1279
1642
|
|
|
1643
|
+
class ComputedRefImpl {
|
|
1644
|
+
constructor(fn, setter, isSSR) {
|
|
1645
|
+
this.fn = fn;
|
|
1646
|
+
this.setter = setter;
|
|
1647
|
+
/**
|
|
1648
|
+
* @internal
|
|
1649
|
+
*/
|
|
1650
|
+
this._value = void 0;
|
|
1651
|
+
/**
|
|
1652
|
+
* @internal
|
|
1653
|
+
*/
|
|
1654
|
+
this.dep = new Dep(this);
|
|
1655
|
+
/**
|
|
1656
|
+
* @internal
|
|
1657
|
+
*/
|
|
1658
|
+
this.__v_isRef = true;
|
|
1659
|
+
// TODO isolatedDeclarations "__v_isReadonly"
|
|
1660
|
+
// A computed is also a subscriber that tracks other deps
|
|
1661
|
+
/**
|
|
1662
|
+
* @internal
|
|
1663
|
+
*/
|
|
1664
|
+
this.deps = void 0;
|
|
1665
|
+
/**
|
|
1666
|
+
* @internal
|
|
1667
|
+
*/
|
|
1668
|
+
this.depsTail = void 0;
|
|
1669
|
+
/**
|
|
1670
|
+
* @internal
|
|
1671
|
+
*/
|
|
1672
|
+
this.flags = 16;
|
|
1673
|
+
/**
|
|
1674
|
+
* @internal
|
|
1675
|
+
*/
|
|
1676
|
+
this.globalVersion = globalVersion - 1;
|
|
1677
|
+
// for backwards compat
|
|
1678
|
+
this.effect = this;
|
|
1679
|
+
this["__v_isReadonly"] = !setter;
|
|
1680
|
+
this.isSSR = isSSR;
|
|
1681
|
+
}
|
|
1682
|
+
/**
|
|
1683
|
+
* @internal
|
|
1684
|
+
*/
|
|
1685
|
+
notify() {
|
|
1686
|
+
this.flags |= 16;
|
|
1687
|
+
if (!(this.flags & 8) && // avoid infinite self recursion
|
|
1688
|
+
activeSub !== this) {
|
|
1689
|
+
batch(this);
|
|
1690
|
+
return true;
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1693
|
+
get value() {
|
|
1694
|
+
const link = this.dep.track({
|
|
1695
|
+
target: this,
|
|
1696
|
+
type: "get",
|
|
1697
|
+
key: "value"
|
|
1698
|
+
}) ;
|
|
1699
|
+
refreshComputed(this);
|
|
1700
|
+
if (link) {
|
|
1701
|
+
link.version = this.dep.version;
|
|
1702
|
+
}
|
|
1703
|
+
return this._value;
|
|
1704
|
+
}
|
|
1705
|
+
set value(newValue) {
|
|
1706
|
+
if (this.setter) {
|
|
1707
|
+
this.setter(newValue);
|
|
1708
|
+
} else {
|
|
1709
|
+
warn("Write operation failed: computed value is readonly");
|
|
1710
|
+
}
|
|
1711
|
+
}
|
|
1712
|
+
}
|
|
1713
|
+
function computed(getterOrOptions, debugOptions, isSSR = false) {
|
|
1714
|
+
let getter;
|
|
1715
|
+
let setter;
|
|
1716
|
+
if (isFunction$1(getterOrOptions)) {
|
|
1717
|
+
getter = getterOrOptions;
|
|
1718
|
+
} else {
|
|
1719
|
+
getter = getterOrOptions.get;
|
|
1720
|
+
setter = getterOrOptions.set;
|
|
1721
|
+
}
|
|
1722
|
+
const cRef = new ComputedRefImpl(getter, setter, isSSR);
|
|
1723
|
+
if (debugOptions && !isSSR) {
|
|
1724
|
+
cRef.onTrack = debugOptions.onTrack;
|
|
1725
|
+
cRef.onTrigger = debugOptions.onTrigger;
|
|
1726
|
+
}
|
|
1727
|
+
return cRef;
|
|
1728
|
+
}
|
|
1729
|
+
|
|
1280
1730
|
const TrackOpTypes = {
|
|
1281
1731
|
"GET": "get",
|
|
1282
1732
|
"HAS": "has",
|
|
@@ -1288,16 +1738,213 @@ const TriggerOpTypes = {
|
|
|
1288
1738
|
"DELETE": "delete",
|
|
1289
1739
|
"CLEAR": "clear"
|
|
1290
1740
|
};
|
|
1291
|
-
const
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1741
|
+
const INITIAL_WATCHER_VALUE = {};
|
|
1742
|
+
const cleanupMap = /* @__PURE__ */ new WeakMap();
|
|
1743
|
+
let activeWatcher = void 0;
|
|
1744
|
+
function getCurrentWatcher() {
|
|
1745
|
+
return activeWatcher;
|
|
1746
|
+
}
|
|
1747
|
+
function onWatcherCleanup(cleanupFn, failSilently = false, owner = activeWatcher) {
|
|
1748
|
+
if (owner) {
|
|
1749
|
+
let cleanups = cleanupMap.get(owner);
|
|
1750
|
+
if (!cleanups) cleanupMap.set(owner, cleanups = []);
|
|
1751
|
+
cleanups.push(cleanupFn);
|
|
1752
|
+
} else if (!failSilently) {
|
|
1753
|
+
warn(
|
|
1754
|
+
`onWatcherCleanup() was called when there was no active watcher to associate with.`
|
|
1755
|
+
);
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1758
|
+
function watch$1(source, cb, options = EMPTY_OBJ$1) {
|
|
1759
|
+
const { immediate, deep, once, scheduler, augmentJob, call } = options;
|
|
1760
|
+
const warnInvalidSource = (s) => {
|
|
1761
|
+
(options.onWarn || warn)(
|
|
1762
|
+
`Invalid watch source: `,
|
|
1763
|
+
s,
|
|
1764
|
+
`A watch source can only be a getter/effect function, a ref, a reactive object, or an array of these types.`
|
|
1765
|
+
);
|
|
1766
|
+
};
|
|
1767
|
+
const reactiveGetter = (source2) => {
|
|
1768
|
+
if (deep) return source2;
|
|
1769
|
+
if (isShallow(source2) || deep === false || deep === 0)
|
|
1770
|
+
return traverse(source2, 1);
|
|
1771
|
+
return traverse(source2);
|
|
1772
|
+
};
|
|
1773
|
+
let effect;
|
|
1774
|
+
let getter;
|
|
1775
|
+
let cleanup;
|
|
1776
|
+
let boundCleanup;
|
|
1777
|
+
let forceTrigger = false;
|
|
1778
|
+
let isMultiSource = false;
|
|
1779
|
+
if (isRef(source)) {
|
|
1780
|
+
getter = () => source.value;
|
|
1781
|
+
forceTrigger = isShallow(source);
|
|
1782
|
+
} else if (isReactive(source)) {
|
|
1783
|
+
getter = () => reactiveGetter(source);
|
|
1784
|
+
forceTrigger = true;
|
|
1785
|
+
} else if (isArray$1(source)) {
|
|
1786
|
+
isMultiSource = true;
|
|
1787
|
+
forceTrigger = source.some((s) => isReactive(s) || isShallow(s));
|
|
1788
|
+
getter = () => source.map((s) => {
|
|
1789
|
+
if (isRef(s)) {
|
|
1790
|
+
return s.value;
|
|
1791
|
+
} else if (isReactive(s)) {
|
|
1792
|
+
return reactiveGetter(s);
|
|
1793
|
+
} else if (isFunction$1(s)) {
|
|
1794
|
+
return call ? call(s, 2) : s();
|
|
1795
|
+
} else {
|
|
1796
|
+
warnInvalidSource(s);
|
|
1797
|
+
}
|
|
1798
|
+
});
|
|
1799
|
+
} else if (isFunction$1(source)) {
|
|
1800
|
+
if (cb) {
|
|
1801
|
+
getter = call ? () => call(source, 2) : source;
|
|
1802
|
+
} else {
|
|
1803
|
+
getter = () => {
|
|
1804
|
+
if (cleanup) {
|
|
1805
|
+
pauseTracking();
|
|
1806
|
+
try {
|
|
1807
|
+
cleanup();
|
|
1808
|
+
} finally {
|
|
1809
|
+
resetTracking();
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
const currentEffect = activeWatcher;
|
|
1813
|
+
activeWatcher = effect;
|
|
1814
|
+
try {
|
|
1815
|
+
return call ? call(source, 3, [boundCleanup]) : source(boundCleanup);
|
|
1816
|
+
} finally {
|
|
1817
|
+
activeWatcher = currentEffect;
|
|
1818
|
+
}
|
|
1819
|
+
};
|
|
1820
|
+
}
|
|
1821
|
+
} else {
|
|
1822
|
+
getter = NOOP;
|
|
1823
|
+
warnInvalidSource(source);
|
|
1824
|
+
}
|
|
1825
|
+
if (cb && deep) {
|
|
1826
|
+
const baseGetter = getter;
|
|
1827
|
+
const depth = deep === true ? Infinity : deep;
|
|
1828
|
+
getter = () => traverse(baseGetter(), depth);
|
|
1829
|
+
}
|
|
1830
|
+
const scope = getCurrentScope();
|
|
1831
|
+
const watchHandle = () => {
|
|
1832
|
+
effect.stop();
|
|
1833
|
+
if (scope) {
|
|
1834
|
+
remove(scope.effects, effect);
|
|
1835
|
+
}
|
|
1836
|
+
};
|
|
1837
|
+
if (once && cb) {
|
|
1838
|
+
const _cb = cb;
|
|
1839
|
+
cb = (...args) => {
|
|
1840
|
+
_cb(...args);
|
|
1841
|
+
watchHandle();
|
|
1842
|
+
};
|
|
1843
|
+
}
|
|
1844
|
+
let oldValue = isMultiSource ? new Array(source.length).fill(INITIAL_WATCHER_VALUE) : INITIAL_WATCHER_VALUE;
|
|
1845
|
+
const job = (immediateFirstRun) => {
|
|
1846
|
+
if (!(effect.flags & 1) || !effect.dirty && !immediateFirstRun) {
|
|
1847
|
+
return;
|
|
1848
|
+
}
|
|
1849
|
+
if (cb) {
|
|
1850
|
+
const newValue = effect.run();
|
|
1851
|
+
if (deep || forceTrigger || (isMultiSource ? newValue.some((v, i) => hasChanged(v, oldValue[i])) : hasChanged(newValue, oldValue))) {
|
|
1852
|
+
if (cleanup) {
|
|
1853
|
+
cleanup();
|
|
1854
|
+
}
|
|
1855
|
+
const currentWatcher = activeWatcher;
|
|
1856
|
+
activeWatcher = effect;
|
|
1857
|
+
try {
|
|
1858
|
+
const args = [
|
|
1859
|
+
newValue,
|
|
1860
|
+
// pass undefined as the old value when it's changed for the first time
|
|
1861
|
+
oldValue === INITIAL_WATCHER_VALUE ? void 0 : isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE ? [] : oldValue,
|
|
1862
|
+
boundCleanup
|
|
1863
|
+
];
|
|
1864
|
+
call ? call(cb, 3, args) : (
|
|
1865
|
+
// @ts-expect-error
|
|
1866
|
+
cb(...args)
|
|
1867
|
+
);
|
|
1868
|
+
oldValue = newValue;
|
|
1869
|
+
} finally {
|
|
1870
|
+
activeWatcher = currentWatcher;
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1873
|
+
} else {
|
|
1874
|
+
effect.run();
|
|
1875
|
+
}
|
|
1876
|
+
};
|
|
1877
|
+
if (augmentJob) {
|
|
1878
|
+
augmentJob(job);
|
|
1879
|
+
}
|
|
1880
|
+
effect = new ReactiveEffect(getter);
|
|
1881
|
+
effect.scheduler = scheduler ? () => scheduler(job, false) : job;
|
|
1882
|
+
boundCleanup = (fn) => onWatcherCleanup(fn, false, effect);
|
|
1883
|
+
cleanup = effect.onStop = () => {
|
|
1884
|
+
const cleanups = cleanupMap.get(effect);
|
|
1885
|
+
if (cleanups) {
|
|
1886
|
+
if (call) {
|
|
1887
|
+
call(cleanups, 4);
|
|
1888
|
+
} else {
|
|
1889
|
+
for (const cleanup2 of cleanups) cleanup2();
|
|
1890
|
+
}
|
|
1891
|
+
cleanupMap.delete(effect);
|
|
1892
|
+
}
|
|
1893
|
+
};
|
|
1894
|
+
{
|
|
1895
|
+
effect.onTrack = options.onTrack;
|
|
1896
|
+
effect.onTrigger = options.onTrigger;
|
|
1897
|
+
}
|
|
1898
|
+
if (cb) {
|
|
1899
|
+
if (immediate) {
|
|
1900
|
+
job(true);
|
|
1901
|
+
} else {
|
|
1902
|
+
oldValue = effect.run();
|
|
1903
|
+
}
|
|
1904
|
+
} else if (scheduler) {
|
|
1905
|
+
scheduler(job.bind(null, true), true);
|
|
1906
|
+
} else {
|
|
1907
|
+
effect.run();
|
|
1908
|
+
}
|
|
1909
|
+
watchHandle.pause = effect.pause.bind(effect);
|
|
1910
|
+
watchHandle.resume = effect.resume.bind(effect);
|
|
1911
|
+
watchHandle.stop = watchHandle;
|
|
1912
|
+
return watchHandle;
|
|
1913
|
+
}
|
|
1914
|
+
function traverse(value, depth = Infinity, seen) {
|
|
1915
|
+
if (depth <= 0 || !isObject$1(value) || value["__v_skip"]) {
|
|
1916
|
+
return value;
|
|
1917
|
+
}
|
|
1918
|
+
seen = seen || /* @__PURE__ */ new Set();
|
|
1919
|
+
if (seen.has(value)) {
|
|
1920
|
+
return value;
|
|
1921
|
+
}
|
|
1922
|
+
seen.add(value);
|
|
1923
|
+
depth--;
|
|
1924
|
+
if (isRef(value)) {
|
|
1925
|
+
traverse(value.value, depth, seen);
|
|
1926
|
+
} else if (isArray$1(value)) {
|
|
1927
|
+
for (let i = 0; i < value.length; i++) {
|
|
1928
|
+
traverse(value[i], depth, seen);
|
|
1929
|
+
}
|
|
1930
|
+
} else if (isSet(value) || isMap(value)) {
|
|
1931
|
+
value.forEach((v) => {
|
|
1932
|
+
traverse(v, depth, seen);
|
|
1933
|
+
});
|
|
1934
|
+
} else if (isPlainObject$1(value)) {
|
|
1935
|
+
for (const key in value) {
|
|
1936
|
+
traverse(value[key], depth, seen);
|
|
1937
|
+
}
|
|
1938
|
+
for (const key of Object.getOwnPropertySymbols(value)) {
|
|
1939
|
+
if (Object.prototype.propertyIsEnumerable.call(value, key)) {
|
|
1940
|
+
traverse(value[key], depth, seen);
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
return value;
|
|
1945
|
+
}
|
|
1298
1946
|
|
|
1299
|
-
|
|
1300
|
-
const NOOP = () => { };
|
|
1947
|
+
const EMPTY_OBJ = Object.freeze({}) ;
|
|
1301
1948
|
const { isArray } = Array;
|
|
1302
1949
|
const extend = Object.assign;
|
|
1303
1950
|
function exclude(obj, keys) {
|
|
@@ -1325,27 +1972,16 @@ function isPlainObject(x) {
|
|
|
1325
1972
|
function isFunction(x) {
|
|
1326
1973
|
return typeof x === 'function';
|
|
1327
1974
|
}
|
|
1328
|
-
function isMap(x) {
|
|
1329
|
-
return getType(x) === 'Map';
|
|
1330
|
-
}
|
|
1331
|
-
function isSet(x) {
|
|
1332
|
-
return getType(x) === 'Set';
|
|
1333
|
-
}
|
|
1334
|
-
// Compare whether a value has changed, accounting for NaN.
|
|
1335
|
-
function hasChanged(value, oldValue) {
|
|
1336
|
-
// eslint-disable-next-line no-self-compare
|
|
1337
|
-
return value !== oldValue && (value === value || oldValue === oldValue);
|
|
1338
|
-
}
|
|
1339
|
-
function remove(arr, el) {
|
|
1340
|
-
const i = arr.indexOf(el);
|
|
1341
|
-
if (i > -1) {
|
|
1342
|
-
arr.splice(i, 1);
|
|
1343
|
-
}
|
|
1344
|
-
}
|
|
1345
1975
|
function toHiddenField(name) {
|
|
1346
1976
|
return `__${name}__`;
|
|
1347
1977
|
}
|
|
1348
1978
|
|
|
1979
|
+
/* eslint-disable no-bitwise, unicorn/prefer-math-trunc, @typescript-eslint/prefer-literal-enum-member */
|
|
1980
|
+
var SchedulerJobFlags;
|
|
1981
|
+
(function (SchedulerJobFlags) {
|
|
1982
|
+
SchedulerJobFlags[SchedulerJobFlags["QUEUED"] = 1] = "QUEUED";
|
|
1983
|
+
SchedulerJobFlags[SchedulerJobFlags["ALLOW_RECURSE"] = 4] = "ALLOW_RECURSE";
|
|
1984
|
+
})(SchedulerJobFlags || (SchedulerJobFlags = {}));
|
|
1349
1985
|
let isFlushing = false;
|
|
1350
1986
|
let isFlushPending = false;
|
|
1351
1987
|
const queue = [];
|
|
@@ -1354,7 +1990,7 @@ const pendingPostFlushCbs = [];
|
|
|
1354
1990
|
let activePostFlushCbs = null;
|
|
1355
1991
|
let postFlushIndex = 0;
|
|
1356
1992
|
// eslint-disable-next-line spaced-comment
|
|
1357
|
-
const resolvedPromise =
|
|
1993
|
+
const resolvedPromise = /*@__PURE__*/ Promise.resolve();
|
|
1358
1994
|
let currentFlushPromise = null;
|
|
1359
1995
|
const RECURSION_LIMIT = 100;
|
|
1360
1996
|
function nextTick(fn) {
|
|
@@ -1363,15 +1999,9 @@ function nextTick(fn) {
|
|
|
1363
1999
|
return fn ? p.then(fn) : p;
|
|
1364
2000
|
}
|
|
1365
2001
|
function queueJob(job) {
|
|
1366
|
-
|
|
1367
|
-
// by default the search index includes the current job that is being run
|
|
1368
|
-
// so it cannot recursively trigger itself again.
|
|
1369
|
-
// if the job is a watch() callback, the search will start with a +1 index to
|
|
1370
|
-
// allow it recursively trigger itself - it is the user's responsibility to
|
|
1371
|
-
// ensure it doesn't end up in an infinite loop.
|
|
1372
|
-
if (queue.length === 0 ||
|
|
1373
|
-
!queue.includes(job, isFlushing && job.allowRecurse ? flushIndex + 1 : flushIndex)) {
|
|
2002
|
+
if (!(job.flags & SchedulerJobFlags.QUEUED)) {
|
|
1374
2003
|
queue.push(job);
|
|
2004
|
+
job.flags |= SchedulerJobFlags.QUEUED;
|
|
1375
2005
|
queueFlush();
|
|
1376
2006
|
}
|
|
1377
2007
|
}
|
|
@@ -1383,9 +2013,9 @@ function queueFlush() {
|
|
|
1383
2013
|
}
|
|
1384
2014
|
}
|
|
1385
2015
|
function queuePostFlushCb(cb) {
|
|
1386
|
-
if (!
|
|
1387
|
-
!activePostFlushCbs.includes(cb, cb.allowRecurse ? postFlushIndex + 1 : postFlushIndex)) {
|
|
2016
|
+
if (!(cb.flags & SchedulerJobFlags.QUEUED)) {
|
|
1388
2017
|
pendingPostFlushCbs.push(cb);
|
|
2018
|
+
cb.flags |= SchedulerJobFlags.QUEUED;
|
|
1389
2019
|
}
|
|
1390
2020
|
}
|
|
1391
2021
|
function flushPostFlushCbs() {
|
|
@@ -1394,8 +2024,11 @@ function flushPostFlushCbs() {
|
|
|
1394
2024
|
pendingPostFlushCbs.length = 0;
|
|
1395
2025
|
for (postFlushIndex = 0; postFlushIndex < activePostFlushCbs.length; postFlushIndex++) {
|
|
1396
2026
|
const cb = activePostFlushCbs[postFlushIndex];
|
|
1397
|
-
if (cb.
|
|
1398
|
-
cb
|
|
2027
|
+
if (cb.flags & SchedulerJobFlags.ALLOW_RECURSE) {
|
|
2028
|
+
cb.flags &= ~SchedulerJobFlags.QUEUED;
|
|
2029
|
+
}
|
|
2030
|
+
cb();
|
|
2031
|
+
cb.flags &= ~SchedulerJobFlags.QUEUED;
|
|
1399
2032
|
}
|
|
1400
2033
|
activePostFlushCbs = null;
|
|
1401
2034
|
postFlushIndex = 0;
|
|
@@ -1418,16 +2051,25 @@ function flushJobs(seen) {
|
|
|
1418
2051
|
try {
|
|
1419
2052
|
for (flushIndex = 0; flushIndex < queue.length; flushIndex++) {
|
|
1420
2053
|
const job = queue[flushIndex];
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
job
|
|
2054
|
+
/* istanbul ignore if -- @preserve */
|
|
2055
|
+
if (true && check(job)) {
|
|
2056
|
+
continue;
|
|
2057
|
+
}
|
|
2058
|
+
if (job.flags & SchedulerJobFlags.ALLOW_RECURSE) {
|
|
2059
|
+
job.flags &= ~SchedulerJobFlags.QUEUED;
|
|
2060
|
+
}
|
|
2061
|
+
job();
|
|
2062
|
+
if (!(job.flags & SchedulerJobFlags.ALLOW_RECURSE)) {
|
|
2063
|
+
job.flags &= ~SchedulerJobFlags.QUEUED;
|
|
1427
2064
|
}
|
|
1428
2065
|
}
|
|
1429
2066
|
}
|
|
1430
2067
|
finally {
|
|
2068
|
+
// If there was an error we still need to clear the QUEUED flags
|
|
2069
|
+
for (; flushIndex < queue.length; flushIndex++) {
|
|
2070
|
+
const job = queue[flushIndex];
|
|
2071
|
+
job.flags &= ~SchedulerJobFlags.QUEUED;
|
|
2072
|
+
}
|
|
1431
2073
|
flushIndex = 0;
|
|
1432
2074
|
queue.length = 0;
|
|
1433
2075
|
isFlushing = false;
|
|
@@ -1459,8 +2101,6 @@ function watchSyncEffect(effect, options) {
|
|
|
1459
2101
|
return doWatch(effect, null, extend({}, options, { flush: 'sync' })
|
|
1460
2102
|
);
|
|
1461
2103
|
}
|
|
1462
|
-
// Initial value for watchers to trigger on undefined initial values
|
|
1463
|
-
const INITIAL_WATCHER_VALUE = {};
|
|
1464
2104
|
// Implementation
|
|
1465
2105
|
function watch(source, cb, options) {
|
|
1466
2106
|
if (!isFunction(cb)) {
|
|
@@ -1470,19 +2110,8 @@ function watch(source, cb, options) {
|
|
|
1470
2110
|
}
|
|
1471
2111
|
return doWatch(source, cb, options);
|
|
1472
2112
|
}
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
if (cb && once) {
|
|
1476
|
-
const _cb = cb;
|
|
1477
|
-
cb = (...args) => {
|
|
1478
|
-
_cb(...args);
|
|
1479
|
-
unwatch();
|
|
1480
|
-
};
|
|
1481
|
-
}
|
|
1482
|
-
if (deep !== undefined && typeof deep === 'number') {
|
|
1483
|
-
console.warn(`watch() "deep" option with number value will be used as watch depth in future versions. ` +
|
|
1484
|
-
`Please use a boolean instead to avoid potential breakage.`);
|
|
1485
|
-
}
|
|
2113
|
+
function doWatch(source, cb, options = EMPTY_OBJ) {
|
|
2114
|
+
const { immediate, deep, flush, once } = options;
|
|
1486
2115
|
if (!cb) {
|
|
1487
2116
|
if (immediate !== undefined) {
|
|
1488
2117
|
console.warn(`watch() "immediate" option is only respected when using the ` +
|
|
@@ -1497,193 +2126,34 @@ function doWatch(source, cb, { immediate, deep, flush, once, onTrack, onTrigger
|
|
|
1497
2126
|
`watch(source, callback, options?) signature.`);
|
|
1498
2127
|
}
|
|
1499
2128
|
}
|
|
1500
|
-
const
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
const reactiveGetter = (source) => deep === true ?
|
|
1505
|
-
source // Traverse will happen in wrapped getter below
|
|
1506
|
-
// For deep: false, only traverse root-level properties
|
|
1507
|
-
: traverse(source, deep === false ? 1 : undefined);
|
|
1508
|
-
let getter;
|
|
1509
|
-
let forceTrigger = false;
|
|
1510
|
-
let isMultiSource = false;
|
|
1511
|
-
if (isRef(source)) {
|
|
1512
|
-
getter = () => source.value;
|
|
1513
|
-
forceTrigger = isShallow(source);
|
|
1514
|
-
}
|
|
1515
|
-
else if (isReactive(source)) {
|
|
1516
|
-
getter = () => reactiveGetter(source);
|
|
1517
|
-
forceTrigger = true;
|
|
1518
|
-
}
|
|
1519
|
-
else if (isArray(source)) {
|
|
1520
|
-
isMultiSource = true;
|
|
1521
|
-
forceTrigger = source.some((s) => isReactive(s) || isShallow(s));
|
|
1522
|
-
getter = () => source.map((s) => {
|
|
1523
|
-
if (isRef(s)) {
|
|
1524
|
-
return s.value;
|
|
1525
|
-
}
|
|
1526
|
-
if (isReactive(s)) {
|
|
1527
|
-
return reactiveGetter(s);
|
|
1528
|
-
}
|
|
1529
|
-
if (isFunction(s)) {
|
|
1530
|
-
return s();
|
|
1531
|
-
}
|
|
1532
|
-
/* istanbul ignore else -- @preserve */
|
|
1533
|
-
{
|
|
1534
|
-
warnInvalidSource(s);
|
|
1535
|
-
}
|
|
1536
|
-
return undefined;
|
|
1537
|
-
});
|
|
1538
|
-
}
|
|
1539
|
-
else if (isFunction(source)) {
|
|
1540
|
-
if (cb) {
|
|
1541
|
-
// Getter with cb
|
|
1542
|
-
getter = () => source();
|
|
1543
|
-
}
|
|
1544
|
-
else {
|
|
1545
|
-
// No cb -> simple effect
|
|
1546
|
-
getter = () => {
|
|
1547
|
-
if (cleanup) {
|
|
1548
|
-
cleanup();
|
|
1549
|
-
}
|
|
1550
|
-
return source(onCleanup);
|
|
1551
|
-
};
|
|
1552
|
-
}
|
|
1553
|
-
}
|
|
1554
|
-
else {
|
|
1555
|
-
getter = NOOP;
|
|
1556
|
-
/* istanbul ignore else -- @preserve */
|
|
1557
|
-
{
|
|
1558
|
-
warnInvalidSource(source);
|
|
1559
|
-
}
|
|
1560
|
-
}
|
|
1561
|
-
if (cb && deep) {
|
|
1562
|
-
const baseGetter = getter;
|
|
1563
|
-
getter = () => traverse(baseGetter());
|
|
1564
|
-
}
|
|
1565
|
-
let cleanup;
|
|
1566
|
-
const onCleanup = (fn) => {
|
|
1567
|
-
// eslint-disable-next-line no-multi-assign
|
|
1568
|
-
cleanup = effect.onStop = () => {
|
|
1569
|
-
fn();
|
|
1570
|
-
// eslint-disable-next-line no-multi-assign
|
|
1571
|
-
cleanup = effect.onStop = undefined;
|
|
1572
|
-
};
|
|
1573
|
-
};
|
|
1574
|
-
let oldValue = isMultiSource ?
|
|
1575
|
-
Array.from({ length: source.length }).fill(INITIAL_WATCHER_VALUE)
|
|
1576
|
-
: INITIAL_WATCHER_VALUE;
|
|
1577
|
-
const job = () => {
|
|
1578
|
-
if (!effect.active || !effect.dirty) {
|
|
1579
|
-
return;
|
|
1580
|
-
}
|
|
1581
|
-
if (cb) {
|
|
1582
|
-
// Watch(source, cb)
|
|
1583
|
-
const newValue = effect.run();
|
|
1584
|
-
if (deep ||
|
|
1585
|
-
forceTrigger ||
|
|
1586
|
-
(isMultiSource ?
|
|
1587
|
-
newValue.some((v, i) => hasChanged(v, oldValue[i]))
|
|
1588
|
-
: hasChanged(newValue, oldValue))) {
|
|
1589
|
-
// Cleanup before running cb again
|
|
1590
|
-
if (cleanup) {
|
|
1591
|
-
cleanup();
|
|
1592
|
-
}
|
|
1593
|
-
cb(newValue,
|
|
1594
|
-
// Pass undefined as the old value when it's changed for the first time
|
|
1595
|
-
oldValue === INITIAL_WATCHER_VALUE ? undefined
|
|
1596
|
-
: isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE ? []
|
|
1597
|
-
: oldValue, onCleanup);
|
|
1598
|
-
oldValue = newValue;
|
|
1599
|
-
}
|
|
1600
|
-
}
|
|
1601
|
-
else {
|
|
1602
|
-
// WatchEffect
|
|
1603
|
-
effect.run();
|
|
1604
|
-
}
|
|
1605
|
-
};
|
|
1606
|
-
// Important: mark the job as a watcher callback so that scheduler knows
|
|
1607
|
-
// it is allowed to self-trigger
|
|
1608
|
-
job.allowRecurse = Boolean(cb);
|
|
1609
|
-
let scheduler;
|
|
1610
|
-
if (flush === 'sync') {
|
|
1611
|
-
scheduler = job; // The scheduler function gets called directly
|
|
1612
|
-
}
|
|
1613
|
-
else if (flush === 'post') {
|
|
1614
|
-
scheduler = () => {
|
|
2129
|
+
const baseWatchOptions = extend({}, options);
|
|
2130
|
+
// Scheduler
|
|
2131
|
+
if (flush === 'post') {
|
|
2132
|
+
baseWatchOptions.scheduler = (job) => {
|
|
1615
2133
|
queuePostFlushCb(job);
|
|
1616
2134
|
};
|
|
1617
2135
|
}
|
|
1618
|
-
else {
|
|
1619
|
-
scheduler = () => {
|
|
1620
|
-
|
|
2136
|
+
else if (flush !== 'sync') {
|
|
2137
|
+
baseWatchOptions.scheduler = (job, isFirstRun) => {
|
|
2138
|
+
if (isFirstRun) {
|
|
2139
|
+
job();
|
|
2140
|
+
}
|
|
2141
|
+
else {
|
|
2142
|
+
queueJob(job);
|
|
2143
|
+
}
|
|
1621
2144
|
};
|
|
1622
2145
|
}
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
if (
|
|
1628
|
-
//
|
|
1629
|
-
|
|
2146
|
+
// @ts-expect-error
|
|
2147
|
+
baseWatchOptions.augmentJob = (job) => {
|
|
2148
|
+
// Important: mark the job as a watcher callback so that scheduler knows
|
|
2149
|
+
// it is allowed to self-trigger
|
|
2150
|
+
if (cb) {
|
|
2151
|
+
// eslint-disable-next-line no-bitwise
|
|
2152
|
+
job.flags |= SchedulerJobFlags.ALLOW_RECURSE;
|
|
1630
2153
|
}
|
|
1631
2154
|
};
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
effect.onTrack = onTrack;
|
|
1635
|
-
effect.onTrigger = onTrigger;
|
|
1636
|
-
}
|
|
1637
|
-
// Initial run
|
|
1638
|
-
if (cb) {
|
|
1639
|
-
if (immediate) {
|
|
1640
|
-
job();
|
|
1641
|
-
}
|
|
1642
|
-
else {
|
|
1643
|
-
oldValue = effect.run();
|
|
1644
|
-
}
|
|
1645
|
-
}
|
|
1646
|
-
else {
|
|
1647
|
-
effect.run();
|
|
1648
|
-
}
|
|
1649
|
-
return unwatch;
|
|
1650
|
-
}
|
|
1651
|
-
function traverse(value, depth = Number.POSITIVE_INFINITY, seen) {
|
|
1652
|
-
if (depth <= 0 || !isObject(value) || value[ReactiveFlags.SKIP]) {
|
|
1653
|
-
return value;
|
|
1654
|
-
}
|
|
1655
|
-
seen = seen || new Set();
|
|
1656
|
-
if (seen.has(value)) {
|
|
1657
|
-
return value;
|
|
1658
|
-
}
|
|
1659
|
-
seen.add(value);
|
|
1660
|
-
depth--;
|
|
1661
|
-
/* istanbul ignore else -- @preserve */
|
|
1662
|
-
if (isRef(value)) {
|
|
1663
|
-
traverse(value.value, depth, seen);
|
|
1664
|
-
}
|
|
1665
|
-
else if (isArray(value)) {
|
|
1666
|
-
for (let i = 0; i < value.length; i++) {
|
|
1667
|
-
traverse(value[i], depth, seen);
|
|
1668
|
-
}
|
|
1669
|
-
}
|
|
1670
|
-
else if (isSet(value) || isMap(value)) {
|
|
1671
|
-
value.forEach((v) => {
|
|
1672
|
-
traverse(v, depth, seen);
|
|
1673
|
-
});
|
|
1674
|
-
}
|
|
1675
|
-
else if (isPlainObject(value)) {
|
|
1676
|
-
// eslint-disable-next-line guard-for-in
|
|
1677
|
-
for (const key in value) {
|
|
1678
|
-
traverse(value[key], depth, seen);
|
|
1679
|
-
}
|
|
1680
|
-
for (const key of Object.getOwnPropertySymbols(value)) {
|
|
1681
|
-
if (Object.prototype.propertyIsEnumerable.call(value, key)) {
|
|
1682
|
-
traverse(value[key], depth, seen);
|
|
1683
|
-
}
|
|
1684
|
-
}
|
|
1685
|
-
}
|
|
1686
|
-
return value;
|
|
2155
|
+
const watchHandle = watch$1(source, cb, baseWatchOptions);
|
|
2156
|
+
return watchHandle;
|
|
1687
2157
|
}
|
|
1688
2158
|
|
|
1689
2159
|
const provides = Object.create(null);
|
|
@@ -1909,15 +2379,20 @@ function definePage(optionsOrSetup, config) {
|
|
|
1909
2379
|
};
|
|
1910
2380
|
const bindings = setup(query, context);
|
|
1911
2381
|
if (bindings !== undefined) {
|
|
2382
|
+
let data;
|
|
1912
2383
|
Object.keys(bindings).forEach((key) => {
|
|
1913
2384
|
const value = bindings[key];
|
|
1914
2385
|
if (isFunction(value)) {
|
|
1915
2386
|
this[key] = value;
|
|
1916
2387
|
return;
|
|
1917
2388
|
}
|
|
1918
|
-
|
|
2389
|
+
data = data || {};
|
|
2390
|
+
data[key] = deepToRaw(value);
|
|
1919
2391
|
deepWatch.call(this, key, value);
|
|
1920
2392
|
});
|
|
2393
|
+
if (data !== undefined) {
|
|
2394
|
+
this.setData(data, flushPostFlushCbs);
|
|
2395
|
+
}
|
|
1921
2396
|
}
|
|
1922
2397
|
unsetCurrentPage();
|
|
1923
2398
|
if (originOnLoad !== undefined) {
|
|
@@ -2088,15 +2563,20 @@ function defineComponent(optionsOrSetup, config) {
|
|
|
2088
2563
|
const bindings = setup(shallowReadonly(this.__props__)
|
|
2089
2564
|
, context);
|
|
2090
2565
|
if (bindings !== undefined) {
|
|
2566
|
+
let data;
|
|
2091
2567
|
Object.keys(bindings).forEach((key) => {
|
|
2092
2568
|
const value = bindings[key];
|
|
2093
2569
|
if (isFunction(value)) {
|
|
2094
2570
|
this[key] = value;
|
|
2095
2571
|
return;
|
|
2096
2572
|
}
|
|
2097
|
-
|
|
2573
|
+
data = data || {};
|
|
2574
|
+
data[key] = deepToRaw(value);
|
|
2098
2575
|
deepWatch.call(this, key, value);
|
|
2099
2576
|
});
|
|
2577
|
+
if (data !== undefined) {
|
|
2578
|
+
this.setData(data, flushPostFlushCbs);
|
|
2579
|
+
}
|
|
2100
2580
|
}
|
|
2101
2581
|
unsetCurrentComponent();
|
|
2102
2582
|
if (originAttached !== undefined) {
|
|
@@ -2421,6 +2901,7 @@ exports.definePage = definePage;
|
|
|
2421
2901
|
exports.effect = effect;
|
|
2422
2902
|
exports.effectScope = effectScope;
|
|
2423
2903
|
exports.getCurrentScope = getCurrentScope;
|
|
2904
|
+
exports.getCurrentWatcher = getCurrentWatcher;
|
|
2424
2905
|
exports.inject = inject;
|
|
2425
2906
|
exports.isProxy = isProxy;
|
|
2426
2907
|
exports.isReactive = isReactive;
|
|
@@ -2454,6 +2935,7 @@ exports.onTabItemTap = onTabItemTap;
|
|
|
2454
2935
|
exports.onThemeChange = onThemeChange;
|
|
2455
2936
|
exports.onUnhandledRejection = onUnhandledRejection;
|
|
2456
2937
|
exports.onUnload = onUnload;
|
|
2938
|
+
exports.onWatcherCleanup = onWatcherCleanup;
|
|
2457
2939
|
exports.provide = provide;
|
|
2458
2940
|
exports.proxyRefs = proxyRefs;
|
|
2459
2941
|
exports.reactive = reactive;
|