@vue/reactivity 3.5.0-beta.2 → 3.5.0-rc.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,9 +1,9 @@
1
1
  /**
2
- * @vue/reactivity v3.5.0-beta.2
2
+ * @vue/reactivity v3.5.0-rc.1
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
6
- import { hasChanged, extend, isArray, isIntegerKey, isSymbol, isMap, hasOwn, isObject, makeMap, capitalize, toRawType, def, isFunction } from '@vue/shared';
6
+ import { hasChanged, extend, isArray, isIntegerKey, isSymbol, isMap, hasOwn, isObject, makeMap, capitalize, toRawType, def, isFunction, EMPTY_OBJ, isSet, isPlainObject, NOOP, remove } from '@vue/shared';
7
7
 
8
8
  function warn(msg, ...args) {
9
9
  console.warn(`[Vue warn] ${msg}`, ...args);
@@ -39,12 +39,13 @@ class EffectScope {
39
39
  pause() {
40
40
  if (this._active) {
41
41
  this._isPaused = true;
42
+ let i, l;
42
43
  if (this.scopes) {
43
- for (let i = 0, l = this.scopes.length; i < l; i++) {
44
+ for (i = 0, l = this.scopes.length; i < l; i++) {
44
45
  this.scopes[i].pause();
45
46
  }
46
47
  }
47
- for (let i = 0, l = this.effects.length; i < l; i++) {
48
+ for (i = 0, l = this.effects.length; i < l; i++) {
48
49
  this.effects[i].pause();
49
50
  }
50
51
  }
@@ -56,12 +57,13 @@ class EffectScope {
56
57
  if (this._active) {
57
58
  if (this._isPaused) {
58
59
  this._isPaused = false;
60
+ let i, l;
59
61
  if (this.scopes) {
60
- for (let i = 0, l = this.scopes.length; i < l; i++) {
62
+ for (i = 0, l = this.scopes.length; i < l; i++) {
61
63
  this.scopes[i].resume();
62
64
  }
63
65
  }
64
- for (let i = 0, l = this.effects.length; i < l; i++) {
66
+ for (i = 0, l = this.effects.length; i < l; i++) {
65
67
  this.effects[i].resume();
66
68
  }
67
69
  }
@@ -270,11 +272,9 @@ function startBatch() {
270
272
  batchDepth++;
271
273
  }
272
274
  function endBatch() {
273
- if (batchDepth > 1) {
274
- batchDepth--;
275
+ if (--batchDepth > 0) {
275
276
  return;
276
277
  }
277
- batchDepth--;
278
278
  let error;
279
279
  while (batchedEffect) {
280
280
  let e = batchedEffect;
@@ -805,14 +805,14 @@ function iterator(self, method, wrapValue) {
805
805
  const arrayProto = Array.prototype;
806
806
  function apply(self, method, fn, thisArg, wrappedRetFn, args) {
807
807
  const arr = shallowReadArray(self);
808
- let methodFn;
809
- if ((methodFn = arr[method]) !== arrayProto[method]) {
810
- return methodFn.apply(arr, args);
808
+ const needsWrap = arr !== self && !isShallow(self);
809
+ const methodFn = arr[method];
810
+ if (methodFn !== arrayProto[method]) {
811
+ const result2 = methodFn.apply(arr, args);
812
+ return needsWrap ? toReactive(result2) : result2;
811
813
  }
812
- let needsWrap = false;
813
814
  let wrappedFn = fn;
814
815
  if (arr !== self) {
815
- needsWrap = !isShallow(self);
816
816
  if (needsWrap) {
817
817
  wrappedFn = function(item, index) {
818
818
  return fn.call(this, toReactive(item), index, self);
@@ -950,7 +950,12 @@ class MutableReactiveHandler extends BaseReactiveHandler {
950
950
  }
951
951
  }
952
952
  const hadKey = isArray(target) && isIntegerKey(key) ? Number(key) < target.length : hasOwn(target, key);
953
- const result = Reflect.set(target, key, value, receiver);
953
+ const result = Reflect.set(
954
+ target,
955
+ key,
956
+ value,
957
+ isRef(target) ? target : receiver
958
+ );
954
959
  if (target === toRaw(receiver)) {
955
960
  if (!hadKey) {
956
961
  trigger(target, "add", key, value);
@@ -1688,4 +1693,226 @@ const ReactiveFlags = {
1688
1693
  "IS_REF": "__v_isRef"
1689
1694
  };
1690
1695
 
1691
- export { ARRAY_ITERATE_KEY, EffectFlags, EffectScope, ITERATE_KEY, MAP_KEY_ITERATE_KEY, ReactiveEffect, ReactiveFlags, TrackOpTypes, TriggerOpTypes, computed, customRef, effect, effectScope, enableTracking, getCurrentScope, isProxy, isReactive, isReadonly, isRef, isShallow, markRaw, onEffectCleanup, onScopeDispose, pauseTracking, proxyRefs, reactive, reactiveReadArray, readonly, ref, resetTracking, shallowReactive, shallowReadArray, shallowReadonly, shallowRef, stop, toRaw, toReactive, toReadonly, toRef, toRefs, toValue, track, trigger, triggerRef, unref };
1696
+ const WatchErrorCodes = {
1697
+ "WATCH_GETTER": 2,
1698
+ "2": "WATCH_GETTER",
1699
+ "WATCH_CALLBACK": 3,
1700
+ "3": "WATCH_CALLBACK",
1701
+ "WATCH_CLEANUP": 4,
1702
+ "4": "WATCH_CLEANUP"
1703
+ };
1704
+ const INITIAL_WATCHER_VALUE = {};
1705
+ const cleanupMap = /* @__PURE__ */ new WeakMap();
1706
+ let activeWatcher = void 0;
1707
+ function getCurrentWatcher() {
1708
+ return activeWatcher;
1709
+ }
1710
+ function onWatcherCleanup(cleanupFn, failSilently = false, owner = activeWatcher) {
1711
+ if (owner) {
1712
+ let cleanups = cleanupMap.get(owner);
1713
+ if (!cleanups) cleanupMap.set(owner, cleanups = []);
1714
+ cleanups.push(cleanupFn);
1715
+ } else if (!!(process.env.NODE_ENV !== "production") && !failSilently) {
1716
+ warn(
1717
+ `onWatcherCleanup() was called when there was no active watcher to associate with.`
1718
+ );
1719
+ }
1720
+ }
1721
+ function watch(source, cb, options = EMPTY_OBJ) {
1722
+ const { immediate, deep, once, scheduler, augmentJob, call } = options;
1723
+ const warnInvalidSource = (s) => {
1724
+ (options.onWarn || warn)(
1725
+ `Invalid watch source: `,
1726
+ s,
1727
+ `A watch source can only be a getter/effect function, a ref, a reactive object, or an array of these types.`
1728
+ );
1729
+ };
1730
+ const reactiveGetter = (source2) => {
1731
+ if (deep) return source2;
1732
+ if (isShallow(source2) || deep === false || deep === 0)
1733
+ return traverse(source2, 1);
1734
+ return traverse(source2);
1735
+ };
1736
+ let effect;
1737
+ let getter;
1738
+ let cleanup;
1739
+ let boundCleanup;
1740
+ let forceTrigger = false;
1741
+ let isMultiSource = false;
1742
+ if (isRef(source)) {
1743
+ getter = () => source.value;
1744
+ forceTrigger = isShallow(source);
1745
+ } else if (isReactive(source)) {
1746
+ getter = () => reactiveGetter(source);
1747
+ forceTrigger = true;
1748
+ } else if (isArray(source)) {
1749
+ isMultiSource = true;
1750
+ forceTrigger = source.some((s) => isReactive(s) || isShallow(s));
1751
+ getter = () => source.map((s) => {
1752
+ if (isRef(s)) {
1753
+ return s.value;
1754
+ } else if (isReactive(s)) {
1755
+ return reactiveGetter(s);
1756
+ } else if (isFunction(s)) {
1757
+ return call ? call(s, 2) : s();
1758
+ } else {
1759
+ !!(process.env.NODE_ENV !== "production") && warnInvalidSource(s);
1760
+ }
1761
+ });
1762
+ } else if (isFunction(source)) {
1763
+ if (cb) {
1764
+ getter = call ? () => call(source, 2) : source;
1765
+ } else {
1766
+ getter = () => {
1767
+ if (cleanup) {
1768
+ pauseTracking();
1769
+ try {
1770
+ cleanup();
1771
+ } finally {
1772
+ resetTracking();
1773
+ }
1774
+ }
1775
+ const currentEffect = activeWatcher;
1776
+ activeWatcher = effect;
1777
+ try {
1778
+ return call ? call(source, 3, [boundCleanup]) : source(boundCleanup);
1779
+ } finally {
1780
+ activeWatcher = currentEffect;
1781
+ }
1782
+ };
1783
+ }
1784
+ } else {
1785
+ getter = NOOP;
1786
+ !!(process.env.NODE_ENV !== "production") && warnInvalidSource(source);
1787
+ }
1788
+ if (cb && deep) {
1789
+ const baseGetter = getter;
1790
+ const depth = deep === true ? Infinity : deep;
1791
+ getter = () => traverse(baseGetter(), depth);
1792
+ }
1793
+ const scope = getCurrentScope();
1794
+ const watchHandle = () => {
1795
+ effect.stop();
1796
+ if (scope) {
1797
+ remove(scope.effects, effect);
1798
+ }
1799
+ };
1800
+ if (once) {
1801
+ if (cb) {
1802
+ const _cb = cb;
1803
+ cb = (...args) => {
1804
+ _cb(...args);
1805
+ watchHandle();
1806
+ };
1807
+ } else {
1808
+ const _getter = getter;
1809
+ getter = () => {
1810
+ _getter();
1811
+ watchHandle();
1812
+ };
1813
+ }
1814
+ }
1815
+ let oldValue = isMultiSource ? new Array(source.length).fill(INITIAL_WATCHER_VALUE) : INITIAL_WATCHER_VALUE;
1816
+ const job = (immediateFirstRun) => {
1817
+ if (!(effect.flags & 1) || !effect.dirty && !immediateFirstRun) {
1818
+ return;
1819
+ }
1820
+ if (cb) {
1821
+ const newValue = effect.run();
1822
+ if (deep || forceTrigger || (isMultiSource ? newValue.some((v, i) => hasChanged(v, oldValue[i])) : hasChanged(newValue, oldValue))) {
1823
+ if (cleanup) {
1824
+ cleanup();
1825
+ }
1826
+ const currentWatcher = activeWatcher;
1827
+ activeWatcher = effect;
1828
+ try {
1829
+ const args = [
1830
+ newValue,
1831
+ // pass undefined as the old value when it's changed for the first time
1832
+ oldValue === INITIAL_WATCHER_VALUE ? void 0 : isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE ? [] : oldValue,
1833
+ boundCleanup
1834
+ ];
1835
+ call ? call(cb, 3, args) : (
1836
+ // @ts-expect-error
1837
+ cb(...args)
1838
+ );
1839
+ oldValue = newValue;
1840
+ } finally {
1841
+ activeWatcher = currentWatcher;
1842
+ }
1843
+ }
1844
+ } else {
1845
+ effect.run();
1846
+ }
1847
+ };
1848
+ if (augmentJob) {
1849
+ augmentJob(job);
1850
+ }
1851
+ effect = new ReactiveEffect(getter);
1852
+ effect.scheduler = scheduler ? () => scheduler(job, false) : job;
1853
+ boundCleanup = (fn) => onWatcherCleanup(fn, false, effect);
1854
+ cleanup = effect.onStop = () => {
1855
+ const cleanups = cleanupMap.get(effect);
1856
+ if (cleanups) {
1857
+ if (call) {
1858
+ call(cleanups, 4);
1859
+ } else {
1860
+ for (const cleanup2 of cleanups) cleanup2();
1861
+ }
1862
+ cleanupMap.delete(effect);
1863
+ }
1864
+ };
1865
+ if (!!(process.env.NODE_ENV !== "production")) {
1866
+ effect.onTrack = options.onTrack;
1867
+ effect.onTrigger = options.onTrigger;
1868
+ }
1869
+ if (cb) {
1870
+ if (immediate) {
1871
+ job(true);
1872
+ } else {
1873
+ oldValue = effect.run();
1874
+ }
1875
+ } else if (scheduler) {
1876
+ scheduler(job.bind(null, true), true);
1877
+ } else {
1878
+ effect.run();
1879
+ }
1880
+ watchHandle.pause = effect.pause.bind(effect);
1881
+ watchHandle.resume = effect.resume.bind(effect);
1882
+ watchHandle.stop = watchHandle;
1883
+ return watchHandle;
1884
+ }
1885
+ function traverse(value, depth = Infinity, seen) {
1886
+ if (depth <= 0 || !isObject(value) || value["__v_skip"]) {
1887
+ return value;
1888
+ }
1889
+ seen = seen || /* @__PURE__ */ new Set();
1890
+ if (seen.has(value)) {
1891
+ return value;
1892
+ }
1893
+ seen.add(value);
1894
+ depth--;
1895
+ if (isRef(value)) {
1896
+ traverse(value.value, depth, seen);
1897
+ } else if (isArray(value)) {
1898
+ for (let i = 0; i < value.length; i++) {
1899
+ traverse(value[i], depth, seen);
1900
+ }
1901
+ } else if (isSet(value) || isMap(value)) {
1902
+ value.forEach((v) => {
1903
+ traverse(v, depth, seen);
1904
+ });
1905
+ } else if (isPlainObject(value)) {
1906
+ for (const key in value) {
1907
+ traverse(value[key], depth, seen);
1908
+ }
1909
+ for (const key of Object.getOwnPropertySymbols(value)) {
1910
+ if (Object.prototype.propertyIsEnumerable.call(value, key)) {
1911
+ traverse(value[key], depth, seen);
1912
+ }
1913
+ }
1914
+ }
1915
+ return value;
1916
+ }
1917
+
1918
+ 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 };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @vue/reactivity v3.5.0-beta.2
2
+ * @vue/reactivity v3.5.0-rc.1
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
@@ -13,11 +13,21 @@ var VueReactivity = (function (exports) {
13
13
  return (val) => set.has(val);
14
14
  }
15
15
 
16
+ const EMPTY_OBJ = Object.freeze({}) ;
17
+ const NOOP = () => {
18
+ };
16
19
  const extend = Object.assign;
20
+ const remove = (arr, el) => {
21
+ const i = arr.indexOf(el);
22
+ if (i > -1) {
23
+ arr.splice(i, 1);
24
+ }
25
+ };
17
26
  const hasOwnProperty$1 = Object.prototype.hasOwnProperty;
18
27
  const hasOwn = (val, key) => hasOwnProperty$1.call(val, key);
19
28
  const isArray = Array.isArray;
20
29
  const isMap = (val) => toTypeString(val) === "[object Map]";
30
+ const isSet = (val) => toTypeString(val) === "[object Set]";
21
31
  const isFunction = (val) => typeof val === "function";
22
32
  const isString = (val) => typeof val === "string";
23
33
  const isSymbol = (val) => typeof val === "symbol";
@@ -27,6 +37,7 @@ var VueReactivity = (function (exports) {
27
37
  const toRawType = (value) => {
28
38
  return toTypeString(value).slice(8, -1);
29
39
  };
40
+ const isPlainObject = (val) => toTypeString(val) === "[object Object]";
30
41
  const isIntegerKey = (key) => isString(key) && key !== "NaN" && key[0] !== "-" && "" + parseInt(key, 10) === key;
31
42
  const cacheStringFunction = (fn) => {
32
43
  const cache = /* @__PURE__ */ Object.create(null);
@@ -82,12 +93,13 @@ var VueReactivity = (function (exports) {
82
93
  pause() {
83
94
  if (this._active) {
84
95
  this._isPaused = true;
96
+ let i, l;
85
97
  if (this.scopes) {
86
- for (let i = 0, l = this.scopes.length; i < l; i++) {
98
+ for (i = 0, l = this.scopes.length; i < l; i++) {
87
99
  this.scopes[i].pause();
88
100
  }
89
101
  }
90
- for (let i = 0, l = this.effects.length; i < l; i++) {
102
+ for (i = 0, l = this.effects.length; i < l; i++) {
91
103
  this.effects[i].pause();
92
104
  }
93
105
  }
@@ -99,12 +111,13 @@ var VueReactivity = (function (exports) {
99
111
  if (this._active) {
100
112
  if (this._isPaused) {
101
113
  this._isPaused = false;
114
+ let i, l;
102
115
  if (this.scopes) {
103
- for (let i = 0, l = this.scopes.length; i < l; i++) {
116
+ for (i = 0, l = this.scopes.length; i < l; i++) {
104
117
  this.scopes[i].resume();
105
118
  }
106
119
  }
107
- for (let i = 0, l = this.effects.length; i < l; i++) {
120
+ for (i = 0, l = this.effects.length; i < l; i++) {
108
121
  this.effects[i].resume();
109
122
  }
110
123
  }
@@ -313,11 +326,9 @@ var VueReactivity = (function (exports) {
313
326
  batchDepth++;
314
327
  }
315
328
  function endBatch() {
316
- if (batchDepth > 1) {
317
- batchDepth--;
329
+ if (--batchDepth > 0) {
318
330
  return;
319
331
  }
320
- batchDepth--;
321
332
  let error;
322
333
  while (batchedEffect) {
323
334
  let e = batchedEffect;
@@ -844,14 +855,14 @@ var VueReactivity = (function (exports) {
844
855
  const arrayProto = Array.prototype;
845
856
  function apply(self, method, fn, thisArg, wrappedRetFn, args) {
846
857
  const arr = shallowReadArray(self);
847
- let methodFn;
848
- if ((methodFn = arr[method]) !== arrayProto[method]) {
849
- return methodFn.apply(arr, args);
858
+ const needsWrap = arr !== self && !isShallow(self);
859
+ const methodFn = arr[method];
860
+ if (methodFn !== arrayProto[method]) {
861
+ const result2 = methodFn.apply(arr, args);
862
+ return needsWrap ? toReactive(result2) : result2;
850
863
  }
851
- let needsWrap = false;
852
864
  let wrappedFn = fn;
853
865
  if (arr !== self) {
854
- needsWrap = !isShallow(self);
855
866
  if (needsWrap) {
856
867
  wrappedFn = function(item, index) {
857
868
  return fn.call(this, toReactive(item), index, self);
@@ -989,7 +1000,12 @@ var VueReactivity = (function (exports) {
989
1000
  }
990
1001
  }
991
1002
  const hadKey = isArray(target) && isIntegerKey(key) ? Number(key) < target.length : hasOwn(target, key);
992
- const result = Reflect.set(target, key, value, receiver);
1003
+ const result = Reflect.set(
1004
+ target,
1005
+ key,
1006
+ value,
1007
+ isRef(target) ? target : receiver
1008
+ );
993
1009
  if (target === toRaw(receiver)) {
994
1010
  if (!hadKey) {
995
1011
  trigger(target, "add", key, value);
@@ -1721,6 +1737,228 @@ var VueReactivity = (function (exports) {
1721
1737
  "IS_REF": "__v_isRef"
1722
1738
  };
1723
1739
 
1740
+ const WatchErrorCodes = {
1741
+ "WATCH_GETTER": 2,
1742
+ "2": "WATCH_GETTER",
1743
+ "WATCH_CALLBACK": 3,
1744
+ "3": "WATCH_CALLBACK",
1745
+ "WATCH_CLEANUP": 4,
1746
+ "4": "WATCH_CLEANUP"
1747
+ };
1748
+ const INITIAL_WATCHER_VALUE = {};
1749
+ const cleanupMap = /* @__PURE__ */ new WeakMap();
1750
+ let activeWatcher = void 0;
1751
+ function getCurrentWatcher() {
1752
+ return activeWatcher;
1753
+ }
1754
+ function onWatcherCleanup(cleanupFn, failSilently = false, owner = activeWatcher) {
1755
+ if (owner) {
1756
+ let cleanups = cleanupMap.get(owner);
1757
+ if (!cleanups) cleanupMap.set(owner, cleanups = []);
1758
+ cleanups.push(cleanupFn);
1759
+ } else if (!failSilently) {
1760
+ warn(
1761
+ `onWatcherCleanup() was called when there was no active watcher to associate with.`
1762
+ );
1763
+ }
1764
+ }
1765
+ function watch(source, cb, options = EMPTY_OBJ) {
1766
+ const { immediate, deep, once, scheduler, augmentJob, call } = options;
1767
+ const warnInvalidSource = (s) => {
1768
+ (options.onWarn || warn)(
1769
+ `Invalid watch source: `,
1770
+ s,
1771
+ `A watch source can only be a getter/effect function, a ref, a reactive object, or an array of these types.`
1772
+ );
1773
+ };
1774
+ const reactiveGetter = (source2) => {
1775
+ if (deep) return source2;
1776
+ if (isShallow(source2) || deep === false || deep === 0)
1777
+ return traverse(source2, 1);
1778
+ return traverse(source2);
1779
+ };
1780
+ let effect;
1781
+ let getter;
1782
+ let cleanup;
1783
+ let boundCleanup;
1784
+ let forceTrigger = false;
1785
+ let isMultiSource = false;
1786
+ if (isRef(source)) {
1787
+ getter = () => source.value;
1788
+ forceTrigger = isShallow(source);
1789
+ } else if (isReactive(source)) {
1790
+ getter = () => reactiveGetter(source);
1791
+ forceTrigger = true;
1792
+ } else if (isArray(source)) {
1793
+ isMultiSource = true;
1794
+ forceTrigger = source.some((s) => isReactive(s) || isShallow(s));
1795
+ getter = () => source.map((s) => {
1796
+ if (isRef(s)) {
1797
+ return s.value;
1798
+ } else if (isReactive(s)) {
1799
+ return reactiveGetter(s);
1800
+ } else if (isFunction(s)) {
1801
+ return call ? call(s, 2) : s();
1802
+ } else {
1803
+ warnInvalidSource(s);
1804
+ }
1805
+ });
1806
+ } else if (isFunction(source)) {
1807
+ if (cb) {
1808
+ getter = call ? () => call(source, 2) : source;
1809
+ } else {
1810
+ getter = () => {
1811
+ if (cleanup) {
1812
+ pauseTracking();
1813
+ try {
1814
+ cleanup();
1815
+ } finally {
1816
+ resetTracking();
1817
+ }
1818
+ }
1819
+ const currentEffect = activeWatcher;
1820
+ activeWatcher = effect;
1821
+ try {
1822
+ return call ? call(source, 3, [boundCleanup]) : source(boundCleanup);
1823
+ } finally {
1824
+ activeWatcher = currentEffect;
1825
+ }
1826
+ };
1827
+ }
1828
+ } else {
1829
+ getter = NOOP;
1830
+ warnInvalidSource(source);
1831
+ }
1832
+ if (cb && deep) {
1833
+ const baseGetter = getter;
1834
+ const depth = deep === true ? Infinity : deep;
1835
+ getter = () => traverse(baseGetter(), depth);
1836
+ }
1837
+ const scope = getCurrentScope();
1838
+ const watchHandle = () => {
1839
+ effect.stop();
1840
+ if (scope) {
1841
+ remove(scope.effects, effect);
1842
+ }
1843
+ };
1844
+ if (once) {
1845
+ if (cb) {
1846
+ const _cb = cb;
1847
+ cb = (...args) => {
1848
+ _cb(...args);
1849
+ watchHandle();
1850
+ };
1851
+ } else {
1852
+ const _getter = getter;
1853
+ getter = () => {
1854
+ _getter();
1855
+ watchHandle();
1856
+ };
1857
+ }
1858
+ }
1859
+ let oldValue = isMultiSource ? new Array(source.length).fill(INITIAL_WATCHER_VALUE) : INITIAL_WATCHER_VALUE;
1860
+ const job = (immediateFirstRun) => {
1861
+ if (!(effect.flags & 1) || !effect.dirty && !immediateFirstRun) {
1862
+ return;
1863
+ }
1864
+ if (cb) {
1865
+ const newValue = effect.run();
1866
+ if (deep || forceTrigger || (isMultiSource ? newValue.some((v, i) => hasChanged(v, oldValue[i])) : hasChanged(newValue, oldValue))) {
1867
+ if (cleanup) {
1868
+ cleanup();
1869
+ }
1870
+ const currentWatcher = activeWatcher;
1871
+ activeWatcher = effect;
1872
+ try {
1873
+ const args = [
1874
+ newValue,
1875
+ // pass undefined as the old value when it's changed for the first time
1876
+ oldValue === INITIAL_WATCHER_VALUE ? void 0 : isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE ? [] : oldValue,
1877
+ boundCleanup
1878
+ ];
1879
+ call ? call(cb, 3, args) : (
1880
+ // @ts-expect-error
1881
+ cb(...args)
1882
+ );
1883
+ oldValue = newValue;
1884
+ } finally {
1885
+ activeWatcher = currentWatcher;
1886
+ }
1887
+ }
1888
+ } else {
1889
+ effect.run();
1890
+ }
1891
+ };
1892
+ if (augmentJob) {
1893
+ augmentJob(job);
1894
+ }
1895
+ effect = new ReactiveEffect(getter);
1896
+ effect.scheduler = scheduler ? () => scheduler(job, false) : job;
1897
+ boundCleanup = (fn) => onWatcherCleanup(fn, false, effect);
1898
+ cleanup = effect.onStop = () => {
1899
+ const cleanups = cleanupMap.get(effect);
1900
+ if (cleanups) {
1901
+ if (call) {
1902
+ call(cleanups, 4);
1903
+ } else {
1904
+ for (const cleanup2 of cleanups) cleanup2();
1905
+ }
1906
+ cleanupMap.delete(effect);
1907
+ }
1908
+ };
1909
+ {
1910
+ effect.onTrack = options.onTrack;
1911
+ effect.onTrigger = options.onTrigger;
1912
+ }
1913
+ if (cb) {
1914
+ if (immediate) {
1915
+ job(true);
1916
+ } else {
1917
+ oldValue = effect.run();
1918
+ }
1919
+ } else if (scheduler) {
1920
+ scheduler(job.bind(null, true), true);
1921
+ } else {
1922
+ effect.run();
1923
+ }
1924
+ watchHandle.pause = effect.pause.bind(effect);
1925
+ watchHandle.resume = effect.resume.bind(effect);
1926
+ watchHandle.stop = watchHandle;
1927
+ return watchHandle;
1928
+ }
1929
+ function traverse(value, depth = Infinity, seen) {
1930
+ if (depth <= 0 || !isObject(value) || value["__v_skip"]) {
1931
+ return value;
1932
+ }
1933
+ seen = seen || /* @__PURE__ */ new Set();
1934
+ if (seen.has(value)) {
1935
+ return value;
1936
+ }
1937
+ seen.add(value);
1938
+ depth--;
1939
+ if (isRef(value)) {
1940
+ traverse(value.value, depth, seen);
1941
+ } else if (isArray(value)) {
1942
+ for (let i = 0; i < value.length; i++) {
1943
+ traverse(value[i], depth, seen);
1944
+ }
1945
+ } else if (isSet(value) || isMap(value)) {
1946
+ value.forEach((v) => {
1947
+ traverse(v, depth, seen);
1948
+ });
1949
+ } else if (isPlainObject(value)) {
1950
+ for (const key in value) {
1951
+ traverse(value[key], depth, seen);
1952
+ }
1953
+ for (const key of Object.getOwnPropertySymbols(value)) {
1954
+ if (Object.prototype.propertyIsEnumerable.call(value, key)) {
1955
+ traverse(value[key], depth, seen);
1956
+ }
1957
+ }
1958
+ }
1959
+ return value;
1960
+ }
1961
+
1724
1962
  exports.ARRAY_ITERATE_KEY = ARRAY_ITERATE_KEY;
1725
1963
  exports.EffectFlags = EffectFlags;
1726
1964
  exports.EffectScope = EffectScope;
@@ -1730,12 +1968,14 @@ var VueReactivity = (function (exports) {
1730
1968
  exports.ReactiveFlags = ReactiveFlags;
1731
1969
  exports.TrackOpTypes = TrackOpTypes;
1732
1970
  exports.TriggerOpTypes = TriggerOpTypes;
1971
+ exports.WatchErrorCodes = WatchErrorCodes;
1733
1972
  exports.computed = computed;
1734
1973
  exports.customRef = customRef;
1735
1974
  exports.effect = effect;
1736
1975
  exports.effectScope = effectScope;
1737
1976
  exports.enableTracking = enableTracking;
1738
1977
  exports.getCurrentScope = getCurrentScope;
1978
+ exports.getCurrentWatcher = getCurrentWatcher;
1739
1979
  exports.isProxy = isProxy;
1740
1980
  exports.isReactive = isReactive;
1741
1981
  exports.isReadonly = isReadonly;
@@ -1744,6 +1984,7 @@ var VueReactivity = (function (exports) {
1744
1984
  exports.markRaw = markRaw;
1745
1985
  exports.onEffectCleanup = onEffectCleanup;
1746
1986
  exports.onScopeDispose = onScopeDispose;
1987
+ exports.onWatcherCleanup = onWatcherCleanup;
1747
1988
  exports.pauseTracking = pauseTracking;
1748
1989
  exports.proxyRefs = proxyRefs;
1749
1990
  exports.reactive = reactive;
@@ -1763,9 +2004,11 @@ var VueReactivity = (function (exports) {
1763
2004
  exports.toRefs = toRefs;
1764
2005
  exports.toValue = toValue;
1765
2006
  exports.track = track;
2007
+ exports.traverse = traverse;
1766
2008
  exports.trigger = trigger;
1767
2009
  exports.triggerRef = triggerRef;
1768
2010
  exports.unref = unref;
2011
+ exports.watch = watch;
1769
2012
 
1770
2013
  return exports;
1771
2014