@vue/reactivity 3.2.40 → 3.2.42

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