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