@vue/reactivity 3.2.40 → 3.2.42

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