@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,4 +1,4 @@
|
|
|
1
|
-
import { extend, isArray, isSymbol, isMap, isIntegerKey, hasOwn, hasChanged, isObject, makeMap, capitalize, toRawType, def, isFunction
|
|
1
|
+
import { NOOP, extend, isArray, isSymbol, isMap, isIntegerKey, hasOwn, hasChanged, isObject, makeMap, capitalize, toRawType, def, isFunction } from '@vue/shared';
|
|
2
2
|
|
|
3
3
|
function warn(msg, ...args) {
|
|
4
4
|
console.warn(`[Vue warn] ${msg}`, ...args);
|
|
@@ -104,117 +104,120 @@ function onScopeDispose(fn) {
|
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
const createDep = (effects) => {
|
|
108
|
-
const dep = new Set(effects);
|
|
109
|
-
dep.w = 0;
|
|
110
|
-
dep.n = 0;
|
|
111
|
-
return dep;
|
|
112
|
-
};
|
|
113
|
-
const wasTracked = (dep) => (dep.w & trackOpBit) > 0;
|
|
114
|
-
const newTracked = (dep) => (dep.n & trackOpBit) > 0;
|
|
115
|
-
const initDepMarkers = ({ deps }) => {
|
|
116
|
-
if (deps.length) {
|
|
117
|
-
for (let i = 0; i < deps.length; i++) {
|
|
118
|
-
deps[i].w |= trackOpBit;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
const finalizeDepMarkers = (effect) => {
|
|
123
|
-
const { deps } = effect;
|
|
124
|
-
if (deps.length) {
|
|
125
|
-
let ptr = 0;
|
|
126
|
-
for (let i = 0; i < deps.length; i++) {
|
|
127
|
-
const dep = deps[i];
|
|
128
|
-
if (wasTracked(dep) && !newTracked(dep)) {
|
|
129
|
-
dep.delete(effect);
|
|
130
|
-
} else {
|
|
131
|
-
deps[ptr++] = dep;
|
|
132
|
-
}
|
|
133
|
-
dep.w &= ~trackOpBit;
|
|
134
|
-
dep.n &= ~trackOpBit;
|
|
135
|
-
}
|
|
136
|
-
deps.length = ptr;
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
const targetMap = /* @__PURE__ */ new WeakMap();
|
|
141
|
-
let effectTrackDepth = 0;
|
|
142
|
-
let trackOpBit = 1;
|
|
143
|
-
const maxMarkerBits = 30;
|
|
144
107
|
let activeEffect;
|
|
145
|
-
const ITERATE_KEY = Symbol(!!(process.env.NODE_ENV !== "production") ? "iterate" : "");
|
|
146
|
-
const MAP_KEY_ITERATE_KEY = Symbol(!!(process.env.NODE_ENV !== "production") ? "Map key iterate" : "");
|
|
147
108
|
class ReactiveEffect {
|
|
148
|
-
constructor(fn, scheduler
|
|
109
|
+
constructor(fn, trigger, scheduler, scope) {
|
|
149
110
|
this.fn = fn;
|
|
111
|
+
this.trigger = trigger;
|
|
150
112
|
this.scheduler = scheduler;
|
|
151
113
|
this.active = true;
|
|
152
114
|
this.deps = [];
|
|
153
|
-
|
|
115
|
+
/**
|
|
116
|
+
* @internal
|
|
117
|
+
*/
|
|
118
|
+
this._dirtyLevel = 3;
|
|
119
|
+
/**
|
|
120
|
+
* @internal
|
|
121
|
+
*/
|
|
122
|
+
this._trackId = 0;
|
|
123
|
+
/**
|
|
124
|
+
* @internal
|
|
125
|
+
*/
|
|
126
|
+
this._runnings = 0;
|
|
127
|
+
/**
|
|
128
|
+
* @internal
|
|
129
|
+
*/
|
|
130
|
+
this._queryings = 0;
|
|
131
|
+
/**
|
|
132
|
+
* @internal
|
|
133
|
+
*/
|
|
134
|
+
this._depsLength = 0;
|
|
154
135
|
recordEffectScope(this, scope);
|
|
155
136
|
}
|
|
137
|
+
get dirty() {
|
|
138
|
+
if (this._dirtyLevel === 1) {
|
|
139
|
+
this._dirtyLevel = 0;
|
|
140
|
+
this._queryings++;
|
|
141
|
+
pauseTracking();
|
|
142
|
+
for (const dep of this.deps) {
|
|
143
|
+
if (dep.computed) {
|
|
144
|
+
triggerComputed(dep.computed);
|
|
145
|
+
if (this._dirtyLevel >= 2) {
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
resetTracking();
|
|
151
|
+
this._queryings--;
|
|
152
|
+
}
|
|
153
|
+
return this._dirtyLevel >= 2;
|
|
154
|
+
}
|
|
155
|
+
set dirty(v) {
|
|
156
|
+
this._dirtyLevel = v ? 3 : 0;
|
|
157
|
+
}
|
|
156
158
|
run() {
|
|
159
|
+
this._dirtyLevel = 0;
|
|
157
160
|
if (!this.active) {
|
|
158
161
|
return this.fn();
|
|
159
162
|
}
|
|
160
|
-
let parent = activeEffect;
|
|
161
163
|
let lastShouldTrack = shouldTrack;
|
|
162
|
-
|
|
163
|
-
if (parent === this) {
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
parent = parent.parent;
|
|
167
|
-
}
|
|
164
|
+
let lastEffect = activeEffect;
|
|
168
165
|
try {
|
|
169
|
-
this.parent = activeEffect;
|
|
170
|
-
activeEffect = this;
|
|
171
166
|
shouldTrack = true;
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
} else {
|
|
176
|
-
cleanupEffect(this);
|
|
177
|
-
}
|
|
167
|
+
activeEffect = this;
|
|
168
|
+
this._runnings++;
|
|
169
|
+
preCleanupEffect(this);
|
|
178
170
|
return this.fn();
|
|
179
171
|
} finally {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
trackOpBit = 1 << --effectTrackDepth;
|
|
184
|
-
activeEffect = this.parent;
|
|
172
|
+
postCleanupEffect(this);
|
|
173
|
+
this._runnings--;
|
|
174
|
+
activeEffect = lastEffect;
|
|
185
175
|
shouldTrack = lastShouldTrack;
|
|
186
|
-
this.parent = void 0;
|
|
187
|
-
if (this.deferStop) {
|
|
188
|
-
this.stop();
|
|
189
|
-
}
|
|
190
176
|
}
|
|
191
177
|
}
|
|
192
178
|
stop() {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
this.onStop();
|
|
199
|
-
}
|
|
179
|
+
var _a;
|
|
180
|
+
if (this.active) {
|
|
181
|
+
preCleanupEffect(this);
|
|
182
|
+
postCleanupEffect(this);
|
|
183
|
+
(_a = this.onStop) == null ? void 0 : _a.call(this);
|
|
200
184
|
this.active = false;
|
|
201
185
|
}
|
|
202
186
|
}
|
|
203
187
|
}
|
|
204
|
-
function
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
188
|
+
function triggerComputed(computed) {
|
|
189
|
+
return computed.value;
|
|
190
|
+
}
|
|
191
|
+
function preCleanupEffect(effect2) {
|
|
192
|
+
effect2._trackId++;
|
|
193
|
+
effect2._depsLength = 0;
|
|
194
|
+
}
|
|
195
|
+
function postCleanupEffect(effect2) {
|
|
196
|
+
if (effect2.deps && effect2.deps.length > effect2._depsLength) {
|
|
197
|
+
for (let i = effect2._depsLength; i < effect2.deps.length; i++) {
|
|
198
|
+
cleanupDepEffect(effect2.deps[i], effect2);
|
|
199
|
+
}
|
|
200
|
+
effect2.deps.length = effect2._depsLength;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
function cleanupDepEffect(dep, effect2) {
|
|
204
|
+
const trackId = dep.get(effect2);
|
|
205
|
+
if (trackId !== void 0 && effect2._trackId !== trackId) {
|
|
206
|
+
dep.delete(effect2);
|
|
207
|
+
if (dep.size === 0) {
|
|
208
|
+
dep.cleanup();
|
|
209
209
|
}
|
|
210
|
-
deps.length = 0;
|
|
211
210
|
}
|
|
212
211
|
}
|
|
213
212
|
function effect(fn, options) {
|
|
214
213
|
if (fn.effect instanceof ReactiveEffect) {
|
|
215
214
|
fn = fn.effect.fn;
|
|
216
215
|
}
|
|
217
|
-
const _effect = new ReactiveEffect(fn)
|
|
216
|
+
const _effect = new ReactiveEffect(fn, NOOP, () => {
|
|
217
|
+
if (_effect.dirty) {
|
|
218
|
+
_effect.run();
|
|
219
|
+
}
|
|
220
|
+
});
|
|
218
221
|
if (options) {
|
|
219
222
|
extend(_effect, options);
|
|
220
223
|
if (options.scope)
|
|
@@ -231,6 +234,7 @@ function stop(runner) {
|
|
|
231
234
|
runner.effect.stop();
|
|
232
235
|
}
|
|
233
236
|
let shouldTrack = true;
|
|
237
|
+
let pauseScheduleStack = 0;
|
|
234
238
|
const trackStack = [];
|
|
235
239
|
function pauseTracking() {
|
|
236
240
|
trackStack.push(shouldTrack);
|
|
@@ -244,6 +248,68 @@ function resetTracking() {
|
|
|
244
248
|
const last = trackStack.pop();
|
|
245
249
|
shouldTrack = last === void 0 ? true : last;
|
|
246
250
|
}
|
|
251
|
+
function pauseScheduling() {
|
|
252
|
+
pauseScheduleStack++;
|
|
253
|
+
}
|
|
254
|
+
function resetScheduling() {
|
|
255
|
+
pauseScheduleStack--;
|
|
256
|
+
while (!pauseScheduleStack && queueEffectSchedulers.length) {
|
|
257
|
+
queueEffectSchedulers.shift()();
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
function trackEffect(effect2, dep, debuggerEventExtraInfo) {
|
|
261
|
+
var _a;
|
|
262
|
+
if (dep.get(effect2) !== effect2._trackId) {
|
|
263
|
+
dep.set(effect2, effect2._trackId);
|
|
264
|
+
const oldDep = effect2.deps[effect2._depsLength];
|
|
265
|
+
if (oldDep !== dep) {
|
|
266
|
+
if (oldDep) {
|
|
267
|
+
cleanupDepEffect(oldDep, effect2);
|
|
268
|
+
}
|
|
269
|
+
effect2.deps[effect2._depsLength++] = dep;
|
|
270
|
+
} else {
|
|
271
|
+
effect2._depsLength++;
|
|
272
|
+
}
|
|
273
|
+
if (!!(process.env.NODE_ENV !== "production")) {
|
|
274
|
+
(_a = effect2.onTrack) == null ? void 0 : _a.call(effect2, extend({ effect: effect2 }, debuggerEventExtraInfo));
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
const queueEffectSchedulers = [];
|
|
279
|
+
function triggerEffects(dep, dirtyLevel, debuggerEventExtraInfo) {
|
|
280
|
+
var _a;
|
|
281
|
+
pauseScheduling();
|
|
282
|
+
for (const effect2 of dep.keys()) {
|
|
283
|
+
if (!effect2.allowRecurse && effect2._runnings) {
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
if (effect2._dirtyLevel < dirtyLevel && (!effect2._runnings || dirtyLevel !== 2)) {
|
|
287
|
+
const lastDirtyLevel = effect2._dirtyLevel;
|
|
288
|
+
effect2._dirtyLevel = dirtyLevel;
|
|
289
|
+
if (lastDirtyLevel === 0 && (!effect2._queryings || dirtyLevel !== 2)) {
|
|
290
|
+
if (!!(process.env.NODE_ENV !== "production")) {
|
|
291
|
+
(_a = effect2.onTrigger) == null ? void 0 : _a.call(effect2, extend({ effect: effect2 }, debuggerEventExtraInfo));
|
|
292
|
+
}
|
|
293
|
+
effect2.trigger();
|
|
294
|
+
if (effect2.scheduler) {
|
|
295
|
+
queueEffectSchedulers.push(effect2.scheduler);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
resetScheduling();
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const createDep = (cleanup, computed) => {
|
|
304
|
+
const dep = /* @__PURE__ */ new Map();
|
|
305
|
+
dep.cleanup = cleanup;
|
|
306
|
+
dep.computed = computed;
|
|
307
|
+
return dep;
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
const targetMap = /* @__PURE__ */ new WeakMap();
|
|
311
|
+
const ITERATE_KEY = Symbol(!!(process.env.NODE_ENV !== "production") ? "iterate" : "");
|
|
312
|
+
const MAP_KEY_ITERATE_KEY = Symbol(!!(process.env.NODE_ENV !== "production") ? "Map key iterate" : "");
|
|
247
313
|
function track(target, type, key) {
|
|
248
314
|
if (shouldTrack && activeEffect) {
|
|
249
315
|
let depsMap = targetMap.get(target);
|
|
@@ -252,35 +318,17 @@ function track(target, type, key) {
|
|
|
252
318
|
}
|
|
253
319
|
let dep = depsMap.get(key);
|
|
254
320
|
if (!dep) {
|
|
255
|
-
depsMap.set(key, dep = createDep());
|
|
256
|
-
}
|
|
257
|
-
const eventInfo = !!(process.env.NODE_ENV !== "production") ? { effect: activeEffect, target, type, key } : void 0;
|
|
258
|
-
trackEffects(dep, eventInfo);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
function trackEffects(dep, debuggerEventExtraInfo) {
|
|
262
|
-
let shouldTrack2 = false;
|
|
263
|
-
if (effectTrackDepth <= maxMarkerBits) {
|
|
264
|
-
if (!newTracked(dep)) {
|
|
265
|
-
dep.n |= trackOpBit;
|
|
266
|
-
shouldTrack2 = !wasTracked(dep);
|
|
267
|
-
}
|
|
268
|
-
} else {
|
|
269
|
-
shouldTrack2 = !dep.has(activeEffect);
|
|
270
|
-
}
|
|
271
|
-
if (shouldTrack2) {
|
|
272
|
-
dep.add(activeEffect);
|
|
273
|
-
activeEffect.deps.push(dep);
|
|
274
|
-
if (!!(process.env.NODE_ENV !== "production") && activeEffect.onTrack) {
|
|
275
|
-
activeEffect.onTrack(
|
|
276
|
-
extend(
|
|
277
|
-
{
|
|
278
|
-
effect: activeEffect
|
|
279
|
-
},
|
|
280
|
-
debuggerEventExtraInfo
|
|
281
|
-
)
|
|
282
|
-
);
|
|
321
|
+
depsMap.set(key, dep = createDep(() => depsMap.delete(key)));
|
|
283
322
|
}
|
|
323
|
+
trackEffect(
|
|
324
|
+
activeEffect,
|
|
325
|
+
dep,
|
|
326
|
+
!!(process.env.NODE_ENV !== "production") ? {
|
|
327
|
+
target,
|
|
328
|
+
type,
|
|
329
|
+
key
|
|
330
|
+
} : void 0
|
|
331
|
+
);
|
|
284
332
|
}
|
|
285
333
|
}
|
|
286
334
|
function trigger(target, type, key, newValue, oldValue, oldTarget) {
|
|
@@ -328,53 +376,24 @@ function trigger(target, type, key, newValue, oldValue, oldTarget) {
|
|
|
328
376
|
break;
|
|
329
377
|
}
|
|
330
378
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
if (
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
}
|
|
347
|
-
if (!!(process.env.NODE_ENV !== "production")) {
|
|
348
|
-
triggerEffects(createDep(effects), eventInfo);
|
|
349
|
-
} else {
|
|
350
|
-
triggerEffects(createDep(effects));
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
function triggerEffects(dep, debuggerEventExtraInfo) {
|
|
355
|
-
const effects = isArray(dep) ? dep : [...dep];
|
|
356
|
-
for (const effect2 of effects) {
|
|
357
|
-
if (effect2.computed) {
|
|
358
|
-
triggerEffect(effect2, debuggerEventExtraInfo);
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
for (const effect2 of effects) {
|
|
362
|
-
if (!effect2.computed) {
|
|
363
|
-
triggerEffect(effect2, debuggerEventExtraInfo);
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
function triggerEffect(effect2, debuggerEventExtraInfo) {
|
|
368
|
-
if (effect2 !== activeEffect || effect2.allowRecurse) {
|
|
369
|
-
if (!!(process.env.NODE_ENV !== "production") && effect2.onTrigger) {
|
|
370
|
-
effect2.onTrigger(extend({ effect: effect2 }, debuggerEventExtraInfo));
|
|
371
|
-
}
|
|
372
|
-
if (effect2.scheduler) {
|
|
373
|
-
effect2.scheduler();
|
|
374
|
-
} else {
|
|
375
|
-
effect2.run();
|
|
379
|
+
pauseScheduling();
|
|
380
|
+
for (const dep of deps) {
|
|
381
|
+
if (dep) {
|
|
382
|
+
triggerEffects(
|
|
383
|
+
dep,
|
|
384
|
+
3,
|
|
385
|
+
!!(process.env.NODE_ENV !== "production") ? {
|
|
386
|
+
target,
|
|
387
|
+
type,
|
|
388
|
+
key,
|
|
389
|
+
newValue,
|
|
390
|
+
oldValue,
|
|
391
|
+
oldTarget
|
|
392
|
+
} : void 0
|
|
393
|
+
);
|
|
376
394
|
}
|
|
377
395
|
}
|
|
396
|
+
resetScheduling();
|
|
378
397
|
}
|
|
379
398
|
function getDepFromReactive(object, key) {
|
|
380
399
|
var _a;
|
|
@@ -405,7 +424,9 @@ function createArrayInstrumentations() {
|
|
|
405
424
|
["push", "pop", "shift", "unshift", "splice"].forEach((key) => {
|
|
406
425
|
instrumentations[key] = function(...args) {
|
|
407
426
|
pauseTracking();
|
|
427
|
+
pauseScheduling();
|
|
408
428
|
const res = toRaw(this)[key].apply(this, args);
|
|
429
|
+
resetScheduling();
|
|
409
430
|
resetTracking();
|
|
410
431
|
return res;
|
|
411
432
|
};
|
|
@@ -944,34 +965,94 @@ function markRaw(value) {
|
|
|
944
965
|
const toReactive = (value) => isObject(value) ? reactive(value) : value;
|
|
945
966
|
const toReadonly = (value) => isObject(value) ? readonly(value) : value;
|
|
946
967
|
|
|
968
|
+
class ComputedRefImpl {
|
|
969
|
+
constructor(getter, _setter, isReadonly, isSSR) {
|
|
970
|
+
this._setter = _setter;
|
|
971
|
+
this.dep = void 0;
|
|
972
|
+
this.__v_isRef = true;
|
|
973
|
+
this["__v_isReadonly"] = false;
|
|
974
|
+
this.effect = new ReactiveEffect(
|
|
975
|
+
() => getter(this._value),
|
|
976
|
+
() => triggerRefValue(this, 1)
|
|
977
|
+
);
|
|
978
|
+
this.effect.computed = this;
|
|
979
|
+
this.effect.active = this._cacheable = !isSSR;
|
|
980
|
+
this["__v_isReadonly"] = isReadonly;
|
|
981
|
+
}
|
|
982
|
+
get value() {
|
|
983
|
+
const self = toRaw(this);
|
|
984
|
+
trackRefValue(self);
|
|
985
|
+
if (!self._cacheable || self.effect.dirty) {
|
|
986
|
+
if (hasChanged(self._value, self._value = self.effect.run())) {
|
|
987
|
+
triggerRefValue(self, 2);
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
return self._value;
|
|
991
|
+
}
|
|
992
|
+
set value(newValue) {
|
|
993
|
+
this._setter(newValue);
|
|
994
|
+
}
|
|
995
|
+
// #region polyfill _dirty for backward compatibility third party code for Vue <= 3.3.x
|
|
996
|
+
get _dirty() {
|
|
997
|
+
return this.effect.dirty;
|
|
998
|
+
}
|
|
999
|
+
set _dirty(v) {
|
|
1000
|
+
this.effect.dirty = v;
|
|
1001
|
+
}
|
|
1002
|
+
// #endregion
|
|
1003
|
+
}
|
|
1004
|
+
function computed(getterOrOptions, debugOptions, isSSR = false) {
|
|
1005
|
+
let getter;
|
|
1006
|
+
let setter;
|
|
1007
|
+
const onlyGetter = isFunction(getterOrOptions);
|
|
1008
|
+
if (onlyGetter) {
|
|
1009
|
+
getter = getterOrOptions;
|
|
1010
|
+
setter = !!(process.env.NODE_ENV !== "production") ? () => {
|
|
1011
|
+
console.warn("Write operation failed: computed value is readonly");
|
|
1012
|
+
} : NOOP;
|
|
1013
|
+
} else {
|
|
1014
|
+
getter = getterOrOptions.get;
|
|
1015
|
+
setter = getterOrOptions.set;
|
|
1016
|
+
}
|
|
1017
|
+
const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter, isSSR);
|
|
1018
|
+
if (!!(process.env.NODE_ENV !== "production") && debugOptions && !isSSR) {
|
|
1019
|
+
cRef.effect.onTrack = debugOptions.onTrack;
|
|
1020
|
+
cRef.effect.onTrigger = debugOptions.onTrigger;
|
|
1021
|
+
}
|
|
1022
|
+
return cRef;
|
|
1023
|
+
}
|
|
1024
|
+
|
|
947
1025
|
function trackRefValue(ref2) {
|
|
948
1026
|
if (shouldTrack && activeEffect) {
|
|
949
1027
|
ref2 = toRaw(ref2);
|
|
950
|
-
|
|
951
|
-
|
|
1028
|
+
trackEffect(
|
|
1029
|
+
activeEffect,
|
|
1030
|
+
ref2.dep || (ref2.dep = createDep(
|
|
1031
|
+
() => ref2.dep = void 0,
|
|
1032
|
+
ref2 instanceof ComputedRefImpl ? ref2 : void 0
|
|
1033
|
+
)),
|
|
1034
|
+
!!(process.env.NODE_ENV !== "production") ? {
|
|
952
1035
|
target: ref2,
|
|
953
1036
|
type: "get",
|
|
954
1037
|
key: "value"
|
|
955
|
-
}
|
|
956
|
-
|
|
957
|
-
trackEffects(ref2.dep || (ref2.dep = createDep()));
|
|
958
|
-
}
|
|
1038
|
+
} : void 0
|
|
1039
|
+
);
|
|
959
1040
|
}
|
|
960
1041
|
}
|
|
961
|
-
function triggerRefValue(ref2, newVal) {
|
|
1042
|
+
function triggerRefValue(ref2, dirtyLevel = 3, newVal) {
|
|
962
1043
|
ref2 = toRaw(ref2);
|
|
963
1044
|
const dep = ref2.dep;
|
|
964
1045
|
if (dep) {
|
|
965
|
-
|
|
966
|
-
|
|
1046
|
+
triggerEffects(
|
|
1047
|
+
dep,
|
|
1048
|
+
dirtyLevel,
|
|
1049
|
+
!!(process.env.NODE_ENV !== "production") ? {
|
|
967
1050
|
target: ref2,
|
|
968
1051
|
type: "set",
|
|
969
1052
|
key: "value",
|
|
970
1053
|
newValue: newVal
|
|
971
|
-
}
|
|
972
|
-
|
|
973
|
-
triggerEffects(dep);
|
|
974
|
-
}
|
|
1054
|
+
} : void 0
|
|
1055
|
+
);
|
|
975
1056
|
}
|
|
976
1057
|
}
|
|
977
1058
|
function isRef(r) {
|
|
@@ -1007,12 +1088,12 @@ class RefImpl {
|
|
|
1007
1088
|
if (hasChanged(newVal, this._rawValue)) {
|
|
1008
1089
|
this._rawValue = newVal;
|
|
1009
1090
|
this._value = useDirectValue ? newVal : toReactive(newVal);
|
|
1010
|
-
triggerRefValue(this, newVal);
|
|
1091
|
+
triggerRefValue(this, 3, newVal);
|
|
1011
1092
|
}
|
|
1012
1093
|
}
|
|
1013
1094
|
}
|
|
1014
1095
|
function triggerRef(ref2) {
|
|
1015
|
-
triggerRefValue(ref2, !!(process.env.NODE_ENV !== "production") ? ref2.value : void 0);
|
|
1096
|
+
triggerRefValue(ref2, 3, !!(process.env.NODE_ENV !== "production") ? ref2.value : void 0);
|
|
1016
1097
|
}
|
|
1017
1098
|
function unref(ref2) {
|
|
1018
1099
|
return isRef(ref2) ? ref2.value : ref2;
|
|
@@ -1110,126 +1191,6 @@ function propertyToRef(source, key, defaultValue) {
|
|
|
1110
1191
|
return isRef(val) ? val : new ObjectRefImpl(source, key, defaultValue);
|
|
1111
1192
|
}
|
|
1112
1193
|
|
|
1113
|
-
|
|
1114
|
-
constructor(getter, _setter, isReadonly, isSSR) {
|
|
1115
|
-
this._setter = _setter;
|
|
1116
|
-
this.dep = void 0;
|
|
1117
|
-
this.__v_isRef = true;
|
|
1118
|
-
this["__v_isReadonly"] = false;
|
|
1119
|
-
this._dirty = true;
|
|
1120
|
-
this.effect = new ReactiveEffect(getter, () => {
|
|
1121
|
-
if (!this._dirty) {
|
|
1122
|
-
this._dirty = true;
|
|
1123
|
-
triggerRefValue(this);
|
|
1124
|
-
}
|
|
1125
|
-
});
|
|
1126
|
-
this.effect.computed = this;
|
|
1127
|
-
this.effect.active = this._cacheable = !isSSR;
|
|
1128
|
-
this["__v_isReadonly"] = isReadonly;
|
|
1129
|
-
}
|
|
1130
|
-
get value() {
|
|
1131
|
-
const self = toRaw(this);
|
|
1132
|
-
trackRefValue(self);
|
|
1133
|
-
if (self._dirty || !self._cacheable) {
|
|
1134
|
-
self._dirty = false;
|
|
1135
|
-
self._value = self.effect.run();
|
|
1136
|
-
}
|
|
1137
|
-
return self._value;
|
|
1138
|
-
}
|
|
1139
|
-
set value(newValue) {
|
|
1140
|
-
this._setter(newValue);
|
|
1141
|
-
}
|
|
1142
|
-
}
|
|
1143
|
-
function computed(getterOrOptions, debugOptions, isSSR = false) {
|
|
1144
|
-
let getter;
|
|
1145
|
-
let setter;
|
|
1146
|
-
const onlyGetter = isFunction(getterOrOptions);
|
|
1147
|
-
if (onlyGetter) {
|
|
1148
|
-
getter = getterOrOptions;
|
|
1149
|
-
setter = !!(process.env.NODE_ENV !== "production") ? () => {
|
|
1150
|
-
console.warn("Write operation failed: computed value is readonly");
|
|
1151
|
-
} : NOOP;
|
|
1152
|
-
} else {
|
|
1153
|
-
getter = getterOrOptions.get;
|
|
1154
|
-
setter = getterOrOptions.set;
|
|
1155
|
-
}
|
|
1156
|
-
const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter, isSSR);
|
|
1157
|
-
if (!!(process.env.NODE_ENV !== "production") && debugOptions && !isSSR) {
|
|
1158
|
-
cRef.effect.onTrack = debugOptions.onTrack;
|
|
1159
|
-
cRef.effect.onTrigger = debugOptions.onTrigger;
|
|
1160
|
-
}
|
|
1161
|
-
return cRef;
|
|
1162
|
-
}
|
|
1163
|
-
|
|
1164
|
-
const tick = /* @__PURE__ */ Promise.resolve();
|
|
1165
|
-
const queue = [];
|
|
1166
|
-
let queued = false;
|
|
1167
|
-
const scheduler = (fn) => {
|
|
1168
|
-
queue.push(fn);
|
|
1169
|
-
if (!queued) {
|
|
1170
|
-
queued = true;
|
|
1171
|
-
tick.then(flush);
|
|
1172
|
-
}
|
|
1173
|
-
};
|
|
1174
|
-
const flush = () => {
|
|
1175
|
-
for (let i = 0; i < queue.length; i++) {
|
|
1176
|
-
queue[i]();
|
|
1177
|
-
}
|
|
1178
|
-
queue.length = 0;
|
|
1179
|
-
queued = false;
|
|
1180
|
-
};
|
|
1181
|
-
class DeferredComputedRefImpl {
|
|
1182
|
-
constructor(getter) {
|
|
1183
|
-
this.dep = void 0;
|
|
1184
|
-
this._dirty = true;
|
|
1185
|
-
this.__v_isRef = true;
|
|
1186
|
-
this["__v_isReadonly"] = true;
|
|
1187
|
-
let compareTarget;
|
|
1188
|
-
let hasCompareTarget = false;
|
|
1189
|
-
let scheduled = false;
|
|
1190
|
-
this.effect = new ReactiveEffect(getter, (computedTrigger) => {
|
|
1191
|
-
if (this.dep) {
|
|
1192
|
-
if (computedTrigger) {
|
|
1193
|
-
compareTarget = this._value;
|
|
1194
|
-
hasCompareTarget = true;
|
|
1195
|
-
} else if (!scheduled) {
|
|
1196
|
-
const valueToCompare = hasCompareTarget ? compareTarget : this._value;
|
|
1197
|
-
scheduled = true;
|
|
1198
|
-
hasCompareTarget = false;
|
|
1199
|
-
scheduler(() => {
|
|
1200
|
-
if (this.effect.active && this._get() !== valueToCompare) {
|
|
1201
|
-
triggerRefValue(this);
|
|
1202
|
-
}
|
|
1203
|
-
scheduled = false;
|
|
1204
|
-
});
|
|
1205
|
-
}
|
|
1206
|
-
for (const e of this.dep) {
|
|
1207
|
-
if (e.computed instanceof DeferredComputedRefImpl) {
|
|
1208
|
-
e.scheduler(
|
|
1209
|
-
true
|
|
1210
|
-
/* computedTrigger */
|
|
1211
|
-
);
|
|
1212
|
-
}
|
|
1213
|
-
}
|
|
1214
|
-
}
|
|
1215
|
-
this._dirty = true;
|
|
1216
|
-
});
|
|
1217
|
-
this.effect.computed = this;
|
|
1218
|
-
}
|
|
1219
|
-
_get() {
|
|
1220
|
-
if (this._dirty) {
|
|
1221
|
-
this._dirty = false;
|
|
1222
|
-
return this._value = this.effect.run();
|
|
1223
|
-
}
|
|
1224
|
-
return this._value;
|
|
1225
|
-
}
|
|
1226
|
-
get value() {
|
|
1227
|
-
trackRefValue(this);
|
|
1228
|
-
return toRaw(this)._get();
|
|
1229
|
-
}
|
|
1230
|
-
}
|
|
1231
|
-
function deferredComputed(getter) {
|
|
1232
|
-
return new DeferredComputedRefImpl(getter);
|
|
1233
|
-
}
|
|
1194
|
+
const deferredComputed = computed;
|
|
1234
1195
|
|
|
1235
|
-
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 };
|
|
1196
|
+
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 };
|