@vue-mini/core 1.0.3 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * vue-mini v1.0.3
2
+ * vue-mini v1.1.0
3
3
  * https://github.com/vue-mini/vue-mini
4
4
  * (c) 2019-present Yang Mingshan
5
5
  * @license MIT
@@ -7,23 +7,33 @@
7
7
  'use strict';
8
8
 
9
9
  /**
10
- * @vue/shared v3.4.37
10
+ * @vue/shared v3.5.5
11
11
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
12
12
  * @license MIT
13
13
  **/
14
14
  /*! #__NO_SIDE_EFFECTS__ */
15
15
  // @__NO_SIDE_EFFECTS__
16
- function makeMap(str, expectsLowerCase) {
17
- const set = new Set(str.split(","));
18
- return (val) => set.has(val);
16
+ function makeMap(str) {
17
+ const map = /* @__PURE__ */ Object.create(null);
18
+ for (const key of str.split(",")) map[key] = 1;
19
+ return (val) => val in map;
19
20
  }
20
- const NOOP$1 = () => {
21
+
22
+ const EMPTY_OBJ$1 = Object.freeze({}) ;
23
+ const NOOP = () => {
21
24
  };
22
25
  const extend$1 = Object.assign;
26
+ const remove = (arr, el) => {
27
+ const i = arr.indexOf(el);
28
+ if (i > -1) {
29
+ arr.splice(i, 1);
30
+ }
31
+ };
23
32
  const hasOwnProperty$1 = Object.prototype.hasOwnProperty;
24
33
  const hasOwn = (val, key) => hasOwnProperty$1.call(val, key);
25
34
  const isArray$1 = Array.isArray;
26
- const isMap$1 = (val) => toTypeString(val) === "[object Map]";
35
+ const isMap = (val) => toTypeString(val) === "[object Map]";
36
+ const isSet = (val) => toTypeString(val) === "[object Set]";
27
37
  const isFunction$1 = (val) => typeof val === "function";
28
38
  const isString = (val) => typeof val === "string";
29
39
  const isSymbol = (val) => typeof val === "symbol";
@@ -33,6 +43,7 @@ const toTypeString = (value) => objectToString.call(value);
33
43
  const toRawType = (value) => {
34
44
  return toTypeString(value).slice(8, -1);
35
45
  };
46
+ const isPlainObject$1 = (val) => toTypeString(val) === "[object Object]";
36
47
  const isIntegerKey = (key) => isString(key) && key !== "NaN" && key[0] !== "-" && "" + parseInt(key, 10) === key;
37
48
  const cacheStringFunction = (fn) => {
38
49
  const cache = /* @__PURE__ */ Object.create(null);
@@ -44,7 +55,7 @@ const cacheStringFunction = (fn) => {
44
55
  const capitalize = cacheStringFunction((str) => {
45
56
  return str.charAt(0).toUpperCase() + str.slice(1);
46
57
  });
47
- const hasChanged$1 = (value, oldValue) => !Object.is(value, oldValue);
58
+ const hasChanged = (value, oldValue) => !Object.is(value, oldValue);
48
59
  const def = (obj, key, value, writable = false) => {
49
60
  Object.defineProperty(obj, key, {
50
61
  configurable: true,
@@ -55,7 +66,7 @@ const def = (obj, key, value, writable = false) => {
55
66
  };
56
67
 
57
68
  /**
58
- * @vue/reactivity v3.4.37
69
+ * @vue/reactivity v3.5.5
59
70
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
60
71
  * @license MIT
61
72
  **/
@@ -80,6 +91,7 @@ class EffectScope {
80
91
  * @internal
81
92
  */
82
93
  this.cleanups = [];
94
+ this._isPaused = false;
83
95
  this.parent = activeEffectScope;
84
96
  if (!detached && activeEffectScope) {
85
97
  this.index = (activeEffectScope.scopes || (activeEffectScope.scopes = [])).push(
@@ -90,6 +102,39 @@ class EffectScope {
90
102
  get active() {
91
103
  return this._active;
92
104
  }
105
+ pause() {
106
+ if (this._active) {
107
+ this._isPaused = true;
108
+ let i, l;
109
+ if (this.scopes) {
110
+ for (i = 0, l = this.scopes.length; i < l; i++) {
111
+ this.scopes[i].pause();
112
+ }
113
+ }
114
+ for (i = 0, l = this.effects.length; i < l; i++) {
115
+ this.effects[i].pause();
116
+ }
117
+ }
118
+ }
119
+ /**
120
+ * Resumes the effect scope, including all child scopes and effects.
121
+ */
122
+ resume() {
123
+ if (this._active) {
124
+ if (this._isPaused) {
125
+ this._isPaused = false;
126
+ let i, l;
127
+ if (this.scopes) {
128
+ for (i = 0, l = this.scopes.length; i < l; i++) {
129
+ this.scopes[i].resume();
130
+ }
131
+ }
132
+ for (i = 0, l = this.effects.length; i < l; i++) {
133
+ this.effects[i].resume();
134
+ }
135
+ }
136
+ }
137
+ }
93
138
  run(fn) {
94
139
  if (this._active) {
95
140
  const currentEffectScope = activeEffectScope;
@@ -146,155 +191,287 @@ class EffectScope {
146
191
  function effectScope(detached) {
147
192
  return new EffectScope(detached);
148
193
  }
149
- function recordEffectScope(effect, scope = activeEffectScope) {
150
- if (scope && scope.active) {
151
- scope.effects.push(effect);
152
- }
153
- }
154
194
  function getCurrentScope() {
155
195
  return activeEffectScope;
156
196
  }
157
- function onScopeDispose(fn) {
197
+ function onScopeDispose(fn, failSilently = false) {
158
198
  if (activeEffectScope) {
159
199
  activeEffectScope.cleanups.push(fn);
160
- } else {
200
+ } else if (!failSilently) {
161
201
  warn(
162
202
  `onScopeDispose() is called when there is no active effect scope to be associated with.`
163
203
  );
164
204
  }
165
205
  }
166
206
 
167
- let activeEffect;
207
+ let activeSub;
208
+ const pausedQueueEffects = /* @__PURE__ */ new WeakSet();
168
209
  class ReactiveEffect {
169
- constructor(fn, trigger, scheduler, scope) {
210
+ constructor(fn) {
170
211
  this.fn = fn;
171
- this.trigger = trigger;
172
- this.scheduler = scheduler;
173
- this.active = true;
174
- this.deps = [];
175
212
  /**
176
213
  * @internal
177
214
  */
178
- this._dirtyLevel = 4;
215
+ this.deps = void 0;
179
216
  /**
180
217
  * @internal
181
218
  */
182
- this._trackId = 0;
219
+ this.depsTail = void 0;
183
220
  /**
184
221
  * @internal
185
222
  */
186
- this._runnings = 0;
223
+ this.flags = 1 | 4;
187
224
  /**
188
225
  * @internal
189
226
  */
190
- this._shouldSchedule = false;
227
+ this.nextEffect = void 0;
191
228
  /**
192
229
  * @internal
193
230
  */
194
- this._depsLength = 0;
195
- recordEffectScope(this, scope);
231
+ this.cleanup = void 0;
232
+ this.scheduler = void 0;
233
+ if (activeEffectScope && activeEffectScope.active) {
234
+ activeEffectScope.effects.push(this);
235
+ }
196
236
  }
197
- get dirty() {
198
- if (this._dirtyLevel === 2 || this._dirtyLevel === 3) {
199
- this._dirtyLevel = 1;
200
- pauseTracking();
201
- for (let i = 0; i < this._depsLength; i++) {
202
- const dep = this.deps[i];
203
- if (dep.computed) {
204
- triggerComputed(dep.computed);
205
- if (this._dirtyLevel >= 4) {
206
- break;
207
- }
208
- }
209
- }
210
- if (this._dirtyLevel === 1) {
211
- this._dirtyLevel = 0;
237
+ pause() {
238
+ this.flags |= 64;
239
+ }
240
+ resume() {
241
+ if (this.flags & 64) {
242
+ this.flags &= ~64;
243
+ if (pausedQueueEffects.has(this)) {
244
+ pausedQueueEffects.delete(this);
245
+ this.trigger();
212
246
  }
213
- resetTracking();
214
247
  }
215
- return this._dirtyLevel >= 4;
216
248
  }
217
- set dirty(v) {
218
- this._dirtyLevel = v ? 4 : 0;
249
+ /**
250
+ * @internal
251
+ */
252
+ notify() {
253
+ if (this.flags & 2 && !(this.flags & 32)) {
254
+ return;
255
+ }
256
+ if (!(this.flags & 8)) {
257
+ this.flags |= 8;
258
+ this.nextEffect = batchedEffect;
259
+ batchedEffect = this;
260
+ }
219
261
  }
220
262
  run() {
221
- this._dirtyLevel = 0;
222
- if (!this.active) {
263
+ if (!(this.flags & 1)) {
223
264
  return this.fn();
224
265
  }
225
- let lastShouldTrack = shouldTrack;
226
- let lastEffect = activeEffect;
266
+ this.flags |= 2;
267
+ cleanupEffect(this);
268
+ prepareDeps(this);
269
+ const prevEffect = activeSub;
270
+ const prevShouldTrack = shouldTrack;
271
+ activeSub = this;
272
+ shouldTrack = true;
227
273
  try {
228
- shouldTrack = true;
229
- activeEffect = this;
230
- this._runnings++;
231
- preCleanupEffect(this);
232
274
  return this.fn();
233
275
  } finally {
234
- postCleanupEffect(this);
235
- this._runnings--;
236
- activeEffect = lastEffect;
237
- shouldTrack = lastShouldTrack;
276
+ if (activeSub !== this) {
277
+ warn(
278
+ "Active effect was not restored correctly - this is likely a Vue internal bug."
279
+ );
280
+ }
281
+ cleanupDeps(this);
282
+ activeSub = prevEffect;
283
+ shouldTrack = prevShouldTrack;
284
+ this.flags &= ~2;
238
285
  }
239
286
  }
240
287
  stop() {
241
- if (this.active) {
242
- preCleanupEffect(this);
243
- postCleanupEffect(this);
288
+ if (this.flags & 1) {
289
+ for (let link = this.deps; link; link = link.nextDep) {
290
+ removeSub(link);
291
+ }
292
+ this.deps = this.depsTail = void 0;
293
+ cleanupEffect(this);
244
294
  this.onStop && this.onStop();
245
- this.active = false;
295
+ this.flags &= ~1;
246
296
  }
247
297
  }
298
+ trigger() {
299
+ if (this.flags & 64) {
300
+ pausedQueueEffects.add(this);
301
+ } else if (this.scheduler) {
302
+ this.scheduler();
303
+ } else {
304
+ this.runIfDirty();
305
+ }
306
+ }
307
+ /**
308
+ * @internal
309
+ */
310
+ runIfDirty() {
311
+ if (isDirty(this)) {
312
+ this.run();
313
+ }
314
+ }
315
+ get dirty() {
316
+ return isDirty(this);
317
+ }
248
318
  }
249
- function triggerComputed(computed) {
250
- return computed.value;
319
+ let batchDepth = 0;
320
+ let batchedEffect;
321
+ function startBatch() {
322
+ batchDepth++;
251
323
  }
252
- function preCleanupEffect(effect2) {
253
- effect2._trackId++;
254
- effect2._depsLength = 0;
324
+ function endBatch() {
325
+ if (--batchDepth > 0) {
326
+ return;
327
+ }
328
+ let error;
329
+ while (batchedEffect) {
330
+ let e = batchedEffect;
331
+ batchedEffect = void 0;
332
+ while (e) {
333
+ const next = e.nextEffect;
334
+ e.nextEffect = void 0;
335
+ e.flags &= ~8;
336
+ if (e.flags & 1) {
337
+ try {
338
+ e.trigger();
339
+ } catch (err) {
340
+ if (!error) error = err;
341
+ }
342
+ }
343
+ e = next;
344
+ }
345
+ }
346
+ if (error) throw error;
347
+ }
348
+ function prepareDeps(sub) {
349
+ for (let link = sub.deps; link; link = link.nextDep) {
350
+ link.version = -1;
351
+ link.prevActiveLink = link.dep.activeLink;
352
+ link.dep.activeLink = link;
353
+ }
255
354
  }
256
- function postCleanupEffect(effect2) {
257
- if (effect2.deps.length > effect2._depsLength) {
258
- for (let i = effect2._depsLength; i < effect2.deps.length; i++) {
259
- cleanupDepEffect(effect2.deps[i], effect2);
355
+ function cleanupDeps(sub) {
356
+ let head;
357
+ let tail = sub.depsTail;
358
+ let link = tail;
359
+ while (link) {
360
+ const prev = link.prevDep;
361
+ if (link.version === -1) {
362
+ if (link === tail) tail = prev;
363
+ removeSub(link);
364
+ removeDep(link);
365
+ } else {
366
+ head = link;
260
367
  }
261
- effect2.deps.length = effect2._depsLength;
368
+ link.dep.activeLink = link.prevActiveLink;
369
+ link.prevActiveLink = void 0;
370
+ link = prev;
262
371
  }
372
+ sub.deps = head;
373
+ sub.depsTail = tail;
263
374
  }
264
- function cleanupDepEffect(dep, effect2) {
265
- const trackId = dep.get(effect2);
266
- if (trackId !== void 0 && effect2._trackId !== trackId) {
267
- dep.delete(effect2);
268
- if (dep.size === 0) {
269
- dep.cleanup();
375
+ function isDirty(sub) {
376
+ for (let link = sub.deps; link; link = link.nextDep) {
377
+ if (link.dep.version !== link.version || link.dep.computed && refreshComputed(link.dep.computed) || link.dep.version !== link.version) {
378
+ return true;
270
379
  }
271
380
  }
381
+ if (sub._dirty) {
382
+ return true;
383
+ }
384
+ return false;
385
+ }
386
+ function refreshComputed(computed) {
387
+ if (computed.flags & 4 && !(computed.flags & 16)) {
388
+ return;
389
+ }
390
+ computed.flags &= ~16;
391
+ if (computed.globalVersion === globalVersion) {
392
+ return;
393
+ }
394
+ computed.globalVersion = globalVersion;
395
+ const dep = computed.dep;
396
+ computed.flags |= 2;
397
+ if (dep.version > 0 && !computed.isSSR && !isDirty(computed)) {
398
+ computed.flags &= ~2;
399
+ return;
400
+ }
401
+ const prevSub = activeSub;
402
+ const prevShouldTrack = shouldTrack;
403
+ activeSub = computed;
404
+ shouldTrack = true;
405
+ try {
406
+ prepareDeps(computed);
407
+ const value = computed.fn(computed._value);
408
+ if (dep.version === 0 || hasChanged(value, computed._value)) {
409
+ computed._value = value;
410
+ dep.version++;
411
+ }
412
+ } catch (err) {
413
+ dep.version++;
414
+ throw err;
415
+ } finally {
416
+ activeSub = prevSub;
417
+ shouldTrack = prevShouldTrack;
418
+ cleanupDeps(computed);
419
+ computed.flags &= ~2;
420
+ }
421
+ }
422
+ function removeSub(link) {
423
+ const { dep, prevSub, nextSub } = link;
424
+ if (prevSub) {
425
+ prevSub.nextSub = nextSub;
426
+ link.prevSub = void 0;
427
+ }
428
+ if (nextSub) {
429
+ nextSub.prevSub = prevSub;
430
+ link.nextSub = void 0;
431
+ }
432
+ if (dep.subs === link) {
433
+ dep.subs = prevSub;
434
+ }
435
+ if (!dep.subs && dep.computed) {
436
+ dep.computed.flags &= ~4;
437
+ for (let l = dep.computed.deps; l; l = l.nextDep) {
438
+ removeSub(l);
439
+ }
440
+ }
441
+ }
442
+ function removeDep(link) {
443
+ const { prevDep, nextDep } = link;
444
+ if (prevDep) {
445
+ prevDep.nextDep = nextDep;
446
+ link.prevDep = void 0;
447
+ }
448
+ if (nextDep) {
449
+ nextDep.prevDep = prevDep;
450
+ link.nextDep = void 0;
451
+ }
272
452
  }
273
453
  function effect(fn, options) {
274
454
  if (fn.effect instanceof ReactiveEffect) {
275
455
  fn = fn.effect.fn;
276
456
  }
277
- const _effect = new ReactiveEffect(fn, NOOP$1, () => {
278
- if (_effect.dirty) {
279
- _effect.run();
280
- }
281
- });
457
+ const e = new ReactiveEffect(fn);
282
458
  if (options) {
283
- extend$1(_effect, options);
284
- if (options.scope) recordEffectScope(_effect, options.scope);
459
+ extend$1(e, options);
285
460
  }
286
- if (!options || !options.lazy) {
287
- _effect.run();
461
+ try {
462
+ e.run();
463
+ } catch (err) {
464
+ e.stop();
465
+ throw err;
288
466
  }
289
- const runner = _effect.run.bind(_effect);
290
- runner.effect = _effect;
467
+ const runner = e.run.bind(e);
468
+ runner.effect = e;
291
469
  return runner;
292
470
  }
293
471
  function stop(runner) {
294
472
  runner.effect.stop();
295
473
  }
296
474
  let shouldTrack = true;
297
- let pauseScheduleStack = 0;
298
475
  const trackStack = [];
299
476
  function pauseTracking() {
300
477
  trackStack.push(shouldTrack);
@@ -304,192 +481,422 @@ function resetTracking() {
304
481
  const last = trackStack.pop();
305
482
  shouldTrack = last === void 0 ? true : last;
306
483
  }
307
- function pauseScheduling() {
308
- pauseScheduleStack++;
309
- }
310
- function resetScheduling() {
311
- pauseScheduleStack--;
312
- while (!pauseScheduleStack && queueEffectSchedulers.length) {
313
- queueEffectSchedulers.shift()();
484
+ function cleanupEffect(e) {
485
+ const { cleanup } = e;
486
+ e.cleanup = void 0;
487
+ if (cleanup) {
488
+ const prevSub = activeSub;
489
+ activeSub = void 0;
490
+ try {
491
+ cleanup();
492
+ } finally {
493
+ activeSub = prevSub;
494
+ }
314
495
  }
315
496
  }
316
- function trackEffect(effect2, dep, debuggerEventExtraInfo) {
317
- var _a;
318
- if (dep.get(effect2) !== effect2._trackId) {
319
- dep.set(effect2, effect2._trackId);
320
- const oldDep = effect2.deps[effect2._depsLength];
321
- if (oldDep !== dep) {
322
- if (oldDep) {
323
- cleanupDepEffect(oldDep, effect2);
324
- }
325
- effect2.deps[effect2._depsLength++] = dep;
326
- } else {
327
- effect2._depsLength++;
328
- }
497
+
498
+ let globalVersion = 0;
499
+ class Link {
500
+ constructor(sub, dep) {
501
+ this.sub = sub;
502
+ this.dep = dep;
503
+ this.version = dep.version;
504
+ this.nextDep = this.prevDep = this.nextSub = this.prevSub = this.prevActiveLink = void 0;
505
+ }
506
+ }
507
+ class Dep {
508
+ constructor(computed) {
509
+ this.computed = computed;
510
+ this.version = 0;
511
+ /**
512
+ * Link between this dep and the current active effect
513
+ */
514
+ this.activeLink = void 0;
515
+ /**
516
+ * Doubly linked list representing the subscribing effects (tail)
517
+ */
518
+ this.subs = void 0;
329
519
  {
330
- (_a = effect2.onTrack) == null ? void 0 : _a.call(effect2, extend$1({ effect: effect2 }, debuggerEventExtraInfo));
520
+ this.subsHead = void 0;
331
521
  }
332
522
  }
333
- }
334
- const queueEffectSchedulers = [];
335
- function triggerEffects(dep, dirtyLevel, debuggerEventExtraInfo) {
336
- var _a;
337
- pauseScheduling();
338
- for (const effect2 of dep.keys()) {
339
- let tracking;
340
- if (effect2._dirtyLevel < dirtyLevel && (tracking != null ? tracking : tracking = dep.get(effect2) === effect2._trackId)) {
341
- effect2._shouldSchedule || (effect2._shouldSchedule = effect2._dirtyLevel === 0);
342
- effect2._dirtyLevel = dirtyLevel;
343
- }
344
- if (effect2._shouldSchedule && (tracking != null ? tracking : tracking = dep.get(effect2) === effect2._trackId)) {
345
- {
346
- (_a = effect2.onTrigger) == null ? void 0 : _a.call(effect2, extend$1({ effect: effect2 }, debuggerEventExtraInfo));
523
+ track(debugInfo) {
524
+ if (!activeSub || !shouldTrack || activeSub === this.computed) {
525
+ return;
526
+ }
527
+ let link = this.activeLink;
528
+ if (link === void 0 || link.sub !== activeSub) {
529
+ link = this.activeLink = new Link(activeSub, this);
530
+ if (!activeSub.deps) {
531
+ activeSub.deps = activeSub.depsTail = link;
532
+ } else {
533
+ link.prevDep = activeSub.depsTail;
534
+ activeSub.depsTail.nextDep = link;
535
+ activeSub.depsTail = link;
536
+ }
537
+ if (activeSub.flags & 4) {
538
+ addSub(link);
347
539
  }
348
- effect2.trigger();
349
- if ((!effect2._runnings || effect2.allowRecurse) && effect2._dirtyLevel !== 2) {
350
- effect2._shouldSchedule = false;
351
- if (effect2.scheduler) {
352
- queueEffectSchedulers.push(effect2.scheduler);
540
+ } else if (link.version === -1) {
541
+ link.version = this.version;
542
+ if (link.nextDep) {
543
+ const next = link.nextDep;
544
+ next.prevDep = link.prevDep;
545
+ if (link.prevDep) {
546
+ link.prevDep.nextDep = next;
547
+ }
548
+ link.prevDep = activeSub.depsTail;
549
+ link.nextDep = void 0;
550
+ activeSub.depsTail.nextDep = link;
551
+ activeSub.depsTail = link;
552
+ if (activeSub.deps === link) {
553
+ activeSub.deps = next;
554
+ }
555
+ }
556
+ }
557
+ if (activeSub.onTrack) {
558
+ activeSub.onTrack(
559
+ extend$1(
560
+ {
561
+ effect: activeSub
562
+ },
563
+ debugInfo
564
+ )
565
+ );
566
+ }
567
+ return link;
568
+ }
569
+ trigger(debugInfo) {
570
+ this.version++;
571
+ globalVersion++;
572
+ this.notify(debugInfo);
573
+ }
574
+ notify(debugInfo) {
575
+ startBatch();
576
+ try {
577
+ if (!!("development" !== "production")) {
578
+ for (let head = this.subsHead; head; head = head.nextSub) {
579
+ if (!!("development" !== "production") && head.sub.onTrigger && !(head.sub.flags & 8)) {
580
+ head.sub.onTrigger(
581
+ extend$1(
582
+ {
583
+ effect: head.sub
584
+ },
585
+ debugInfo
586
+ )
587
+ );
588
+ }
353
589
  }
354
590
  }
591
+ for (let link = this.subs; link; link = link.prevSub) {
592
+ link.sub.notify();
593
+ }
594
+ } finally {
595
+ endBatch();
355
596
  }
356
597
  }
357
- resetScheduling();
358
598
  }
359
-
360
- const createDep = (cleanup, computed) => {
361
- const dep = /* @__PURE__ */ new Map();
362
- dep.cleanup = cleanup;
363
- dep.computed = computed;
364
- return dep;
365
- };
366
-
599
+ function addSub(link) {
600
+ const computed = link.dep.computed;
601
+ if (computed && !link.dep.subs) {
602
+ computed.flags |= 4 | 16;
603
+ for (let l = computed.deps; l; l = l.nextDep) {
604
+ addSub(l);
605
+ }
606
+ }
607
+ const currentTail = link.dep.subs;
608
+ if (currentTail !== link) {
609
+ link.prevSub = currentTail;
610
+ if (currentTail) currentTail.nextSub = link;
611
+ }
612
+ if (link.dep.subsHead === void 0) {
613
+ link.dep.subsHead = link;
614
+ }
615
+ link.dep.subs = link;
616
+ }
367
617
  const targetMap = /* @__PURE__ */ new WeakMap();
368
- const ITERATE_KEY = Symbol("iterate" );
369
- const MAP_KEY_ITERATE_KEY = Symbol("Map key iterate" );
618
+ const ITERATE_KEY = Symbol(
619
+ "Object iterate"
620
+ );
621
+ const MAP_KEY_ITERATE_KEY = Symbol(
622
+ "Map keys iterate"
623
+ );
624
+ const ARRAY_ITERATE_KEY = Symbol(
625
+ "Array iterate"
626
+ );
370
627
  function track(target, type, key) {
371
- if (shouldTrack && activeEffect) {
628
+ if (shouldTrack && activeSub) {
372
629
  let depsMap = targetMap.get(target);
373
630
  if (!depsMap) {
374
631
  targetMap.set(target, depsMap = /* @__PURE__ */ new Map());
375
632
  }
376
633
  let dep = depsMap.get(key);
377
634
  if (!dep) {
378
- depsMap.set(key, dep = createDep(() => depsMap.delete(key)));
635
+ depsMap.set(key, dep = new Dep());
379
636
  }
380
- trackEffect(
381
- activeEffect,
382
- dep,
383
- {
637
+ {
638
+ dep.track({
384
639
  target,
385
640
  type,
386
641
  key
387
- }
388
- );
642
+ });
643
+ }
389
644
  }
390
645
  }
391
646
  function trigger(target, type, key, newValue, oldValue, oldTarget) {
392
647
  const depsMap = targetMap.get(target);
393
648
  if (!depsMap) {
649
+ globalVersion++;
394
650
  return;
395
651
  }
396
- let deps = [];
397
- if (type === "clear") {
398
- deps = [...depsMap.values()];
399
- } else if (key === "length" && isArray$1(target)) {
400
- const newLength = Number(newValue);
401
- depsMap.forEach((dep, key2) => {
402
- if (key2 === "length" || !isSymbol(key2) && key2 >= newLength) {
403
- deps.push(dep);
404
- }
405
- });
406
- } else {
407
- if (key !== void 0) {
408
- deps.push(depsMap.get(key));
409
- }
410
- switch (type) {
411
- case "add":
412
- if (!isArray$1(target)) {
413
- deps.push(depsMap.get(ITERATE_KEY));
414
- if (isMap$1(target)) {
415
- deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
416
- }
417
- } else if (isIntegerKey(key)) {
418
- deps.push(depsMap.get("length"));
419
- }
420
- break;
421
- case "delete":
422
- if (!isArray$1(target)) {
423
- deps.push(depsMap.get(ITERATE_KEY));
424
- if (isMap$1(target)) {
425
- deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
426
- }
427
- }
428
- break;
429
- case "set":
430
- if (isMap$1(target)) {
431
- deps.push(depsMap.get(ITERATE_KEY));
432
- }
433
- break;
434
- }
435
- }
436
- pauseScheduling();
437
- for (const dep of deps) {
652
+ const run = (dep) => {
438
653
  if (dep) {
439
- triggerEffects(
440
- dep,
441
- 4,
442
- {
654
+ {
655
+ dep.trigger({
443
656
  target,
444
657
  type,
445
658
  key,
446
659
  newValue,
447
660
  oldValue,
448
661
  oldTarget
449
- }
450
- );
662
+ });
663
+ }
664
+ }
665
+ };
666
+ startBatch();
667
+ if (type === "clear") {
668
+ depsMap.forEach(run);
669
+ } else {
670
+ const targetIsArray = isArray$1(target);
671
+ const isArrayIndex = targetIsArray && isIntegerKey(key);
672
+ if (targetIsArray && key === "length") {
673
+ const newLength = Number(newValue);
674
+ depsMap.forEach((dep, key2) => {
675
+ if (key2 === "length" || key2 === ARRAY_ITERATE_KEY || !isSymbol(key2) && key2 >= newLength) {
676
+ run(dep);
677
+ }
678
+ });
679
+ } else {
680
+ if (key !== void 0) {
681
+ run(depsMap.get(key));
682
+ }
683
+ if (isArrayIndex) {
684
+ run(depsMap.get(ARRAY_ITERATE_KEY));
685
+ }
686
+ switch (type) {
687
+ case "add":
688
+ if (!targetIsArray) {
689
+ run(depsMap.get(ITERATE_KEY));
690
+ if (isMap(target)) {
691
+ run(depsMap.get(MAP_KEY_ITERATE_KEY));
692
+ }
693
+ } else if (isArrayIndex) {
694
+ run(depsMap.get("length"));
695
+ }
696
+ break;
697
+ case "delete":
698
+ if (!targetIsArray) {
699
+ run(depsMap.get(ITERATE_KEY));
700
+ if (isMap(target)) {
701
+ run(depsMap.get(MAP_KEY_ITERATE_KEY));
702
+ }
703
+ }
704
+ break;
705
+ case "set":
706
+ if (isMap(target)) {
707
+ run(depsMap.get(ITERATE_KEY));
708
+ }
709
+ break;
710
+ }
451
711
  }
452
712
  }
453
- resetScheduling();
713
+ endBatch();
454
714
  }
455
715
  function getDepFromReactive(object, key) {
456
- const depsMap = targetMap.get(object);
457
- return depsMap && depsMap.get(key);
716
+ var _a;
717
+ return (_a = targetMap.get(object)) == null ? void 0 : _a.get(key);
718
+ }
719
+
720
+ function reactiveReadArray(array) {
721
+ const raw = toRaw(array);
722
+ if (raw === array) return raw;
723
+ track(raw, "iterate", ARRAY_ITERATE_KEY);
724
+ return isShallow(array) ? raw : raw.map(toReactive);
725
+ }
726
+ function shallowReadArray(arr) {
727
+ track(arr = toRaw(arr), "iterate", ARRAY_ITERATE_KEY);
728
+ return arr;
729
+ }
730
+ const arrayInstrumentations = {
731
+ __proto__: null,
732
+ [Symbol.iterator]() {
733
+ return iterator(this, Symbol.iterator, toReactive);
734
+ },
735
+ concat(...args) {
736
+ return reactiveReadArray(this).concat(
737
+ ...args.map((x) => isArray$1(x) ? reactiveReadArray(x) : x)
738
+ );
739
+ },
740
+ entries() {
741
+ return iterator(this, "entries", (value) => {
742
+ value[1] = toReactive(value[1]);
743
+ return value;
744
+ });
745
+ },
746
+ every(fn, thisArg) {
747
+ return apply(this, "every", fn, thisArg, void 0, arguments);
748
+ },
749
+ filter(fn, thisArg) {
750
+ return apply(this, "filter", fn, thisArg, (v) => v.map(toReactive), arguments);
751
+ },
752
+ find(fn, thisArg) {
753
+ return apply(this, "find", fn, thisArg, toReactive, arguments);
754
+ },
755
+ findIndex(fn, thisArg) {
756
+ return apply(this, "findIndex", fn, thisArg, void 0, arguments);
757
+ },
758
+ findLast(fn, thisArg) {
759
+ return apply(this, "findLast", fn, thisArg, toReactive, arguments);
760
+ },
761
+ findLastIndex(fn, thisArg) {
762
+ return apply(this, "findLastIndex", fn, thisArg, void 0, arguments);
763
+ },
764
+ // flat, flatMap could benefit from ARRAY_ITERATE but are not straight-forward to implement
765
+ forEach(fn, thisArg) {
766
+ return apply(this, "forEach", fn, thisArg, void 0, arguments);
767
+ },
768
+ includes(...args) {
769
+ return searchProxy(this, "includes", args);
770
+ },
771
+ indexOf(...args) {
772
+ return searchProxy(this, "indexOf", args);
773
+ },
774
+ join(separator) {
775
+ return reactiveReadArray(this).join(separator);
776
+ },
777
+ // keys() iterator only reads `length`, no optimisation required
778
+ lastIndexOf(...args) {
779
+ return searchProxy(this, "lastIndexOf", args);
780
+ },
781
+ map(fn, thisArg) {
782
+ return apply(this, "map", fn, thisArg, void 0, arguments);
783
+ },
784
+ pop() {
785
+ return noTracking(this, "pop");
786
+ },
787
+ push(...args) {
788
+ return noTracking(this, "push", args);
789
+ },
790
+ reduce(fn, ...args) {
791
+ return reduce(this, "reduce", fn, args);
792
+ },
793
+ reduceRight(fn, ...args) {
794
+ return reduce(this, "reduceRight", fn, args);
795
+ },
796
+ shift() {
797
+ return noTracking(this, "shift");
798
+ },
799
+ // slice could use ARRAY_ITERATE but also seems to beg for range tracking
800
+ some(fn, thisArg) {
801
+ return apply(this, "some", fn, thisArg, void 0, arguments);
802
+ },
803
+ splice(...args) {
804
+ return noTracking(this, "splice", args);
805
+ },
806
+ toReversed() {
807
+ return reactiveReadArray(this).toReversed();
808
+ },
809
+ toSorted(comparer) {
810
+ return reactiveReadArray(this).toSorted(comparer);
811
+ },
812
+ toSpliced(...args) {
813
+ return reactiveReadArray(this).toSpliced(...args);
814
+ },
815
+ unshift(...args) {
816
+ return noTracking(this, "unshift", args);
817
+ },
818
+ values() {
819
+ return iterator(this, "values", toReactive);
820
+ }
821
+ };
822
+ function iterator(self, method, wrapValue) {
823
+ const arr = shallowReadArray(self);
824
+ const iter = arr[method]();
825
+ if (arr !== self && !isShallow(self)) {
826
+ iter._next = iter.next;
827
+ iter.next = () => {
828
+ const result = iter._next();
829
+ if (result.value) {
830
+ result.value = wrapValue(result.value);
831
+ }
832
+ return result;
833
+ };
834
+ }
835
+ return iter;
836
+ }
837
+ const arrayProto = Array.prototype;
838
+ function apply(self, method, fn, thisArg, wrappedRetFn, args) {
839
+ const arr = shallowReadArray(self);
840
+ const needsWrap = arr !== self && !isShallow(self);
841
+ const methodFn = arr[method];
842
+ if (methodFn !== arrayProto[method]) {
843
+ const result2 = methodFn.apply(self, args);
844
+ return needsWrap ? toReactive(result2) : result2;
845
+ }
846
+ let wrappedFn = fn;
847
+ if (arr !== self) {
848
+ if (needsWrap) {
849
+ wrappedFn = function(item, index) {
850
+ return fn.call(this, toReactive(item), index, self);
851
+ };
852
+ } else if (fn.length > 2) {
853
+ wrappedFn = function(item, index) {
854
+ return fn.call(this, item, index, self);
855
+ };
856
+ }
857
+ }
858
+ const result = methodFn.call(arr, wrappedFn, thisArg);
859
+ return needsWrap && wrappedRetFn ? wrappedRetFn(result) : result;
860
+ }
861
+ function reduce(self, method, fn, args) {
862
+ const arr = shallowReadArray(self);
863
+ let wrappedFn = fn;
864
+ if (arr !== self) {
865
+ if (!isShallow(self)) {
866
+ wrappedFn = function(acc, item, index) {
867
+ return fn.call(this, acc, toReactive(item), index, self);
868
+ };
869
+ } else if (fn.length > 3) {
870
+ wrappedFn = function(acc, item, index) {
871
+ return fn.call(this, acc, item, index, self);
872
+ };
873
+ }
874
+ }
875
+ return arr[method](wrappedFn, ...args);
876
+ }
877
+ function searchProxy(self, method, args) {
878
+ const arr = toRaw(self);
879
+ track(arr, "iterate", ARRAY_ITERATE_KEY);
880
+ const res = arr[method](...args);
881
+ if ((res === -1 || res === false) && isProxy(args[0])) {
882
+ args[0] = toRaw(args[0]);
883
+ return arr[method](...args);
884
+ }
885
+ return res;
886
+ }
887
+ function noTracking(self, method, args = []) {
888
+ pauseTracking();
889
+ startBatch();
890
+ const res = toRaw(self)[method].apply(self, args);
891
+ endBatch();
892
+ resetTracking();
893
+ return res;
458
894
  }
459
895
 
460
896
  const isNonTrackableKeys = /* @__PURE__ */ makeMap(`__proto__,__v_isRef,__isVue`);
461
897
  const builtInSymbols = new Set(
462
898
  /* @__PURE__ */ Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller").map((key) => Symbol[key]).filter(isSymbol)
463
899
  );
464
- const arrayInstrumentations = /* @__PURE__ */ createArrayInstrumentations();
465
- function createArrayInstrumentations() {
466
- const instrumentations = {};
467
- ["includes", "indexOf", "lastIndexOf"].forEach((key) => {
468
- instrumentations[key] = function(...args) {
469
- const arr = toRaw(this);
470
- for (let i = 0, l = this.length; i < l; i++) {
471
- track(arr, "get", i + "");
472
- }
473
- const res = arr[key](...args);
474
- if (res === -1 || res === false) {
475
- return arr[key](...args.map(toRaw));
476
- } else {
477
- return res;
478
- }
479
- };
480
- });
481
- ["push", "pop", "shift", "unshift", "splice"].forEach((key) => {
482
- instrumentations[key] = function(...args) {
483
- pauseTracking();
484
- pauseScheduling();
485
- const res = toRaw(this)[key].apply(this, args);
486
- resetScheduling();
487
- resetTracking();
488
- return res;
489
- };
490
- });
491
- return instrumentations;
492
- }
493
900
  function hasOwnProperty(key) {
494
901
  if (!isSymbol(key)) key = String(key);
495
902
  const obj = toRaw(this);
@@ -519,14 +926,22 @@ class BaseReactiveHandler {
519
926
  }
520
927
  const targetIsArray = isArray$1(target);
521
928
  if (!isReadonly2) {
522
- if (targetIsArray && hasOwn(arrayInstrumentations, key)) {
523
- return Reflect.get(arrayInstrumentations, key, receiver);
929
+ let fn;
930
+ if (targetIsArray && (fn = arrayInstrumentations[key])) {
931
+ return fn;
524
932
  }
525
933
  if (key === "hasOwnProperty") {
526
934
  return hasOwnProperty;
527
935
  }
528
936
  }
529
- const res = Reflect.get(target, key, receiver);
937
+ const res = Reflect.get(
938
+ target,
939
+ key,
940
+ // if this is a proxy wrapping a ref, return methods using the raw ref
941
+ // as receiver so that we don't have to call `toRaw` on the ref in all
942
+ // its class methods
943
+ isRef(target) ? target : receiver
944
+ );
530
945
  if (isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) {
531
946
  return res;
532
947
  }
@@ -567,11 +982,16 @@ class MutableReactiveHandler extends BaseReactiveHandler {
567
982
  }
568
983
  }
569
984
  const hadKey = isArray$1(target) && isIntegerKey(key) ? Number(key) < target.length : hasOwn(target, key);
570
- const result = Reflect.set(target, key, value, receiver);
985
+ const result = Reflect.set(
986
+ target,
987
+ key,
988
+ value,
989
+ isRef(target) ? target : receiver
990
+ );
571
991
  if (target === toRaw(receiver)) {
572
992
  if (!hadKey) {
573
993
  trigger(target, "add", key, value);
574
- } else if (hasChanged$1(value, oldValue)) {
994
+ } else if (hasChanged(value, oldValue)) {
575
995
  trigger(target, "set", key, value, oldValue);
576
996
  }
577
997
  }
@@ -627,9 +1047,7 @@ class ReadonlyReactiveHandler extends BaseReactiveHandler {
627
1047
  }
628
1048
  const mutableHandlers = /* @__PURE__ */ new MutableReactiveHandler();
629
1049
  const readonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler();
630
- const shallowReactiveHandlers = /* @__PURE__ */ new MutableReactiveHandler(
631
- true
632
- );
1050
+ const shallowReactiveHandlers = /* @__PURE__ */ new MutableReactiveHandler(true);
633
1051
  const shallowReadonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler(true);
634
1052
 
635
1053
  const toShallow = (value) => value;
@@ -639,7 +1057,7 @@ function get(target, key, isReadonly2 = false, isShallow2 = false) {
639
1057
  const rawTarget = toRaw(target);
640
1058
  const rawKey = toRaw(key);
641
1059
  if (!isReadonly2) {
642
- if (hasChanged$1(key, rawKey)) {
1060
+ if (hasChanged(key, rawKey)) {
643
1061
  track(rawTarget, "get", key);
644
1062
  }
645
1063
  track(rawTarget, "get", rawKey);
@@ -659,7 +1077,7 @@ function has(key, isReadonly2 = false) {
659
1077
  const rawTarget = toRaw(target);
660
1078
  const rawKey = toRaw(key);
661
1079
  if (!isReadonly2) {
662
- if (hasChanged$1(key, rawKey)) {
1080
+ if (hasChanged(key, rawKey)) {
663
1081
  track(rawTarget, "has", key);
664
1082
  }
665
1083
  track(rawTarget, "has", rawKey);
@@ -701,7 +1119,7 @@ function set(key, value, _isShallow = false) {
701
1119
  target.set(key, value);
702
1120
  if (!hadKey) {
703
1121
  trigger(target, "add", key, value);
704
- } else if (hasChanged$1(value, oldValue)) {
1122
+ } else if (hasChanged(value, oldValue)) {
705
1123
  trigger(target, "set", key, value, oldValue);
706
1124
  }
707
1125
  return this;
@@ -726,7 +1144,7 @@ function deleteEntry(key) {
726
1144
  function clear() {
727
1145
  const target = toRaw(this);
728
1146
  const hadItems = target.size !== 0;
729
- const oldTarget = isMap$1(target) ? new Map(target) : new Set(target) ;
1147
+ const oldTarget = isMap(target) ? new Map(target) : new Set(target) ;
730
1148
  const result = target.clear();
731
1149
  if (hadItems) {
732
1150
  trigger(target, "clear", void 0, void 0, oldTarget);
@@ -749,7 +1167,7 @@ function createIterableMethod(method, isReadonly2, isShallow2) {
749
1167
  return function(...args) {
750
1168
  const target = this["__v_raw"];
751
1169
  const rawTarget = toRaw(target);
752
- const targetIsMap = isMap$1(rawTarget);
1170
+ const targetIsMap = isMap(rawTarget);
753
1171
  const isPair = method === "entries" || method === Symbol.iterator && targetIsMap;
754
1172
  const isKeyOnly = method === "keys" && targetIsMap;
755
1173
  const innerIterator = target[method](...args);
@@ -1029,7 +1447,7 @@ function toRaw(observed) {
1029
1447
  return raw ? toRaw(raw) : observed;
1030
1448
  }
1031
1449
  function markRaw(value) {
1032
- if (Object.isExtensible(value)) {
1450
+ if (!hasOwn(value, "__v_skip") && Object.isExtensible(value)) {
1033
1451
  def(value, "__v_skip", true);
1034
1452
  }
1035
1453
  return value;
@@ -1037,111 +1455,8 @@ function markRaw(value) {
1037
1455
  const toReactive = (value) => isObject$1(value) ? reactive(value) : value;
1038
1456
  const toReadonly = (value) => isObject$1(value) ? readonly(value) : value;
1039
1457
 
1040
- const COMPUTED_SIDE_EFFECT_WARN = `Computed is still dirty after getter evaluation, likely because a computed is mutating its own dependency in its getter. State mutations in computed getters should be avoided. Check the docs for more details: https://vuejs.org/guide/essentials/computed.html#getters-should-be-side-effect-free`;
1041
- class ComputedRefImpl {
1042
- constructor(getter, _setter, isReadonly, isSSR) {
1043
- this.getter = getter;
1044
- this._setter = _setter;
1045
- this.dep = void 0;
1046
- this.__v_isRef = true;
1047
- this["__v_isReadonly"] = false;
1048
- this.effect = new ReactiveEffect(
1049
- () => getter(this._value),
1050
- () => triggerRefValue(
1051
- this,
1052
- this.effect._dirtyLevel === 2 ? 2 : 3
1053
- )
1054
- );
1055
- this.effect.computed = this;
1056
- this.effect.active = this._cacheable = !isSSR;
1057
- this["__v_isReadonly"] = isReadonly;
1058
- }
1059
- get value() {
1060
- const self = toRaw(this);
1061
- if ((!self._cacheable || self.effect.dirty) && hasChanged$1(self._value, self._value = self.effect.run())) {
1062
- triggerRefValue(self, 4);
1063
- }
1064
- trackRefValue(self);
1065
- if (self.effect._dirtyLevel >= 2) {
1066
- if (this._warnRecursive) {
1067
- warn(COMPUTED_SIDE_EFFECT_WARN, `
1068
-
1069
- getter: `, this.getter);
1070
- }
1071
- triggerRefValue(self, 2);
1072
- }
1073
- return self._value;
1074
- }
1075
- set value(newValue) {
1076
- this._setter(newValue);
1077
- }
1078
- // #region polyfill _dirty for backward compatibility third party code for Vue <= 3.3.x
1079
- get _dirty() {
1080
- return this.effect.dirty;
1081
- }
1082
- set _dirty(v) {
1083
- this.effect.dirty = v;
1084
- }
1085
- // #endregion
1086
- }
1087
- function computed(getterOrOptions, debugOptions, isSSR = false) {
1088
- let getter;
1089
- let setter;
1090
- const onlyGetter = isFunction$1(getterOrOptions);
1091
- if (onlyGetter) {
1092
- getter = getterOrOptions;
1093
- setter = () => {
1094
- warn("Write operation failed: computed value is readonly");
1095
- } ;
1096
- } else {
1097
- getter = getterOrOptions.get;
1098
- setter = getterOrOptions.set;
1099
- }
1100
- const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter, isSSR);
1101
- if (debugOptions && !isSSR) {
1102
- cRef.effect.onTrack = debugOptions.onTrack;
1103
- cRef.effect.onTrigger = debugOptions.onTrigger;
1104
- }
1105
- return cRef;
1106
- }
1107
-
1108
- function trackRefValue(ref2) {
1109
- var _a;
1110
- if (shouldTrack && activeEffect) {
1111
- ref2 = toRaw(ref2);
1112
- trackEffect(
1113
- activeEffect,
1114
- (_a = ref2.dep) != null ? _a : ref2.dep = createDep(
1115
- () => ref2.dep = void 0,
1116
- ref2 instanceof ComputedRefImpl ? ref2 : void 0
1117
- ),
1118
- {
1119
- target: ref2,
1120
- type: "get",
1121
- key: "value"
1122
- }
1123
- );
1124
- }
1125
- }
1126
- function triggerRefValue(ref2, dirtyLevel = 4, newVal, oldVal) {
1127
- ref2 = toRaw(ref2);
1128
- const dep = ref2.dep;
1129
- if (dep) {
1130
- triggerEffects(
1131
- dep,
1132
- dirtyLevel,
1133
- {
1134
- target: ref2,
1135
- type: "set",
1136
- key: "value",
1137
- newValue: newVal,
1138
- oldValue: oldVal
1139
- }
1140
- );
1141
- }
1142
- }
1143
1458
  function isRef(r) {
1144
- return !!(r && r.__v_isRef === true);
1459
+ return r ? r["__v_isRef"] === true : false;
1145
1460
  }
1146
1461
  function ref(value) {
1147
1462
  return createRef(value, false);
@@ -1156,30 +1471,52 @@ function createRef(rawValue, shallow) {
1156
1471
  return new RefImpl(rawValue, shallow);
1157
1472
  }
1158
1473
  class RefImpl {
1159
- constructor(value, __v_isShallow) {
1160
- this.__v_isShallow = __v_isShallow;
1161
- this.dep = void 0;
1162
- this.__v_isRef = true;
1163
- this._rawValue = __v_isShallow ? value : toRaw(value);
1164
- this._value = __v_isShallow ? value : toReactive(value);
1474
+ constructor(value, isShallow2) {
1475
+ this.dep = new Dep();
1476
+ this["__v_isRef"] = true;
1477
+ this["__v_isShallow"] = false;
1478
+ this._rawValue = isShallow2 ? value : toRaw(value);
1479
+ this._value = isShallow2 ? value : toReactive(value);
1480
+ this["__v_isShallow"] = isShallow2;
1165
1481
  }
1166
1482
  get value() {
1167
- trackRefValue(this);
1483
+ {
1484
+ this.dep.track({
1485
+ target: this,
1486
+ type: "get",
1487
+ key: "value"
1488
+ });
1489
+ }
1168
1490
  return this._value;
1169
1491
  }
1170
- set value(newVal) {
1171
- const useDirectValue = this.__v_isShallow || isShallow(newVal) || isReadonly(newVal);
1172
- newVal = useDirectValue ? newVal : toRaw(newVal);
1173
- if (hasChanged$1(newVal, this._rawValue)) {
1174
- const oldVal = this._rawValue;
1175
- this._rawValue = newVal;
1176
- this._value = useDirectValue ? newVal : toReactive(newVal);
1177
- triggerRefValue(this, 4, newVal, oldVal);
1492
+ set value(newValue) {
1493
+ const oldValue = this._rawValue;
1494
+ const useDirectValue = this["__v_isShallow"] || isShallow(newValue) || isReadonly(newValue);
1495
+ newValue = useDirectValue ? newValue : toRaw(newValue);
1496
+ if (hasChanged(newValue, oldValue)) {
1497
+ this._rawValue = newValue;
1498
+ this._value = useDirectValue ? newValue : toReactive(newValue);
1499
+ {
1500
+ this.dep.trigger({
1501
+ target: this,
1502
+ type: "set",
1503
+ key: "value",
1504
+ newValue,
1505
+ oldValue
1506
+ });
1507
+ }
1178
1508
  }
1179
1509
  }
1180
1510
  }
1181
1511
  function triggerRef(ref2) {
1182
- triggerRefValue(ref2, 4, ref2.value );
1512
+ {
1513
+ ref2.dep.trigger({
1514
+ target: ref2,
1515
+ type: "set",
1516
+ key: "value",
1517
+ newValue: ref2._value
1518
+ });
1519
+ }
1183
1520
  }
1184
1521
  function unref(ref2) {
1185
1522
  return isRef(ref2) ? ref2.value : ref2;
@@ -1188,7 +1525,7 @@ function toValue(source) {
1188
1525
  return isFunction$1(source) ? source() : unref(source);
1189
1526
  }
1190
1527
  const shallowUnwrapHandlers = {
1191
- get: (target, key, receiver) => unref(Reflect.get(target, key, receiver)),
1528
+ get: (target, key, receiver) => key === "__v_raw" ? target : unref(Reflect.get(target, key, receiver)),
1192
1529
  set: (target, key, value, receiver) => {
1193
1530
  const oldValue = target[key];
1194
1531
  if (isRef(oldValue) && !isRef(value)) {
@@ -1204,17 +1541,15 @@ function proxyRefs(objectWithRefs) {
1204
1541
  }
1205
1542
  class CustomRefImpl {
1206
1543
  constructor(factory) {
1207
- this.dep = void 0;
1208
- this.__v_isRef = true;
1209
- const { get, set } = factory(
1210
- () => trackRefValue(this),
1211
- () => triggerRefValue(this)
1212
- );
1544
+ this["__v_isRef"] = true;
1545
+ this._value = void 0;
1546
+ const dep = this.dep = new Dep();
1547
+ const { get, set } = factory(dep.track.bind(dep), dep.trigger.bind(dep));
1213
1548
  this._get = get;
1214
1549
  this._set = set;
1215
1550
  }
1216
1551
  get value() {
1217
- return this._get();
1552
+ return this._value = this._get();
1218
1553
  }
1219
1554
  set value(newVal) {
1220
1555
  this._set(newVal);
@@ -1238,11 +1573,12 @@ class ObjectRefImpl {
1238
1573
  this._object = _object;
1239
1574
  this._key = _key;
1240
1575
  this._defaultValue = _defaultValue;
1241
- this.__v_isRef = true;
1576
+ this["__v_isRef"] = true;
1577
+ this._value = void 0;
1242
1578
  }
1243
1579
  get value() {
1244
1580
  const val = this._object[this._key];
1245
- return val === void 0 ? this._defaultValue : val;
1581
+ return this._value = val === void 0 ? this._defaultValue : val;
1246
1582
  }
1247
1583
  set value(newVal) {
1248
1584
  this._object[this._key] = newVal;
@@ -1254,11 +1590,12 @@ class ObjectRefImpl {
1254
1590
  class GetterRefImpl {
1255
1591
  constructor(_getter) {
1256
1592
  this._getter = _getter;
1257
- this.__v_isRef = true;
1258
- this.__v_isReadonly = true;
1593
+ this["__v_isRef"] = true;
1594
+ this["__v_isReadonly"] = true;
1595
+ this._value = void 0;
1259
1596
  }
1260
1597
  get value() {
1261
- return this._getter();
1598
+ return this._value = this._getter();
1262
1599
  }
1263
1600
  }
1264
1601
  function toRef(source, key, defaultValue) {
@@ -1277,6 +1614,91 @@ function propertyToRef(source, key, defaultValue) {
1277
1614
  return isRef(val) ? val : new ObjectRefImpl(source, key, defaultValue);
1278
1615
  }
1279
1616
 
1617
+ class ComputedRefImpl {
1618
+ constructor(fn, setter, isSSR) {
1619
+ this.fn = fn;
1620
+ this.setter = setter;
1621
+ /**
1622
+ * @internal
1623
+ */
1624
+ this._value = void 0;
1625
+ /**
1626
+ * @internal
1627
+ */
1628
+ this.dep = new Dep(this);
1629
+ /**
1630
+ * @internal
1631
+ */
1632
+ this.__v_isRef = true;
1633
+ // TODO isolatedDeclarations "__v_isReadonly"
1634
+ // A computed is also a subscriber that tracks other deps
1635
+ /**
1636
+ * @internal
1637
+ */
1638
+ this.deps = void 0;
1639
+ /**
1640
+ * @internal
1641
+ */
1642
+ this.depsTail = void 0;
1643
+ /**
1644
+ * @internal
1645
+ */
1646
+ this.flags = 16;
1647
+ /**
1648
+ * @internal
1649
+ */
1650
+ this.globalVersion = globalVersion - 1;
1651
+ // for backwards compat
1652
+ this.effect = this;
1653
+ this["__v_isReadonly"] = !setter;
1654
+ this.isSSR = isSSR;
1655
+ }
1656
+ /**
1657
+ * @internal
1658
+ */
1659
+ notify() {
1660
+ this.flags |= 16;
1661
+ if (activeSub !== this) {
1662
+ this.dep.notify();
1663
+ }
1664
+ }
1665
+ get value() {
1666
+ const link = this.dep.track({
1667
+ target: this,
1668
+ type: "get",
1669
+ key: "value"
1670
+ }) ;
1671
+ refreshComputed(this);
1672
+ if (link) {
1673
+ link.version = this.dep.version;
1674
+ }
1675
+ return this._value;
1676
+ }
1677
+ set value(newValue) {
1678
+ if (this.setter) {
1679
+ this.setter(newValue);
1680
+ } else {
1681
+ warn("Write operation failed: computed value is readonly");
1682
+ }
1683
+ }
1684
+ }
1685
+ function computed(getterOrOptions, debugOptions, isSSR = false) {
1686
+ let getter;
1687
+ let setter;
1688
+ if (isFunction$1(getterOrOptions)) {
1689
+ getter = getterOrOptions;
1690
+ } else {
1691
+ getter = getterOrOptions.get;
1692
+ setter = getterOrOptions.set;
1693
+ }
1694
+ const cRef = new ComputedRefImpl(getter, setter, isSSR);
1695
+ if (debugOptions && !isSSR) {
1696
+ cRef.onTrack = debugOptions.onTrack;
1697
+ cRef.onTrigger = debugOptions.onTrigger;
1698
+ }
1699
+ return cRef;
1700
+ }
1701
+
1280
1702
  const TrackOpTypes = {
1281
1703
  "GET": "get",
1282
1704
  "HAS": "has",
@@ -1288,16 +1710,221 @@ const TriggerOpTypes = {
1288
1710
  "DELETE": "delete",
1289
1711
  "CLEAR": "clear"
1290
1712
  };
1291
- const ReactiveFlags = {
1292
- "SKIP": "__v_skip",
1293
- "IS_REACTIVE": "__v_isReactive",
1294
- "IS_READONLY": "__v_isReadonly",
1295
- "IS_SHALLOW": "__v_isShallow",
1296
- "RAW": "__v_raw"
1297
- };
1713
+ const INITIAL_WATCHER_VALUE = {};
1714
+ const cleanupMap = /* @__PURE__ */ new WeakMap();
1715
+ let activeWatcher = void 0;
1716
+ function getCurrentWatcher() {
1717
+ return activeWatcher;
1718
+ }
1719
+ function onWatcherCleanup(cleanupFn, failSilently = false, owner = activeWatcher) {
1720
+ if (owner) {
1721
+ let cleanups = cleanupMap.get(owner);
1722
+ if (!cleanups) cleanupMap.set(owner, cleanups = []);
1723
+ cleanups.push(cleanupFn);
1724
+ } else if (!failSilently) {
1725
+ warn(
1726
+ `onWatcherCleanup() was called when there was no active watcher to associate with.`
1727
+ );
1728
+ }
1729
+ }
1730
+ function watch$1(source, cb, options = EMPTY_OBJ$1) {
1731
+ const { immediate, deep, once, scheduler, augmentJob, call } = options;
1732
+ const warnInvalidSource = (s) => {
1733
+ (options.onWarn || warn)(
1734
+ `Invalid watch source: `,
1735
+ s,
1736
+ `A watch source can only be a getter/effect function, a ref, a reactive object, or an array of these types.`
1737
+ );
1738
+ };
1739
+ const reactiveGetter = (source2) => {
1740
+ if (deep) return source2;
1741
+ if (isShallow(source2) || deep === false || deep === 0)
1742
+ return traverse(source2, 1);
1743
+ return traverse(source2);
1744
+ };
1745
+ let effect;
1746
+ let getter;
1747
+ let cleanup;
1748
+ let boundCleanup;
1749
+ let forceTrigger = false;
1750
+ let isMultiSource = false;
1751
+ if (isRef(source)) {
1752
+ getter = () => source.value;
1753
+ forceTrigger = isShallow(source);
1754
+ } else if (isReactive(source)) {
1755
+ getter = () => reactiveGetter(source);
1756
+ forceTrigger = true;
1757
+ } else if (isArray$1(source)) {
1758
+ isMultiSource = true;
1759
+ forceTrigger = source.some((s) => isReactive(s) || isShallow(s));
1760
+ getter = () => source.map((s) => {
1761
+ if (isRef(s)) {
1762
+ return s.value;
1763
+ } else if (isReactive(s)) {
1764
+ return reactiveGetter(s);
1765
+ } else if (isFunction$1(s)) {
1766
+ return call ? call(s, 2) : s();
1767
+ } else {
1768
+ warnInvalidSource(s);
1769
+ }
1770
+ });
1771
+ } else if (isFunction$1(source)) {
1772
+ if (cb) {
1773
+ getter = call ? () => call(source, 2) : source;
1774
+ } else {
1775
+ getter = () => {
1776
+ if (cleanup) {
1777
+ pauseTracking();
1778
+ try {
1779
+ cleanup();
1780
+ } finally {
1781
+ resetTracking();
1782
+ }
1783
+ }
1784
+ const currentEffect = activeWatcher;
1785
+ activeWatcher = effect;
1786
+ try {
1787
+ return call ? call(source, 3, [boundCleanup]) : source(boundCleanup);
1788
+ } finally {
1789
+ activeWatcher = currentEffect;
1790
+ }
1791
+ };
1792
+ }
1793
+ } else {
1794
+ getter = NOOP;
1795
+ warnInvalidSource(source);
1796
+ }
1797
+ if (cb && deep) {
1798
+ const baseGetter = getter;
1799
+ const depth = deep === true ? Infinity : deep;
1800
+ getter = () => traverse(baseGetter(), depth);
1801
+ }
1802
+ const scope = getCurrentScope();
1803
+ const watchHandle = () => {
1804
+ effect.stop();
1805
+ if (scope) {
1806
+ remove(scope.effects, effect);
1807
+ }
1808
+ };
1809
+ if (once) {
1810
+ if (cb) {
1811
+ const _cb = cb;
1812
+ cb = (...args) => {
1813
+ _cb(...args);
1814
+ watchHandle();
1815
+ };
1816
+ } else {
1817
+ const _getter = getter;
1818
+ getter = () => {
1819
+ _getter();
1820
+ watchHandle();
1821
+ };
1822
+ }
1823
+ }
1824
+ let oldValue = isMultiSource ? new Array(source.length).fill(INITIAL_WATCHER_VALUE) : INITIAL_WATCHER_VALUE;
1825
+ const job = (immediateFirstRun) => {
1826
+ if (!(effect.flags & 1) || !effect.dirty && !immediateFirstRun) {
1827
+ return;
1828
+ }
1829
+ if (cb) {
1830
+ const newValue = effect.run();
1831
+ if (deep || forceTrigger || (isMultiSource ? newValue.some((v, i) => hasChanged(v, oldValue[i])) : hasChanged(newValue, oldValue))) {
1832
+ if (cleanup) {
1833
+ cleanup();
1834
+ }
1835
+ const currentWatcher = activeWatcher;
1836
+ activeWatcher = effect;
1837
+ try {
1838
+ const args = [
1839
+ newValue,
1840
+ // pass undefined as the old value when it's changed for the first time
1841
+ oldValue === INITIAL_WATCHER_VALUE ? void 0 : isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE ? [] : oldValue,
1842
+ boundCleanup
1843
+ ];
1844
+ call ? call(cb, 3, args) : (
1845
+ // @ts-expect-error
1846
+ cb(...args)
1847
+ );
1848
+ oldValue = newValue;
1849
+ } finally {
1850
+ activeWatcher = currentWatcher;
1851
+ }
1852
+ }
1853
+ } else {
1854
+ effect.run();
1855
+ }
1856
+ };
1857
+ if (augmentJob) {
1858
+ augmentJob(job);
1859
+ }
1860
+ effect = new ReactiveEffect(getter);
1861
+ effect.scheduler = scheduler ? () => scheduler(job, false) : job;
1862
+ boundCleanup = (fn) => onWatcherCleanup(fn, false, effect);
1863
+ cleanup = effect.onStop = () => {
1864
+ const cleanups = cleanupMap.get(effect);
1865
+ if (cleanups) {
1866
+ if (call) {
1867
+ call(cleanups, 4);
1868
+ } else {
1869
+ for (const cleanup2 of cleanups) cleanup2();
1870
+ }
1871
+ cleanupMap.delete(effect);
1872
+ }
1873
+ };
1874
+ {
1875
+ effect.onTrack = options.onTrack;
1876
+ effect.onTrigger = options.onTrigger;
1877
+ }
1878
+ if (cb) {
1879
+ if (immediate) {
1880
+ job(true);
1881
+ } else {
1882
+ oldValue = effect.run();
1883
+ }
1884
+ } else if (scheduler) {
1885
+ scheduler(job.bind(null, true), true);
1886
+ } else {
1887
+ effect.run();
1888
+ }
1889
+ watchHandle.pause = effect.pause.bind(effect);
1890
+ watchHandle.resume = effect.resume.bind(effect);
1891
+ watchHandle.stop = watchHandle;
1892
+ return watchHandle;
1893
+ }
1894
+ function traverse(value, depth = Infinity, seen) {
1895
+ if (depth <= 0 || !isObject$1(value) || value["__v_skip"]) {
1896
+ return value;
1897
+ }
1898
+ seen = seen || /* @__PURE__ */ new Set();
1899
+ if (seen.has(value)) {
1900
+ return value;
1901
+ }
1902
+ seen.add(value);
1903
+ depth--;
1904
+ if (isRef(value)) {
1905
+ traverse(value.value, depth, seen);
1906
+ } else if (isArray$1(value)) {
1907
+ for (let i = 0; i < value.length; i++) {
1908
+ traverse(value[i], depth, seen);
1909
+ }
1910
+ } else if (isSet(value) || isMap(value)) {
1911
+ value.forEach((v) => {
1912
+ traverse(v, depth, seen);
1913
+ });
1914
+ } else if (isPlainObject$1(value)) {
1915
+ for (const key in value) {
1916
+ traverse(value[key], depth, seen);
1917
+ }
1918
+ for (const key of Object.getOwnPropertySymbols(value)) {
1919
+ if (Object.prototype.propertyIsEnumerable.call(value, key)) {
1920
+ traverse(value[key], depth, seen);
1921
+ }
1922
+ }
1923
+ }
1924
+ return value;
1925
+ }
1298
1926
 
1299
- // eslint-disable-next-line @typescript-eslint/no-empty-function
1300
- const NOOP = () => { };
1927
+ const EMPTY_OBJ = Object.freeze({}) ;
1301
1928
  const { isArray } = Array;
1302
1929
  const extend = Object.assign;
1303
1930
  function exclude(obj, keys) {
@@ -1325,27 +1952,16 @@ function isPlainObject(x) {
1325
1952
  function isFunction(x) {
1326
1953
  return typeof x === 'function';
1327
1954
  }
1328
- function isMap(x) {
1329
- return getType(x) === 'Map';
1330
- }
1331
- function isSet(x) {
1332
- return getType(x) === 'Set';
1333
- }
1334
- // Compare whether a value has changed, accounting for NaN.
1335
- function hasChanged(value, oldValue) {
1336
- // eslint-disable-next-line no-self-compare
1337
- return value !== oldValue && (value === value || oldValue === oldValue);
1338
- }
1339
- function remove(arr, el) {
1340
- const i = arr.indexOf(el);
1341
- if (i > -1) {
1342
- arr.splice(i, 1);
1343
- }
1344
- }
1345
1955
  function toHiddenField(name) {
1346
1956
  return `__${name}__`;
1347
1957
  }
1348
1958
 
1959
+ /* eslint-disable no-bitwise, unicorn/prefer-math-trunc, @typescript-eslint/prefer-literal-enum-member */
1960
+ var SchedulerJobFlags;
1961
+ (function (SchedulerJobFlags) {
1962
+ SchedulerJobFlags[SchedulerJobFlags["QUEUED"] = 1] = "QUEUED";
1963
+ SchedulerJobFlags[SchedulerJobFlags["ALLOW_RECURSE"] = 4] = "ALLOW_RECURSE";
1964
+ })(SchedulerJobFlags || (SchedulerJobFlags = {}));
1349
1965
  let isFlushing = false;
1350
1966
  let isFlushPending = false;
1351
1967
  const queue = [];
@@ -1354,7 +1970,7 @@ const pendingPostFlushCbs = [];
1354
1970
  let activePostFlushCbs = null;
1355
1971
  let postFlushIndex = 0;
1356
1972
  // eslint-disable-next-line spaced-comment
1357
- const resolvedPromise = /*#__PURE__*/ Promise.resolve();
1973
+ const resolvedPromise = /*@__PURE__*/ Promise.resolve();
1358
1974
  let currentFlushPromise = null;
1359
1975
  const RECURSION_LIMIT = 100;
1360
1976
  function nextTick(fn) {
@@ -1363,15 +1979,9 @@ function nextTick(fn) {
1363
1979
  return fn ? p.then(fn) : p;
1364
1980
  }
1365
1981
  function queueJob(job) {
1366
- // The dedupe search uses the startIndex argument of Array.includes()
1367
- // by default the search index includes the current job that is being run
1368
- // so it cannot recursively trigger itself again.
1369
- // if the job is a watch() callback, the search will start with a +1 index to
1370
- // allow it recursively trigger itself - it is the user's responsibility to
1371
- // ensure it doesn't end up in an infinite loop.
1372
- if (queue.length === 0 ||
1373
- !queue.includes(job, isFlushing && job.allowRecurse ? flushIndex + 1 : flushIndex)) {
1982
+ if (!(job.flags & SchedulerJobFlags.QUEUED)) {
1374
1983
  queue.push(job);
1984
+ job.flags |= SchedulerJobFlags.QUEUED;
1375
1985
  queueFlush();
1376
1986
  }
1377
1987
  }
@@ -1383,9 +1993,9 @@ function queueFlush() {
1383
1993
  }
1384
1994
  }
1385
1995
  function queuePostFlushCb(cb) {
1386
- if (!activePostFlushCbs ||
1387
- !activePostFlushCbs.includes(cb, cb.allowRecurse ? postFlushIndex + 1 : postFlushIndex)) {
1996
+ if (!(cb.flags & SchedulerJobFlags.QUEUED)) {
1388
1997
  pendingPostFlushCbs.push(cb);
1998
+ cb.flags |= SchedulerJobFlags.QUEUED;
1389
1999
  }
1390
2000
  }
1391
2001
  function flushPostFlushCbs() {
@@ -1394,8 +2004,11 @@ function flushPostFlushCbs() {
1394
2004
  pendingPostFlushCbs.length = 0;
1395
2005
  for (postFlushIndex = 0; postFlushIndex < activePostFlushCbs.length; postFlushIndex++) {
1396
2006
  const cb = activePostFlushCbs[postFlushIndex];
1397
- if (cb.active !== false)
1398
- cb();
2007
+ if (cb.flags & SchedulerJobFlags.ALLOW_RECURSE) {
2008
+ cb.flags &= ~SchedulerJobFlags.QUEUED;
2009
+ }
2010
+ cb();
2011
+ cb.flags &= ~SchedulerJobFlags.QUEUED;
1399
2012
  }
1400
2013
  activePostFlushCbs = null;
1401
2014
  postFlushIndex = 0;
@@ -1418,16 +2031,23 @@ function flushJobs(seen) {
1418
2031
  try {
1419
2032
  for (flushIndex = 0; flushIndex < queue.length; flushIndex++) {
1420
2033
  const job = queue[flushIndex];
1421
- if (job.active !== false) {
1422
- /* istanbul ignore if -- @preserve */
1423
- if (true && check(job)) {
1424
- continue;
1425
- }
1426
- job();
2034
+ /* istanbul ignore if -- @preserve */
2035
+ if (true && check(job)) {
2036
+ continue;
2037
+ }
2038
+ if (job.flags & SchedulerJobFlags.ALLOW_RECURSE) {
2039
+ job.flags &= ~SchedulerJobFlags.QUEUED;
1427
2040
  }
2041
+ job();
2042
+ job.flags &= ~SchedulerJobFlags.QUEUED;
1428
2043
  }
1429
2044
  }
1430
2045
  finally {
2046
+ // If there was an error we still need to clear the QUEUED flags
2047
+ for (; flushIndex < queue.length; flushIndex++) {
2048
+ const job = queue[flushIndex];
2049
+ job.flags &= ~SchedulerJobFlags.QUEUED;
2050
+ }
1431
2051
  flushIndex = 0;
1432
2052
  queue.length = 0;
1433
2053
  isFlushing = false;
@@ -1459,8 +2079,6 @@ function watchSyncEffect(effect, options) {
1459
2079
  return doWatch(effect, null, extend({}, options, { flush: 'sync' })
1460
2080
  );
1461
2081
  }
1462
- // Initial value for watchers to trigger on undefined initial values
1463
- const INITIAL_WATCHER_VALUE = {};
1464
2082
  // Implementation
1465
2083
  function watch(source, cb, options) {
1466
2084
  if (!isFunction(cb)) {
@@ -1470,19 +2088,8 @@ function watch(source, cb, options) {
1470
2088
  }
1471
2089
  return doWatch(source, cb, options);
1472
2090
  }
1473
- // eslint-disable-next-line complexity
1474
- function doWatch(source, cb, { immediate, deep, flush, once, onTrack, onTrigger } = {}) {
1475
- if (cb && once) {
1476
- const _cb = cb;
1477
- cb = (...args) => {
1478
- _cb(...args);
1479
- unwatch();
1480
- };
1481
- }
1482
- if (deep !== undefined && typeof deep === 'number') {
1483
- console.warn(`watch() "deep" option with number value will be used as watch depth in future versions. ` +
1484
- `Please use a boolean instead to avoid potential breakage.`);
1485
- }
2091
+ function doWatch(source, cb, options = EMPTY_OBJ) {
2092
+ const { immediate, deep, flush, once } = options;
1486
2093
  if (!cb) {
1487
2094
  if (immediate !== undefined) {
1488
2095
  console.warn(`watch() "immediate" option is only respected when using the ` +
@@ -1497,193 +2104,34 @@ function doWatch(source, cb, { immediate, deep, flush, once, onTrack, onTrigger
1497
2104
  `watch(source, callback, options?) signature.`);
1498
2105
  }
1499
2106
  }
1500
- const warnInvalidSource = (s) => {
1501
- console.warn(`Invalid watch source:`, s, `A watch source can only be a getter/effect function, a ref, ` +
1502
- `a reactive object, or an array of these types.`);
1503
- };
1504
- const reactiveGetter = (source) => deep === true ?
1505
- source // Traverse will happen in wrapped getter below
1506
- // For deep: false, only traverse root-level properties
1507
- : traverse(source, deep === false ? 1 : undefined);
1508
- let getter;
1509
- let forceTrigger = false;
1510
- let isMultiSource = false;
1511
- if (isRef(source)) {
1512
- getter = () => source.value;
1513
- forceTrigger = isShallow(source);
1514
- }
1515
- else if (isReactive(source)) {
1516
- getter = () => reactiveGetter(source);
1517
- forceTrigger = true;
1518
- }
1519
- else if (isArray(source)) {
1520
- isMultiSource = true;
1521
- forceTrigger = source.some((s) => isReactive(s) || isShallow(s));
1522
- getter = () => source.map((s) => {
1523
- if (isRef(s)) {
1524
- return s.value;
1525
- }
1526
- if (isReactive(s)) {
1527
- return reactiveGetter(s);
1528
- }
1529
- if (isFunction(s)) {
1530
- return s();
1531
- }
1532
- /* istanbul ignore else -- @preserve */
1533
- {
1534
- warnInvalidSource(s);
1535
- }
1536
- return undefined;
1537
- });
1538
- }
1539
- else if (isFunction(source)) {
1540
- if (cb) {
1541
- // Getter with cb
1542
- getter = () => source();
1543
- }
1544
- else {
1545
- // No cb -> simple effect
1546
- getter = () => {
1547
- if (cleanup) {
1548
- cleanup();
1549
- }
1550
- return source(onCleanup);
1551
- };
1552
- }
1553
- }
1554
- else {
1555
- getter = NOOP;
1556
- /* istanbul ignore else -- @preserve */
1557
- {
1558
- warnInvalidSource(source);
1559
- }
1560
- }
1561
- if (cb && deep) {
1562
- const baseGetter = getter;
1563
- getter = () => traverse(baseGetter());
1564
- }
1565
- let cleanup;
1566
- const onCleanup = (fn) => {
1567
- // eslint-disable-next-line no-multi-assign
1568
- cleanup = effect.onStop = () => {
1569
- fn();
1570
- // eslint-disable-next-line no-multi-assign
1571
- cleanup = effect.onStop = undefined;
1572
- };
1573
- };
1574
- let oldValue = isMultiSource ?
1575
- Array.from({ length: source.length }).fill(INITIAL_WATCHER_VALUE)
1576
- : INITIAL_WATCHER_VALUE;
1577
- const job = () => {
1578
- if (!effect.active || !effect.dirty) {
1579
- return;
1580
- }
1581
- if (cb) {
1582
- // Watch(source, cb)
1583
- const newValue = effect.run();
1584
- if (deep ||
1585
- forceTrigger ||
1586
- (isMultiSource ?
1587
- newValue.some((v, i) => hasChanged(v, oldValue[i]))
1588
- : hasChanged(newValue, oldValue))) {
1589
- // Cleanup before running cb again
1590
- if (cleanup) {
1591
- cleanup();
1592
- }
1593
- cb(newValue,
1594
- // Pass undefined as the old value when it's changed for the first time
1595
- oldValue === INITIAL_WATCHER_VALUE ? undefined
1596
- : isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE ? []
1597
- : oldValue, onCleanup);
1598
- oldValue = newValue;
1599
- }
1600
- }
1601
- else {
1602
- // WatchEffect
1603
- effect.run();
1604
- }
1605
- };
1606
- // Important: mark the job as a watcher callback so that scheduler knows
1607
- // it is allowed to self-trigger
1608
- job.allowRecurse = Boolean(cb);
1609
- let scheduler;
1610
- if (flush === 'sync') {
1611
- scheduler = job; // The scheduler function gets called directly
1612
- }
1613
- else if (flush === 'post') {
1614
- scheduler = () => {
2107
+ const baseWatchOptions = extend({}, options);
2108
+ // Scheduler
2109
+ if (flush === 'post') {
2110
+ baseWatchOptions.scheduler = (job) => {
1615
2111
  queuePostFlushCb(job);
1616
2112
  };
1617
2113
  }
1618
- else {
1619
- scheduler = () => {
1620
- queueJob(job);
2114
+ else if (flush !== 'sync') {
2115
+ baseWatchOptions.scheduler = (job, isFirstRun) => {
2116
+ if (isFirstRun) {
2117
+ job();
2118
+ }
2119
+ else {
2120
+ queueJob(job);
2121
+ }
1621
2122
  };
1622
2123
  }
1623
- const effect = new ReactiveEffect(getter, NOOP, scheduler);
1624
- const scope = getCurrentScope();
1625
- const unwatch = () => {
1626
- effect.stop();
1627
- if (scope) {
1628
- // @ts-expect-error
1629
- remove(scope.effects, effect);
2124
+ // @ts-expect-error
2125
+ baseWatchOptions.augmentJob = (job) => {
2126
+ // Important: mark the job as a watcher callback so that scheduler knows
2127
+ // it is allowed to self-trigger
2128
+ if (cb) {
2129
+ // eslint-disable-next-line no-bitwise
2130
+ job.flags |= SchedulerJobFlags.ALLOW_RECURSE;
1630
2131
  }
1631
2132
  };
1632
- /* istanbul ignore else -- @preserve */
1633
- {
1634
- effect.onTrack = onTrack;
1635
- effect.onTrigger = onTrigger;
1636
- }
1637
- // Initial run
1638
- if (cb) {
1639
- if (immediate) {
1640
- job();
1641
- }
1642
- else {
1643
- oldValue = effect.run();
1644
- }
1645
- }
1646
- else {
1647
- effect.run();
1648
- }
1649
- return unwatch;
1650
- }
1651
- function traverse(value, depth = Number.POSITIVE_INFINITY, seen) {
1652
- if (depth <= 0 || !isObject(value) || value[ReactiveFlags.SKIP]) {
1653
- return value;
1654
- }
1655
- seen = seen || new Set();
1656
- if (seen.has(value)) {
1657
- return value;
1658
- }
1659
- seen.add(value);
1660
- depth--;
1661
- /* istanbul ignore else -- @preserve */
1662
- if (isRef(value)) {
1663
- traverse(value.value, depth, seen);
1664
- }
1665
- else if (isArray(value)) {
1666
- for (let i = 0; i < value.length; i++) {
1667
- traverse(value[i], depth, seen);
1668
- }
1669
- }
1670
- else if (isSet(value) || isMap(value)) {
1671
- value.forEach((v) => {
1672
- traverse(v, depth, seen);
1673
- });
1674
- }
1675
- else if (isPlainObject(value)) {
1676
- // eslint-disable-next-line guard-for-in
1677
- for (const key in value) {
1678
- traverse(value[key], depth, seen);
1679
- }
1680
- for (const key of Object.getOwnPropertySymbols(value)) {
1681
- if (Object.prototype.propertyIsEnumerable.call(value, key)) {
1682
- traverse(value[key], depth, seen);
1683
- }
1684
- }
1685
- }
1686
- return value;
2133
+ const watchHandle = watch$1(source, cb, baseWatchOptions);
2134
+ return watchHandle;
1687
2135
  }
1688
2136
 
1689
2137
  const provides = Object.create(null);
@@ -1909,15 +2357,20 @@ function definePage(optionsOrSetup, config) {
1909
2357
  };
1910
2358
  const bindings = setup(query, context);
1911
2359
  if (bindings !== undefined) {
2360
+ let data;
1912
2361
  Object.keys(bindings).forEach((key) => {
1913
2362
  const value = bindings[key];
1914
2363
  if (isFunction(value)) {
1915
2364
  this[key] = value;
1916
2365
  return;
1917
2366
  }
1918
- this.setData({ [key]: deepToRaw(value) });
2367
+ data = data || {};
2368
+ data[key] = deepToRaw(value);
1919
2369
  deepWatch.call(this, key, value);
1920
2370
  });
2371
+ if (data !== undefined) {
2372
+ this.setData(data, flushPostFlushCbs);
2373
+ }
1921
2374
  }
1922
2375
  unsetCurrentPage();
1923
2376
  if (originOnLoad !== undefined) {
@@ -2088,15 +2541,20 @@ function defineComponent(optionsOrSetup, config) {
2088
2541
  const bindings = setup(shallowReadonly(this.__props__)
2089
2542
  , context);
2090
2543
  if (bindings !== undefined) {
2544
+ let data;
2091
2545
  Object.keys(bindings).forEach((key) => {
2092
2546
  const value = bindings[key];
2093
2547
  if (isFunction(value)) {
2094
2548
  this[key] = value;
2095
2549
  return;
2096
2550
  }
2097
- this.setData({ [key]: deepToRaw(value) });
2551
+ data = data || {};
2552
+ data[key] = deepToRaw(value);
2098
2553
  deepWatch.call(this, key, value);
2099
2554
  });
2555
+ if (data !== undefined) {
2556
+ this.setData(data, flushPostFlushCbs);
2557
+ }
2100
2558
  }
2101
2559
  unsetCurrentComponent();
2102
2560
  if (originAttached !== undefined) {
@@ -2421,6 +2879,7 @@ exports.definePage = definePage;
2421
2879
  exports.effect = effect;
2422
2880
  exports.effectScope = effectScope;
2423
2881
  exports.getCurrentScope = getCurrentScope;
2882
+ exports.getCurrentWatcher = getCurrentWatcher;
2424
2883
  exports.inject = inject;
2425
2884
  exports.isProxy = isProxy;
2426
2885
  exports.isReactive = isReactive;
@@ -2454,6 +2913,7 @@ exports.onTabItemTap = onTabItemTap;
2454
2913
  exports.onThemeChange = onThemeChange;
2455
2914
  exports.onUnhandledRejection = onUnhandledRejection;
2456
2915
  exports.onUnload = onUnload;
2916
+ exports.onWatcherCleanup = onWatcherCleanup;
2457
2917
  exports.provide = provide;
2458
2918
  exports.proxyRefs = proxyRefs;
2459
2919
  exports.reactive = reactive;