@vue/reactivity 3.3.9 → 3.4.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 +251 -280
- package/dist/reactivity.cjs.prod.js +216 -257
- package/dist/reactivity.d.ts +105 -95
- package/dist/reactivity.esm-browser.js +254 -287
- package/dist/reactivity.esm-browser.prod.js +1 -1
- package/dist/reactivity.esm-bundler.js +251 -290
- package/dist/reactivity.global.js +255 -286
- package/dist/reactivity.global.prod.js +1 -1
- package/package.json +2 -2
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
function makeMap(str, expectsLowerCase) {
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
for (let i = 0; i < list.length; i++) {
|
|
5
|
-
map[list[i]] = true;
|
|
6
|
-
}
|
|
7
|
-
return expectsLowerCase ? (val) => !!map[val.toLowerCase()] : (val) => !!map[val];
|
|
2
|
+
const set = new Set(str.split(","));
|
|
3
|
+
return expectsLowerCase ? (val) => set.has(val.toLowerCase()) : (val) => set.has(val);
|
|
8
4
|
}
|
|
9
5
|
|
|
6
|
+
const NOOP = () => {
|
|
7
|
+
};
|
|
10
8
|
const extend = Object.assign;
|
|
11
9
|
const hasOwnProperty$1 = Object.prototype.hasOwnProperty;
|
|
12
10
|
const hasOwn = (val, key) => hasOwnProperty$1.call(val, key);
|
|
@@ -145,117 +143,120 @@ function onScopeDispose(fn) {
|
|
|
145
143
|
}
|
|
146
144
|
}
|
|
147
145
|
|
|
148
|
-
const createDep = (effects) => {
|
|
149
|
-
const dep = new Set(effects);
|
|
150
|
-
dep.w = 0;
|
|
151
|
-
dep.n = 0;
|
|
152
|
-
return dep;
|
|
153
|
-
};
|
|
154
|
-
const wasTracked = (dep) => (dep.w & trackOpBit) > 0;
|
|
155
|
-
const newTracked = (dep) => (dep.n & trackOpBit) > 0;
|
|
156
|
-
const initDepMarkers = ({ deps }) => {
|
|
157
|
-
if (deps.length) {
|
|
158
|
-
for (let i = 0; i < deps.length; i++) {
|
|
159
|
-
deps[i].w |= trackOpBit;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
const finalizeDepMarkers = (effect) => {
|
|
164
|
-
const { deps } = effect;
|
|
165
|
-
if (deps.length) {
|
|
166
|
-
let ptr = 0;
|
|
167
|
-
for (let i = 0; i < deps.length; i++) {
|
|
168
|
-
const dep = deps[i];
|
|
169
|
-
if (wasTracked(dep) && !newTracked(dep)) {
|
|
170
|
-
dep.delete(effect);
|
|
171
|
-
} else {
|
|
172
|
-
deps[ptr++] = dep;
|
|
173
|
-
}
|
|
174
|
-
dep.w &= ~trackOpBit;
|
|
175
|
-
dep.n &= ~trackOpBit;
|
|
176
|
-
}
|
|
177
|
-
deps.length = ptr;
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
const targetMap = /* @__PURE__ */ new WeakMap();
|
|
182
|
-
let effectTrackDepth = 0;
|
|
183
|
-
let trackOpBit = 1;
|
|
184
|
-
const maxMarkerBits = 30;
|
|
185
146
|
let activeEffect;
|
|
186
|
-
const ITERATE_KEY = Symbol("iterate" );
|
|
187
|
-
const MAP_KEY_ITERATE_KEY = Symbol("Map key iterate" );
|
|
188
147
|
class ReactiveEffect {
|
|
189
|
-
constructor(fn, scheduler
|
|
148
|
+
constructor(fn, trigger, scheduler, scope) {
|
|
190
149
|
this.fn = fn;
|
|
150
|
+
this.trigger = trigger;
|
|
191
151
|
this.scheduler = scheduler;
|
|
192
152
|
this.active = true;
|
|
193
153
|
this.deps = [];
|
|
194
|
-
|
|
154
|
+
/**
|
|
155
|
+
* @internal
|
|
156
|
+
*/
|
|
157
|
+
this._dirtyLevel = 3;
|
|
158
|
+
/**
|
|
159
|
+
* @internal
|
|
160
|
+
*/
|
|
161
|
+
this._trackId = 0;
|
|
162
|
+
/**
|
|
163
|
+
* @internal
|
|
164
|
+
*/
|
|
165
|
+
this._runnings = 0;
|
|
166
|
+
/**
|
|
167
|
+
* @internal
|
|
168
|
+
*/
|
|
169
|
+
this._queryings = 0;
|
|
170
|
+
/**
|
|
171
|
+
* @internal
|
|
172
|
+
*/
|
|
173
|
+
this._depsLength = 0;
|
|
195
174
|
recordEffectScope(this, scope);
|
|
196
175
|
}
|
|
176
|
+
get dirty() {
|
|
177
|
+
if (this._dirtyLevel === 1) {
|
|
178
|
+
this._dirtyLevel = 0;
|
|
179
|
+
this._queryings++;
|
|
180
|
+
pauseTracking();
|
|
181
|
+
for (const dep of this.deps) {
|
|
182
|
+
if (dep.computed) {
|
|
183
|
+
triggerComputed(dep.computed);
|
|
184
|
+
if (this._dirtyLevel >= 2) {
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
resetTracking();
|
|
190
|
+
this._queryings--;
|
|
191
|
+
}
|
|
192
|
+
return this._dirtyLevel >= 2;
|
|
193
|
+
}
|
|
194
|
+
set dirty(v) {
|
|
195
|
+
this._dirtyLevel = v ? 3 : 0;
|
|
196
|
+
}
|
|
197
197
|
run() {
|
|
198
|
+
this._dirtyLevel = 0;
|
|
198
199
|
if (!this.active) {
|
|
199
200
|
return this.fn();
|
|
200
201
|
}
|
|
201
|
-
let parent = activeEffect;
|
|
202
202
|
let lastShouldTrack = shouldTrack;
|
|
203
|
-
|
|
204
|
-
if (parent === this) {
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
parent = parent.parent;
|
|
208
|
-
}
|
|
203
|
+
let lastEffect = activeEffect;
|
|
209
204
|
try {
|
|
210
|
-
this.parent = activeEffect;
|
|
211
|
-
activeEffect = this;
|
|
212
205
|
shouldTrack = true;
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
} else {
|
|
217
|
-
cleanupEffect(this);
|
|
218
|
-
}
|
|
206
|
+
activeEffect = this;
|
|
207
|
+
this._runnings++;
|
|
208
|
+
preCleanupEffect(this);
|
|
219
209
|
return this.fn();
|
|
220
210
|
} finally {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
trackOpBit = 1 << --effectTrackDepth;
|
|
225
|
-
activeEffect = this.parent;
|
|
211
|
+
postCleanupEffect(this);
|
|
212
|
+
this._runnings--;
|
|
213
|
+
activeEffect = lastEffect;
|
|
226
214
|
shouldTrack = lastShouldTrack;
|
|
227
|
-
this.parent = void 0;
|
|
228
|
-
if (this.deferStop) {
|
|
229
|
-
this.stop();
|
|
230
|
-
}
|
|
231
215
|
}
|
|
232
216
|
}
|
|
233
217
|
stop() {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
this.onStop();
|
|
240
|
-
}
|
|
218
|
+
var _a;
|
|
219
|
+
if (this.active) {
|
|
220
|
+
preCleanupEffect(this);
|
|
221
|
+
postCleanupEffect(this);
|
|
222
|
+
(_a = this.onStop) == null ? void 0 : _a.call(this);
|
|
241
223
|
this.active = false;
|
|
242
224
|
}
|
|
243
225
|
}
|
|
244
226
|
}
|
|
245
|
-
function
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
227
|
+
function triggerComputed(computed) {
|
|
228
|
+
return computed.value;
|
|
229
|
+
}
|
|
230
|
+
function preCleanupEffect(effect2) {
|
|
231
|
+
effect2._trackId++;
|
|
232
|
+
effect2._depsLength = 0;
|
|
233
|
+
}
|
|
234
|
+
function postCleanupEffect(effect2) {
|
|
235
|
+
if (effect2.deps && effect2.deps.length > effect2._depsLength) {
|
|
236
|
+
for (let i = effect2._depsLength; i < effect2.deps.length; i++) {
|
|
237
|
+
cleanupDepEffect(effect2.deps[i], effect2);
|
|
238
|
+
}
|
|
239
|
+
effect2.deps.length = effect2._depsLength;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
function cleanupDepEffect(dep, effect2) {
|
|
243
|
+
const trackId = dep.get(effect2);
|
|
244
|
+
if (trackId !== void 0 && effect2._trackId !== trackId) {
|
|
245
|
+
dep.delete(effect2);
|
|
246
|
+
if (dep.size === 0) {
|
|
247
|
+
dep.cleanup();
|
|
250
248
|
}
|
|
251
|
-
deps.length = 0;
|
|
252
249
|
}
|
|
253
250
|
}
|
|
254
251
|
function effect(fn, options) {
|
|
255
252
|
if (fn.effect instanceof ReactiveEffect) {
|
|
256
253
|
fn = fn.effect.fn;
|
|
257
254
|
}
|
|
258
|
-
const _effect = new ReactiveEffect(fn)
|
|
255
|
+
const _effect = new ReactiveEffect(fn, NOOP, () => {
|
|
256
|
+
if (_effect.dirty) {
|
|
257
|
+
_effect.run();
|
|
258
|
+
}
|
|
259
|
+
});
|
|
259
260
|
if (options) {
|
|
260
261
|
extend(_effect, options);
|
|
261
262
|
if (options.scope)
|
|
@@ -272,6 +273,7 @@ function stop(runner) {
|
|
|
272
273
|
runner.effect.stop();
|
|
273
274
|
}
|
|
274
275
|
let shouldTrack = true;
|
|
276
|
+
let pauseScheduleStack = 0;
|
|
275
277
|
const trackStack = [];
|
|
276
278
|
function pauseTracking() {
|
|
277
279
|
trackStack.push(shouldTrack);
|
|
@@ -285,6 +287,68 @@ function resetTracking() {
|
|
|
285
287
|
const last = trackStack.pop();
|
|
286
288
|
shouldTrack = last === void 0 ? true : last;
|
|
287
289
|
}
|
|
290
|
+
function pauseScheduling() {
|
|
291
|
+
pauseScheduleStack++;
|
|
292
|
+
}
|
|
293
|
+
function resetScheduling() {
|
|
294
|
+
pauseScheduleStack--;
|
|
295
|
+
while (!pauseScheduleStack && queueEffectSchedulers.length) {
|
|
296
|
+
queueEffectSchedulers.shift()();
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
function trackEffect(effect2, dep, debuggerEventExtraInfo) {
|
|
300
|
+
var _a;
|
|
301
|
+
if (dep.get(effect2) !== effect2._trackId) {
|
|
302
|
+
dep.set(effect2, effect2._trackId);
|
|
303
|
+
const oldDep = effect2.deps[effect2._depsLength];
|
|
304
|
+
if (oldDep !== dep) {
|
|
305
|
+
if (oldDep) {
|
|
306
|
+
cleanupDepEffect(oldDep, effect2);
|
|
307
|
+
}
|
|
308
|
+
effect2.deps[effect2._depsLength++] = dep;
|
|
309
|
+
} else {
|
|
310
|
+
effect2._depsLength++;
|
|
311
|
+
}
|
|
312
|
+
{
|
|
313
|
+
(_a = effect2.onTrack) == null ? void 0 : _a.call(effect2, extend({ effect: effect2 }, debuggerEventExtraInfo));
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
const queueEffectSchedulers = [];
|
|
318
|
+
function triggerEffects(dep, dirtyLevel, debuggerEventExtraInfo) {
|
|
319
|
+
var _a;
|
|
320
|
+
pauseScheduling();
|
|
321
|
+
for (const effect2 of dep.keys()) {
|
|
322
|
+
if (!effect2.allowRecurse && effect2._runnings) {
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
if (effect2._dirtyLevel < dirtyLevel && (!effect2._runnings || dirtyLevel !== 2)) {
|
|
326
|
+
const lastDirtyLevel = effect2._dirtyLevel;
|
|
327
|
+
effect2._dirtyLevel = dirtyLevel;
|
|
328
|
+
if (lastDirtyLevel === 0 && (!effect2._queryings || dirtyLevel !== 2)) {
|
|
329
|
+
{
|
|
330
|
+
(_a = effect2.onTrigger) == null ? void 0 : _a.call(effect2, extend({ effect: effect2 }, debuggerEventExtraInfo));
|
|
331
|
+
}
|
|
332
|
+
effect2.trigger();
|
|
333
|
+
if (effect2.scheduler) {
|
|
334
|
+
queueEffectSchedulers.push(effect2.scheduler);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
resetScheduling();
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
const createDep = (cleanup, computed) => {
|
|
343
|
+
const dep = /* @__PURE__ */ new Map();
|
|
344
|
+
dep.cleanup = cleanup;
|
|
345
|
+
dep.computed = computed;
|
|
346
|
+
return dep;
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
const targetMap = /* @__PURE__ */ new WeakMap();
|
|
350
|
+
const ITERATE_KEY = Symbol("iterate" );
|
|
351
|
+
const MAP_KEY_ITERATE_KEY = Symbol("Map key iterate" );
|
|
288
352
|
function track(target, type, key) {
|
|
289
353
|
if (shouldTrack && activeEffect) {
|
|
290
354
|
let depsMap = targetMap.get(target);
|
|
@@ -293,35 +357,17 @@ function track(target, type, key) {
|
|
|
293
357
|
}
|
|
294
358
|
let dep = depsMap.get(key);
|
|
295
359
|
if (!dep) {
|
|
296
|
-
depsMap.set(key, dep = createDep());
|
|
297
|
-
}
|
|
298
|
-
const eventInfo = { effect: activeEffect, target, type, key } ;
|
|
299
|
-
trackEffects(dep, eventInfo);
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
function trackEffects(dep, debuggerEventExtraInfo) {
|
|
303
|
-
let shouldTrack2 = false;
|
|
304
|
-
if (effectTrackDepth <= maxMarkerBits) {
|
|
305
|
-
if (!newTracked(dep)) {
|
|
306
|
-
dep.n |= trackOpBit;
|
|
307
|
-
shouldTrack2 = !wasTracked(dep);
|
|
308
|
-
}
|
|
309
|
-
} else {
|
|
310
|
-
shouldTrack2 = !dep.has(activeEffect);
|
|
311
|
-
}
|
|
312
|
-
if (shouldTrack2) {
|
|
313
|
-
dep.add(activeEffect);
|
|
314
|
-
activeEffect.deps.push(dep);
|
|
315
|
-
if (activeEffect.onTrack) {
|
|
316
|
-
activeEffect.onTrack(
|
|
317
|
-
extend(
|
|
318
|
-
{
|
|
319
|
-
effect: activeEffect
|
|
320
|
-
},
|
|
321
|
-
debuggerEventExtraInfo
|
|
322
|
-
)
|
|
323
|
-
);
|
|
360
|
+
depsMap.set(key, dep = createDep(() => depsMap.delete(key)));
|
|
324
361
|
}
|
|
362
|
+
trackEffect(
|
|
363
|
+
activeEffect,
|
|
364
|
+
dep,
|
|
365
|
+
{
|
|
366
|
+
target,
|
|
367
|
+
type,
|
|
368
|
+
key
|
|
369
|
+
}
|
|
370
|
+
);
|
|
325
371
|
}
|
|
326
372
|
}
|
|
327
373
|
function trigger(target, type, key, newValue, oldValue, oldTarget) {
|
|
@@ -369,49 +415,24 @@ function trigger(target, type, key, newValue, oldValue, oldTarget) {
|
|
|
369
415
|
break;
|
|
370
416
|
}
|
|
371
417
|
}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
if (
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
triggerEffects(createDep(effects), eventInfo);
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
function triggerEffects(dep, debuggerEventExtraInfo) {
|
|
392
|
-
const effects = isArray(dep) ? dep : [...dep];
|
|
393
|
-
for (const effect2 of effects) {
|
|
394
|
-
if (effect2.computed) {
|
|
395
|
-
triggerEffect(effect2, debuggerEventExtraInfo);
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
for (const effect2 of effects) {
|
|
399
|
-
if (!effect2.computed) {
|
|
400
|
-
triggerEffect(effect2, debuggerEventExtraInfo);
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
function triggerEffect(effect2, debuggerEventExtraInfo) {
|
|
405
|
-
if (effect2 !== activeEffect || effect2.allowRecurse) {
|
|
406
|
-
if (effect2.onTrigger) {
|
|
407
|
-
effect2.onTrigger(extend({ effect: effect2 }, debuggerEventExtraInfo));
|
|
408
|
-
}
|
|
409
|
-
if (effect2.scheduler) {
|
|
410
|
-
effect2.scheduler();
|
|
411
|
-
} else {
|
|
412
|
-
effect2.run();
|
|
418
|
+
pauseScheduling();
|
|
419
|
+
for (const dep of deps) {
|
|
420
|
+
if (dep) {
|
|
421
|
+
triggerEffects(
|
|
422
|
+
dep,
|
|
423
|
+
3,
|
|
424
|
+
{
|
|
425
|
+
target,
|
|
426
|
+
type,
|
|
427
|
+
key,
|
|
428
|
+
newValue,
|
|
429
|
+
oldValue,
|
|
430
|
+
oldTarget
|
|
431
|
+
}
|
|
432
|
+
);
|
|
413
433
|
}
|
|
414
434
|
}
|
|
435
|
+
resetScheduling();
|
|
415
436
|
}
|
|
416
437
|
function getDepFromReactive(object, key) {
|
|
417
438
|
var _a;
|
|
@@ -442,7 +463,9 @@ function createArrayInstrumentations() {
|
|
|
442
463
|
["push", "pop", "shift", "unshift", "splice"].forEach((key) => {
|
|
443
464
|
instrumentations[key] = function(...args) {
|
|
444
465
|
pauseTracking();
|
|
466
|
+
pauseScheduling();
|
|
445
467
|
const res = toRaw(this)[key].apply(this, args);
|
|
468
|
+
resetScheduling();
|
|
446
469
|
resetTracking();
|
|
447
470
|
return res;
|
|
448
471
|
};
|
|
@@ -981,30 +1004,94 @@ function markRaw(value) {
|
|
|
981
1004
|
const toReactive = (value) => isObject(value) ? reactive(value) : value;
|
|
982
1005
|
const toReadonly = (value) => isObject(value) ? readonly(value) : value;
|
|
983
1006
|
|
|
1007
|
+
class ComputedRefImpl {
|
|
1008
|
+
constructor(getter, _setter, isReadonly, isSSR) {
|
|
1009
|
+
this._setter = _setter;
|
|
1010
|
+
this.dep = void 0;
|
|
1011
|
+
this.__v_isRef = true;
|
|
1012
|
+
this["__v_isReadonly"] = false;
|
|
1013
|
+
this.effect = new ReactiveEffect(
|
|
1014
|
+
() => getter(this._value),
|
|
1015
|
+
() => triggerRefValue(this, 1)
|
|
1016
|
+
);
|
|
1017
|
+
this.effect.computed = this;
|
|
1018
|
+
this.effect.active = this._cacheable = !isSSR;
|
|
1019
|
+
this["__v_isReadonly"] = isReadonly;
|
|
1020
|
+
}
|
|
1021
|
+
get value() {
|
|
1022
|
+
const self = toRaw(this);
|
|
1023
|
+
trackRefValue(self);
|
|
1024
|
+
if (!self._cacheable || self.effect.dirty) {
|
|
1025
|
+
if (hasChanged(self._value, self._value = self.effect.run())) {
|
|
1026
|
+
triggerRefValue(self, 2);
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
return self._value;
|
|
1030
|
+
}
|
|
1031
|
+
set value(newValue) {
|
|
1032
|
+
this._setter(newValue);
|
|
1033
|
+
}
|
|
1034
|
+
// #region polyfill _dirty for backward compatibility third party code for Vue <= 3.3.x
|
|
1035
|
+
get _dirty() {
|
|
1036
|
+
return this.effect.dirty;
|
|
1037
|
+
}
|
|
1038
|
+
set _dirty(v) {
|
|
1039
|
+
this.effect.dirty = v;
|
|
1040
|
+
}
|
|
1041
|
+
// #endregion
|
|
1042
|
+
}
|
|
1043
|
+
function computed(getterOrOptions, debugOptions, isSSR = false) {
|
|
1044
|
+
let getter;
|
|
1045
|
+
let setter;
|
|
1046
|
+
const onlyGetter = isFunction(getterOrOptions);
|
|
1047
|
+
if (onlyGetter) {
|
|
1048
|
+
getter = getterOrOptions;
|
|
1049
|
+
setter = () => {
|
|
1050
|
+
console.warn("Write operation failed: computed value is readonly");
|
|
1051
|
+
} ;
|
|
1052
|
+
} else {
|
|
1053
|
+
getter = getterOrOptions.get;
|
|
1054
|
+
setter = getterOrOptions.set;
|
|
1055
|
+
}
|
|
1056
|
+
const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter, isSSR);
|
|
1057
|
+
if (debugOptions && !isSSR) {
|
|
1058
|
+
cRef.effect.onTrack = debugOptions.onTrack;
|
|
1059
|
+
cRef.effect.onTrigger = debugOptions.onTrigger;
|
|
1060
|
+
}
|
|
1061
|
+
return cRef;
|
|
1062
|
+
}
|
|
1063
|
+
|
|
984
1064
|
function trackRefValue(ref2) {
|
|
985
1065
|
if (shouldTrack && activeEffect) {
|
|
986
1066
|
ref2 = toRaw(ref2);
|
|
987
|
-
|
|
988
|
-
|
|
1067
|
+
trackEffect(
|
|
1068
|
+
activeEffect,
|
|
1069
|
+
ref2.dep || (ref2.dep = createDep(
|
|
1070
|
+
() => ref2.dep = void 0,
|
|
1071
|
+
ref2 instanceof ComputedRefImpl ? ref2 : void 0
|
|
1072
|
+
)),
|
|
1073
|
+
{
|
|
989
1074
|
target: ref2,
|
|
990
1075
|
type: "get",
|
|
991
1076
|
key: "value"
|
|
992
|
-
}
|
|
993
|
-
|
|
1077
|
+
}
|
|
1078
|
+
);
|
|
994
1079
|
}
|
|
995
1080
|
}
|
|
996
|
-
function triggerRefValue(ref2, newVal) {
|
|
1081
|
+
function triggerRefValue(ref2, dirtyLevel = 3, newVal) {
|
|
997
1082
|
ref2 = toRaw(ref2);
|
|
998
1083
|
const dep = ref2.dep;
|
|
999
1084
|
if (dep) {
|
|
1000
|
-
|
|
1001
|
-
|
|
1085
|
+
triggerEffects(
|
|
1086
|
+
dep,
|
|
1087
|
+
dirtyLevel,
|
|
1088
|
+
{
|
|
1002
1089
|
target: ref2,
|
|
1003
1090
|
type: "set",
|
|
1004
1091
|
key: "value",
|
|
1005
1092
|
newValue: newVal
|
|
1006
|
-
}
|
|
1007
|
-
|
|
1093
|
+
}
|
|
1094
|
+
);
|
|
1008
1095
|
}
|
|
1009
1096
|
}
|
|
1010
1097
|
function isRef(r) {
|
|
@@ -1040,12 +1127,12 @@ class RefImpl {
|
|
|
1040
1127
|
if (hasChanged(newVal, this._rawValue)) {
|
|
1041
1128
|
this._rawValue = newVal;
|
|
1042
1129
|
this._value = useDirectValue ? newVal : toReactive(newVal);
|
|
1043
|
-
triggerRefValue(this, newVal);
|
|
1130
|
+
triggerRefValue(this, 3, newVal);
|
|
1044
1131
|
}
|
|
1045
1132
|
}
|
|
1046
1133
|
}
|
|
1047
1134
|
function triggerRef(ref2) {
|
|
1048
|
-
triggerRefValue(ref2, ref2.value );
|
|
1135
|
+
triggerRefValue(ref2, 3, ref2.value );
|
|
1049
1136
|
}
|
|
1050
1137
|
function unref(ref2) {
|
|
1051
1138
|
return isRef(ref2) ? ref2.value : ref2;
|
|
@@ -1143,126 +1230,6 @@ function propertyToRef(source, key, defaultValue) {
|
|
|
1143
1230
|
return isRef(val) ? val : new ObjectRefImpl(source, key, defaultValue);
|
|
1144
1231
|
}
|
|
1145
1232
|
|
|
1146
|
-
|
|
1147
|
-
constructor(getter, _setter, isReadonly, isSSR) {
|
|
1148
|
-
this._setter = _setter;
|
|
1149
|
-
this.dep = void 0;
|
|
1150
|
-
this.__v_isRef = true;
|
|
1151
|
-
this["__v_isReadonly"] = false;
|
|
1152
|
-
this._dirty = true;
|
|
1153
|
-
this.effect = new ReactiveEffect(getter, () => {
|
|
1154
|
-
if (!this._dirty) {
|
|
1155
|
-
this._dirty = true;
|
|
1156
|
-
triggerRefValue(this);
|
|
1157
|
-
}
|
|
1158
|
-
});
|
|
1159
|
-
this.effect.computed = this;
|
|
1160
|
-
this.effect.active = this._cacheable = !isSSR;
|
|
1161
|
-
this["__v_isReadonly"] = isReadonly;
|
|
1162
|
-
}
|
|
1163
|
-
get value() {
|
|
1164
|
-
const self = toRaw(this);
|
|
1165
|
-
trackRefValue(self);
|
|
1166
|
-
if (self._dirty || !self._cacheable) {
|
|
1167
|
-
self._dirty = false;
|
|
1168
|
-
self._value = self.effect.run();
|
|
1169
|
-
}
|
|
1170
|
-
return self._value;
|
|
1171
|
-
}
|
|
1172
|
-
set value(newValue) {
|
|
1173
|
-
this._setter(newValue);
|
|
1174
|
-
}
|
|
1175
|
-
}
|
|
1176
|
-
function computed(getterOrOptions, debugOptions, isSSR = false) {
|
|
1177
|
-
let getter;
|
|
1178
|
-
let setter;
|
|
1179
|
-
const onlyGetter = isFunction(getterOrOptions);
|
|
1180
|
-
if (onlyGetter) {
|
|
1181
|
-
getter = getterOrOptions;
|
|
1182
|
-
setter = () => {
|
|
1183
|
-
console.warn("Write operation failed: computed value is readonly");
|
|
1184
|
-
} ;
|
|
1185
|
-
} else {
|
|
1186
|
-
getter = getterOrOptions.get;
|
|
1187
|
-
setter = getterOrOptions.set;
|
|
1188
|
-
}
|
|
1189
|
-
const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter, isSSR);
|
|
1190
|
-
if (debugOptions && !isSSR) {
|
|
1191
|
-
cRef.effect.onTrack = debugOptions.onTrack;
|
|
1192
|
-
cRef.effect.onTrigger = debugOptions.onTrigger;
|
|
1193
|
-
}
|
|
1194
|
-
return cRef;
|
|
1195
|
-
}
|
|
1196
|
-
|
|
1197
|
-
const tick = /* @__PURE__ */ Promise.resolve();
|
|
1198
|
-
const queue = [];
|
|
1199
|
-
let queued = false;
|
|
1200
|
-
const scheduler = (fn) => {
|
|
1201
|
-
queue.push(fn);
|
|
1202
|
-
if (!queued) {
|
|
1203
|
-
queued = true;
|
|
1204
|
-
tick.then(flush);
|
|
1205
|
-
}
|
|
1206
|
-
};
|
|
1207
|
-
const flush = () => {
|
|
1208
|
-
for (let i = 0; i < queue.length; i++) {
|
|
1209
|
-
queue[i]();
|
|
1210
|
-
}
|
|
1211
|
-
queue.length = 0;
|
|
1212
|
-
queued = false;
|
|
1213
|
-
};
|
|
1214
|
-
class DeferredComputedRefImpl {
|
|
1215
|
-
constructor(getter) {
|
|
1216
|
-
this.dep = void 0;
|
|
1217
|
-
this._dirty = true;
|
|
1218
|
-
this.__v_isRef = true;
|
|
1219
|
-
this["__v_isReadonly"] = true;
|
|
1220
|
-
let compareTarget;
|
|
1221
|
-
let hasCompareTarget = false;
|
|
1222
|
-
let scheduled = false;
|
|
1223
|
-
this.effect = new ReactiveEffect(getter, (computedTrigger) => {
|
|
1224
|
-
if (this.dep) {
|
|
1225
|
-
if (computedTrigger) {
|
|
1226
|
-
compareTarget = this._value;
|
|
1227
|
-
hasCompareTarget = true;
|
|
1228
|
-
} else if (!scheduled) {
|
|
1229
|
-
const valueToCompare = hasCompareTarget ? compareTarget : this._value;
|
|
1230
|
-
scheduled = true;
|
|
1231
|
-
hasCompareTarget = false;
|
|
1232
|
-
scheduler(() => {
|
|
1233
|
-
if (this.effect.active && this._get() !== valueToCompare) {
|
|
1234
|
-
triggerRefValue(this);
|
|
1235
|
-
}
|
|
1236
|
-
scheduled = false;
|
|
1237
|
-
});
|
|
1238
|
-
}
|
|
1239
|
-
for (const e of this.dep) {
|
|
1240
|
-
if (e.computed instanceof DeferredComputedRefImpl) {
|
|
1241
|
-
e.scheduler(
|
|
1242
|
-
true
|
|
1243
|
-
/* computedTrigger */
|
|
1244
|
-
);
|
|
1245
|
-
}
|
|
1246
|
-
}
|
|
1247
|
-
}
|
|
1248
|
-
this._dirty = true;
|
|
1249
|
-
});
|
|
1250
|
-
this.effect.computed = this;
|
|
1251
|
-
}
|
|
1252
|
-
_get() {
|
|
1253
|
-
if (this._dirty) {
|
|
1254
|
-
this._dirty = false;
|
|
1255
|
-
return this._value = this.effect.run();
|
|
1256
|
-
}
|
|
1257
|
-
return this._value;
|
|
1258
|
-
}
|
|
1259
|
-
get value() {
|
|
1260
|
-
trackRefValue(this);
|
|
1261
|
-
return toRaw(this)._get();
|
|
1262
|
-
}
|
|
1263
|
-
}
|
|
1264
|
-
function deferredComputed(getter) {
|
|
1265
|
-
return new DeferredComputedRefImpl(getter);
|
|
1266
|
-
}
|
|
1233
|
+
const deferredComputed = computed;
|
|
1267
1234
|
|
|
1268
|
-
export { EffectScope, ITERATE_KEY, ReactiveEffect, computed, customRef, deferredComputed, effect, effectScope, enableTracking, getCurrentScope, isProxy, isReactive, isReadonly, isRef, isShallow, markRaw, onScopeDispose, pauseTracking, proxyRefs, reactive, readonly, ref, resetTracking, shallowReactive, shallowReadonly, shallowRef, stop, toRaw, toRef, toRefs, toValue, track, trigger, triggerRef, unref };
|
|
1235
|
+
export { EffectScope, ITERATE_KEY, ReactiveEffect, computed, customRef, deferredComputed, effect, effectScope, enableTracking, getCurrentScope, isProxy, isReactive, isReadonly, isRef, isShallow, markRaw, onScopeDispose, pauseScheduling, pauseTracking, proxyRefs, reactive, readonly, ref, resetScheduling, resetTracking, shallowReactive, shallowReadonly, shallowRef, stop, toRaw, toRef, toRefs, toValue, track, trigger, triggerRef, unref };
|