@vue/reactivity 3.2.40 → 3.2.41

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,1257 @@
1
1
  import { extend, isArray, 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
+ depsMap.forEach((dep, key) => {
309
+ if (key === 'length' || key >= newValue) {
310
+ deps.push(dep);
311
+ }
312
+ });
313
+ }
314
+ else {
315
+ // schedule runs for SET | ADD | DELETE
316
+ if (key !== void 0) {
317
+ deps.push(depsMap.get(key));
318
+ }
319
+ // also run for iteration key on ADD | DELETE | Map.SET
320
+ switch (type) {
321
+ case "add" /* TriggerOpTypes.ADD */:
322
+ if (!isArray(target)) {
323
+ deps.push(depsMap.get(ITERATE_KEY));
324
+ if (isMap(target)) {
325
+ deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
326
+ }
327
+ }
328
+ else if (isIntegerKey(key)) {
329
+ // new index added to array -> length changes
330
+ deps.push(depsMap.get('length'));
331
+ }
332
+ break;
333
+ case "delete" /* TriggerOpTypes.DELETE */:
334
+ if (!isArray(target)) {
335
+ deps.push(depsMap.get(ITERATE_KEY));
336
+ if (isMap(target)) {
337
+ deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
338
+ }
339
+ }
340
+ break;
341
+ case "set" /* TriggerOpTypes.SET */:
342
+ if (isMap(target)) {
343
+ deps.push(depsMap.get(ITERATE_KEY));
344
+ }
345
+ break;
346
+ }
347
+ }
348
+ const eventInfo = (process.env.NODE_ENV !== 'production')
349
+ ? { target, type, key, newValue, oldValue, oldTarget }
350
+ : undefined;
351
+ if (deps.length === 1) {
352
+ if (deps[0]) {
353
+ if ((process.env.NODE_ENV !== 'production')) {
354
+ triggerEffects(deps[0], eventInfo);
355
+ }
356
+ else {
357
+ triggerEffects(deps[0]);
358
+ }
359
+ }
360
+ }
361
+ else {
362
+ const effects = [];
363
+ for (const dep of deps) {
364
+ if (dep) {
365
+ effects.push(...dep);
366
+ }
367
+ }
368
+ if ((process.env.NODE_ENV !== 'production')) {
369
+ triggerEffects(createDep(effects), eventInfo);
370
+ }
371
+ else {
372
+ triggerEffects(createDep(effects));
373
+ }
374
+ }
375
+ }
376
+ function triggerEffects(dep, debuggerEventExtraInfo) {
377
+ // spread into array for stabilization
378
+ const effects = isArray(dep) ? dep : [...dep];
379
+ for (const effect of effects) {
380
+ if (effect.computed) {
381
+ triggerEffect(effect, debuggerEventExtraInfo);
382
+ }
383
+ }
384
+ for (const effect of effects) {
385
+ if (!effect.computed) {
386
+ triggerEffect(effect, debuggerEventExtraInfo);
387
+ }
388
+ }
389
+ }
390
+ function triggerEffect(effect, debuggerEventExtraInfo) {
391
+ if (effect !== activeEffect || effect.allowRecurse) {
392
+ if ((process.env.NODE_ENV !== 'production') && effect.onTrigger) {
393
+ effect.onTrigger(extend({ effect }, debuggerEventExtraInfo));
394
+ }
395
+ if (effect.scheduler) {
396
+ effect.scheduler();
397
+ }
398
+ else {
399
+ effect.run();
400
+ }
401
+ }
400
402
  }
