@vue/reactivity 3.4.25 → 3.5.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/reactivity.cjs.js +727 -345
- package/dist/reactivity.cjs.prod.js +655 -299
- package/dist/reactivity.d.ts +216 -185
- package/dist/reactivity.esm-browser.js +720 -345
- package/dist/reactivity.esm-browser.prod.js +2 -2
- package/dist/reactivity.esm-bundler.js +731 -344
- package/dist/reactivity.global.js +727 -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.1
|
|
3
3
|
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
4
4
|
* @license MIT
|
|
5
5
|
**/
|
|
@@ -89,153 +89,287 @@ class EffectScope {
|
|
|
89
89
|
function effectScope(detached) {
|
|
90
90
|
return new EffectScope(detached);
|
|
91
91
|
}
|
|
92
|
-
function recordEffectScope(effect, scope = activeEffectScope) {
|
|
93
|
-
if (scope && scope.active) {
|
|
94
|
-
scope.effects.push(effect);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
92
|
function getCurrentScope() {
|
|
98
93
|
return activeEffectScope;
|
|
99
94
|
}
|
|
100
|
-
function onScopeDispose(fn) {
|
|
95
|
+
function onScopeDispose(fn, failSilently = false) {
|
|
101
96
|
if (activeEffectScope) {
|
|
102
97
|
activeEffectScope.cleanups.push(fn);
|
|
103
98
|
}
|
|
104
99
|
}
|
|
105
100
|
|
|
106
|
-
let
|
|
101
|
+
let activeSub;
|
|
102
|
+
const EffectFlags = {
|
|
103
|
+
"ACTIVE": 1,
|
|
104
|
+
"1": "ACTIVE",
|
|
105
|
+
"RUNNING": 2,
|
|
106
|
+
"2": "RUNNING",
|
|
107
|
+
"TRACKING": 4,
|
|
108
|
+
"4": "TRACKING",
|
|
109
|
+
"NOTIFIED": 8,
|
|
110
|
+
"8": "NOTIFIED",
|
|
111
|
+
"DIRTY": 16,
|
|
112
|
+
"16": "DIRTY",
|
|
113
|
+
"ALLOW_RECURSE": 32,
|
|
114
|
+
"32": "ALLOW_RECURSE",
|
|
115
|
+
"NO_BATCH": 64,
|
|
116
|
+
"64": "NO_BATCH"
|
|
117
|
+
};
|
|
107
118
|
class ReactiveEffect {
|
|
108
|
-
constructor(fn
|
|
119
|
+
constructor(fn) {
|
|
109
120
|
this.fn = fn;
|
|
110
|
-
this.trigger = trigger;
|
|
111
|
-
this.scheduler = scheduler;
|
|
112
|
-
this.active = true;
|
|
113
|
-
this.deps = [];
|
|
114
121
|
/**
|
|
115
122
|
* @internal
|
|
116
123
|
*/
|
|
117
|
-
this.
|
|
124
|
+
this.deps = void 0;
|
|
118
125
|
/**
|
|
119
126
|
* @internal
|
|
120
127
|
*/
|
|
121
|
-
this.
|
|
128
|
+
this.depsTail = void 0;
|
|
122
129
|
/**
|
|
123
130
|
* @internal
|
|
124
131
|
*/
|
|
125
|
-
this.
|
|
132
|
+
this.flags = 1 | 4;
|
|
126
133
|
/**
|
|
127
134
|
* @internal
|
|
128
135
|
*/
|
|
129
|
-
this.
|
|
136
|
+
this.nextEffect = void 0;
|
|
130
137
|
/**
|
|
131
138
|
* @internal
|
|
132
139
|
*/
|
|
133
|
-
this.
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
if (this._dirtyLevel === 2 || this._dirtyLevel === 3) {
|
|
138
|
-
this._dirtyLevel = 1;
|
|
139
|
-
pauseTracking();
|
|
140
|
-
for (let i = 0; i < this._depsLength; i++) {
|
|
141
|
-
const dep = this.deps[i];
|
|
142
|
-
if (dep.computed) {
|
|
143
|
-
triggerComputed(dep.computed);
|
|
144
|
-
if (this._dirtyLevel >= 4) {
|
|
145
|
-
break;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
if (this._dirtyLevel === 1) {
|
|
150
|
-
this._dirtyLevel = 0;
|
|
151
|
-
}
|
|
152
|
-
resetTracking();
|
|
140
|
+
this.cleanup = void 0;
|
|
141
|
+
this.scheduler = void 0;
|
|
142
|
+
if (activeEffectScope && activeEffectScope.active) {
|
|
143
|
+
activeEffectScope.effects.push(this);
|
|
153
144
|
}
|
|
154
|
-
return this._dirtyLevel >= 4;
|
|
155
145
|
}
|
|
156
|
-
|
|
157
|
-
|
|
146
|
+
/**
|
|
147
|
+
* @internal
|
|
148
|
+
*/
|
|
149
|
+
notify() {
|
|
150
|
+
if (this.flags & 2 && !(this.flags & 32)) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (this.flags & 64) {
|
|
154
|
+
return this.trigger();
|
|
155
|
+
}
|
|
156
|
+
if (!(this.flags & 8)) {
|
|
157
|
+
this.flags |= 8;
|
|
158
|
+
this.nextEffect = batchedEffect;
|
|
159
|
+
batchedEffect = this;
|
|
160
|
+
}
|
|
158
161
|
}
|
|
159
162
|
run() {
|
|
160
|
-
this.
|
|
161
|
-
if (!this.active) {
|
|
163
|
+
if (!(this.flags & 1)) {
|
|
162
164
|
return this.fn();
|
|
163
165
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
+
this.flags |= 2;
|
|
167
|
+
cleanupEffect(this);
|
|
168
|
+
prepareDeps(this);
|
|
169
|
+
const prevEffect = activeSub;
|
|
170
|
+
const prevShouldTrack = shouldTrack;
|
|
171
|
+
activeSub = this;
|
|
172
|
+
shouldTrack = true;
|
|
166
173
|
try {
|
|
167
|
-
shouldTrack = true;
|
|
168
|
-
activeEffect = this;
|
|
169
|
-
this._runnings++;
|
|
170
|
-
preCleanupEffect(this);
|
|
171
174
|
return this.fn();
|
|
172
175
|
} finally {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
176
|
+
cleanupDeps(this);
|
|
177
|
+
activeSub = prevEffect;
|
|
178
|
+
shouldTrack = prevShouldTrack;
|
|
179
|
+
this.flags &= ~2;
|
|
177
180
|
}
|
|
178
181
|
}
|
|
179
182
|
stop() {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
this
|
|
183
|
+
if (this.flags & 1) {
|
|
184
|
+
for (let link = this.deps; link; link = link.nextDep) {
|
|
185
|
+
removeSub(link);
|
|
186
|
+
}
|
|
187
|
+
this.deps = this.depsTail = void 0;
|
|
188
|
+
cleanupEffect(this);
|
|
189
|
+
this.onStop && this.onStop();
|
|
190
|
+
this.flags &= ~1;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
trigger() {
|
|
194
|
+
if (this.scheduler) {
|
|
195
|
+
this.scheduler();
|
|
196
|
+
} else {
|
|
197
|
+
this.runIfDirty();
|
|
186
198
|
}
|
|
187
199
|
}
|
|
200
|
+
/**
|
|
201
|
+
* @internal
|
|
202
|
+
*/
|
|
203
|
+
runIfDirty() {
|
|
204
|
+
if (isDirty(this)) {
|
|
205
|
+
this.run();
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
get dirty() {
|
|
209
|
+
return isDirty(this);
|
|
210
|
+
}
|
|
188
211
|
}
|
|
189
|
-
|
|
190
|
-
|
|
212
|
+
let batchDepth = 0;
|
|
213
|
+
let batchedEffect;
|
|
214
|
+
function startBatch() {
|
|
215
|
+
batchDepth++;
|
|
191
216
|
}
|
|
192
|
-
function
|
|
193
|
-
|
|
194
|
-
|
|
217
|
+
function endBatch() {
|
|
218
|
+
if (batchDepth > 1) {
|
|
219
|
+
batchDepth--;
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
let error;
|
|
223
|
+
while (batchedEffect) {
|
|
224
|
+
let e = batchedEffect;
|
|
225
|
+
batchedEffect = void 0;
|
|
226
|
+
while (e) {
|
|
227
|
+
const next = e.nextEffect;
|
|
228
|
+
e.nextEffect = void 0;
|
|
229
|
+
e.flags &= ~8;
|
|
230
|
+
if (e.flags & 1) {
|
|
231
|
+
try {
|
|
232
|
+
e.trigger();
|
|
233
|
+
} catch (err) {
|
|
234
|
+
if (!error)
|
|
235
|
+
error = err;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
e = next;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
batchDepth--;
|
|
242
|
+
if (error)
|
|
243
|
+
throw error;
|
|
244
|
+
}
|
|
245
|
+
function prepareDeps(sub) {
|
|
246
|
+
for (let link = sub.deps; link; link = link.nextDep) {
|
|
247
|
+
link.version = -1;
|
|
248
|
+
link.prevActiveLink = link.dep.activeLink;
|
|
249
|
+
link.dep.activeLink = link;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
function cleanupDeps(sub) {
|
|
253
|
+
let head;
|
|
254
|
+
let tail = sub.depsTail;
|
|
255
|
+
for (let link = tail; link; link = link.prevDep) {
|
|
256
|
+
if (link.version === -1) {
|
|
257
|
+
if (link === tail)
|
|
258
|
+
tail = link.prevDep;
|
|
259
|
+
removeSub(link);
|
|
260
|
+
removeDep(link);
|
|
261
|
+
} else {
|
|
262
|
+
head = link;
|
|
263
|
+
}
|
|
264
|
+
link.dep.activeLink = link.prevActiveLink;
|
|
265
|
+
link.prevActiveLink = void 0;
|
|
266
|
+
}
|
|
267
|
+
sub.deps = head;
|
|
268
|
+
sub.depsTail = tail;
|
|
195
269
|
}
|
|
196
|
-
function
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
270
|
+
function isDirty(sub) {
|
|
271
|
+
for (let link = sub.deps; link; link = link.nextDep) {
|
|
272
|
+
if (link.dep.version !== link.version || link.dep.computed && refreshComputed(link.dep.computed) === false || link.dep.version !== link.version) {
|
|
273
|
+
return true;
|
|
200
274
|
}
|
|
201
|
-
effect2.deps.length = effect2._depsLength;
|
|
202
275
|
}
|
|
276
|
+
if (sub._dirty) {
|
|
277
|
+
return true;
|
|
278
|
+
}
|
|
279
|
+
return false;
|
|
203
280
|
}
|
|
204
|
-
function
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
281
|
+
function refreshComputed(computed) {
|
|
282
|
+
if (computed.flags & 2) {
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
if (computed.flags & 4 && !(computed.flags & 16)) {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
computed.flags &= ~16;
|
|
289
|
+
if (computed.globalVersion === globalVersion) {
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
computed.globalVersion = globalVersion;
|
|
293
|
+
const dep = computed.dep;
|
|
294
|
+
computed.flags |= 2;
|
|
295
|
+
if (dep.version > 0 && !computed.isSSR && !isDirty(computed)) {
|
|
296
|
+
computed.flags &= ~2;
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
const prevSub = activeSub;
|
|
300
|
+
const prevShouldTrack = shouldTrack;
|
|
301
|
+
activeSub = computed;
|
|
302
|
+
shouldTrack = true;
|
|
303
|
+
try {
|
|
304
|
+
prepareDeps(computed);
|
|
305
|
+
const value = computed.fn();
|
|
306
|
+
if (dep.version === 0 || shared.hasChanged(value, computed._value)) {
|
|
307
|
+
computed._value = value;
|
|
308
|
+
dep.version++;
|
|
309
|
+
}
|
|
310
|
+
} catch (err) {
|
|
311
|
+
dep.version++;
|
|
312
|
+
throw err;
|
|
313
|
+
} finally {
|
|
314
|
+
activeSub = prevSub;
|
|
315
|
+
shouldTrack = prevShouldTrack;
|
|
316
|
+
cleanupDeps(computed);
|
|
317
|
+
computed.flags &= ~2;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
function removeSub(link) {
|
|
321
|
+
const { dep, prevSub, nextSub } = link;
|
|
322
|
+
if (prevSub) {
|
|
323
|
+
prevSub.nextSub = nextSub;
|
|
324
|
+
link.prevSub = void 0;
|
|
325
|
+
}
|
|
326
|
+
if (nextSub) {
|
|
327
|
+
nextSub.prevSub = prevSub;
|
|
328
|
+
link.nextSub = void 0;
|
|
329
|
+
}
|
|
330
|
+
if (dep.subs === link) {
|
|
331
|
+
dep.subs = prevSub;
|
|
332
|
+
}
|
|
333
|
+
if (!dep.subs && dep.computed) {
|
|
334
|
+
dep.computed.flags &= ~4;
|
|
335
|
+
for (let l = dep.computed.deps; l; l = l.nextDep) {
|
|
336
|
+
removeSub(l);
|
|
210
337
|
}
|
|
211
338
|
}
|
|
212
339
|
}
|
|
340
|
+
function removeDep(link) {
|
|
341
|
+
const { prevDep, nextDep } = link;
|
|
342
|
+
if (prevDep) {
|
|
343
|
+
prevDep.nextDep = nextDep;
|
|
344
|
+
link.prevDep = void 0;
|
|
345
|
+
}
|
|
346
|
+
if (nextDep) {
|
|
347
|
+
nextDep.prevDep = prevDep;
|
|
348
|
+
link.nextDep = void 0;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
213
351
|
function effect(fn, options) {
|
|
214
352
|
if (fn.effect instanceof ReactiveEffect) {
|
|
215
353
|
fn = fn.effect.fn;
|
|
216
354
|
}
|
|
217
|
-
const
|
|
218
|
-
if (_effect.dirty) {
|
|
219
|
-
_effect.run();
|
|
220
|
-
}
|
|
221
|
-
});
|
|
355
|
+
const e = new ReactiveEffect(fn);
|
|
222
356
|
if (options) {
|
|
223
|
-
shared.extend(
|
|
224
|
-
if (options.scope)
|
|
225
|
-
recordEffectScope(_effect, options.scope);
|
|
357
|
+
shared.extend(e, options);
|
|
226
358
|
}
|
|
227
|
-
|
|
228
|
-
|
|
359
|
+
try {
|
|
360
|
+
e.run();
|
|
361
|
+
} catch (err) {
|
|
362
|
+
e.stop();
|
|
363
|
+
throw err;
|
|
229
364
|
}
|
|
230
|
-
const runner =
|
|
231
|
-
runner.effect =
|
|
365
|
+
const runner = e.run.bind(e);
|
|
366
|
+
runner.effect = e;
|
|
232
367
|
return runner;
|
|
233
368
|
}
|
|
234
369
|
function stop(runner) {
|
|
235
370
|
runner.effect.stop();
|
|
236
371
|
}
|
|
237
372
|
let shouldTrack = true;
|
|
238
|
-
let pauseScheduleStack = 0;
|
|
239
373
|
const trackStack = [];
|
|
240
374
|
function pauseTracking() {
|
|
241
375
|
trackStack.push(shouldTrack);
|
|
@@ -249,169 +383,379 @@ function resetTracking() {
|
|
|
249
383
|
const last = trackStack.pop();
|
|
250
384
|
shouldTrack = last === void 0 ? true : last;
|
|
251
385
|
}
|
|
252
|
-
function
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
function resetScheduling() {
|
|
256
|
-
pauseScheduleStack--;
|
|
257
|
-
while (!pauseScheduleStack && queueEffectSchedulers.length) {
|
|
258
|
-
queueEffectSchedulers.shift()();
|
|
386
|
+
function onEffectCleanup(fn, failSilently = false) {
|
|
387
|
+
if (activeSub instanceof ReactiveEffect) {
|
|
388
|
+
activeSub.cleanup = fn;
|
|
259
389
|
}
|
|
260
390
|
}
|
|
261
|
-
function
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
effect2._depsLength++;
|
|
391
|
+
function cleanupEffect(e) {
|
|
392
|
+
const { cleanup } = e;
|
|
393
|
+
e.cleanup = void 0;
|
|
394
|
+
if (cleanup) {
|
|
395
|
+
const prevSub = activeSub;
|
|
396
|
+
activeSub = void 0;
|
|
397
|
+
try {
|
|
398
|
+
cleanup();
|
|
399
|
+
} finally {
|
|
400
|
+
activeSub = prevSub;
|
|
272
401
|
}
|
|
273
402
|
}
|
|
274
403
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
404
|
+
|
|
405
|
+
let globalVersion = 0;
|
|
406
|
+
class Dep {
|
|
407
|
+
constructor(computed) {
|
|
408
|
+
this.computed = computed;
|
|
409
|
+
this.version = 0;
|
|
410
|
+
/**
|
|
411
|
+
* Link between this dep and the current active effect
|
|
412
|
+
*/
|
|
413
|
+
this.activeLink = void 0;
|
|
414
|
+
/**
|
|
415
|
+
* Doubly linked list representing the subscribing effects (tail)
|
|
416
|
+
*/
|
|
417
|
+
this.subs = void 0;
|
|
418
|
+
}
|
|
419
|
+
track(debugInfo) {
|
|
420
|
+
if (!activeSub || !shouldTrack) {
|
|
421
|
+
return;
|
|
283
422
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
423
|
+
let link = this.activeLink;
|
|
424
|
+
if (link === void 0 || link.sub !== activeSub) {
|
|
425
|
+
link = this.activeLink = {
|
|
426
|
+
dep: this,
|
|
427
|
+
sub: activeSub,
|
|
428
|
+
version: this.version,
|
|
429
|
+
nextDep: void 0,
|
|
430
|
+
prevDep: void 0,
|
|
431
|
+
nextSub: void 0,
|
|
432
|
+
prevSub: void 0,
|
|
433
|
+
prevActiveLink: void 0
|
|
434
|
+
};
|
|
435
|
+
if (!activeSub.deps) {
|
|
436
|
+
activeSub.deps = activeSub.depsTail = link;
|
|
437
|
+
} else {
|
|
438
|
+
link.prevDep = activeSub.depsTail;
|
|
439
|
+
activeSub.depsTail.nextDep = link;
|
|
440
|
+
activeSub.depsTail = link;
|
|
441
|
+
}
|
|
442
|
+
if (activeSub.flags & 4) {
|
|
443
|
+
addSub(link);
|
|
444
|
+
}
|
|
445
|
+
} else if (link.version === -1) {
|
|
446
|
+
link.version = this.version;
|
|
447
|
+
if (link.nextDep) {
|
|
448
|
+
const next = link.nextDep;
|
|
449
|
+
next.prevDep = link.prevDep;
|
|
450
|
+
if (link.prevDep) {
|
|
451
|
+
link.prevDep.nextDep = next;
|
|
452
|
+
}
|
|
453
|
+
link.prevDep = activeSub.depsTail;
|
|
454
|
+
link.nextDep = void 0;
|
|
455
|
+
activeSub.depsTail.nextDep = link;
|
|
456
|
+
activeSub.depsTail = link;
|
|
457
|
+
if (activeSub.deps === link) {
|
|
458
|
+
activeSub.deps = next;
|
|
290
459
|
}
|
|
291
460
|
}
|
|
292
461
|
}
|
|
462
|
+
return link;
|
|
463
|
+
}
|
|
464
|
+
trigger(debugInfo) {
|
|
465
|
+
this.version++;
|
|
466
|
+
globalVersion++;
|
|
467
|
+
this.notify(debugInfo);
|
|
468
|
+
}
|
|
469
|
+
notify(debugInfo) {
|
|
470
|
+
startBatch();
|
|
471
|
+
try {
|
|
472
|
+
if (false) ;
|
|
473
|
+
for (let link = this.subs; link; link = link.prevSub) {
|
|
474
|
+
link.sub.notify();
|
|
475
|
+
}
|
|
476
|
+
} finally {
|
|
477
|
+
endBatch();
|
|
478
|
+
}
|
|
293
479
|
}
|
|
294
|
-
resetScheduling();
|
|
295
480
|
}
|
|
296
|
-
|
|
297
|
-
const
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
}
|
|
303
|
-
|
|
481
|
+
function addSub(link) {
|
|
482
|
+
const computed = link.dep.computed;
|
|
483
|
+
if (computed && !link.dep.subs) {
|
|
484
|
+
computed.flags |= 4 | 16;
|
|
485
|
+
for (let l = computed.deps; l; l = l.nextDep) {
|
|
486
|
+
addSub(l);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
const currentTail = link.dep.subs;
|
|
490
|
+
if (currentTail !== link) {
|
|
491
|
+
link.prevSub = currentTail;
|
|
492
|
+
if (currentTail)
|
|
493
|
+
currentTail.nextSub = link;
|
|
494
|
+
}
|
|
495
|
+
link.dep.subs = link;
|
|
496
|
+
}
|
|
304
497
|
const targetMap = /* @__PURE__ */ new WeakMap();
|
|
305
498
|
const ITERATE_KEY = Symbol("");
|
|
306
499
|
const MAP_KEY_ITERATE_KEY = Symbol("");
|
|
500
|
+
const ARRAY_ITERATE_KEY = Symbol("");
|
|
307
501
|
function track(target, type, key) {
|
|
308
|
-
if (shouldTrack &&
|
|
502
|
+
if (shouldTrack && activeSub) {
|
|
309
503
|
let depsMap = targetMap.get(target);
|
|
310
504
|
if (!depsMap) {
|
|
311
505
|
targetMap.set(target, depsMap = /* @__PURE__ */ new Map());
|
|
312
506
|
}
|
|
313
507
|
let dep = depsMap.get(key);
|
|
314
508
|
if (!dep) {
|
|
315
|
-
depsMap.set(key, dep =
|
|
509
|
+
depsMap.set(key, dep = new Dep());
|
|
510
|
+
}
|
|
511
|
+
{
|
|
512
|
+
dep.track();
|
|
316
513
|
}
|
|
317
|
-
trackEffect(
|
|
318
|
-
activeEffect,
|
|
319
|
-
dep);
|
|
320
514
|
}
|
|
321
515
|
}
|
|
322
516
|
function trigger(target, type, key, newValue, oldValue, oldTarget) {
|
|
323
517
|
const depsMap = targetMap.get(target);
|
|
324
518
|
if (!depsMap) {
|
|
519
|
+
globalVersion++;
|
|
325
520
|
return;
|
|
326
521
|
}
|
|
327
522
|
let deps = [];
|
|
328
523
|
if (type === "clear") {
|
|
329
524
|
deps = [...depsMap.values()];
|
|
330
|
-
} else if (key === "length" && shared.isArray(target)) {
|
|
331
|
-
const newLength = Number(newValue);
|
|
332
|
-
depsMap.forEach((dep, key2) => {
|
|
333
|
-
if (key2 === "length" || !shared.isSymbol(key2) && key2 >= newLength) {
|
|
334
|
-
deps.push(dep);
|
|
335
|
-
}
|
|
336
|
-
});
|
|
337
525
|
} else {
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
if (!shared.
|
|
344
|
-
deps.push(
|
|
345
|
-
if (shared.isMap(target)) {
|
|
346
|
-
deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
|
|
347
|
-
}
|
|
348
|
-
} else if (shared.isIntegerKey(key)) {
|
|
349
|
-
deps.push(depsMap.get("length"));
|
|
526
|
+
const targetIsArray = shared.isArray(target);
|
|
527
|
+
const isArrayIndex = targetIsArray && shared.isIntegerKey(key);
|
|
528
|
+
if (targetIsArray && key === "length") {
|
|
529
|
+
const newLength = Number(newValue);
|
|
530
|
+
depsMap.forEach((dep, key2) => {
|
|
531
|
+
if (key2 === "length" || key2 === ARRAY_ITERATE_KEY || !shared.isSymbol(key2) && key2 >= newLength) {
|
|
532
|
+
deps.push(dep);
|
|
350
533
|
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
534
|
+
});
|
|
535
|
+
} else {
|
|
536
|
+
const push = (dep) => dep && deps.push(dep);
|
|
537
|
+
if (key !== void 0) {
|
|
538
|
+
push(depsMap.get(key));
|
|
539
|
+
}
|
|
540
|
+
if (isArrayIndex) {
|
|
541
|
+
push(depsMap.get(ARRAY_ITERATE_KEY));
|
|
542
|
+
}
|
|
543
|
+
switch (type) {
|
|
544
|
+
case "add":
|
|
545
|
+
if (!targetIsArray) {
|
|
546
|
+
push(depsMap.get(ITERATE_KEY));
|
|
547
|
+
if (shared.isMap(target)) {
|
|
548
|
+
push(depsMap.get(MAP_KEY_ITERATE_KEY));
|
|
549
|
+
}
|
|
550
|
+
} else if (isArrayIndex) {
|
|
551
|
+
push(depsMap.get("length"));
|
|
552
|
+
}
|
|
553
|
+
break;
|
|
554
|
+
case "delete":
|
|
555
|
+
if (!targetIsArray) {
|
|
556
|
+
push(depsMap.get(ITERATE_KEY));
|
|
557
|
+
if (shared.isMap(target)) {
|
|
558
|
+
push(depsMap.get(MAP_KEY_ITERATE_KEY));
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
break;
|
|
562
|
+
case "set":
|
|
355
563
|
if (shared.isMap(target)) {
|
|
356
|
-
|
|
564
|
+
push(depsMap.get(ITERATE_KEY));
|
|
357
565
|
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
case "set":
|
|
361
|
-
if (shared.isMap(target)) {
|
|
362
|
-
deps.push(depsMap.get(ITERATE_KEY));
|
|
363
|
-
}
|
|
364
|
-
break;
|
|
566
|
+
break;
|
|
567
|
+
}
|
|
365
568
|
}
|
|
366
569
|
}
|
|
367
|
-
|
|
570
|
+
startBatch();
|
|
368
571
|
for (const dep of deps) {
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
dep,
|
|
372
|
-
4);
|
|
572
|
+
{
|
|
573
|
+
dep.trigger();
|
|
373
574
|
}
|
|
374
575
|
}
|
|
375
|
-
|
|
576
|
+
endBatch();
|
|
376
577
|
}
|
|
377
578
|
function getDepFromReactive(object, key) {
|
|
378
579
|
var _a;
|
|
379
580
|
return (_a = targetMap.get(object)) == null ? void 0 : _a.get(key);
|
|
380
581
|
}
|
|
381
582
|
|
|
583
|
+
function reactiveReadArray(array) {
|
|
584
|
+
const raw = toRaw(array);
|
|
585
|
+
if (raw === array)
|
|
586
|
+
return raw;
|
|
587
|
+
track(raw, "iterate", ARRAY_ITERATE_KEY);
|
|
588
|
+
return isShallow(array) ? raw : raw.map(toReactive);
|
|
589
|
+
}
|
|
590
|
+
function shallowReadArray(arr) {
|
|
591
|
+
track(arr = toRaw(arr), "iterate", ARRAY_ITERATE_KEY);
|
|
592
|
+
return arr;
|
|
593
|
+
}
|
|
594
|
+
const arrayInstrumentations = {
|
|
595
|
+
__proto__: null,
|
|
596
|
+
[Symbol.iterator]() {
|
|
597
|
+
return iterator(this, Symbol.iterator, toReactive);
|
|
598
|
+
},
|
|
599
|
+
concat(...args) {
|
|
600
|
+
return reactiveReadArray(this).concat(
|
|
601
|
+
...args.map((x) => reactiveReadArray(x))
|
|
602
|
+
);
|
|
603
|
+
},
|
|
604
|
+
entries() {
|
|
605
|
+
return iterator(this, "entries", (value) => {
|
|
606
|
+
value[1] = toReactive(value[1]);
|
|
607
|
+
return value;
|
|
608
|
+
});
|
|
609
|
+
},
|
|
610
|
+
every(fn, thisArg) {
|
|
611
|
+
return apply(this, "every", fn, thisArg);
|
|
612
|
+
},
|
|
613
|
+
filter(fn, thisArg) {
|
|
614
|
+
const result = apply(this, "filter", fn, thisArg);
|
|
615
|
+
return isProxy(this) && !isShallow(this) ? result.map(toReactive) : result;
|
|
616
|
+
},
|
|
617
|
+
find(fn, thisArg) {
|
|
618
|
+
const result = apply(this, "find", fn, thisArg);
|
|
619
|
+
return isProxy(this) && !isShallow(this) ? toReactive(result) : result;
|
|
620
|
+
},
|
|
621
|
+
findIndex(fn, thisArg) {
|
|
622
|
+
return apply(this, "findIndex", fn, thisArg);
|
|
623
|
+
},
|
|
624
|
+
findLast(fn, thisArg) {
|
|
625
|
+
const result = apply(this, "findLast", fn, thisArg);
|
|
626
|
+
return isProxy(this) && !isShallow(this) ? toReactive(result) : result;
|
|
627
|
+
},
|
|
628
|
+
findLastIndex(fn, thisArg) {
|
|
629
|
+
return apply(this, "findLastIndex", fn, thisArg);
|
|
630
|
+
},
|
|
631
|
+
// flat, flatMap could benefit from ARRAY_ITERATE but are not straight-forward to implement
|
|
632
|
+
forEach(fn, thisArg) {
|
|
633
|
+
return apply(this, "forEach", fn, thisArg);
|
|
634
|
+
},
|
|
635
|
+
includes(...args) {
|
|
636
|
+
return searchProxy(this, "includes", args);
|
|
637
|
+
},
|
|
638
|
+
indexOf(...args) {
|
|
639
|
+
return searchProxy(this, "indexOf", args);
|
|
640
|
+
},
|
|
641
|
+
join(separator) {
|
|
642
|
+
return reactiveReadArray(this).join(separator);
|
|
643
|
+
},
|
|
644
|
+
// keys() iterator only reads `length`, no optimisation required
|
|
645
|
+
lastIndexOf(...args) {
|
|
646
|
+
return searchProxy(this, "lastIndexOf", args);
|
|
647
|
+
},
|
|
648
|
+
map(fn, thisArg) {
|
|
649
|
+
return apply(this, "map", fn, thisArg);
|
|
650
|
+
},
|
|
651
|
+
pop() {
|
|
652
|
+
return noTracking(this, "pop");
|
|
653
|
+
},
|
|
654
|
+
push(...args) {
|
|
655
|
+
return noTracking(this, "push", args);
|
|
656
|
+
},
|
|
657
|
+
reduce(fn, ...args) {
|
|
658
|
+
return reduce(this, "reduce", fn, args);
|
|
659
|
+
},
|
|
660
|
+
reduceRight(fn, ...args) {
|
|
661
|
+
return reduce(this, "reduceRight", fn, args);
|
|
662
|
+
},
|
|
663
|
+
shift() {
|
|
664
|
+
return noTracking(this, "shift");
|
|
665
|
+
},
|
|
666
|
+
// slice could use ARRAY_ITERATE but also seems to beg for range tracking
|
|
667
|
+
some(fn, thisArg) {
|
|
668
|
+
return apply(this, "some", fn, thisArg);
|
|
669
|
+
},
|
|
670
|
+
splice(...args) {
|
|
671
|
+
return noTracking(this, "splice", args);
|
|
672
|
+
},
|
|
673
|
+
toReversed() {
|
|
674
|
+
return reactiveReadArray(this).toReversed();
|
|
675
|
+
},
|
|
676
|
+
toSorted(comparer) {
|
|
677
|
+
return reactiveReadArray(this).toSorted(comparer);
|
|
678
|
+
},
|
|
679
|
+
toSpliced(...args) {
|
|
680
|
+
return reactiveReadArray(this).toSpliced(...args);
|
|
681
|
+
},
|
|
682
|
+
unshift(...args) {
|
|
683
|
+
return noTracking(this, "unshift", args);
|
|
684
|
+
},
|
|
685
|
+
values() {
|
|
686
|
+
return iterator(this, "values", toReactive);
|
|
687
|
+
}
|
|
688
|
+
};
|
|
689
|
+
function iterator(self, method, wrapValue) {
|
|
690
|
+
const arr = shallowReadArray(self);
|
|
691
|
+
const iter = arr[method]();
|
|
692
|
+
if (arr !== self && !isShallow(self)) {
|
|
693
|
+
iter._next = iter.next;
|
|
694
|
+
iter.next = () => {
|
|
695
|
+
const result = iter._next();
|
|
696
|
+
if (result.value) {
|
|
697
|
+
result.value = wrapValue(result.value);
|
|
698
|
+
}
|
|
699
|
+
return result;
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
return iter;
|
|
703
|
+
}
|
|
704
|
+
function apply(self, method, fn, thisArg) {
|
|
705
|
+
const arr = shallowReadArray(self);
|
|
706
|
+
let wrappedFn = fn;
|
|
707
|
+
if (arr !== self) {
|
|
708
|
+
if (!isShallow(self)) {
|
|
709
|
+
wrappedFn = function(item, index) {
|
|
710
|
+
return fn.call(this, toReactive(item), index, self);
|
|
711
|
+
};
|
|
712
|
+
} else if (fn.length > 2) {
|
|
713
|
+
wrappedFn = function(item, index) {
|
|
714
|
+
return fn.call(this, item, index, self);
|
|
715
|
+
};
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
return arr[method](wrappedFn, thisArg);
|
|
719
|
+
}
|
|
720
|
+
function reduce(self, method, fn, args) {
|
|
721
|
+
const arr = shallowReadArray(self);
|
|
722
|
+
let wrappedFn = fn;
|
|
723
|
+
if (arr !== self) {
|
|
724
|
+
if (!isShallow(self)) {
|
|
725
|
+
wrappedFn = function(acc, item, index) {
|
|
726
|
+
return fn.call(this, acc, toReactive(item), index, self);
|
|
727
|
+
};
|
|
728
|
+
} else if (fn.length > 3) {
|
|
729
|
+
wrappedFn = function(acc, item, index) {
|
|
730
|
+
return fn.call(this, acc, item, index, self);
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
return arr[method](wrappedFn, ...args);
|
|
735
|
+
}
|
|
736
|
+
function searchProxy(self, method, args) {
|
|
737
|
+
const arr = toRaw(self);
|
|
738
|
+
track(arr, "iterate", ARRAY_ITERATE_KEY);
|
|
739
|
+
const res = arr[method](...args);
|
|
740
|
+
if ((res === -1 || res === false) && isProxy(args[0])) {
|
|
741
|
+
args[0] = toRaw(args[0]);
|
|
742
|
+
return arr[method](...args);
|
|
743
|
+
}
|
|
744
|
+
return res;
|
|
745
|
+
}
|
|
746
|
+
function noTracking(self, method, args = []) {
|
|
747
|
+
pauseTracking();
|
|
748
|
+
startBatch();
|
|
749
|
+
const res = toRaw(self)[method].apply(self, args);
|
|
750
|
+
endBatch();
|
|
751
|
+
resetTracking();
|
|
752
|
+
return res;
|
|
753
|
+
}
|
|
754
|
+
|
|
382
755
|
const isNonTrackableKeys = /* @__PURE__ */ shared.makeMap(`__proto__,__v_isRef,__isVue`);
|
|
383
756
|
const builtInSymbols = new Set(
|
|
384
757
|
/* @__PURE__ */ Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller").map((key) => Symbol[key]).filter(shared.isSymbol)
|
|
385
758
|
);
|
|
386
|
-
const arrayInstrumentations = /* @__PURE__ */ createArrayInstrumentations();
|
|
387
|
-
function createArrayInstrumentations() {
|
|
388
|
-
const instrumentations = {};
|
|
389
|
-
["includes", "indexOf", "lastIndexOf"].forEach((key) => {
|
|
390
|
-
instrumentations[key] = function(...args) {
|
|
391
|
-
const arr = toRaw(this);
|
|
392
|
-
for (let i = 0, l = this.length; i < l; i++) {
|
|
393
|
-
track(arr, "get", i + "");
|
|
394
|
-
}
|
|
395
|
-
const res = arr[key](...args);
|
|
396
|
-
if (res === -1 || res === false) {
|
|
397
|
-
return arr[key](...args.map(toRaw));
|
|
398
|
-
} else {
|
|
399
|
-
return res;
|
|
400
|
-
}
|
|
401
|
-
};
|
|
402
|
-
});
|
|
403
|
-
["push", "pop", "shift", "unshift", "splice"].forEach((key) => {
|
|
404
|
-
instrumentations[key] = function(...args) {
|
|
405
|
-
pauseTracking();
|
|
406
|
-
pauseScheduling();
|
|
407
|
-
const res = toRaw(this)[key].apply(this, args);
|
|
408
|
-
resetScheduling();
|
|
409
|
-
resetTracking();
|
|
410
|
-
return res;
|
|
411
|
-
};
|
|
412
|
-
});
|
|
413
|
-
return instrumentations;
|
|
414
|
-
}
|
|
415
759
|
function hasOwnProperty(key) {
|
|
416
760
|
if (!shared.isSymbol(key))
|
|
417
761
|
key = String(key);
|
|
@@ -442,14 +786,22 @@ class BaseReactiveHandler {
|
|
|
442
786
|
}
|
|
443
787
|
const targetIsArray = shared.isArray(target);
|
|
444
788
|
if (!isReadonly2) {
|
|
445
|
-
|
|
446
|
-
|
|
789
|
+
let fn;
|
|
790
|
+
if (targetIsArray && (fn = arrayInstrumentations[key])) {
|
|
791
|
+
return fn;
|
|
447
792
|
}
|
|
448
793
|
if (key === "hasOwnProperty") {
|
|
449
794
|
return hasOwnProperty;
|
|
450
795
|
}
|
|
451
796
|
}
|
|
452
|
-
const res = Reflect.get(
|
|
797
|
+
const res = Reflect.get(
|
|
798
|
+
target,
|
|
799
|
+
key,
|
|
800
|
+
// if this is a proxy wrapping a ref, return methods using the raw ref
|
|
801
|
+
// as receiver so that we don't have to call `toRaw` on the ref in all
|
|
802
|
+
// its class methods
|
|
803
|
+
isRef(target) ? target : receiver
|
|
804
|
+
);
|
|
453
805
|
if (shared.isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) {
|
|
454
806
|
return res;
|
|
455
807
|
}
|
|
@@ -912,85 +1264,8 @@ function markRaw(value) {
|
|
|
912
1264
|
const toReactive = (value) => shared.isObject(value) ? reactive(value) : value;
|
|
913
1265
|
const toReadonly = (value) => shared.isObject(value) ? readonly(value) : value;
|
|
914
1266
|
|
|
915
|
-
class ComputedRefImpl {
|
|
916
|
-
constructor(getter, _setter, isReadonly, isSSR) {
|
|
917
|
-
this.getter = getter;
|
|
918
|
-
this._setter = _setter;
|
|
919
|
-
this.dep = void 0;
|
|
920
|
-
this.__v_isRef = true;
|
|
921
|
-
this["__v_isReadonly"] = false;
|
|
922
|
-
this.effect = new ReactiveEffect(
|
|
923
|
-
() => getter(this._value),
|
|
924
|
-
() => triggerRefValue(
|
|
925
|
-
this,
|
|
926
|
-
this.effect._dirtyLevel === 2 ? 2 : 3
|
|
927
|
-
)
|
|
928
|
-
);
|
|
929
|
-
this.effect.computed = this;
|
|
930
|
-
this.effect.active = this._cacheable = !isSSR;
|
|
931
|
-
this["__v_isReadonly"] = isReadonly;
|
|
932
|
-
}
|
|
933
|
-
get value() {
|
|
934
|
-
const self = toRaw(this);
|
|
935
|
-
if ((!self._cacheable || self.effect.dirty) && shared.hasChanged(self._value, self._value = self.effect.run())) {
|
|
936
|
-
triggerRefValue(self, 4);
|
|
937
|
-
}
|
|
938
|
-
trackRefValue(self);
|
|
939
|
-
if (self.effect._dirtyLevel >= 2) {
|
|
940
|
-
triggerRefValue(self, 2);
|
|
941
|
-
}
|
|
942
|
-
return self._value;
|
|
943
|
-
}
|
|
944
|
-
set value(newValue) {
|
|
945
|
-
this._setter(newValue);
|
|
946
|
-
}
|
|
947
|
-
// #region polyfill _dirty for backward compatibility third party code for Vue <= 3.3.x
|
|
948
|
-
get _dirty() {
|
|
949
|
-
return this.effect.dirty;
|
|
950
|
-
}
|
|
951
|
-
set _dirty(v) {
|
|
952
|
-
this.effect.dirty = v;
|
|
953
|
-
}
|
|
954
|
-
// #endregion
|
|
955
|
-
}
|
|
956
|
-
function computed(getterOrOptions, debugOptions, isSSR = false) {
|
|
957
|
-
let getter;
|
|
958
|
-
let setter;
|
|
959
|
-
const onlyGetter = shared.isFunction(getterOrOptions);
|
|
960
|
-
if (onlyGetter) {
|
|
961
|
-
getter = getterOrOptions;
|
|
962
|
-
setter = shared.NOOP;
|
|
963
|
-
} else {
|
|
964
|
-
getter = getterOrOptions.get;
|
|
965
|
-
setter = getterOrOptions.set;
|
|
966
|
-
}
|
|
967
|
-
const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter, isSSR);
|
|
968
|
-
return cRef;
|
|
969
|
-
}
|
|
970
|
-
|
|
971
|
-
function trackRefValue(ref2) {
|
|
972
|
-
var _a;
|
|
973
|
-
if (shouldTrack && activeEffect) {
|
|
974
|
-
ref2 = toRaw(ref2);
|
|
975
|
-
trackEffect(
|
|
976
|
-
activeEffect,
|
|
977
|
-
(_a = ref2.dep) != null ? _a : ref2.dep = createDep(
|
|
978
|
-
() => ref2.dep = void 0,
|
|
979
|
-
ref2 instanceof ComputedRefImpl ? ref2 : void 0
|
|
980
|
-
));
|
|
981
|
-
}
|
|
982
|
-
}
|
|
983
|
-
function triggerRefValue(ref2, dirtyLevel = 4, newVal) {
|
|
984
|
-
ref2 = toRaw(ref2);
|
|
985
|
-
const dep = ref2.dep;
|
|
986
|
-
if (dep) {
|
|
987
|
-
triggerEffects(
|
|
988
|
-
dep,
|
|
989
|
-
dirtyLevel);
|
|
990
|
-
}
|
|
991
|
-
}
|
|
992
1267
|
function isRef(r) {
|
|
993
|
-
return
|
|
1268
|
+
return r ? r.__v_isRef === true : false;
|
|
994
1269
|
}
|
|
995
1270
|
function ref(value) {
|
|
996
1271
|
return createRef(value, false);
|
|
@@ -1007,27 +1282,34 @@ function createRef(rawValue, shallow) {
|
|
|
1007
1282
|
class RefImpl {
|
|
1008
1283
|
constructor(value, __v_isShallow) {
|
|
1009
1284
|
this.__v_isShallow = __v_isShallow;
|
|
1010
|
-
this.dep =
|
|
1285
|
+
this.dep = new Dep();
|
|
1011
1286
|
this.__v_isRef = true;
|
|
1012
1287
|
this._rawValue = __v_isShallow ? value : toRaw(value);
|
|
1013
1288
|
this._value = __v_isShallow ? value : toReactive(value);
|
|
1014
1289
|
}
|
|
1015
1290
|
get value() {
|
|
1016
|
-
|
|
1291
|
+
{
|
|
1292
|
+
this.dep.track();
|
|
1293
|
+
}
|
|
1017
1294
|
return this._value;
|
|
1018
1295
|
}
|
|
1019
|
-
set value(
|
|
1020
|
-
const
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
this.
|
|
1025
|
-
|
|
1296
|
+
set value(newValue) {
|
|
1297
|
+
const oldValue = this._rawValue;
|
|
1298
|
+
const useDirectValue = this.__v_isShallow || isShallow(newValue) || isReadonly(newValue);
|
|
1299
|
+
newValue = useDirectValue ? newValue : toRaw(newValue);
|
|
1300
|
+
if (shared.hasChanged(newValue, oldValue)) {
|
|
1301
|
+
this._rawValue = newValue;
|
|
1302
|
+
this._value = useDirectValue ? newValue : toReactive(newValue);
|
|
1303
|
+
{
|
|
1304
|
+
this.dep.trigger();
|
|
1305
|
+
}
|
|
1026
1306
|
}
|
|
1027
1307
|
}
|
|
1028
1308
|
}
|
|
1029
1309
|
function triggerRef(ref2) {
|
|
1030
|
-
|
|
1310
|
+
{
|
|
1311
|
+
ref2.dep.trigger();
|
|
1312
|
+
}
|
|
1031
1313
|
}
|
|
1032
1314
|
function unref(ref2) {
|
|
1033
1315
|
return isRef(ref2) ? ref2.value : ref2;
|
|
@@ -1052,12 +1334,9 @@ function proxyRefs(objectWithRefs) {
|
|
|
1052
1334
|
}
|
|
1053
1335
|
class CustomRefImpl {
|
|
1054
1336
|
constructor(factory) {
|
|
1055
|
-
this.dep = void 0;
|
|
1056
1337
|
this.__v_isRef = true;
|
|
1057
|
-
const
|
|
1058
|
-
|
|
1059
|
-
() => triggerRefValue(this)
|
|
1060
|
-
);
|
|
1338
|
+
const dep = this.dep = new Dep();
|
|
1339
|
+
const { get, set } = factory(dep.track.bind(dep), dep.trigger.bind(dep));
|
|
1061
1340
|
this._get = get;
|
|
1062
1341
|
this._set = set;
|
|
1063
1342
|
}
|
|
@@ -1122,7 +1401,79 @@ function propertyToRef(source, key, defaultValue) {
|
|
|
1122
1401
|
return isRef(val) ? val : new ObjectRefImpl(source, key, defaultValue);
|
|
1123
1402
|
}
|
|
1124
1403
|
|
|
1125
|
-
|
|
1404
|
+
class ComputedRefImpl {
|
|
1405
|
+
constructor(fn, setter, isSSR) {
|
|
1406
|
+
this.fn = fn;
|
|
1407
|
+
this.setter = setter;
|
|
1408
|
+
/**
|
|
1409
|
+
* @internal
|
|
1410
|
+
*/
|
|
1411
|
+
this._value = void 0;
|
|
1412
|
+
/**
|
|
1413
|
+
* @internal
|
|
1414
|
+
*/
|
|
1415
|
+
this.dep = new Dep(this);
|
|
1416
|
+
/**
|
|
1417
|
+
* @internal
|
|
1418
|
+
*/
|
|
1419
|
+
this.__v_isRef = true;
|
|
1420
|
+
// A computed is also a subscriber that tracks other deps
|
|
1421
|
+
/**
|
|
1422
|
+
* @internal
|
|
1423
|
+
*/
|
|
1424
|
+
this.deps = void 0;
|
|
1425
|
+
/**
|
|
1426
|
+
* @internal
|
|
1427
|
+
*/
|
|
1428
|
+
this.depsTail = void 0;
|
|
1429
|
+
/**
|
|
1430
|
+
* @internal
|
|
1431
|
+
*/
|
|
1432
|
+
this.flags = 16;
|
|
1433
|
+
/**
|
|
1434
|
+
* @internal
|
|
1435
|
+
*/
|
|
1436
|
+
this.globalVersion = globalVersion - 1;
|
|
1437
|
+
// for backwards compat
|
|
1438
|
+
this.effect = this;
|
|
1439
|
+
this.__v_isReadonly = !setter;
|
|
1440
|
+
this.isSSR = isSSR;
|
|
1441
|
+
}
|
|
1442
|
+
/**
|
|
1443
|
+
* @internal
|
|
1444
|
+
*/
|
|
1445
|
+
notify() {
|
|
1446
|
+
if (activeSub !== this) {
|
|
1447
|
+
this.flags |= 16;
|
|
1448
|
+
this.dep.notify();
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
get value() {
|
|
1452
|
+
const link = this.dep.track();
|
|
1453
|
+
refreshComputed(this);
|
|
1454
|
+
if (link) {
|
|
1455
|
+
link.version = this.dep.version;
|
|
1456
|
+
}
|
|
1457
|
+
return this._value;
|
|
1458
|
+
}
|
|
1459
|
+
set value(newValue) {
|
|
1460
|
+
if (this.setter) {
|
|
1461
|
+
this.setter(newValue);
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
function computed(getterOrOptions, debugOptions, isSSR = false) {
|
|
1466
|
+
let getter;
|
|
1467
|
+
let setter;
|
|
1468
|
+
if (shared.isFunction(getterOrOptions)) {
|
|
1469
|
+
getter = getterOrOptions;
|
|
1470
|
+
} else {
|
|
1471
|
+
getter = getterOrOptions.get;
|
|
1472
|
+
setter = getterOrOptions.set;
|
|
1473
|
+
}
|
|
1474
|
+
const cRef = new ComputedRefImpl(getter, setter, isSSR);
|
|
1475
|
+
return cRef;
|
|
1476
|
+
}
|
|
1126
1477
|
|
|
1127
1478
|
const TrackOpTypes = {
|
|
1128
1479
|
"GET": "get",
|
|
@@ -1143,15 +1494,17 @@ const ReactiveFlags = {
|
|
|
1143
1494
|
"RAW": "__v_raw"
|
|
1144
1495
|
};
|
|
1145
1496
|
|
|
1497
|
+
exports.ARRAY_ITERATE_KEY = ARRAY_ITERATE_KEY;
|
|
1498
|
+
exports.EffectFlags = EffectFlags;
|
|
1146
1499
|
exports.EffectScope = EffectScope;
|
|
1147
1500
|
exports.ITERATE_KEY = ITERATE_KEY;
|
|
1501
|
+
exports.MAP_KEY_ITERATE_KEY = MAP_KEY_ITERATE_KEY;
|
|
1148
1502
|
exports.ReactiveEffect = ReactiveEffect;
|
|
1149
1503
|
exports.ReactiveFlags = ReactiveFlags;
|
|
1150
1504
|
exports.TrackOpTypes = TrackOpTypes;
|
|
1151
1505
|
exports.TriggerOpTypes = TriggerOpTypes;
|
|
1152
1506
|
exports.computed = computed;
|
|
1153
1507
|
exports.customRef = customRef;
|
|
1154
|
-
exports.deferredComputed = deferredComputed;
|
|
1155
1508
|
exports.effect = effect;
|
|
1156
1509
|
exports.effectScope = effectScope;
|
|
1157
1510
|
exports.enableTracking = enableTracking;
|
|
@@ -1162,20 +1515,23 @@ exports.isReadonly = isReadonly;
|
|
|
1162
1515
|
exports.isRef = isRef;
|
|
1163
1516
|
exports.isShallow = isShallow;
|
|
1164
1517
|
exports.markRaw = markRaw;
|
|
1518
|
+
exports.onEffectCleanup = onEffectCleanup;
|
|
1165
1519
|
exports.onScopeDispose = onScopeDispose;
|
|
1166
|
-
exports.pauseScheduling = pauseScheduling;
|
|
1167
1520
|
exports.pauseTracking = pauseTracking;
|
|
1168
1521
|
exports.proxyRefs = proxyRefs;
|
|
1169
1522
|
exports.reactive = reactive;
|
|
1523
|
+
exports.reactiveReadArray = reactiveReadArray;
|
|
1170
1524
|
exports.readonly = readonly;
|
|
1171
1525
|
exports.ref = ref;
|
|
1172
|
-
exports.resetScheduling = resetScheduling;
|
|
1173
1526
|
exports.resetTracking = resetTracking;
|
|
1174
1527
|
exports.shallowReactive = shallowReactive;
|
|
1528
|
+
exports.shallowReadArray = shallowReadArray;
|
|
1175
1529
|
exports.shallowReadonly = shallowReadonly;
|
|
1176
1530
|
exports.shallowRef = shallowRef;
|
|
1177
1531
|
exports.stop = stop;
|
|
1178
1532
|
exports.toRaw = toRaw;
|
|
1533
|
+
exports.toReactive = toReactive;
|
|
1534
|
+
exports.toReadonly = toReadonly;
|
|
1179
1535
|
exports.toRef = toRef;
|
|
1180
1536
|
exports.toRefs = toRefs;
|
|
1181
1537
|
exports.toValue = toValue;
|