@vue/reactivity 3.3.7 → 3.4.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 +250 -280
- package/dist/reactivity.cjs.prod.js +215 -257
- package/dist/reactivity.d.ts +103 -93
- package/dist/reactivity.esm-browser.js +251 -281
- package/dist/reactivity.esm-browser.prod.js +1 -1
- package/dist/reactivity.esm-bundler.js +250 -290
- package/dist/reactivity.global.js +252 -280
- package/dist/reactivity.global.prod.js +1 -1
- package/package.json +2 -2
|
@@ -7,6 +7,8 @@ function makeMap(str, expectsLowerCase) {
|
|
|
7
7
|
return expectsLowerCase ? (val) => !!map[val.toLowerCase()] : (val) => !!map[val];
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
const NOOP = () => {
|
|
11
|
+
};
|
|
10
12
|
const extend = Object.assign;
|
|
11
13
|
const hasOwnProperty$1 = Object.prototype.hasOwnProperty;
|
|
12
14
|
const hasOwn = (val, key) => hasOwnProperty$1.call(val, key);
|
|
@@ -145,117 +147,120 @@ function onScopeDispose(fn) {
|
|
|
145
147
|
}
|
|
146
148
|
}
|
|
147
149
|
|
|
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
150
|
let activeEffect;
|
|
186
|
-
const ITERATE_KEY = Symbol("iterate" );
|
|
187
|
-
const MAP_KEY_ITERATE_KEY = Symbol("Map key iterate" );
|
|
188
151
|
class ReactiveEffect {
|
|
189
|
-
constructor(fn, scheduler
|
|
152
|
+
constructor(fn, trigger, scheduler, scope) {
|
|
190
153
|
this.fn = fn;
|
|
154
|
+
this.trigger = trigger;
|
|
191
155
|
this.scheduler = scheduler;
|
|
192
156
|
this.active = true;
|
|
193
157
|
this.deps = [];
|
|
194
|
-
|
|
158
|
+
/**
|
|
159
|
+
* @internal
|
|
160
|
+
*/
|
|
161
|
+
this._dirtyLevel = 3;
|
|
162
|
+
/**
|
|
163
|
+
* @internal
|
|
164
|
+
*/
|
|
165
|
+
this._trackId = 0;
|
|
166
|
+
/**
|
|
167
|
+
* @internal
|
|
168
|
+
*/
|
|
169
|
+
this._runnings = 0;
|
|
170
|
+
/**
|
|
171
|
+
* @internal
|
|
172
|
+
*/
|
|
173
|
+
this._queryings = 0;
|
|
174
|
+
/**
|
|
175
|
+
* @internal
|
|
176
|
+
*/
|
|
177
|
+
this._depsLength = 0;
|
|
195
178
|
recordEffectScope(this, scope);
|
|
196
179
|
}
|
|
180
|
+
get dirty() {
|
|
181
|
+
if (this._dirtyLevel === 1) {
|
|
182
|
+
this._dirtyLevel = 0;
|
|
183
|
+
this._queryings++;
|
|
184
|
+
pauseTracking();
|
|
185
|
+
for (const dep of this.deps) {
|
|
186
|
+
if (dep.computed) {
|
|
187
|
+
triggerComputed(dep.computed);
|
|
188
|
+
if (this._dirtyLevel >= 2) {
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
resetTracking();
|
|
194
|
+
this._queryings--;
|
|
195
|
+
}
|
|
196
|
+
return this._dirtyLevel >= 2;
|
|
197
|
+
}
|
|
198
|
+
set dirty(v) {
|
|
199
|
+
this._dirtyLevel = v ? 3 : 0;
|
|
200
|
+
}
|
|
197
201
|
run() {
|
|
202
|
+
this._dirtyLevel = 0;
|
|
198
203
|
if (!this.active) {
|
|
199
204
|
return this.fn();
|
|
200
205
|
}
|
|
201
|
-
let parent = activeEffect;
|
|
202
206
|
let lastShouldTrack = shouldTrack;
|
|
203
|
-
|
|
204
|
-
if (parent === this) {
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
parent = parent.parent;
|
|
208
|
-
}
|
|
207
|
+
let lastEffect = activeEffect;
|
|
209
208
|
try {
|
|
210
|
-
this.parent = activeEffect;
|
|
211
|
-
activeEffect = this;
|
|
212
209
|
shouldTrack = true;
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
} else {
|
|
217
|
-
cleanupEffect(this);
|
|
218
|
-
}
|
|
210
|
+
activeEffect = this;
|
|
211
|
+
this._runnings++;
|
|
212
|
+
preCleanupEffect(this);
|
|
219
213
|
return this.fn();
|
|
220
214
|
} finally {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
trackOpBit = 1 << --effectTrackDepth;
|
|
225
|
-
activeEffect = this.parent;
|
|
215
|
+
postCleanupEffect(this);
|
|
216
|
+
this._runnings--;
|
|
217
|
+
activeEffect = lastEffect;
|
|
226
218
|
shouldTrack = lastShouldTrack;
|
|
227
|
-
this.parent = void 0;
|
|
228
|
-
if (this.deferStop) {
|
|
229
|
-
this.stop();
|
|
230
|
-
}
|
|
231
219
|
}
|
|
232
220
|
}
|
|
233
221
|
stop() {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
this.onStop();
|
|
240
|
-
}
|
|
222
|
+
var _a;
|
|
223
|
+
if (this.active) {
|
|
224
|
+
preCleanupEffect(this);
|
|
225
|
+
postCleanupEffect(this);
|
|
226
|
+
(_a = this.onStop) == null ? void 0 : _a.call(this);
|
|
241
227
|
this.active = false;
|
|
242
228
|
}
|
|
243
229
|
}
|
|
244
230
|
}
|
|
245
|
-
function
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
231
|
+
function triggerComputed(computed) {
|
|
232
|
+
return computed.value;
|
|
233
|
+
}
|
|
234
|
+
function preCleanupEffect(effect2) {
|
|
235
|
+
effect2._trackId++;
|
|
236
|
+
effect2._depsLength = 0;
|
|
237
|
+
}
|
|
238
|
+
function postCleanupEffect(effect2) {
|
|
239
|
+
if (effect2.deps && effect2.deps.length > effect2._depsLength) {
|
|
240
|
+
for (let i = effect2._depsLength; i < effect2.deps.length; i++) {
|
|
241
|
+
cleanupDepEffect(effect2.deps[i], effect2);
|
|
242
|
+
}
|
|
243
|
+
effect2.deps.length = effect2._depsLength;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
function cleanupDepEffect(dep, effect2) {
|
|
247
|
+
const trackId = dep.get(effect2);
|
|
248
|
+
if (trackId !== void 0 && effect2._trackId !== trackId) {
|
|
249
|
+
dep.delete(effect2);
|
|
250
|
+
if (dep.size === 0) {
|
|
251
|
+
dep.cleanup();
|
|
250
252
|
}
|
|
251
|
-
deps.length = 0;
|
|
252
253
|
}
|
|
253
254
|
}
|
|
254
255
|
function effect(fn, options) {
|
|
255
256
|
if (fn.effect instanceof ReactiveEffect) {
|
|
256
257
|
fn = fn.effect.fn;
|
|
257
258
|
}
|
|
258
|
-
const _effect = new ReactiveEffect(fn)
|
|
259
|
+
const _effect = new ReactiveEffect(fn, NOOP, () => {
|
|
260
|
+
if (_effect.dirty) {
|
|
261
|
+
_effect.run();
|
|
262
|
+
}
|
|
263
|
+
});
|
|
259
264
|
if (options) {
|
|
260
265
|
extend(_effect, options);
|
|
261
266
|
if (options.scope)
|
|
@@ -272,6 +277,7 @@ function stop(runner) {
|
|
|
272
277
|
runner.effect.stop();
|
|
273
278
|
}
|
|
274
279
|
let shouldTrack = true;
|
|
280
|
+
let pauseScheduleStack = 0;
|
|
275
281
|
const trackStack = [];
|
|
276
282
|
function pauseTracking() {
|
|
277
283
|
trackStack.push(shouldTrack);
|
|
@@ -285,6 +291,68 @@ function resetTracking() {
|
|
|
285
291
|
const last = trackStack.pop();
|
|
286
292
|
shouldTrack = last === void 0 ? true : last;
|
|
287
293
|
}
|
|
294
|
+
function pauseScheduling() {
|
|
295
|
+
pauseScheduleStack++;
|
|
296
|
+
}
|
|
297
|
+
function resetScheduling() {
|
|
298
|
+
pauseScheduleStack--;
|
|
299
|
+
while (!pauseScheduleStack && queueEffectSchedulers.length) {
|
|
300
|
+
queueEffectSchedulers.shift()();
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
function trackEffect(effect2, dep, debuggerEventExtraInfo) {
|
|
304
|
+
var _a;
|
|
305
|
+
if (dep.get(effect2) !== effect2._trackId) {
|
|
306
|
+
dep.set(effect2, effect2._trackId);
|
|
307
|
+
const oldDep = effect2.deps[effect2._depsLength];
|
|
308
|
+
if (oldDep !== dep) {
|
|
309
|
+
if (oldDep) {
|
|
310
|
+
cleanupDepEffect(oldDep, effect2);
|
|
311
|
+
}
|
|
312
|
+
effect2.deps[effect2._depsLength++] = dep;
|
|
313
|
+
} else {
|
|
314
|
+
effect2._depsLength++;
|
|
315
|
+
}
|
|
316
|
+
{
|
|
317
|
+
(_a = effect2.onTrack) == null ? void 0 : _a.call(effect2, extend({ effect: effect2 }, debuggerEventExtraInfo));
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
const queueEffectSchedulers = [];
|
|
322
|
+
function triggerEffects(dep, dirtyLevel, debuggerEventExtraInfo) {
|
|
323
|
+
var _a;
|
|
324
|
+
pauseScheduling();
|
|
325
|
+
for (const effect2 of dep.keys()) {
|
|
326
|
+
if (!effect2.allowRecurse && effect2._runnings) {
|
|
327
|
+
continue;
|
|
328
|
+
}
|
|
329
|
+
if (effect2._dirtyLevel < dirtyLevel && (!effect2._runnings || dirtyLevel !== 2)) {
|
|
330
|
+
const lastDirtyLevel = effect2._dirtyLevel;
|
|
331
|
+
effect2._dirtyLevel = dirtyLevel;
|
|
332
|
+
if (lastDirtyLevel === 0 && (!effect2._queryings || dirtyLevel !== 2)) {
|
|
333
|
+
{
|
|
334
|
+
(_a = effect2.onTrigger) == null ? void 0 : _a.call(effect2, extend({ effect: effect2 }, debuggerEventExtraInfo));
|
|
335
|
+
}
|
|
336
|
+
effect2.trigger();
|
|
337
|
+
if (effect2.scheduler) {
|
|
338
|
+
queueEffectSchedulers.push(effect2.scheduler);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
resetScheduling();
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
const createDep = (cleanup, computed) => {
|
|
347
|
+
const dep = /* @__PURE__ */ new Map();
|
|
348
|
+
dep.cleanup = cleanup;
|
|
349
|
+
dep.computed = computed;
|
|
350
|
+
return dep;
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
const targetMap = /* @__PURE__ */ new WeakMap();
|
|
354
|
+
const ITERATE_KEY = Symbol("iterate" );
|
|
355
|
+
const MAP_KEY_ITERATE_KEY = Symbol("Map key iterate" );
|
|
288
356
|
function track(target, type, key) {
|
|
289
357
|
if (shouldTrack && activeEffect) {
|
|
290
358
|
let depsMap = targetMap.get(target);
|
|
@@ -293,35 +361,17 @@ function track(target, type, key) {
|
|
|
293
361
|
}
|
|
294
362
|
let dep = depsMap.get(key);
|
|
295
363
|
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
|
-
);
|
|
364
|
+
depsMap.set(key, dep = createDep(() => depsMap.delete(key)));
|
|
324
365
|
}
|
|
366
|
+
trackEffect(
|
|
367
|
+
activeEffect,
|
|
368
|
+
dep,
|
|
369
|
+
{
|
|
370
|
+
target,
|
|
371
|
+
type,
|
|
372
|
+
key
|
|
373
|
+
}
|
|
374
|
+
);
|
|
325
375
|
}
|
|
326
376
|
}
|
|
327
377
|
function trigger(target, type, key, newValue, oldValue, oldTarget) {
|
|
@@ -369,49 +419,24 @@ function trigger(target, type, key, newValue, oldValue, oldTarget) {
|
|
|
369
419
|
break;
|
|
370
420
|
}
|
|
371
421
|
}
|
|
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();
|
|
422
|
+
pauseScheduling();
|
|
423
|
+
for (const dep of deps) {
|
|
424
|
+
if (dep) {
|
|
425
|
+
triggerEffects(
|
|
426
|
+
dep,
|
|
427
|
+
3,
|
|
428
|
+
{
|
|
429
|
+
target,
|
|
430
|
+
type,
|
|
431
|
+
key,
|
|
432
|
+
newValue,
|
|
433
|
+
oldValue,
|
|
434
|
+
oldTarget
|
|
435
|
+
}
|
|
436
|
+
);
|
|
413
437
|
}
|
|
414
438
|
}
|
|
439
|
+
resetScheduling();
|
|
415
440
|
}
|
|
416
441
|
function getDepFromReactive(object, key) {
|
|
417
442
|
var _a;
|
|
@@ -442,7 +467,9 @@ function createArrayInstrumentations() {
|
|
|
442
467
|
["push", "pop", "shift", "unshift", "splice"].forEach((key) => {
|
|
443
468
|
instrumentations[key] = function(...args) {
|
|
444
469
|
pauseTracking();
|
|
470
|
+
pauseScheduling();
|
|
445
471
|
const res = toRaw(this)[key].apply(this, args);
|
|
472
|
+
resetScheduling();
|
|
446
473
|
resetTracking();
|
|
447
474
|
return res;
|
|
448
475
|
};
|
|
@@ -981,30 +1008,93 @@ function markRaw(value) {
|
|
|
981
1008
|
const toReactive = (value) => isObject(value) ? reactive(value) : value;
|
|
982
1009
|
const toReadonly = (value) => isObject(value) ? readonly(value) : value;
|
|
983
1010
|
|
|
1011
|
+
class ComputedRefImpl {
|
|
1012
|
+
constructor(getter, _setter, isReadonly, isSSR) {
|
|
1013
|
+
this._setter = _setter;
|
|
1014
|
+
this.dep = void 0;
|
|
1015
|
+
this.__v_isRef = true;
|
|
1016
|
+
this["__v_isReadonly"] = false;
|
|
1017
|
+
this.effect = new ReactiveEffect(getter, () => {
|
|
1018
|
+
triggerRefValue(this, 1);
|
|
1019
|
+
});
|
|
1020
|
+
this.effect.computed = this;
|
|
1021
|
+
this.effect.active = this._cacheable = !isSSR;
|
|
1022
|
+
this["__v_isReadonly"] = isReadonly;
|
|
1023
|
+
}
|
|
1024
|
+
get value() {
|
|
1025
|
+
const self = toRaw(this);
|
|
1026
|
+
trackRefValue(self);
|
|
1027
|
+
if (!self._cacheable || self.effect.dirty) {
|
|
1028
|
+
if (hasChanged(self._value, self._value = self.effect.run())) {
|
|
1029
|
+
triggerRefValue(self, 2);
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
return self._value;
|
|
1033
|
+
}
|
|
1034
|
+
set value(newValue) {
|
|
1035
|
+
this._setter(newValue);
|
|
1036
|
+
}
|
|
1037
|
+
// #region polyfill _dirty for backward compatibility third party code for Vue <= 3.3.x
|
|
1038
|
+
get _dirty() {
|
|
1039
|
+
return this.effect.dirty;
|
|
1040
|
+
}
|
|
1041
|
+
set _dirty(v) {
|
|
1042
|
+
this.effect.dirty = v;
|
|
1043
|
+
}
|
|
1044
|
+
// #endregion
|
|
1045
|
+
}
|
|
1046
|
+
function computed(getterOrOptions, debugOptions, isSSR = false) {
|
|
1047
|
+
let getter;
|
|
1048
|
+
let setter;
|
|
1049
|
+
const onlyGetter = isFunction(getterOrOptions);
|
|
1050
|
+
if (onlyGetter) {
|
|
1051
|
+
getter = getterOrOptions;
|
|
1052
|
+
setter = () => {
|
|
1053
|
+
console.warn("Write operation failed: computed value is readonly");
|
|
1054
|
+
} ;
|
|
1055
|
+
} else {
|
|
1056
|
+
getter = getterOrOptions.get;
|
|
1057
|
+
setter = getterOrOptions.set;
|
|
1058
|
+
}
|
|
1059
|
+
const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter, isSSR);
|
|
1060
|
+
if (debugOptions && !isSSR) {
|
|
1061
|
+
cRef.effect.onTrack = debugOptions.onTrack;
|
|
1062
|
+
cRef.effect.onTrigger = debugOptions.onTrigger;
|
|
1063
|
+
}
|
|
1064
|
+
return cRef;
|
|
1065
|
+
}
|
|
1066
|
+
|
|
984
1067
|
function trackRefValue(ref2) {
|
|
985
1068
|
if (shouldTrack && activeEffect) {
|
|
986
1069
|
ref2 = toRaw(ref2);
|
|
987
|
-
|
|
988
|
-
|
|
1070
|
+
trackEffect(
|
|
1071
|
+
activeEffect,
|
|
1072
|
+
ref2.dep || (ref2.dep = createDep(
|
|
1073
|
+
() => ref2.dep = void 0,
|
|
1074
|
+
ref2 instanceof ComputedRefImpl ? ref2 : void 0
|
|
1075
|
+
)),
|
|
1076
|
+
{
|
|
989
1077
|
target: ref2,
|
|
990
1078
|
type: "get",
|
|
991
1079
|
key: "value"
|
|
992
|
-
}
|
|
993
|
-
|
|
1080
|
+
}
|
|
1081
|
+
);
|
|
994
1082
|
}
|
|
995
1083
|
}
|
|
996
|
-
function triggerRefValue(ref2, newVal) {
|
|
1084
|
+
function triggerRefValue(ref2, dirtyLevel = 3, newVal) {
|
|
997
1085
|
ref2 = toRaw(ref2);
|
|
998
1086
|
const dep = ref2.dep;
|
|
999
1087
|
if (dep) {
|
|
1000
|
-
|
|
1001
|
-
|
|
1088
|
+
triggerEffects(
|
|
1089
|
+
dep,
|
|
1090
|
+
dirtyLevel,
|
|
1091
|
+
{
|
|
1002
1092
|
target: ref2,
|
|
1003
1093
|
type: "set",
|
|
1004
1094
|
key: "value",
|
|
1005
1095
|
newValue: newVal
|
|
1006
|
-
}
|
|
1007
|
-
|
|
1096
|
+
}
|
|
1097
|
+
);
|
|
1008
1098
|
}
|
|
1009
1099
|
}
|
|
1010
1100
|
function isRef(r) {
|
|
@@ -1040,12 +1130,12 @@ class RefImpl {
|
|
|
1040
1130
|
if (hasChanged(newVal, this._rawValue)) {
|
|
1041
1131
|
this._rawValue = newVal;
|
|
1042
1132
|
this._value = useDirectValue ? newVal : toReactive(newVal);
|
|
1043
|
-
triggerRefValue(this, newVal);
|
|
1133
|
+
triggerRefValue(this, 3, newVal);
|
|
1044
1134
|
}
|
|
1045
1135
|
}
|
|
1046
1136
|
}
|
|
1047
1137
|
function triggerRef(ref2) {
|
|
1048
|
-
triggerRefValue(ref2, ref2.value );
|
|
1138
|
+
triggerRefValue(ref2, 3, ref2.value );
|
|
1049
1139
|
}
|
|
1050
1140
|
function unref(ref2) {
|
|
1051
1141
|
return isRef(ref2) ? ref2.value : ref2;
|
|
@@ -1143,126 +1233,6 @@ function propertyToRef(source, key, defaultValue) {
|
|
|
1143
1233
|
return isRef(val) ? val : new ObjectRefImpl(source, key, defaultValue);
|
|
1144
1234
|
}
|
|
1145
1235
|
|
|
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
|
-
}
|
|
1236
|
+
const deferredComputed = computed;
|
|
1267
1237
|
|
|
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 };
|
|
1238
|
+
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 };
|