@vue/reactivity 3.5.16 → 3.6.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.
@@ -1,634 +1,367 @@
1
1
  /**
2
- * @vue/reactivity v3.5.16
2
+ * @vue/reactivity v3.6.0-alpha.1
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
6
- import { extend, hasChanged, isArray, isIntegerKey, isSymbol, isMap, hasOwn, makeMap, isObject, capitalize, toRawType, def, isFunction, EMPTY_OBJ, isSet, isPlainObject, remove, NOOP } from '@vue/shared';
6
+ import { extend, isArray, isIntegerKey, isSymbol, isMap, hasOwn, hasChanged, makeMap, isObject, capitalize, toRawType, def, isFunction, EMPTY_OBJ, isSet, isPlainObject, NOOP } from '@vue/shared';
7
7
 
8
8
  function warn(msg, ...args) {
9
9
  console.warn(`[Vue warn] ${msg}`, ...args);
10
10
  }
11
11
 
12
- let activeEffectScope;
13
- class EffectScope {
14
- constructor(detached = false) {
15
- this.detached = detached;
16
- /**
17
- * @internal
18
- */
19
- this._active = true;
20
- /**
21
- * @internal track `on` calls, allow `on` call multiple times
22
- */
23
- this._on = 0;
24
- /**
25
- * @internal
26
- */
27
- this.effects = [];
28
- /**
29
- * @internal
30
- */
31
- this.cleanups = [];
32
- this._isPaused = false;
33
- this.parent = activeEffectScope;
34
- if (!detached && activeEffectScope) {
35
- this.index = (activeEffectScope.scopes || (activeEffectScope.scopes = [])).push(
36
- this
37
- ) - 1;
38
- }
39
- }
40
- get active() {
41
- return this._active;
42
- }
43
- pause() {
44
- if (this._active) {
45
- this._isPaused = true;
46
- let i, l;
47
- if (this.scopes) {
48
- for (i = 0, l = this.scopes.length; i < l; i++) {
49
- this.scopes[i].pause();
50
- }
51
- }
52
- for (i = 0, l = this.effects.length; i < l; i++) {
53
- this.effects[i].pause();
54
- }
55
- }
56
- }
57
- /**
58
- * Resumes the effect scope, including all child scopes and effects.
59
- */
60
- resume() {
61
- if (this._active) {
62
- if (this._isPaused) {
63
- this._isPaused = false;
64
- let i, l;
65
- if (this.scopes) {
66
- for (i = 0, l = this.scopes.length; i < l; i++) {
67
- this.scopes[i].resume();
68
- }
69
- }
70
- for (i = 0, l = this.effects.length; i < l; i++) {
71
- this.effects[i].resume();
72
- }
73
- }
74
- }
75
- }
76
- run(fn) {
77
- if (this._active) {
78
- const currentEffectScope = activeEffectScope;
79
- try {
80
- activeEffectScope = this;
81
- return fn();
82
- } finally {
83
- activeEffectScope = currentEffectScope;
84
- }
85
- } else if (!!(process.env.NODE_ENV !== "production")) {
86
- warn(`cannot run an inactive effect scope.`);
87
- }
88
- }
89
- /**
90
- * This should only be called on non-detached scopes
91
- * @internal
92
- */
93
- on() {
94
- if (++this._on === 1) {
95
- this.prevScope = activeEffectScope;
96
- activeEffectScope = this;
97
- }
98
- }
99
- /**
100
- * This should only be called on non-detached scopes
101
- * @internal
102
- */
103
- off() {
104
- if (this._on > 0 && --this._on === 0) {
105
- activeEffectScope = this.prevScope;
106
- this.prevScope = void 0;
107
- }
108
- }
109
- stop(fromParent) {
110
- if (this._active) {
111
- this._active = false;
112
- let i, l;
113
- for (i = 0, l = this.effects.length; i < l; i++) {
114
- this.effects[i].stop();
115
- }
116
- this.effects.length = 0;
117
- for (i = 0, l = this.cleanups.length; i < l; i++) {
118
- this.cleanups[i]();
119
- }
120
- this.cleanups.length = 0;
121
- if (this.scopes) {
122
- for (i = 0, l = this.scopes.length; i < l; i++) {
123
- this.scopes[i].stop(true);
124
- }
125
- this.scopes.length = 0;
126
- }
127
- if (!this.detached && this.parent && !fromParent) {
128
- const last = this.parent.scopes.pop();
129
- if (last && last !== this) {
130
- this.parent.scopes[this.index] = last;
131
- last.index = this.index;
132
- }
133
- }
134
- this.parent = void 0;
135
- }
12
+ var ReactiveFlags$1 = /* @__PURE__ */ ((ReactiveFlags2) => {
13
+ ReactiveFlags2[ReactiveFlags2["None"] = 0] = "None";
14
+ ReactiveFlags2[ReactiveFlags2["Mutable"] = 1] = "Mutable";
15
+ ReactiveFlags2[ReactiveFlags2["Watching"] = 2] = "Watching";
16
+ ReactiveFlags2[ReactiveFlags2["RecursedCheck"] = 4] = "RecursedCheck";
17
+ ReactiveFlags2[ReactiveFlags2["Recursed"] = 8] = "Recursed";
18
+ ReactiveFlags2[ReactiveFlags2["Dirty"] = 16] = "Dirty";
19
+ ReactiveFlags2[ReactiveFlags2["Pending"] = 32] = "Pending";
20
+ return ReactiveFlags2;
21
+ })(ReactiveFlags$1 || {});
22
+ const notifyBuffer = [];
23
+ let batchDepth = 0;
24
+ let activeSub = void 0;
25
+ let notifyIndex = 0;
26
+ let notifyBufferLength = 0;
27
+ function setActiveSub(sub) {
28
+ try {
29
+ return activeSub;
30
+ } finally {
31
+ activeSub = sub;
136
32
  }
137
33
  }
138
- function effectScope(detached) {
139
- return new EffectScope(detached);
140
- }
141
- function getCurrentScope() {
142
- return activeEffectScope;
34
+ function startBatch() {
35
+ ++batchDepth;
143
36
  }
144
- function onScopeDispose(fn, failSilently = false) {
145
- if (activeEffectScope) {
146
- activeEffectScope.cleanups.push(fn);
147
- } else if (!!(process.env.NODE_ENV !== "production") && !failSilently) {
148
- warn(
149
- `onScopeDispose() is called when there is no active effect scope to be associated with.`
150
- );
37
+ function endBatch() {
38
+ if (!--batchDepth && notifyBufferLength) {
39
+ flush();
151
40
  }
152
41
  }
153
-
154
- let activeSub;
155
- const EffectFlags = {
156
- "ACTIVE": 1,
157
- "1": "ACTIVE",
158
- "RUNNING": 2,
159
- "2": "RUNNING",
160
- "TRACKING": 4,
161
- "4": "TRACKING",
162
- "NOTIFIED": 8,
163
- "8": "NOTIFIED",
164
- "DIRTY": 16,
165
- "16": "DIRTY",
166
- "ALLOW_RECURSE": 32,
167
- "32": "ALLOW_RECURSE",
168
- "PAUSED": 64,
169
- "64": "PAUSED",
170
- "EVALUATED": 128,
171
- "128": "EVALUATED"
172
- };
173
- const pausedQueueEffects = /* @__PURE__ */ new WeakSet();
174
- class ReactiveEffect {
175
- constructor(fn) {
176
- this.fn = fn;
177
- /**
178
- * @internal
179
- */
180
- this.deps = void 0;
181
- /**
182
- * @internal
183
- */
184
- this.depsTail = void 0;
185
- /**
186
- * @internal
187
- */
188
- this.flags = 1 | 4;
189
- /**
190
- * @internal
191
- */
192
- this.next = void 0;
193
- /**
194
- * @internal
195
- */
196
- this.cleanup = void 0;
197
- this.scheduler = void 0;
198
- if (activeEffectScope && activeEffectScope.active) {
199
- activeEffectScope.effects.push(this);
200
- }
201
- }
202
- pause() {
203
- this.flags |= 64;
204
- }
205
- resume() {
206
- if (this.flags & 64) {
207
- this.flags &= -65;
208
- if (pausedQueueEffects.has(this)) {
209
- pausedQueueEffects.delete(this);
210
- this.trigger();
211
- }
212
- }
42
+ function link(dep, sub) {
43
+ const prevDep = sub.depsTail;
44
+ if (prevDep !== void 0 && prevDep.dep === dep) {
45
+ return;
213
46
  }
214
- /**
215
- * @internal
216
- */
217
- notify() {
218
- if (this.flags & 2 && !(this.flags & 32)) {
47
+ let nextDep = void 0;
48
+ const recursedCheck = sub.flags & 4 /* RecursedCheck */;
49
+ if (recursedCheck) {
50
+ nextDep = prevDep !== void 0 ? prevDep.nextDep : sub.deps;
51
+ if (nextDep !== void 0 && nextDep.dep === dep) {
52
+ sub.depsTail = nextDep;
219
53
  return;
220
54
  }
221
- if (!(this.flags & 8)) {
222
- batch(this);
223
- }
224
- }
225
- run() {
226
- if (!(this.flags & 1)) {
227
- return this.fn();
228
- }
229
- this.flags |= 2;
230
- cleanupEffect(this);
231
- prepareDeps(this);
232
- const prevEffect = activeSub;
233
- const prevShouldTrack = shouldTrack;
234
- activeSub = this;
235
- shouldTrack = true;
236
- try {
237
- return this.fn();
238
- } finally {
239
- if (!!(process.env.NODE_ENV !== "production") && activeSub !== this) {
240
- warn(
241
- "Active effect was not restored correctly - this is likely a Vue internal bug."
242
- );
243
- }
244
- cleanupDeps(this);
245
- activeSub = prevEffect;
246
- shouldTrack = prevShouldTrack;
247
- this.flags &= -3;
248
- }
249
55
  }
250
- stop() {
251
- if (this.flags & 1) {
252
- for (let link = this.deps; link; link = link.nextDep) {
253
- removeSub(link);
254
- }
255
- this.deps = this.depsTail = void 0;
256
- cleanupEffect(this);
257
- this.onStop && this.onStop();
258
- this.flags &= -2;
259
- }
56
+ const prevSub = dep.subsTail;
57
+ if (prevSub !== void 0 && prevSub.sub === sub && (!recursedCheck || isValidLink(prevSub, sub))) {
58
+ return;
260
59
  }
261
- trigger() {
262
- if (this.flags & 64) {
263
- pausedQueueEffects.add(this);
264
- } else if (this.scheduler) {
265
- this.scheduler();
266
- } else {
267
- this.runIfDirty();
268
- }
60
+ const newLink = sub.depsTail = dep.subsTail = {
61
+ dep,
62
+ sub,
63
+ prevDep,
64
+ nextDep,
65
+ prevSub,
66
+ nextSub: void 0
67
+ };
68
+ if (nextDep !== void 0) {
69
+ nextDep.prevDep = newLink;
269
70
  }
270
- /**
271
- * @internal
272
- */
273
- runIfDirty() {
274
- if (isDirty(this)) {
275
- this.run();
276
- }
71
+ if (prevDep !== void 0) {
72
+ prevDep.nextDep = newLink;
73
+ } else {
74
+ sub.deps = newLink;
277
75
  }
278
- get dirty() {
279
- return isDirty(this);
76
+ if (prevSub !== void 0) {
77
+ prevSub.nextSub = newLink;
78
+ } else {
79
+ dep.subs = newLink;
280
80
  }
281
81
  }
282
- let batchDepth = 0;
283
- let batchedSub;
284
- let batchedComputed;
285
- function batch(sub, isComputed = false) {
286
- sub.flags |= 8;
287
- if (isComputed) {
288
- sub.next = batchedComputed;
289
- batchedComputed = sub;
290
- return;
82
+ function unlink(link2, sub = link2.sub) {
83
+ const dep = link2.dep;
84
+ const prevDep = link2.prevDep;
85
+ const nextDep = link2.nextDep;
86
+ const nextSub = link2.nextSub;
87
+ const prevSub = link2.prevSub;
88
+ if (nextDep !== void 0) {
89
+ nextDep.prevDep = prevDep;
90
+ } else {
91
+ sub.depsTail = prevDep;
291
92
  }
292
- sub.next = batchedSub;
293
- batchedSub = sub;
294
- }
295
- function startBatch() {
296
- batchDepth++;
297
- }
298
- function endBatch() {
299
- if (--batchDepth > 0) {
300
- return;
93
+ if (prevDep !== void 0) {
94
+ prevDep.nextDep = nextDep;
95
+ } else {
96
+ sub.deps = nextDep;
301
97
  }
302
- if (batchedComputed) {
303
- let e = batchedComputed;
304
- batchedComputed = void 0;
305
- while (e) {
306
- const next = e.next;
307
- e.next = void 0;
308
- e.flags &= -9;
309
- e = next;
310
- }
311
- }
312
- let error;
313
- while (batchedSub) {
314
- let e = batchedSub;
315
- batchedSub = void 0;
316
- while (e) {
317
- const next = e.next;
318
- e.next = void 0;
319
- e.flags &= -9;
320
- if (e.flags & 1) {
321
- try {
322
- ;
323
- e.trigger();
324
- } catch (err) {
325
- if (!error) error = err;
98
+ if (nextSub !== void 0) {
99
+ nextSub.prevSub = prevSub;
100
+ } else {
101
+ dep.subsTail = prevSub;
102
+ }
103
+ if (prevSub !== void 0) {
104
+ prevSub.nextSub = nextSub;
105
+ } else if ((dep.subs = nextSub) === void 0) {
106
+ let toRemove = dep.deps;
107
+ if (toRemove !== void 0) {
108
+ do {
109
+ toRemove = unlink(toRemove, dep);
110
+ } while (toRemove !== void 0);
111
+ dep.flags |= 16 /* Dirty */;
112
+ }
113
+ }
114
+ return nextDep;
115
+ }
116
+ function propagate(link2) {
117
+ let next = link2.nextSub;
118
+ let stack;
119
+ top: do {
120
+ const sub = link2.sub;
121
+ let flags = sub.flags;
122
+ if (flags & (1 /* Mutable */ | 2 /* Watching */)) {
123
+ if (!(flags & (4 /* RecursedCheck */ | 8 /* Recursed */ | 16 /* Dirty */ | 32 /* Pending */))) {
124
+ sub.flags = flags | 32 /* Pending */;
125
+ } else if (!(flags & (4 /* RecursedCheck */ | 8 /* Recursed */))) {
126
+ flags = 0 /* None */;
127
+ } else if (!(flags & 4 /* RecursedCheck */)) {
128
+ sub.flags = flags & -9 /* Recursed */ | 32 /* Pending */;
129
+ } else if (!(flags & (16 /* Dirty */ | 32 /* Pending */)) && isValidLink(link2, sub)) {
130
+ sub.flags = flags | 8 /* Recursed */ | 32 /* Pending */;
131
+ flags &= 1 /* Mutable */;
132
+ } else {
133
+ flags = 0 /* None */;
134
+ }
135
+ if (flags & 2 /* Watching */) {
136
+ notifyBuffer[notifyBufferLength++] = sub;
137
+ }
138
+ if (flags & 1 /* Mutable */) {
139
+ const subSubs = sub.subs;
140
+ if (subSubs !== void 0) {
141
+ link2 = subSubs;
142
+ if (subSubs.nextSub !== void 0) {
143
+ stack = { value: next, prev: stack };
144
+ next = link2.nextSub;
145
+ }
146
+ continue;
326
147
  }
327
148
  }
328
- e = next;
329
149
  }
330
- }
331
- if (error) throw error;
332
- }
333
- function prepareDeps(sub) {
334
- for (let link = sub.deps; link; link = link.nextDep) {
335
- link.version = -1;
336
- link.prevActiveLink = link.dep.activeLink;
337
- link.dep.activeLink = link;
338
- }
339
- }
340
- function cleanupDeps(sub) {
341
- let head;
342
- let tail = sub.depsTail;
343
- let link = tail;
344
- while (link) {
345
- const prev = link.prevDep;
346
- if (link.version === -1) {
347
- if (link === tail) tail = prev;
348
- removeSub(link);
349
- removeDep(link);
350
- } else {
351
- head = link;
150
+ if ((link2 = next) !== void 0) {
151
+ next = link2.nextSub;
152
+ continue;
352
153
  }
353
- link.dep.activeLink = link.prevActiveLink;
354
- link.prevActiveLink = void 0;
355
- link = prev;
356
- }
357
- sub.deps = head;
358
- sub.depsTail = tail;
359
- }
360
- function isDirty(sub) {
361
- for (let link = sub.deps; link; link = link.nextDep) {
362
- if (link.dep.version !== link.version || link.dep.computed && (refreshComputed(link.dep.computed) || link.dep.version !== link.version)) {
363
- return true;
154
+ while (stack !== void 0) {
155
+ link2 = stack.value;
156
+ stack = stack.prev;
157
+ if (link2 !== void 0) {
158
+ next = link2.nextSub;
159
+ continue top;
160
+ }
364
161
  }
365
- }
366
- if (sub._dirty) {
367
- return true;
368
- }
369
- return false;
162
+ break;
163
+ } while (true);
370
164
  }
371
- function refreshComputed(computed) {
372
- if (computed.flags & 4 && !(computed.flags & 16)) {
373
- return;
374
- }
375
- computed.flags &= -17;
376
- if (computed.globalVersion === globalVersion) {
377
- return;
378
- }
379
- computed.globalVersion = globalVersion;
380
- if (!computed.isSSR && computed.flags & 128 && (!computed.deps && !computed._dirty || !isDirty(computed))) {
381
- return;
382
- }
383
- computed.flags |= 2;
384
- const dep = computed.dep;
385
- const prevSub = activeSub;
386
- const prevShouldTrack = shouldTrack;
387
- activeSub = computed;
388
- shouldTrack = true;
389
- try {
390
- prepareDeps(computed);
391
- const value = computed.fn(computed._value);
392
- if (dep.version === 0 || hasChanged(value, computed._value)) {
393
- computed.flags |= 128;
394
- computed._value = value;
395
- dep.version++;
396
- }
397
- } catch (err) {
398
- dep.version++;
399
- throw err;
400
- } finally {
401
- activeSub = prevSub;
402
- shouldTrack = prevShouldTrack;
403
- cleanupDeps(computed);
404
- computed.flags &= -3;
405
- }
165
+ function startTracking(sub) {
166
+ sub.depsTail = void 0;
167
+ sub.flags = sub.flags & -57 | 4 /* RecursedCheck */;
168
+ return setActiveSub(sub);
406
169
  }
407
- function removeSub(link, soft = false) {
408
- const { dep, prevSub, nextSub } = link;
409
- if (prevSub) {
410
- prevSub.nextSub = nextSub;
411
- link.prevSub = void 0;
412
- }
413
- if (nextSub) {
414
- nextSub.prevSub = prevSub;
415
- link.nextSub = void 0;
416
- }
417
- if (!!(process.env.NODE_ENV !== "production") && dep.subsHead === link) {
418
- dep.subsHead = nextSub;
170
+ function endTracking(sub, prevSub) {
171
+ if (!!(process.env.NODE_ENV !== "production") && activeSub !== sub) {
172
+ warn(
173
+ "Active effect was not restored correctly - this is likely a Vue internal bug."
174
+ );
419
175
  }
420
- if (dep.subs === link) {
421
- dep.subs = prevSub;
422
- if (!prevSub && dep.computed) {
423
- dep.computed.flags &= -5;
424
- for (let l = dep.computed.deps; l; l = l.nextDep) {
425
- removeSub(l, true);
176
+ activeSub = prevSub;
177
+ const depsTail = sub.depsTail;
178
+ let toRemove = depsTail !== void 0 ? depsTail.nextDep : sub.deps;
179
+ while (toRemove !== void 0) {
180
+ toRemove = unlink(toRemove, sub);
181
+ }
182
+ sub.flags &= -5 /* RecursedCheck */;
183
+ }
184
+ function flush() {
185
+ while (notifyIndex < notifyBufferLength) {
186
+ const effect = notifyBuffer[notifyIndex];
187
+ notifyBuffer[notifyIndex++] = void 0;
188
+ effect.notify();
189
+ }
190
+ notifyIndex = 0;
191
+ notifyBufferLength = 0;
192
+ }
193
+ function checkDirty(link2, sub) {
194
+ let stack;
195
+ let checkDepth = 0;
196
+ top: do {
197
+ const dep = link2.dep;
198
+ const depFlags = dep.flags;
199
+ let dirty = false;
200
+ if (sub.flags & 16 /* Dirty */) {
201
+ dirty = true;
202
+ } else if ((depFlags & (1 /* Mutable */ | 16 /* Dirty */)) === (1 /* Mutable */ | 16 /* Dirty */)) {
203
+ if (dep.update()) {
204
+ const subs = dep.subs;
205
+ if (subs.nextSub !== void 0) {
206
+ shallowPropagate(subs);
207
+ }
208
+ dirty = true;
426
209
  }
427
- }
428
- }
429
- if (!soft && !--dep.sc && dep.map) {
430
- dep.map.delete(dep.key);
210
+ } else if ((depFlags & (1 /* Mutable */ | 32 /* Pending */)) === (1 /* Mutable */ | 32 /* Pending */)) {
211
+ if (link2.nextSub !== void 0 || link2.prevSub !== void 0) {
212
+ stack = { value: link2, prev: stack };
213
+ }
214
+ link2 = dep.deps;
215
+ sub = dep;
216
+ ++checkDepth;
217
+ continue;
218
+ }
219
+ if (!dirty && link2.nextDep !== void 0) {
220
+ link2 = link2.nextDep;
221
+ continue;
222
+ }
223
+ while (checkDepth) {
224
+ --checkDepth;
225
+ const firstSub = sub.subs;
226
+ const hasMultipleSubs = firstSub.nextSub !== void 0;
227
+ if (hasMultipleSubs) {
228
+ link2 = stack.value;
229
+ stack = stack.prev;
230
+ } else {
231
+ link2 = firstSub;
232
+ }
233
+ if (dirty) {
234
+ if (sub.update()) {
235
+ if (hasMultipleSubs) {
236
+ shallowPropagate(firstSub);
237
+ }
238
+ sub = link2.sub;
239
+ continue;
240
+ }
241
+ } else {
242
+ sub.flags &= -33 /* Pending */;
243
+ }
244
+ sub = link2.sub;
245
+ if (link2.nextDep !== void 0) {
246
+ link2 = link2.nextDep;
247
+ continue top;
248
+ }
249
+ dirty = false;
250
+ }
251
+ return dirty;
252
+ } while (true);
253
+ }
254
+ function shallowPropagate(link2) {
255
+ do {
256
+ const sub = link2.sub;
257
+ const nextSub = link2.nextSub;
258
+ const subFlags = sub.flags;
259
+ if ((subFlags & (32 /* Pending */ | 16 /* Dirty */)) === 32 /* Pending */) {
260
+ sub.flags = subFlags | 16 /* Dirty */;
261
+ }
262
+ link2 = nextSub;
263
+ } while (link2 !== void 0);
264
+ }
265
+ function isValidLink(checkLink, sub) {
266
+ const depsTail = sub.depsTail;
267
+ if (depsTail !== void 0) {
268
+ let link2 = sub.deps;
269
+ do {
270
+ if (link2 === checkLink) {
271
+ return true;
272
+ }
273
+ if (link2 === depsTail) {
274
+ break;
275
+ }
276
+ link2 = link2.nextDep;
277
+ } while (link2 !== void 0);
431
278
  }
279
+ return false;
432
280
  }
433
- function removeDep(link) {
434
- const { prevDep, nextDep } = link;
435
- if (prevDep) {
436
- prevDep.nextDep = nextDep;
437
- link.prevDep = void 0;
281
+
282
+ const triggerEventInfos = [];
283
+ function onTrack(sub, debugInfo) {
284
+ if (!!!(process.env.NODE_ENV !== "production")) {
285
+ throw new Error(
286
+ `Internal error: onTrack should be called only in development.`
287
+ );
438
288
  }
439
- if (nextDep) {
440
- nextDep.prevDep = prevDep;
441
- link.nextDep = void 0;
289
+ if (sub.onTrack) {
290
+ sub.onTrack(
291
+ extend(
292
+ {
293
+ effect: sub
294
+ },
295
+ debugInfo
296
+ )
297
+ );
442
298
  }
443
299
  }
444
- function effect(fn, options) {
445
- if (fn.effect instanceof ReactiveEffect) {
446
- fn = fn.effect.fn;
447
- }
448
- const e = new ReactiveEffect(fn);
449
- if (options) {
450
- extend(e, options);
300
+ function onTrigger(sub) {
301
+ if (!!!(process.env.NODE_ENV !== "production")) {
302
+ throw new Error(
303
+ `Internal error: onTrigger should be called only in development.`
304
+ );
451
305
  }
452
- try {
453
- e.run();
454
- } catch (err) {
455
- e.stop();
456
- throw err;
306
+ if (sub.onTrigger) {
307
+ const debugInfo = triggerEventInfos[triggerEventInfos.length - 1];
308
+ sub.onTrigger(
309
+ extend(
310
+ {
311
+ effect: sub
312
+ },
313
+ debugInfo
314
+ )
315
+ );
457
316
  }
458
- const runner = e.run.bind(e);
459
- runner.effect = e;
460
- return runner;
461
317
  }
462
- function stop(runner) {
463
- runner.effect.stop();
464
- }
465
- let shouldTrack = true;
466
- const trackStack = [];
467
- function pauseTracking() {
468
- trackStack.push(shouldTrack);
469
- shouldTrack = false;
470
- }
471
- function enableTracking() {
472
- trackStack.push(shouldTrack);
473
- shouldTrack = true;
474
- }
475
- function resetTracking() {
476
- const last = trackStack.pop();
477
- shouldTrack = last === void 0 ? true : last;
478
- }
479
- function onEffectCleanup(fn, failSilently = false) {
480
- if (activeSub instanceof ReactiveEffect) {
481
- activeSub.cleanup = fn;
482
- } else if (!!(process.env.NODE_ENV !== "production") && !failSilently) {
483
- warn(
484
- `onEffectCleanup() was called when there was no active effect to associate with.`
318
+ function setupOnTrigger(target) {
319
+ if (!!!(process.env.NODE_ENV !== "production")) {
320
+ throw new Error(
321
+ `Internal error: setupOnTrigger should be called only in development.`
485
322
  );
486
323
  }
324
+ Object.defineProperty(target.prototype, "onTrigger", {
325
+ get() {
326
+ return this._onTrigger;
327
+ },
328
+ set(val) {
329
+ if (val && !this._onTrigger) setupFlagsHandler(this);
330
+ this._onTrigger = val;
331
+ }
332
+ });
487
333
  }
488
- function cleanupEffect(e) {
489
- const { cleanup } = e;
490
- e.cleanup = void 0;
491
- if (cleanup) {
492
- const prevSub = activeSub;
493
- activeSub = void 0;
494
- try {
495
- cleanup();
496
- } finally {
497
- activeSub = prevSub;
334
+ function setupFlagsHandler(target) {
335
+ target._flags = target.flags;
336
+ Object.defineProperty(target, "flags", {
337
+ get() {
338
+ return target._flags;
339
+ },
340
+ set(value) {
341
+ if (!(target._flags & (ReactiveFlags$1.Dirty | ReactiveFlags$1.Pending)) && !!(value & (ReactiveFlags$1.Dirty | ReactiveFlags$1.Pending))) {
342
+ onTrigger(this);
343
+ }
344
+ target._flags = value;
498
345
  }
499
- }
346
+ });
500
347
  }
501
348
 
502
- let globalVersion = 0;
503
- class Link {
504
- constructor(sub, dep) {
505
- this.sub = sub;
506
- this.dep = dep;
507
- this.version = dep.version;
508
- this.nextDep = this.prevDep = this.nextSub = this.prevSub = this.prevActiveLink = void 0;
509
- }
510
- }
511
349
  class Dep {
512
- constructor(computed) {
513
- this.computed = computed;
514
- this.version = 0;
515
- /**
516
- * Link between this dep and the current active effect
517
- */
518
- this.activeLink = void 0;
519
- /**
520
- * Doubly linked list representing the subscribing effects (tail)
521
- */
522
- this.subs = void 0;
523
- /**
524
- * For object property deps cleanup
525
- */
526
- this.map = void 0;
527
- this.key = void 0;
528
- /**
529
- * Subscriber counter
530
- */
531
- this.sc = 0;
532
- if (!!(process.env.NODE_ENV !== "production")) {
533
- this.subsHead = void 0;
534
- }
535
- }
536
- track(debugInfo) {
537
- if (!activeSub || !shouldTrack || activeSub === this.computed) {
538
- return;
539
- }
540
- let link = this.activeLink;
541
- if (link === void 0 || link.sub !== activeSub) {
542
- link = this.activeLink = new Link(activeSub, this);
543
- if (!activeSub.deps) {
544
- activeSub.deps = activeSub.depsTail = link;
545
- } else {
546
- link.prevDep = activeSub.depsTail;
547
- activeSub.depsTail.nextDep = link;
548
- activeSub.depsTail = link;
549
- }
550
- addSub(link);
551
- } else if (link.version === -1) {
552
- link.version = this.version;
553
- if (link.nextDep) {
554
- const next = link.nextDep;
555
- next.prevDep = link.prevDep;
556
- if (link.prevDep) {
557
- link.prevDep.nextDep = next;
558
- }
559
- link.prevDep = activeSub.depsTail;
560
- link.nextDep = void 0;
561
- activeSub.depsTail.nextDep = link;
562
- activeSub.depsTail = link;
563
- if (activeSub.deps === link) {
564
- activeSub.deps = next;
565
- }
566
- }
567
- }
568
- if (!!(process.env.NODE_ENV !== "production") && activeSub.onTrack) {
569
- activeSub.onTrack(
570
- extend(
571
- {
572
- effect: activeSub
573
- },
574
- debugInfo
575
- )
576
- );
577
- }
578
- return link;
579
- }
580
- trigger(debugInfo) {
581
- this.version++;
582
- globalVersion++;
583
- this.notify(debugInfo);
350
+ constructor(map, key) {
351
+ this.map = map;
352
+ this.key = key;
353
+ this._subs = void 0;
354
+ this.subsTail = void 0;
355
+ this.flags = ReactiveFlags$1.None;
584
356
  }
585
- notify(debugInfo) {
586
- startBatch();
587
- try {
588
- if (!!(process.env.NODE_ENV !== "production")) {
589
- for (let head = this.subsHead; head; head = head.nextSub) {
590
- if (head.sub.onTrigger && !(head.sub.flags & 8)) {
591
- head.sub.onTrigger(
592
- extend(
593
- {
594
- effect: head.sub
595
- },
596
- debugInfo
597
- )
598
- );
599
- }
600
- }
601
- }
602
- for (let link = this.subs; link; link = link.prevSub) {
603
- if (link.sub.notify()) {
604
- ;
605
- link.sub.dep.notify();
606
- }
607
- }
608
- } finally {
609
- endBatch();
610
- }
357
+ get subs() {
358
+ return this._subs;
611
359
  }
612
- }
613
- function addSub(link) {
614
- link.dep.sc++;
615
- if (link.sub.flags & 4) {
616
- const computed = link.dep.computed;
617
- if (computed && !link.dep.subs) {
618
- computed.flags |= 4 | 16;
619
- for (let l = computed.deps; l; l = l.nextDep) {
620
- addSub(l);
621
- }
622
- }
623
- const currentTail = link.dep.subs;
624
- if (currentTail !== link) {
625
- link.prevSub = currentTail;
626
- if (currentTail) currentTail.nextSub = link;
360
+ set subs(value) {
361
+ this._subs = value;
362
+ if (value === void 0) {
363
+ this.map.delete(this.key);
627
364
  }
628
- if (!!(process.env.NODE_ENV !== "production") && link.dep.subsHead === void 0) {
629
- link.dep.subsHead = link;
630
- }
631
- link.dep.subs = link;
632
365
  }
633
366
  }
634
367
  const targetMap = /* @__PURE__ */ new WeakMap();
@@ -642,38 +375,34 @@ const ARRAY_ITERATE_KEY = Symbol(
642
375
  !!(process.env.NODE_ENV !== "production") ? "Array iterate" : ""
643
376
  );
644
377
  function track(target, type, key) {
645
- if (shouldTrack && activeSub) {
378
+ if (activeSub !== void 0) {
646
379
  let depsMap = targetMap.get(target);
647
380
  if (!depsMap) {
648
381
  targetMap.set(target, depsMap = /* @__PURE__ */ new Map());
649
382
  }
650
383
  let dep = depsMap.get(key);
651
384
  if (!dep) {
652
- depsMap.set(key, dep = new Dep());
653
- dep.map = depsMap;
654
- dep.key = key;
385
+ depsMap.set(key, dep = new Dep(depsMap, key));
655
386
  }
656
387
  if (!!(process.env.NODE_ENV !== "production")) {
657
- dep.track({
388
+ onTrack(activeSub, {
658
389
  target,
659
390
  type,
660
391
  key
661
392
  });
662
- } else {
663
- dep.track();
664
393
  }
394
+ link(dep, activeSub);
665
395
  }
666
396
  }
667
397
  function trigger(target, type, key, newValue, oldValue, oldTarget) {
668
398
  const depsMap = targetMap.get(target);
669
399
  if (!depsMap) {
670
- globalVersion++;
671
400
  return;
672
401
  }
673
402
  const run = (dep) => {
674
- if (dep) {
403
+ if (dep !== void 0 && dep.subs !== void 0) {
675
404
  if (!!(process.env.NODE_ENV !== "production")) {
676
- dep.trigger({
405
+ triggerEventInfos.push({
677
406
  target,
678
407
  type,
679
408
  key,
@@ -681,8 +410,11 @@ function trigger(target, type, key, newValue, oldValue, oldTarget) {
681
410
  oldValue,
682
411
  oldTarget
683
412
  });
684
- } else {
685
- dep.trigger();
413
+ }
414
+ propagate(dep.subs);
415
+ shallowPropagate(dep.subs);
416
+ if (!!(process.env.NODE_ENV !== "production")) {
417
+ triggerEventInfos.pop();
686
418
  }
687
419
  }
688
420
  };
@@ -908,11 +640,11 @@ function searchProxy(self, method, args) {
908
640
  return res;
909
641
  }
910
642
  function noTracking(self, method, args = []) {
911
- pauseTracking();
912
643
  startBatch();
644
+ const prevSub = setActiveSub();
913
645
  const res = toRaw(self)[method].apply(self, args);
646
+ setActiveSub(prevSub);
914
647
  endBatch();
915
- resetTracking();
916
648
  return res;
917
649
  }
918
650
 
@@ -958,14 +690,18 @@ class BaseReactiveHandler {
958
690
  return hasOwnProperty;
959
691
  }
960
692
  }
693
+ const wasRef = isRef(target);
961
694
  const res = Reflect.get(
962
695
  target,
963
696
  key,
964
697
  // if this is a proxy wrapping a ref, return methods using the raw ref
965
698
  // as receiver so that we don't have to call `toRaw` on the ref in all
966
699
  // its class methods
967
- isRef(target) ? target : receiver
700
+ wasRef ? target : receiver
968
701
  );
702
+ if (wasRef && key !== "value") {
703
+ return res;
704
+ }
969
705
  if (isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) {
970
706
  return res;
971
707
  }
@@ -1417,35 +1153,47 @@ function isRef(r) {
1417
1153
  return r ? r["__v_isRef"] === true : false;
1418
1154
  }
1419
1155
  function ref(value) {
1420
- return createRef(value, false);
1156
+ return createRef(value, toReactive);
1421
1157
  }
1422
1158
  function shallowRef(value) {
1423
- return createRef(value, true);
1159
+ return createRef(value);
1424
1160
  }
1425
- function createRef(rawValue, shallow) {
1161
+ function createRef(rawValue, wrap) {
1426
1162
  if (isRef(rawValue)) {
1427
1163
  return rawValue;
1428
1164
  }
1429
- return new RefImpl(rawValue, shallow);
1165
+ return new RefImpl(rawValue, wrap);
1430
1166
  }
1431
1167
  class RefImpl {
1432
- constructor(value, isShallow2) {
1433
- this.dep = new Dep();
1434
- this["__v_isRef"] = true;
1435
- this["__v_isShallow"] = false;
1436
- this._rawValue = isShallow2 ? value : toRaw(value);
1437
- this._value = isShallow2 ? value : toReactive(value);
1438
- this["__v_isShallow"] = isShallow2;
1168
+ // TODO isolatedDeclarations "__v_isShallow"
1169
+ constructor(value, wrap) {
1170
+ this.subs = void 0;
1171
+ this.subsTail = void 0;
1172
+ this.flags = ReactiveFlags$1.Mutable;
1173
+ /**
1174
+ * @internal
1175
+ */
1176
+ this.__v_isRef = true;
1177
+ // TODO isolatedDeclarations "__v_isRef"
1178
+ /**
1179
+ * @internal
1180
+ */
1181
+ this.__v_isShallow = false;
1182
+ this._oldValue = this._rawValue = wrap ? toRaw(value) : value;
1183
+ this._value = wrap ? wrap(value) : value;
1184
+ this._wrap = wrap;
1185
+ this["__v_isShallow"] = !wrap;
1186
+ }
1187
+ get dep() {
1188
+ return this;
1439
1189
  }
1440
1190
  get value() {
1441
- if (!!(process.env.NODE_ENV !== "production")) {
1442
- this.dep.track({
1443
- target: this,
1444
- type: "get",
1445
- key: "value"
1446
- });
1447
- } else {
1448
- this.dep.track();
1191
+ trackRef(this);
1192
+ if (this.flags & ReactiveFlags$1.Dirty && this.update()) {
1193
+ const subs = this.subs;
1194
+ if (subs !== void 0) {
1195
+ shallowPropagate(subs);
1196
+ }
1449
1197
  }
1450
1198
  return this._value;
1451
1199
  }
@@ -1454,195 +1202,541 @@ class RefImpl {
1454
1202
  const useDirectValue = this["__v_isShallow"] || isShallow(newValue) || isReadonly(newValue);
1455
1203
  newValue = useDirectValue ? newValue : toRaw(newValue);
1456
1204
  if (hasChanged(newValue, oldValue)) {
1205
+ this.flags |= ReactiveFlags$1.Dirty;
1457
1206
  this._rawValue = newValue;
1458
- this._value = useDirectValue ? newValue : toReactive(newValue);
1459
- if (!!(process.env.NODE_ENV !== "production")) {
1460
- this.dep.trigger({
1461
- target: this,
1462
- type: "set",
1463
- key: "value",
1464
- newValue,
1465
- oldValue
1466
- });
1467
- } else {
1468
- this.dep.trigger();
1207
+ this._value = !useDirectValue && this._wrap ? this._wrap(newValue) : newValue;
1208
+ const subs = this.subs;
1209
+ if (subs !== void 0) {
1210
+ if (!!(process.env.NODE_ENV !== "production")) {
1211
+ triggerEventInfos.push({
1212
+ target: this,
1213
+ type: "set",
1214
+ key: "value",
1215
+ newValue,
1216
+ oldValue
1217
+ });
1218
+ }
1219
+ propagate(subs);
1220
+ if (!batchDepth) {
1221
+ flush();
1222
+ }
1223
+ if (!!(process.env.NODE_ENV !== "production")) {
1224
+ triggerEventInfos.pop();
1225
+ }
1469
1226
  }
1470
1227
  }
1471
1228
  }
1229
+ update() {
1230
+ this.flags &= ~ReactiveFlags$1.Dirty;
1231
+ return hasChanged(this._oldValue, this._oldValue = this._rawValue);
1232
+ }
1472
1233
  }
1473
1234
  function triggerRef(ref2) {
1474
- if (ref2.dep) {
1235
+ const dep = ref2.dep;
1236
+ if (dep !== void 0 && dep.subs !== void 0) {
1237
+ propagate(dep.subs);
1238
+ shallowPropagate(dep.subs);
1239
+ if (!batchDepth) {
1240
+ flush();
1241
+ }
1242
+ }
1243
+ }
1244
+ function trackRef(dep) {
1245
+ if (activeSub !== void 0) {
1475
1246
  if (!!(process.env.NODE_ENV !== "production")) {
1476
- ref2.dep.trigger({
1477
- target: ref2,
1478
- type: "set",
1479
- key: "value",
1480
- newValue: ref2._value
1247
+ onTrack(activeSub, {
1248
+ target: dep,
1249
+ type: "get",
1250
+ key: "value"
1481
1251
  });
1252
+ }
1253
+ link(dep, activeSub);
1254
+ }
1255
+ }
1256
+ function unref(ref2) {
1257
+ return isRef(ref2) ? ref2.value : ref2;
1258
+ }
1259
+ function toValue(source) {
1260
+ return isFunction(source) ? source() : unref(source);
1261
+ }
1262
+ const shallowUnwrapHandlers = {
1263
+ get: (target, key, receiver) => key === "__v_raw" ? target : unref(Reflect.get(target, key, receiver)),
1264
+ set: (target, key, value, receiver) => {
1265
+ const oldValue = target[key];
1266
+ if (isRef(oldValue) && !isRef(value)) {
1267
+ oldValue.value = value;
1268
+ return true;
1482
1269
  } else {
1483
- ref2.dep.trigger();
1270
+ return Reflect.set(target, key, value, receiver);
1271
+ }
1272
+ }
1273
+ };
1274
+ function proxyRefs(objectWithRefs) {
1275
+ return isReactive(objectWithRefs) ? objectWithRefs : new Proxy(objectWithRefs, shallowUnwrapHandlers);
1276
+ }
1277
+ class CustomRefImpl {
1278
+ constructor(factory) {
1279
+ this.subs = void 0;
1280
+ this.subsTail = void 0;
1281
+ this.flags = ReactiveFlags$1.None;
1282
+ this["__v_isRef"] = true;
1283
+ this._value = void 0;
1284
+ const { get, set } = factory(
1285
+ () => trackRef(this),
1286
+ () => triggerRef(this)
1287
+ );
1288
+ this._get = get;
1289
+ this._set = set;
1290
+ }
1291
+ get dep() {
1292
+ return this;
1293
+ }
1294
+ get value() {
1295
+ return this._value = this._get();
1296
+ }
1297
+ set value(newVal) {
1298
+ this._set(newVal);
1299
+ }
1300
+ }
1301
+ function customRef(factory) {
1302
+ return new CustomRefImpl(factory);
1303
+ }
1304
+ function toRefs(object) {
1305
+ const ret = isArray(object) ? new Array(object.length) : {};
1306
+ for (const key in object) {
1307
+ ret[key] = propertyToRef(object, key);
1308
+ }
1309
+ return ret;
1310
+ }
1311
+ class ObjectRefImpl {
1312
+ constructor(_object, _key, _defaultValue) {
1313
+ this._object = _object;
1314
+ this._key = _key;
1315
+ this._defaultValue = _defaultValue;
1316
+ this["__v_isRef"] = true;
1317
+ this._value = void 0;
1318
+ }
1319
+ get value() {
1320
+ const val = this._object[this._key];
1321
+ return this._value = val === void 0 ? this._defaultValue : val;
1322
+ }
1323
+ set value(newVal) {
1324
+ this._object[this._key] = newVal;
1325
+ }
1326
+ get dep() {
1327
+ return getDepFromReactive(toRaw(this._object), this._key);
1328
+ }
1329
+ }
1330
+ class GetterRefImpl {
1331
+ constructor(_getter) {
1332
+ this._getter = _getter;
1333
+ this["__v_isRef"] = true;
1334
+ this["__v_isReadonly"] = true;
1335
+ this._value = void 0;
1336
+ }
1337
+ get value() {
1338
+ return this._value = this._getter();
1339
+ }
1340
+ }
1341
+ function toRef(source, key, defaultValue) {
1342
+ if (isRef(source)) {
1343
+ return source;
1344
+ } else if (isFunction(source)) {
1345
+ return new GetterRefImpl(source);
1346
+ } else if (isObject(source) && arguments.length > 1) {
1347
+ return propertyToRef(source, key, defaultValue);
1348
+ } else {
1349
+ return ref(source);
1350
+ }
1351
+ }
1352
+ function propertyToRef(source, key, defaultValue) {
1353
+ const val = source[key];
1354
+ return isRef(val) ? val : new ObjectRefImpl(source, key, defaultValue);
1355
+ }
1356
+
1357
+ const EffectFlags = {
1358
+ "ALLOW_RECURSE": 128,
1359
+ "128": "ALLOW_RECURSE",
1360
+ "PAUSED": 256,
1361
+ "256": "PAUSED",
1362
+ "STOP": 1024,
1363
+ "1024": "STOP"
1364
+ };
1365
+ class ReactiveEffect {
1366
+ constructor(fn) {
1367
+ this.deps = void 0;
1368
+ this.depsTail = void 0;
1369
+ this.subs = void 0;
1370
+ this.subsTail = void 0;
1371
+ this.flags = ReactiveFlags$1.Watching | ReactiveFlags$1.Dirty;
1372
+ /**
1373
+ * @internal
1374
+ */
1375
+ this.cleanups = [];
1376
+ /**
1377
+ * @internal
1378
+ */
1379
+ this.cleanupsLength = 0;
1380
+ if (fn !== void 0) {
1381
+ this.fn = fn;
1382
+ }
1383
+ if (activeEffectScope) {
1384
+ link(this, activeEffectScope);
1385
+ }
1386
+ }
1387
+ // @ts-expect-error
1388
+ fn() {
1389
+ }
1390
+ get active() {
1391
+ return !(this.flags & 1024);
1392
+ }
1393
+ pause() {
1394
+ this.flags |= 256;
1395
+ }
1396
+ resume() {
1397
+ const flags = this.flags &= -257;
1398
+ if (flags & (ReactiveFlags$1.Dirty | ReactiveFlags$1.Pending)) {
1399
+ this.notify();
1400
+ }
1401
+ }
1402
+ notify() {
1403
+ if (!(this.flags & 256) && this.dirty) {
1404
+ this.run();
1405
+ }
1406
+ }
1407
+ run() {
1408
+ if (!this.active) {
1409
+ return this.fn();
1410
+ }
1411
+ cleanup(this);
1412
+ const prevSub = startTracking(this);
1413
+ try {
1414
+ return this.fn();
1415
+ } finally {
1416
+ endTracking(this, prevSub);
1417
+ const flags = this.flags;
1418
+ if ((flags & (ReactiveFlags$1.Recursed | 128)) === (ReactiveFlags$1.Recursed | 128)) {
1419
+ this.flags = flags & ~ReactiveFlags$1.Recursed;
1420
+ this.notify();
1421
+ }
1422
+ }
1423
+ }
1424
+ stop() {
1425
+ if (!this.active) {
1426
+ return;
1427
+ }
1428
+ this.flags = 1024;
1429
+ let dep = this.deps;
1430
+ while (dep !== void 0) {
1431
+ dep = unlink(dep, this);
1432
+ }
1433
+ const sub = this.subs;
1434
+ if (sub !== void 0) {
1435
+ unlink(sub);
1436
+ }
1437
+ cleanup(this);
1438
+ }
1439
+ get dirty() {
1440
+ const flags = this.flags;
1441
+ if (flags & ReactiveFlags$1.Dirty) {
1442
+ return true;
1443
+ }
1444
+ if (flags & ReactiveFlags$1.Pending) {
1445
+ if (checkDirty(this.deps, this)) {
1446
+ this.flags = flags | ReactiveFlags$1.Dirty;
1447
+ return true;
1448
+ } else {
1449
+ this.flags = flags & ~ReactiveFlags$1.Pending;
1450
+ }
1451
+ }
1452
+ return false;
1453
+ }
1454
+ }
1455
+ if (!!(process.env.NODE_ENV !== "production")) {
1456
+ setupOnTrigger(ReactiveEffect);
1457
+ }
1458
+ function effect(fn, options) {
1459
+ if (fn.effect instanceof ReactiveEffect) {
1460
+ fn = fn.effect.fn;
1461
+ }
1462
+ const e = new ReactiveEffect(fn);
1463
+ if (options) {
1464
+ const { onStop, scheduler } = options;
1465
+ if (onStop) {
1466
+ options.onStop = void 0;
1467
+ const stop2 = e.stop.bind(e);
1468
+ e.stop = () => {
1469
+ stop2();
1470
+ onStop();
1471
+ };
1484
1472
  }
1473
+ if (scheduler) {
1474
+ options.scheduler = void 0;
1475
+ e.notify = () => {
1476
+ if (!(e.flags & 256)) {
1477
+ scheduler();
1478
+ }
1479
+ };
1480
+ }
1481
+ extend(e, options);
1482
+ }
1483
+ try {
1484
+ e.run();
1485
+ } catch (err) {
1486
+ e.stop();
1487
+ throw err;
1485
1488
  }
1489
+ const runner = e.run.bind(e);
1490
+ runner.effect = e;
1491
+ return runner;
1486
1492
  }
1487
- function unref(ref2) {
1488
- return isRef(ref2) ? ref2.value : ref2;
1493
+ function stop(runner) {
1494
+ runner.effect.stop();
1489
1495
  }
1490
- function toValue(source) {
1491
- return isFunction(source) ? source() : unref(source);
1496
+ const resetTrackingStack = [];
1497
+ function pauseTracking() {
1498
+ resetTrackingStack.push(activeSub);
1499
+ setActiveSub();
1492
1500
  }
1493
- const shallowUnwrapHandlers = {
1494
- get: (target, key, receiver) => key === "__v_raw" ? target : unref(Reflect.get(target, key, receiver)),
1495
- set: (target, key, value, receiver) => {
1496
- const oldValue = target[key];
1497
- if (isRef(oldValue) && !isRef(value)) {
1498
- oldValue.value = value;
1499
- return true;
1500
- } else {
1501
- return Reflect.set(target, key, value, receiver);
1501
+ function enableTracking() {
1502
+ const isPaused = activeSub === void 0;
1503
+ if (!isPaused) {
1504
+ resetTrackingStack.push(activeSub);
1505
+ } else {
1506
+ resetTrackingStack.push(void 0);
1507
+ for (let i = resetTrackingStack.length - 1; i >= 0; i--) {
1508
+ if (resetTrackingStack[i] !== void 0) {
1509
+ setActiveSub(resetTrackingStack[i]);
1510
+ break;
1511
+ }
1502
1512
  }
1503
1513
  }
1504
- };
1505
- function proxyRefs(objectWithRefs) {
1506
- return isReactive(objectWithRefs) ? objectWithRefs : new Proxy(objectWithRefs, shallowUnwrapHandlers);
1507
1514
  }
1508
- class CustomRefImpl {
1509
- constructor(factory) {
1510
- this["__v_isRef"] = true;
1511
- this._value = void 0;
1512
- const dep = this.dep = new Dep();
1513
- const { get, set } = factory(dep.track.bind(dep), dep.trigger.bind(dep));
1514
- this._get = get;
1515
- this._set = set;
1516
- }
1517
- get value() {
1518
- return this._value = this._get();
1515
+ function resetTracking() {
1516
+ if (!!(process.env.NODE_ENV !== "production") && resetTrackingStack.length === 0) {
1517
+ warn(
1518
+ `resetTracking() was called when there was no active tracking to reset.`
1519
+ );
1519
1520
  }
1520
- set value(newVal) {
1521
- this._set(newVal);
1521
+ if (resetTrackingStack.length) {
1522
+ setActiveSub(resetTrackingStack.pop());
1523
+ } else {
1524
+ setActiveSub();
1522
1525
  }
1523
1526
  }
1524
- function customRef(factory) {
1525
- return new CustomRefImpl(factory);
1527
+ function cleanup(sub) {
1528
+ const l = sub.cleanupsLength;
1529
+ if (l) {
1530
+ for (let i = 0; i < l; i++) {
1531
+ sub.cleanups[i]();
1532
+ }
1533
+ sub.cleanupsLength = 0;
1534
+ }
1526
1535
  }
1527
- function toRefs(object) {
1528
- if (!!(process.env.NODE_ENV !== "production") && !isProxy(object)) {
1529
- warn(`toRefs() expects a reactive object but received a plain one.`);
1536
+ function onEffectCleanup(fn, failSilently = false) {
1537
+ if (activeSub instanceof ReactiveEffect) {
1538
+ activeSub.cleanups[activeSub.cleanupsLength++] = () => cleanupEffect(fn);
1539
+ } else if (!!(process.env.NODE_ENV !== "production") && !failSilently) {
1540
+ warn(
1541
+ `onEffectCleanup() was called when there was no active effect to associate with.`
1542
+ );
1530
1543
  }
1531
- const ret = isArray(object) ? new Array(object.length) : {};
1532
- for (const key in object) {
1533
- ret[key] = propertyToRef(object, key);
1544
+ }
1545
+ function cleanupEffect(fn) {
1546
+ const prevSub = setActiveSub();
1547
+ try {
1548
+ fn();
1549
+ } finally {
1550
+ setActiveSub(prevSub);
1534
1551
  }
1535
- return ret;
1536
1552
  }
1537
- class ObjectRefImpl {
1538
- constructor(_object, _key, _defaultValue) {
1539
- this._object = _object;
1540
- this._key = _key;
1541
- this._defaultValue = _defaultValue;
1542
- this["__v_isRef"] = true;
1543
- this._value = void 0;
1553
+
1554
+ let activeEffectScope;
1555
+ class EffectScope {
1556
+ constructor(detached = false) {
1557
+ this.deps = void 0;
1558
+ this.depsTail = void 0;
1559
+ this.subs = void 0;
1560
+ this.subsTail = void 0;
1561
+ this.flags = 0;
1562
+ /**
1563
+ * @internal
1564
+ */
1565
+ this.cleanups = [];
1566
+ /**
1567
+ * @internal
1568
+ */
1569
+ this.cleanupsLength = 0;
1570
+ if (!detached && activeEffectScope) {
1571
+ link(this, activeEffectScope);
1572
+ }
1544
1573
  }
1545
- get value() {
1546
- const val = this._object[this._key];
1547
- return this._value = val === void 0 ? this._defaultValue : val;
1574
+ get active() {
1575
+ return !(this.flags & 1024);
1548
1576
  }
1549
- set value(newVal) {
1550
- this._object[this._key] = newVal;
1577
+ pause() {
1578
+ if (!(this.flags & 256)) {
1579
+ this.flags |= 256;
1580
+ for (let link2 = this.deps; link2 !== void 0; link2 = link2.nextDep) {
1581
+ const dep = link2.dep;
1582
+ if ("pause" in dep) {
1583
+ dep.pause();
1584
+ }
1585
+ }
1586
+ }
1551
1587
  }
1552
- get dep() {
1553
- return getDepFromReactive(toRaw(this._object), this._key);
1588
+ /**
1589
+ * Resumes the effect scope, including all child scopes and effects.
1590
+ */
1591
+ resume() {
1592
+ const flags = this.flags;
1593
+ if (flags & 256) {
1594
+ this.flags = flags & -257;
1595
+ for (let link2 = this.deps; link2 !== void 0; link2 = link2.nextDep) {
1596
+ const dep = link2.dep;
1597
+ if ("resume" in dep) {
1598
+ dep.resume();
1599
+ }
1600
+ }
1601
+ }
1554
1602
  }
1555
- }
1556
- class GetterRefImpl {
1557
- constructor(_getter) {
1558
- this._getter = _getter;
1559
- this["__v_isRef"] = true;
1560
- this["__v_isReadonly"] = true;
1561
- this._value = void 0;
1603
+ run(fn) {
1604
+ const prevSub = setActiveSub();
1605
+ const prevScope = activeEffectScope;
1606
+ try {
1607
+ activeEffectScope = this;
1608
+ return fn();
1609
+ } finally {
1610
+ activeEffectScope = prevScope;
1611
+ setActiveSub(prevSub);
1612
+ }
1562
1613
  }
1563
- get value() {
1564
- return this._value = this._getter();
1614
+ stop() {
1615
+ if (!this.active) {
1616
+ return;
1617
+ }
1618
+ this.flags = 1024;
1619
+ let dep = this.deps;
1620
+ while (dep !== void 0) {
1621
+ const node = dep.dep;
1622
+ if ("stop" in node) {
1623
+ dep = dep.nextDep;
1624
+ node.stop();
1625
+ } else {
1626
+ dep = unlink(dep, this);
1627
+ }
1628
+ }
1629
+ const sub = this.subs;
1630
+ if (sub !== void 0) {
1631
+ unlink(sub);
1632
+ }
1633
+ cleanup(this);
1565
1634
  }
1566
1635
  }
1567
- function toRef(source, key, defaultValue) {
1568
- if (isRef(source)) {
1569
- return source;
1570
- } else if (isFunction(source)) {
1571
- return new GetterRefImpl(source);
1572
- } else if (isObject(source) && arguments.length > 1) {
1573
- return propertyToRef(source, key, defaultValue);
1574
- } else {
1575
- return ref(source);
1636
+ function effectScope(detached) {
1637
+ return new EffectScope(detached);
1638
+ }
1639
+ function getCurrentScope() {
1640
+ return activeEffectScope;
1641
+ }
1642
+ function setCurrentScope(scope) {
1643
+ try {
1644
+ return activeEffectScope;
1645
+ } finally {
1646
+ activeEffectScope = scope;
1576
1647
  }
1577
1648
  }
1578
- function propertyToRef(source, key, defaultValue) {
1579
- const val = source[key];
1580
- return isRef(val) ? val : new ObjectRefImpl(source, key, defaultValue);
1649
+ function onScopeDispose(fn, failSilently = false) {
1650
+ if (activeEffectScope !== void 0) {
1651
+ activeEffectScope.cleanups[activeEffectScope.cleanupsLength++] = fn;
1652
+ } else if (!!(process.env.NODE_ENV !== "production") && !failSilently) {
1653
+ warn(
1654
+ `onScopeDispose() is called when there is no active effect scope to be associated with.`
1655
+ );
1656
+ }
1581
1657
  }
1582
1658
 
1583
1659
  class ComputedRefImpl {
1584
- constructor(fn, setter, isSSR) {
1660
+ constructor(fn, setter) {
1585
1661
  this.fn = fn;
1586
1662
  this.setter = setter;
1587
1663
  /**
1588
1664
  * @internal
1589
1665
  */
1590
1666
  this._value = void 0;
1591
- /**
1592
- * @internal
1593
- */
1594
- this.dep = new Dep(this);
1595
- /**
1596
- * @internal
1597
- */
1598
- this.__v_isRef = true;
1599
- // TODO isolatedDeclarations "__v_isReadonly"
1600
- // A computed is also a subscriber that tracks other deps
1601
- /**
1602
- * @internal
1603
- */
1667
+ this.subs = void 0;
1668
+ this.subsTail = void 0;
1604
1669
  this.deps = void 0;
1605
- /**
1606
- * @internal
1607
- */
1608
1670
  this.depsTail = void 0;
1671
+ this.flags = ReactiveFlags$1.Mutable | ReactiveFlags$1.Dirty;
1609
1672
  /**
1610
1673
  * @internal
1611
1674
  */
1612
- this.flags = 16;
1613
- /**
1614
- * @internal
1615
- */
1616
- this.globalVersion = globalVersion - 1;
1617
- /**
1618
- * @internal
1619
- */
1620
- this.next = void 0;
1621
- // for backwards compat
1622
- this.effect = this;
1675
+ this.__v_isRef = true;
1623
1676
  this["__v_isReadonly"] = !setter;
1624
- this.isSSR = isSSR;
1677
+ }
1678
+ // TODO isolatedDeclarations "__v_isReadonly"
1679
+ // for backwards compat
1680
+ get effect() {
1681
+ return this;
1682
+ }
1683
+ // for backwards compat
1684
+ get dep() {
1685
+ return this;
1625
1686
  }
1626
1687
  /**
1627
1688
  * @internal
1689
+ * for backwards compat
1628
1690
  */
1629
- notify() {
1630
- this.flags |= 16;
1631
- if (!(this.flags & 8) && // avoid infinite self recursion
1632
- activeSub !== this) {
1633
- batch(this, true);
1691
+ get _dirty() {
1692
+ const flags = this.flags;
1693
+ if (flags & ReactiveFlags$1.Dirty) {
1634
1694
  return true;
1635
- } else if (!!(process.env.NODE_ENV !== "production")) ;
1695
+ }
1696
+ if (flags & ReactiveFlags$1.Pending) {
1697
+ if (checkDirty(this.deps, this)) {
1698
+ this.flags = flags | ReactiveFlags$1.Dirty;
1699
+ return true;
1700
+ } else {
1701
+ this.flags = flags & ~ReactiveFlags$1.Pending;
1702
+ }
1703
+ }
1704
+ return false;
1705
+ }
1706
+ /**
1707
+ * @internal
1708
+ * for backwards compat
1709
+ */
1710
+ set _dirty(v) {
1711
+ if (v) {
1712
+ this.flags |= ReactiveFlags$1.Dirty;
1713
+ } else {
1714
+ this.flags &= ~(ReactiveFlags$1.Dirty | ReactiveFlags$1.Pending);
1715
+ }
1636
1716
  }
1637
1717
  get value() {
1638
- const link = !!(process.env.NODE_ENV !== "production") ? this.dep.track({
1639
- target: this,
1640
- type: "get",
1641
- key: "value"
1642
- }) : this.dep.track();
1643
- refreshComputed(this);
1644
- if (link) {
1645
- link.version = this.dep.version;
1718
+ const flags = this.flags;
1719
+ if (flags & ReactiveFlags$1.Dirty || flags & ReactiveFlags$1.Pending && checkDirty(this.deps, this)) {
1720
+ if (this.update()) {
1721
+ const subs = this.subs;
1722
+ if (subs !== void 0) {
1723
+ shallowPropagate(subs);
1724
+ }
1725
+ }
1726
+ } else if (flags & ReactiveFlags$1.Pending) {
1727
+ this.flags = flags & ~ReactiveFlags$1.Pending;
1728
+ }
1729
+ if (activeSub !== void 0) {
1730
+ if (!!(process.env.NODE_ENV !== "production")) {
1731
+ onTrack(activeSub, {
1732
+ target: this,
1733
+ type: "get",
1734
+ key: "value"
1735
+ });
1736
+ }
1737
+ link(this, activeSub);
1738
+ } else if (activeEffectScope !== void 0) {
1739
+ link(this, activeEffectScope);
1646
1740
  }
1647
1741
  return this._value;
1648
1742
  }
@@ -1653,6 +1747,23 @@ class ComputedRefImpl {
1653
1747
  warn("Write operation failed: computed value is readonly");
1654
1748
  }
1655
1749
  }
1750
+ update() {
1751
+ const prevSub = startTracking(this);
1752
+ try {
1753
+ const oldValue = this._value;
1754
+ const newValue = this.fn(oldValue);
1755
+ if (hasChanged(oldValue, newValue)) {
1756
+ this._value = newValue;
1757
+ return true;
1758
+ }
1759
+ return false;
1760
+ } finally {
1761
+ endTracking(this, prevSub);
1762
+ }
1763
+ }
1764
+ }
1765
+ if (!!(process.env.NODE_ENV !== "production")) {
1766
+ setupOnTrigger(ComputedRefImpl);
1656
1767
  }
1657
1768
  function computed(getterOrOptions, debugOptions, isSSR = false) {
1658
1769
  let getter;
@@ -1663,7 +1774,7 @@ function computed(getterOrOptions, debugOptions, isSSR = false) {
1663
1774
  getter = getterOrOptions.get;
1664
1775
  setter = getterOrOptions.set;
1665
1776
  }
1666
- const cRef = new ComputedRefImpl(getter, setter, isSSR);
1777
+ const cRef = new ComputedRefImpl(getter, setter);
1667
1778
  if (!!(process.env.NODE_ENV !== "production") && debugOptions && !isSSR) {
1668
1779
  cRef.onTrack = debugOptions.onTrack;
1669
1780
  cRef.onTrigger = debugOptions.onTrigger;
@@ -1700,177 +1811,155 @@ const WatchErrorCodes = {
1700
1811
  "4": "WATCH_CLEANUP"
1701
1812
  };
1702
1813
  const INITIAL_WATCHER_VALUE = {};
1703
- const cleanupMap = /* @__PURE__ */ new WeakMap();
1704
1814
  let activeWatcher = void 0;
1705
1815
  function getCurrentWatcher() {
1706
1816
  return activeWatcher;
1707
1817
  }
1708
1818
  function onWatcherCleanup(cleanupFn, failSilently = false, owner = activeWatcher) {
1709
1819
  if (owner) {
1710
- let cleanups = cleanupMap.get(owner);
1711
- if (!cleanups) cleanupMap.set(owner, cleanups = []);
1712
- cleanups.push(cleanupFn);
1820
+ const { call } = owner.options;
1821
+ if (call) {
1822
+ owner.cleanups[owner.cleanupsLength++] = () => call(cleanupFn, 4);
1823
+ } else {
1824
+ owner.cleanups[owner.cleanupsLength++] = cleanupFn;
1825
+ }
1713
1826
  } else if (!!(process.env.NODE_ENV !== "production") && !failSilently) {
1714
1827
  warn(
1715
1828
  `onWatcherCleanup() was called when there was no active watcher to associate with.`
1716
1829
  );
1717
1830
  }
1718
1831
  }
1719
- function watch(source, cb, options = EMPTY_OBJ) {
1720
- const { immediate, deep, once, scheduler, augmentJob, call } = options;
1721
- const warnInvalidSource = (s) => {
1722
- (options.onWarn || warn)(
1723
- `Invalid watch source: `,
1724
- s,
1725
- `A watch source can only be a getter/effect function, a ref, a reactive object, or an array of these types.`
1726
- );
1727
- };
1728
- const reactiveGetter = (source2) => {
1729
- if (deep) return source2;
1730
- if (isShallow(source2) || deep === false || deep === 0)
1731
- return traverse(source2, 1);
1732
- return traverse(source2);
1733
- };
1734
- let effect;
1735
- let getter;
1736
- let cleanup;
1737
- let boundCleanup;
1738
- let forceTrigger = false;
1739
- let isMultiSource = false;
1740
- if (isRef(source)) {
1741
- getter = () => source.value;
1742
- forceTrigger = isShallow(source);
1743
- } else if (isReactive(source)) {
1744
- getter = () => reactiveGetter(source);
1745
- forceTrigger = true;
1746
- } else if (isArray(source)) {
1747
- isMultiSource = true;
1748
- forceTrigger = source.some((s) => isReactive(s) || isShallow(s));
1749
- getter = () => source.map((s) => {
1750
- if (isRef(s)) {
1751
- return s.value;
1752
- } else if (isReactive(s)) {
1753
- return reactiveGetter(s);
1754
- } else if (isFunction(s)) {
1755
- return call ? call(s, 2) : s();
1832
+ class WatcherEffect extends ReactiveEffect {
1833
+ constructor(source, cb, options = EMPTY_OBJ) {
1834
+ const { deep, once, call, onWarn } = options;
1835
+ let getter;
1836
+ let forceTrigger = false;
1837
+ let isMultiSource = false;
1838
+ if (isRef(source)) {
1839
+ getter = () => source.value;
1840
+ forceTrigger = isShallow(source);
1841
+ } else if (isReactive(source)) {
1842
+ getter = () => reactiveGetter(source, deep);
1843
+ forceTrigger = true;
1844
+ } else if (isArray(source)) {
1845
+ isMultiSource = true;
1846
+ forceTrigger = source.some((s) => isReactive(s) || isShallow(s));
1847
+ getter = () => source.map((s) => {
1848
+ if (isRef(s)) {
1849
+ return s.value;
1850
+ } else if (isReactive(s)) {
1851
+ return reactiveGetter(s, deep);
1852
+ } else if (isFunction(s)) {
1853
+ return call ? call(s, 2) : s();
1854
+ } else {
1855
+ !!(process.env.NODE_ENV !== "production") && warnInvalidSource(s, onWarn);
1856
+ }
1857
+ });
1858
+ } else if (isFunction(source)) {
1859
+ if (cb) {
1860
+ getter = call ? () => call(source, 2) : source;
1756
1861
  } else {
1757
- !!(process.env.NODE_ENV !== "production") && warnInvalidSource(s);
1758
- }
1759
- });
1760
- } else if (isFunction(source)) {
1761
- if (cb) {
1762
- getter = call ? () => call(source, 2) : source;
1763
- } else {
1764
- getter = () => {
1765
- if (cleanup) {
1766
- pauseTracking();
1862
+ getter = () => {
1863
+ if (this.cleanupsLength) {
1864
+ const prevSub = setActiveSub();
1865
+ try {
1866
+ cleanup(this);
1867
+ } finally {
1868
+ setActiveSub(prevSub);
1869
+ }
1870
+ }
1871
+ const currentEffect = activeWatcher;
1872
+ activeWatcher = this;
1767
1873
  try {
1768
- cleanup();
1874
+ return call ? call(source, 3, [
1875
+ this.boundCleanup
1876
+ ]) : source(this.boundCleanup);
1769
1877
  } finally {
1770
- resetTracking();
1878
+ activeWatcher = currentEffect;
1771
1879
  }
1772
- }
1773
- const currentEffect = activeWatcher;
1774
- activeWatcher = effect;
1775
- try {
1776
- return call ? call(source, 3, [boundCleanup]) : source(boundCleanup);
1777
- } finally {
1778
- activeWatcher = currentEffect;
1779
- }
1880
+ };
1881
+ }
1882
+ } else {
1883
+ getter = NOOP;
1884
+ !!(process.env.NODE_ENV !== "production") && warnInvalidSource(source, onWarn);
1885
+ }
1886
+ if (cb && deep) {
1887
+ const baseGetter = getter;
1888
+ const depth = deep === true ? Infinity : deep;
1889
+ getter = () => traverse(baseGetter(), depth);
1890
+ }
1891
+ super(getter);
1892
+ this.cb = cb;
1893
+ this.options = options;
1894
+ this.boundCleanup = (fn) => onWatcherCleanup(fn, false, this);
1895
+ this.forceTrigger = forceTrigger;
1896
+ this.isMultiSource = isMultiSource;
1897
+ if (once && cb) {
1898
+ const _cb = cb;
1899
+ cb = (...args) => {
1900
+ _cb(...args);
1901
+ this.stop();
1780
1902
  };
1781
1903
  }
1782
- } else {
1783
- getter = NOOP;
1784
- !!(process.env.NODE_ENV !== "production") && warnInvalidSource(source);
1785
- }
1786
- if (cb && deep) {
1787
- const baseGetter = getter;
1788
- const depth = deep === true ? Infinity : deep;
1789
- getter = () => traverse(baseGetter(), depth);
1790
- }
1791
- const scope = getCurrentScope();
1792
- const watchHandle = () => {
1793
- effect.stop();
1794
- if (scope && scope.active) {
1795
- remove(scope.effects, effect);
1904
+ this.cb = cb;
1905
+ this.oldValue = isMultiSource ? new Array(source.length).fill(INITIAL_WATCHER_VALUE) : INITIAL_WATCHER_VALUE;
1906
+ if (!!(process.env.NODE_ENV !== "production")) {
1907
+ this.onTrack = options.onTrack;
1908
+ this.onTrigger = options.onTrigger;
1796
1909
  }
1797
- };
1798
- if (once && cb) {
1799
- const _cb = cb;
1800
- cb = (...args) => {
1801
- _cb(...args);
1802
- watchHandle();
1803
- };
1804
1910
  }
1805
- let oldValue = isMultiSource ? new Array(source.length).fill(INITIAL_WATCHER_VALUE) : INITIAL_WATCHER_VALUE;
1806
- const job = (immediateFirstRun) => {
1807
- if (!(effect.flags & 1) || !effect.dirty && !immediateFirstRun) {
1911
+ run(initialRun = false) {
1912
+ const oldValue = this.oldValue;
1913
+ const newValue = this.oldValue = super.run();
1914
+ if (!this.cb) {
1808
1915
  return;
1809
1916
  }
1810
- if (cb) {
1811
- const newValue = effect.run();
1812
- if (deep || forceTrigger || (isMultiSource ? newValue.some((v, i) => hasChanged(v, oldValue[i])) : hasChanged(newValue, oldValue))) {
1813
- if (cleanup) {
1814
- cleanup();
1815
- }
1816
- const currentWatcher = activeWatcher;
1817
- activeWatcher = effect;
1818
- try {
1819
- const args = [
1820
- newValue,
1821
- // pass undefined as the old value when it's changed for the first time
1822
- oldValue === INITIAL_WATCHER_VALUE ? void 0 : isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE ? [] : oldValue,
1823
- boundCleanup
1824
- ];
1825
- oldValue = newValue;
1826
- call ? call(cb, 3, args) : (
1827
- // @ts-expect-error
1828
- cb(...args)
1829
- );
1830
- } finally {
1831
- activeWatcher = currentWatcher;
1832
- }
1833
- }
1834
- } else {
1835
- effect.run();
1917
+ const { immediate, deep, call } = this.options;
1918
+ if (initialRun && !immediate) {
1919
+ return;
1836
1920
  }
1837
- };
1838
- if (augmentJob) {
1839
- augmentJob(job);
1840
- }
1841
- effect = new ReactiveEffect(getter);
1842
- effect.scheduler = scheduler ? () => scheduler(job, false) : job;
1843
- boundCleanup = (fn) => onWatcherCleanup(fn, false, effect);
1844
- cleanup = effect.onStop = () => {
1845
- const cleanups = cleanupMap.get(effect);
1846
- if (cleanups) {
1847
- if (call) {
1848
- call(cleanups, 4);
1849
- } else {
1850
- for (const cleanup2 of cleanups) cleanup2();
1921
+ if (deep || this.forceTrigger || (this.isMultiSource ? newValue.some((v, i) => hasChanged(v, oldValue[i])) : hasChanged(newValue, oldValue))) {
1922
+ cleanup(this);
1923
+ const currentWatcher = activeWatcher;
1924
+ activeWatcher = this;
1925
+ try {
1926
+ const args = [
1927
+ newValue,
1928
+ // pass undefined as the old value when it's changed for the first time
1929
+ oldValue === INITIAL_WATCHER_VALUE ? void 0 : this.isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE ? [] : oldValue,
1930
+ this.boundCleanup
1931
+ ];
1932
+ call ? call(this.cb, 3, args) : (
1933
+ // @ts-expect-error
1934
+ this.cb(...args)
1935
+ );
1936
+ } finally {
1937
+ activeWatcher = currentWatcher;
1851
1938
  }
1852
- cleanupMap.delete(effect);
1853
- }
1854
- };
1855
- if (!!(process.env.NODE_ENV !== "production")) {
1856
- effect.onTrack = options.onTrack;
1857
- effect.onTrigger = options.onTrigger;
1858
- }
1859
- if (cb) {
1860
- if (immediate) {
1861
- job(true);
1862
- } else {
1863
- oldValue = effect.run();
1864
1939
  }
1865
- } else if (scheduler) {
1866
- scheduler(job.bind(null, true), true);
1867
- } else {
1868
- effect.run();
1869
1940
  }
1870
- watchHandle.pause = effect.pause.bind(effect);
1871
- watchHandle.resume = effect.resume.bind(effect);
1872
- watchHandle.stop = watchHandle;
1873
- return watchHandle;
1941
+ }
1942
+ function reactiveGetter(source, deep) {
1943
+ if (deep) return source;
1944
+ if (isShallow(source) || deep === false || deep === 0)
1945
+ return traverse(source, 1);
1946
+ return traverse(source);
1947
+ }
1948
+ function warnInvalidSource(s, onWarn) {
1949
+ (onWarn || warn)(
1950
+ `Invalid watch source: `,
1951
+ s,
1952
+ `A watch source can only be a getter/effect function, a ref, a reactive object, or an array of these types.`
1953
+ );
1954
+ }
1955
+ function watch(source, cb, options = EMPTY_OBJ) {
1956
+ const effect = new WatcherEffect(source, cb, options);
1957
+ effect.run(true);
1958
+ const stop = effect.stop.bind(effect);
1959
+ stop.pause = effect.pause.bind(effect);
1960
+ stop.resume = effect.resume.bind(effect);
1961
+ stop.stop = stop;
1962
+ return stop;
1874
1963
  }
1875
1964
  function traverse(value, depth = Infinity, seen) {
1876
1965
  if (depth <= 0 || !isObject(value) || value["__v_skip"]) {
@@ -1905,4 +1994,4 @@ function traverse(value, depth = Infinity, seen) {
1905
1994
  return value;
1906
1995
  }
1907
1996
 
1908
- export { ARRAY_ITERATE_KEY, EffectFlags, EffectScope, ITERATE_KEY, MAP_KEY_ITERATE_KEY, ReactiveEffect, ReactiveFlags, TrackOpTypes, TriggerOpTypes, WatchErrorCodes, computed, customRef, effect, effectScope, enableTracking, getCurrentScope, getCurrentWatcher, isProxy, isReactive, isReadonly, isRef, isShallow, markRaw, onEffectCleanup, onScopeDispose, onWatcherCleanup, pauseTracking, proxyRefs, reactive, reactiveReadArray, readonly, ref, resetTracking, shallowReactive, shallowReadArray, shallowReadonly, shallowRef, stop, toRaw, toReactive, toReadonly, toRef, toRefs, toValue, track, traverse, trigger, triggerRef, unref, watch };
1997
+ export { ARRAY_ITERATE_KEY, EffectFlags, EffectScope, ITERATE_KEY, MAP_KEY_ITERATE_KEY, ReactiveEffect, ReactiveFlags, TrackOpTypes, TriggerOpTypes, WatchErrorCodes, WatcherEffect, computed, customRef, effect, effectScope, enableTracking, getCurrentScope, getCurrentWatcher, isProxy, isReactive, isReadonly, isRef, isShallow, markRaw, onEffectCleanup, onScopeDispose, onWatcherCleanup, pauseTracking, proxyRefs, reactive, reactiveReadArray, readonly, ref, resetTracking, setActiveSub, setCurrentScope, shallowReactive, shallowReadArray, shallowReadonly, shallowRef, stop, toRaw, toReactive, toReadonly, toRef, toRefs, toValue, track, traverse, trigger, triggerRef, unref, watch };