401
403
 
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
404
+ const isNonTrackableKeys = /*#__PURE__*/ 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(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 = isArray(target);
471
+ if (!isReadonly && targetIsArray && hasOwn(arrayInstrumentations, key)) {
472
+ return Reflect.get(arrayInstrumentations, key, receiver);
473
+ }
474
+ const res = Reflect.get(target, key, receiver);
475
+ if (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 && isIntegerKey(key) ? res : res.value;
487
+ }
488
+ if (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 (!isArray(target) && isRef(oldValue) && !isRef(value)) {
511
+ oldValue.value = value;
512
+ return true;
513
+ }
514
+ }
515
+ const hadKey = isArray(target) && isIntegerKey(key)
516
+ ? Number(key) < target.length
517
+ : 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 (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 = 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 (!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 */, 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
+ if ((process.env.NODE_ENV !== 'production')) {
562
+ warn(`Set operation on key "${String(key)}" failed: target is readonly.`, target);
563
+ }
564
+ return true;
565
+ },
566
+ deleteProperty(target, key) {
567
+ if ((process.env.NODE_ENV !== 'production')) {
568
+ warn(`Delete operation on key "${String(key)}" failed: target is readonly.`, target);
569
+ }
570
+ return true;
571
+ }
572
+ };
573
+ const shallowReactiveHandlers = /*#__PURE__*/ 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__*/ extend({}, readonlyHandlers, {
581
+ get: shallowReadonlyGet
580
582
  });
581
583
 
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
- }
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 if ((process.env.NODE_ENV !== 'production')) {
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 (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 if ((process.env.NODE_ENV !== 'production')) {
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 = (process.env.NODE_ENV !== 'production')
687
+ ? isMap(target)
688
+ ? new Map(target)
689
+ : new Set(target)
690
+ : undefined;
691
+ // forward the operation before queueing reactions
692
+ const result = target.clear();
693
+ if (hadItems) {
694
+ trigger(target, "clear" /* TriggerOpTypes.CLEAR */, undefined, undefined, oldTarget);
695
+ }
696
+ return result;
697
+ }
698
+ function createForEach(isReadonly, isShallow) {
699
+ return function forEach(callback, thisArg) {
700
+ const observed = this;
701
+ const target = observed["__v_raw" /* ReactiveFlags.RAW */];
702
+ const rawTarget = toRaw(target);
703
+ const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
704
+ !isReadonly && track(rawTarget, "iterate" /* TrackOpTypes.ITERATE */, ITERATE_KEY);
705
+ return target.forEach((value, key) => {
706
+ // important: make sure the callback is
707
+ // 1. invoked with the reactive map as `this` and 3rd arg
708
+ // 2. the value received should be a corresponding reactive/readonly.
709
+ return callback.call(thisArg, wrap(value), wrap(key), observed);
710
+ });
711
+ };
712
+ }
713
+ function createIterableMethod(method, isReadonly, isShallow) {
714
+ return function (...args) {
715
+ const target = this["__v_raw" /* ReactiveFlags.RAW */];
716
+ const rawTarget = toRaw(target);
717
+ const targetIsMap = isMap(rawTarget);
718
+ const isPair = method === 'entries' || (method === Symbol.iterator && targetIsMap);
719
+ const isKeyOnly = method === 'keys' && targetIsMap;
720
+ const innerIterator = target[method](...args);
721
+ const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
722
+ !isReadonly &&
723
+ track(rawTarget, "iterate" /* TrackOpTypes.ITERATE */, isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY);
724
+ // return a wrapped iterator which returns observed versions of the
725
+ // values emitted from the real iterator
726
+ return {
727
+ // iterator protocol
728
+ next() {
729
+ const { value, done } = innerIterator.next();
730
+ return done
731
+ ? { value, done }
732
+ : {
733
+ value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
734
+ done
735
+ };
736
+ },
737
+ // iterable protocol
738
+ [Symbol.iterator]() {
739
+ return this;
740
+ }
741
+ };
742
+ };
743
+ }
744
+ function createReadonlyMethod(type) {
745
+ return function (...args) {
746
+ if ((process.env.NODE_ENV !== 'production')) {
747
+ const key = args[0] ? `on key "${args[0]}" ` : ``;
748
+ console.warn(`${capitalize(type)} operation ${key}failed: target is readonly.`, toRaw(this));
749
+ }
750
+ return type === "delete" /* TriggerOpTypes.DELETE */ ? false : this;
751
+ };
752
+ }
753
+ function createInstrumentations() {
754
+ const mutableInstrumentations = {
755
+ get(key) {
756
+ return get$1(this, key);
757
+ },
758
+ get size() {
759
+ return size(this);
760
+ },
761
+ has: has$1,
762
+ add,
763
+ set: set$1,
764
+ delete: deleteEntry,
765
+ clear,
766
+ forEach: createForEach(false, false)
767
+ };
768
+ const shallowInstrumentations = {
769
+ get(key) {
770
+ return get$1(this, key, false, true);
771
+ },
772
+ get size() {
773
+ return size(this);
774
+ },
775
+ has: has$1,
776
+ add,
777
+ set: set$1,
778
+ delete: deleteEntry,
779
+ clear,
780
+ forEach: createForEach(false, true)
781
+ };
782
+ const readonlyInstrumentations = {
783
+ get(key) {
784
+ return get$1(this, key, true);
785
+ },
786
+ get size() {
787
+ return size(this, true);
788
+ },
789
+ has(key) {
790
+ return has$1.call(this, key, true);
791
+ },
792
+ add: createReadonlyMethod("add" /* TriggerOpTypes.ADD */),
793
+ set: createReadonlyMethod("set" /* TriggerOpTypes.SET */),
794
+ delete: createReadonlyMethod("delete" /* TriggerOpTypes.DELETE */),
795
+ clear: createReadonlyMethod("clear" /* TriggerOpTypes.CLEAR */),
796
+ forEach: createForEach(true, false)
797
+ };
798
+ const shallowReadonlyInstrumentations = {
799
+ get(key) {
800
+ return get$1(this, key, true, true);
801
+ },
802
+ get size() {
803
+ return size(this, true);
804
+ },
805
+ has(key) {
806
+ return has$1.call(this, key, true);
807
+ },
808
+ add: createReadonlyMethod("add" /* TriggerOpTypes.ADD */),
809
+ set: createReadonlyMethod("set" /* TriggerOpTypes.SET */),
810
+ delete: createReadonlyMethod("delete" /* TriggerOpTypes.DELETE */),
811
+ clear: createReadonlyMethod("clear" /* TriggerOpTypes.CLEAR */),
812
+ forEach: createForEach(true, true)
813
+ };
814
+ const iteratorMethods = ['keys', 'values', 'entries', Symbol.iterator];
815
+ iteratorMethods.forEach(method => {
816
+ mutableInstrumentations[method] = createIterableMethod(method, false, false);
817
+ readonlyInstrumentations[method] = createIterableMethod(method, true, false);
818
+ shallowInstrumentations[method] = createIterableMethod(method, false, true);
819
+ shallowReadonlyInstrumentations[method] = createIterableMethod(method, true, true);
820
+ });
821
+ return [
822
+ mutableInstrumentations,
823
+ readonlyInstrumentations,
824
+ shallowInstrumentations,
825
+ shallowReadonlyInstrumentations
826
+ ];
827
+ }
828
+ const [mutableInstrumentations, readonlyInstrumentations, shallowInstrumentations, shallowReadonlyInstrumentations] = /* #__PURE__*/ createInstrumentations();
829
+ function createInstrumentationGetter(isReadonly, shallow) {
830
+ const instrumentations = shallow
831
+ ? isReadonly
832
+ ? shallowReadonlyInstrumentations
833
+ : shallowInstrumentations
834
+ : isReadonly
835
+ ? readonlyInstrumentations
836
+ : mutableInstrumentations;
837
+ return (target, key, receiver) => {
838
+ if (key === "__v_isReactive" /* ReactiveFlags.IS_REACTIVE */) {
839
+ return !isReadonly;
840
+ }
841
+ else if (key === "__v_isReadonly" /* ReactiveFlags.IS_READONLY */) {
842
+ return isReadonly;
843
+ }
844
+ else if (key === "__v_raw" /* ReactiveFlags.RAW */) {
845
+ return target;
846
+ }
847
+ return Reflect.get(hasOwn(instrumentations, key) && key in target
848
+ ? instrumentations
849
+ : target, key, receiver);
850
+ };
851
+ }
852
+ const mutableCollectionHandlers = {
853
+ get: /*#__PURE__*/ createInstrumentationGetter(false, false)
854
+ };
855
+ const shallowCollectionHandlers = {
856
+ get: /*#__PURE__*/ createInstrumentationGetter(false, true)
857
+ };
858
+ const readonlyCollectionHandlers = {
859
+ get: /*#__PURE__*/ createInstrumentationGetter(true, false)
860
+ };
861
+ const shallowReadonlyCollectionHandlers = {
862
+ get: /*#__PURE__*/ createInstrumentationGetter(true, true)
863
+ };
864
+ function checkIdentityKeys(target, has, key) {
865
+ const rawKey = toRaw(key);
866
+ if (rawKey !== key && has.call(target, rawKey)) {
867
+ const type = toRawType(target);
868
+ console.warn(`Reactive ${type} contains both the raw and reactive ` +
869
+ `versions of the same object${type === `Map` ? ` as keys` : ``}, ` +
870
+ `which can lead to inconsistencies. ` +
871
+ `Avoid differentiating between the raw and reactive versions ` +
872
+ `of an object and only use the reactive version if possible.`);
873
+ }
872
874
  }
873
875
 
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;
876
+ const reactiveMap = new WeakMap();
877
+ const shallowReactiveMap = new WeakMap();
878
+ const readonlyMap = new WeakMap();
879
+ const shallowReadonlyMap = new WeakMap();
880
+ function targetTypeMap(rawType) {
881
+ switch (rawType) {
882
+ case 'Object':
883
+ case 'Array':
884
+ return 1 /* TargetType.COMMON */;
885
+ case 'Map':
886
+ case 'Set':
887
+ case 'WeakMap':
888
+ case 'WeakSet':
889
+ return 2 /* TargetType.COLLECTION */;
890
+ default:
891
+ return 0 /* TargetType.INVALID */;
892
+ }
893
+ }
894
+ function getTargetType(value) {
895
+ return value["__v_skip" /* ReactiveFlags.SKIP */] || !Object.isExtensible(value)
896
+ ? 0 /* TargetType.INVALID */
897
+ : targetTypeMap(toRawType(value));
898
+ }
899
+ function reactive(target) {
900
+ // if trying to observe a readonly proxy, return the readonly version.
901
+ if (isReadonly(target)) {
902
+ return target;
903
+ }
904
+ return createReactiveObject(target, false, mutableHandlers, mutableCollectionHandlers, reactiveMap);
905
+ }
906
+ /**
907
+ * Return a shallowly-reactive copy of the original object, where only the root
908
+ * level properties are reactive. It also does not auto-unwrap refs (even at the
909
+ * root level).
910
+ */
911
+ function shallowReactive(target) {
912
+ return createReactiveObject(target, false, shallowReactiveHandlers, shallowCollectionHandlers, shallowReactiveMap);
913
+ }
914
+ /**
915
+ * Creates a readonly copy of the original object. Note the returned copy is not
916
+ * made reactive, but `readonly` can be called on an already reactive object.
917
+ */
918
+ function readonly(target) {
919
+ return createReactiveObject(target, true, readonlyHandlers, readonlyCollectionHandlers, readonlyMap);
920
+ }
921
+ /**
922
+ * Returns a reactive-copy of the original object, where only the root level
923
+ * properties are readonly, and does NOT unwrap refs nor recursively convert
924
+ * returned properties.
925
+ * This is used for creating the props proxy object for stateful components.
926
+ */
927
+ function shallowReadonly(target) {
928
+ return createReactiveObject(target, true, shallowReadonlyHandlers, shallowReadonlyCollectionHandlers, shallowReadonlyMap);
929
+ }
930
+ function createReactiveObject(target, isReadonly, baseHandlers, collectionHandlers, proxyMap) {
931
+ if (!isObject(target)) {
932
+ if ((process.env.NODE_ENV !== 'production')) {
933
+ console.warn(`value cannot be made reactive: ${String(target)}`);
934
+ }
935
+ return target;
936
+ }
937
+ // target is already a Proxy, return it.
938
+ // exception: calling readonly() on a reactive object
939
+ if (target["__v_raw" /* ReactiveFlags.RAW */] &&
940
+ !(isReadonly && target["__v_isReactive" /* ReactiveFlags.IS_REACTIVE */])) {
941
+ return target;
942
+ }
943
+ // target already has corresponding Proxy
944
+ const existingProxy = proxyMap.get(target);
945
+ if (existingProxy) {
946
+ return existingProxy;
947
+ }
948
+ // only specific value types can be observed.
949
+ const targetType = getTargetType(target);
950
+ if (targetType === 0 /* TargetType.INVALID */) {
951
+ return target;
952
+ }
953
+ const proxy = new Proxy(target, targetType === 2 /* TargetType.COLLECTION */ ? collectionHandlers : baseHandlers);
954
+ proxyMap.set(target, proxy);
955
+ return proxy;
956
+ }
957
+ function isReactive(value) {
958
+ if (isReadonly(value)) {
959
+ return isReactive(value["__v_raw" /* ReactiveFlags.RAW */]);
960
+ }
961
+ return !!(value && value["__v_isReactive" /* ReactiveFlags.IS_REACTIVE */]);
962
+ }
963
+ function isReadonly(value) {
964
+ return !!(value && value["__v_isReadonly" /* ReactiveFlags.IS_READONLY */]);
965
+ }
966
+ function isShallow(value) {
967
+ return !!(value && value["__v_isShallow" /* ReactiveFlags.IS_SHALLOW */]);
968
+ }
969
+ function isProxy(value) {
970
+ return isReactive(value) || isReadonly(value);
971
+ }
972
+ function toRaw(observed) {
973
+ const raw = observed && observed["__v_raw" /* ReactiveFlags.RAW */];
974
+ return raw ? toRaw(raw) : observed;
975
+ }
976
+ function markRaw(value) {
977
+ def(value, "__v_skip" /* ReactiveFlags.SKIP */, true);
978
+ return value;
979
+ }
980
+ const toReactive = (value) => isObject(value) ? reactive(value) : value;
979
981
  const toReadonly = (value) => isObject(value) ? readonly(value) : value;
980
982
 
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);
983
+ function trackRefValue(ref) {
984
+ if (shouldTrack && activeEffect) {
985
+ ref = toRaw(ref);
986
+ if ((process.env.NODE_ENV !== 'production')) {
987
+ trackEffects(ref.dep || (ref.dep = createDep()), {
988
+ target: ref,
989
+ type: "get" /* TrackOpTypes.GET */,
990
+ key: 'value'
991
+ });
992
+ }
993
+ else {
994
+ trackEffects(ref.dep || (ref.dep = createDep()));
995
+ }
996
+ }
997
+ }
998
+ function triggerRefValue(ref, newVal) {
999
+ ref = toRaw(ref);
1000
+ if (ref.dep) {
1001
+ if ((process.env.NODE_ENV !== 'production')) {
1002
+ triggerEffects(ref.dep, {
1003
+ target: ref,
1004
+ type: "set" /* TriggerOpTypes.SET */,
1005
+ key: 'value',
1006
+ newValue: newVal
1007
+ });
1008
+ }
1009
+ else {
1010
+ triggerEffects(ref.dep);
1011
+ }
1012
+ }
1013
+ }
1014
+ function isRef(r) {
1015
+ return !!(r && r.__v_isRef === true);
1016
+ }
1017
+ function ref(value) {
1018
+ return createRef(value, false);
1019
+ }
1020
+ function shallowRef(value) {
1021
+ return createRef(value, true);
1022
+ }
1023
+ function createRef(rawValue, shallow) {
1024
+ if (isRef(rawValue)) {
1025
+ return rawValue;
1026
+ }
1027
+ return new RefImpl(rawValue, shallow);
1028
+ }
1029
+ class RefImpl {
1030
+ constructor(value, __v_isShallow) {
1031
+ this.__v_isShallow = __v_isShallow;
1032
+ this.dep = undefined;
1033
+ this.__v_isRef = true;
1034
+ this._rawValue = __v_isShallow ? value : toRaw(value);
1035
+ this._value = __v_isShallow ? value : toReactive(value);
1036
+ }
1037
+ get value() {
1038
+ trackRefValue(this);
1039
+ return this._value;
1040
+ }
1041
+ set value(newVal) {
1042
+ const useDirectValue = this.__v_isShallow || isShallow(newVal) || isReadonly(newVal);
1043
+ newVal = useDirectValue ? newVal : toRaw(newVal);
1044
+ if (hasChanged(newVal, this._rawValue)) {
1045
+ this._rawValue = newVal;
1046
+ this._value = useDirectValue ? newVal : toReactive(newVal);
1047
+ triggerRefValue(this, newVal);
1048
+ }
1049
+ }
1050
+ }
1051
+ function triggerRef(ref) {
1052
+ triggerRefValue(ref, (process.env.NODE_ENV !== 'production') ? ref.value : void 0);
1053
+ }
1054
+ function unref(ref) {
1055
+ return isRef(ref) ? ref.value : ref;
1056
+ }
1057
+ const shallowUnwrapHandlers = {
1058
+ get: (target, key, receiver) => unref(Reflect.get(target, key, receiver)),
1059
+ set: (target, key, value, receiver) => {
1060
+ const oldValue = target[key];
1061
+ if (isRef(oldValue) && !isRef(value)) {
1062
+ oldValue.value = value;
1063
+ return true;
1064
+ }
1065
+ else {
1066
+ return Reflect.set(target, key, value, receiver);
1067
+ }
1068
+ }
1069
+ };
1070
+ function proxyRefs(objectWithRefs) {
1071
+ return isReactive(objectWithRefs)
1072
+ ? objectWithRefs
1073
+ : new Proxy(objectWithRefs, shallowUnwrapHandlers);
1074
+ }
1075
+ class CustomRefImpl {
1076
+ constructor(factory) {
1077
+ this.dep = undefined;
1078
+ this.__v_isRef = true;
1079
+ const { get, set } = factory(() => trackRefValue(this), () => triggerRefValue(this));
1080
+ this._get = get;
1081
+ this._set = set;
1082
+ }
1083
+ get value() {
1084
+ return this._get();
1085
+ }
1086
+ set value(newVal) {
1087
+ this._set(newVal);
1088
+ }
1089
+ }
1090
+ function customRef(factory) {
1091
+ return new CustomRefImpl(factory);
1092
+ }
1093
+ function toRefs(object) {
1094
+ if ((process.env.NODE_ENV !== 'production') && !isProxy(object)) {
1095
+ console.warn(`toRefs() expects a reactive object but received a plain one.`);
1096
+ }
1097
+ const ret = isArray(object) ? new Array(object.length) : {};
1098
+ for (const key in object) {
1099
+ ret[key] = toRef(object, key);
1100
+ }
1101
+ return ret;
1102
+ }
1103
+ class ObjectRefImpl {
1104
+ constructor(_object, _key, _defaultValue) {
1105
+ this._object = _object;
1106
+ this._key = _key;
1107
+ this._defaultValue = _defaultValue;
1108
+ this.__v_isRef = true;
1109
+ }
1110
+ get value() {
1111
+ const val = this._object[this._key];
1112
+ return val === undefined ? this._defaultValue : val;
1113
+ }
1114
+ set value(newVal) {
1115
+ this._object[this._key] = newVal;
1116
+ }
1117
+ }
1118
+ function toRef(object, key, defaultValue) {
1119
+ const val = object[key];
1120
+ return isRef(val)
1121
+ ? val
1122
+ : new ObjectRefImpl(object, key, defaultValue);
1121
1123
  }
1122
1124
 
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;
1125
+ var _a;
1126
+ class ComputedRefImpl {
1127
+ constructor(getter, _setter, isReadonly, isSSR) {
1128
+ this._setter = _setter;
1129
+ this.dep = undefined;
1130
+ this.__v_isRef = true;
1131
+ this[_a] = false;
1132
+ this._dirty = true;
1133
+ this.effect = new ReactiveEffect(getter, () => {
1134
+ if (!this._dirty) {
1135
+ this._dirty = true;
1136
+ triggerRefValue(this);
1137
+ }
1138
+ });
1139
+ this.effect.computed = this;
1140
+ this.effect.active = this._cacheable = !isSSR;
1141
+ this["__v_isReadonly" /* ReactiveFlags.IS_READONLY */] = isReadonly;
1142
+ }
1143
+ get value() {
1144
+ // the computed ref may get wrapped by other proxies e.g. readonly() #3376
1145
+ const self = toRaw(this);
1146
+ trackRefValue(self);
1147
+ if (self._dirty || !self._cacheable) {
1148
+ self._dirty = false;
1149
+ self._value = self.effect.run();
1150
+ }
1151
+ return self._value;
1152
+ }
1153
+ set value(newValue) {
1154
+ this._setter(newValue);
1155
+ }
1156
+ }
1157
+ _a = "__v_isReadonly" /* ReactiveFlags.IS_READONLY */;
1158
+ function computed(getterOrOptions, debugOptions, isSSR = false) {
1159
+ let getter;
1160
+ let setter;
1161
+ const onlyGetter = isFunction(getterOrOptions);
1162
+ if (onlyGetter) {
1163
+ getter = getterOrOptions;
1164
+ setter = (process.env.NODE_ENV !== 'production')
1165
+ ? () => {
1166
+ console.warn('Write operation failed: computed value is readonly');
1167
+ }
1168
+ : NOOP;
1169
+ }
1170
+ else {
1171
+ getter = getterOrOptions.get;
1172
+ setter = getterOrOptions.set;
1173
+ }
1174
+ const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter, isSSR);
1175
+ if ((process.env.NODE_ENV !== 'production') && debugOptions && !isSSR) {
1176
+ cRef.effect.onTrack = debugOptions.onTrack;
1177
+ cRef.effect.onTrigger = debugOptions.onTrigger;
1178
+ }
1179
+ return cRef;
1178
1180
  }
