@vue/reactivity 3.5.17 → 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,641 +1,369 @@
1
1
  /**
2
- * @vue/reactivity v3.5.17
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
55
  }
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
- }
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
- }
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
317
  }
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
- // TODO isolatedDeclarations "__v_skip"
513
- constructor(computed) {
514
- this.computed = computed;
515
- this.version = 0;
516
- /**
517
- * Link between this dep and the current active effect
518
- */
519
- this.activeLink = void 0;
520
- /**
521
- * Doubly linked list representing the subscribing effects (tail)
522
- */
523
- this.subs = void 0;
524
- /**
525
- * For object property deps cleanup
526
- */
527
- this.map = void 0;
528
- this.key = void 0;
529
- /**
530
- * Subscriber counter
531
- */
532
- this.sc = 0;
533
- /**
534
- * @internal
535
- */
536
- this.__v_skip = true;
537
- if (!!(process.env.NODE_ENV !== "production")) {
538
- this.subsHead = void 0;
539
- }
540
- }
541
- track(debugInfo) {
542
- if (!activeSub || !shouldTrack || activeSub === this.computed) {
543
- return;
544
- }
545
- let link = this.activeLink;
546
- if (link === void 0 || link.sub !== activeSub) {
547
- link = this.activeLink = new Link(activeSub, this);
548
- if (!activeSub.deps) {
549
- activeSub.deps = activeSub.depsTail = link;
550
- } else {
551
- link.prevDep = activeSub.depsTail;
552
- activeSub.depsTail.nextDep = link;
553
- activeSub.depsTail = link;
554
- }
555
- addSub(link);
556
- } else if (link.version === -1) {
557
- link.version = this.version;
558
- if (link.nextDep) {
559
- const next = link.nextDep;
560
- next.prevDep = link.prevDep;
561
- if (link.prevDep) {
562
- link.prevDep.nextDep = next;
563
- }
564
- link.prevDep = activeSub.depsTail;
565
- link.nextDep = void 0;
566
- activeSub.depsTail.nextDep = link;
567
- activeSub.depsTail = link;
568
- if (activeSub.deps === link) {
569
- activeSub.deps = next;
570
- }
571
- }
572
- }
573
- if (!!(process.env.NODE_ENV !== "production") && activeSub.onTrack) {
574
- activeSub.onTrack(
575
- extend(
576
- {
577
- effect: activeSub
578
- },
579
- debugInfo
580
- )
581
- );
582
- }
583
- return link;
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
- trigger(debugInfo) {
586
- this.version++;
587
- globalVersion++;
588
- this.notify(debugInfo);
357
+ get subs() {
358
+ return this._subs;
589
359
  }
590
- notify(debugInfo) {
591
- startBatch();
592
- try {
593
- if (!!(process.env.NODE_ENV !== "production")) {
594
- for (let head = this.subsHead; head; head = head.nextSub) {
595
- if (head.sub.onTrigger && !(head.sub.flags & 8)) {
596
- head.sub.onTrigger(
597
- extend(
598
- {
599
- effect: head.sub
600
- },
601
- debugInfo
602
- )
603
- );
604
- }
605
- }
606
- }
607
- for (let link = this.subs; link; link = link.prevSub) {
608
- if (link.sub.notify()) {
609
- ;
610
- link.sub.dep.notify();
611
- }
612
- }
613
- } finally {
614
- endBatch();
360
+ set subs(value) {
361
+ this._subs = value;
362
+ if (value === void 0) {
363
+ this.map.delete(this.key);
615
364
  }
616
365
  }
617
366
  }
618
- function addSub(link) {
619
- link.dep.sc++;
620
- if (link.sub.flags & 4) {
621
- const computed = link.dep.computed;
622
- if (computed && !link.dep.subs) {
623
- computed.flags |= 4 | 16;
624
- for (let l = computed.deps; l; l = l.nextDep) {
625
- addSub(l);
626
- }
627
- }
628
- const currentTail = link.dep.subs;
629
- if (currentTail !== link) {
630
- link.prevSub = currentTail;
631
- if (currentTail) currentTail.nextSub = link;
632
- }
633
- if (!!(process.env.NODE_ENV !== "production") && link.dep.subsHead === void 0) {
634
- link.dep.subsHead = link;
635
- }
636
- link.dep.subs = link;
637
- }
638
- }
639
367
  const targetMap = /* @__PURE__ */ new WeakMap();
640
368
  const ITERATE_KEY = Symbol(
641
369
  !!(process.env.NODE_ENV !== "production") ? "Object iterate" : ""
@@ -647,38 +375,34 @@ const ARRAY_ITERATE_KEY = Symbol(
647
375
  !!(process.env.NODE_ENV !== "production") ? "Array iterate" : ""
648
376
  );
649
377
  function track(target, type, key) {
650
- if (shouldTrack && activeSub) {
378
+ if (activeSub !== void 0) {
651
379
  let depsMap = targetMap.get(target);
652
380
  if (!depsMap) {
653
381
  targetMap.set(target, depsMap = /* @__PURE__ */ new Map());
654
382
  }
655
383
  let dep = depsMap.get(key);
656
384
  if (!dep) {
657
- depsMap.set(key, dep = new Dep());
658
- dep.map = depsMap;
659
- dep.key = key;
385
+ depsMap.set(key, dep = new Dep(depsMap, key));
660
386
  }
661
387
  if (!!(process.env.NODE_ENV !== "production")) {
662
- dep.track({
388
+ onTrack(activeSub, {
663
389
  target,
664
390
  type,
665
391
  key
666
392
  });
667
- } else {
668
- dep.track();
669
393
  }
394
+ link(dep, activeSub);
670
395
  }
671
396
  }
672
397
  function trigger(target, type, key, newValue, oldValue, oldTarget) {
673
398
  const depsMap = targetMap.get(target);
674
399
  if (!depsMap) {
675
- globalVersion++;
676
400
  return;
677
401
  }
678
402
  const run = (dep) => {
679
- if (dep) {
403
+ if (dep !== void 0 && dep.subs !== void 0) {
680
404
  if (!!(process.env.NODE_ENV !== "production")) {
681
- dep.trigger({
405
+ triggerEventInfos.push({
682
406
  target,
683
407
  type,
684
408
  key,
@@ -686,8 +410,11 @@ function trigger(target, type, key, newValue, oldValue, oldTarget) {
686
410
  oldValue,
687
411
  oldTarget
688
412
  });
689
- } else {
690
- dep.trigger();
413
+ }
414
+ propagate(dep.subs);
415
+ shallowPropagate(dep.subs);
416
+ if (!!(process.env.NODE_ENV !== "production")) {
417
+ triggerEventInfos.pop();
691
418
  }
692
419
  }
693
420
  };
@@ -913,11 +640,11 @@ function searchProxy(self, method, args) {
913
640
  return res;
914
641
  }
915
642
  function noTracking(self, method, args = []) {
916
- pauseTracking();
917
643
  startBatch();
644
+ const prevSub = setActiveSub();
918
645
  const res = toRaw(self)[method].apply(self, args);
646
+ setActiveSub(prevSub);
919
647
  endBatch();
920
- resetTracking();
921
648
  return res;
922
649
  }
923
650
 
@@ -963,14 +690,18 @@ class BaseReactiveHandler {
963
690
  return hasOwnProperty;
964
691
  }
965
692
  }
693
+ const wasRef = isRef(target);
966
694
  const res = Reflect.get(
967
695
  target,
968
696
  key,
969
697
  // if this is a proxy wrapping a ref, return methods using the raw ref
970
698
  // as receiver so that we don't have to call `toRaw` on the ref in all
971
699
  // its class methods
972
- isRef(target) ? target : receiver
700
+ wasRef ? target : receiver
973
701
  );
702
+ if (wasRef && key !== "value") {
703
+ return res;
704
+ }
974
705
  if (isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) {
975
706
  return res;
976
707
  }
@@ -1422,35 +1153,47 @@ function isRef(r) {
1422
1153
  return r ? r["__v_isRef"] === true : false;
1423
1154
  }
1424
1155
  function ref(value) {
1425
- return createRef(value, false);
1156
+ return createRef(value, toReactive);
1426
1157
  }
1427
1158
  function shallowRef(value) {
1428
- return createRef(value, true);
1159
+ return createRef(value);
1429
1160
  }
1430
- function createRef(rawValue, shallow) {
1161
+ function createRef(rawValue, wrap) {
1431
1162
  if (isRef(rawValue)) {
1432
1163
  return rawValue;
1433
1164
  }
1434
- return new RefImpl(rawValue, shallow);
1165
+ return new RefImpl(rawValue, wrap);
1435
1166
  }
1436
1167
  class RefImpl {
1437
- constructor(value, isShallow2) {
1438
- this.dep = new Dep();
1439
- this["__v_isRef"] = true;
1440
- this["__v_isShallow"] = false;
1441
- this._rawValue = isShallow2 ? value : toRaw(value);
1442
- this._value = isShallow2 ? value : toReactive(value);
1443
- 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;
1444
1189
  }
1445
1190
  get value() {
1446
- if (!!(process.env.NODE_ENV !== "production")) {
1447
- this.dep.track({
1448
- target: this,
1449
- type: "get",
1450
- key: "value"
1451
- });
1452
- } else {
1453
- 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
+ }
1454
1197
  }
1455
1198
  return this._value;
1456
1199
  }
@@ -1459,195 +1202,541 @@ class RefImpl {
1459
1202
  const useDirectValue = this["__v_isShallow"] || isShallow(newValue) || isReadonly(newValue);
1460
1203
  newValue = useDirectValue ? newValue : toRaw(newValue);
1461
1204
  if (hasChanged(newValue, oldValue)) {
1205
+ this.flags |= ReactiveFlags$1.Dirty;
1462
1206
  this._rawValue = newValue;
1463
- this._value = useDirectValue ? newValue : toReactive(newValue);
1464
- if (!!(process.env.NODE_ENV !== "production")) {
1465
- this.dep.trigger({
1466
- target: this,
1467
- type: "set",
1468
- key: "value",
1469
- newValue,
1470
- oldValue
1471
- });
1472
- } else {
1473
- 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
+ }
1474
1226
  }
1475
1227
  }
1476
1228
  }
1229
+ update() {
1230
+ this.flags &= ~ReactiveFlags$1.Dirty;
1231
+ return hasChanged(this._oldValue, this._oldValue = this._rawValue);
1232
+ }
1477
1233
  }
1478
1234
  function triggerRef(ref2) {
1479
- 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) {
1480
1246
  if (!!(process.env.NODE_ENV !== "production")) {
1481
- ref2.dep.trigger({
1482
- target: ref2,
1483
- type: "set",
1484
- key: "value",
1485
- newValue: ref2._value
1247
+ onTrack(activeSub, {
1248
+ target: dep,
1249
+ type: "get",
1250
+ key: "value"
1486
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;
1487
1269
  } else {
1488
- 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
+ };
1489
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;
1490
1488
  }
1489
+ const runner = e.run.bind(e);
1490
+ runner.effect = e;
1491
+ return runner;
1491
1492
  }
1492
- function unref(ref2) {
1493
- return isRef(ref2) ? ref2.value : ref2;
1493
+ function stop(runner) {
1494
+ runner.effect.stop();
1494
1495
  }
1495
- function toValue(source) {
1496
- return isFunction(source) ? source() : unref(source);
1496
+ const resetTrackingStack = [];
1497
+ function pauseTracking() {
1498
+ resetTrackingStack.push(activeSub);
1499
+ setActiveSub();
1497
1500
  }
1498
- const shallowUnwrapHandlers = {
1499
- get: (target, key, receiver) => key === "__v_raw" ? target : unref(Reflect.get(target, key, receiver)),
1500
- set: (target, key, value, receiver) => {
1501
- const oldValue = target[key];
1502
- if (isRef(oldValue) && !isRef(value)) {
1503
- oldValue.value = value;
1504
- return true;
1505
- } else {
1506
- 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
+ }
1507
1512
  }
1508
1513
  }
1509
- };
1510
- function proxyRefs(objectWithRefs) {
1511
- return isReactive(objectWithRefs) ? objectWithRefs : new Proxy(objectWithRefs, shallowUnwrapHandlers);
1512
1514
  }
1513
- class CustomRefImpl {
1514
- constructor(factory) {
1515
- this["__v_isRef"] = true;
1516
- this._value = void 0;
1517
- const dep = this.dep = new Dep();
1518
- const { get, set } = factory(dep.track.bind(dep), dep.trigger.bind(dep));
1519
- this._get = get;
1520
- this._set = set;
1521
- }
1522
- get value() {
1523
- 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
+ );
1524
1520
  }
1525
- set value(newVal) {
1526
- this._set(newVal);
1521
+ if (resetTrackingStack.length) {
1522
+ setActiveSub(resetTrackingStack.pop());
1523
+ } else {
1524
+ setActiveSub();
1527
1525
  }
1528
1526
  }
1529
- function customRef(factory) {
1530
- 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
+ }
1531
1535
  }
1532
- function toRefs(object) {
1533
- if (!!(process.env.NODE_ENV !== "production") && !isProxy(object)) {
1534
- 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
+ );
1535
1543
  }
1536
- const ret = isArray(object) ? new Array(object.length) : {};
1537
- for (const key in object) {
1538
- ret[key] = propertyToRef(object, key);
1544
+ }
1545
+ function cleanupEffect(fn) {
1546
+ const prevSub = setActiveSub();
1547
+ try {
1548
+ fn();
1549
+ } finally {
1550
+ setActiveSub(prevSub);
1539
1551
  }
1540
- return ret;
1541
1552
  }
1542
- class ObjectRefImpl {
1543
- constructor(_object, _key, _defaultValue) {
1544
- this._object = _object;
1545
- this._key = _key;
1546
- this._defaultValue = _defaultValue;
1547
- this["__v_isRef"] = true;
1548
- 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
+ }
1549
1573
  }
1550
- get value() {
1551
- const val = this._object[this._key];
1552
- return this._value = val === void 0 ? this._defaultValue : val;
1574
+ get active() {
1575
+ return !(this.flags & 1024);
1553
1576
  }
1554
- set value(newVal) {
1555
- 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
+ }
1556
1587
  }
1557
- get dep() {
1558
- 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
+ }
1559
1602
  }
1560
- }
1561
- class GetterRefImpl {
1562
- constructor(_getter) {
1563
- this._getter = _getter;
1564
- this["__v_isRef"] = true;
1565
- this["__v_isReadonly"] = true;
1566
- 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
+ }
1567
1613
  }
1568
- get value() {
1569
- 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);
1570
1634
  }
1571
1635
  }
1572
- function toRef(source, key, defaultValue) {
1573
- if (isRef(source)) {
1574
- return source;
1575
- } else if (isFunction(source)) {
1576
- return new GetterRefImpl(source);
1577
- } else if (isObject(source) && arguments.length > 1) {
1578
- return propertyToRef(source, key, defaultValue);
1579
- } else {
1580
- 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;
1581
1647
  }
1582
1648
  }
1583
- function propertyToRef(source, key, defaultValue) {
1584
- const val = source[key];
1585
- 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
+ }
1586
1657
  }
1587
1658
 
1588
1659
  class ComputedRefImpl {
1589
- constructor(fn, setter, isSSR) {
1660
+ constructor(fn, setter) {
1590
1661
  this.fn = fn;
1591
1662
  this.setter = setter;
1592
1663
  /**
1593
1664
  * @internal
1594
1665
  */
1595
1666
  this._value = void 0;
1596
- /**
1597
- * @internal
1598
- */
1599
- this.dep = new Dep(this);
1600
- /**
1601
- * @internal
1602
- */
1603
- this.__v_isRef = true;
1604
- // TODO isolatedDeclarations "__v_isReadonly"
1605
- // A computed is also a subscriber that tracks other deps
1606
- /**
1607
- * @internal
1608
- */
1667
+ this.subs = void 0;
1668
+ this.subsTail = void 0;
1609
1669
  this.deps = void 0;
1610
- /**
1611
- * @internal
1612
- */
1613
1670
  this.depsTail = void 0;
1671
+ this.flags = ReactiveFlags$1.Mutable | ReactiveFlags$1.Dirty;
1614
1672
  /**
1615
1673
  * @internal
1616
1674
  */
1617
- this.flags = 16;
1618
- /**
1619
- * @internal
1620
- */
1621
- this.globalVersion = globalVersion - 1;
1622
- /**
1623
- * @internal
1624
- */
1625
- this.next = void 0;
1626
- // for backwards compat
1627
- this.effect = this;
1675
+ this.__v_isRef = true;
1628
1676
  this["__v_isReadonly"] = !setter;
1629
- 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;
1630
1686
  }
1631
1687
  /**
1632
1688
  * @internal
1689
+ * for backwards compat
1633
1690
  */
1634
- notify() {
1635
- this.flags |= 16;
1636
- if (!(this.flags & 8) && // avoid infinite self recursion
1637
- activeSub !== this) {
1638
- batch(this, true);
1691
+ get _dirty() {
1692
+ const flags = this.flags;
1693
+ if (flags & ReactiveFlags$1.Dirty) {
1639
1694
  return true;
1640
- } 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
+ }
1641
1716
  }
1642
1717
  get value() {
1643
- const link = !!(process.env.NODE_ENV !== "production") ? this.dep.track({
1644
- target: this,
1645
- type: "get",
1646
- key: "value"
1647
- }) : this.dep.track();
1648
- refreshComputed(this);
1649
- if (link) {
1650
- 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);
1651
1740
  }
1652
1741
  return this._value;
1653
1742
  }
@@ -1658,6 +1747,23 @@ class ComputedRefImpl {
1658
1747
  warn("Write operation failed: computed value is readonly");
1659
1748
  }
1660
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);
1661
1767
  }
1662
1768
  function computed(getterOrOptions, debugOptions, isSSR = false) {
1663
1769
  let getter;
@@ -1668,7 +1774,7 @@ function computed(getterOrOptions, debugOptions, isSSR = false) {
1668
1774
  getter = getterOrOptions.get;
1669
1775
  setter = getterOrOptions.set;
1670
1776
  }
1671
- const cRef = new ComputedRefImpl(getter, setter, isSSR);
1777
+ const cRef = new ComputedRefImpl(getter, setter);
1672
1778
  if (!!(process.env.NODE_ENV !== "production") && debugOptions && !isSSR) {
1673
1779
  cRef.onTrack = debugOptions.onTrack;
1674
1780
  cRef.onTrigger = debugOptions.onTrigger;
@@ -1705,177 +1811,155 @@ const WatchErrorCodes = {
1705
1811
  "4": "WATCH_CLEANUP"
1706
1812
  };
1707
1813
  const INITIAL_WATCHER_VALUE = {};
1708
- const cleanupMap = /* @__PURE__ */ new WeakMap();
1709
1814
  let activeWatcher = void 0;
1710
1815
  function getCurrentWatcher() {
1711
1816
  return activeWatcher;
1712
1817
  }
1713
1818
  function onWatcherCleanup(cleanupFn, failSilently = false, owner = activeWatcher) {
1714
1819
  if (owner) {
1715
- let cleanups = cleanupMap.get(owner);
1716
- if (!cleanups) cleanupMap.set(owner, cleanups = []);
1717
- 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
+ }
1718
1826
  } else if (!!(process.env.NODE_ENV !== "production") && !failSilently) {
1719
1827
  warn(
1720
1828
  `onWatcherCleanup() was called when there was no active watcher to associate with.`
1721
1829
  );
1722
1830
  }
1723
1831
  }
1724
- function watch(source, cb, options = EMPTY_OBJ) {
1725
- const { immediate, deep, once, scheduler, augmentJob, call } = options;
1726
- const warnInvalidSource = (s) => {
1727
- (options.onWarn || warn)(
1728
- `Invalid watch source: `,
1729
- s,
1730
- `A watch source can only be a getter/effect function, a ref, a reactive object, or an array of these types.`
1731
- );
1732
- };
1733
- const reactiveGetter = (source2) => {
1734
- if (deep) return source2;
1735
- if (isShallow(source2) || deep === false || deep === 0)
1736
- return traverse(source2, 1);
1737
- return traverse(source2);
1738
- };
1739
- let effect;
1740
- let getter;
1741
- let cleanup;
1742
- let boundCleanup;
1743
- let forceTrigger = false;
1744
- let isMultiSource = false;
1745
- if (isRef(source)) {
1746
- getter = () => source.value;
1747
- forceTrigger = isShallow(source);
1748
- } else if (isReactive(source)) {
1749
- getter = () => reactiveGetter(source);
1750
- forceTrigger = true;
1751
- } else if (isArray(source)) {
1752
- isMultiSource = true;
1753
- forceTrigger = source.some((s) => isReactive(s) || isShallow(s));
1754
- getter = () => source.map((s) => {
1755
- if (isRef(s)) {
1756
- return s.value;
1757
- } else if (isReactive(s)) {
1758
- return reactiveGetter(s);
1759
- } else if (isFunction(s)) {
1760
- 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;
1761
1861
  } else {
1762
- !!(process.env.NODE_ENV !== "production") && warnInvalidSource(s);
1763
- }
1764
- });
1765
- } else if (isFunction(source)) {
1766
- if (cb) {
1767
- getter = call ? () => call(source, 2) : source;
1768
- } else {
1769
- getter = () => {
1770
- if (cleanup) {
1771
- 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;
1772
1873
  try {
1773
- cleanup();
1874
+ return call ? call(source, 3, [
1875
+ this.boundCleanup
1876
+ ]) : source(this.boundCleanup);
1774
1877
  } finally {
1775
- resetTracking();
1878
+ activeWatcher = currentEffect;
1776
1879
  }
1777
- }
1778
- const currentEffect = activeWatcher;
1779
- activeWatcher = effect;
1780
- try {
1781
- return call ? call(source, 3, [boundCleanup]) : source(boundCleanup);
1782
- } finally {
1783
- activeWatcher = currentEffect;
1784
- }
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();
1785
1902
  };
1786
1903
  }
1787
- } else {
1788
- getter = NOOP;
1789
- !!(process.env.NODE_ENV !== "production") && warnInvalidSource(source);
1790
- }
1791
- if (cb && deep) {
1792
- const baseGetter = getter;
1793
- const depth = deep === true ? Infinity : deep;
1794
- getter = () => traverse(baseGetter(), depth);
1795
- }
1796
- const scope = getCurrentScope();
1797
- const watchHandle = () => {
1798
- effect.stop();
1799
- if (scope && scope.active) {
1800
- 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;
1801
1909
  }
1802
- };
1803
- if (once && cb) {
1804
- const _cb = cb;
1805
- cb = (...args) => {
1806
- _cb(...args);
1807
- watchHandle();
1808
- };
1809
1910
  }
1810
- let oldValue = isMultiSource ? new Array(source.length).fill(INITIAL_WATCHER_VALUE) : INITIAL_WATCHER_VALUE;
1811
- const job = (immediateFirstRun) => {
1812
- 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) {
1813
1915
  return;
1814
1916
  }
1815
- if (cb) {
1816
- const newValue = effect.run();
1817
- if (deep || forceTrigger || (isMultiSource ? newValue.some((v, i) => hasChanged(v, oldValue[i])) : hasChanged(newValue, oldValue))) {
1818
- if (cleanup) {
1819
- cleanup();
1820
- }
1821
- const currentWatcher = activeWatcher;
1822
- activeWatcher = effect;
1823
- try {
1824
- const args = [
1825
- newValue,
1826
- // pass undefined as the old value when it's changed for the first time
1827
- oldValue === INITIAL_WATCHER_VALUE ? void 0 : isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE ? [] : oldValue,
1828
- boundCleanup
1829
- ];
1830
- oldValue = newValue;
1831
- call ? call(cb, 3, args) : (
1832
- // @ts-expect-error
1833
- cb(...args)
1834
- );
1835
- } finally {
1836
- activeWatcher = currentWatcher;
1837
- }
1838
- }
1839
- } else {
1840
- effect.run();
1917
+ const { immediate, deep, call } = this.options;
1918
+ if (initialRun && !immediate) {
1919
+ return;
1841
1920
  }
1842
- };
1843
- if (augmentJob) {
1844
- augmentJob(job);
1845
- }
1846
- effect = new ReactiveEffect(getter);
1847
- effect.scheduler = scheduler ? () => scheduler(job, false) : job;
1848
- boundCleanup = (fn) => onWatcherCleanup(fn, false, effect);
1849
- cleanup = effect.onStop = () => {
1850
- const cleanups = cleanupMap.get(effect);
1851
- if (cleanups) {
1852
- if (call) {
1853
- call(cleanups, 4);
1854
- } else {
1855
- 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;
1856
1938
  }
1857
- cleanupMap.delete(effect);
1858
- }
1859
- };
1860
- if (!!(process.env.NODE_ENV !== "production")) {
1861
- effect.onTrack = options.onTrack;
1862
- effect.onTrigger = options.onTrigger;
1863
- }
1864
- if (cb) {
1865
- if (immediate) {
1866
- job(true);
1867
- } else {
1868
- oldValue = effect.run();
1869
1939
  }
1870
- } else if (scheduler) {
1871
- scheduler(job.bind(null, true), true);
1872
- } else {
1873
- effect.run();
1874
1940
  }
1875
- watchHandle.pause = effect.pause.bind(effect);
1876
- watchHandle.resume = effect.resume.bind(effect);
1877
- watchHandle.stop = watchHandle;
1878
- 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;
1879
1963
  }
1880
1964
  function traverse(value, depth = Infinity, seen) {
1881
1965
  if (depth <= 0 || !isObject(value) || value["__v_skip"]) {
@@ -1910,4 +1994,4 @@ function traverse(value, depth = Infinity, seen) {
1910
1994
  return value;
1911
1995
  }
1912
1996
 
1913
- 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 };