reactivity.esm-bundler.js 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280
  1. import { extend, isArray, isMap, isIntegerKey, hasOwn, isSymbol, isObject, hasChanged, makeMap, capitalize, toRawType, def, isFunction, NOOP } from '@vue/shared';
  2. function warn(msg, ...args) {
  3. console.warn(`[Vue warn] ${msg}`, ...args);
  4. }
  5. let activeEffectScope;
  6. class EffectScope {
  7. constructor(detached = false) {
  8. this.detached = detached;
  9. /**
  10. * @internal
  11. */
  12. this._active = true;
  13. /**
  14. * @internal
  15. */
  16. this.effects = [];
  17. /**
  18. * @internal
  19. */
  20. this.cleanups = [];
  21. this.parent = activeEffectScope;
  22. if (!detached && activeEffectScope) {
  23. this.index =
  24. (activeEffectScope.scopes || (activeEffectScope.scopes = [])).push(this) - 1;
  25. }
  26. }
  27. get active() {
  28. return this._active;
  29. }
  30. run(fn) {
  31. if (this._active) {
  32. const currentEffectScope = activeEffectScope;
  33. try {
  34. activeEffectScope = this;
  35. return fn();
  36. }
  37. finally {
  38. activeEffectScope = currentEffectScope;
  39. }
  40. }
  41. else if ((process.env.NODE_ENV !== 'production')) {
  42. warn(`cannot run an inactive effect scope.`);
  43. }
  44. }
  45. /**
  46. * This should only be called on non-detached scopes
  47. * @internal
  48. */
  49. on() {
  50. activeEffectScope = this;
  51. }
  52. /**
  53. * This should only be called on non-detached scopes
  54. * @internal
  55. */
  56. off() {
  57. activeEffectScope = this.parent;
  58. }
  59. stop(fromParent) {
  60. if (this._active) {
  61. let i, l;
  62. for (i = 0, l = this.effects.length; i < l; i++) {
  63. this.effects[i].stop();
  64. }
  65. for (i = 0, l = this.cleanups.length; i < l; i++) {
  66. this.cleanups[i]();
  67. }
  68. if (this.scopes) {
  69. for (i = 0, l = this.scopes.length; i < l; i++) {
  70. this.scopes[i].stop(true);
  71. }
  72. }
  73. // nested scope, dereference from parent to avoid memory leaks
  74. if (!this.detached && this.parent && !fromParent) {
  75. // optimized O(1) removal
  76. const last = this.parent.scopes.pop();
  77. if (last && last !== this) {
  78. this.parent.scopes[this.index] = last;
  79. last.index = this.index;
  80. }
  81. }
  82. this.parent = undefined;
  83. this._active = false;
  84. }
  85. }
  86. }
  87. function effectScope(detached) {
  88. return new EffectScope(detached);
  89. }
  90. function recordEffectScope(effect, scope = activeEffectScope) {
  91. if (scope && scope.active) {
  92. scope.effects.push(effect);
  93. }
  94. }
  95. function getCurrentScope() {
  96. return activeEffectScope;
  97. }
  98. function onScopeDispose(fn) {
  99. if (activeEffectScope) {
  100. activeEffectScope.cleanups.push(fn);
  101. }
  102. else if ((process.env.NODE_ENV !== 'production')) {
  103. warn(`onScopeDispose() is called when there is no active effect scope` +
  104. ` to be associated with.`);
  105. }
  106. }
  107. const createDep = (effects) => {
  108. const dep = new Set(effects);
  109. dep.w = 0;
  110. dep.n = 0;
  111. return dep;
  112. };
  113. const wasTracked = (dep) => (dep.w & trackOpBit) > 0;
  114. const newTracked = (dep) => (dep.n & trackOpBit) > 0;
  115. const initDepMarkers = ({ deps }) => {
  116. if (deps.length) {
  117. for (let i = 0; i < deps.length; i++) {
  118. deps[i].w |= trackOpBit; // set was tracked
  119. }
  120. }
  121. };
  122. const finalizeDepMarkers = (effect) => {
  123. const { deps } = effect;
  124. if (deps.length) {
  125. let ptr = 0;
  126. for (let i = 0; i < deps.length; i++) {
  127. const dep = deps[i];
  128. if (wasTracked(dep) && !newTracked(dep)) {
  129. dep.delete(effect);
  130. }
  131. else {
  132. deps[ptr++] = dep;
  133. }
  134. // clear bits
  135. dep.w &= ~trackOpBit;
  136. dep.n &= ~trackOpBit;
  137. }
  138. deps.length = ptr;
  139. }
  140. };
  141. const targetMap = new WeakMap();
  142. // The number of effects currently being tracked recursively.
  143. let effectTrackDepth = 0;
  144. let trackOpBit = 1;
  145. /**
  146. * The bitwise track markers support at most 30 levels of recursion.
  147. * This value is chosen to enable modern JS engines to use a SMI on all platforms.
  148. * When recursion depth is greater, fall back to using a full cleanup.
  149. */
  150. const maxMarkerBits = 30;
  151. let activeEffect;
  152. const ITERATE_KEY = Symbol((process.env.NODE_ENV !== 'production') ? 'iterate' : '');
  153. const MAP_KEY_ITERATE_KEY = Symbol((process.env.NODE_ENV !== 'production') ? 'Map key iterate' : '');
  154. class ReactiveEffect {
  155. constructor(fn, scheduler = null, scope) {
  156. this.fn = fn;
  157. this.scheduler = scheduler;
  158. this.active = true;
  159. this.deps = [];
  160. this.parent = undefined;
  161. recordEffectScope(this, scope);
  162. }
  163. run() {
  164. if (!this.active) {
  165. return this.fn();
  166. }
  167. let parent = activeEffect;
  168. let lastShouldTrack = shouldTrack;
  169. while (parent) {
  170. if (parent === this) {
  171. return;
  172. }
  173. parent = parent.parent;
  174. }
  175. try {
  176. this.parent = activeEffect;
  177. activeEffect = this;
  178. shouldTrack = true;
  179. trackOpBit = 1 << ++effectTrackDepth;
  180. if (effectTrackDepth <= maxMarkerBits) {
  181. initDepMarkers(this);
  182. }
  183. else {
  184. cleanupEffect(this);
  185. }
  186. return this.fn();
  187. }
  188. finally {
  189. if (effectTrackDepth <= maxMarkerBits) {
  190. finalizeDepMarkers(this);
  191. }
  192. trackOpBit = 1 << --effectTrackDepth;
  193. activeEffect = this.parent;
  194. shouldTrack = lastShouldTrack;
  195. this.parent = undefined;
  196. if (this.deferStop) {
  197. this.stop();
  198. }
  199. }
  200. }
  201. stop() {
  202. // stopped while running itself - defer the cleanup
  203. if (activeEffect === this) {
  204. this.deferStop = true;
  205. }
  206. else if (this.active) {
  207. cleanupEffect(this);
  208. if (this.onStop) {
  209. this.onStop();
  210. }
  211. this.active = false;
  212. }
  213. }
  214. }
  215. function cleanupEffect(effect) {
  216. const { deps } = effect;
  217. if (deps.length) {
  218. for (let i = 0; i < deps.length; i++) {
  219. deps[i].delete(effect);
  220. }
  221. deps.length = 0;
  222. }
  223. }
  224. function effect(fn, options) {
  225. if (fn.effect) {
  226. fn = fn.effect.fn;
  227. }
  228. const _effect = new ReactiveEffect(fn);
  229. if (options) {
  230. extend(_effect, options);
  231. if (options.scope)
  232. recordEffectScope(_effect, options.scope);
  233. }
  234. if (!options || !options.lazy) {
  235. _effect.run();
  236. }
  237. const runner = _effect.run.bind(_effect);
  238. runner.effect = _effect;
  239. return runner;
  240. }
  241. function stop(runner) {
  242. runner.effect.stop();
  243. }
  244. let shouldTrack = true;
  245. const trackStack = [];
  246. function pauseTracking() {
  247. trackStack.push(shouldTrack);
  248. shouldTrack = false;
  249. }
  250. function enableTracking() {
  251. trackStack.push(shouldTrack);
  252. shouldTrack = true;
  253. }
  254. function resetTracking() {
  255. const last = trackStack.pop();
  256. shouldTrack = last === undefined ? true : last;
  257. }
  258. function track(target, type, key) {
  259. if (shouldTrack && activeEffect) {
  260. let depsMap = targetMap.get(target);
  261. if (!depsMap) {
  262. targetMap.set(target, (depsMap = new Map()));
  263. }
  264. let dep = depsMap.get(key);
  265. if (!dep) {
  266. depsMap.set(key, (dep = createDep()));
  267. }
  268. const eventInfo = (process.env.NODE_ENV !== 'production')
  269. ? { effect: activeEffect, target, type, key }
  270. : undefined;
  271. trackEffects(dep, eventInfo);
  272. }
  273. }
  274. function trackEffects(dep, debuggerEventExtraInfo) {
  275. let shouldTrack = false;
  276. if (effectTrackDepth <= maxMarkerBits) {
  277. if (!newTracked(dep)) {
  278. dep.n |= trackOpBit; // set newly tracked
  279. shouldTrack = !wasTracked(dep);
  280. }
  281. }
  282. else {
  283. // Full cleanup mode.
  284. shouldTrack = !dep.has(activeEffect);
  285. }
  286. if (shouldTrack) {
  287. dep.add(activeEffect);
  288. activeEffect.deps.push(dep);
  289. if ((process.env.NODE_ENV !== 'production') && activeEffect.onTrack) {
  290. activeEffect.onTrack(Object.assign({ effect: activeEffect }, debuggerEventExtraInfo));
  291. }
  292. }
  293. }
  294. function trigger(target, type, key, newValue, oldValue, oldTarget) {
  295. const depsMap = targetMap.get(target);
  296. if (!depsMap) {
  297. // never been tracked
  298. return;
  299. }
  300. let deps = [];
  301. if (type === "clear" /* TriggerOpTypes.CLEAR */) {
  302. // collection being cleared
  303. // trigger all effects for target
  304. deps = [...depsMap.values()];
  305. }
  306. else if (key === 'length' && isArray(target)) {
  307. const newLength = Number(newValue);
  308. depsMap.forEach((dep, key) => {
  309. if (key === 'length' || key >= newLength) {
  310. deps.push(dep);
  311. }
  312. });
  313. }
  314. else {
  315. // schedule runs for SET | ADD | DELETE
  316. if (key !== void 0) {
  317. deps.push(depsMap.get(key));
  318. }
  319. // also run for iteration key on ADD | DELETE | Map.SET
  320. switch (type) {
  321. case "add" /* TriggerOpTypes.ADD */:
  322. if (!isArray(target)) {
  323. deps.push(depsMap.get(ITERATE_KEY));
  324. if (isMap(target)) {
  325. deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
  326. }
  327. }
  328. else if (isIntegerKey(key)) {
  329. // new index added to array -> length changes
  330. deps.push(depsMap.get('length'));
  331. }
  332. break;
  333. case "delete" /* TriggerOpTypes.DELETE */:
  334. if (!isArray(target)) {
  335. deps.push(depsMap.get(ITERATE_KEY));
  336. if (isMap(target)) {
  337. deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
  338. }
  339. }
  340. break;
  341. case "set" /* TriggerOpTypes.SET */:
  342. if (isMap(target)) {
  343. deps.push(depsMap.get(ITERATE_KEY));
  344. }
  345. break;
  346. }
  347. }
  348. const eventInfo = (process.env.NODE_ENV !== 'production')
  349. ? { target, type, key, newValue, oldValue, oldTarget }
  350. : undefined;
  351. if (deps.length === 1) {
  352. if (deps[0]) {
  353. if ((process.env.NODE_ENV !== 'production')) {
  354. triggerEffects(deps[0], eventInfo);
  355. }
  356. else {
  357. triggerEffects(deps[0]);
  358. }
  359. }
  360. }
  361. else {
  362. const effects = [];
  363. for (const dep of deps) {
  364. if (dep) {
  365. effects.push(...dep);
  366. }
  367. }
  368. if ((process.env.NODE_ENV !== 'production')) {
  369. triggerEffects(createDep(effects), eventInfo);
  370. }
  371. else {
  372. triggerEffects(createDep(effects));
  373. }
  374. }
  375. }
  376. function triggerEffects(dep, debuggerEventExtraInfo) {
  377. // spread into array for stabilization
  378. const effects = isArray(dep) ? dep : [...dep];
  379. for (const effect of effects) {
  380. if (effect.computed) {
  381. triggerEffect(effect, debuggerEventExtraInfo);
  382. }
  383. }
  384. for (const effect of effects) {
  385. if (!effect.computed) {
  386. triggerEffect(effect, debuggerEventExtraInfo);
  387. }
  388. }
  389. }
  390. function triggerEffect(effect, debuggerEventExtraInfo) {
  391. if (effect !== activeEffect || effect.allowRecurse) {
  392. if ((process.env.NODE_ENV !== 'production') && effect.onTrigger) {
  393. effect.onTrigger(extend({ effect }, debuggerEventExtraInfo));
  394. }
  395. if (effect.scheduler) {
  396. effect.scheduler();
  397. }
  398. else {
  399. effect.run();
  400. }
  401. }
  402. }
  403. function getDepFromReactive(object, key) {
  404. var _a;
  405. return (_a = targetMap.get(object)) === null || _a === void 0 ? void 0 : _a.get(key);
  406. }
  407. const isNonTrackableKeys = /*#__PURE__*/ makeMap(`__proto__,__v_isRef,__isVue`);
  408. const builtInSymbols = new Set(
  409. /*#__PURE__*/
  410. Object.getOwnPropertyNames(Symbol)
  411. // ios10.x Object.getOwnPropertyNames(Symbol) can enumerate 'arguments' and 'caller'
  412. // but accessing them on Symbol leads to TypeError because Symbol is a strict mode
  413. // function
  414. .filter(key => key !== 'arguments' && key !== 'caller')
  415. .map(key => Symbol[key])
  416. .filter(isSymbol));
  417. const get$1 = /*#__PURE__*/ createGetter();
  418. const shallowGet = /*#__PURE__*/ createGetter(false, true);
  419. const readonlyGet = /*#__PURE__*/ createGetter(true);
  420. const shallowReadonlyGet = /*#__PURE__*/ createGetter(true, true);
  421. const arrayInstrumentations = /*#__PURE__*/ createArrayInstrumentations();
  422. function createArrayInstrumentations() {
  423. const instrumentations = {};
  424. ['includes', 'indexOf', 'lastIndexOf'].forEach(key => {
  425. instrumentations[key] = function (...args) {
  426. const arr = toRaw(this);
  427. for (let i = 0, l = this.length; i < l; i++) {
  428. track(arr, "get" /* TrackOpTypes.GET */, i + '');
  429. }
  430. // we run the method using the original args first (which may be reactive)
  431. const res = arr[key](...args);
  432. if (res === -1 || res === false) {
  433. // if that didn't work, run it again using raw values.
  434. return arr[key](...args.map(toRaw));
  435. }
  436. else {
  437. return res;
  438. }
  439. };
  440. });
  441. ['push', 'pop', 'shift', 'unshift', 'splice'].forEach(key => {
  442. instrumentations[key] = function (...args) {
  443. pauseTracking();
  444. const res = toRaw(this)[key].apply(this, args);
  445. resetTracking();
  446. return res;
  447. };
  448. });
  449. return instrumentations;
  450. }
  451. function hasOwnProperty(key) {
  452. const obj = toRaw(this);
  453. track(obj, "has" /* TrackOpTypes.HAS */, key);
  454. return obj.hasOwnProperty(key);
  455. }
  456. function createGetter(isReadonly = false, shallow = false) {
  457. return function get(target, key, receiver) {
  458. if (key === "__v_isReactive" /* ReactiveFlags.IS_REACTIVE */) {
  459. return !isReadonly;
  460. }
  461. else if (key === "__v_isReadonly" /* ReactiveFlags.IS_READONLY */) {
  462. return isReadonly;
  463. }
  464. else if (key === "__v_isShallow" /* ReactiveFlags.IS_SHALLOW */) {
  465. return shallow;
  466. }
  467. else if (key === "__v_raw" /* ReactiveFlags.RAW */ &&
  468. receiver ===
  469. (isReadonly
  470. ? shallow
  471. ? shallowReadonlyMap
  472. : readonlyMap
  473. : shallow
  474. ? shallowReactiveMap
  475. : reactiveMap).get(target)) {
  476. return target;
  477. }
  478. const targetIsArray = isArray(target);
  479. if (!isReadonly) {
  480. if (targetIsArray && hasOwn(arrayInstrumentations, key)) {
  481. return Reflect.get(arrayInstrumentations, key, receiver);
  482. }
  483. if (key === 'hasOwnProperty') {
  484. return hasOwnProperty;
  485. }
  486. }
  487. const res = Reflect.get(target, key, receiver);
  488. if (isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) {
  489. return res;
  490. }
  491. if (!isReadonly) {
  492. track(target, "get" /* TrackOpTypes.GET */, key);
  493. }
  494. if (shallow) {
  495. return res;
  496. }
  497. if (isRef(res)) {
  498. // ref unwrapping - skip unwrap for Array + integer key.
  499. return targetIsArray && isIntegerKey(key) ? res : res.value;
  500. }
  501. if (isObject(res)) {
  502. // Convert returned value into a proxy as well. we do the isObject check
  503. // here to avoid invalid value warning. Also need to lazy access readonly
  504. // and reactive here to avoid circular dependency.
  505. return isReadonly ? readonly(res) : reactive(res);
  506. }
  507. return res;
  508. };
  509. }
  510. const set$1 = /*#__PURE__*/ createSetter();
  511. const shallowSet = /*#__PURE__*/ createSetter(true);
  512. function createSetter(shallow = false) {
  513. return function set(target, key, value, receiver) {
  514. let oldValue = target[key];
  515. if (isReadonly(oldValue) && isRef(oldValue) && !isRef(value)) {
  516. return false;
  517. }
  518. if (!shallow) {
  519. if (!isShallow(value) && !isReadonly(value)) {
  520. oldValue = toRaw(oldValue);
  521. value = toRaw(value);
  522. }
  523. if (!isArray(target) && isRef(oldValue) && !isRef(value)) {
  524. oldValue.value = value;
  525. return true;
  526. }
  527. }
  528. const hadKey = isArray(target) && isIntegerKey(key)
  529. ? Number(key) < target.length
  530. : hasOwn(target, key);
  531. const result = Reflect.set(target, key, value, receiver);
  532. // don't trigger if target is something up in the prototype chain of original
  533. if (target === toRaw(receiver)) {
  534. if (!hadKey) {
  535. trigger(target, "add" /* TriggerOpTypes.ADD */, key, value);
  536. }
  537. else if (hasChanged(value, oldValue)) {
  538. trigger(target, "set" /* TriggerOpTypes.SET */, key, value, oldValue);
  539. }
  540. }
  541. return result;
  542. };
  543. }
  544. function deleteProperty(target, key) {
  545. const hadKey = hasOwn(target, key);
  546. const oldValue = target[key];
  547. const result = Reflect.deleteProperty(target, key);
  548. if (result && hadKey) {
  549. trigger(target, "delete" /* TriggerOpTypes.DELETE */, key, undefined, oldValue);
  550. }
  551. return result;
  552. }
  553. function has$1(target, key) {
  554. const result = Reflect.has(target, key);
  555. if (!isSymbol(key) || !builtInSymbols.has(key)) {
  556. track(target, "has" /* TrackOpTypes.HAS */, key);
  557. }
  558. return result;
  559. }
  560. function ownKeys(target) {
  561. track(target, "iterate" /* TrackOpTypes.ITERATE */, isArray(target) ? 'length' : ITERATE_KEY);
  562. return Reflect.ownKeys(target);
  563. }
  564. const mutableHandlers = {
  565. get: get$1,
  566. set: set$1,
  567. deleteProperty,
  568. has: has$1,
  569. ownKeys
  570. };
  571. const readonlyHandlers = {
  572. get: readonlyGet,
  573. set(target, key) {
  574. if ((process.env.NODE_ENV !== 'production')) {
  575. warn(`Set operation on key "${String(key)}" failed: target is readonly.`, target);
  576. }
  577. return true;
  578. },
  579. deleteProperty(target, key) {
  580. if ((process.env.NODE_ENV !== 'production')) {
  581. warn(`Delete operation on key "${String(key)}" failed: target is readonly.`, target);
  582. }
  583. return true;
  584. }
  585. };
  586. const shallowReactiveHandlers = /*#__PURE__*/ extend({}, mutableHandlers, {
  587. get: shallowGet,
  588. set: shallowSet
  589. });
  590. // Props handlers are special in the sense that it should not unwrap top-level
  591. // refs (in order to allow refs to be explicitly passed down), but should
  592. // retain the reactivity of the normal readonly object.
  593. const shallowReadonlyHandlers = /*#__PURE__*/ extend({}, readonlyHandlers, {
  594. get: shallowReadonlyGet
  595. });
  596. const toShallow = (value) => value;
  597. const getProto = (v) => Reflect.getPrototypeOf(v);
  598. function get(target, key, isReadonly = false, isShallow = false) {
  599. // #1772: readonly(reactive(Map)) should return readonly + reactive version
  600. // of the value
  601. target = target["__v_raw" /* ReactiveFlags.RAW */];
  602. const rawTarget = toRaw(target);
  603. const rawKey = toRaw(key);
  604. if (!isReadonly) {
  605. if (key !== rawKey) {
  606. track(rawTarget, "get" /* TrackOpTypes.GET */, key);
  607. }
  608. track(rawTarget, "get" /* TrackOpTypes.GET */, rawKey);
  609. }
  610. const { has } = getProto(rawTarget);
  611. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  612. if (has.call(rawTarget, key)) {
  613. return wrap(target.get(key));
  614. }
  615. else if (has.call(rawTarget, rawKey)) {
  616. return wrap(target.get(rawKey));
  617. }
  618. else if (target !== rawTarget) {
  619. // #3602 readonly(reactive(Map))
  620. // ensure that the nested reactive `Map` can do tracking for itself
  621. target.get(key);
  622. }
  623. }
  624. function has(key, isReadonly = false) {
  625. const target = this["__v_raw" /* ReactiveFlags.RAW */];
  626. const rawTarget = toRaw(target);
  627. const rawKey = toRaw(key);
  628. if (!isReadonly) {
  629. if (key !== rawKey) {
  630. track(rawTarget, "has" /* TrackOpTypes.HAS */, key);
  631. }
  632. track(rawTarget, "has" /* TrackOpTypes.HAS */, rawKey);
  633. }
  634. return key === rawKey
  635. ? target.has(key)
  636. : target.has(key) || target.has(rawKey);
  637. }
  638. function size(target, isReadonly = false) {
  639. target = target["__v_raw" /* ReactiveFlags.RAW */];
  640. !isReadonly && track(toRaw(target), "iterate" /* TrackOpTypes.ITERATE */, ITERATE_KEY);
  641. return Reflect.get(target, 'size', target);
  642. }
  643. function add(value) {
  644. value = toRaw(value);
  645. const target = toRaw(this);
  646. const proto = getProto(target);
  647. const hadKey = proto.has.call(target, value);
  648. if (!hadKey) {
  649. target.add(value);
  650. trigger(target, "add" /* TriggerOpTypes.ADD */, value, value);
  651. }
  652. return this;
  653. }
  654. function set(key, value) {
  655. value = toRaw(value);
  656. const target = toRaw(this);
  657. const { has, get } = getProto(target);
  658. let hadKey = has.call(target, key);
  659. if (!hadKey) {
  660. key = toRaw(key);
  661. hadKey = has.call(target, key);
  662. }
  663. else if ((process.env.NODE_ENV !== 'production')) {
  664. checkIdentityKeys(target, has, key);
  665. }
  666. const oldValue = get.call(target, key);
  667. target.set(key, value);
  668. if (!hadKey) {
  669. trigger(target, "add" /* TriggerOpTypes.ADD */, key, value);
  670. }
  671. else if (hasChanged(value, oldValue)) {
  672. trigger(target, "set" /* TriggerOpTypes.SET */, key, value, oldValue);
  673. }
  674. return this;
  675. }
  676. function deleteEntry(key) {
  677. const target = toRaw(this);
  678. const { has, get } = getProto(target);
  679. let hadKey = has.call(target, key);
  680. if (!hadKey) {
  681. key = toRaw(key);
  682. hadKey = has.call(target, key);
  683. }
  684. else if ((process.env.NODE_ENV !== 'production')) {
  685. checkIdentityKeys(target, has, key);
  686. }
  687. const oldValue = get ? get.call(target, key) : undefined;
  688. // forward the operation before queueing reactions
  689. const result = target.delete(key);
  690. if (hadKey) {
  691. trigger(target, "delete" /* TriggerOpTypes.DELETE */, key, undefined, oldValue);
  692. }
  693. return result;
  694. }
  695. function clear() {
  696. const target = toRaw(this);
  697. const hadItems = target.size !== 0;
  698. const oldTarget = (process.env.NODE_ENV !== 'production')
  699. ? isMap(target)
  700. ? new Map(target)
  701. : new Set(target)
  702. : undefined;
  703. // forward the operation before queueing reactions
  704. const result = target.clear();
  705. if (hadItems) {
  706. trigger(target, "clear" /* TriggerOpTypes.CLEAR */, undefined, undefined, oldTarget);
  707. }
  708. return result;
  709. }
  710. function createForEach(isReadonly, isShallow) {
  711. return function forEach(callback, thisArg) {
  712. const observed = this;
  713. const target = observed["__v_raw" /* ReactiveFlags.RAW */];
  714. const rawTarget = toRaw(target);
  715. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  716. !isReadonly && track(rawTarget, "iterate" /* TrackOpTypes.ITERATE */, ITERATE_KEY);
  717. return target.forEach((value, key) => {
  718. // important: make sure the callback is
  719. // 1. invoked with the reactive map as `this` and 3rd arg
  720. // 2. the value received should be a corresponding reactive/readonly.
  721. return callback.call(thisArg, wrap(value), wrap(key), observed);
  722. });
  723. };
  724. }
  725. function createIterableMethod(method, isReadonly, isShallow) {
  726. return function (...args) {
  727. const target = this["__v_raw" /* ReactiveFlags.RAW */];
  728. const rawTarget = toRaw(target);
  729. const targetIsMap = isMap(rawTarget);
  730. const isPair = method === 'entries' || (method === Symbol.iterator && targetIsMap);
  731. const isKeyOnly = method === 'keys' && targetIsMap;
  732. const innerIterator = target[method](...args);
  733. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  734. !isReadonly &&
  735. track(rawTarget, "iterate" /* TrackOpTypes.ITERATE */, isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY);
  736. // return a wrapped iterator which returns observed versions of the
  737. // values emitted from the real iterator
  738. return {
  739. // iterator protocol
  740. next() {
  741. const { value, done } = innerIterator.next();
  742. return done
  743. ? { value, done }
  744. : {
  745. value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
  746. done
  747. };
  748. },
  749. // iterable protocol
  750. [Symbol.iterator]() {
  751. return this;
  752. }
  753. };
  754. };
  755. }
  756. function createReadonlyMethod(type) {
  757. return function (...args) {
  758. if ((process.env.NODE_ENV !== 'production')) {
  759. const key = args[0] ? `on key "${args[0]}" ` : ``;
  760. console.warn(`${capitalize(type)} operation ${key}failed: target is readonly.`, toRaw(this));
  761. }
  762. return type === "delete" /* TriggerOpTypes.DELETE */ ? false : this;
  763. };
  764. }
  765. function createInstrumentations() {
  766. const mutableInstrumentations = {
  767. get(key) {
  768. return get(this, key);
  769. },
  770. get size() {
  771. return size(this);
  772. },
  773. has,
  774. add,
  775. set,
  776. delete: deleteEntry,
  777. clear,
  778. forEach: createForEach(false, false)
  779. };
  780. const shallowInstrumentations = {
  781. get(key) {
  782. return get(this, key, false, true);
  783. },
  784. get size() {
  785. return size(this);
  786. },
  787. has,
  788. add,
  789. set,
  790. delete: deleteEntry,
  791. clear,
  792. forEach: createForEach(false, true)
  793. };
  794. const readonlyInstrumentations = {
  795. get(key) {
  796. return get(this, key, true);
  797. },
  798. get size() {
  799. return size(this, true);
  800. },
  801. has(key) {
  802. return has.call(this, key, true);
  803. },
  804. add: createReadonlyMethod("add" /* TriggerOpTypes.ADD */),
  805. set: createReadonlyMethod("set" /* TriggerOpTypes.SET */),
  806. delete: createReadonlyMethod("delete" /* TriggerOpTypes.DELETE */),
  807. clear: createReadonlyMethod("clear" /* TriggerOpTypes.CLEAR */),
  808. forEach: createForEach(true, false)
  809. };
  810. const shallowReadonlyInstrumentations = {
  811. get(key) {
  812. return get(this, key, true, true);
  813. },
  814. get size() {
  815. return size(this, true);
  816. },
  817. has(key) {
  818. return has.call(this, key, true);
  819. },
  820. add: createReadonlyMethod("add" /* TriggerOpTypes.ADD */),
  821. set: createReadonlyMethod("set" /* TriggerOpTypes.SET */),
  822. delete: createReadonlyMethod("delete" /* TriggerOpTypes.DELETE */),
  823. clear: createReadonlyMethod("clear" /* TriggerOpTypes.CLEAR */),
  824. forEach: createForEach(true, true)
  825. };
  826. const iteratorMethods = ['keys', 'values', 'entries', Symbol.iterator];
  827. iteratorMethods.forEach(method => {
  828. mutableInstrumentations[method] = createIterableMethod(method, false, false);
  829. readonlyInstrumentations[method] = createIterableMethod(method, true, false);
  830. shallowInstrumentations[method] = createIterableMethod(method, false, true);
  831. shallowReadonlyInstrumentations[method] = createIterableMethod(method, true, true);
  832. });
  833. return [
  834. mutableInstrumentations,
  835. readonlyInstrumentations,
  836. shallowInstrumentations,
  837. shallowReadonlyInstrumentations
  838. ];
  839. }
  840. const [mutableInstrumentations, readonlyInstrumentations, shallowInstrumentations, shallowReadonlyInstrumentations] = /* #__PURE__*/ createInstrumentations();
  841. function createInstrumentationGetter(isReadonly, shallow) {
  842. const instrumentations = shallow
  843. ? isReadonly
  844. ? shallowReadonlyInstrumentations
  845. : shallowInstrumentations
  846. : isReadonly
  847. ? readonlyInstrumentations
  848. : mutableInstrumentations;
  849. return (target, key, receiver) => {
  850. if (key === "__v_isReactive" /* ReactiveFlags.IS_REACTIVE */) {
  851. return !isReadonly;
  852. }
  853. else if (key === "__v_isReadonly" /* ReactiveFlags.IS_READONLY */) {
  854. return isReadonly;
  855. }
  856. else if (key === "__v_raw" /* ReactiveFlags.RAW */) {
  857. return target;
  858. }
  859. return Reflect.get(hasOwn(instrumentations, key) && key in target
  860. ? instrumentations
  861. : target, key, receiver);
  862. };
  863. }
  864. const mutableCollectionHandlers = {
  865. get: /*#__PURE__*/ createInstrumentationGetter(false, false)
  866. };
  867. const shallowCollectionHandlers = {
  868. get: /*#__PURE__*/ createInstrumentationGetter(false, true)
  869. };
  870. const readonlyCollectionHandlers = {
  871. get: /*#__PURE__*/ createInstrumentationGetter(true, false)
  872. };
  873. const shallowReadonlyCollectionHandlers = {
  874. get: /*#__PURE__*/ createInstrumentationGetter(true, true)
  875. };
  876. function checkIdentityKeys(target, has, key) {
  877. const rawKey = toRaw(key);
  878. if (rawKey !== key && has.call(target, rawKey)) {
  879. const type = toRawType(target);
  880. console.warn(`Reactive ${type} contains both the raw and reactive ` +
  881. `versions of the same object${type === `Map` ? ` as keys` : ``}, ` +
  882. `which can lead to inconsistencies. ` +
  883. `Avoid differentiating between the raw and reactive versions ` +
  884. `of an object and only use the reactive version if possible.`);
  885. }
  886. }
  887. const reactiveMap = new WeakMap();
  888. const shallowReactiveMap = new WeakMap();
  889. const readonlyMap = new WeakMap();
  890. const shallowReadonlyMap = new WeakMap();
  891. function targetTypeMap(rawType) {
  892. switch (rawType) {
  893. case 'Object':
  894. case 'Array':
  895. return 1 /* TargetType.COMMON */;
  896. case 'Map':
  897. case 'Set':
  898. case 'WeakMap':
  899. case 'WeakSet':
  900. return 2 /* TargetType.COLLECTION */;
  901. default:
  902. return 0 /* TargetType.INVALID */;
  903. }
  904. }
  905. function getTargetType(value) {
  906. return value["__v_skip" /* ReactiveFlags.SKIP */] || !Object.isExtensible(value)
  907. ? 0 /* TargetType.INVALID */
  908. : targetTypeMap(toRawType(value));
  909. }
  910. function reactive(target) {
  911. // if trying to observe a readonly proxy, return the readonly version.
  912. if (isReadonly(target)) {
  913. return target;
  914. }
  915. return createReactiveObject(target, false, mutableHandlers, mutableCollectionHandlers, reactiveMap);
  916. }
  917. /**
  918. * Return a shallowly-reactive copy of the original object, where only the root
  919. * level properties are reactive. It also does not auto-unwrap refs (even at the
  920. * root level).
  921. */
  922. function shallowReactive(target) {
  923. return createReactiveObject(target, false, shallowReactiveHandlers, shallowCollectionHandlers, shallowReactiveMap);
  924. }
  925. /**
  926. * Creates a readonly copy of the original object. Note the returned copy is not
  927. * made reactive, but `readonly` can be called on an already reactive object.
  928. */
  929. function readonly(target) {
  930. return createReactiveObject(target, true, readonlyHandlers, readonlyCollectionHandlers, readonlyMap);
  931. }
  932. /**
  933. * Returns a reactive-copy of the original object, where only the root level
  934. * properties are readonly, and does NOT unwrap refs nor recursively convert
  935. * returned properties.
  936. * This is used for creating the props proxy object for stateful components.
  937. */
  938. function shallowReadonly(target) {
  939. return createReactiveObject(target, true, shallowReadonlyHandlers, shallowReadonlyCollectionHandlers, shallowReadonlyMap);
  940. }
  941. function createReactiveObject(target, isReadonly, baseHandlers, collectionHandlers, proxyMap) {
  942. if (!isObject(target)) {
  943. if ((process.env.NODE_ENV !== 'production')) {
  944. console.warn(`value cannot be made reactive: ${String(target)}`);
  945. }
  946. return target;
  947. }
  948. // target is already a Proxy, return it.
  949. // exception: calling readonly() on a reactive object
  950. if (target["__v_raw" /* ReactiveFlags.RAW */] &&
  951. !(isReadonly && target["__v_isReactive" /* ReactiveFlags.IS_REACTIVE */])) {
  952. return target;
  953. }
  954. // target already has corresponding Proxy
  955. const existingProxy = proxyMap.get(target);
  956. if (existingProxy) {
  957. return existingProxy;
  958. }
  959. // only specific value types can be observed.
  960. const targetType = getTargetType(target);
  961. if (targetType === 0 /* TargetType.INVALID */) {
  962. return target;
  963. }
  964. const proxy = new Proxy(target, targetType === 2 /* TargetType.COLLECTION */ ? collectionHandlers : baseHandlers);
  965. proxyMap.set(target, proxy);
  966. return proxy;
  967. }
  968. function isReactive(value) {
  969. if (isReadonly(value)) {
  970. return isReactive(value["__v_raw" /* ReactiveFlags.RAW */]);
  971. }
  972. return !!(value && value["__v_isReactive" /* ReactiveFlags.IS_REACTIVE */]);
  973. }
  974. function isReadonly(value) {
  975. return !!(value && value["__v_isReadonly" /* ReactiveFlags.IS_READONLY */]);
  976. }
  977. function isShallow(value) {
  978. return !!(value && value["__v_isShallow" /* ReactiveFlags.IS_SHALLOW */]);
  979. }
  980. function isProxy(value) {
  981. return isReactive(value) || isReadonly(value);
  982. }
  983. function toRaw(observed) {
  984. const raw = observed && observed["__v_raw" /* ReactiveFlags.RAW */];
  985. return raw ? toRaw(raw) : observed;
  986. }
  987. function markRaw(value) {
  988. def(value, "__v_skip" /* ReactiveFlags.SKIP */, true);
  989. return value;
  990. }
  991. const toReactive = (value) => isObject(value) ? reactive(value) : value;
  992. const toReadonly = (value) => isObject(value) ? readonly(value) : value;
  993. function trackRefValue(ref) {
  994. if (shouldTrack && activeEffect) {
  995. ref = toRaw(ref);
  996. if ((process.env.NODE_ENV !== 'production')) {
  997. trackEffects(ref.dep || (ref.dep = createDep()), {
  998. target: ref,
  999. type: "get" /* TrackOpTypes.GET */,
  1000. key: 'value'
  1001. });
  1002. }
  1003. else {
  1004. trackEffects(ref.dep || (ref.dep = createDep()));
  1005. }
  1006. }
  1007. }
  1008. function triggerRefValue(ref, newVal) {
  1009. ref = toRaw(ref);
  1010. const dep = ref.dep;
  1011. if (dep) {
  1012. if ((process.env.NODE_ENV !== 'production')) {
  1013. triggerEffects(dep, {
  1014. target: ref,
  1015. type: "set" /* TriggerOpTypes.SET */,
  1016. key: 'value',
  1017. newValue: newVal
  1018. });
  1019. }
  1020. else {
  1021. triggerEffects(dep);
  1022. }
  1023. }
  1024. }
  1025. function isRef(r) {
  1026. return !!(r && r.__v_isRef === true);
  1027. }
  1028. function ref(value) {
  1029. return createRef(value, false);
  1030. }
  1031. function shallowRef(value) {
  1032. return createRef(value, true);
  1033. }
  1034. function createRef(rawValue, shallow) {
  1035. if (isRef(rawValue)) {
  1036. return rawValue;
  1037. }
  1038. return new RefImpl(rawValue, shallow);
  1039. }
  1040. class RefImpl {
  1041. constructor(value, __v_isShallow) {
  1042. this.__v_isShallow = __v_isShallow;
  1043. this.dep = undefined;
  1044. this.__v_isRef = true;
  1045. this._rawValue = __v_isShallow ? value : toRaw(value);
  1046. this._value = __v_isShallow ? value : toReactive(value);
  1047. }
  1048. get value() {
  1049. trackRefValue(this);
  1050. return this._value;
  1051. }
  1052. set value(newVal) {
  1053. const useDirectValue = this.__v_isShallow || isShallow(newVal) || isReadonly(newVal);
  1054. newVal = useDirectValue ? newVal : toRaw(newVal);
  1055. if (hasChanged(newVal, this._rawValue)) {
  1056. this._rawValue = newVal;
  1057. this._value = useDirectValue ? newVal : toReactive(newVal);
  1058. triggerRefValue(this, newVal);
  1059. }
  1060. }
  1061. }
  1062. function triggerRef(ref) {
  1063. triggerRefValue(ref, (process.env.NODE_ENV !== 'production') ? ref.value : void 0);
  1064. }
  1065. function unref(ref) {
  1066. return isRef(ref) ? ref.value : ref;
  1067. }
  1068. const shallowUnwrapHandlers = {
  1069. get: (target, key, receiver) => unref(Reflect.get(target, key, receiver)),
  1070. set: (target, key, value, receiver) => {
  1071. const oldValue = target[key];
  1072. if (isRef(oldValue) && !isRef(value)) {
  1073. oldValue.value = value;
  1074. return true;
  1075. }
  1076. else {
  1077. return Reflect.set(target, key, value, receiver);
  1078. }
  1079. }
  1080. };
  1081. function proxyRefs(objectWithRefs) {
  1082. return isReactive(objectWithRefs)
  1083. ? objectWithRefs
  1084. : new Proxy(objectWithRefs, shallowUnwrapHandlers);
  1085. }
  1086. class CustomRefImpl {
  1087. constructor(factory) {
  1088. this.dep = undefined;
  1089. this.__v_isRef = true;
  1090. const { get, set } = factory(() => trackRefValue(this), () => triggerRefValue(this));
  1091. this._get = get;
  1092. this._set = set;
  1093. }
  1094. get value() {
  1095. return this._get();
  1096. }
  1097. set value(newVal) {
  1098. this._set(newVal);
  1099. }
  1100. }
  1101. function customRef(factory) {
  1102. return new CustomRefImpl(factory);
  1103. }
  1104. function toRefs(object) {
  1105. if ((process.env.NODE_ENV !== 'production') && !isProxy(object)) {
  1106. console.warn(`toRefs() expects a reactive object but received a plain one.`);
  1107. }
  1108. const ret = isArray(object) ? new Array(object.length) : {};
  1109. for (const key in object) {
  1110. ret[key] = toRef(object, key);
  1111. }
  1112. return ret;
  1113. }
  1114. class ObjectRefImpl {
  1115. constructor(_object, _key, _defaultValue) {
  1116. this._object = _object;
  1117. this._key = _key;
  1118. this._defaultValue = _defaultValue;
  1119. this.__v_isRef = true;
  1120. }
  1121. get value() {
  1122. const val = this._object[this._key];
  1123. return val === undefined ? this._defaultValue : val;
  1124. }
  1125. set value(newVal) {
  1126. this._object[this._key] = newVal;
  1127. }
  1128. get dep() {
  1129. return getDepFromReactive(toRaw(this._object), this._key);
  1130. }
  1131. }
  1132. function toRef(object, key, defaultValue) {
  1133. const val = object[key];
  1134. return isRef(val)
  1135. ? val
  1136. : new ObjectRefImpl(object, key, defaultValue);
  1137. }
  1138. var _a$1;
  1139. class ComputedRefImpl {
  1140. constructor(getter, _setter, isReadonly, isSSR) {
  1141. this._setter = _setter;
  1142. this.dep = undefined;
  1143. this.__v_isRef = true;
  1144. this[_a$1] = false;
  1145. this._dirty = true;
  1146. this.effect = new ReactiveEffect(getter, () => {
  1147. if (!this._dirty) {
  1148. this._dirty = true;
  1149. triggerRefValue(this);
  1150. }
  1151. });
  1152. this.effect.computed = this;
  1153. this.effect.active = this._cacheable = !isSSR;
  1154. this["__v_isReadonly" /* ReactiveFlags.IS_READONLY */] = isReadonly;
  1155. }
  1156. get value() {
  1157. // the computed ref may get wrapped by other proxies e.g. readonly() #3376
  1158. const self = toRaw(this);
  1159. trackRefValue(self);
  1160. if (self._dirty || !self._cacheable) {
  1161. self._dirty = false;
  1162. self._value = self.effect.run();
  1163. }
  1164. return self._value;
  1165. }
  1166. set value(newValue) {
  1167. this._setter(newValue);
  1168. }
  1169. }
  1170. _a$1 = "__v_isReadonly" /* ReactiveFlags.IS_READONLY */;
  1171. function computed(getterOrOptions, debugOptions, isSSR = false) {
  1172. let getter;
  1173. let setter;
  1174. const onlyGetter = isFunction(getterOrOptions);
  1175. if (onlyGetter) {
  1176. getter = getterOrOptions;
  1177. setter = (process.env.NODE_ENV !== 'production')
  1178. ? () => {
  1179. console.warn('Write operation failed: computed value is readonly');
  1180. }
  1181. : NOOP;
  1182. }
  1183. else {
  1184. getter = getterOrOptions.get;
  1185. setter = getterOrOptions.set;
  1186. }
  1187. const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter, isSSR);
  1188. if ((process.env.NODE_ENV !== 'production') && debugOptions && !isSSR) {
  1189. cRef.effect.onTrack = debugOptions.onTrack;
  1190. cRef.effect.onTrigger = debugOptions.onTrigger;
  1191. }
  1192. return cRef;
  1193. }
  1194. var _a;
  1195. const tick = /*#__PURE__*/ Promise.resolve();
  1196. const queue = [];
  1197. let queued = false;
  1198. const scheduler = (fn) => {
  1199. queue.push(fn);
  1200. if (!queued) {
  1201. queued = true;
  1202. tick.then(flush);
  1203. }
  1204. };
  1205. const flush = () => {
  1206. for (let i = 0; i < queue.length; i++) {
  1207. queue[i]();
  1208. }
  1209. queue.length = 0;
  1210. queued = false;
  1211. };
  1212. class DeferredComputedRefImpl {
  1213. constructor(getter) {
  1214. this.dep = undefined;
  1215. this._dirty = true;
  1216. this.__v_isRef = true;
  1217. this[_a] = true;
  1218. let compareTarget;
  1219. let hasCompareTarget = false;
  1220. let scheduled = false;
  1221. this.effect = new ReactiveEffect(getter, (computedTrigger) => {
  1222. if (this.dep) {
  1223. if (computedTrigger) {
  1224. compareTarget = this._value;
  1225. hasCompareTarget = true;
  1226. }
  1227. else if (!scheduled) {
  1228. const valueToCompare = hasCompareTarget ? compareTarget : this._value;
  1229. scheduled = true;
  1230. hasCompareTarget = false;
  1231. scheduler(() => {
  1232. if (this.effect.active && this._get() !== valueToCompare) {
  1233. triggerRefValue(this);
  1234. }
  1235. scheduled = false;
  1236. });
  1237. }
  1238. // chained upstream computeds are notified synchronously to ensure
  1239. // value invalidation in case of sync access; normal effects are
  1240. // deferred to be triggered in scheduler.
  1241. for (const e of this.dep) {
  1242. if (e.computed instanceof DeferredComputedRefImpl) {
  1243. e.scheduler(true /* computedTrigger */);
  1244. }
  1245. }
  1246. }
  1247. this._dirty = true;
  1248. });
  1249. this.effect.computed = this;
  1250. }
  1251. _get() {
  1252. if (this._dirty) {
  1253. this._dirty = false;
  1254. return (this._value = this.effect.run());
  1255. }
  1256. return this._value;
  1257. }
  1258. get value() {
  1259. trackRefValue(this);
  1260. // the computed ref may get wrapped by other proxies e.g. readonly() #3376
  1261. return toRaw(this)._get();
  1262. }
  1263. }
  1264. _a = "__v_isReadonly" /* ReactiveFlags.IS_READONLY */;
  1265. function deferredComputed(getter) {
  1266. return new DeferredComputedRefImpl(getter);
  1267. }
  1268. export { EffectScope, ITERATE_KEY, ReactiveEffect, computed, customRef, deferredComputed, effect, effectScope, enableTracking, getCurrentScope, isProxy, isReactive, isReadonly, isRef, isShallow, markRaw, onScopeDispose, pauseTracking, proxyRefs, reactive, readonly, ref, resetTracking, shallowReactive, shallowReadonly, shallowRef, stop, toRaw, toRef, toRefs, track, trigger, triggerRef, unref };