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