@vue/reactivity 3.4.26 → 3.5.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/reactivity.cjs.js +728 -345
- package/dist/reactivity.cjs.prod.js +656 -299
- package/dist/reactivity.d.ts +216 -185
- package/dist/reactivity.esm-browser.js +721 -345
- package/dist/reactivity.esm-browser.prod.js +2 -2
- package/dist/reactivity.esm-bundler.js +732 -344
- package/dist/reactivity.global.js +728 -347
- package/dist/reactivity.global.prod.js +2 -2
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vue/reactivity v3.
|
|
2
|
+
* @vue/reactivity v3.5.0-alpha.2
|
|
3
3
|
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
4
4
|
* @license MIT
|
|
5
5
|
**/
|
|
@@ -13,8 +13,6 @@ var VueReactivity = (function (exports) {
|
|
|
13
13
|
return (val) => set.has(val);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
const NOOP = () => {
|
|
17
|
-
};
|
|
18
16
|
const extend = Object.assign;
|
|
19
17
|
const hasOwnProperty$1 = Object.prototype.hasOwnProperty;
|
|
20
18
|
const hasOwn = (val, key) => hasOwnProperty$1.call(val, key);
|
|
@@ -136,156 +134,296 @@ var VueReactivity = (function (exports) {
|
|
|
136
134
|
function effectScope(detached) {
|
|
137
135
|
return new EffectScope(detached);
|
|
138
136
|
}
|
|
139
|
-
function recordEffectScope(effect, scope = activeEffectScope) {
|
|
140
|
-
if (scope && scope.active) {
|
|
141
|
-
scope.effects.push(effect);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
137
|
function getCurrentScope() {
|
|
145
138
|
return activeEffectScope;
|
|
146
139
|
}
|
|
147
|
-
function onScopeDispose(fn) {
|
|
140
|
+
function onScopeDispose(fn, failSilently = false) {
|
|
148
141
|
if (activeEffectScope) {
|
|
149
142
|
activeEffectScope.cleanups.push(fn);
|
|
150
|
-
} else {
|
|
143
|
+
} else if (!failSilently) {
|
|
151
144
|
warn(
|
|
152
145
|
`onScopeDispose() is called when there is no active effect scope to be associated with.`
|
|
153
146
|
);
|
|
154
147
|
}
|
|
155
148
|
}
|
|
156
149
|
|
|
157
|
-
let
|
|
150
|
+
let activeSub;
|
|
151
|
+
const EffectFlags = {
|
|
152
|
+
"ACTIVE": 1,
|
|
153
|
+
"1": "ACTIVE",
|
|
154
|
+
"RUNNING": 2,
|
|
155
|
+
"2": "RUNNING",
|
|
156
|
+
"TRACKING": 4,
|
|
157
|
+
"4": "TRACKING",
|
|
158
|
+
"NOTIFIED": 8,
|
|
159
|
+
"8": "NOTIFIED",
|
|
160
|
+
"DIRTY": 16,
|
|
161
|
+
"16": "DIRTY",
|
|
162
|
+
"ALLOW_RECURSE": 32,
|
|
163
|
+
"32": "ALLOW_RECURSE",
|
|
164
|
+
"NO_BATCH": 64,
|
|
165
|
+
"64": "NO_BATCH"
|
|
166
|
+
};
|
|
158
167
|
class ReactiveEffect {
|
|
159
|
-
constructor(fn
|
|
168
|
+
constructor(fn) {
|
|
160
169
|
this.fn = fn;
|
|
161
|
-
this.trigger = trigger;
|
|
162
|
-
this.scheduler = scheduler;
|
|
163
|
-
this.active = true;
|
|
164
|
-
this.deps = [];
|
|
165
170
|
/**
|
|
166
171
|
* @internal
|
|
167
172
|
*/
|
|
168
|
-
this.
|
|
173
|
+
this.deps = void 0;
|
|
169
174
|
/**
|
|
170
175
|
* @internal
|
|
171
176
|
*/
|
|
172
|
-
this.
|
|
177
|
+
this.depsTail = void 0;
|
|
173
178
|
/**
|
|
174
179
|
* @internal
|
|
175
180
|
*/
|
|
176
|
-
this.
|
|
181
|
+
this.flags = 1 | 4;
|
|
177
182
|
/**
|
|
178
183
|
* @internal
|
|
179
184
|
*/
|
|
180
|
-
this.
|
|
185
|
+
this.nextEffect = void 0;
|
|
181
186
|
/**
|
|
182
187
|
* @internal
|
|
183
188
|
*/
|
|
184
|
-
this.
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
if (this._dirtyLevel === 2 || this._dirtyLevel === 3) {
|
|
189
|
-
this._dirtyLevel = 1;
|
|
190
|
-
pauseTracking();
|
|
191
|
-
for (let i = 0; i < this._depsLength; i++) {
|
|
192
|
-
const dep = this.deps[i];
|
|
193
|
-
if (dep.computed) {
|
|
194
|
-
triggerComputed(dep.computed);
|
|
195
|
-
if (this._dirtyLevel >= 4) {
|
|
196
|
-
break;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
if (this._dirtyLevel === 1) {
|
|
201
|
-
this._dirtyLevel = 0;
|
|
202
|
-
}
|
|
203
|
-
resetTracking();
|
|
189
|
+
this.cleanup = void 0;
|
|
190
|
+
this.scheduler = void 0;
|
|
191
|
+
if (activeEffectScope && activeEffectScope.active) {
|
|
192
|
+
activeEffectScope.effects.push(this);
|
|
204
193
|
}
|
|
205
|
-
return this._dirtyLevel >= 4;
|
|
206
194
|
}
|
|
207
|
-
|
|
208
|
-
|
|
195
|
+
/**
|
|
196
|
+
* @internal
|
|
197
|
+
*/
|
|
198
|
+
notify() {
|
|
199
|
+
if (this.flags & 2 && !(this.flags & 32)) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
if (this.flags & 64) {
|
|
203
|
+
return this.trigger();
|
|
204
|
+
}
|
|
205
|
+
if (!(this.flags & 8)) {
|
|
206
|
+
this.flags |= 8;
|
|
207
|
+
this.nextEffect = batchedEffect;
|
|
208
|
+
batchedEffect = this;
|
|
209
|
+
}
|
|
209
210
|
}
|
|
210
211
|
run() {
|
|
211
|
-
this.
|
|
212
|
-
if (!this.active) {
|
|
212
|
+
if (!(this.flags & 1)) {
|
|
213
213
|
return this.fn();
|
|
214
214
|
}
|
|
215
|
-
|
|
216
|
-
|
|
215
|
+
this.flags |= 2;
|
|
216
|
+
cleanupEffect(this);
|
|
217
|
+
prepareDeps(this);
|
|
218
|
+
const prevEffect = activeSub;
|
|
219
|
+
const prevShouldTrack = shouldTrack;
|
|
220
|
+
activeSub = this;
|
|
221
|
+
shouldTrack = true;
|
|
217
222
|
try {
|
|
218
|
-
shouldTrack = true;
|
|
219
|
-
activeEffect = this;
|
|
220
|
-
this._runnings++;
|
|
221
|
-
preCleanupEffect(this);
|
|
222
223
|
return this.fn();
|
|
223
224
|
} finally {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
225
|
+
if (activeSub !== this) {
|
|
226
|
+
warn(
|
|
227
|
+
"Active effect was not restored correctly - this is likely a Vue internal bug."
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
cleanupDeps(this);
|
|
231
|
+
activeSub = prevEffect;
|
|
232
|
+
shouldTrack = prevShouldTrack;
|
|
233
|
+
this.flags &= ~2;
|
|
228
234
|
}
|
|
229
235
|
}
|
|
230
236
|
stop() {
|
|
231
|
-
if (this.
|
|
232
|
-
|
|
233
|
-
|
|
237
|
+
if (this.flags & 1) {
|
|
238
|
+
for (let link = this.deps; link; link = link.nextDep) {
|
|
239
|
+
removeSub(link);
|
|
240
|
+
}
|
|
241
|
+
this.deps = this.depsTail = void 0;
|
|
242
|
+
cleanupEffect(this);
|
|
234
243
|
this.onStop && this.onStop();
|
|
235
|
-
this.
|
|
244
|
+
this.flags &= ~1;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
trigger() {
|
|
248
|
+
if (this.scheduler) {
|
|
249
|
+
this.scheduler();
|
|
250
|
+
} else {
|
|
251
|
+
this.runIfDirty();
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* @internal
|
|
256
|
+
*/
|
|
257
|
+
runIfDirty() {
|
|
258
|
+
if (isDirty(this)) {
|
|
259
|
+
this.run();
|
|
236
260
|
}
|
|
237
261
|
}
|
|
262
|
+
get dirty() {
|
|
263
|
+
return isDirty(this);
|
|
264
|
+
}
|
|
238
265
|
}
|
|
239
|
-
|
|
240
|
-
|
|
266
|
+
let batchDepth = 0;
|
|
267
|
+
let batchedEffect;
|
|
268
|
+
function startBatch() {
|
|
269
|
+
batchDepth++;
|
|
241
270
|
}
|
|
242
|
-
function
|
|
243
|
-
|
|
244
|
-
|
|
271
|
+
function endBatch() {
|
|
272
|
+
if (batchDepth > 1) {
|
|
273
|
+
batchDepth--;
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
let error;
|
|
277
|
+
while (batchedEffect) {
|
|
278
|
+
let e = batchedEffect;
|
|
279
|
+
batchedEffect = void 0;
|
|
280
|
+
while (e) {
|
|
281
|
+
const next = e.nextEffect;
|
|
282
|
+
e.nextEffect = void 0;
|
|
283
|
+
e.flags &= ~8;
|
|
284
|
+
if (e.flags & 1) {
|
|
285
|
+
try {
|
|
286
|
+
e.trigger();
|
|
287
|
+
} catch (err) {
|
|
288
|
+
if (!error)
|
|
289
|
+
error = err;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
e = next;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
batchDepth--;
|
|
296
|
+
if (error)
|
|
297
|
+
throw error;
|
|
298
|
+
}
|
|
299
|
+
function prepareDeps(sub) {
|
|
300
|
+
for (let link = sub.deps; link; link = link.nextDep) {
|
|
301
|
+
link.version = -1;
|
|
302
|
+
link.prevActiveLink = link.dep.activeLink;
|
|
303
|
+
link.dep.activeLink = link;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
function cleanupDeps(sub) {
|
|
307
|
+
let head;
|
|
308
|
+
let tail = sub.depsTail;
|
|
309
|
+
for (let link = tail; link; link = link.prevDep) {
|
|
310
|
+
if (link.version === -1) {
|
|
311
|
+
if (link === tail)
|
|
312
|
+
tail = link.prevDep;
|
|
313
|
+
removeSub(link);
|
|
314
|
+
removeDep(link);
|
|
315
|
+
} else {
|
|
316
|
+
head = link;
|
|
317
|
+
}
|
|
318
|
+
link.dep.activeLink = link.prevActiveLink;
|
|
319
|
+
link.prevActiveLink = void 0;
|
|
320
|
+
}
|
|
321
|
+
sub.deps = head;
|
|
322
|
+
sub.depsTail = tail;
|
|
245
323
|
}
|
|
246
|
-
function
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
324
|
+
function isDirty(sub) {
|
|
325
|
+
for (let link = sub.deps; link; link = link.nextDep) {
|
|
326
|
+
if (link.dep.version !== link.version || link.dep.computed && refreshComputed(link.dep.computed) === false || link.dep.version !== link.version) {
|
|
327
|
+
return true;
|
|
250
328
|
}
|
|
251
|
-
effect2.deps.length = effect2._depsLength;
|
|
252
329
|
}
|
|
330
|
+
if (sub._dirty) {
|
|
331
|
+
return true;
|
|
332
|
+
}
|
|
333
|
+
return false;
|
|
253
334
|
}
|
|
254
|
-
function
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
335
|
+
function refreshComputed(computed) {
|
|
336
|
+
if (computed.flags & 2) {
|
|
337
|
+
return false;
|
|
338
|
+
}
|
|
339
|
+
if (computed.flags & 4 && !(computed.flags & 16)) {
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
computed.flags &= ~16;
|
|
343
|
+
if (computed.globalVersion === globalVersion) {
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
computed.globalVersion = globalVersion;
|
|
347
|
+
const dep = computed.dep;
|
|
348
|
+
computed.flags |= 2;
|
|
349
|
+
if (dep.version > 0 && !computed.isSSR && !isDirty(computed)) {
|
|
350
|
+
computed.flags &= ~2;
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
const prevSub = activeSub;
|
|
354
|
+
const prevShouldTrack = shouldTrack;
|
|
355
|
+
activeSub = computed;
|
|
356
|
+
shouldTrack = true;
|
|
357
|
+
try {
|
|
358
|
+
prepareDeps(computed);
|
|
359
|
+
const value = computed.fn();
|
|
360
|
+
if (dep.version === 0 || hasChanged(value, computed._value)) {
|
|
361
|
+
computed._value = value;
|
|
362
|
+
dep.version++;
|
|
260
363
|
}
|
|
364
|
+
} catch (err) {
|
|
365
|
+
dep.version++;
|
|
366
|
+
throw err;
|
|
367
|
+
} finally {
|
|
368
|
+
activeSub = prevSub;
|
|
369
|
+
shouldTrack = prevShouldTrack;
|
|
370
|
+
cleanupDeps(computed);
|
|
371
|
+
computed.flags &= ~2;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
function removeSub(link) {
|
|
375
|
+
const { dep, prevSub, nextSub } = link;
|
|
376
|
+
if (prevSub) {
|
|
377
|
+
prevSub.nextSub = nextSub;
|
|
378
|
+
link.prevSub = void 0;
|
|
379
|
+
}
|
|
380
|
+
if (nextSub) {
|
|
381
|
+
nextSub.prevSub = prevSub;
|
|
382
|
+
link.nextSub = void 0;
|
|
383
|
+
}
|
|
384
|
+
if (dep.subs === link) {
|
|
385
|
+
dep.subs = prevSub;
|
|
386
|
+
}
|
|
387
|
+
if (!dep.subs && dep.computed) {
|
|
388
|
+
dep.computed.flags &= ~4;
|
|
389
|
+
for (let l = dep.computed.deps; l; l = l.nextDep) {
|
|
390
|
+
removeSub(l);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
function removeDep(link) {
|
|
395
|
+
const { prevDep, nextDep } = link;
|
|
396
|
+
if (prevDep) {
|
|
397
|
+
prevDep.nextDep = nextDep;
|
|
398
|
+
link.prevDep = void 0;
|
|
399
|
+
}
|
|
400
|
+
if (nextDep) {
|
|
401
|
+
nextDep.prevDep = prevDep;
|
|
402
|
+
link.nextDep = void 0;
|
|
261
403
|
}
|
|
262
404
|
}
|
|
263
405
|
function effect(fn, options) {
|
|
264
406
|
if (fn.effect instanceof ReactiveEffect) {
|
|
265
407
|
fn = fn.effect.fn;
|
|
266
408
|
}
|
|
267
|
-
const
|
|
268
|
-
if (_effect.dirty) {
|
|
269
|
-
_effect.run();
|
|
270
|
-
}
|
|
271
|
-
});
|
|
409
|
+
const e = new ReactiveEffect(fn);
|
|
272
410
|
if (options) {
|
|
273
|
-
extend(
|
|
274
|
-
if (options.scope)
|
|
275
|
-
recordEffectScope(_effect, options.scope);
|
|
411
|
+
extend(e, options);
|
|
276
412
|
}
|
|
277
|
-
|
|
278
|
-
|
|
413
|
+
try {
|
|
414
|
+
e.run();
|
|
415
|
+
} catch (err) {
|
|
416
|
+
e.stop();
|
|
417
|
+
throw err;
|
|
279
418
|
}
|
|
280
|
-
const runner =
|
|
281
|
-
runner.effect =
|
|
419
|
+
const runner = e.run.bind(e);
|
|
420
|
+
runner.effect = e;
|
|
282
421
|
return runner;
|
|
283
422
|
}
|
|
284
423
|
function stop(runner) {
|
|
285
424
|
runner.effect.stop();
|
|
286
425
|
}
|
|
287
426
|
let shouldTrack = true;
|
|
288
|
-
let pauseScheduleStack = 0;
|
|
289
427
|
const trackStack = [];
|
|
290
428
|
function pauseTracking() {
|
|
291
429
|
trackStack.push(shouldTrack);
|
|
@@ -299,192 +437,423 @@ var VueReactivity = (function (exports) {
|
|
|
299
437
|
const last = trackStack.pop();
|
|
300
438
|
shouldTrack = last === void 0 ? true : last;
|
|
301
439
|
}
|
|
302
|
-
function
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
440
|
+
function onEffectCleanup(fn, failSilently = false) {
|
|
441
|
+
if (activeSub instanceof ReactiveEffect) {
|
|
442
|
+
activeSub.cleanup = fn;
|
|
443
|
+
} else if (!failSilently) {
|
|
444
|
+
warn(
|
|
445
|
+
`onEffectCleanup() was called when there was no active effect to associate with.`
|
|
446
|
+
);
|
|
309
447
|
}
|
|
310
448
|
}
|
|
311
|
-
function
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
const
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
} else {
|
|
322
|
-
effect2._depsLength++;
|
|
449
|
+
function cleanupEffect(e) {
|
|
450
|
+
const { cleanup } = e;
|
|
451
|
+
e.cleanup = void 0;
|
|
452
|
+
if (cleanup) {
|
|
453
|
+
const prevSub = activeSub;
|
|
454
|
+
activeSub = void 0;
|
|
455
|
+
try {
|
|
456
|
+
cleanup();
|
|
457
|
+
} finally {
|
|
458
|
+
activeSub = prevSub;
|
|
323
459
|
}
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
let globalVersion = 0;
|
|
464
|
+
class Dep {
|
|
465
|
+
constructor(computed) {
|
|
466
|
+
this.computed = computed;
|
|
467
|
+
this.version = 0;
|
|
468
|
+
/**
|
|
469
|
+
* Link between this dep and the current active effect
|
|
470
|
+
*/
|
|
471
|
+
this.activeLink = void 0;
|
|
472
|
+
/**
|
|
473
|
+
* Doubly linked list representing the subscribing effects (tail)
|
|
474
|
+
*/
|
|
475
|
+
this.subs = void 0;
|
|
324
476
|
{
|
|
325
|
-
|
|
477
|
+
this.subsHead = void 0;
|
|
326
478
|
}
|
|
327
479
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
var _a;
|
|
332
|
-
pauseScheduling();
|
|
333
|
-
for (const effect2 of dep.keys()) {
|
|
334
|
-
let tracking;
|
|
335
|
-
if (effect2._dirtyLevel < dirtyLevel && (tracking != null ? tracking : tracking = dep.get(effect2) === effect2._trackId)) {
|
|
336
|
-
effect2._shouldSchedule || (effect2._shouldSchedule = effect2._dirtyLevel === 0);
|
|
337
|
-
effect2._dirtyLevel = dirtyLevel;
|
|
480
|
+
track(debugInfo) {
|
|
481
|
+
if (!activeSub || !shouldTrack) {
|
|
482
|
+
return;
|
|
338
483
|
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
484
|
+
let link = this.activeLink;
|
|
485
|
+
if (link === void 0 || link.sub !== activeSub) {
|
|
486
|
+
link = this.activeLink = {
|
|
487
|
+
dep: this,
|
|
488
|
+
sub: activeSub,
|
|
489
|
+
version: this.version,
|
|
490
|
+
nextDep: void 0,
|
|
491
|
+
prevDep: void 0,
|
|
492
|
+
nextSub: void 0,
|
|
493
|
+
prevSub: void 0,
|
|
494
|
+
prevActiveLink: void 0
|
|
495
|
+
};
|
|
496
|
+
if (!activeSub.deps) {
|
|
497
|
+
activeSub.deps = activeSub.depsTail = link;
|
|
498
|
+
} else {
|
|
499
|
+
link.prevDep = activeSub.depsTail;
|
|
500
|
+
activeSub.depsTail.nextDep = link;
|
|
501
|
+
activeSub.depsTail = link;
|
|
502
|
+
}
|
|
503
|
+
if (activeSub.flags & 4) {
|
|
504
|
+
addSub(link);
|
|
505
|
+
}
|
|
506
|
+
} else if (link.version === -1) {
|
|
507
|
+
link.version = this.version;
|
|
508
|
+
if (link.nextDep) {
|
|
509
|
+
const next = link.nextDep;
|
|
510
|
+
next.prevDep = link.prevDep;
|
|
511
|
+
if (link.prevDep) {
|
|
512
|
+
link.prevDep.nextDep = next;
|
|
513
|
+
}
|
|
514
|
+
link.prevDep = activeSub.depsTail;
|
|
515
|
+
link.nextDep = void 0;
|
|
516
|
+
activeSub.depsTail.nextDep = link;
|
|
517
|
+
activeSub.depsTail = link;
|
|
518
|
+
if (activeSub.deps === link) {
|
|
519
|
+
activeSub.deps = next;
|
|
520
|
+
}
|
|
342
521
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
522
|
+
}
|
|
523
|
+
if (activeSub.onTrack) {
|
|
524
|
+
activeSub.onTrack(
|
|
525
|
+
extend(
|
|
526
|
+
{
|
|
527
|
+
effect: activeSub
|
|
528
|
+
},
|
|
529
|
+
debugInfo
|
|
530
|
+
)
|
|
531
|
+
);
|
|
532
|
+
}
|
|
533
|
+
return link;
|
|
534
|
+
}
|
|
535
|
+
trigger(debugInfo) {
|
|
536
|
+
this.version++;
|
|
537
|
+
globalVersion++;
|
|
538
|
+
this.notify(debugInfo);
|
|
539
|
+
}
|
|
540
|
+
notify(debugInfo) {
|
|
541
|
+
startBatch();
|
|
542
|
+
try {
|
|
543
|
+
if (true) {
|
|
544
|
+
for (let head = this.subsHead; head; head = head.nextSub) {
|
|
545
|
+
if (head.sub.onTrigger && !(head.sub.flags & 8)) {
|
|
546
|
+
head.sub.onTrigger(
|
|
547
|
+
extend(
|
|
548
|
+
{
|
|
549
|
+
effect: head.sub
|
|
550
|
+
},
|
|
551
|
+
debugInfo
|
|
552
|
+
)
|
|
553
|
+
);
|
|
554
|
+
}
|
|
348
555
|
}
|
|
349
556
|
}
|
|
557
|
+
for (let link = this.subs; link; link = link.prevSub) {
|
|
558
|
+
link.sub.notify();
|
|
559
|
+
}
|
|
560
|
+
} finally {
|
|
561
|
+
endBatch();
|
|
350
562
|
}
|
|
351
563
|
}
|
|
352
|
-
resetScheduling();
|
|
353
564
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
565
|
+
function addSub(link) {
|
|
566
|
+
const computed = link.dep.computed;
|
|
567
|
+
if (computed && !link.dep.subs) {
|
|
568
|
+
computed.flags |= 4 | 16;
|
|
569
|
+
for (let l = computed.deps; l; l = l.nextDep) {
|
|
570
|
+
addSub(l);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
const currentTail = link.dep.subs;
|
|
574
|
+
if (currentTail !== link) {
|
|
575
|
+
link.prevSub = currentTail;
|
|
576
|
+
if (currentTail)
|
|
577
|
+
currentTail.nextSub = link;
|
|
578
|
+
}
|
|
579
|
+
if (link.dep.subsHead === void 0) {
|
|
580
|
+
link.dep.subsHead = link;
|
|
581
|
+
}
|
|
582
|
+
link.dep.subs = link;
|
|
583
|
+
}
|
|
362
584
|
const targetMap = /* @__PURE__ */ new WeakMap();
|
|
363
|
-
const ITERATE_KEY = Symbol("iterate" );
|
|
364
|
-
const MAP_KEY_ITERATE_KEY = Symbol("Map
|
|
585
|
+
const ITERATE_KEY = Symbol("Object iterate" );
|
|
586
|
+
const MAP_KEY_ITERATE_KEY = Symbol("Map keys iterate" );
|
|
587
|
+
const ARRAY_ITERATE_KEY = Symbol("Array iterate" );
|
|
365
588
|
function track(target, type, key) {
|
|
366
|
-
if (shouldTrack &&
|
|
589
|
+
if (shouldTrack && activeSub) {
|
|
367
590
|
let depsMap = targetMap.get(target);
|
|
368
591
|
if (!depsMap) {
|
|
369
592
|
targetMap.set(target, depsMap = /* @__PURE__ */ new Map());
|
|
370
593
|
}
|
|
371
594
|
let dep = depsMap.get(key);
|
|
372
595
|
if (!dep) {
|
|
373
|
-
depsMap.set(key, dep =
|
|
596
|
+
depsMap.set(key, dep = new Dep());
|
|
374
597
|
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
dep,
|
|
378
|
-
{
|
|
598
|
+
{
|
|
599
|
+
dep.track({
|
|
379
600
|
target,
|
|
380
601
|
type,
|
|
381
602
|
key
|
|
382
|
-
}
|
|
383
|
-
|
|
603
|
+
});
|
|
604
|
+
}
|
|
384
605
|
}
|
|
385
606
|
}
|
|
386
607
|
function trigger(target, type, key, newValue, oldValue, oldTarget) {
|
|
387
608
|
const depsMap = targetMap.get(target);
|
|
388
609
|
if (!depsMap) {
|
|
610
|
+
globalVersion++;
|
|
389
611
|
return;
|
|
390
612
|
}
|
|
391
613
|
let deps = [];
|
|
392
614
|
if (type === "clear") {
|
|
393
615
|
deps = [...depsMap.values()];
|
|
394
|
-
} else if (key === "length" && isArray(target)) {
|
|
395
|
-
const newLength = Number(newValue);
|
|
396
|
-
depsMap.forEach((dep, key2) => {
|
|
397
|
-
if (key2 === "length" || !isSymbol(key2) && key2 >= newLength) {
|
|
398
|
-
deps.push(dep);
|
|
399
|
-
}
|
|
400
|
-
});
|
|
401
616
|
} else {
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
if (!
|
|
408
|
-
deps.push(
|
|
409
|
-
if (isMap(target)) {
|
|
410
|
-
deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
|
|
411
|
-
}
|
|
412
|
-
} else if (isIntegerKey(key)) {
|
|
413
|
-
deps.push(depsMap.get("length"));
|
|
617
|
+
const targetIsArray = isArray(target);
|
|
618
|
+
const isArrayIndex = targetIsArray && isIntegerKey(key);
|
|
619
|
+
if (targetIsArray && key === "length") {
|
|
620
|
+
const newLength = Number(newValue);
|
|
621
|
+
depsMap.forEach((dep, key2) => {
|
|
622
|
+
if (key2 === "length" || key2 === ARRAY_ITERATE_KEY || !isSymbol(key2) && key2 >= newLength) {
|
|
623
|
+
deps.push(dep);
|
|
414
624
|
}
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
625
|
+
});
|
|
626
|
+
} else {
|
|
627
|
+
const push = (dep) => dep && deps.push(dep);
|
|
628
|
+
if (key !== void 0) {
|
|
629
|
+
push(depsMap.get(key));
|
|
630
|
+
}
|
|
631
|
+
if (isArrayIndex) {
|
|
632
|
+
push(depsMap.get(ARRAY_ITERATE_KEY));
|
|
633
|
+
}
|
|
634
|
+
switch (type) {
|
|
635
|
+
case "add":
|
|
636
|
+
if (!targetIsArray) {
|
|
637
|
+
push(depsMap.get(ITERATE_KEY));
|
|
638
|
+
if (isMap(target)) {
|
|
639
|
+
push(depsMap.get(MAP_KEY_ITERATE_KEY));
|
|
640
|
+
}
|
|
641
|
+
} else if (isArrayIndex) {
|
|
642
|
+
push(depsMap.get("length"));
|
|
643
|
+
}
|
|
644
|
+
break;
|
|
645
|
+
case "delete":
|
|
646
|
+
if (!targetIsArray) {
|
|
647
|
+
push(depsMap.get(ITERATE_KEY));
|
|
648
|
+
if (isMap(target)) {
|
|
649
|
+
push(depsMap.get(MAP_KEY_ITERATE_KEY));
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
break;
|
|
653
|
+
case "set":
|
|
419
654
|
if (isMap(target)) {
|
|
420
|
-
|
|
655
|
+
push(depsMap.get(ITERATE_KEY));
|
|
421
656
|
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
case "set":
|
|
425
|
-
if (isMap(target)) {
|
|
426
|
-
deps.push(depsMap.get(ITERATE_KEY));
|
|
427
|
-
}
|
|
428
|
-
break;
|
|
657
|
+
break;
|
|
658
|
+
}
|
|
429
659
|
}
|
|
430
660
|
}
|
|
431
|
-
|
|
661
|
+
startBatch();
|
|
432
662
|
for (const dep of deps) {
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
oldValue,
|
|
443
|
-
oldTarget
|
|
444
|
-
}
|
|
445
|
-
);
|
|
663
|
+
{
|
|
664
|
+
dep.trigger({
|
|
665
|
+
target,
|
|
666
|
+
type,
|
|
667
|
+
key,
|
|
668
|
+
newValue,
|
|
669
|
+
oldValue,
|
|
670
|
+
oldTarget
|
|
671
|
+
});
|
|
446
672
|
}
|
|
447
673
|
}
|
|
448
|
-
|
|
674
|
+
endBatch();
|
|
449
675
|
}
|
|
450
676
|
function getDepFromReactive(object, key) {
|
|
451
|
-
|
|
452
|
-
return
|
|
677
|
+
var _a;
|
|
678
|
+
return (_a = targetMap.get(object)) == null ? void 0 : _a.get(key);
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
function reactiveReadArray(array) {
|
|
682
|
+
const raw = toRaw(array);
|
|
683
|
+
if (raw === array)
|
|
684
|
+
return raw;
|
|
685
|
+
track(raw, "iterate", ARRAY_ITERATE_KEY);
|
|
686
|
+
return isShallow(array) ? raw : raw.map(toReactive);
|
|
687
|
+
}
|
|
688
|
+
function shallowReadArray(arr) {
|
|
689
|
+
track(arr = toRaw(arr), "iterate", ARRAY_ITERATE_KEY);
|
|
690
|
+
return arr;
|
|
691
|
+
}
|
|
692
|
+
const arrayInstrumentations = {
|
|
693
|
+
__proto__: null,
|
|
694
|
+
[Symbol.iterator]() {
|
|
695
|
+
return iterator(this, Symbol.iterator, toReactive);
|
|
696
|
+
},
|
|
697
|
+
concat(...args) {
|
|
698
|
+
return reactiveReadArray(this).concat(
|
|
699
|
+
...args.map((x) => reactiveReadArray(x))
|
|
700
|
+
);
|
|
701
|
+
},
|
|
702
|
+
entries() {
|
|
703
|
+
return iterator(this, "entries", (value) => {
|
|
704
|
+
value[1] = toReactive(value[1]);
|
|
705
|
+
return value;
|
|
706
|
+
});
|
|
707
|
+
},
|
|
708
|
+
every(fn, thisArg) {
|
|
709
|
+
return apply(this, "every", fn, thisArg);
|
|
710
|
+
},
|
|
711
|
+
filter(fn, thisArg) {
|
|
712
|
+
const result = apply(this, "filter", fn, thisArg);
|
|
713
|
+
return isProxy(this) && !isShallow(this) ? result.map(toReactive) : result;
|
|
714
|
+
},
|
|
715
|
+
find(fn, thisArg) {
|
|
716
|
+
const result = apply(this, "find", fn, thisArg);
|
|
717
|
+
return isProxy(this) && !isShallow(this) ? toReactive(result) : result;
|
|
718
|
+
},
|
|
719
|
+
findIndex(fn, thisArg) {
|
|
720
|
+
return apply(this, "findIndex", fn, thisArg);
|
|
721
|
+
},
|
|
722
|
+
findLast(fn, thisArg) {
|
|
723
|
+
const result = apply(this, "findLast", fn, thisArg);
|
|
724
|
+
return isProxy(this) && !isShallow(this) ? toReactive(result) : result;
|
|
725
|
+
},
|
|
726
|
+
findLastIndex(fn, thisArg) {
|
|
727
|
+
return apply(this, "findLastIndex", fn, thisArg);
|
|
728
|
+
},
|
|
729
|
+
// flat, flatMap could benefit from ARRAY_ITERATE but are not straight-forward to implement
|
|
730
|
+
forEach(fn, thisArg) {
|
|
731
|
+
return apply(this, "forEach", fn, thisArg);
|
|
732
|
+
},
|
|
733
|
+
includes(...args) {
|
|
734
|
+
return searchProxy(this, "includes", args);
|
|
735
|
+
},
|
|
736
|
+
indexOf(...args) {
|
|
737
|
+
return searchProxy(this, "indexOf", args);
|
|
738
|
+
},
|
|
739
|
+
join(separator) {
|
|
740
|
+
return reactiveReadArray(this).join(separator);
|
|
741
|
+
},
|
|
742
|
+
// keys() iterator only reads `length`, no optimisation required
|
|
743
|
+
lastIndexOf(...args) {
|
|
744
|
+
return searchProxy(this, "lastIndexOf", args);
|
|
745
|
+
},
|
|
746
|
+
map(fn, thisArg) {
|
|
747
|
+
return apply(this, "map", fn, thisArg);
|
|
748
|
+
},
|
|
749
|
+
pop() {
|
|
750
|
+
return noTracking(this, "pop");
|
|
751
|
+
},
|
|
752
|
+
push(...args) {
|
|
753
|
+
return noTracking(this, "push", args);
|
|
754
|
+
},
|
|
755
|
+
reduce(fn, ...args) {
|
|
756
|
+
return reduce(this, "reduce", fn, args);
|
|
757
|
+
},
|
|
758
|
+
reduceRight(fn, ...args) {
|
|
759
|
+
return reduce(this, "reduceRight", fn, args);
|
|
760
|
+
},
|
|
761
|
+
shift() {
|
|
762
|
+
return noTracking(this, "shift");
|
|
763
|
+
},
|
|
764
|
+
// slice could use ARRAY_ITERATE but also seems to beg for range tracking
|
|
765
|
+
some(fn, thisArg) {
|
|
766
|
+
return apply(this, "some", fn, thisArg);
|
|
767
|
+
},
|
|
768
|
+
splice(...args) {
|
|
769
|
+
return noTracking(this, "splice", args);
|
|
770
|
+
},
|
|
771
|
+
toReversed() {
|
|
772
|
+
return reactiveReadArray(this).toReversed();
|
|
773
|
+
},
|
|
774
|
+
toSorted(comparer) {
|
|
775
|
+
return reactiveReadArray(this).toSorted(comparer);
|
|
776
|
+
},
|
|
777
|
+
toSpliced(...args) {
|
|
778
|
+
return reactiveReadArray(this).toSpliced(...args);
|
|
779
|
+
},
|
|
780
|
+
unshift(...args) {
|
|
781
|
+
return noTracking(this, "unshift", args);
|
|
782
|
+
},
|
|
783
|
+
values() {
|
|
784
|
+
return iterator(this, "values", toReactive);
|
|
785
|
+
}
|
|
786
|
+
};
|
|
787
|
+
function iterator(self, method, wrapValue) {
|
|
788
|
+
const arr = shallowReadArray(self);
|
|
789
|
+
const iter = arr[method]();
|
|
790
|
+
if (arr !== self && !isShallow(self)) {
|
|
791
|
+
iter._next = iter.next;
|
|
792
|
+
iter.next = () => {
|
|
793
|
+
const result = iter._next();
|
|
794
|
+
if (result.value) {
|
|
795
|
+
result.value = wrapValue(result.value);
|
|
796
|
+
}
|
|
797
|
+
return result;
|
|
798
|
+
};
|
|
799
|
+
}
|
|
800
|
+
return iter;
|
|
801
|
+
}
|
|
802
|
+
function apply(self, method, fn, thisArg) {
|
|
803
|
+
const arr = shallowReadArray(self);
|
|
804
|
+
let wrappedFn = fn;
|
|
805
|
+
if (arr !== self) {
|
|
806
|
+
if (!isShallow(self)) {
|
|
807
|
+
wrappedFn = function(item, index) {
|
|
808
|
+
return fn.call(this, toReactive(item), index, self);
|
|
809
|
+
};
|
|
810
|
+
} else if (fn.length > 2) {
|
|
811
|
+
wrappedFn = function(item, index) {
|
|
812
|
+
return fn.call(this, item, index, self);
|
|
813
|
+
};
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
return arr[method](wrappedFn, thisArg);
|
|
817
|
+
}
|
|
818
|
+
function reduce(self, method, fn, args) {
|
|
819
|
+
const arr = shallowReadArray(self);
|
|
820
|
+
let wrappedFn = fn;
|
|
821
|
+
if (arr !== self) {
|
|
822
|
+
if (!isShallow(self)) {
|
|
823
|
+
wrappedFn = function(acc, item, index) {
|
|
824
|
+
return fn.call(this, acc, toReactive(item), index, self);
|
|
825
|
+
};
|
|
826
|
+
} else if (fn.length > 3) {
|
|
827
|
+
wrappedFn = function(acc, item, index) {
|
|
828
|
+
return fn.call(this, acc, item, index, self);
|
|
829
|
+
};
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
return arr[method](wrappedFn, ...args);
|
|
833
|
+
}
|
|
834
|
+
function searchProxy(self, method, args) {
|
|
835
|
+
const arr = toRaw(self);
|
|
836
|
+
track(arr, "iterate", ARRAY_ITERATE_KEY);
|
|
837
|
+
const res = arr[method](...args);
|
|
838
|
+
if ((res === -1 || res === false) && isProxy(args[0])) {
|
|
839
|
+
args[0] = toRaw(args[0]);
|
|
840
|
+
return arr[method](...args);
|
|
841
|
+
}
|
|
842
|
+
return res;
|
|
843
|
+
}
|
|
844
|
+
function noTracking(self, method, args = []) {
|
|
845
|
+
pauseTracking();
|
|
846
|
+
startBatch();
|
|
847
|
+
const res = toRaw(self)[method].apply(self, args);
|
|
848
|
+
endBatch();
|
|
849
|
+
resetTracking();
|
|
850
|
+
return res;
|
|
453
851
|
}
|
|
454
852
|
|
|
455
853
|
const isNonTrackableKeys = /* @__PURE__ */ makeMap(`__proto__,__v_isRef,__isVue`);
|
|
456
854
|
const builtInSymbols = new Set(
|
|
457
855
|
/* @__PURE__ */ Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller").map((key) => Symbol[key]).filter(isSymbol)
|
|
458
856
|
);
|
|
459
|
-
const arrayInstrumentations = /* @__PURE__ */ createArrayInstrumentations();
|
|
460
|
-
function createArrayInstrumentations() {
|
|
461
|
-
const instrumentations = {};
|
|
462
|
-
["includes", "indexOf", "lastIndexOf"].forEach((key) => {
|
|
463
|
-
instrumentations[key] = function(...args) {
|
|
464
|
-
const arr = toRaw(this);
|
|
465
|
-
for (let i = 0, l = this.length; i < l; i++) {
|
|
466
|
-
track(arr, "get", i + "");
|
|
467
|
-
}
|
|
468
|
-
const res = arr[key](...args);
|
|
469
|
-
if (res === -1 || res === false) {
|
|
470
|
-
return arr[key](...args.map(toRaw));
|
|
471
|
-
} else {
|
|
472
|
-
return res;
|
|
473
|
-
}
|
|
474
|
-
};
|
|
475
|
-
});
|
|
476
|
-
["push", "pop", "shift", "unshift", "splice"].forEach((key) => {
|
|
477
|
-
instrumentations[key] = function(...args) {
|
|
478
|
-
pauseTracking();
|
|
479
|
-
pauseScheduling();
|
|
480
|
-
const res = toRaw(this)[key].apply(this, args);
|
|
481
|
-
resetScheduling();
|
|
482
|
-
resetTracking();
|
|
483
|
-
return res;
|
|
484
|
-
};
|
|
485
|
-
});
|
|
486
|
-
return instrumentations;
|
|
487
|
-
}
|
|
488
857
|
function hasOwnProperty(key) {
|
|
489
858
|
if (!isSymbol(key))
|
|
490
859
|
key = String(key);
|
|
@@ -515,14 +884,22 @@ var VueReactivity = (function (exports) {
|
|
|
515
884
|
}
|
|
516
885
|
const targetIsArray = isArray(target);
|
|
517
886
|
if (!isReadonly2) {
|
|
518
|
-
|
|
519
|
-
|
|
887
|
+
let fn;
|
|
888
|
+
if (targetIsArray && (fn = arrayInstrumentations[key])) {
|
|
889
|
+
return fn;
|
|
520
890
|
}
|
|
521
891
|
if (key === "hasOwnProperty") {
|
|
522
892
|
return hasOwnProperty;
|
|
523
893
|
}
|
|
524
894
|
}
|
|
525
|
-
const res = Reflect.get(
|
|
895
|
+
const res = Reflect.get(
|
|
896
|
+
target,
|
|
897
|
+
key,
|
|
898
|
+
// if this is a proxy wrapping a ref, return methods using the raw ref
|
|
899
|
+
// as receiver so that we don't have to call `toRaw` on the ref in all
|
|
900
|
+
// its class methods
|
|
901
|
+
isRef(target) ? target : receiver
|
|
902
|
+
);
|
|
526
903
|
if (isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) {
|
|
527
904
|
return res;
|
|
528
905
|
}
|
|
@@ -1021,110 +1398,8 @@ var VueReactivity = (function (exports) {
|
|
|
1021
1398
|
const toReactive = (value) => isObject(value) ? reactive(value) : value;
|
|
1022
1399
|
const toReadonly = (value) => isObject(value) ? readonly(value) : value;
|
|
1023
1400
|
|
|
1024
|
-
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`;
|
|
1025
|
-
class ComputedRefImpl {
|
|
1026
|
-
constructor(getter, _setter, isReadonly, isSSR) {
|
|
1027
|
-
this.getter = getter;
|
|
1028
|
-
this._setter = _setter;
|
|
1029
|
-
this.dep = void 0;
|
|
1030
|
-
this.__v_isRef = true;
|
|
1031
|
-
this["__v_isReadonly"] = false;
|
|
1032
|
-
this.effect = new ReactiveEffect(
|
|
1033
|
-
() => getter(this._value),
|
|
1034
|
-
() => triggerRefValue(
|
|
1035
|
-
this,
|
|
1036
|
-
this.effect._dirtyLevel === 2 ? 2 : 3
|
|
1037
|
-
)
|
|
1038
|
-
);
|
|
1039
|
-
this.effect.computed = this;
|
|
1040
|
-
this.effect.active = this._cacheable = !isSSR;
|
|
1041
|
-
this["__v_isReadonly"] = isReadonly;
|
|
1042
|
-
}
|
|
1043
|
-
get value() {
|
|
1044
|
-
const self = toRaw(this);
|
|
1045
|
-
if ((!self._cacheable || self.effect.dirty) && hasChanged(self._value, self._value = self.effect.run())) {
|
|
1046
|
-
triggerRefValue(self, 4);
|
|
1047
|
-
}
|
|
1048
|
-
trackRefValue(self);
|
|
1049
|
-
if (self.effect._dirtyLevel >= 2) {
|
|
1050
|
-
if (this._warnRecursive) {
|
|
1051
|
-
warn(COMPUTED_SIDE_EFFECT_WARN, `
|
|
1052
|
-
|
|
1053
|
-
getter: `, this.getter);
|
|
1054
|
-
}
|
|
1055
|
-
triggerRefValue(self, 2);
|
|
1056
|
-
}
|
|
1057
|
-
return self._value;
|
|
1058
|
-
}
|
|
1059
|
-
set value(newValue) {
|
|
1060
|
-
this._setter(newValue);
|
|
1061
|
-
}
|
|
1062
|
-
// #region polyfill _dirty for backward compatibility third party code for Vue <= 3.3.x
|
|
1063
|
-
get _dirty() {
|
|
1064
|
-
return this.effect.dirty;
|
|
1065
|
-
}
|
|
1066
|
-
set _dirty(v) {
|
|
1067
|
-
this.effect.dirty = v;
|
|
1068
|
-
}
|
|
1069
|
-
// #endregion
|
|
1070
|
-
}
|
|
1071
|
-
function computed(getterOrOptions, debugOptions, isSSR = false) {
|
|
1072
|
-
let getter;
|
|
1073
|
-
let setter;
|
|
1074
|
-
const onlyGetter = isFunction(getterOrOptions);
|
|
1075
|
-
if (onlyGetter) {
|
|
1076
|
-
getter = getterOrOptions;
|
|
1077
|
-
setter = () => {
|
|
1078
|
-
warn("Write operation failed: computed value is readonly");
|
|
1079
|
-
} ;
|
|
1080
|
-
} else {
|
|
1081
|
-
getter = getterOrOptions.get;
|
|
1082
|
-
setter = getterOrOptions.set;
|
|
1083
|
-
}
|
|
1084
|
-
const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter, isSSR);
|
|
1085
|
-
if (debugOptions && !isSSR) {
|
|
1086
|
-
cRef.effect.onTrack = debugOptions.onTrack;
|
|
1087
|
-
cRef.effect.onTrigger = debugOptions.onTrigger;
|
|
1088
|
-
}
|
|
1089
|
-
return cRef;
|
|
1090
|
-
}
|
|
1091
|
-
|
|
1092
|
-
function trackRefValue(ref2) {
|
|
1093
|
-
var _a;
|
|
1094
|
-
if (shouldTrack && activeEffect) {
|
|
1095
|
-
ref2 = toRaw(ref2);
|
|
1096
|
-
trackEffect(
|
|
1097
|
-
activeEffect,
|
|
1098
|
-
(_a = ref2.dep) != null ? _a : ref2.dep = createDep(
|
|
1099
|
-
() => ref2.dep = void 0,
|
|
1100
|
-
ref2 instanceof ComputedRefImpl ? ref2 : void 0
|
|
1101
|
-
),
|
|
1102
|
-
{
|
|
1103
|
-
target: ref2,
|
|
1104
|
-
type: "get",
|
|
1105
|
-
key: "value"
|
|
1106
|
-
}
|
|
1107
|
-
);
|
|
1108
|
-
}
|
|
1109
|
-
}
|
|
1110
|
-
function triggerRefValue(ref2, dirtyLevel = 4, newVal) {
|
|
1111
|
-
ref2 = toRaw(ref2);
|
|
1112
|
-
const dep = ref2.dep;
|
|
1113
|
-
if (dep) {
|
|
1114
|
-
triggerEffects(
|
|
1115
|
-
dep,
|
|
1116
|
-
dirtyLevel,
|
|
1117
|
-
{
|
|
1118
|
-
target: ref2,
|
|
1119
|
-
type: "set",
|
|
1120
|
-
key: "value",
|
|
1121
|
-
newValue: newVal
|
|
1122
|
-
}
|
|
1123
|
-
);
|
|
1124
|
-
}
|
|
1125
|
-
}
|
|
1126
1401
|
function isRef(r) {
|
|
1127
|
-
return
|
|
1402
|
+
return r ? r.__v_isRef === true : false;
|
|
1128
1403
|
}
|
|
1129
1404
|
function ref(value) {
|
|
1130
1405
|
return createRef(value, false);
|
|
@@ -1141,27 +1416,49 @@ getter: `, this.getter);
|
|
|
1141
1416
|
class RefImpl {
|
|
1142
1417
|
constructor(value, __v_isShallow) {
|
|
1143
1418
|
this.__v_isShallow = __v_isShallow;
|
|
1144
|
-
this.dep =
|
|
1419
|
+
this.dep = new Dep();
|
|
1145
1420
|
this.__v_isRef = true;
|
|
1146
1421
|
this._rawValue = __v_isShallow ? value : toRaw(value);
|
|
1147
1422
|
this._value = __v_isShallow ? value : toReactive(value);
|
|
1148
1423
|
}
|
|
1149
1424
|
get value() {
|
|
1150
|
-
|
|
1425
|
+
{
|
|
1426
|
+
this.dep.track({
|
|
1427
|
+
target: this,
|
|
1428
|
+
type: "get",
|
|
1429
|
+
key: "value"
|
|
1430
|
+
});
|
|
1431
|
+
}
|
|
1151
1432
|
return this._value;
|
|
1152
1433
|
}
|
|
1153
|
-
set value(
|
|
1154
|
-
const
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
this.
|
|
1159
|
-
|
|
1434
|
+
set value(newValue) {
|
|
1435
|
+
const oldValue = this._rawValue;
|
|
1436
|
+
const useDirectValue = this.__v_isShallow || isShallow(newValue) || isReadonly(newValue);
|
|
1437
|
+
newValue = useDirectValue ? newValue : toRaw(newValue);
|
|
1438
|
+
if (hasChanged(newValue, oldValue)) {
|
|
1439
|
+
this._rawValue = newValue;
|
|
1440
|
+
this._value = useDirectValue ? newValue : toReactive(newValue);
|
|
1441
|
+
{
|
|
1442
|
+
this.dep.trigger({
|
|
1443
|
+
target: this,
|
|
1444
|
+
type: "set",
|
|
1445
|
+
key: "value",
|
|
1446
|
+
newValue,
|
|
1447
|
+
oldValue
|
|
1448
|
+
});
|
|
1449
|
+
}
|
|
1160
1450
|
}
|
|
1161
1451
|
}
|
|
1162
1452
|
}
|
|
1163
1453
|
function triggerRef(ref2) {
|
|
1164
|
-
|
|
1454
|
+
{
|
|
1455
|
+
ref2.dep.trigger({
|
|
1456
|
+
target: ref2,
|
|
1457
|
+
type: "set",
|
|
1458
|
+
key: "value",
|
|
1459
|
+
newValue: ref2._value
|
|
1460
|
+
});
|
|
1461
|
+
}
|
|
1165
1462
|
}
|
|
1166
1463
|
function unref(ref2) {
|
|
1167
1464
|
return isRef(ref2) ? ref2.value : ref2;
|
|
@@ -1186,12 +1483,9 @@ getter: `, this.getter);
|
|
|
1186
1483
|
}
|
|
1187
1484
|
class CustomRefImpl {
|
|
1188
1485
|
constructor(factory) {
|
|
1189
|
-
this.dep = void 0;
|
|
1190
1486
|
this.__v_isRef = true;
|
|
1191
|
-
const
|
|
1192
|
-
|
|
1193
|
-
() => triggerRefValue(this)
|
|
1194
|
-
);
|
|
1487
|
+
const dep = this.dep = new Dep();
|
|
1488
|
+
const { get, set } = factory(dep.track.bind(dep), dep.trigger.bind(dep));
|
|
1195
1489
|
this._get = get;
|
|
1196
1490
|
this._set = set;
|
|
1197
1491
|
}
|
|
@@ -1259,7 +1553,89 @@ getter: `, this.getter);
|
|
|
1259
1553
|
return isRef(val) ? val : new ObjectRefImpl(source, key, defaultValue);
|
|
1260
1554
|
}
|
|
1261
1555
|
|
|
1262
|
-
|
|
1556
|
+
class ComputedRefImpl {
|
|
1557
|
+
constructor(fn, setter, isSSR) {
|
|
1558
|
+
this.fn = fn;
|
|
1559
|
+
this.setter = setter;
|
|
1560
|
+
/**
|
|
1561
|
+
* @internal
|
|
1562
|
+
*/
|
|
1563
|
+
this._value = void 0;
|
|
1564
|
+
/**
|
|
1565
|
+
* @internal
|
|
1566
|
+
*/
|
|
1567
|
+
this.dep = new Dep(this);
|
|
1568
|
+
/**
|
|
1569
|
+
* @internal
|
|
1570
|
+
*/
|
|
1571
|
+
this.__v_isRef = true;
|
|
1572
|
+
// A computed is also a subscriber that tracks other deps
|
|
1573
|
+
/**
|
|
1574
|
+
* @internal
|
|
1575
|
+
*/
|
|
1576
|
+
this.deps = void 0;
|
|
1577
|
+
/**
|
|
1578
|
+
* @internal
|
|
1579
|
+
*/
|
|
1580
|
+
this.depsTail = void 0;
|
|
1581
|
+
/**
|
|
1582
|
+
* @internal
|
|
1583
|
+
*/
|
|
1584
|
+
this.flags = 16;
|
|
1585
|
+
/**
|
|
1586
|
+
* @internal
|
|
1587
|
+
*/
|
|
1588
|
+
this.globalVersion = globalVersion - 1;
|
|
1589
|
+
// for backwards compat
|
|
1590
|
+
this.effect = this;
|
|
1591
|
+
this.__v_isReadonly = !setter;
|
|
1592
|
+
this.isSSR = isSSR;
|
|
1593
|
+
}
|
|
1594
|
+
/**
|
|
1595
|
+
* @internal
|
|
1596
|
+
*/
|
|
1597
|
+
notify() {
|
|
1598
|
+
if (activeSub !== this) {
|
|
1599
|
+
this.flags |= 16;
|
|
1600
|
+
this.dep.notify();
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1603
|
+
get value() {
|
|
1604
|
+
const link = this.dep.track({
|
|
1605
|
+
target: this,
|
|
1606
|
+
type: "get",
|
|
1607
|
+
key: "value"
|
|
1608
|
+
}) ;
|
|
1609
|
+
refreshComputed(this);
|
|
1610
|
+
if (link) {
|
|
1611
|
+
link.version = this.dep.version;
|
|
1612
|
+
}
|
|
1613
|
+
return this._value;
|
|
1614
|
+
}
|
|
1615
|
+
set value(newValue) {
|
|
1616
|
+
if (this.setter) {
|
|
1617
|
+
this.setter(newValue);
|
|
1618
|
+
} else {
|
|
1619
|
+
warn("Write operation failed: computed value is readonly");
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
function computed(getterOrOptions, debugOptions, isSSR = false) {
|
|
1624
|
+
let getter;
|
|
1625
|
+
let setter;
|
|
1626
|
+
if (isFunction(getterOrOptions)) {
|
|
1627
|
+
getter = getterOrOptions;
|
|
1628
|
+
} else {
|
|
1629
|
+
getter = getterOrOptions.get;
|
|
1630
|
+
setter = getterOrOptions.set;
|
|
1631
|
+
}
|
|
1632
|
+
const cRef = new ComputedRefImpl(getter, setter, isSSR);
|
|
1633
|
+
if (debugOptions && !isSSR) {
|
|
1634
|
+
cRef.onTrack = debugOptions.onTrack;
|
|
1635
|
+
cRef.onTrigger = debugOptions.onTrigger;
|
|
1636
|
+
}
|
|
1637
|
+
return cRef;
|
|
1638
|
+
}
|
|
1263
1639
|
|
|
1264
1640
|
const TrackOpTypes = {
|
|
1265
1641
|
"GET": "get",
|
|
@@ -1280,15 +1656,17 @@ getter: `, this.getter);
|
|
|
1280
1656
|
"RAW": "__v_raw"
|
|
1281
1657
|
};
|
|
1282
1658
|
|
|
1659
|
+
exports.ARRAY_ITERATE_KEY = ARRAY_ITERATE_KEY;
|
|
1660
|
+
exports.EffectFlags = EffectFlags;
|
|
1283
1661
|
exports.EffectScope = EffectScope;
|
|
1284
1662
|
exports.ITERATE_KEY = ITERATE_KEY;
|
|
1663
|
+
exports.MAP_KEY_ITERATE_KEY = MAP_KEY_ITERATE_KEY;
|
|
1285
1664
|
exports.ReactiveEffect = ReactiveEffect;
|
|
1286
1665
|
exports.ReactiveFlags = ReactiveFlags;
|
|
1287
1666
|
exports.TrackOpTypes = TrackOpTypes;
|
|
1288
1667
|
exports.TriggerOpTypes = TriggerOpTypes;
|
|
1289
1668
|
exports.computed = computed;
|
|
1290
1669
|
exports.customRef = customRef;
|
|
1291
|
-
exports.deferredComputed = deferredComputed;
|
|
1292
1670
|
exports.effect = effect;
|
|
1293
1671
|
exports.effectScope = effectScope;
|
|
1294
1672
|
exports.enableTracking = enableTracking;
|
|
@@ -1299,20 +1677,23 @@ getter: `, this.getter);
|
|
|
1299
1677
|
exports.isRef = isRef;
|
|
1300
1678
|
exports.isShallow = isShallow;
|
|
1301
1679
|
exports.markRaw = markRaw;
|
|
1680
|
+
exports.onEffectCleanup = onEffectCleanup;
|
|
1302
1681
|
exports.onScopeDispose = onScopeDispose;
|
|
1303
|
-
exports.pauseScheduling = pauseScheduling;
|
|
1304
1682
|
exports.pauseTracking = pauseTracking;
|
|
1305
1683
|
exports.proxyRefs = proxyRefs;
|
|
1306
1684
|
exports.reactive = reactive;
|
|
1685
|
+
exports.reactiveReadArray = reactiveReadArray;
|
|
1307
1686
|
exports.readonly = readonly;
|
|
1308
1687
|
exports.ref = ref;
|
|
1309
|
-
exports.resetScheduling = resetScheduling;
|
|
1310
1688
|
exports.resetTracking = resetTracking;
|
|
1311
1689
|
exports.shallowReactive = shallowReactive;
|
|
1690
|
+
exports.shallowReadArray = shallowReadArray;
|
|
1312
1691
|
exports.shallowReadonly = shallowReadonly;
|
|
1313
1692
|
exports.shallowRef = shallowRef;
|
|
1314
1693
|
exports.stop = stop;
|
|
1315
1694
|
exports.toRaw = toRaw;
|
|
1695
|
+
exports.toReactive = toReactive;
|
|
1696
|
+
exports.toReadonly = toReadonly;
|
|
1316
1697
|
exports.toRef = toRef;
|
|
1317
1698
|
exports.toRefs = toRefs;
|
|
1318
1699
|
exports.toValue = toValue;
|