1179
1181
 
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);
1182
+ var _a$1;
1183
+ const tick = /*#__PURE__*/ Promise.resolve();
1184
+ const queue = [];
1185
+ let queued = false;
1186
+ const scheduler = (fn) => {
1187
+ queue.push(fn);
1188
+ if (!queued) {
1189
+ queued = true;
1190
+ tick.then(flush);
1191
+ }
1192
+ };
1193
+ const flush = () => {
1194
+ for (let i = 0; i < queue.length; i++) {
1195
+ queue[i]();
1196
+ }
1197
+ queue.length = 0;
1198
+ queued = false;
1199
+ };
1200
+ class DeferredComputedRefImpl {
1201
+ constructor(getter) {
1202
+ this.dep = undefined;
1203
+ this._dirty = true;
1204
+ this.__v_isRef = true;
1205
+ this[_a$1] = true;
1206
+ let compareTarget;
1207
+ let hasCompareTarget = false;
1208
+ let scheduled = false;
1209
+ this.effect = new ReactiveEffect(getter, (computedTrigger) => {
1210
+ if (this.dep) {
1211
+ if (computedTrigger) {
1212
+ compareTarget = this._value;
1213
+ hasCompareTarget = true;
1214
+ }
1215
+ else if (!scheduled) {
1216
+ const valueToCompare = hasCompareTarget ? compareTarget : this._value;
1217
+ scheduled = true;
1218
+ hasCompareTarget = false;
1219
+ scheduler(() => {
1220
+ if (this.effect.active && this._get() !== valueToCompare) {
1221
+ triggerRefValue(this);
1222
+ }
1223
+ scheduled = false;
1224
+ });
1225
+ }
1226
+ // chained upstream computeds are notified synchronously to ensure
1227
+ // value invalidation in case of sync access; normal effects are
1228
+ // deferred to be triggered in scheduler.
1229
+ for (const e of this.dep) {
1230
+ if (e.computed instanceof DeferredComputedRefImpl) {
1231
+ e.scheduler(true /* computedTrigger */);
1232
+ }
1233
+ }
1234
+ }
1235
+ this._dirty = true;
1236
+ });
1237
+ this.effect.computed = this;
1238
+ }
1239
+ _get() {
1240
+ if (this._dirty) {
1241
+ this._dirty = false;
1242
+ return (this._value = this.effect.run());
1243
+ }
1244
+ return this._value;
1245
+ }
1246
+ get value() {
1247
+ trackRefValue(this);
1248
+ // the computed ref may get wrapped by other proxies e.g. readonly() #3376
1249
+ return toRaw(this)._get();
1250
+ }
1251
+ }
1252
+ _a$1 = "__v_isReadonly" /* ReactiveFlags.IS_READONLY */;
1253
+ function deferredComputed(getter) {
1254
+ return new DeferredComputedRefImpl(getter);
1253
1255
  }
1254
1256
 
1255
1257
  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 };