1 | /**
|
---|
2 | * @vue/reactivity v3.5.13
|
---|
3 | * (c) 2018-present Yuxi (Evan) You and Vue contributors
|
---|
4 | * @license MIT
|
---|
5 | **/
|
---|
6 | 'use strict';
|
---|
7 |
|
---|
8 | Object.defineProperty(exports, '__esModule', { value: true });
|
---|
9 |
|
---|
10 | var shared = require('@vue/shared');
|
---|
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
|
---|
22 | */
|
---|
23 | this.effects = [];
|
---|
24 | /**
|
---|
25 | * @internal
|
---|
26 | */
|
---|
27 | this.cleanups = [];
|
---|
28 | this._isPaused = false;
|
---|
29 | this.parent = activeEffectScope;
|
---|
30 | if (!detached && activeEffectScope) {
|
---|
31 | this.index = (activeEffectScope.scopes || (activeEffectScope.scopes = [])).push(
|
---|
32 | this
|
---|
33 | ) - 1;
|
---|
34 | }
|
---|
35 | }
|
---|
36 | get active() {
|
---|
37 | return this._active;
|
---|
38 | }
|
---|
39 | pause() {
|
---|
40 | if (this._active) {
|
---|
41 | this._isPaused = true;
|
---|
42 | let i, l;
|
---|
43 | if (this.scopes) {
|
---|
44 | for (i = 0, l = this.scopes.length; i < l; i++) {
|
---|
45 | this.scopes[i].pause();
|
---|
46 | }
|
---|
47 | }
|
---|
48 | for (i = 0, l = this.effects.length; i < l; i++) {
|
---|
49 | this.effects[i].pause();
|
---|
50 | }
|
---|
51 | }
|
---|
52 | }
|
---|
53 | /**
|
---|
54 | * Resumes the effect scope, including all child scopes and effects.
|
---|
55 | */
|
---|
56 | resume() {
|
---|
57 | if (this._active) {
|
---|
58 | if (this._isPaused) {
|
---|
59 | this._isPaused = false;
|
---|
60 | let i, l;
|
---|
61 | if (this.scopes) {
|
---|
62 | for (i = 0, l = this.scopes.length; i < l; i++) {
|
---|
63 | this.scopes[i].resume();
|
---|
64 | }
|
---|
65 | }
|
---|
66 | for (i = 0, l = this.effects.length; i < l; i++) {
|
---|
67 | this.effects[i].resume();
|
---|
68 | }
|
---|
69 | }
|
---|
70 | }
|
---|
71 | }
|
---|
72 | run(fn) {
|
---|
73 | if (this._active) {
|
---|
74 | const currentEffectScope = activeEffectScope;
|
---|
75 | try {
|
---|
76 | activeEffectScope = this;
|
---|
77 | return fn();
|
---|
78 | } finally {
|
---|
79 | activeEffectScope = currentEffectScope;
|
---|
80 | }
|
---|
81 | }
|
---|
82 | }
|
---|
83 | /**
|
---|
84 | * This should only be called on non-detached scopes
|
---|
85 | * @internal
|
---|
86 | */
|
---|
87 | on() {
|
---|
88 | activeEffectScope = this;
|
---|
89 | }
|
---|
90 | /**
|
---|
91 | * This should only be called on non-detached scopes
|
---|
92 | * @internal
|
---|
93 | */
|
---|
94 | off() {
|
---|
95 | activeEffectScope = this.parent;
|
---|
96 | }
|
---|
97 | stop(fromParent) {
|
---|
98 | if (this._active) {
|
---|
99 | this._active = false;
|
---|
100 | let i, l;
|
---|
101 | for (i = 0, l = this.effects.length; i < l; i++) {
|
---|
102 | this.effects[i].stop();
|
---|
103 | }
|
---|
104 | this.effects.length = 0;
|
---|
105 | for (i = 0, l = this.cleanups.length; i < l; i++) {
|
---|
106 | this.cleanups[i]();
|
---|
107 | }
|
---|
108 | this.cleanups.length = 0;
|
---|
109 | if (this.scopes) {
|
---|
110 | for (i = 0, l = this.scopes.length; i < l; i++) {
|
---|
111 | this.scopes[i].stop(true);
|
---|
112 | }
|
---|
113 | this.scopes.length = 0;
|
---|
114 | }
|
---|
115 | if (!this.detached && this.parent && !fromParent) {
|
---|
116 | const last = this.parent.scopes.pop();
|
---|
117 | if (last && last !== this) {
|
---|
118 | this.parent.scopes[this.index] = last;
|
---|
119 | last.index = this.index;
|
---|
120 | }
|
---|
121 | }
|
---|
122 | this.parent = void 0;
|
---|
123 | }
|
---|
124 | }
|
---|
125 | }
|
---|
126 | function effectScope(detached) {
|
---|
127 | return new EffectScope(detached);
|
---|
128 | }
|
---|
129 | function getCurrentScope() {
|
---|
130 | return activeEffectScope;
|
---|
131 | }
|
---|
132 | function onScopeDispose(fn, failSilently = false) {
|
---|
133 | if (activeEffectScope) {
|
---|
134 | activeEffectScope.cleanups.push(fn);
|
---|
135 | }
|
---|
136 | }
|
---|
137 |
|
---|
138 | let activeSub;
|
---|
139 | const EffectFlags = {
|
---|
140 | "ACTIVE": 1,
|
---|
141 | "1": "ACTIVE",
|
---|
142 | "RUNNING": 2,
|
---|
143 | "2": "RUNNING",
|
---|
144 | "TRACKING": 4,
|
---|
145 | "4": "TRACKING",
|
---|
146 | "NOTIFIED": 8,
|
---|
147 | "8": "NOTIFIED",
|
---|
148 | "DIRTY": 16,
|
---|
149 | "16": "DIRTY",
|
---|
150 | "ALLOW_RECURSE": 32,
|
---|
151 | "32": "ALLOW_RECURSE",
|
---|
152 | "PAUSED": 64,
|
---|
153 | "64": "PAUSED"
|
---|
154 | };
|
---|
155 | const pausedQueueEffects = /* @__PURE__ */ new WeakSet();
|
---|
156 | class ReactiveEffect {
|
---|
157 | constructor(fn) {
|
---|
158 | this.fn = fn;
|
---|
159 | /**
|
---|
160 | * @internal
|
---|
161 | */
|
---|
162 | this.deps = void 0;
|
---|
163 | /**
|
---|
164 | * @internal
|
---|
165 | */
|
---|
166 | this.depsTail = void 0;
|
---|
167 | /**
|
---|
168 | * @internal
|
---|
169 | */
|
---|
170 | this.flags = 1 | 4;
|
---|
171 | /**
|
---|
172 | * @internal
|
---|
173 | */
|
---|
174 | this.next = void 0;
|
---|
175 | /**
|
---|
176 | * @internal
|
---|
177 | */
|
---|
178 | this.cleanup = void 0;
|
---|
179 | this.scheduler = void 0;
|
---|
180 | if (activeEffectScope && activeEffectScope.active) {
|
---|
181 | activeEffectScope.effects.push(this);
|
---|
182 | }
|
---|
183 | }
|
---|
184 | pause() {
|
---|
185 | this.flags |= 64;
|
---|
186 | }
|
---|
187 | resume() {
|
---|
188 | if (this.flags & 64) {
|
---|
189 | this.flags &= ~64;
|
---|
190 | if (pausedQueueEffects.has(this)) {
|
---|
191 | pausedQueueEffects.delete(this);
|
---|
192 | this.trigger();
|
---|
193 | }
|
---|
194 | }
|
---|
195 | }
|
---|
196 | /**
|
---|
197 | * @internal
|
---|
198 | */
|
---|
199 | notify() {
|
---|
200 | if (this.flags & 2 && !(this.flags & 32)) {
|
---|
201 | return;
|
---|
202 | }
|
---|
203 | if (!(this.flags & 8)) {
|
---|
204 | batch(this);
|
---|
205 | }
|
---|
206 | }
|
---|
207 | run() {
|
---|
208 | if (!(this.flags & 1)) {
|
---|
209 | return this.fn();
|
---|
210 | }
|
---|
211 | this.flags |= 2;
|
---|
212 | cleanupEffect(this);
|
---|
213 | prepareDeps(this);
|
---|
214 | const prevEffect = activeSub;
|
---|
215 | const prevShouldTrack = shouldTrack;
|
---|
216 | activeSub = this;
|
---|
217 | shouldTrack = true;
|
---|
218 | try {
|
---|
219 | return this.fn();
|
---|
220 | } finally {
|
---|
221 | cleanupDeps(this);
|
---|
222 | activeSub = prevEffect;
|
---|
223 | shouldTrack = prevShouldTrack;
|
---|
224 | this.flags &= ~2;
|
---|
225 | }
|
---|
226 | }
|
---|
227 | stop() {
|
---|
228 | if (this.flags & 1) {
|
---|
229 | for (let link = this.deps; link; link = link.nextDep) {
|
---|
230 | removeSub(link);
|
---|
231 | }
|
---|
232 | this.deps = this.depsTail = void 0;
|
---|
233 | cleanupEffect(this);
|
---|
234 | this.onStop && this.onStop();
|
---|
235 | this.flags &= ~1;
|
---|
236 | }
|
---|
237 | }
|
---|
238 | trigger() {
|
---|
239 | if (this.flags & 64) {
|
---|
240 | pausedQueueEffects.add(this);
|
---|
241 | } else if (this.scheduler) {
|
---|
242 | this.scheduler();
|
---|
243 | } else {
|
---|
244 | this.runIfDirty();
|
---|
245 | }
|
---|
246 | }
|
---|
247 | /**
|
---|
248 | * @internal
|
---|
249 | */
|
---|
250 | runIfDirty() {
|
---|
251 | if (isDirty(this)) {
|
---|
252 | this.run();
|
---|
253 | }
|
---|
254 | }
|
---|
255 | get dirty() {
|
---|
256 | return isDirty(this);
|
---|
257 | }
|
---|
258 | }
|
---|
259 | let batchDepth = 0;
|
---|
260 | let batchedSub;
|
---|
261 | let batchedComputed;
|
---|
262 | function batch(sub, isComputed = false) {
|
---|
263 | sub.flags |= 8;
|
---|
264 | if (isComputed) {
|
---|
265 | sub.next = batchedComputed;
|
---|
266 | batchedComputed = sub;
|
---|
267 | return;
|
---|
268 | }
|
---|
269 | sub.next = batchedSub;
|
---|
270 | batchedSub = sub;
|
---|
271 | }
|
---|
272 | function startBatch() {
|
---|
273 | batchDepth++;
|
---|
274 | }
|
---|
275 | function endBatch() {
|
---|
276 | if (--batchDepth > 0) {
|
---|
277 | return;
|
---|
278 | }
|
---|
279 | if (batchedComputed) {
|
---|
280 | let e = batchedComputed;
|
---|
281 | batchedComputed = void 0;
|
---|
282 | while (e) {
|
---|
283 | const next = e.next;
|
---|
284 | e.next = void 0;
|
---|
285 | e.flags &= ~8;
|
---|
286 | e = next;
|
---|
287 | }
|
---|
288 | }
|
---|
289 | let error;
|
---|
290 | while (batchedSub) {
|
---|
291 | let e = batchedSub;
|
---|
292 | batchedSub = void 0;
|
---|
293 | while (e) {
|
---|
294 | const next = e.next;
|
---|
295 | e.next = void 0;
|
---|
296 | e.flags &= ~8;
|
---|
297 | if (e.flags & 1) {
|
---|
298 | try {
|
---|
299 | ;
|
---|
300 | e.trigger();
|
---|
301 | } catch (err) {
|
---|
302 | if (!error) error = err;
|
---|
303 | }
|
---|
304 | }
|
---|
305 | e = next;
|
---|
306 | }
|
---|
307 | }
|
---|
308 | if (error) throw error;
|
---|
309 | }
|
---|
310 | function prepareDeps(sub) {
|
---|
311 | for (let link = sub.deps; link; link = link.nextDep) {
|
---|
312 | link.version = -1;
|
---|
313 | link.prevActiveLink = link.dep.activeLink;
|
---|
314 | link.dep.activeLink = link;
|
---|
315 | }
|
---|
316 | }
|
---|
317 | function cleanupDeps(sub) {
|
---|
318 | let head;
|
---|
319 | let tail = sub.depsTail;
|
---|
320 | let link = tail;
|
---|
321 | while (link) {
|
---|
322 | const prev = link.prevDep;
|
---|
323 | if (link.version === -1) {
|
---|
324 | if (link === tail) tail = prev;
|
---|
325 | removeSub(link);
|
---|
326 | removeDep(link);
|
---|
327 | } else {
|
---|
328 | head = link;
|
---|
329 | }
|
---|
330 | link.dep.activeLink = link.prevActiveLink;
|
---|
331 | link.prevActiveLink = void 0;
|
---|
332 | link = prev;
|
---|
333 | }
|
---|
334 | sub.deps = head;
|
---|
335 | sub.depsTail = tail;
|
---|
336 | }
|
---|
337 | function isDirty(sub) {
|
---|
338 | for (let link = sub.deps; link; link = link.nextDep) {
|
---|
339 | if (link.dep.version !== link.version || link.dep.computed && (refreshComputed(link.dep.computed) || link.dep.version !== link.version)) {
|
---|
340 | return true;
|
---|
341 | }
|
---|
342 | }
|
---|
343 | if (sub._dirty) {
|
---|
344 | return true;
|
---|
345 | }
|
---|
346 | return false;
|
---|
347 | }
|
---|
348 | function refreshComputed(computed) {
|
---|
349 | if (computed.flags & 4 && !(computed.flags & 16)) {
|
---|
350 | return;
|
---|
351 | }
|
---|
352 | computed.flags &= ~16;
|
---|
353 | if (computed.globalVersion === globalVersion) {
|
---|
354 | return;
|
---|
355 | }
|
---|
356 | computed.globalVersion = globalVersion;
|
---|
357 | const dep = computed.dep;
|
---|
358 | computed.flags |= 2;
|
---|
359 | if (dep.version > 0 && !computed.isSSR && computed.deps && !isDirty(computed)) {
|
---|
360 | computed.flags &= ~2;
|
---|
361 | return;
|
---|
362 | }
|
---|
363 | const prevSub = activeSub;
|
---|
364 | const prevShouldTrack = shouldTrack;
|
---|
365 | activeSub = computed;
|
---|
366 | shouldTrack = true;
|
---|
367 | try {
|
---|
368 | prepareDeps(computed);
|
---|
369 | const value = computed.fn(computed._value);
|
---|
370 | if (dep.version === 0 || shared.hasChanged(value, computed._value)) {
|
---|
371 | computed._value = value;
|
---|
372 | dep.version++;
|
---|
373 | }
|
---|
374 | } catch (err) {
|
---|
375 | dep.version++;
|
---|
376 | throw err;
|
---|
377 | } finally {
|
---|
378 | activeSub = prevSub;
|
---|
379 | shouldTrack = prevShouldTrack;
|
---|
380 | cleanupDeps(computed);
|
---|
381 | computed.flags &= ~2;
|
---|
382 | }
|
---|
383 | }
|
---|
384 | function removeSub(link, soft = false) {
|
---|
385 | const { dep, prevSub, nextSub } = link;
|
---|
386 | if (prevSub) {
|
---|
387 | prevSub.nextSub = nextSub;
|
---|
388 | link.prevSub = void 0;
|
---|
389 | }
|
---|
390 | if (nextSub) {
|
---|
391 | nextSub.prevSub = prevSub;
|
---|
392 | link.nextSub = void 0;
|
---|
393 | }
|
---|
394 | if (dep.subs === link) {
|
---|
395 | dep.subs = prevSub;
|
---|
396 | if (!prevSub && dep.computed) {
|
---|
397 | dep.computed.flags &= ~4;
|
---|
398 | for (let l = dep.computed.deps; l; l = l.nextDep) {
|
---|
399 | removeSub(l, true);
|
---|
400 | }
|
---|
401 | }
|
---|
402 | }
|
---|
403 | if (!soft && !--dep.sc && dep.map) {
|
---|
404 | dep.map.delete(dep.key);
|
---|
405 | }
|
---|
406 | }
|
---|
407 | function removeDep(link) {
|
---|
408 | const { prevDep, nextDep } = link;
|
---|
409 | if (prevDep) {
|
---|
410 | prevDep.nextDep = nextDep;
|
---|
411 | link.prevDep = void 0;
|
---|
412 | }
|
---|
413 | if (nextDep) {
|
---|
414 | nextDep.prevDep = prevDep;
|
---|
415 | link.nextDep = void 0;
|
---|
416 | }
|
---|
417 | }
|
---|
418 | function effect(fn, options) {
|
---|
419 | if (fn.effect instanceof ReactiveEffect) {
|
---|
420 | fn = fn.effect.fn;
|
---|
421 | }
|
---|
422 | const e = new ReactiveEffect(fn);
|
---|
423 | if (options) {
|
---|
424 | shared.extend(e, options);
|
---|
425 | }
|
---|
426 | try {
|
---|
427 | e.run();
|
---|
428 | } catch (err) {
|
---|
429 | e.stop();
|
---|
430 | throw err;
|
---|
431 | }
|
---|
432 | const runner = e.run.bind(e);
|
---|
433 | runner.effect = e;
|
---|
434 | return runner;
|
---|
435 | }
|
---|
436 | function stop(runner) {
|
---|
437 | runner.effect.stop();
|
---|
438 | }
|
---|
439 | let shouldTrack = true;
|
---|
440 | const trackStack = [];
|
---|
441 | function pauseTracking() {
|
---|
442 | trackStack.push(shouldTrack);
|
---|
443 | shouldTrack = false;
|
---|
444 | }
|
---|
445 | function enableTracking() {
|
---|
446 | trackStack.push(shouldTrack);
|
---|
447 | shouldTrack = true;
|
---|
448 | }
|
---|
449 | function resetTracking() {
|
---|
450 | const last = trackStack.pop();
|
---|
451 | shouldTrack = last === void 0 ? true : last;
|
---|
452 | }
|
---|
453 | function onEffectCleanup(fn, failSilently = false) {
|
---|
454 | if (activeSub instanceof ReactiveEffect) {
|
---|
455 | activeSub.cleanup = fn;
|
---|
456 | }
|
---|
457 | }
|
---|
458 | function cleanupEffect(e) {
|
---|
459 | const { cleanup } = e;
|
---|
460 | e.cleanup = void 0;
|
---|
461 | if (cleanup) {
|
---|
462 | const prevSub = activeSub;
|
---|
463 | activeSub = void 0;
|
---|
464 | try {
|
---|
465 | cleanup();
|
---|
466 | } finally {
|
---|
467 | activeSub = prevSub;
|
---|
468 | }
|
---|
469 | }
|
---|
470 | }
|
---|
471 |
|
---|
472 | let globalVersion = 0;
|
---|
473 | class Link {
|
---|
474 | constructor(sub, dep) {
|
---|
475 | this.sub = sub;
|
---|
476 | this.dep = dep;
|
---|
477 | this.version = dep.version;
|
---|
478 | this.nextDep = this.prevDep = this.nextSub = this.prevSub = this.prevActiveLink = void 0;
|
---|
479 | }
|
---|
480 | }
|
---|
481 | class Dep {
|
---|
482 | constructor(computed) {
|
---|
483 | this.computed = computed;
|
---|
484 | this.version = 0;
|
---|
485 | /**
|
---|
486 | * Link between this dep and the current active effect
|
---|
487 | */
|
---|
488 | this.activeLink = void 0;
|
---|
489 | /**
|
---|
490 | * Doubly linked list representing the subscribing effects (tail)
|
---|
491 | */
|
---|
492 | this.subs = void 0;
|
---|
493 | /**
|
---|
494 | * For object property deps cleanup
|
---|
495 | */
|
---|
496 | this.map = void 0;
|
---|
497 | this.key = void 0;
|
---|
498 | /**
|
---|
499 | * Subscriber counter
|
---|
500 | */
|
---|
501 | this.sc = 0;
|
---|
502 | }
|
---|
503 | track(debugInfo) {
|
---|
504 | if (!activeSub || !shouldTrack || activeSub === this.computed) {
|
---|
505 | return;
|
---|
506 | }
|
---|
507 | let link = this.activeLink;
|
---|
508 | if (link === void 0 || link.sub !== activeSub) {
|
---|
509 | link = this.activeLink = new Link(activeSub, this);
|
---|
510 | if (!activeSub.deps) {
|
---|
511 | activeSub.deps = activeSub.depsTail = link;
|
---|
512 | } else {
|
---|
513 | link.prevDep = activeSub.depsTail;
|
---|
514 | activeSub.depsTail.nextDep = link;
|
---|
515 | activeSub.depsTail = link;
|
---|
516 | }
|
---|
517 | addSub(link);
|
---|
518 | } else if (link.version === -1) {
|
---|
519 | link.version = this.version;
|
---|
520 | if (link.nextDep) {
|
---|
521 | const next = link.nextDep;
|
---|
522 | next.prevDep = link.prevDep;
|
---|
523 | if (link.prevDep) {
|
---|
524 | link.prevDep.nextDep = next;
|
---|
525 | }
|
---|
526 | link.prevDep = activeSub.depsTail;
|
---|
527 | link.nextDep = void 0;
|
---|
528 | activeSub.depsTail.nextDep = link;
|
---|
529 | activeSub.depsTail = link;
|
---|
530 | if (activeSub.deps === link) {
|
---|
531 | activeSub.deps = next;
|
---|
532 | }
|
---|
533 | }
|
---|
534 | }
|
---|
535 | return link;
|
---|
536 | }
|
---|
537 | trigger(debugInfo) {
|
---|
538 | this.version++;
|
---|
539 | globalVersion++;
|
---|
540 | this.notify(debugInfo);
|
---|
541 | }
|
---|
542 | notify(debugInfo) {
|
---|
543 | startBatch();
|
---|
544 | try {
|
---|
545 | if (false) ;
|
---|
546 | for (let link = this.subs; link; link = link.prevSub) {
|
---|
547 | if (link.sub.notify()) {
|
---|
548 | ;
|
---|
549 | link.sub.dep.notify();
|
---|
550 | }
|
---|
551 | }
|
---|
552 | } finally {
|
---|
553 | endBatch();
|
---|
554 | }
|
---|
555 | }
|
---|
556 | }
|
---|
557 | function addSub(link) {
|
---|
558 | link.dep.sc++;
|
---|
559 | if (link.sub.flags & 4) {
|
---|
560 | const computed = link.dep.computed;
|
---|
561 | if (computed && !link.dep.subs) {
|
---|
562 | computed.flags |= 4 | 16;
|
---|
563 | for (let l = computed.deps; l; l = l.nextDep) {
|
---|
564 | addSub(l);
|
---|
565 | }
|
---|
566 | }
|
---|
567 | const currentTail = link.dep.subs;
|
---|
568 | if (currentTail !== link) {
|
---|
569 | link.prevSub = currentTail;
|
---|
570 | if (currentTail) currentTail.nextSub = link;
|
---|
571 | }
|
---|
572 | link.dep.subs = link;
|
---|
573 | }
|
---|
574 | }
|
---|
575 | const targetMap = /* @__PURE__ */ new WeakMap();
|
---|
576 | const ITERATE_KEY = Symbol(
|
---|
577 | ""
|
---|
578 | );
|
---|
579 | const MAP_KEY_ITERATE_KEY = Symbol(
|
---|
580 | ""
|
---|
581 | );
|
---|
582 | const ARRAY_ITERATE_KEY = Symbol(
|
---|
583 | ""
|
---|
584 | );
|
---|
585 | function track(target, type, key) {
|
---|
586 | if (shouldTrack && activeSub) {
|
---|
587 | let depsMap = targetMap.get(target);
|
---|
588 | if (!depsMap) {
|
---|
589 | targetMap.set(target, depsMap = /* @__PURE__ */ new Map());
|
---|
590 | }
|
---|
591 | let dep = depsMap.get(key);
|
---|
592 | if (!dep) {
|
---|
593 | depsMap.set(key, dep = new Dep());
|
---|
594 | dep.map = depsMap;
|
---|
595 | dep.key = key;
|
---|
596 | }
|
---|
597 | {
|
---|
598 | dep.track();
|
---|
599 | }
|
---|
600 | }
|
---|
601 | }
|
---|
602 | function trigger(target, type, key, newValue, oldValue, oldTarget) {
|
---|
603 | const depsMap = targetMap.get(target);
|
---|
604 | if (!depsMap) {
|
---|
605 | globalVersion++;
|
---|
606 | return;
|
---|
607 | }
|
---|
608 | const run = (dep) => {
|
---|
609 | if (dep) {
|
---|
610 | {
|
---|
611 | dep.trigger();
|
---|
612 | }
|
---|
613 | }
|
---|
614 | };
|
---|
615 | startBatch();
|
---|
616 | if (type === "clear") {
|
---|
617 | depsMap.forEach(run);
|
---|
618 | } else {
|
---|
619 | const targetIsArray = shared.isArray(target);
|
---|
620 | const isArrayIndex = targetIsArray && shared.isIntegerKey(key);
|
---|
621 | if (targetIsArray && key === "length") {
|
---|
622 | const newLength = Number(newValue);
|
---|
623 | depsMap.forEach((dep, key2) => {
|
---|
624 | if (key2 === "length" || key2 === ARRAY_ITERATE_KEY || !shared.isSymbol(key2) && key2 >= newLength) {
|
---|
625 | run(dep);
|
---|
626 | }
|
---|
627 | });
|
---|
628 | } else {
|
---|
629 | if (key !== void 0 || depsMap.has(void 0)) {
|
---|
630 | run(depsMap.get(key));
|
---|
631 | }
|
---|
632 | if (isArrayIndex) {
|
---|
633 | run(depsMap.get(ARRAY_ITERATE_KEY));
|
---|
634 | }
|
---|
635 | switch (type) {
|
---|
636 | case "add":
|
---|
637 | if (!targetIsArray) {
|
---|
638 | run(depsMap.get(ITERATE_KEY));
|
---|
639 | if (shared.isMap(target)) {
|
---|
640 | run(depsMap.get(MAP_KEY_ITERATE_KEY));
|
---|
641 | }
|
---|
642 | } else if (isArrayIndex) {
|
---|
643 | run(depsMap.get("length"));
|
---|
644 | }
|
---|
645 | break;
|
---|
646 | case "delete":
|
---|
647 | if (!targetIsArray) {
|
---|
648 | run(depsMap.get(ITERATE_KEY));
|
---|
649 | if (shared.isMap(target)) {
|
---|
650 | run(depsMap.get(MAP_KEY_ITERATE_KEY));
|
---|
651 | }
|
---|
652 | }
|
---|
653 | break;
|
---|
654 | case "set":
|
---|
655 | if (shared.isMap(target)) {
|
---|
656 | run(depsMap.get(ITERATE_KEY));
|
---|
657 | }
|
---|
658 | break;
|
---|
659 | }
|
---|
660 | }
|
---|
661 | }
|
---|
662 | endBatch();
|
---|
663 | }
|
---|
664 | function getDepFromReactive(object, key) {
|
---|
665 | const depMap = targetMap.get(object);
|
---|
666 | return depMap && depMap.get(key);
|
---|
667 | }
|
---|
668 |
|
---|
669 | function reactiveReadArray(array) {
|
---|
670 | const raw = toRaw(array);
|
---|
671 | if (raw === array) return raw;
|
---|
672 | track(raw, "iterate", ARRAY_ITERATE_KEY);
|
---|
673 | return isShallow(array) ? raw : raw.map(toReactive);
|
---|
674 | }
|
---|
675 | function shallowReadArray(arr) {
|
---|
676 | track(arr = toRaw(arr), "iterate", ARRAY_ITERATE_KEY);
|
---|
677 | return arr;
|
---|
678 | }
|
---|
679 | const arrayInstrumentations = {
|
---|
680 | __proto__: null,
|
---|
681 | [Symbol.iterator]() {
|
---|
682 | return iterator(this, Symbol.iterator, toReactive);
|
---|
683 | },
|
---|
684 | concat(...args) {
|
---|
685 | return reactiveReadArray(this).concat(
|
---|
686 | ...args.map((x) => shared.isArray(x) ? reactiveReadArray(x) : x)
|
---|
687 | );
|
---|
688 | },
|
---|
689 | entries() {
|
---|
690 | return iterator(this, "entries", (value) => {
|
---|
691 | value[1] = toReactive(value[1]);
|
---|
692 | return value;
|
---|
693 | });
|
---|
694 | },
|
---|
695 | every(fn, thisArg) {
|
---|
696 | return apply(this, "every", fn, thisArg, void 0, arguments);
|
---|
697 | },
|
---|
698 | filter(fn, thisArg) {
|
---|
699 | return apply(this, "filter", fn, thisArg, (v) => v.map(toReactive), arguments);
|
---|
700 | },
|
---|
701 | find(fn, thisArg) {
|
---|
702 | return apply(this, "find", fn, thisArg, toReactive, arguments);
|
---|
703 | },
|
---|
704 | findIndex(fn, thisArg) {
|
---|
705 | return apply(this, "findIndex", fn, thisArg, void 0, arguments);
|
---|
706 | },
|
---|
707 | findLast(fn, thisArg) {
|
---|
708 | return apply(this, "findLast", fn, thisArg, toReactive, arguments);
|
---|
709 | },
|
---|
710 | findLastIndex(fn, thisArg) {
|
---|
711 | return apply(this, "findLastIndex", fn, thisArg, void 0, arguments);
|
---|
712 | },
|
---|
713 | // flat, flatMap could benefit from ARRAY_ITERATE but are not straight-forward to implement
|
---|
714 | forEach(fn, thisArg) {
|
---|
715 | return apply(this, "forEach", fn, thisArg, void 0, arguments);
|
---|
716 | },
|
---|
717 | includes(...args) {
|
---|
718 | return searchProxy(this, "includes", args);
|
---|
719 | },
|
---|
720 | indexOf(...args) {
|
---|
721 | return searchProxy(this, "indexOf", args);
|
---|
722 | },
|
---|
723 | join(separator) {
|
---|
724 | return reactiveReadArray(this).join(separator);
|
---|
725 | },
|
---|
726 | // keys() iterator only reads `length`, no optimisation required
|
---|
727 | lastIndexOf(...args) {
|
---|
728 | return searchProxy(this, "lastIndexOf", args);
|
---|
729 | },
|
---|
730 | map(fn, thisArg) {
|
---|
731 | return apply(this, "map", fn, thisArg, void 0, arguments);
|
---|
732 | },
|
---|
733 | pop() {
|
---|
734 | return noTracking(this, "pop");
|
---|
735 | },
|
---|
736 | push(...args) {
|
---|
737 | return noTracking(this, "push", args);
|
---|
738 | },
|
---|
739 | reduce(fn, ...args) {
|
---|
740 | return reduce(this, "reduce", fn, args);
|
---|
741 | },
|
---|
742 | reduceRight(fn, ...args) {
|
---|
743 | return reduce(this, "reduceRight", fn, args);
|
---|
744 | },
|
---|
745 | shift() {
|
---|
746 | return noTracking(this, "shift");
|
---|
747 | },
|
---|
748 | // slice could use ARRAY_ITERATE but also seems to beg for range tracking
|
---|
749 | some(fn, thisArg) {
|
---|
750 | return apply(this, "some", fn, thisArg, void 0, arguments);
|
---|
751 | },
|
---|
752 | splice(...args) {
|
---|
753 | return noTracking(this, "splice", args);
|
---|
754 | },
|
---|
755 | toReversed() {
|
---|
756 | return reactiveReadArray(this).toReversed();
|
---|
757 | },
|
---|
758 | toSorted(comparer) {
|
---|
759 | return reactiveReadArray(this).toSorted(comparer);
|
---|
760 | },
|
---|
761 | toSpliced(...args) {
|
---|
762 | return reactiveReadArray(this).toSpliced(...args);
|
---|
763 | },
|
---|
764 | unshift(...args) {
|
---|
765 | return noTracking(this, "unshift", args);
|
---|
766 | },
|
---|
767 | values() {
|
---|
768 | return iterator(this, "values", toReactive);
|
---|
769 | }
|
---|
770 | };
|
---|
771 | function iterator(self, method, wrapValue) {
|
---|
772 | const arr = shallowReadArray(self);
|
---|
773 | const iter = arr[method]();
|
---|
774 | if (arr !== self && !isShallow(self)) {
|
---|
775 | iter._next = iter.next;
|
---|
776 | iter.next = () => {
|
---|
777 | const result = iter._next();
|
---|
778 | if (result.value) {
|
---|
779 | result.value = wrapValue(result.value);
|
---|
780 | }
|
---|
781 | return result;
|
---|
782 | };
|
---|
783 | }
|
---|
784 | return iter;
|
---|
785 | }
|
---|
786 | const arrayProto = Array.prototype;
|
---|
787 | function apply(self, method, fn, thisArg, wrappedRetFn, args) {
|
---|
788 | const arr = shallowReadArray(self);
|
---|
789 | const needsWrap = arr !== self && !isShallow(self);
|
---|
790 | const methodFn = arr[method];
|
---|
791 | if (methodFn !== arrayProto[method]) {
|
---|
792 | const result2 = methodFn.apply(self, args);
|
---|
793 | return needsWrap ? toReactive(result2) : result2;
|
---|
794 | }
|
---|
795 | let wrappedFn = fn;
|
---|
796 | if (arr !== self) {
|
---|
797 | if (needsWrap) {
|
---|
798 | wrappedFn = function(item, index) {
|
---|
799 | return fn.call(this, toReactive(item), index, self);
|
---|
800 | };
|
---|
801 | } else if (fn.length > 2) {
|
---|
802 | wrappedFn = function(item, index) {
|
---|
803 | return fn.call(this, item, index, self);
|
---|
804 | };
|
---|
805 | }
|
---|
806 | }
|
---|
807 | const result = methodFn.call(arr, wrappedFn, thisArg);
|
---|
808 | return needsWrap && wrappedRetFn ? wrappedRetFn(result) : result;
|
---|
809 | }
|
---|
810 | function reduce(self, method, fn, args) {
|
---|
811 | const arr = shallowReadArray(self);
|
---|
812 | let wrappedFn = fn;
|
---|
813 | if (arr !== self) {
|
---|
814 | if (!isShallow(self)) {
|
---|
815 | wrappedFn = function(acc, item, index) {
|
---|
816 | return fn.call(this, acc, toReactive(item), index, self);
|
---|
817 | };
|
---|
818 | } else if (fn.length > 3) {
|
---|
819 | wrappedFn = function(acc, item, index) {
|
---|
820 | return fn.call(this, acc, item, index, self);
|
---|
821 | };
|
---|
822 | }
|
---|
823 | }
|
---|
824 | return arr[method](wrappedFn, ...args);
|
---|
825 | }
|
---|
826 | function searchProxy(self, method, args) {
|
---|
827 | const arr = toRaw(self);
|
---|
828 | track(arr, "iterate", ARRAY_ITERATE_KEY);
|
---|
829 | const res = arr[method](...args);
|
---|
830 | if ((res === -1 || res === false) && isProxy(args[0])) {
|
---|
831 | args[0] = toRaw(args[0]);
|
---|
832 | return arr[method](...args);
|
---|
833 | }
|
---|
834 | return res;
|
---|
835 | }
|
---|
836 | function noTracking(self, method, args = []) {
|
---|
837 | pauseTracking();
|
---|
838 | startBatch();
|
---|
839 | const res = toRaw(self)[method].apply(self, args);
|
---|
840 | endBatch();
|
---|
841 | resetTracking();
|
---|
842 | return res;
|
---|
843 | }
|
---|
844 |
|
---|
845 | const isNonTrackableKeys = /* @__PURE__ */ shared.makeMap(`__proto__,__v_isRef,__isVue`);
|
---|
846 | const builtInSymbols = new Set(
|
---|
847 | /* @__PURE__ */ Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller").map((key) => Symbol[key]).filter(shared.isSymbol)
|
---|
848 | );
|
---|
849 | function hasOwnProperty(key) {
|
---|
850 | if (!shared.isSymbol(key)) key = String(key);
|
---|
851 | const obj = toRaw(this);
|
---|
852 | track(obj, "has", key);
|
---|
853 | return obj.hasOwnProperty(key);
|
---|
854 | }
|
---|
855 | class BaseReactiveHandler {
|
---|
856 | constructor(_isReadonly = false, _isShallow = false) {
|
---|
857 | this._isReadonly = _isReadonly;
|
---|
858 | this._isShallow = _isShallow;
|
---|
859 | }
|
---|
860 | get(target, key, receiver) {
|
---|
861 | if (key === "__v_skip") return target["__v_skip"];
|
---|
862 | const isReadonly2 = this._isReadonly, isShallow2 = this._isShallow;
|
---|
863 | if (key === "__v_isReactive") {
|
---|
864 | return !isReadonly2;
|
---|
865 | } else if (key === "__v_isReadonly") {
|
---|
866 | return isReadonly2;
|
---|
867 | } else if (key === "__v_isShallow") {
|
---|
868 | return isShallow2;
|
---|
869 | } else if (key === "__v_raw") {
|
---|
870 | if (receiver === (isReadonly2 ? isShallow2 ? shallowReadonlyMap : readonlyMap : isShallow2 ? shallowReactiveMap : reactiveMap).get(target) || // receiver is not the reactive proxy, but has the same prototype
|
---|
871 | // this means the receiver is a user proxy of the reactive proxy
|
---|
872 | Object.getPrototypeOf(target) === Object.getPrototypeOf(receiver)) {
|
---|
873 | return target;
|
---|
874 | }
|
---|
875 | return;
|
---|
876 | }
|
---|
877 | const targetIsArray = shared.isArray(target);
|
---|
878 | if (!isReadonly2) {
|
---|
879 | let fn;
|
---|
880 | if (targetIsArray && (fn = arrayInstrumentations[key])) {
|
---|
881 | return fn;
|
---|
882 | }
|
---|
883 | if (key === "hasOwnProperty") {
|
---|
884 | return hasOwnProperty;
|
---|
885 | }
|
---|
886 | }
|
---|
887 | const res = Reflect.get(
|
---|
888 | target,
|
---|
889 | key,
|
---|
890 | // if this is a proxy wrapping a ref, return methods using the raw ref
|
---|
891 | // as receiver so that we don't have to call `toRaw` on the ref in all
|
---|
892 | // its class methods
|
---|
893 | isRef(target) ? target : receiver
|
---|
894 | );
|
---|
895 | if (shared.isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) {
|
---|
896 | return res;
|
---|
897 | }
|
---|
898 | if (!isReadonly2) {
|
---|
899 | track(target, "get", key);
|
---|
900 | }
|
---|
901 | if (isShallow2) {
|
---|
902 | return res;
|
---|
903 | }
|
---|
904 | if (isRef(res)) {
|
---|
905 | return targetIsArray && shared.isIntegerKey(key) ? res : res.value;
|
---|
906 | }
|
---|
907 | if (shared.isObject(res)) {
|
---|
908 | return isReadonly2 ? readonly(res) : reactive(res);
|
---|
909 | }
|
---|
910 | return res;
|
---|
911 | }
|
---|
912 | }
|
---|
913 | class MutableReactiveHandler extends BaseReactiveHandler {
|
---|
914 | constructor(isShallow2 = false) {
|
---|
915 | super(false, isShallow2);
|
---|
916 | }
|
---|
917 | set(target, key, value, receiver) {
|
---|
918 | let oldValue = target[key];
|
---|
919 | if (!this._isShallow) {
|
---|
920 | const isOldValueReadonly = isReadonly(oldValue);
|
---|
921 | if (!isShallow(value) && !isReadonly(value)) {
|
---|
922 | oldValue = toRaw(oldValue);
|
---|
923 | value = toRaw(value);
|
---|
924 | }
|
---|
925 | if (!shared.isArray(target) && isRef(oldValue) && !isRef(value)) {
|
---|
926 | if (isOldValueReadonly) {
|
---|
927 | return false;
|
---|
928 | } else {
|
---|
929 | oldValue.value = value;
|
---|
930 | return true;
|
---|
931 | }
|
---|
932 | }
|
---|
933 | }
|
---|
934 | const hadKey = shared.isArray(target) && shared.isIntegerKey(key) ? Number(key) < target.length : shared.hasOwn(target, key);
|
---|
935 | const result = Reflect.set(
|
---|
936 | target,
|
---|
937 | key,
|
---|
938 | value,
|
---|
939 | isRef(target) ? target : receiver
|
---|
940 | );
|
---|
941 | if (target === toRaw(receiver)) {
|
---|
942 | if (!hadKey) {
|
---|
943 | trigger(target, "add", key, value);
|
---|
944 | } else if (shared.hasChanged(value, oldValue)) {
|
---|
945 | trigger(target, "set", key, value);
|
---|
946 | }
|
---|
947 | }
|
---|
948 | return result;
|
---|
949 | }
|
---|
950 | deleteProperty(target, key) {
|
---|
951 | const hadKey = shared.hasOwn(target, key);
|
---|
952 | target[key];
|
---|
953 | const result = Reflect.deleteProperty(target, key);
|
---|
954 | if (result && hadKey) {
|
---|
955 | trigger(target, "delete", key, void 0);
|
---|
956 | }
|
---|
957 | return result;
|
---|
958 | }
|
---|
959 | has(target, key) {
|
---|
960 | const result = Reflect.has(target, key);
|
---|
961 | if (!shared.isSymbol(key) || !builtInSymbols.has(key)) {
|
---|
962 | track(target, "has", key);
|
---|
963 | }
|
---|
964 | return result;
|
---|
965 | }
|
---|
966 | ownKeys(target) {
|
---|
967 | track(
|
---|
968 | target,
|
---|
969 | "iterate",
|
---|
970 | shared.isArray(target) ? "length" : ITERATE_KEY
|
---|
971 | );
|
---|
972 | return Reflect.ownKeys(target);
|
---|
973 | }
|
---|
974 | }
|
---|
975 | class ReadonlyReactiveHandler extends BaseReactiveHandler {
|
---|
976 | constructor(isShallow2 = false) {
|
---|
977 | super(true, isShallow2);
|
---|
978 | }
|
---|
979 | set(target, key) {
|
---|
980 | return true;
|
---|
981 | }
|
---|
982 | deleteProperty(target, key) {
|
---|
983 | return true;
|
---|
984 | }
|
---|
985 | }
|
---|
986 | const mutableHandlers = /* @__PURE__ */ new MutableReactiveHandler();
|
---|
987 | const readonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler();
|
---|
988 | const shallowReactiveHandlers = /* @__PURE__ */ new MutableReactiveHandler(true);
|
---|
989 | const shallowReadonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler(true);
|
---|
990 |
|
---|
991 | const toShallow = (value) => value;
|
---|
992 | const getProto = (v) => Reflect.getPrototypeOf(v);
|
---|
993 | function createIterableMethod(method, isReadonly2, isShallow2) {
|
---|
994 | return function(...args) {
|
---|
995 | const target = this["__v_raw"];
|
---|
996 | const rawTarget = toRaw(target);
|
---|
997 | const targetIsMap = shared.isMap(rawTarget);
|
---|
998 | const isPair = method === "entries" || method === Symbol.iterator && targetIsMap;
|
---|
999 | const isKeyOnly = method === "keys" && targetIsMap;
|
---|
1000 | const innerIterator = target[method](...args);
|
---|
1001 | const wrap = isShallow2 ? toShallow : isReadonly2 ? toReadonly : toReactive;
|
---|
1002 | !isReadonly2 && track(
|
---|
1003 | rawTarget,
|
---|
1004 | "iterate",
|
---|
1005 | isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY
|
---|
1006 | );
|
---|
1007 | return {
|
---|
1008 | // iterator protocol
|
---|
1009 | next() {
|
---|
1010 | const { value, done } = innerIterator.next();
|
---|
1011 | return done ? { value, done } : {
|
---|
1012 | value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
|
---|
1013 | done
|
---|
1014 | };
|
---|
1015 | },
|
---|
1016 | // iterable protocol
|
---|
1017 | [Symbol.iterator]() {
|
---|
1018 | return this;
|
---|
1019 | }
|
---|
1020 | };
|
---|
1021 | };
|
---|
1022 | }
|
---|
1023 | function createReadonlyMethod(type) {
|
---|
1024 | return function(...args) {
|
---|
1025 | return type === "delete" ? false : type === "clear" ? void 0 : this;
|
---|
1026 | };
|
---|
1027 | }
|
---|
1028 | function createInstrumentations(readonly, shallow) {
|
---|
1029 | const instrumentations = {
|
---|
1030 | get(key) {
|
---|
1031 | const target = this["__v_raw"];
|
---|
1032 | const rawTarget = toRaw(target);
|
---|
1033 | const rawKey = toRaw(key);
|
---|
1034 | if (!readonly) {
|
---|
1035 | if (shared.hasChanged(key, rawKey)) {
|
---|
1036 | track(rawTarget, "get", key);
|
---|
1037 | }
|
---|
1038 | track(rawTarget, "get", rawKey);
|
---|
1039 | }
|
---|
1040 | const { has } = getProto(rawTarget);
|
---|
1041 | const wrap = shallow ? toShallow : readonly ? toReadonly : toReactive;
|
---|
1042 | if (has.call(rawTarget, key)) {
|
---|
1043 | return wrap(target.get(key));
|
---|
1044 | } else if (has.call(rawTarget, rawKey)) {
|
---|
1045 | return wrap(target.get(rawKey));
|
---|
1046 | } else if (target !== rawTarget) {
|
---|
1047 | target.get(key);
|
---|
1048 | }
|
---|
1049 | },
|
---|
1050 | get size() {
|
---|
1051 | const target = this["__v_raw"];
|
---|
1052 | !readonly && track(toRaw(target), "iterate", ITERATE_KEY);
|
---|
1053 | return Reflect.get(target, "size", target);
|
---|
1054 | },
|
---|
1055 | has(key) {
|
---|
1056 | const target = this["__v_raw"];
|
---|
1057 | const rawTarget = toRaw(target);
|
---|
1058 | const rawKey = toRaw(key);
|
---|
1059 | if (!readonly) {
|
---|
1060 | if (shared.hasChanged(key, rawKey)) {
|
---|
1061 | track(rawTarget, "has", key);
|
---|
1062 | }
|
---|
1063 | track(rawTarget, "has", rawKey);
|
---|
1064 | }
|
---|
1065 | return key === rawKey ? target.has(key) : target.has(key) || target.has(rawKey);
|
---|
1066 | },
|
---|
1067 | forEach(callback, thisArg) {
|
---|
1068 | const observed = this;
|
---|
1069 | const target = observed["__v_raw"];
|
---|
1070 | const rawTarget = toRaw(target);
|
---|
1071 | const wrap = shallow ? toShallow : readonly ? toReadonly : toReactive;
|
---|
1072 | !readonly && track(rawTarget, "iterate", ITERATE_KEY);
|
---|
1073 | return target.forEach((value, key) => {
|
---|
1074 | return callback.call(thisArg, wrap(value), wrap(key), observed);
|
---|
1075 | });
|
---|
1076 | }
|
---|
1077 | };
|
---|
1078 | shared.extend(
|
---|
1079 | instrumentations,
|
---|
1080 | readonly ? {
|
---|
1081 | add: createReadonlyMethod("add"),
|
---|
1082 | set: createReadonlyMethod("set"),
|
---|
1083 | delete: createReadonlyMethod("delete"),
|
---|
1084 | clear: createReadonlyMethod("clear")
|
---|
1085 | } : {
|
---|
1086 | add(value) {
|
---|
1087 | if (!shallow && !isShallow(value) && !isReadonly(value)) {
|
---|
1088 | value = toRaw(value);
|
---|
1089 | }
|
---|
1090 | const target = toRaw(this);
|
---|
1091 | const proto = getProto(target);
|
---|
1092 | const hadKey = proto.has.call(target, value);
|
---|
1093 | if (!hadKey) {
|
---|
1094 | target.add(value);
|
---|
1095 | trigger(target, "add", value, value);
|
---|
1096 | }
|
---|
1097 | return this;
|
---|
1098 | },
|
---|
1099 | set(key, value) {
|
---|
1100 | if (!shallow && !isShallow(value) && !isReadonly(value)) {
|
---|
1101 | value = toRaw(value);
|
---|
1102 | }
|
---|
1103 | const target = toRaw(this);
|
---|
1104 | const { has, get } = getProto(target);
|
---|
1105 | let hadKey = has.call(target, key);
|
---|
1106 | if (!hadKey) {
|
---|
1107 | key = toRaw(key);
|
---|
1108 | hadKey = has.call(target, key);
|
---|
1109 | }
|
---|
1110 | const oldValue = get.call(target, key);
|
---|
1111 | target.set(key, value);
|
---|
1112 | if (!hadKey) {
|
---|
1113 | trigger(target, "add", key, value);
|
---|
1114 | } else if (shared.hasChanged(value, oldValue)) {
|
---|
1115 | trigger(target, "set", key, value);
|
---|
1116 | }
|
---|
1117 | return this;
|
---|
1118 | },
|
---|
1119 | delete(key) {
|
---|
1120 | const target = toRaw(this);
|
---|
1121 | const { has, get } = getProto(target);
|
---|
1122 | let hadKey = has.call(target, key);
|
---|
1123 | if (!hadKey) {
|
---|
1124 | key = toRaw(key);
|
---|
1125 | hadKey = has.call(target, key);
|
---|
1126 | }
|
---|
1127 | get ? get.call(target, key) : void 0;
|
---|
1128 | const result = target.delete(key);
|
---|
1129 | if (hadKey) {
|
---|
1130 | trigger(target, "delete", key, void 0);
|
---|
1131 | }
|
---|
1132 | return result;
|
---|
1133 | },
|
---|
1134 | clear() {
|
---|
1135 | const target = toRaw(this);
|
---|
1136 | const hadItems = target.size !== 0;
|
---|
1137 | const result = target.clear();
|
---|
1138 | if (hadItems) {
|
---|
1139 | trigger(
|
---|
1140 | target,
|
---|
1141 | "clear",
|
---|
1142 | void 0,
|
---|
1143 | void 0);
|
---|
1144 | }
|
---|
1145 | return result;
|
---|
1146 | }
|
---|
1147 | }
|
---|
1148 | );
|
---|
1149 | const iteratorMethods = [
|
---|
1150 | "keys",
|
---|
1151 | "values",
|
---|
1152 | "entries",
|
---|
1153 | Symbol.iterator
|
---|
1154 | ];
|
---|
1155 | iteratorMethods.forEach((method) => {
|
---|
1156 | instrumentations[method] = createIterableMethod(method, readonly, shallow);
|
---|
1157 | });
|
---|
1158 | return instrumentations;
|
---|
1159 | }
|
---|
1160 | function createInstrumentationGetter(isReadonly2, shallow) {
|
---|
1161 | const instrumentations = createInstrumentations(isReadonly2, shallow);
|
---|
1162 | return (target, key, receiver) => {
|
---|
1163 | if (key === "__v_isReactive") {
|
---|
1164 | return !isReadonly2;
|
---|
1165 | } else if (key === "__v_isReadonly") {
|
---|
1166 | return isReadonly2;
|
---|
1167 | } else if (key === "__v_raw") {
|
---|
1168 | return target;
|
---|
1169 | }
|
---|
1170 | return Reflect.get(
|
---|
1171 | shared.hasOwn(instrumentations, key) && key in target ? instrumentations : target,
|
---|
1172 | key,
|
---|
1173 | receiver
|
---|
1174 | );
|
---|
1175 | };
|
---|
1176 | }
|
---|
1177 | const mutableCollectionHandlers = {
|
---|
1178 | get: /* @__PURE__ */ createInstrumentationGetter(false, false)
|
---|
1179 | };
|
---|
1180 | const shallowCollectionHandlers = {
|
---|
1181 | get: /* @__PURE__ */ createInstrumentationGetter(false, true)
|
---|
1182 | };
|
---|
1183 | const readonlyCollectionHandlers = {
|
---|
1184 | get: /* @__PURE__ */ createInstrumentationGetter(true, false)
|
---|
1185 | };
|
---|
1186 | const shallowReadonlyCollectionHandlers = {
|
---|
1187 | get: /* @__PURE__ */ createInstrumentationGetter(true, true)
|
---|
1188 | };
|
---|
1189 |
|
---|
1190 | const reactiveMap = /* @__PURE__ */ new WeakMap();
|
---|
1191 | const shallowReactiveMap = /* @__PURE__ */ new WeakMap();
|
---|
1192 | const readonlyMap = /* @__PURE__ */ new WeakMap();
|
---|
1193 | const shallowReadonlyMap = /* @__PURE__ */ new WeakMap();
|
---|
1194 | function targetTypeMap(rawType) {
|
---|
1195 | switch (rawType) {
|
---|
1196 | case "Object":
|
---|
1197 | case "Array":
|
---|
1198 | return 1 /* COMMON */;
|
---|
1199 | case "Map":
|
---|
1200 | case "Set":
|
---|
1201 | case "WeakMap":
|
---|
1202 | case "WeakSet":
|
---|
1203 | return 2 /* COLLECTION */;
|
---|
1204 | default:
|
---|
1205 | return 0 /* INVALID */;
|
---|
1206 | }
|
---|
1207 | }
|
---|
1208 | function getTargetType(value) {
|
---|
1209 | return value["__v_skip"] || !Object.isExtensible(value) ? 0 /* INVALID */ : targetTypeMap(shared.toRawType(value));
|
---|
1210 | }
|
---|
1211 | function reactive(target) {
|
---|
1212 | if (isReadonly(target)) {
|
---|
1213 | return target;
|
---|
1214 | }
|
---|
1215 | return createReactiveObject(
|
---|
1216 | target,
|
---|
1217 | false,
|
---|
1218 | mutableHandlers,
|
---|
1219 | mutableCollectionHandlers,
|
---|
1220 | reactiveMap
|
---|
1221 | );
|
---|
1222 | }
|
---|
1223 | function shallowReactive(target) {
|
---|
1224 | return createReactiveObject(
|
---|
1225 | target,
|
---|
1226 | false,
|
---|
1227 | shallowReactiveHandlers,
|
---|
1228 | shallowCollectionHandlers,
|
---|
1229 | shallowReactiveMap
|
---|
1230 | );
|
---|
1231 | }
|
---|
1232 | function readonly(target) {
|
---|
1233 | return createReactiveObject(
|
---|
1234 | target,
|
---|
1235 | true,
|
---|
1236 | readonlyHandlers,
|
---|
1237 | readonlyCollectionHandlers,
|
---|
1238 | readonlyMap
|
---|
1239 | );
|
---|
1240 | }
|
---|
1241 | function shallowReadonly(target) {
|
---|
1242 | return createReactiveObject(
|
---|
1243 | target,
|
---|
1244 | true,
|
---|
1245 | shallowReadonlyHandlers,
|
---|
1246 | shallowReadonlyCollectionHandlers,
|
---|
1247 | shallowReadonlyMap
|
---|
1248 | );
|
---|
1249 | }
|
---|
1250 | function createReactiveObject(target, isReadonly2, baseHandlers, collectionHandlers, proxyMap) {
|
---|
1251 | if (!shared.isObject(target)) {
|
---|
1252 | return target;
|
---|
1253 | }
|
---|
1254 | if (target["__v_raw"] && !(isReadonly2 && target["__v_isReactive"])) {
|
---|
1255 | return target;
|
---|
1256 | }
|
---|
1257 | const existingProxy = proxyMap.get(target);
|
---|
1258 | if (existingProxy) {
|
---|
1259 | return existingProxy;
|
---|
1260 | }
|
---|
1261 | const targetType = getTargetType(target);
|
---|
1262 | if (targetType === 0 /* INVALID */) {
|
---|
1263 | return target;
|
---|
1264 | }
|
---|
1265 | const proxy = new Proxy(
|
---|
1266 | target,
|
---|
1267 | targetType === 2 /* COLLECTION */ ? collectionHandlers : baseHandlers
|
---|
1268 | );
|
---|
1269 | proxyMap.set(target, proxy);
|
---|
1270 | return proxy;
|
---|
1271 | }
|
---|
1272 | function isReactive(value) {
|
---|
1273 | if (isReadonly(value)) {
|
---|
1274 | return isReactive(value["__v_raw"]);
|
---|
1275 | }
|
---|
1276 | return !!(value && value["__v_isReactive"]);
|
---|
1277 | }
|
---|
1278 | function isReadonly(value) {
|
---|
1279 | return !!(value && value["__v_isReadonly"]);
|
---|
1280 | }
|
---|
1281 | function isShallow(value) {
|
---|
1282 | return !!(value && value["__v_isShallow"]);
|
---|
1283 | }
|
---|
1284 | function isProxy(value) {
|
---|
1285 | return value ? !!value["__v_raw"] : false;
|
---|
1286 | }
|
---|
1287 | function toRaw(observed) {
|
---|
1288 | const raw = observed && observed["__v_raw"];
|
---|
1289 | return raw ? toRaw(raw) : observed;
|
---|
1290 | }
|
---|
1291 | function markRaw(value) {
|
---|
1292 | if (!shared.hasOwn(value, "__v_skip") && Object.isExtensible(value)) {
|
---|
1293 | shared.def(value, "__v_skip", true);
|
---|
1294 | }
|
---|
1295 | return value;
|
---|
1296 | }
|
---|
1297 | const toReactive = (value) => shared.isObject(value) ? reactive(value) : value;
|
---|
1298 | const toReadonly = (value) => shared.isObject(value) ? readonly(value) : value;
|
---|
1299 |
|
---|
1300 | function isRef(r) {
|
---|
1301 | return r ? r["__v_isRef"] === true : false;
|
---|
1302 | }
|
---|
1303 | function ref(value) {
|
---|
1304 | return createRef(value, false);
|
---|
1305 | }
|
---|
1306 | function shallowRef(value) {
|
---|
1307 | return createRef(value, true);
|
---|
1308 | }
|
---|
1309 | function createRef(rawValue, shallow) {
|
---|
1310 | if (isRef(rawValue)) {
|
---|
1311 | return rawValue;
|
---|
1312 | }
|
---|
1313 | return new RefImpl(rawValue, shallow);
|
---|
1314 | }
|
---|
1315 | class RefImpl {
|
---|
1316 | constructor(value, isShallow2) {
|
---|
1317 | this.dep = new Dep();
|
---|
1318 | this["__v_isRef"] = true;
|
---|
1319 | this["__v_isShallow"] = false;
|
---|
1320 | this._rawValue = isShallow2 ? value : toRaw(value);
|
---|
1321 | this._value = isShallow2 ? value : toReactive(value);
|
---|
1322 | this["__v_isShallow"] = isShallow2;
|
---|
1323 | }
|
---|
1324 | get value() {
|
---|
1325 | {
|
---|
1326 | this.dep.track();
|
---|
1327 | }
|
---|
1328 | return this._value;
|
---|
1329 | }
|
---|
1330 | set value(newValue) {
|
---|
1331 | const oldValue = this._rawValue;
|
---|
1332 | const useDirectValue = this["__v_isShallow"] || isShallow(newValue) || isReadonly(newValue);
|
---|
1333 | newValue = useDirectValue ? newValue : toRaw(newValue);
|
---|
1334 | if (shared.hasChanged(newValue, oldValue)) {
|
---|
1335 | this._rawValue = newValue;
|
---|
1336 | this._value = useDirectValue ? newValue : toReactive(newValue);
|
---|
1337 | {
|
---|
1338 | this.dep.trigger();
|
---|
1339 | }
|
---|
1340 | }
|
---|
1341 | }
|
---|
1342 | }
|
---|
1343 | function triggerRef(ref2) {
|
---|
1344 | if (ref2.dep) {
|
---|
1345 | {
|
---|
1346 | ref2.dep.trigger();
|
---|
1347 | }
|
---|
1348 | }
|
---|
1349 | }
|
---|
1350 | function unref(ref2) {
|
---|
1351 | return isRef(ref2) ? ref2.value : ref2;
|
---|
1352 | }
|
---|
1353 | function toValue(source) {
|
---|
1354 | return shared.isFunction(source) ? source() : unref(source);
|
---|
1355 | }
|
---|
1356 | const shallowUnwrapHandlers = {
|
---|
1357 | get: (target, key, receiver) => key === "__v_raw" ? target : unref(Reflect.get(target, key, receiver)),
|
---|
1358 | set: (target, key, value, receiver) => {
|
---|
1359 | const oldValue = target[key];
|
---|
1360 | if (isRef(oldValue) && !isRef(value)) {
|
---|
1361 | oldValue.value = value;
|
---|
1362 | return true;
|
---|
1363 | } else {
|
---|
1364 | return Reflect.set(target, key, value, receiver);
|
---|
1365 | }
|
---|
1366 | }
|
---|
1367 | };
|
---|
1368 | function proxyRefs(objectWithRefs) {
|
---|
1369 | return isReactive(objectWithRefs) ? objectWithRefs : new Proxy(objectWithRefs, shallowUnwrapHandlers);
|
---|
1370 | }
|
---|
1371 | class CustomRefImpl {
|
---|
1372 | constructor(factory) {
|
---|
1373 | this["__v_isRef"] = true;
|
---|
1374 | this._value = void 0;
|
---|
1375 | const dep = this.dep = new Dep();
|
---|
1376 | const { get, set } = factory(dep.track.bind(dep), dep.trigger.bind(dep));
|
---|
1377 | this._get = get;
|
---|
1378 | this._set = set;
|
---|
1379 | }
|
---|
1380 | get value() {
|
---|
1381 | return this._value = this._get();
|
---|
1382 | }
|
---|
1383 | set value(newVal) {
|
---|
1384 | this._set(newVal);
|
---|
1385 | }
|
---|
1386 | }
|
---|
1387 | function customRef(factory) {
|
---|
1388 | return new CustomRefImpl(factory);
|
---|
1389 | }
|
---|
1390 | function toRefs(object) {
|
---|
1391 | const ret = shared.isArray(object) ? new Array(object.length) : {};
|
---|
1392 | for (const key in object) {
|
---|
1393 | ret[key] = propertyToRef(object, key);
|
---|
1394 | }
|
---|
1395 | return ret;
|
---|
1396 | }
|
---|
1397 | class ObjectRefImpl {
|
---|
1398 | constructor(_object, _key, _defaultValue) {
|
---|
1399 | this._object = _object;
|
---|
1400 | this._key = _key;
|
---|
1401 | this._defaultValue = _defaultValue;
|
---|
1402 | this["__v_isRef"] = true;
|
---|
1403 | this._value = void 0;
|
---|
1404 | }
|
---|
1405 | get value() {
|
---|
1406 | const val = this._object[this._key];
|
---|
1407 | return this._value = val === void 0 ? this._defaultValue : val;
|
---|
1408 | }
|
---|
1409 | set value(newVal) {
|
---|
1410 | this._object[this._key] = newVal;
|
---|
1411 | }
|
---|
1412 | get dep() {
|
---|
1413 | return getDepFromReactive(toRaw(this._object), this._key);
|
---|
1414 | }
|
---|
1415 | }
|
---|
1416 | class GetterRefImpl {
|
---|
1417 | constructor(_getter) {
|
---|
1418 | this._getter = _getter;
|
---|
1419 | this["__v_isRef"] = true;
|
---|
1420 | this["__v_isReadonly"] = true;
|
---|
1421 | this._value = void 0;
|
---|
1422 | }
|
---|
1423 | get value() {
|
---|
1424 | return this._value = this._getter();
|
---|
1425 | }
|
---|
1426 | }
|
---|
1427 | function toRef(source, key, defaultValue) {
|
---|
1428 | if (isRef(source)) {
|
---|
1429 | return source;
|
---|
1430 | } else if (shared.isFunction(source)) {
|
---|
1431 | return new GetterRefImpl(source);
|
---|
1432 | } else if (shared.isObject(source) && arguments.length > 1) {
|
---|
1433 | return propertyToRef(source, key, defaultValue);
|
---|
1434 | } else {
|
---|
1435 | return ref(source);
|
---|
1436 | }
|
---|
1437 | }
|
---|
1438 | function propertyToRef(source, key, defaultValue) {
|
---|
1439 | const val = source[key];
|
---|
1440 | return isRef(val) ? val : new ObjectRefImpl(source, key, defaultValue);
|
---|
1441 | }
|
---|
1442 |
|
---|
1443 | class ComputedRefImpl {
|
---|
1444 | constructor(fn, setter, isSSR) {
|
---|
1445 | this.fn = fn;
|
---|
1446 | this.setter = setter;
|
---|
1447 | /**
|
---|
1448 | * @internal
|
---|
1449 | */
|
---|
1450 | this._value = void 0;
|
---|
1451 | /**
|
---|
1452 | * @internal
|
---|
1453 | */
|
---|
1454 | this.dep = new Dep(this);
|
---|
1455 | /**
|
---|
1456 | * @internal
|
---|
1457 | */
|
---|
1458 | this.__v_isRef = true;
|
---|
1459 | // TODO isolatedDeclarations "__v_isReadonly"
|
---|
1460 | // A computed is also a subscriber that tracks other deps
|
---|
1461 | /**
|
---|
1462 | * @internal
|
---|
1463 | */
|
---|
1464 | this.deps = void 0;
|
---|
1465 | /**
|
---|
1466 | * @internal
|
---|
1467 | */
|
---|
1468 | this.depsTail = void 0;
|
---|
1469 | /**
|
---|
1470 | * @internal
|
---|
1471 | */
|
---|
1472 | this.flags = 16;
|
---|
1473 | /**
|
---|
1474 | * @internal
|
---|
1475 | */
|
---|
1476 | this.globalVersion = globalVersion - 1;
|
---|
1477 | /**
|
---|
1478 | * @internal
|
---|
1479 | */
|
---|
1480 | this.next = void 0;
|
---|
1481 | // for backwards compat
|
---|
1482 | this.effect = this;
|
---|
1483 | this["__v_isReadonly"] = !setter;
|
---|
1484 | this.isSSR = isSSR;
|
---|
1485 | }
|
---|
1486 | /**
|
---|
1487 | * @internal
|
---|
1488 | */
|
---|
1489 | notify() {
|
---|
1490 | this.flags |= 16;
|
---|
1491 | if (!(this.flags & 8) && // avoid infinite self recursion
|
---|
1492 | activeSub !== this) {
|
---|
1493 | batch(this, true);
|
---|
1494 | return true;
|
---|
1495 | }
|
---|
1496 | }
|
---|
1497 | get value() {
|
---|
1498 | const link = this.dep.track();
|
---|
1499 | refreshComputed(this);
|
---|
1500 | if (link) {
|
---|
1501 | link.version = this.dep.version;
|
---|
1502 | }
|
---|
1503 | return this._value;
|
---|
1504 | }
|
---|
1505 | set value(newValue) {
|
---|
1506 | if (this.setter) {
|
---|
1507 | this.setter(newValue);
|
---|
1508 | }
|
---|
1509 | }
|
---|
1510 | }
|
---|
1511 | function computed(getterOrOptions, debugOptions, isSSR = false) {
|
---|
1512 | let getter;
|
---|
1513 | let setter;
|
---|
1514 | if (shared.isFunction(getterOrOptions)) {
|
---|
1515 | getter = getterOrOptions;
|
---|
1516 | } else {
|
---|
1517 | getter = getterOrOptions.get;
|
---|
1518 | setter = getterOrOptions.set;
|
---|
1519 | }
|
---|
1520 | const cRef = new ComputedRefImpl(getter, setter, isSSR);
|
---|
1521 | return cRef;
|
---|
1522 | }
|
---|
1523 |
|
---|
1524 | const TrackOpTypes = {
|
---|
1525 | "GET": "get",
|
---|
1526 | "HAS": "has",
|
---|
1527 | "ITERATE": "iterate"
|
---|
1528 | };
|
---|
1529 | const TriggerOpTypes = {
|
---|
1530 | "SET": "set",
|
---|
1531 | "ADD": "add",
|
---|
1532 | "DELETE": "delete",
|
---|
1533 | "CLEAR": "clear"
|
---|
1534 | };
|
---|
1535 | const ReactiveFlags = {
|
---|
1536 | "SKIP": "__v_skip",
|
---|
1537 | "IS_REACTIVE": "__v_isReactive",
|
---|
1538 | "IS_READONLY": "__v_isReadonly",
|
---|
1539 | "IS_SHALLOW": "__v_isShallow",
|
---|
1540 | "RAW": "__v_raw",
|
---|
1541 | "IS_REF": "__v_isRef"
|
---|
1542 | };
|
---|
1543 |
|
---|
1544 | const WatchErrorCodes = {
|
---|
1545 | "WATCH_GETTER": 2,
|
---|
1546 | "2": "WATCH_GETTER",
|
---|
1547 | "WATCH_CALLBACK": 3,
|
---|
1548 | "3": "WATCH_CALLBACK",
|
---|
1549 | "WATCH_CLEANUP": 4,
|
---|
1550 | "4": "WATCH_CLEANUP"
|
---|
1551 | };
|
---|
1552 | const INITIAL_WATCHER_VALUE = {};
|
---|
1553 | const cleanupMap = /* @__PURE__ */ new WeakMap();
|
---|
1554 | let activeWatcher = void 0;
|
---|
1555 | function getCurrentWatcher() {
|
---|
1556 | return activeWatcher;
|
---|
1557 | }
|
---|
1558 | function onWatcherCleanup(cleanupFn, failSilently = false, owner = activeWatcher) {
|
---|
1559 | if (owner) {
|
---|
1560 | let cleanups = cleanupMap.get(owner);
|
---|
1561 | if (!cleanups) cleanupMap.set(owner, cleanups = []);
|
---|
1562 | cleanups.push(cleanupFn);
|
---|
1563 | }
|
---|
1564 | }
|
---|
1565 | function watch(source, cb, options = shared.EMPTY_OBJ) {
|
---|
1566 | const { immediate, deep, once, scheduler, augmentJob, call } = options;
|
---|
1567 | const reactiveGetter = (source2) => {
|
---|
1568 | if (deep) return source2;
|
---|
1569 | if (isShallow(source2) || deep === false || deep === 0)
|
---|
1570 | return traverse(source2, 1);
|
---|
1571 | return traverse(source2);
|
---|
1572 | };
|
---|
1573 | let effect;
|
---|
1574 | let getter;
|
---|
1575 | let cleanup;
|
---|
1576 | let boundCleanup;
|
---|
1577 | let forceTrigger = false;
|
---|
1578 | let isMultiSource = false;
|
---|
1579 | if (isRef(source)) {
|
---|
1580 | getter = () => source.value;
|
---|
1581 | forceTrigger = isShallow(source);
|
---|
1582 | } else if (isReactive(source)) {
|
---|
1583 | getter = () => reactiveGetter(source);
|
---|
1584 | forceTrigger = true;
|
---|
1585 | } else if (shared.isArray(source)) {
|
---|
1586 | isMultiSource = true;
|
---|
1587 | forceTrigger = source.some((s) => isReactive(s) || isShallow(s));
|
---|
1588 | getter = () => source.map((s) => {
|
---|
1589 | if (isRef(s)) {
|
---|
1590 | return s.value;
|
---|
1591 | } else if (isReactive(s)) {
|
---|
1592 | return reactiveGetter(s);
|
---|
1593 | } else if (shared.isFunction(s)) {
|
---|
1594 | return call ? call(s, 2) : s();
|
---|
1595 | } else ;
|
---|
1596 | });
|
---|
1597 | } else if (shared.isFunction(source)) {
|
---|
1598 | if (cb) {
|
---|
1599 | getter = call ? () => call(source, 2) : source;
|
---|
1600 | } else {
|
---|
1601 | getter = () => {
|
---|
1602 | if (cleanup) {
|
---|
1603 | pauseTracking();
|
---|
1604 | try {
|
---|
1605 | cleanup();
|
---|
1606 | } finally {
|
---|
1607 | resetTracking();
|
---|
1608 | }
|
---|
1609 | }
|
---|
1610 | const currentEffect = activeWatcher;
|
---|
1611 | activeWatcher = effect;
|
---|
1612 | try {
|
---|
1613 | return call ? call(source, 3, [boundCleanup]) : source(boundCleanup);
|
---|
1614 | } finally {
|
---|
1615 | activeWatcher = currentEffect;
|
---|
1616 | }
|
---|
1617 | };
|
---|
1618 | }
|
---|
1619 | } else {
|
---|
1620 | getter = shared.NOOP;
|
---|
1621 | }
|
---|
1622 | if (cb && deep) {
|
---|
1623 | const baseGetter = getter;
|
---|
1624 | const depth = deep === true ? Infinity : deep;
|
---|
1625 | getter = () => traverse(baseGetter(), depth);
|
---|
1626 | }
|
---|
1627 | const scope = getCurrentScope();
|
---|
1628 | const watchHandle = () => {
|
---|
1629 | effect.stop();
|
---|
1630 | if (scope && scope.active) {
|
---|
1631 | shared.remove(scope.effects, effect);
|
---|
1632 | }
|
---|
1633 | };
|
---|
1634 | if (once && cb) {
|
---|
1635 | const _cb = cb;
|
---|
1636 | cb = (...args) => {
|
---|
1637 | _cb(...args);
|
---|
1638 | watchHandle();
|
---|
1639 | };
|
---|
1640 | }
|
---|
1641 | let oldValue = isMultiSource ? new Array(source.length).fill(INITIAL_WATCHER_VALUE) : INITIAL_WATCHER_VALUE;
|
---|
1642 | const job = (immediateFirstRun) => {
|
---|
1643 | if (!(effect.flags & 1) || !effect.dirty && !immediateFirstRun) {
|
---|
1644 | return;
|
---|
1645 | }
|
---|
1646 | if (cb) {
|
---|
1647 | const newValue = effect.run();
|
---|
1648 | if (deep || forceTrigger || (isMultiSource ? newValue.some((v, i) => shared.hasChanged(v, oldValue[i])) : shared.hasChanged(newValue, oldValue))) {
|
---|
1649 | if (cleanup) {
|
---|
1650 | cleanup();
|
---|
1651 | }
|
---|
1652 | const currentWatcher = activeWatcher;
|
---|
1653 | activeWatcher = effect;
|
---|
1654 | try {
|
---|
1655 | const args = [
|
---|
1656 | newValue,
|
---|
1657 | // pass undefined as the old value when it's changed for the first time
|
---|
1658 | oldValue === INITIAL_WATCHER_VALUE ? void 0 : isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE ? [] : oldValue,
|
---|
1659 | boundCleanup
|
---|
1660 | ];
|
---|
1661 | call ? call(cb, 3, args) : (
|
---|
1662 | // @ts-expect-error
|
---|
1663 | cb(...args)
|
---|
1664 | );
|
---|
1665 | oldValue = newValue;
|
---|
1666 | } finally {
|
---|
1667 | activeWatcher = currentWatcher;
|
---|
1668 | }
|
---|
1669 | }
|
---|
1670 | } else {
|
---|
1671 | effect.run();
|
---|
1672 | }
|
---|
1673 | };
|
---|
1674 | if (augmentJob) {
|
---|
1675 | augmentJob(job);
|
---|
1676 | }
|
---|
1677 | effect = new ReactiveEffect(getter);
|
---|
1678 | effect.scheduler = scheduler ? () => scheduler(job, false) : job;
|
---|
1679 | boundCleanup = (fn) => onWatcherCleanup(fn, false, effect);
|
---|
1680 | cleanup = effect.onStop = () => {
|
---|
1681 | const cleanups = cleanupMap.get(effect);
|
---|
1682 | if (cleanups) {
|
---|
1683 | if (call) {
|
---|
1684 | call(cleanups, 4);
|
---|
1685 | } else {
|
---|
1686 | for (const cleanup2 of cleanups) cleanup2();
|
---|
1687 | }
|
---|
1688 | cleanupMap.delete(effect);
|
---|
1689 | }
|
---|
1690 | };
|
---|
1691 | if (cb) {
|
---|
1692 | if (immediate) {
|
---|
1693 | job(true);
|
---|
1694 | } else {
|
---|
1695 | oldValue = effect.run();
|
---|
1696 | }
|
---|
1697 | } else if (scheduler) {
|
---|
1698 | scheduler(job.bind(null, true), true);
|
---|
1699 | } else {
|
---|
1700 | effect.run();
|
---|
1701 | }
|
---|
1702 | watchHandle.pause = effect.pause.bind(effect);
|
---|
1703 | watchHandle.resume = effect.resume.bind(effect);
|
---|
1704 | watchHandle.stop = watchHandle;
|
---|
1705 | return watchHandle;
|
---|
1706 | }
|
---|
1707 | function traverse(value, depth = Infinity, seen) {
|
---|
1708 | if (depth <= 0 || !shared.isObject(value) || value["__v_skip"]) {
|
---|
1709 | return value;
|
---|
1710 | }
|
---|
1711 | seen = seen || /* @__PURE__ */ new Set();
|
---|
1712 | if (seen.has(value)) {
|
---|
1713 | return value;
|
---|
1714 | }
|
---|
1715 | seen.add(value);
|
---|
1716 | depth--;
|
---|
1717 | if (isRef(value)) {
|
---|
1718 | traverse(value.value, depth, seen);
|
---|
1719 | } else if (shared.isArray(value)) {
|
---|
1720 | for (let i = 0; i < value.length; i++) {
|
---|
1721 | traverse(value[i], depth, seen);
|
---|
1722 | }
|
---|
1723 | } else if (shared.isSet(value) || shared.isMap(value)) {
|
---|
1724 | value.forEach((v) => {
|
---|
1725 | traverse(v, depth, seen);
|
---|
1726 | });
|
---|
1727 | } else if (shared.isPlainObject(value)) {
|
---|
1728 | for (const key in value) {
|
---|
1729 | traverse(value[key], depth, seen);
|
---|
1730 | }
|
---|
1731 | for (const key of Object.getOwnPropertySymbols(value)) {
|
---|
1732 | if (Object.prototype.propertyIsEnumerable.call(value, key)) {
|
---|
1733 | traverse(value[key], depth, seen);
|
---|
1734 | }
|
---|
1735 | }
|
---|
1736 | }
|
---|
1737 | return value;
|
---|
1738 | }
|
---|
1739 |
|
---|
1740 | exports.ARRAY_ITERATE_KEY = ARRAY_ITERATE_KEY;
|
---|
1741 | exports.EffectFlags = EffectFlags;
|
---|
1742 | exports.EffectScope = EffectScope;
|
---|
1743 | exports.ITERATE_KEY = ITERATE_KEY;
|
---|
1744 | exports.MAP_KEY_ITERATE_KEY = MAP_KEY_ITERATE_KEY;
|
---|
1745 | exports.ReactiveEffect = ReactiveEffect;
|
---|
1746 | exports.ReactiveFlags = ReactiveFlags;
|
---|
1747 | exports.TrackOpTypes = TrackOpTypes;
|
---|
1748 | exports.TriggerOpTypes = TriggerOpTypes;
|
---|
1749 | exports.WatchErrorCodes = WatchErrorCodes;
|
---|
1750 | exports.computed = computed;
|
---|
1751 | exports.customRef = customRef;
|
---|
1752 | exports.effect = effect;
|
---|
1753 | exports.effectScope = effectScope;
|
---|
1754 | exports.enableTracking = enableTracking;
|
---|
1755 | exports.getCurrentScope = getCurrentScope;
|
---|
1756 | exports.getCurrentWatcher = getCurrentWatcher;
|
---|
1757 | exports.isProxy = isProxy;
|
---|
1758 | exports.isReactive = isReactive;
|
---|
1759 | exports.isReadonly = isReadonly;
|
---|
1760 | exports.isRef = isRef;
|
---|
1761 | exports.isShallow = isShallow;
|
---|
1762 | exports.markRaw = markRaw;
|
---|
1763 | exports.onEffectCleanup = onEffectCleanup;
|
---|
1764 | exports.onScopeDispose = onScopeDispose;
|
---|
1765 | exports.onWatcherCleanup = onWatcherCleanup;
|
---|
1766 | exports.pauseTracking = pauseTracking;
|
---|
1767 | exports.proxyRefs = proxyRefs;
|
---|
1768 | exports.reactive = reactive;
|
---|
1769 | exports.reactiveReadArray = reactiveReadArray;
|
---|
1770 | exports.readonly = readonly;
|
---|
1771 | exports.ref = ref;
|
---|
1772 | exports.resetTracking = resetTracking;
|
---|
1773 | exports.shallowReactive = shallowReactive;
|
---|
1774 | exports.shallowReadArray = shallowReadArray;
|
---|
1775 | exports.shallowReadonly = shallowReadonly;
|
---|
1776 | exports.shallowRef = shallowRef;
|
---|
1777 | exports.stop = stop;
|
---|
1778 | exports.toRaw = toRaw;
|
---|
1779 | exports.toReactive = toReactive;
|
---|
1780 | exports.toReadonly = toReadonly;
|
---|
1781 | exports.toRef = toRef;
|
---|
1782 | exports.toRefs = toRefs;
|
---|
1783 | exports.toValue = toValue;
|
---|
1784 | exports.track = track;
|
---|
1785 | exports.traverse = traverse;
|
---|
1786 | exports.trigger = trigger;
|
---|
1787 | exports.triggerRef = triggerRef;
|
---|
1788 | exports.unref = unref;
|
---|
1789 | exports.watch = watch;
|
---|