@vue/reactivity 3.6.0-beta.4 → 3.6.0-beta.6
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.
- package/dist/reactivity.cjs.js +1761 -1878
- package/dist/reactivity.cjs.prod.js +1652 -1687
- package/dist/reactivity.d.ts +622 -624
- package/dist/reactivity.esm-browser.js +1805 -1889
- package/dist/reactivity.esm-browser.prod.js +5 -4
- package/dist/reactivity.esm-bundler.js +1761 -1885
- package/dist/reactivity.global.js +2048 -2133
- package/dist/reactivity.global.prod.js +5 -4
- package/package.json +2 -2
|
@@ -1,24 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vue/reactivity v3.6.0-beta.
|
|
3
|
-
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
4
|
-
* @license MIT
|
|
5
|
-
**/
|
|
6
|
-
'
|
|
2
|
+
* @vue/reactivity v3.6.0-beta.6
|
|
3
|
+
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
4
|
+
* @license MIT
|
|
5
|
+
**/
|
|
6
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
7
|
+
let _vue_shared = require("@vue/shared");
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
9
|
+
//#region packages/reactivity/src/system.ts
|
|
10
|
+
const ReactiveFlags$1 = {
|
|
11
|
+
"None": 0,
|
|
12
|
+
"0": "None",
|
|
13
|
+
"Mutable": 1,
|
|
14
|
+
"1": "Mutable",
|
|
15
|
+
"Watching": 2,
|
|
16
|
+
"2": "Watching",
|
|
17
|
+
"RecursedCheck": 4,
|
|
18
|
+
"4": "RecursedCheck",
|
|
19
|
+
"Recursed": 8,
|
|
20
|
+
"8": "Recursed",
|
|
21
|
+
"Dirty": 16,
|
|
22
|
+
"16": "Dirty",
|
|
23
|
+
"Pending": 32,
|
|
24
|
+
"32": "Pending"
|
|
25
|
+
};
|
|
22
26
|
const notifyBuffer = [];
|
|
23
27
|
let batchDepth = 0;
|
|
24
28
|
let activeSub = void 0;
|
|
@@ -26,1831 +30,1792 @@ let globalVersion = 0;
|
|
|
26
30
|
let notifyIndex = 0;
|
|
27
31
|
let notifyBufferLength = 0;
|
|
28
32
|
function setActiveSub(sub) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
try {
|
|
34
|
+
return activeSub;
|
|
35
|
+
} finally {
|
|
36
|
+
activeSub = sub;
|
|
37
|
+
}
|
|
34
38
|
}
|
|
35
39
|
function startBatch() {
|
|
36
|
-
|
|
40
|
+
++batchDepth;
|
|
37
41
|
}
|
|
38
42
|
function endBatch() {
|
|
39
|
-
|
|
40
|
-
flush();
|
|
41
|
-
}
|
|
43
|
+
if (!--batchDepth && notifyBufferLength) flush();
|
|
42
44
|
}
|
|
43
45
|
function link(dep, sub) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
if (flags & 1 /* Mutable */) {
|
|
138
|
-
const subSubs = sub.subs;
|
|
139
|
-
if (subSubs !== void 0) {
|
|
140
|
-
link2 = subSubs;
|
|
141
|
-
if (subSubs.nextSub !== void 0) {
|
|
142
|
-
stack = { value: next, prev: stack };
|
|
143
|
-
next = link2.nextSub;
|
|
144
|
-
}
|
|
145
|
-
continue;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
if ((link2 = next) !== void 0) {
|
|
150
|
-
next = link2.nextSub;
|
|
151
|
-
continue;
|
|
152
|
-
}
|
|
153
|
-
while (stack !== void 0) {
|
|
154
|
-
link2 = stack.value;
|
|
155
|
-
stack = stack.prev;
|
|
156
|
-
if (link2 !== void 0) {
|
|
157
|
-
next = link2.nextSub;
|
|
158
|
-
continue top;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
break;
|
|
162
|
-
} while (true);
|
|
46
|
+
const prevDep = sub.depsTail;
|
|
47
|
+
if (prevDep !== void 0 && prevDep.dep === dep) return;
|
|
48
|
+
const nextDep = prevDep !== void 0 ? prevDep.nextDep : sub.deps;
|
|
49
|
+
if (nextDep !== void 0 && nextDep.dep === dep) {
|
|
50
|
+
nextDep.version = globalVersion;
|
|
51
|
+
sub.depsTail = nextDep;
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const prevSub = dep.subsTail;
|
|
55
|
+
if (prevSub !== void 0 && prevSub.version === globalVersion && prevSub.sub === sub) return;
|
|
56
|
+
const newLink = sub.depsTail = dep.subsTail = {
|
|
57
|
+
version: globalVersion,
|
|
58
|
+
dep,
|
|
59
|
+
sub,
|
|
60
|
+
prevDep,
|
|
61
|
+
nextDep,
|
|
62
|
+
prevSub,
|
|
63
|
+
nextSub: void 0
|
|
64
|
+
};
|
|
65
|
+
if (nextDep !== void 0) nextDep.prevDep = newLink;
|
|
66
|
+
if (prevDep !== void 0) prevDep.nextDep = newLink;
|
|
67
|
+
else sub.deps = newLink;
|
|
68
|
+
if (prevSub !== void 0) prevSub.nextSub = newLink;
|
|
69
|
+
else dep.subs = newLink;
|
|
70
|
+
}
|
|
71
|
+
function unlink(link, sub = link.sub) {
|
|
72
|
+
const dep = link.dep;
|
|
73
|
+
const prevDep = link.prevDep;
|
|
74
|
+
const nextDep = link.nextDep;
|
|
75
|
+
const nextSub = link.nextSub;
|
|
76
|
+
const prevSub = link.prevSub;
|
|
77
|
+
if (nextDep !== void 0) nextDep.prevDep = prevDep;
|
|
78
|
+
else sub.depsTail = prevDep;
|
|
79
|
+
if (prevDep !== void 0) prevDep.nextDep = nextDep;
|
|
80
|
+
else sub.deps = nextDep;
|
|
81
|
+
if (nextSub !== void 0) nextSub.prevSub = prevSub;
|
|
82
|
+
else dep.subsTail = prevSub;
|
|
83
|
+
if (prevSub !== void 0) prevSub.nextSub = nextSub;
|
|
84
|
+
else if ((dep.subs = nextSub) === void 0) {
|
|
85
|
+
let toRemove = dep.deps;
|
|
86
|
+
if (toRemove !== void 0) {
|
|
87
|
+
do
|
|
88
|
+
toRemove = unlink(toRemove, dep);
|
|
89
|
+
while (toRemove !== void 0);
|
|
90
|
+
dep.flags |= 16;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return nextDep;
|
|
94
|
+
}
|
|
95
|
+
function propagate(link) {
|
|
96
|
+
let next = link.nextSub;
|
|
97
|
+
let stack;
|
|
98
|
+
top: do {
|
|
99
|
+
const sub = link.sub;
|
|
100
|
+
let flags = sub.flags;
|
|
101
|
+
if (flags & 3) {
|
|
102
|
+
if (!(flags & 60)) sub.flags = flags | 32;
|
|
103
|
+
else if (!(flags & 12)) flags = 0;
|
|
104
|
+
else if (!(flags & 4)) sub.flags = flags & -9 | 32;
|
|
105
|
+
else if (!(flags & 48) && isValidLink(link, sub)) {
|
|
106
|
+
sub.flags = flags | 40;
|
|
107
|
+
flags &= 1;
|
|
108
|
+
} else flags = 0;
|
|
109
|
+
if (flags & 2) notifyBuffer[notifyBufferLength++] = sub;
|
|
110
|
+
if (flags & 1) {
|
|
111
|
+
const subSubs = sub.subs;
|
|
112
|
+
if (subSubs !== void 0) {
|
|
113
|
+
link = subSubs;
|
|
114
|
+
if (subSubs.nextSub !== void 0) {
|
|
115
|
+
stack = {
|
|
116
|
+
value: next,
|
|
117
|
+
prev: stack
|
|
118
|
+
};
|
|
119
|
+
next = link.nextSub;
|
|
120
|
+
}
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if ((link = next) !== void 0) {
|
|
126
|
+
next = link.nextSub;
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
while (stack !== void 0) {
|
|
130
|
+
link = stack.value;
|
|
131
|
+
stack = stack.prev;
|
|
132
|
+
if (link !== void 0) {
|
|
133
|
+
next = link.nextSub;
|
|
134
|
+
continue top;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
break;
|
|
138
|
+
} while (true);
|
|
163
139
|
}
|
|
164
140
|
function startTracking(sub) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
141
|
+
++globalVersion;
|
|
142
|
+
sub.depsTail = void 0;
|
|
143
|
+
sub.flags = sub.flags & -57 | 4;
|
|
144
|
+
return setActiveSub(sub);
|
|
169
145
|
}
|
|
170
146
|
function endTracking(sub, prevSub) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
sub.flags &= -5 /* RecursedCheck */;
|
|
147
|
+
activeSub = prevSub;
|
|
148
|
+
const depsTail = sub.depsTail;
|
|
149
|
+
let toRemove = depsTail !== void 0 ? depsTail.nextDep : sub.deps;
|
|
150
|
+
while (toRemove !== void 0) toRemove = unlink(toRemove, sub);
|
|
151
|
+
sub.flags &= -5;
|
|
178
152
|
}
|
|
179
153
|
function flush() {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}
|
|
188
|
-
function checkDirty(
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}
|
|
249
|
-
function shallowPropagate(link2) {
|
|
250
|
-
do {
|
|
251
|
-
const sub = link2.sub;
|
|
252
|
-
const nextSub = link2.nextSub;
|
|
253
|
-
const subFlags = sub.flags;
|
|
254
|
-
if ((subFlags & (32 /* Pending */ | 16 /* Dirty */)) === 32 /* Pending */) {
|
|
255
|
-
sub.flags = subFlags | 16 /* Dirty */;
|
|
256
|
-
}
|
|
257
|
-
link2 = nextSub;
|
|
258
|
-
} while (link2 !== void 0);
|
|
154
|
+
while (notifyIndex < notifyBufferLength) {
|
|
155
|
+
const effect = notifyBuffer[notifyIndex];
|
|
156
|
+
notifyBuffer[notifyIndex++] = void 0;
|
|
157
|
+
effect.notify();
|
|
158
|
+
}
|
|
159
|
+
notifyIndex = 0;
|
|
160
|
+
notifyBufferLength = 0;
|
|
161
|
+
}
|
|
162
|
+
function checkDirty(link, sub) {
|
|
163
|
+
let stack;
|
|
164
|
+
let checkDepth = 0;
|
|
165
|
+
top: do {
|
|
166
|
+
const dep = link.dep;
|
|
167
|
+
const depFlags = dep.flags;
|
|
168
|
+
let dirty = false;
|
|
169
|
+
if (sub.flags & 16) dirty = true;
|
|
170
|
+
else if ((depFlags & 17) === 17) {
|
|
171
|
+
if (dep.update()) {
|
|
172
|
+
const subs = dep.subs;
|
|
173
|
+
if (subs.nextSub !== void 0) shallowPropagate(subs);
|
|
174
|
+
dirty = true;
|
|
175
|
+
}
|
|
176
|
+
} else if ((depFlags & 33) === 33) {
|
|
177
|
+
if (link.nextSub !== void 0 || link.prevSub !== void 0) stack = {
|
|
178
|
+
value: link,
|
|
179
|
+
prev: stack
|
|
180
|
+
};
|
|
181
|
+
link = dep.deps;
|
|
182
|
+
sub = dep;
|
|
183
|
+
++checkDepth;
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
if (!dirty && link.nextDep !== void 0) {
|
|
187
|
+
link = link.nextDep;
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
while (checkDepth) {
|
|
191
|
+
--checkDepth;
|
|
192
|
+
const firstSub = sub.subs;
|
|
193
|
+
const hasMultipleSubs = firstSub.nextSub !== void 0;
|
|
194
|
+
if (hasMultipleSubs) {
|
|
195
|
+
link = stack.value;
|
|
196
|
+
stack = stack.prev;
|
|
197
|
+
} else link = firstSub;
|
|
198
|
+
if (dirty) {
|
|
199
|
+
if (sub.update()) {
|
|
200
|
+
if (hasMultipleSubs) shallowPropagate(firstSub);
|
|
201
|
+
sub = link.sub;
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
} else sub.flags &= -33;
|
|
205
|
+
sub = link.sub;
|
|
206
|
+
if (link.nextDep !== void 0) {
|
|
207
|
+
link = link.nextDep;
|
|
208
|
+
continue top;
|
|
209
|
+
}
|
|
210
|
+
dirty = false;
|
|
211
|
+
}
|
|
212
|
+
return dirty;
|
|
213
|
+
} while (true);
|
|
214
|
+
}
|
|
215
|
+
function shallowPropagate(link) {
|
|
216
|
+
do {
|
|
217
|
+
const sub = link.sub;
|
|
218
|
+
const nextSub = link.nextSub;
|
|
219
|
+
const subFlags = sub.flags;
|
|
220
|
+
if ((subFlags & 48) === 32) sub.flags = subFlags | 16;
|
|
221
|
+
link = nextSub;
|
|
222
|
+
} while (link !== void 0);
|
|
259
223
|
}
|
|
260
224
|
function isValidLink(checkLink, sub) {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
}
|
|
268
|
-
return false;
|
|
225
|
+
let link = sub.depsTail;
|
|
226
|
+
while (link !== void 0) {
|
|
227
|
+
if (link === checkLink) return true;
|
|
228
|
+
link = link.prevDep;
|
|
229
|
+
}
|
|
230
|
+
return false;
|
|
269
231
|
}
|
|
270
232
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
}
|
|
233
|
+
//#endregion
|
|
234
|
+
//#region packages/reactivity/src/dep.ts
|
|
235
|
+
var Dep = class {
|
|
236
|
+
constructor(map, key) {
|
|
237
|
+
this.map = map;
|
|
238
|
+
this.key = key;
|
|
239
|
+
this._subs = void 0;
|
|
240
|
+
this.subsTail = void 0;
|
|
241
|
+
this.flags = 0;
|
|
242
|
+
}
|
|
243
|
+
get subs() {
|
|
244
|
+
return this._subs;
|
|
245
|
+
}
|
|
246
|
+
set subs(value) {
|
|
247
|
+
this._subs = value;
|
|
248
|
+
if (value === void 0) this.map.delete(this.key);
|
|
249
|
+
}
|
|
250
|
+
};
|
|
289
251
|
const targetMap = /* @__PURE__ */ new WeakMap();
|
|
290
|
-
const ITERATE_KEY =
|
|
291
|
-
|
|
292
|
-
);
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
252
|
+
const ITERATE_KEY = Symbol("");
|
|
253
|
+
const MAP_KEY_ITERATE_KEY = Symbol("");
|
|
254
|
+
const ARRAY_ITERATE_KEY = Symbol("");
|
|
255
|
+
/**
|
|
256
|
+
* Tracks access to a reactive property.
|
|
257
|
+
*
|
|
258
|
+
* This will check which effect is running at the moment and record it as dep
|
|
259
|
+
* which records all effects that depend on the reactive property.
|
|
260
|
+
*
|
|
261
|
+
* @param target - Object holding the reactive property.
|
|
262
|
+
* @param type - Defines the type of access to the reactive property.
|
|
263
|
+
* @param key - Identifier of the reactive property to track.
|
|
264
|
+
*/
|
|
299
265
|
function track(target, type, key) {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
depsMap.set(key, dep = new Dep(depsMap, key));
|
|
308
|
-
}
|
|
309
|
-
link(dep, activeSub);
|
|
310
|
-
}
|
|
266
|
+
if (activeSub !== void 0) {
|
|
267
|
+
let depsMap = targetMap.get(target);
|
|
268
|
+
if (!depsMap) targetMap.set(target, depsMap = /* @__PURE__ */ new Map());
|
|
269
|
+
let dep = depsMap.get(key);
|
|
270
|
+
if (!dep) depsMap.set(key, dep = new Dep(depsMap, key));
|
|
271
|
+
link(dep, activeSub);
|
|
272
|
+
}
|
|
311
273
|
}
|
|
274
|
+
/**
|
|
275
|
+
* Finds all deps associated with the target (or a specific property) and
|
|
276
|
+
* triggers the effects stored within.
|
|
277
|
+
*
|
|
278
|
+
* @param target - The reactive object.
|
|
279
|
+
* @param type - Defines the type of the operation that needs to trigger effects.
|
|
280
|
+
* @param key - Can be used to target a specific reactive property in the target object.
|
|
281
|
+
*/
|
|
312
282
|
function trigger(target, type, key, newValue, oldValue, oldTarget) {
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
case "delete":
|
|
355
|
-
if (!targetIsArray) {
|
|
356
|
-
run(depsMap.get(ITERATE_KEY));
|
|
357
|
-
if (shared.isMap(target)) {
|
|
358
|
-
run(depsMap.get(MAP_KEY_ITERATE_KEY));
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
break;
|
|
362
|
-
case "set":
|
|
363
|
-
if (shared.isMap(target)) {
|
|
364
|
-
run(depsMap.get(ITERATE_KEY));
|
|
365
|
-
}
|
|
366
|
-
break;
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
endBatch();
|
|
283
|
+
const depsMap = targetMap.get(target);
|
|
284
|
+
if (!depsMap) return;
|
|
285
|
+
const run = (dep) => {
|
|
286
|
+
if (dep !== void 0 && dep.subs !== void 0) {
|
|
287
|
+
propagate(dep.subs);
|
|
288
|
+
shallowPropagate(dep.subs);
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
startBatch();
|
|
292
|
+
if (type === "clear") depsMap.forEach(run);
|
|
293
|
+
else {
|
|
294
|
+
const targetIsArray = (0, _vue_shared.isArray)(target);
|
|
295
|
+
const isArrayIndex = targetIsArray && (0, _vue_shared.isIntegerKey)(key);
|
|
296
|
+
if (targetIsArray && key === "length") {
|
|
297
|
+
const newLength = Number(newValue);
|
|
298
|
+
depsMap.forEach((dep, key) => {
|
|
299
|
+
if (key === "length" || key === ARRAY_ITERATE_KEY || !(0, _vue_shared.isSymbol)(key) && key >= newLength) run(dep);
|
|
300
|
+
});
|
|
301
|
+
} else {
|
|
302
|
+
if (key !== void 0 || depsMap.has(void 0)) run(depsMap.get(key));
|
|
303
|
+
if (isArrayIndex) run(depsMap.get(ARRAY_ITERATE_KEY));
|
|
304
|
+
switch (type) {
|
|
305
|
+
case "add":
|
|
306
|
+
if (!targetIsArray) {
|
|
307
|
+
run(depsMap.get(ITERATE_KEY));
|
|
308
|
+
if ((0, _vue_shared.isMap)(target)) run(depsMap.get(MAP_KEY_ITERATE_KEY));
|
|
309
|
+
} else if (isArrayIndex) run(depsMap.get("length"));
|
|
310
|
+
break;
|
|
311
|
+
case "delete":
|
|
312
|
+
if (!targetIsArray) {
|
|
313
|
+
run(depsMap.get(ITERATE_KEY));
|
|
314
|
+
if ((0, _vue_shared.isMap)(target)) run(depsMap.get(MAP_KEY_ITERATE_KEY));
|
|
315
|
+
}
|
|
316
|
+
break;
|
|
317
|
+
case "set":
|
|
318
|
+
if ((0, _vue_shared.isMap)(target)) run(depsMap.get(ITERATE_KEY));
|
|
319
|
+
break;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
endBatch();
|
|
371
324
|
}
|
|
372
325
|
function getDepFromReactive(object, key) {
|
|
373
|
-
|
|
374
|
-
|
|
326
|
+
const depMap = targetMap.get(object);
|
|
327
|
+
return depMap && depMap.get(key);
|
|
375
328
|
}
|
|
376
329
|
|
|
330
|
+
//#endregion
|
|
331
|
+
//#region packages/reactivity/src/arrayInstrumentations.ts
|
|
332
|
+
/**
|
|
333
|
+
* Track array iteration and return:
|
|
334
|
+
* - if input is reactive: a cloned raw array with reactive values
|
|
335
|
+
* - if input is non-reactive or shallowReactive: the original raw array
|
|
336
|
+
*/
|
|
377
337
|
function reactiveReadArray(array) {
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
338
|
+
const raw = /* @__PURE__ */ toRaw(array);
|
|
339
|
+
if (raw === array) return raw;
|
|
340
|
+
track(raw, "iterate", ARRAY_ITERATE_KEY);
|
|
341
|
+
return /* @__PURE__ */ isShallow(array) ? raw : raw.map(toReactive);
|
|
382
342
|
}
|
|
343
|
+
/**
|
|
344
|
+
* Track array iteration and return raw array
|
|
345
|
+
*/
|
|
383
346
|
function shallowReadArray(arr) {
|
|
384
|
-
|
|
385
|
-
|
|
347
|
+
track(arr = /* @__PURE__ */ toRaw(arr), "iterate", ARRAY_ITERATE_KEY);
|
|
348
|
+
return arr;
|
|
386
349
|
}
|
|
387
350
|
function toWrapped(target, item) {
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
}
|
|
391
|
-
return toReactive(item);
|
|
351
|
+
if (/* @__PURE__ */ isReadonly(target)) return /* @__PURE__ */ isReactive(target) ? toReadonly(toReactive(item)) : toReadonly(item);
|
|
352
|
+
return toReactive(item);
|
|
392
353
|
}
|
|
393
354
|
const arrayInstrumentations = {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
},
|
|
480
|
-
shift() {
|
|
481
|
-
return noTracking(this, "shift");
|
|
482
|
-
},
|
|
483
|
-
// slice could use ARRAY_ITERATE but also seems to beg for range tracking
|
|
484
|
-
some(fn, thisArg) {
|
|
485
|
-
return apply(this, "some", fn, thisArg, void 0, arguments);
|
|
486
|
-
},
|
|
487
|
-
splice(...args) {
|
|
488
|
-
return noTracking(this, "splice", args);
|
|
489
|
-
},
|
|
490
|
-
toReversed() {
|
|
491
|
-
return reactiveReadArray(this).toReversed();
|
|
492
|
-
},
|
|
493
|
-
toSorted(comparer) {
|
|
494
|
-
return reactiveReadArray(this).toSorted(comparer);
|
|
495
|
-
},
|
|
496
|
-
toSpliced(...args) {
|
|
497
|
-
return reactiveReadArray(this).toSpliced(...args);
|
|
498
|
-
},
|
|
499
|
-
unshift(...args) {
|
|
500
|
-
return noTracking(this, "unshift", args);
|
|
501
|
-
},
|
|
502
|
-
values() {
|
|
503
|
-
return iterator(this, "values", (item) => toWrapped(this, item));
|
|
504
|
-
}
|
|
355
|
+
__proto__: null,
|
|
356
|
+
[Symbol.iterator]() {
|
|
357
|
+
return iterator(this, Symbol.iterator, (item) => toWrapped(this, item));
|
|
358
|
+
},
|
|
359
|
+
concat(...args) {
|
|
360
|
+
return reactiveReadArray(this).concat(...args.map((x) => (0, _vue_shared.isArray)(x) ? reactiveReadArray(x) : x));
|
|
361
|
+
},
|
|
362
|
+
entries() {
|
|
363
|
+
return iterator(this, "entries", (value) => {
|
|
364
|
+
value[1] = toWrapped(this, value[1]);
|
|
365
|
+
return value;
|
|
366
|
+
});
|
|
367
|
+
},
|
|
368
|
+
every(fn, thisArg) {
|
|
369
|
+
return apply(this, "every", fn, thisArg, void 0, arguments);
|
|
370
|
+
},
|
|
371
|
+
filter(fn, thisArg) {
|
|
372
|
+
return apply(this, "filter", fn, thisArg, (v) => v.map((item) => toWrapped(this, item)), arguments);
|
|
373
|
+
},
|
|
374
|
+
find(fn, thisArg) {
|
|
375
|
+
return apply(this, "find", fn, thisArg, (item) => toWrapped(this, item), arguments);
|
|
376
|
+
},
|
|
377
|
+
findIndex(fn, thisArg) {
|
|
378
|
+
return apply(this, "findIndex", fn, thisArg, void 0, arguments);
|
|
379
|
+
},
|
|
380
|
+
findLast(fn, thisArg) {
|
|
381
|
+
return apply(this, "findLast", fn, thisArg, (item) => toWrapped(this, item), arguments);
|
|
382
|
+
},
|
|
383
|
+
findLastIndex(fn, thisArg) {
|
|
384
|
+
return apply(this, "findLastIndex", fn, thisArg, void 0, arguments);
|
|
385
|
+
},
|
|
386
|
+
forEach(fn, thisArg) {
|
|
387
|
+
return apply(this, "forEach", fn, thisArg, void 0, arguments);
|
|
388
|
+
},
|
|
389
|
+
includes(...args) {
|
|
390
|
+
return searchProxy(this, "includes", args);
|
|
391
|
+
},
|
|
392
|
+
indexOf(...args) {
|
|
393
|
+
return searchProxy(this, "indexOf", args);
|
|
394
|
+
},
|
|
395
|
+
join(separator) {
|
|
396
|
+
return reactiveReadArray(this).join(separator);
|
|
397
|
+
},
|
|
398
|
+
lastIndexOf(...args) {
|
|
399
|
+
return searchProxy(this, "lastIndexOf", args);
|
|
400
|
+
},
|
|
401
|
+
map(fn, thisArg) {
|
|
402
|
+
return apply(this, "map", fn, thisArg, void 0, arguments);
|
|
403
|
+
},
|
|
404
|
+
pop() {
|
|
405
|
+
return noTracking(this, "pop");
|
|
406
|
+
},
|
|
407
|
+
push(...args) {
|
|
408
|
+
return noTracking(this, "push", args);
|
|
409
|
+
},
|
|
410
|
+
reduce(fn, ...args) {
|
|
411
|
+
return reduce(this, "reduce", fn, args);
|
|
412
|
+
},
|
|
413
|
+
reduceRight(fn, ...args) {
|
|
414
|
+
return reduce(this, "reduceRight", fn, args);
|
|
415
|
+
},
|
|
416
|
+
shift() {
|
|
417
|
+
return noTracking(this, "shift");
|
|
418
|
+
},
|
|
419
|
+
some(fn, thisArg) {
|
|
420
|
+
return apply(this, "some", fn, thisArg, void 0, arguments);
|
|
421
|
+
},
|
|
422
|
+
splice(...args) {
|
|
423
|
+
return noTracking(this, "splice", args);
|
|
424
|
+
},
|
|
425
|
+
toReversed() {
|
|
426
|
+
return reactiveReadArray(this).toReversed();
|
|
427
|
+
},
|
|
428
|
+
toSorted(comparer) {
|
|
429
|
+
return reactiveReadArray(this).toSorted(comparer);
|
|
430
|
+
},
|
|
431
|
+
toSpliced(...args) {
|
|
432
|
+
return reactiveReadArray(this).toSpliced(...args);
|
|
433
|
+
},
|
|
434
|
+
unshift(...args) {
|
|
435
|
+
return noTracking(this, "unshift", args);
|
|
436
|
+
},
|
|
437
|
+
values() {
|
|
438
|
+
return iterator(this, "values", (item) => toWrapped(this, item));
|
|
439
|
+
}
|
|
505
440
|
};
|
|
506
441
|
function iterator(self, method, wrapValue) {
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
}
|
|
519
|
-
return iter;
|
|
442
|
+
const arr = shallowReadArray(self);
|
|
443
|
+
const iter = arr[method]();
|
|
444
|
+
if (arr !== self && !/* @__PURE__ */ isShallow(self)) {
|
|
445
|
+
iter._next = iter.next;
|
|
446
|
+
iter.next = () => {
|
|
447
|
+
const result = iter._next();
|
|
448
|
+
if (!result.done) result.value = wrapValue(result.value);
|
|
449
|
+
return result;
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
return iter;
|
|
520
453
|
}
|
|
521
454
|
const arrayProto = Array.prototype;
|
|
522
455
|
function apply(self, method, fn, thisArg, wrappedRetFn, args) {
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
}
|
|
542
|
-
const result = methodFn.call(arr, wrappedFn, thisArg);
|
|
543
|
-
return needsWrap && wrappedRetFn ? wrappedRetFn(result) : result;
|
|
456
|
+
const arr = shallowReadArray(self);
|
|
457
|
+
const needsWrap = arr !== self && !/* @__PURE__ */ isShallow(self);
|
|
458
|
+
const methodFn = arr[method];
|
|
459
|
+
if (methodFn !== arrayProto[method]) {
|
|
460
|
+
const result = methodFn.apply(self, args);
|
|
461
|
+
return needsWrap ? toReactive(result) : result;
|
|
462
|
+
}
|
|
463
|
+
let wrappedFn = fn;
|
|
464
|
+
if (arr !== self) {
|
|
465
|
+
if (needsWrap) wrappedFn = function(item, index) {
|
|
466
|
+
return fn.call(this, toWrapped(self, item), index, self);
|
|
467
|
+
};
|
|
468
|
+
else if (fn.length > 2) wrappedFn = function(item, index) {
|
|
469
|
+
return fn.call(this, item, index, self);
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
const result = methodFn.call(arr, wrappedFn, thisArg);
|
|
473
|
+
return needsWrap && wrappedRetFn ? wrappedRetFn(result) : result;
|
|
544
474
|
}
|
|
545
475
|
function reduce(self, method, fn, args) {
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
return arr[method](wrappedFn, ...args);
|
|
476
|
+
const arr = shallowReadArray(self);
|
|
477
|
+
let wrappedFn = fn;
|
|
478
|
+
if (arr !== self) {
|
|
479
|
+
if (!/* @__PURE__ */ isShallow(self)) wrappedFn = function(acc, item, index) {
|
|
480
|
+
return fn.call(this, acc, toWrapped(self, item), index, self);
|
|
481
|
+
};
|
|
482
|
+
else if (fn.length > 3) wrappedFn = function(acc, item, index) {
|
|
483
|
+
return fn.call(this, acc, item, index, self);
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
return arr[method](wrappedFn, ...args);
|
|
560
487
|
}
|
|
561
488
|
function searchProxy(self, method, args) {
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
489
|
+
const arr = /* @__PURE__ */ toRaw(self);
|
|
490
|
+
track(arr, "iterate", ARRAY_ITERATE_KEY);
|
|
491
|
+
const res = arr[method](...args);
|
|
492
|
+
if ((res === -1 || res === false) && /* @__PURE__ */ isProxy(args[0])) {
|
|
493
|
+
args[0] = /* @__PURE__ */ toRaw(args[0]);
|
|
494
|
+
return arr[method](...args);
|
|
495
|
+
}
|
|
496
|
+
return res;
|
|
570
497
|
}
|
|
571
498
|
function noTracking(self, method, args = []) {
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
499
|
+
startBatch();
|
|
500
|
+
const prevSub = setActiveSub();
|
|
501
|
+
const res = (/* @__PURE__ */ toRaw(self))[method].apply(self, args);
|
|
502
|
+
setActiveSub(prevSub);
|
|
503
|
+
endBatch();
|
|
504
|
+
return res;
|
|
578
505
|
}
|
|
579
506
|
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
);
|
|
507
|
+
//#endregion
|
|
508
|
+
//#region packages/reactivity/src/baseHandlers.ts
|
|
509
|
+
const isNonTrackableKeys = /* @__PURE__ */ (0, _vue_shared.makeMap)(`__proto__,__v_isRef,__isVue`);
|
|
510
|
+
const builtInSymbols = new Set(/* @__PURE__ */ Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller").map((key) => Symbol[key]).filter(_vue_shared.isSymbol));
|
|
584
511
|
function hasOwnProperty(key) {
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
isRef(target) ? target : receiver
|
|
681
|
-
);
|
|
682
|
-
if (target === toRaw(receiver)) {
|
|
683
|
-
if (!hadKey) {
|
|
684
|
-
trigger(target, "add", key, value);
|
|
685
|
-
} else if (shared.hasChanged(value, oldValue)) {
|
|
686
|
-
trigger(target, "set", key, value);
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
return result;
|
|
690
|
-
}
|
|
691
|
-
deleteProperty(target, key) {
|
|
692
|
-
const hadKey = shared.hasOwn(target, key);
|
|
693
|
-
target[key];
|
|
694
|
-
const result = Reflect.deleteProperty(target, key);
|
|
695
|
-
if (result && hadKey) {
|
|
696
|
-
trigger(target, "delete", key, void 0);
|
|
697
|
-
}
|
|
698
|
-
return result;
|
|
699
|
-
}
|
|
700
|
-
has(target, key) {
|
|
701
|
-
const result = Reflect.has(target, key);
|
|
702
|
-
if (!shared.isSymbol(key) || !builtInSymbols.has(key)) {
|
|
703
|
-
track(target, "has", key);
|
|
704
|
-
}
|
|
705
|
-
return result;
|
|
706
|
-
}
|
|
707
|
-
ownKeys(target) {
|
|
708
|
-
track(
|
|
709
|
-
target,
|
|
710
|
-
"iterate",
|
|
711
|
-
shared.isArray(target) ? "length" : ITERATE_KEY
|
|
712
|
-
);
|
|
713
|
-
return Reflect.ownKeys(target);
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
|
-
class ReadonlyReactiveHandler extends BaseReactiveHandler {
|
|
717
|
-
constructor(isShallow2 = false) {
|
|
718
|
-
super(true, isShallow2);
|
|
719
|
-
}
|
|
720
|
-
set(target, key) {
|
|
721
|
-
return true;
|
|
722
|
-
}
|
|
723
|
-
deleteProperty(target, key) {
|
|
724
|
-
return true;
|
|
725
|
-
}
|
|
726
|
-
}
|
|
512
|
+
if (!(0, _vue_shared.isSymbol)(key)) key = String(key);
|
|
513
|
+
const obj = /* @__PURE__ */ toRaw(this);
|
|
514
|
+
track(obj, "has", key);
|
|
515
|
+
return obj.hasOwnProperty(key);
|
|
516
|
+
}
|
|
517
|
+
var BaseReactiveHandler = class {
|
|
518
|
+
constructor(_isReadonly = false, _isShallow = false) {
|
|
519
|
+
this._isReadonly = _isReadonly;
|
|
520
|
+
this._isShallow = _isShallow;
|
|
521
|
+
}
|
|
522
|
+
get(target, key, receiver) {
|
|
523
|
+
if (key === "__v_skip") return target["__v_skip"];
|
|
524
|
+
const isReadonly = this._isReadonly, isShallow = this._isShallow;
|
|
525
|
+
if (key === "__v_isReactive") return !isReadonly;
|
|
526
|
+
else if (key === "__v_isReadonly") return isReadonly;
|
|
527
|
+
else if (key === "__v_isShallow") return isShallow;
|
|
528
|
+
else if (key === "__v_raw") {
|
|
529
|
+
if (receiver === (isReadonly ? isShallow ? shallowReadonlyMap : readonlyMap : isShallow ? shallowReactiveMap : reactiveMap).get(target) || Object.getPrototypeOf(target) === Object.getPrototypeOf(receiver)) return target;
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
const targetIsArray = (0, _vue_shared.isArray)(target);
|
|
533
|
+
if (!isReadonly) {
|
|
534
|
+
let fn;
|
|
535
|
+
if (targetIsArray && (fn = arrayInstrumentations[key])) return fn;
|
|
536
|
+
if (key === "hasOwnProperty") return hasOwnProperty;
|
|
537
|
+
}
|
|
538
|
+
const wasRef = /* @__PURE__ */ isRef(target);
|
|
539
|
+
const res = Reflect.get(target, key, wasRef ? target : receiver);
|
|
540
|
+
if (wasRef && key !== "value") return res;
|
|
541
|
+
if ((0, _vue_shared.isSymbol)(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) return res;
|
|
542
|
+
if (!isReadonly) track(target, "get", key);
|
|
543
|
+
if (isShallow) return res;
|
|
544
|
+
if (/* @__PURE__ */ isRef(res)) {
|
|
545
|
+
const value = targetIsArray && (0, _vue_shared.isIntegerKey)(key) ? res : res.value;
|
|
546
|
+
return isReadonly && (0, _vue_shared.isObject)(value) ? /* @__PURE__ */ readonly(value) : value;
|
|
547
|
+
}
|
|
548
|
+
if ((0, _vue_shared.isObject)(res)) return isReadonly ? /* @__PURE__ */ readonly(res) : /* @__PURE__ */ reactive(res);
|
|
549
|
+
return res;
|
|
550
|
+
}
|
|
551
|
+
};
|
|
552
|
+
var MutableReactiveHandler = class extends BaseReactiveHandler {
|
|
553
|
+
constructor(isShallow = false) {
|
|
554
|
+
super(false, isShallow);
|
|
555
|
+
}
|
|
556
|
+
set(target, key, value, receiver) {
|
|
557
|
+
let oldValue = target[key];
|
|
558
|
+
const isArrayWithIntegerKey = (0, _vue_shared.isArray)(target) && (0, _vue_shared.isIntegerKey)(key);
|
|
559
|
+
if (!this._isShallow) {
|
|
560
|
+
const isOldValueReadonly = /* @__PURE__ */ isReadonly(oldValue);
|
|
561
|
+
if (!/* @__PURE__ */ isShallow(value) && !/* @__PURE__ */ isReadonly(value)) {
|
|
562
|
+
oldValue = /* @__PURE__ */ toRaw(oldValue);
|
|
563
|
+
value = /* @__PURE__ */ toRaw(value);
|
|
564
|
+
}
|
|
565
|
+
if (!isArrayWithIntegerKey && /* @__PURE__ */ isRef(oldValue) && !/* @__PURE__ */ isRef(value)) if (isOldValueReadonly) return true;
|
|
566
|
+
else {
|
|
567
|
+
oldValue.value = value;
|
|
568
|
+
return true;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
const hadKey = isArrayWithIntegerKey ? Number(key) < target.length : (0, _vue_shared.hasOwn)(target, key);
|
|
572
|
+
const result = Reflect.set(target, key, value, /* @__PURE__ */ isRef(target) ? target : receiver);
|
|
573
|
+
if (target === /* @__PURE__ */ toRaw(receiver)) {
|
|
574
|
+
if (!hadKey) trigger(target, "add", key, value);
|
|
575
|
+
else if ((0, _vue_shared.hasChanged)(value, oldValue)) trigger(target, "set", key, value, oldValue);
|
|
576
|
+
}
|
|
577
|
+
return result;
|
|
578
|
+
}
|
|
579
|
+
deleteProperty(target, key) {
|
|
580
|
+
const hadKey = (0, _vue_shared.hasOwn)(target, key);
|
|
581
|
+
const oldValue = target[key];
|
|
582
|
+
const result = Reflect.deleteProperty(target, key);
|
|
583
|
+
if (result && hadKey) trigger(target, "delete", key, void 0, oldValue);
|
|
584
|
+
return result;
|
|
585
|
+
}
|
|
586
|
+
has(target, key) {
|
|
587
|
+
const result = Reflect.has(target, key);
|
|
588
|
+
if (!(0, _vue_shared.isSymbol)(key) || !builtInSymbols.has(key)) track(target, "has", key);
|
|
589
|
+
return result;
|
|
590
|
+
}
|
|
591
|
+
ownKeys(target) {
|
|
592
|
+
track(target, "iterate", (0, _vue_shared.isArray)(target) ? "length" : ITERATE_KEY);
|
|
593
|
+
return Reflect.ownKeys(target);
|
|
594
|
+
}
|
|
595
|
+
};
|
|
596
|
+
var ReadonlyReactiveHandler = class extends BaseReactiveHandler {
|
|
597
|
+
constructor(isShallow = false) {
|
|
598
|
+
super(true, isShallow);
|
|
599
|
+
}
|
|
600
|
+
set(target, key) {
|
|
601
|
+
return true;
|
|
602
|
+
}
|
|
603
|
+
deleteProperty(target, key) {
|
|
604
|
+
return true;
|
|
605
|
+
}
|
|
606
|
+
};
|
|
727
607
|
const mutableHandlers = /* @__PURE__ */ new MutableReactiveHandler();
|
|
728
608
|
const readonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler();
|
|
729
609
|
const shallowReactiveHandlers = /* @__PURE__ */ new MutableReactiveHandler(true);
|
|
730
610
|
const shallowReadonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler(true);
|
|
731
611
|
|
|
612
|
+
//#endregion
|
|
613
|
+
//#region packages/reactivity/src/collectionHandlers.ts
|
|
732
614
|
const toShallow = (value) => value;
|
|
733
615
|
const getProto = (v) => Reflect.getPrototypeOf(v);
|
|
734
|
-
function createIterableMethod(method,
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
return done ? { value, done } : {
|
|
756
|
-
value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
|
|
757
|
-
done
|
|
758
|
-
};
|
|
759
|
-
}
|
|
760
|
-
}
|
|
761
|
-
);
|
|
762
|
-
};
|
|
616
|
+
function createIterableMethod(method, isReadonly, isShallow) {
|
|
617
|
+
return function(...args) {
|
|
618
|
+
const target = this["__v_raw"];
|
|
619
|
+
const rawTarget = /* @__PURE__ */ toRaw(target);
|
|
620
|
+
const targetIsMap = (0, _vue_shared.isMap)(rawTarget);
|
|
621
|
+
const isPair = method === "entries" || method === Symbol.iterator && targetIsMap;
|
|
622
|
+
const isKeyOnly = method === "keys" && targetIsMap;
|
|
623
|
+
const innerIterator = target[method](...args);
|
|
624
|
+
const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
|
|
625
|
+
!isReadonly && track(rawTarget, "iterate", isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY);
|
|
626
|
+
return (0, _vue_shared.extend)(Object.create(innerIterator), { next() {
|
|
627
|
+
const { value, done } = innerIterator.next();
|
|
628
|
+
return done ? {
|
|
629
|
+
value,
|
|
630
|
+
done
|
|
631
|
+
} : {
|
|
632
|
+
value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
|
|
633
|
+
done
|
|
634
|
+
};
|
|
635
|
+
} });
|
|
636
|
+
};
|
|
763
637
|
}
|
|
764
638
|
function createReadonlyMethod(type) {
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
639
|
+
return function(...args) {
|
|
640
|
+
return type === "delete" ? false : type === "clear" ? void 0 : this;
|
|
641
|
+
};
|
|
768
642
|
}
|
|
769
643
|
function createInstrumentations(readonly, shallow) {
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
return result;
|
|
887
|
-
}
|
|
888
|
-
}
|
|
889
|
-
);
|
|
890
|
-
const iteratorMethods = [
|
|
891
|
-
"keys",
|
|
892
|
-
"values",
|
|
893
|
-
"entries",
|
|
894
|
-
Symbol.iterator
|
|
895
|
-
];
|
|
896
|
-
iteratorMethods.forEach((method) => {
|
|
897
|
-
instrumentations[method] = createIterableMethod(method, readonly, shallow);
|
|
898
|
-
});
|
|
899
|
-
return instrumentations;
|
|
900
|
-
}
|
|
901
|
-
function createInstrumentationGetter(isReadonly2, shallow) {
|
|
902
|
-
const instrumentations = createInstrumentations(isReadonly2, shallow);
|
|
903
|
-
return (target, key, receiver) => {
|
|
904
|
-
if (key === "__v_isReactive") {
|
|
905
|
-
return !isReadonly2;
|
|
906
|
-
} else if (key === "__v_isReadonly") {
|
|
907
|
-
return isReadonly2;
|
|
908
|
-
} else if (key === "__v_raw") {
|
|
909
|
-
return target;
|
|
910
|
-
}
|
|
911
|
-
return Reflect.get(
|
|
912
|
-
shared.hasOwn(instrumentations, key) && key in target ? instrumentations : target,
|
|
913
|
-
key,
|
|
914
|
-
receiver
|
|
915
|
-
);
|
|
916
|
-
};
|
|
917
|
-
}
|
|
918
|
-
const mutableCollectionHandlers = {
|
|
919
|
-
get: /* @__PURE__ */ createInstrumentationGetter(false, false)
|
|
920
|
-
};
|
|
921
|
-
const shallowCollectionHandlers = {
|
|
922
|
-
get: /* @__PURE__ */ createInstrumentationGetter(false, true)
|
|
923
|
-
};
|
|
924
|
-
const readonlyCollectionHandlers = {
|
|
925
|
-
get: /* @__PURE__ */ createInstrumentationGetter(true, false)
|
|
926
|
-
};
|
|
927
|
-
const shallowReadonlyCollectionHandlers = {
|
|
928
|
-
get: /* @__PURE__ */ createInstrumentationGetter(true, true)
|
|
929
|
-
};
|
|
644
|
+
const instrumentations = {
|
|
645
|
+
get(key) {
|
|
646
|
+
const target = this["__v_raw"];
|
|
647
|
+
const rawTarget = /* @__PURE__ */ toRaw(target);
|
|
648
|
+
const rawKey = /* @__PURE__ */ toRaw(key);
|
|
649
|
+
if (!readonly) {
|
|
650
|
+
if ((0, _vue_shared.hasChanged)(key, rawKey)) track(rawTarget, "get", key);
|
|
651
|
+
track(rawTarget, "get", rawKey);
|
|
652
|
+
}
|
|
653
|
+
const { has } = getProto(rawTarget);
|
|
654
|
+
const wrap = shallow ? toShallow : readonly ? toReadonly : toReactive;
|
|
655
|
+
if (has.call(rawTarget, key)) return wrap(target.get(key));
|
|
656
|
+
else if (has.call(rawTarget, rawKey)) return wrap(target.get(rawKey));
|
|
657
|
+
else if (target !== rawTarget) target.get(key);
|
|
658
|
+
},
|
|
659
|
+
get size() {
|
|
660
|
+
const target = this["__v_raw"];
|
|
661
|
+
!readonly && track(/* @__PURE__ */ toRaw(target), "iterate", ITERATE_KEY);
|
|
662
|
+
return target.size;
|
|
663
|
+
},
|
|
664
|
+
has(key) {
|
|
665
|
+
const target = this["__v_raw"];
|
|
666
|
+
const rawTarget = /* @__PURE__ */ toRaw(target);
|
|
667
|
+
const rawKey = /* @__PURE__ */ toRaw(key);
|
|
668
|
+
if (!readonly) {
|
|
669
|
+
if ((0, _vue_shared.hasChanged)(key, rawKey)) track(rawTarget, "has", key);
|
|
670
|
+
track(rawTarget, "has", rawKey);
|
|
671
|
+
}
|
|
672
|
+
return key === rawKey ? target.has(key) : target.has(key) || target.has(rawKey);
|
|
673
|
+
},
|
|
674
|
+
forEach(callback, thisArg) {
|
|
675
|
+
const observed = this;
|
|
676
|
+
const target = observed["__v_raw"];
|
|
677
|
+
const rawTarget = /* @__PURE__ */ toRaw(target);
|
|
678
|
+
const wrap = shallow ? toShallow : readonly ? toReadonly : toReactive;
|
|
679
|
+
!readonly && track(rawTarget, "iterate", ITERATE_KEY);
|
|
680
|
+
return target.forEach((value, key) => {
|
|
681
|
+
return callback.call(thisArg, wrap(value), wrap(key), observed);
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
};
|
|
685
|
+
(0, _vue_shared.extend)(instrumentations, readonly ? {
|
|
686
|
+
add: createReadonlyMethod("add"),
|
|
687
|
+
set: createReadonlyMethod("set"),
|
|
688
|
+
delete: createReadonlyMethod("delete"),
|
|
689
|
+
clear: createReadonlyMethod("clear")
|
|
690
|
+
} : {
|
|
691
|
+
add(value) {
|
|
692
|
+
if (!shallow && !/* @__PURE__ */ isShallow(value) && !/* @__PURE__ */ isReadonly(value)) value = /* @__PURE__ */ toRaw(value);
|
|
693
|
+
const target = /* @__PURE__ */ toRaw(this);
|
|
694
|
+
if (!getProto(target).has.call(target, value)) {
|
|
695
|
+
target.add(value);
|
|
696
|
+
trigger(target, "add", value, value);
|
|
697
|
+
}
|
|
698
|
+
return this;
|
|
699
|
+
},
|
|
700
|
+
set(key, value) {
|
|
701
|
+
if (!shallow && !/* @__PURE__ */ isShallow(value) && !/* @__PURE__ */ isReadonly(value)) value = /* @__PURE__ */ toRaw(value);
|
|
702
|
+
const target = /* @__PURE__ */ toRaw(this);
|
|
703
|
+
const { has, get } = getProto(target);
|
|
704
|
+
let hadKey = has.call(target, key);
|
|
705
|
+
if (!hadKey) {
|
|
706
|
+
key = /* @__PURE__ */ toRaw(key);
|
|
707
|
+
hadKey = has.call(target, key);
|
|
708
|
+
}
|
|
709
|
+
const oldValue = get.call(target, key);
|
|
710
|
+
target.set(key, value);
|
|
711
|
+
if (!hadKey) trigger(target, "add", key, value);
|
|
712
|
+
else if ((0, _vue_shared.hasChanged)(value, oldValue)) trigger(target, "set", key, value, oldValue);
|
|
713
|
+
return this;
|
|
714
|
+
},
|
|
715
|
+
delete(key) {
|
|
716
|
+
const target = /* @__PURE__ */ toRaw(this);
|
|
717
|
+
const { has, get } = getProto(target);
|
|
718
|
+
let hadKey = has.call(target, key);
|
|
719
|
+
if (!hadKey) {
|
|
720
|
+
key = /* @__PURE__ */ toRaw(key);
|
|
721
|
+
hadKey = has.call(target, key);
|
|
722
|
+
}
|
|
723
|
+
const oldValue = get ? get.call(target, key) : void 0;
|
|
724
|
+
const result = target.delete(key);
|
|
725
|
+
if (hadKey) trigger(target, "delete", key, void 0, oldValue);
|
|
726
|
+
return result;
|
|
727
|
+
},
|
|
728
|
+
clear() {
|
|
729
|
+
const target = /* @__PURE__ */ toRaw(this);
|
|
730
|
+
const hadItems = target.size !== 0;
|
|
731
|
+
const oldTarget = void 0;
|
|
732
|
+
const result = target.clear();
|
|
733
|
+
if (hadItems) trigger(target, "clear", void 0, void 0, oldTarget);
|
|
734
|
+
return result;
|
|
735
|
+
}
|
|
736
|
+
});
|
|
737
|
+
[
|
|
738
|
+
"keys",
|
|
739
|
+
"values",
|
|
740
|
+
"entries",
|
|
741
|
+
Symbol.iterator
|
|
742
|
+
].forEach((method) => {
|
|
743
|
+
instrumentations[method] = createIterableMethod(method, readonly, shallow);
|
|
744
|
+
});
|
|
745
|
+
return instrumentations;
|
|
746
|
+
}
|
|
747
|
+
function createInstrumentationGetter(isReadonly, shallow) {
|
|
748
|
+
const instrumentations = createInstrumentations(isReadonly, shallow);
|
|
749
|
+
return (target, key, receiver) => {
|
|
750
|
+
if (key === "__v_isReactive") return !isReadonly;
|
|
751
|
+
else if (key === "__v_isReadonly") return isReadonly;
|
|
752
|
+
else if (key === "__v_raw") return target;
|
|
753
|
+
return Reflect.get((0, _vue_shared.hasOwn)(instrumentations, key) && key in target ? instrumentations : target, key, receiver);
|
|
754
|
+
};
|
|
755
|
+
}
|
|
756
|
+
const mutableCollectionHandlers = { get: /* @__PURE__ */ createInstrumentationGetter(false, false) };
|
|
757
|
+
const shallowCollectionHandlers = { get: /* @__PURE__ */ createInstrumentationGetter(false, true) };
|
|
758
|
+
const readonlyCollectionHandlers = { get: /* @__PURE__ */ createInstrumentationGetter(true, false) };
|
|
759
|
+
const shallowReadonlyCollectionHandlers = { get: /* @__PURE__ */ createInstrumentationGetter(true, true) };
|
|
930
760
|
|
|
761
|
+
//#endregion
|
|
762
|
+
//#region packages/reactivity/src/reactive.ts
|
|
931
763
|
const reactiveMap = /* @__PURE__ */ new WeakMap();
|
|
932
764
|
const shallowReactiveMap = /* @__PURE__ */ new WeakMap();
|
|
933
765
|
const readonlyMap = /* @__PURE__ */ new WeakMap();
|
|
934
766
|
const shallowReadonlyMap = /* @__PURE__ */ new WeakMap();
|
|
935
767
|
function targetTypeMap(rawType) {
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
default:
|
|
946
|
-
return 0 /* INVALID */;
|
|
947
|
-
}
|
|
768
|
+
switch (rawType) {
|
|
769
|
+
case "Object":
|
|
770
|
+
case "Array": return 1;
|
|
771
|
+
case "Map":
|
|
772
|
+
case "Set":
|
|
773
|
+
case "WeakMap":
|
|
774
|
+
case "WeakSet": return 2;
|
|
775
|
+
default: return 0;
|
|
776
|
+
}
|
|
948
777
|
}
|
|
949
778
|
function getTargetType(value) {
|
|
950
|
-
|
|
779
|
+
return value["__v_skip"] || !Object.isExtensible(value) ? 0 : targetTypeMap((0, _vue_shared.toRawType)(value));
|
|
951
780
|
}
|
|
952
|
-
|
|
781
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
953
782
|
function reactive(target) {
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
783
|
+
if (/* @__PURE__ */ isReadonly(target)) return target;
|
|
784
|
+
return createReactiveObject(target, false, mutableHandlers, mutableCollectionHandlers, reactiveMap);
|
|
785
|
+
}
|
|
786
|
+
/**
|
|
787
|
+
* Shallow version of {@link reactive}.
|
|
788
|
+
*
|
|
789
|
+
* Unlike {@link reactive}, there is no deep conversion: only root-level
|
|
790
|
+
* properties are reactive for a shallow reactive object. Property values are
|
|
791
|
+
* stored and exposed as-is - this also means properties with ref values will
|
|
792
|
+
* not be automatically unwrapped.
|
|
793
|
+
*
|
|
794
|
+
* @example
|
|
795
|
+
* ```js
|
|
796
|
+
* const state = shallowReactive({
|
|
797
|
+
* foo: 1,
|
|
798
|
+
* nested: {
|
|
799
|
+
* bar: 2
|
|
800
|
+
* }
|
|
801
|
+
* })
|
|
802
|
+
*
|
|
803
|
+
* // mutating state's own properties is reactive
|
|
804
|
+
* state.foo++
|
|
805
|
+
*
|
|
806
|
+
* // ...but does not convert nested objects
|
|
807
|
+
* isReactive(state.nested) // false
|
|
808
|
+
*
|
|
809
|
+
* // NOT reactive
|
|
810
|
+
* state.nested.bar++
|
|
811
|
+
* ```
|
|
812
|
+
*
|
|
813
|
+
* @param target - The source object.
|
|
814
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#shallowreactive}
|
|
815
|
+
*/
|
|
816
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
966
817
|
function shallowReactive(target) {
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
}
|
|
975
|
-
|
|
818
|
+
return createReactiveObject(target, false, shallowReactiveHandlers, shallowCollectionHandlers, shallowReactiveMap);
|
|
819
|
+
}
|
|
820
|
+
/**
|
|
821
|
+
* Takes an object (reactive or plain) or a ref and returns a readonly proxy to
|
|
822
|
+
* the original.
|
|
823
|
+
*
|
|
824
|
+
* A readonly proxy is deep: any nested property accessed will be readonly as
|
|
825
|
+
* well. It also has the same ref-unwrapping behavior as {@link reactive},
|
|
826
|
+
* except the unwrapped values will also be made readonly.
|
|
827
|
+
*
|
|
828
|
+
* @example
|
|
829
|
+
* ```js
|
|
830
|
+
* const original = reactive({ count: 0 })
|
|
831
|
+
*
|
|
832
|
+
* const copy = readonly(original)
|
|
833
|
+
*
|
|
834
|
+
* watchEffect(() => {
|
|
835
|
+
* // works for reactivity tracking
|
|
836
|
+
* console.log(copy.count)
|
|
837
|
+
* })
|
|
838
|
+
*
|
|
839
|
+
* // mutating original will trigger watchers relying on the copy
|
|
840
|
+
* original.count++
|
|
841
|
+
*
|
|
842
|
+
* // mutating the copy will fail and result in a warning
|
|
843
|
+
* copy.count++ // warning!
|
|
844
|
+
* ```
|
|
845
|
+
*
|
|
846
|
+
* @param target - The source object.
|
|
847
|
+
* @see {@link https://vuejs.org/api/reactivity-core.html#readonly}
|
|
848
|
+
*/
|
|
849
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
976
850
|
function readonly(target) {
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
851
|
+
return createReactiveObject(target, true, readonlyHandlers, readonlyCollectionHandlers, readonlyMap);
|
|
852
|
+
}
|
|
853
|
+
/**
|
|
854
|
+
* Shallow version of {@link readonly}.
|
|
855
|
+
*
|
|
856
|
+
* Unlike {@link readonly}, there is no deep conversion: only root-level
|
|
857
|
+
* properties are made readonly. Property values are stored and exposed as-is -
|
|
858
|
+
* this also means properties with ref values will not be automatically
|
|
859
|
+
* unwrapped.
|
|
860
|
+
*
|
|
861
|
+
* @example
|
|
862
|
+
* ```js
|
|
863
|
+
* const state = shallowReadonly({
|
|
864
|
+
* foo: 1,
|
|
865
|
+
* nested: {
|
|
866
|
+
* bar: 2
|
|
867
|
+
* }
|
|
868
|
+
* })
|
|
869
|
+
*
|
|
870
|
+
* // mutating state's own properties will fail
|
|
871
|
+
* state.foo++
|
|
872
|
+
*
|
|
873
|
+
* // ...but works on nested objects
|
|
874
|
+
* isReadonly(state.nested) // false
|
|
875
|
+
*
|
|
876
|
+
* // works
|
|
877
|
+
* state.nested.bar++
|
|
878
|
+
* ```
|
|
879
|
+
*
|
|
880
|
+
* @param target - The source object.
|
|
881
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#shallowreadonly}
|
|
882
|
+
*/
|
|
883
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
986
884
|
function shallowReadonly(target) {
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
}
|
|
1017
|
-
|
|
885
|
+
return createReactiveObject(target, true, shallowReadonlyHandlers, shallowReadonlyCollectionHandlers, shallowReadonlyMap);
|
|
886
|
+
}
|
|
887
|
+
function createReactiveObject(target, isReadonly, baseHandlers, collectionHandlers, proxyMap) {
|
|
888
|
+
if (!(0, _vue_shared.isObject)(target)) return target;
|
|
889
|
+
if (target["__v_raw"] && !(isReadonly && target["__v_isReactive"])) return target;
|
|
890
|
+
const targetType = getTargetType(target);
|
|
891
|
+
if (targetType === 0) return target;
|
|
892
|
+
const existingProxy = proxyMap.get(target);
|
|
893
|
+
if (existingProxy) return existingProxy;
|
|
894
|
+
const proxy = new Proxy(target, targetType === 2 ? collectionHandlers : baseHandlers);
|
|
895
|
+
proxyMap.set(target, proxy);
|
|
896
|
+
return proxy;
|
|
897
|
+
}
|
|
898
|
+
/**
|
|
899
|
+
* Checks if an object is a proxy created by {@link reactive} or
|
|
900
|
+
* {@link shallowReactive} (or {@link ref} in some cases).
|
|
901
|
+
*
|
|
902
|
+
* @example
|
|
903
|
+
* ```js
|
|
904
|
+
* isReactive(reactive({})) // => true
|
|
905
|
+
* isReactive(readonly(reactive({}))) // => true
|
|
906
|
+
* isReactive(ref({}).value) // => true
|
|
907
|
+
* isReactive(readonly(ref({})).value) // => true
|
|
908
|
+
* isReactive(ref(true)) // => false
|
|
909
|
+
* isReactive(shallowRef({}).value) // => false
|
|
910
|
+
* isReactive(shallowReactive({})) // => true
|
|
911
|
+
* ```
|
|
912
|
+
*
|
|
913
|
+
* @param value - The value to check.
|
|
914
|
+
* @see {@link https://vuejs.org/api/reactivity-utilities.html#isreactive}
|
|
915
|
+
*/
|
|
916
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1018
917
|
function isReactive(value) {
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
}
|
|
1022
|
-
return !!(value && value["__v_isReactive"]);
|
|
918
|
+
if (/* @__PURE__ */ isReadonly(value)) return /* @__PURE__ */ isReactive(value["__v_raw"]);
|
|
919
|
+
return !!(value && value["__v_isReactive"]);
|
|
1023
920
|
}
|
|
1024
|
-
|
|
921
|
+
/**
|
|
922
|
+
* Checks whether the passed value is a readonly object. The properties of a
|
|
923
|
+
* readonly object can change, but they can't be assigned directly via the
|
|
924
|
+
* passed object.
|
|
925
|
+
*
|
|
926
|
+
* The proxies created by {@link readonly} and {@link shallowReadonly} are
|
|
927
|
+
* both considered readonly, as is a computed ref without a set function.
|
|
928
|
+
*
|
|
929
|
+
* @param value - The value to check.
|
|
930
|
+
* @see {@link https://vuejs.org/api/reactivity-utilities.html#isreadonly}
|
|
931
|
+
*/
|
|
932
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1025
933
|
function isReadonly(value) {
|
|
1026
|
-
|
|
934
|
+
return !!(value && value["__v_isReadonly"]);
|
|
1027
935
|
}
|
|
1028
|
-
|
|
936
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1029
937
|
function isShallow(value) {
|
|
1030
|
-
|
|
938
|
+
return !!(value && value["__v_isShallow"]);
|
|
1031
939
|
}
|
|
1032
|
-
|
|
940
|
+
/**
|
|
941
|
+
* Checks if an object is a proxy created by {@link reactive},
|
|
942
|
+
* {@link readonly}, {@link shallowReactive} or {@link shallowReadonly}.
|
|
943
|
+
*
|
|
944
|
+
* @param value - The value to check.
|
|
945
|
+
* @see {@link https://vuejs.org/api/reactivity-utilities.html#isproxy}
|
|
946
|
+
*/
|
|
947
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1033
948
|
function isProxy(value) {
|
|
1034
|
-
|
|
949
|
+
return value ? !!value["__v_raw"] : false;
|
|
1035
950
|
}
|
|
1036
|
-
|
|
951
|
+
/**
|
|
952
|
+
* Returns the raw, original object of a Vue-created proxy.
|
|
953
|
+
*
|
|
954
|
+
* `toRaw()` can return the original object from proxies created by
|
|
955
|
+
* {@link reactive}, {@link readonly}, {@link shallowReactive} or
|
|
956
|
+
* {@link shallowReadonly}.
|
|
957
|
+
*
|
|
958
|
+
* This is an escape hatch that can be used to temporarily read without
|
|
959
|
+
* incurring proxy access / tracking overhead or write without triggering
|
|
960
|
+
* changes. It is **not** recommended to hold a persistent reference to the
|
|
961
|
+
* original object. Use with caution.
|
|
962
|
+
*
|
|
963
|
+
* @example
|
|
964
|
+
* ```js
|
|
965
|
+
* const foo = {}
|
|
966
|
+
* const reactiveFoo = reactive(foo)
|
|
967
|
+
*
|
|
968
|
+
* console.log(toRaw(reactiveFoo) === foo) // true
|
|
969
|
+
* ```
|
|
970
|
+
*
|
|
971
|
+
* @param observed - The object for which the "raw" value is requested.
|
|
972
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#toraw}
|
|
973
|
+
*/
|
|
974
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1037
975
|
function toRaw(observed) {
|
|
1038
|
-
|
|
1039
|
-
|
|
976
|
+
const raw = observed && observed["__v_raw"];
|
|
977
|
+
return raw ? /* @__PURE__ */ toRaw(raw) : observed;
|
|
1040
978
|
}
|
|
979
|
+
/**
|
|
980
|
+
* Marks an object so that it will never be converted to a proxy. Returns the
|
|
981
|
+
* object itself.
|
|
982
|
+
*
|
|
983
|
+
* @example
|
|
984
|
+
* ```js
|
|
985
|
+
* const foo = markRaw({})
|
|
986
|
+
* console.log(isReactive(reactive(foo))) // false
|
|
987
|
+
*
|
|
988
|
+
* // also works when nested inside other reactive objects
|
|
989
|
+
* const bar = reactive({ foo })
|
|
990
|
+
* console.log(isReactive(bar.foo)) // false
|
|
991
|
+
* ```
|
|
992
|
+
*
|
|
993
|
+
* **Warning:** `markRaw()` together with the shallow APIs such as
|
|
994
|
+
* {@link shallowReactive} allow you to selectively opt-out of the default
|
|
995
|
+
* deep reactive/readonly conversion and embed raw, non-proxied objects in your
|
|
996
|
+
* state graph.
|
|
997
|
+
*
|
|
998
|
+
* @param value - The object to be marked as "raw".
|
|
999
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#markraw}
|
|
1000
|
+
*/
|
|
1041
1001
|
function markRaw(value) {
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
}
|
|
1045
|
-
return value;
|
|
1002
|
+
if (!(0, _vue_shared.hasOwn)(value, "__v_skip") && Object.isExtensible(value)) (0, _vue_shared.def)(value, "__v_skip", true);
|
|
1003
|
+
return value;
|
|
1046
1004
|
}
|
|
1047
|
-
|
|
1048
|
-
|
|
1005
|
+
/**
|
|
1006
|
+
* Returns a reactive proxy of the given value (if possible).
|
|
1007
|
+
*
|
|
1008
|
+
* If the given value is not an object, the original value itself is returned.
|
|
1009
|
+
*
|
|
1010
|
+
* @param value - The value for which a reactive proxy shall be created.
|
|
1011
|
+
*/
|
|
1012
|
+
const toReactive = (value) => (0, _vue_shared.isObject)(value) ? /* @__PURE__ */ reactive(value) : value;
|
|
1013
|
+
/**
|
|
1014
|
+
* Returns a readonly proxy of the given value (if possible).
|
|
1015
|
+
*
|
|
1016
|
+
* If the given value is not an object, the original value itself is returned.
|
|
1017
|
+
*
|
|
1018
|
+
* @param value - The value for which a readonly proxy shall be created.
|
|
1019
|
+
*/
|
|
1020
|
+
const toReadonly = (value) => (0, _vue_shared.isObject)(value) ? /* @__PURE__ */ readonly(value) : value;
|
|
1049
1021
|
|
|
1050
|
-
|
|
1022
|
+
//#endregion
|
|
1023
|
+
//#region packages/reactivity/src/ref.ts
|
|
1024
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1051
1025
|
function isRef(r) {
|
|
1052
|
-
|
|
1026
|
+
return r ? r["__v_isRef"] === true : false;
|
|
1053
1027
|
}
|
|
1054
|
-
|
|
1028
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1055
1029
|
function ref(value) {
|
|
1056
|
-
|
|
1030
|
+
return createRef(value, toReactive);
|
|
1057
1031
|
}
|
|
1058
|
-
|
|
1032
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1059
1033
|
function shallowRef(value) {
|
|
1060
|
-
|
|
1034
|
+
return createRef(value);
|
|
1061
1035
|
}
|
|
1062
1036
|
function createRef(rawValue, wrap) {
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1037
|
+
if (/* @__PURE__ */ isRef(rawValue)) return rawValue;
|
|
1038
|
+
return new RefImpl(rawValue, wrap);
|
|
1039
|
+
}
|
|
1040
|
+
/**
|
|
1041
|
+
* @internal
|
|
1042
|
+
*/
|
|
1043
|
+
var RefImpl = class {
|
|
1044
|
+
constructor(value, wrap) {
|
|
1045
|
+
this.subs = void 0;
|
|
1046
|
+
this.subsTail = void 0;
|
|
1047
|
+
this.flags = ReactiveFlags$1.Mutable;
|
|
1048
|
+
this.__v_isRef = true;
|
|
1049
|
+
this.__v_isShallow = false;
|
|
1050
|
+
this._oldValue = this._rawValue = wrap ? /* @__PURE__ */ toRaw(value) : value;
|
|
1051
|
+
this._value = wrap ? wrap(value) : value;
|
|
1052
|
+
this._wrap = wrap;
|
|
1053
|
+
this["__v_isShallow"] = !wrap;
|
|
1054
|
+
}
|
|
1055
|
+
get dep() {
|
|
1056
|
+
return this;
|
|
1057
|
+
}
|
|
1058
|
+
get value() {
|
|
1059
|
+
trackRef(this);
|
|
1060
|
+
if (this.flags & ReactiveFlags$1.Dirty && this.update()) {
|
|
1061
|
+
const subs = this.subs;
|
|
1062
|
+
if (subs !== void 0) shallowPropagate(subs);
|
|
1063
|
+
}
|
|
1064
|
+
return this._value;
|
|
1065
|
+
}
|
|
1066
|
+
set value(newValue) {
|
|
1067
|
+
const oldValue = this._rawValue;
|
|
1068
|
+
const useDirectValue = this["__v_isShallow"] || /* @__PURE__ */ isShallow(newValue) || /* @__PURE__ */ isReadonly(newValue);
|
|
1069
|
+
newValue = useDirectValue ? newValue : /* @__PURE__ */ toRaw(newValue);
|
|
1070
|
+
if ((0, _vue_shared.hasChanged)(newValue, oldValue)) {
|
|
1071
|
+
this.flags |= ReactiveFlags$1.Dirty;
|
|
1072
|
+
this._rawValue = newValue;
|
|
1073
|
+
this._value = !useDirectValue && this._wrap ? this._wrap(newValue) : newValue;
|
|
1074
|
+
const subs = this.subs;
|
|
1075
|
+
if (subs !== void 0) {
|
|
1076
|
+
propagate(subs);
|
|
1077
|
+
if (!batchDepth) flush();
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
update() {
|
|
1082
|
+
this.flags &= ~ReactiveFlags$1.Dirty;
|
|
1083
|
+
return (0, _vue_shared.hasChanged)(this._oldValue, this._oldValue = this._rawValue);
|
|
1084
|
+
}
|
|
1085
|
+
};
|
|
1086
|
+
/**
|
|
1087
|
+
* Force trigger effects that depends on a shallow ref. This is typically used
|
|
1088
|
+
* after making deep mutations to the inner value of a shallow ref.
|
|
1089
|
+
*
|
|
1090
|
+
* @example
|
|
1091
|
+
* ```js
|
|
1092
|
+
* const shallow = shallowRef({
|
|
1093
|
+
* greet: 'Hello, world'
|
|
1094
|
+
* })
|
|
1095
|
+
*
|
|
1096
|
+
* // Logs "Hello, world" once for the first run-through
|
|
1097
|
+
* watchEffect(() => {
|
|
1098
|
+
* console.log(shallow.value.greet)
|
|
1099
|
+
* })
|
|
1100
|
+
*
|
|
1101
|
+
* // This won't trigger the effect because the ref is shallow
|
|
1102
|
+
* shallow.value.greet = 'Hello, universe'
|
|
1103
|
+
*
|
|
1104
|
+
* // Logs "Hello, universe"
|
|
1105
|
+
* triggerRef(shallow)
|
|
1106
|
+
* ```
|
|
1107
|
+
*
|
|
1108
|
+
* @param ref - The ref whose tied effects shall be executed.
|
|
1109
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#triggerref}
|
|
1110
|
+
*/
|
|
1111
|
+
function triggerRef(ref) {
|
|
1112
|
+
const dep = ref.dep;
|
|
1113
|
+
if (dep !== void 0 && dep.subs !== void 0) {
|
|
1114
|
+
propagate(dep.subs);
|
|
1115
|
+
shallowPropagate(dep.subs);
|
|
1116
|
+
if (!batchDepth) flush();
|
|
1117
|
+
}
|
|
1132
1118
|
}
|
|
1133
1119
|
function trackRef(dep) {
|
|
1134
|
-
|
|
1135
|
-
link(dep, activeSub);
|
|
1136
|
-
}
|
|
1120
|
+
if (activeSub !== void 0) link(dep, activeSub);
|
|
1137
1121
|
}
|
|
1138
|
-
|
|
1139
|
-
|
|
1122
|
+
/**
|
|
1123
|
+
* Returns the inner value if the argument is a ref, otherwise return the
|
|
1124
|
+
* argument itself. This is a sugar function for
|
|
1125
|
+
* `val = isRef(val) ? val.value : val`.
|
|
1126
|
+
*
|
|
1127
|
+
* @example
|
|
1128
|
+
* ```js
|
|
1129
|
+
* function useFoo(x: number | Ref<number>) {
|
|
1130
|
+
* const unwrapped = unref(x)
|
|
1131
|
+
* // unwrapped is guaranteed to be number now
|
|
1132
|
+
* }
|
|
1133
|
+
* ```
|
|
1134
|
+
*
|
|
1135
|
+
* @param ref - Ref or plain value to be converted into the plain value.
|
|
1136
|
+
* @see {@link https://vuejs.org/api/reactivity-utilities.html#unref}
|
|
1137
|
+
*/
|
|
1138
|
+
function unref(ref) {
|
|
1139
|
+
return /* @__PURE__ */ isRef(ref) ? ref.value : ref;
|
|
1140
1140
|
}
|
|
1141
|
+
/**
|
|
1142
|
+
* Normalizes values / refs / getters to values.
|
|
1143
|
+
* This is similar to {@link unref}, except that it also normalizes getters.
|
|
1144
|
+
* If the argument is a getter, it will be invoked and its return value will
|
|
1145
|
+
* be returned.
|
|
1146
|
+
*
|
|
1147
|
+
* @example
|
|
1148
|
+
* ```js
|
|
1149
|
+
* toValue(1) // 1
|
|
1150
|
+
* toValue(ref(1)) // 1
|
|
1151
|
+
* toValue(() => 1) // 1
|
|
1152
|
+
* ```
|
|
1153
|
+
*
|
|
1154
|
+
* @param source - A getter, an existing ref, or a non-function value.
|
|
1155
|
+
* @see {@link https://vuejs.org/api/reactivity-utilities.html#tovalue}
|
|
1156
|
+
*/
|
|
1141
1157
|
function toValue(source) {
|
|
1142
|
-
|
|
1158
|
+
return (0, _vue_shared.isFunction)(source) ? source() : unref(source);
|
|
1143
1159
|
}
|
|
1144
1160
|
const shallowUnwrapHandlers = {
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
}
|
|
1154
|
-
}
|
|
1161
|
+
get: (target, key, receiver) => key === "__v_raw" ? target : unref(Reflect.get(target, key, receiver)),
|
|
1162
|
+
set: (target, key, value, receiver) => {
|
|
1163
|
+
const oldValue = target[key];
|
|
1164
|
+
if (/* @__PURE__ */ isRef(oldValue) && !/* @__PURE__ */ isRef(value)) {
|
|
1165
|
+
oldValue.value = value;
|
|
1166
|
+
return true;
|
|
1167
|
+
} else return Reflect.set(target, key, value, receiver);
|
|
1168
|
+
}
|
|
1155
1169
|
};
|
|
1170
|
+
/**
|
|
1171
|
+
* Returns a proxy for the given object that shallowly unwraps properties that
|
|
1172
|
+
* are refs. If the object already is reactive, it's returned as-is. If not, a
|
|
1173
|
+
* new reactive proxy is created.
|
|
1174
|
+
*
|
|
1175
|
+
* @param objectWithRefs - Either an already-reactive object or a simple object
|
|
1176
|
+
* that contains refs.
|
|
1177
|
+
*/
|
|
1156
1178
|
function proxyRefs(objectWithRefs) {
|
|
1157
|
-
|
|
1158
|
-
}
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1179
|
+
return /* @__PURE__ */ isReactive(objectWithRefs) ? objectWithRefs : new Proxy(objectWithRefs, shallowUnwrapHandlers);
|
|
1180
|
+
}
|
|
1181
|
+
var CustomRefImpl = class {
|
|
1182
|
+
constructor(factory) {
|
|
1183
|
+
this.subs = void 0;
|
|
1184
|
+
this.subsTail = void 0;
|
|
1185
|
+
this.flags = ReactiveFlags$1.None;
|
|
1186
|
+
this["__v_isRef"] = true;
|
|
1187
|
+
this._value = void 0;
|
|
1188
|
+
const { get, set } = factory(() => trackRef(this), () => triggerRef(this));
|
|
1189
|
+
this._get = get;
|
|
1190
|
+
this._set = set;
|
|
1191
|
+
}
|
|
1192
|
+
get dep() {
|
|
1193
|
+
return this;
|
|
1194
|
+
}
|
|
1195
|
+
get value() {
|
|
1196
|
+
return this._value = this._get();
|
|
1197
|
+
}
|
|
1198
|
+
set value(newVal) {
|
|
1199
|
+
this._set(newVal);
|
|
1200
|
+
}
|
|
1201
|
+
};
|
|
1202
|
+
/**
|
|
1203
|
+
* Creates a customized ref with explicit control over its dependency tracking
|
|
1204
|
+
* and updates triggering.
|
|
1205
|
+
*
|
|
1206
|
+
* @param factory - The function that receives the `track` and `trigger` callbacks.
|
|
1207
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#customref}
|
|
1208
|
+
*/
|
|
1183
1209
|
function customRef(factory) {
|
|
1184
|
-
|
|
1210
|
+
return new CustomRefImpl(factory);
|
|
1185
1211
|
}
|
|
1186
|
-
|
|
1212
|
+
/**
|
|
1213
|
+
* Converts a reactive object to a plain object where each property of the
|
|
1214
|
+
* resulting object is a ref pointing to the corresponding property of the
|
|
1215
|
+
* original object. Each individual ref is created using {@link toRef}.
|
|
1216
|
+
*
|
|
1217
|
+
* @param object - Reactive object to be made into an object of linked refs.
|
|
1218
|
+
* @see {@link https://vuejs.org/api/reactivity-utilities.html#torefs}
|
|
1219
|
+
*/
|
|
1220
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1187
1221
|
function toRefs(object) {
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
}
|
|
1239
|
-
get value() {
|
|
1240
|
-
return this._value = this._getter();
|
|
1241
|
-
}
|
|
1242
|
-
}
|
|
1243
|
-
// @__NO_SIDE_EFFECTS__
|
|
1222
|
+
const ret = (0, _vue_shared.isArray)(object) ? new Array(object.length) : {};
|
|
1223
|
+
for (const key in object) ret[key] = propertyToRef(object, key);
|
|
1224
|
+
return ret;
|
|
1225
|
+
}
|
|
1226
|
+
var ObjectRefImpl = class {
|
|
1227
|
+
constructor(_object, _key, _defaultValue) {
|
|
1228
|
+
this._object = _object;
|
|
1229
|
+
this._key = _key;
|
|
1230
|
+
this._defaultValue = _defaultValue;
|
|
1231
|
+
this["__v_isRef"] = true;
|
|
1232
|
+
this._value = void 0;
|
|
1233
|
+
this._raw = /* @__PURE__ */ toRaw(_object);
|
|
1234
|
+
let shallow = true;
|
|
1235
|
+
let obj = _object;
|
|
1236
|
+
if (!(0, _vue_shared.isArray)(_object) || !(0, _vue_shared.isIntegerKey)(String(_key))) do
|
|
1237
|
+
shallow = !/* @__PURE__ */ isProxy(obj) || /* @__PURE__ */ isShallow(obj);
|
|
1238
|
+
while (shallow && (obj = obj["__v_raw"]));
|
|
1239
|
+
this._shallow = shallow;
|
|
1240
|
+
}
|
|
1241
|
+
get value() {
|
|
1242
|
+
let val = this._object[this._key];
|
|
1243
|
+
if (this._shallow) val = unref(val);
|
|
1244
|
+
return this._value = val === void 0 ? this._defaultValue : val;
|
|
1245
|
+
}
|
|
1246
|
+
set value(newVal) {
|
|
1247
|
+
if (this._shallow && /* @__PURE__ */ isRef(this._raw[this._key])) {
|
|
1248
|
+
const nestedRef = this._object[this._key];
|
|
1249
|
+
if (/* @__PURE__ */ isRef(nestedRef)) {
|
|
1250
|
+
nestedRef.value = newVal;
|
|
1251
|
+
return;
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
this._object[this._key] = newVal;
|
|
1255
|
+
}
|
|
1256
|
+
get dep() {
|
|
1257
|
+
return getDepFromReactive(this._raw, this._key);
|
|
1258
|
+
}
|
|
1259
|
+
};
|
|
1260
|
+
var GetterRefImpl = class {
|
|
1261
|
+
constructor(_getter) {
|
|
1262
|
+
this._getter = _getter;
|
|
1263
|
+
this["__v_isRef"] = true;
|
|
1264
|
+
this["__v_isReadonly"] = true;
|
|
1265
|
+
this._value = void 0;
|
|
1266
|
+
}
|
|
1267
|
+
get value() {
|
|
1268
|
+
return this._value = this._getter();
|
|
1269
|
+
}
|
|
1270
|
+
};
|
|
1271
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1244
1272
|
function toRef(source, key, defaultValue) {
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
} else if (shared.isObject(source) && arguments.length > 1) {
|
|
1250
|
-
return propertyToRef(source, key, defaultValue);
|
|
1251
|
-
} else {
|
|
1252
|
-
return /* @__PURE__ */ ref(source);
|
|
1253
|
-
}
|
|
1273
|
+
if (/* @__PURE__ */ isRef(source)) return source;
|
|
1274
|
+
else if ((0, _vue_shared.isFunction)(source)) return new GetterRefImpl(source);
|
|
1275
|
+
else if ((0, _vue_shared.isObject)(source) && arguments.length > 1) return propertyToRef(source, key, defaultValue);
|
|
1276
|
+
else return /* @__PURE__ */ ref(source);
|
|
1254
1277
|
}
|
|
1255
1278
|
function propertyToRef(source, key, defaultValue) {
|
|
1256
|
-
|
|
1279
|
+
return new ObjectRefImpl(source, key, defaultValue);
|
|
1257
1280
|
}
|
|
1258
1281
|
|
|
1282
|
+
//#endregion
|
|
1283
|
+
//#region packages/reactivity/src/effect.ts
|
|
1259
1284
|
const EffectFlags = {
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1285
|
+
"ALLOW_RECURSE": 128,
|
|
1286
|
+
"128": "ALLOW_RECURSE",
|
|
1287
|
+
"PAUSED": 256,
|
|
1288
|
+
"256": "PAUSED",
|
|
1289
|
+
"STOP": 1024,
|
|
1290
|
+
"1024": "STOP"
|
|
1291
|
+
};
|
|
1292
|
+
var ReactiveEffect = class {
|
|
1293
|
+
fn() {}
|
|
1294
|
+
constructor(fn) {
|
|
1295
|
+
this.deps = void 0;
|
|
1296
|
+
this.depsTail = void 0;
|
|
1297
|
+
this.subs = void 0;
|
|
1298
|
+
this.subsTail = void 0;
|
|
1299
|
+
this.flags = 18;
|
|
1300
|
+
this.cleanups = [];
|
|
1301
|
+
this.cleanupsLength = 0;
|
|
1302
|
+
if (fn !== void 0) this.fn = fn;
|
|
1303
|
+
if (activeEffectScope) link(this, activeEffectScope);
|
|
1304
|
+
}
|
|
1305
|
+
get active() {
|
|
1306
|
+
return !(this.flags & 1024);
|
|
1307
|
+
}
|
|
1308
|
+
pause() {
|
|
1309
|
+
this.flags |= 256;
|
|
1310
|
+
}
|
|
1311
|
+
resume() {
|
|
1312
|
+
if ((this.flags &= -257) & 48) this.notify();
|
|
1313
|
+
}
|
|
1314
|
+
notify() {
|
|
1315
|
+
if (!(this.flags & 256) && this.dirty) this.run();
|
|
1316
|
+
}
|
|
1317
|
+
run() {
|
|
1318
|
+
if (!this.active) return this.fn();
|
|
1319
|
+
cleanup(this);
|
|
1320
|
+
const prevSub = startTracking(this);
|
|
1321
|
+
try {
|
|
1322
|
+
return this.fn();
|
|
1323
|
+
} finally {
|
|
1324
|
+
endTracking(this, prevSub);
|
|
1325
|
+
const flags = this.flags;
|
|
1326
|
+
if ((flags & 136) === 136) {
|
|
1327
|
+
this.flags = flags & -9;
|
|
1328
|
+
this.notify();
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
stop() {
|
|
1333
|
+
if (!this.active) return;
|
|
1334
|
+
this.flags = 1024;
|
|
1335
|
+
let dep = this.deps;
|
|
1336
|
+
while (dep !== void 0) dep = unlink(dep, this);
|
|
1337
|
+
const sub = this.subs;
|
|
1338
|
+
if (sub !== void 0) unlink(sub);
|
|
1339
|
+
cleanup(this);
|
|
1340
|
+
}
|
|
1341
|
+
get dirty() {
|
|
1342
|
+
const flags = this.flags;
|
|
1343
|
+
if (flags & 16) return true;
|
|
1344
|
+
if (flags & 32) if (checkDirty(this.deps, this)) {
|
|
1345
|
+
this.flags = flags | 16;
|
|
1346
|
+
return true;
|
|
1347
|
+
} else this.flags = flags & -33;
|
|
1348
|
+
return false;
|
|
1349
|
+
}
|
|
1266
1350
|
};
|
|
1267
|
-
class ReactiveEffect {
|
|
1268
|
-
constructor(fn) {
|
|
1269
|
-
this.deps = void 0;
|
|
1270
|
-
this.depsTail = void 0;
|
|
1271
|
-
this.subs = void 0;
|
|
1272
|
-
this.subsTail = void 0;
|
|
1273
|
-
this.flags = ReactiveFlags$1.Watching | ReactiveFlags$1.Dirty;
|
|
1274
|
-
/**
|
|
1275
|
-
* @internal
|
|
1276
|
-
*/
|
|
1277
|
-
this.cleanups = [];
|
|
1278
|
-
/**
|
|
1279
|
-
* @internal
|
|
1280
|
-
*/
|
|
1281
|
-
this.cleanupsLength = 0;
|
|
1282
|
-
if (fn !== void 0) {
|
|
1283
|
-
this.fn = fn;
|
|
1284
|
-
}
|
|
1285
|
-
if (activeEffectScope) {
|
|
1286
|
-
link(this, activeEffectScope);
|
|
1287
|
-
}
|
|
1288
|
-
}
|
|
1289
|
-
// @ts-expect-error
|
|
1290
|
-
fn() {
|
|
1291
|
-
}
|
|
1292
|
-
get active() {
|
|
1293
|
-
return !(this.flags & 1024);
|
|
1294
|
-
}
|
|
1295
|
-
pause() {
|
|
1296
|
-
this.flags |= 256;
|
|
1297
|
-
}
|
|
1298
|
-
resume() {
|
|
1299
|
-
const flags = this.flags &= -257;
|
|
1300
|
-
if (flags & (ReactiveFlags$1.Dirty | ReactiveFlags$1.Pending)) {
|
|
1301
|
-
this.notify();
|
|
1302
|
-
}
|
|
1303
|
-
}
|
|
1304
|
-
notify() {
|
|
1305
|
-
if (!(this.flags & 256) && this.dirty) {
|
|
1306
|
-
this.run();
|
|
1307
|
-
}
|
|
1308
|
-
}
|
|
1309
|
-
run() {
|
|
1310
|
-
if (!this.active) {
|
|
1311
|
-
return this.fn();
|
|
1312
|
-
}
|
|
1313
|
-
cleanup(this);
|
|
1314
|
-
const prevSub = startTracking(this);
|
|
1315
|
-
try {
|
|
1316
|
-
return this.fn();
|
|
1317
|
-
} finally {
|
|
1318
|
-
endTracking(this, prevSub);
|
|
1319
|
-
const flags = this.flags;
|
|
1320
|
-
if ((flags & (ReactiveFlags$1.Recursed | 128)) === (ReactiveFlags$1.Recursed | 128)) {
|
|
1321
|
-
this.flags = flags & ~ReactiveFlags$1.Recursed;
|
|
1322
|
-
this.notify();
|
|
1323
|
-
}
|
|
1324
|
-
}
|
|
1325
|
-
}
|
|
1326
|
-
stop() {
|
|
1327
|
-
if (!this.active) {
|
|
1328
|
-
return;
|
|
1329
|
-
}
|
|
1330
|
-
this.flags = 1024;
|
|
1331
|
-
let dep = this.deps;
|
|
1332
|
-
while (dep !== void 0) {
|
|
1333
|
-
dep = unlink(dep, this);
|
|
1334
|
-
}
|
|
1335
|
-
const sub = this.subs;
|
|
1336
|
-
if (sub !== void 0) {
|
|
1337
|
-
unlink(sub);
|
|
1338
|
-
}
|
|
1339
|
-
cleanup(this);
|
|
1340
|
-
}
|
|
1341
|
-
get dirty() {
|
|
1342
|
-
const flags = this.flags;
|
|
1343
|
-
if (flags & ReactiveFlags$1.Dirty) {
|
|
1344
|
-
return true;
|
|
1345
|
-
}
|
|
1346
|
-
if (flags & ReactiveFlags$1.Pending) {
|
|
1347
|
-
if (checkDirty(this.deps, this)) {
|
|
1348
|
-
this.flags = flags | ReactiveFlags$1.Dirty;
|
|
1349
|
-
return true;
|
|
1350
|
-
} else {
|
|
1351
|
-
this.flags = flags & ~ReactiveFlags$1.Pending;
|
|
1352
|
-
}
|
|
1353
|
-
}
|
|
1354
|
-
return false;
|
|
1355
|
-
}
|
|
1356
|
-
}
|
|
1357
1351
|
function effect(fn, options) {
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
}
|
|
1388
|
-
const runner = e.run.bind(e);
|
|
1389
|
-
runner.effect = e;
|
|
1390
|
-
return runner;
|
|
1352
|
+
if (fn.effect instanceof ReactiveEffect) fn = fn.effect.fn;
|
|
1353
|
+
const e = new ReactiveEffect(fn);
|
|
1354
|
+
if (options) {
|
|
1355
|
+
const { onStop, scheduler } = options;
|
|
1356
|
+
if (onStop) {
|
|
1357
|
+
options.onStop = void 0;
|
|
1358
|
+
const stop = e.stop.bind(e);
|
|
1359
|
+
e.stop = () => {
|
|
1360
|
+
stop();
|
|
1361
|
+
onStop();
|
|
1362
|
+
};
|
|
1363
|
+
}
|
|
1364
|
+
if (scheduler) {
|
|
1365
|
+
options.scheduler = void 0;
|
|
1366
|
+
e.notify = () => {
|
|
1367
|
+
if (!(e.flags & 256)) scheduler();
|
|
1368
|
+
};
|
|
1369
|
+
}
|
|
1370
|
+
(0, _vue_shared.extend)(e, options);
|
|
1371
|
+
}
|
|
1372
|
+
try {
|
|
1373
|
+
e.run();
|
|
1374
|
+
} catch (err) {
|
|
1375
|
+
e.stop();
|
|
1376
|
+
throw err;
|
|
1377
|
+
}
|
|
1378
|
+
const runner = e.run.bind(e);
|
|
1379
|
+
runner.effect = e;
|
|
1380
|
+
return runner;
|
|
1391
1381
|
}
|
|
1382
|
+
/**
|
|
1383
|
+
* Stops the effect associated with the given runner.
|
|
1384
|
+
*
|
|
1385
|
+
* @param runner - Association with the effect to stop tracking.
|
|
1386
|
+
*/
|
|
1392
1387
|
function stop(runner) {
|
|
1393
|
-
|
|
1388
|
+
runner.effect.stop();
|
|
1394
1389
|
}
|
|
1395
1390
|
const resetTrackingStack = [];
|
|
1391
|
+
/**
|
|
1392
|
+
* Temporarily pauses tracking.
|
|
1393
|
+
*/
|
|
1396
1394
|
function pauseTracking() {
|
|
1397
|
-
|
|
1398
|
-
|
|
1395
|
+
resetTrackingStack.push(activeSub);
|
|
1396
|
+
setActiveSub();
|
|
1399
1397
|
}
|
|
1398
|
+
/**
|
|
1399
|
+
* Re-enables effect tracking (if it was paused).
|
|
1400
|
+
*/
|
|
1400
1401
|
function enableTracking() {
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
break;
|
|
1410
|
-
}
|
|
1411
|
-
}
|
|
1412
|
-
}
|
|
1402
|
+
if (!(activeSub === void 0)) resetTrackingStack.push(activeSub);
|
|
1403
|
+
else {
|
|
1404
|
+
resetTrackingStack.push(void 0);
|
|
1405
|
+
for (let i = resetTrackingStack.length - 1; i >= 0; i--) if (resetTrackingStack[i] !== void 0) {
|
|
1406
|
+
setActiveSub(resetTrackingStack[i]);
|
|
1407
|
+
break;
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1413
1410
|
}
|
|
1411
|
+
/**
|
|
1412
|
+
* Resets the previous global effect tracking state.
|
|
1413
|
+
*/
|
|
1414
1414
|
function resetTracking() {
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
} else {
|
|
1418
|
-
setActiveSub();
|
|
1419
|
-
}
|
|
1415
|
+
if (resetTrackingStack.length) setActiveSub(resetTrackingStack.pop());
|
|
1416
|
+
else setActiveSub();
|
|
1420
1417
|
}
|
|
1421
1418
|
function cleanup(sub) {
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
sub.cleanupsLength = 0;
|
|
1428
|
-
}
|
|
1419
|
+
const l = sub.cleanupsLength;
|
|
1420
|
+
if (l) {
|
|
1421
|
+
for (let i = 0; i < l; i++) sub.cleanups[i]();
|
|
1422
|
+
sub.cleanupsLength = 0;
|
|
1423
|
+
}
|
|
1429
1424
|
}
|
|
1425
|
+
/**
|
|
1426
|
+
* Registers a cleanup function for the current active effect.
|
|
1427
|
+
* The cleanup function is called right before the next effect run, or when the
|
|
1428
|
+
* effect is stopped.
|
|
1429
|
+
*
|
|
1430
|
+
* Throws a warning if there is no current active effect. The warning can be
|
|
1431
|
+
* suppressed by passing `true` to the second argument.
|
|
1432
|
+
*
|
|
1433
|
+
* @param fn - the cleanup function to be registered
|
|
1434
|
+
* @param failSilently - if `true`, will not throw warning when called without
|
|
1435
|
+
* an active effect.
|
|
1436
|
+
*/
|
|
1430
1437
|
function onEffectCleanup(fn, failSilently = false) {
|
|
1431
|
-
|
|
1432
|
-
activeSub.cleanups[activeSub.cleanupsLength++] = () => cleanupEffect(fn);
|
|
1433
|
-
}
|
|
1438
|
+
if (activeSub instanceof ReactiveEffect) activeSub.cleanups[activeSub.cleanupsLength++] = () => cleanupEffect(fn);
|
|
1434
1439
|
}
|
|
1435
1440
|
function cleanupEffect(fn) {
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1441
|
+
const prevSub = setActiveSub();
|
|
1442
|
+
try {
|
|
1443
|
+
fn();
|
|
1444
|
+
} finally {
|
|
1445
|
+
setActiveSub(prevSub);
|
|
1446
|
+
}
|
|
1442
1447
|
}
|
|
1443
1448
|
|
|
1449
|
+
//#endregion
|
|
1450
|
+
//#region packages/reactivity/src/effectScope.ts
|
|
1444
1451
|
let activeEffectScope;
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
dep = dep.nextDep;
|
|
1522
|
-
node.stop();
|
|
1523
|
-
} else {
|
|
1524
|
-
dep = unlink(dep, this);
|
|
1525
|
-
}
|
|
1526
|
-
}
|
|
1527
|
-
cleanup(this);
|
|
1528
|
-
}
|
|
1529
|
-
}
|
|
1452
|
+
var EffectScope = class {
|
|
1453
|
+
constructor(detached = false) {
|
|
1454
|
+
this.deps = void 0;
|
|
1455
|
+
this.depsTail = void 0;
|
|
1456
|
+
this.subs = void 0;
|
|
1457
|
+
this.subsTail = void 0;
|
|
1458
|
+
this.flags = 0;
|
|
1459
|
+
this.cleanups = [];
|
|
1460
|
+
this.cleanupsLength = 0;
|
|
1461
|
+
if (!detached && activeEffectScope) link(this, activeEffectScope);
|
|
1462
|
+
}
|
|
1463
|
+
get active() {
|
|
1464
|
+
return !(this.flags & 1024);
|
|
1465
|
+
}
|
|
1466
|
+
pause() {
|
|
1467
|
+
if (!(this.flags & 256)) {
|
|
1468
|
+
this.flags |= 256;
|
|
1469
|
+
for (let link = this.deps; link !== void 0; link = link.nextDep) {
|
|
1470
|
+
const dep = link.dep;
|
|
1471
|
+
if ("pause" in dep) dep.pause();
|
|
1472
|
+
}
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
/**
|
|
1476
|
+
* Resumes the effect scope, including all child scopes and effects.
|
|
1477
|
+
*/
|
|
1478
|
+
resume() {
|
|
1479
|
+
const flags = this.flags;
|
|
1480
|
+
if (flags & 256) {
|
|
1481
|
+
this.flags = flags & -257;
|
|
1482
|
+
for (let link = this.deps; link !== void 0; link = link.nextDep) {
|
|
1483
|
+
const dep = link.dep;
|
|
1484
|
+
if ("resume" in dep) dep.resume();
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
run(fn) {
|
|
1489
|
+
const prevScope = activeEffectScope;
|
|
1490
|
+
try {
|
|
1491
|
+
activeEffectScope = this;
|
|
1492
|
+
return fn();
|
|
1493
|
+
} finally {
|
|
1494
|
+
activeEffectScope = prevScope;
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
stop() {
|
|
1498
|
+
if (!this.active) return;
|
|
1499
|
+
this.flags = 1024;
|
|
1500
|
+
this.reset();
|
|
1501
|
+
const sub = this.subs;
|
|
1502
|
+
if (sub !== void 0) unlink(sub);
|
|
1503
|
+
}
|
|
1504
|
+
/**
|
|
1505
|
+
* @internal
|
|
1506
|
+
*/
|
|
1507
|
+
reset() {
|
|
1508
|
+
let dep = this.deps;
|
|
1509
|
+
while (dep !== void 0) {
|
|
1510
|
+
const node = dep.dep;
|
|
1511
|
+
if ("stop" in node) {
|
|
1512
|
+
dep = dep.nextDep;
|
|
1513
|
+
node.stop();
|
|
1514
|
+
} else dep = unlink(dep, this);
|
|
1515
|
+
}
|
|
1516
|
+
cleanup(this);
|
|
1517
|
+
}
|
|
1518
|
+
};
|
|
1519
|
+
/**
|
|
1520
|
+
* Creates an effect scope object which can capture the reactive effects (i.e.
|
|
1521
|
+
* computed and watchers) created within it so that these effects can be
|
|
1522
|
+
* disposed together. For detailed use cases of this API, please consult its
|
|
1523
|
+
* corresponding {@link https://github.com/vuejs/rfcs/blob/master/active-rfcs/0041-reactivity-effect-scope.md | RFC}.
|
|
1524
|
+
*
|
|
1525
|
+
* @param detached - Can be used to create a "detached" effect scope.
|
|
1526
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#effectscope}
|
|
1527
|
+
*/
|
|
1530
1528
|
function effectScope(detached) {
|
|
1531
|
-
|
|
1529
|
+
return new EffectScope(detached);
|
|
1532
1530
|
}
|
|
1531
|
+
/**
|
|
1532
|
+
* Returns the current active effect scope if there is one.
|
|
1533
|
+
*
|
|
1534
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#getcurrentscope}
|
|
1535
|
+
*/
|
|
1533
1536
|
function getCurrentScope() {
|
|
1534
|
-
|
|
1537
|
+
return activeEffectScope;
|
|
1535
1538
|
}
|
|
1536
1539
|
function setCurrentScope(scope) {
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1540
|
+
try {
|
|
1541
|
+
return activeEffectScope;
|
|
1542
|
+
} finally {
|
|
1543
|
+
activeEffectScope = scope;
|
|
1544
|
+
}
|
|
1542
1545
|
}
|
|
1546
|
+
/**
|
|
1547
|
+
* Registers a dispose callback on the current active effect scope. The
|
|
1548
|
+
* callback will be invoked when the associated effect scope is stopped.
|
|
1549
|
+
*
|
|
1550
|
+
* @param fn - The callback function to attach to the scope's cleanup.
|
|
1551
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#onscopedispose}
|
|
1552
|
+
*/
|
|
1543
1553
|
function onScopeDispose(fn, failSilently = false) {
|
|
1544
|
-
|
|
1545
|
-
activeEffectScope.cleanups[activeEffectScope.cleanupsLength++] = fn;
|
|
1546
|
-
}
|
|
1554
|
+
if (activeEffectScope !== void 0) activeEffectScope.cleanups[activeEffectScope.cleanupsLength++] = fn;
|
|
1547
1555
|
}
|
|
1548
1556
|
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
set value(newValue) {
|
|
1627
|
-
if (this.setter) {
|
|
1628
|
-
this.setter(newValue);
|
|
1629
|
-
}
|
|
1630
|
-
}
|
|
1631
|
-
update() {
|
|
1632
|
-
const prevSub = startTracking(this);
|
|
1633
|
-
try {
|
|
1634
|
-
const oldValue = this._value;
|
|
1635
|
-
const newValue = this.fn(oldValue);
|
|
1636
|
-
if (shared.hasChanged(oldValue, newValue)) {
|
|
1637
|
-
this._value = newValue;
|
|
1638
|
-
return true;
|
|
1639
|
-
}
|
|
1640
|
-
return false;
|
|
1641
|
-
} finally {
|
|
1642
|
-
endTracking(this, prevSub);
|
|
1643
|
-
}
|
|
1644
|
-
}
|
|
1645
|
-
}
|
|
1646
|
-
// @__NO_SIDE_EFFECTS__
|
|
1557
|
+
//#endregion
|
|
1558
|
+
//#region packages/reactivity/src/computed.ts
|
|
1559
|
+
/**
|
|
1560
|
+
* @private exported by @vue/reactivity for Vue core use, but not exported from
|
|
1561
|
+
* the main vue package
|
|
1562
|
+
*/
|
|
1563
|
+
var ComputedRefImpl = class {
|
|
1564
|
+
get effect() {
|
|
1565
|
+
return this;
|
|
1566
|
+
}
|
|
1567
|
+
get dep() {
|
|
1568
|
+
return this;
|
|
1569
|
+
}
|
|
1570
|
+
/**
|
|
1571
|
+
* @internal
|
|
1572
|
+
* for backwards compat
|
|
1573
|
+
*/
|
|
1574
|
+
get _dirty() {
|
|
1575
|
+
const flags = this.flags;
|
|
1576
|
+
if (flags & ReactiveFlags$1.Dirty) return true;
|
|
1577
|
+
if (flags & ReactiveFlags$1.Pending) if (checkDirty(this.deps, this)) {
|
|
1578
|
+
this.flags = flags | ReactiveFlags$1.Dirty;
|
|
1579
|
+
return true;
|
|
1580
|
+
} else this.flags = flags & ~ReactiveFlags$1.Pending;
|
|
1581
|
+
return false;
|
|
1582
|
+
}
|
|
1583
|
+
/**
|
|
1584
|
+
* @internal
|
|
1585
|
+
* for backwards compat
|
|
1586
|
+
*/
|
|
1587
|
+
set _dirty(v) {
|
|
1588
|
+
if (v) this.flags |= ReactiveFlags$1.Dirty;
|
|
1589
|
+
else this.flags &= ~(ReactiveFlags$1.Dirty | ReactiveFlags$1.Pending);
|
|
1590
|
+
}
|
|
1591
|
+
constructor(fn, setter) {
|
|
1592
|
+
this.fn = fn;
|
|
1593
|
+
this.setter = setter;
|
|
1594
|
+
this._value = void 0;
|
|
1595
|
+
this.subs = void 0;
|
|
1596
|
+
this.subsTail = void 0;
|
|
1597
|
+
this.deps = void 0;
|
|
1598
|
+
this.depsTail = void 0;
|
|
1599
|
+
this.flags = ReactiveFlags$1.Mutable | ReactiveFlags$1.Dirty;
|
|
1600
|
+
this.__v_isRef = true;
|
|
1601
|
+
this["__v_isReadonly"] = !setter;
|
|
1602
|
+
}
|
|
1603
|
+
get value() {
|
|
1604
|
+
const flags = this.flags;
|
|
1605
|
+
if (flags & ReactiveFlags$1.Dirty || flags & ReactiveFlags$1.Pending && checkDirty(this.deps, this)) {
|
|
1606
|
+
if (this.update()) {
|
|
1607
|
+
const subs = this.subs;
|
|
1608
|
+
if (subs !== void 0) shallowPropagate(subs);
|
|
1609
|
+
}
|
|
1610
|
+
} else if (flags & ReactiveFlags$1.Pending) this.flags = flags & ~ReactiveFlags$1.Pending;
|
|
1611
|
+
if (activeSub !== void 0) link(this, activeSub);
|
|
1612
|
+
else if (activeEffectScope !== void 0) link(this, activeEffectScope);
|
|
1613
|
+
return this._value;
|
|
1614
|
+
}
|
|
1615
|
+
set value(newValue) {
|
|
1616
|
+
if (this.setter) this.setter(newValue);
|
|
1617
|
+
}
|
|
1618
|
+
update() {
|
|
1619
|
+
const prevSub = startTracking(this);
|
|
1620
|
+
try {
|
|
1621
|
+
const oldValue = this._value;
|
|
1622
|
+
const newValue = this.fn(oldValue);
|
|
1623
|
+
if ((0, _vue_shared.hasChanged)(oldValue, newValue)) {
|
|
1624
|
+
this._value = newValue;
|
|
1625
|
+
return true;
|
|
1626
|
+
}
|
|
1627
|
+
return false;
|
|
1628
|
+
} finally {
|
|
1629
|
+
endTracking(this, prevSub);
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
};
|
|
1633
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1647
1634
|
function computed(getterOrOptions, debugOptions, isSSR = false) {
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
const cRef = new ComputedRefImpl(getter, setter);
|
|
1657
|
-
return cRef;
|
|
1635
|
+
let getter;
|
|
1636
|
+
let setter;
|
|
1637
|
+
if ((0, _vue_shared.isFunction)(getterOrOptions)) getter = getterOrOptions;
|
|
1638
|
+
else {
|
|
1639
|
+
getter = getterOrOptions.get;
|
|
1640
|
+
setter = getterOrOptions.set;
|
|
1641
|
+
}
|
|
1642
|
+
return new ComputedRefImpl(getter, setter);
|
|
1658
1643
|
}
|
|
1659
1644
|
|
|
1645
|
+
//#endregion
|
|
1646
|
+
//#region packages/reactivity/src/constants.ts
|
|
1660
1647
|
const TrackOpTypes = {
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1648
|
+
"GET": "get",
|
|
1649
|
+
"HAS": "has",
|
|
1650
|
+
"ITERATE": "iterate"
|
|
1664
1651
|
};
|
|
1665
1652
|
const TriggerOpTypes = {
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1653
|
+
"SET": "set",
|
|
1654
|
+
"ADD": "add",
|
|
1655
|
+
"DELETE": "delete",
|
|
1656
|
+
"CLEAR": "clear"
|
|
1670
1657
|
};
|
|
1671
1658
|
const ReactiveFlags = {
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1659
|
+
"SKIP": "__v_skip",
|
|
1660
|
+
"IS_REACTIVE": "__v_isReactive",
|
|
1661
|
+
"IS_READONLY": "__v_isReadonly",
|
|
1662
|
+
"IS_SHALLOW": "__v_isShallow",
|
|
1663
|
+
"RAW": "__v_raw",
|
|
1664
|
+
"IS_REF": "__v_isRef"
|
|
1678
1665
|
};
|
|
1679
1666
|
|
|
1667
|
+
//#endregion
|
|
1668
|
+
//#region packages/reactivity/src/watch.ts
|
|
1680
1669
|
const WatchErrorCodes = {
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1670
|
+
"WATCH_GETTER": 2,
|
|
1671
|
+
"2": "WATCH_GETTER",
|
|
1672
|
+
"WATCH_CALLBACK": 3,
|
|
1673
|
+
"3": "WATCH_CALLBACK",
|
|
1674
|
+
"WATCH_CLEANUP": 4,
|
|
1675
|
+
"4": "WATCH_CLEANUP"
|
|
1687
1676
|
};
|
|
1688
1677
|
const INITIAL_WATCHER_VALUE = {};
|
|
1689
1678
|
let activeWatcher = void 0;
|
|
1679
|
+
/**
|
|
1680
|
+
* Returns the current active effect if there is one.
|
|
1681
|
+
*/
|
|
1690
1682
|
function getCurrentWatcher() {
|
|
1691
|
-
|
|
1683
|
+
return activeWatcher;
|
|
1692
1684
|
}
|
|
1685
|
+
/**
|
|
1686
|
+
* Registers a cleanup callback on the current active effect. This
|
|
1687
|
+
* registered cleanup callback will be invoked right before the
|
|
1688
|
+
* associated effect re-runs.
|
|
1689
|
+
*
|
|
1690
|
+
* @param cleanupFn - The callback function to attach to the effect's cleanup.
|
|
1691
|
+
* @param failSilently - if `true`, will not throw warning when called without
|
|
1692
|
+
* an active effect.
|
|
1693
|
+
* @param owner - The effect that this cleanup function should be attached to.
|
|
1694
|
+
* By default, the current active effect.
|
|
1695
|
+
*/
|
|
1693
1696
|
function onWatcherCleanup(cleanupFn, failSilently = false, owner = activeWatcher) {
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
}
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
return;
|
|
1784
|
-
}
|
|
1785
|
-
if (deep || this.forceTrigger || (this.isMultiSource ? newValue.some((v, i) => shared.hasChanged(v, oldValue[i])) : shared.hasChanged(newValue, oldValue))) {
|
|
1786
|
-
cleanup(this);
|
|
1787
|
-
const currentWatcher = activeWatcher;
|
|
1788
|
-
activeWatcher = this;
|
|
1789
|
-
try {
|
|
1790
|
-
const args = [
|
|
1791
|
-
newValue,
|
|
1792
|
-
// pass undefined as the old value when it's changed for the first time
|
|
1793
|
-
oldValue === INITIAL_WATCHER_VALUE ? void 0 : this.isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE ? [] : oldValue,
|
|
1794
|
-
this.boundCleanup
|
|
1795
|
-
];
|
|
1796
|
-
call ? call(this.cb, 3, args) : (
|
|
1797
|
-
// @ts-expect-error
|
|
1798
|
-
this.cb(...args)
|
|
1799
|
-
);
|
|
1800
|
-
} finally {
|
|
1801
|
-
activeWatcher = currentWatcher;
|
|
1802
|
-
}
|
|
1803
|
-
}
|
|
1804
|
-
}
|
|
1805
|
-
}
|
|
1697
|
+
if (owner) {
|
|
1698
|
+
const { call } = owner.options;
|
|
1699
|
+
if (call) owner.cleanups[owner.cleanupsLength++] = () => call(cleanupFn, 4);
|
|
1700
|
+
else owner.cleanups[owner.cleanupsLength++] = cleanupFn;
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
var WatcherEffect = class extends ReactiveEffect {
|
|
1704
|
+
constructor(source, cb, options = _vue_shared.EMPTY_OBJ) {
|
|
1705
|
+
const { deep, once, call, onWarn } = options;
|
|
1706
|
+
let getter;
|
|
1707
|
+
let forceTrigger = false;
|
|
1708
|
+
let isMultiSource = false;
|
|
1709
|
+
if (/* @__PURE__ */ isRef(source)) {
|
|
1710
|
+
getter = () => source.value;
|
|
1711
|
+
forceTrigger = /* @__PURE__ */ isShallow(source);
|
|
1712
|
+
} else if (/* @__PURE__ */ isReactive(source)) {
|
|
1713
|
+
getter = () => reactiveGetter(source, deep);
|
|
1714
|
+
forceTrigger = true;
|
|
1715
|
+
} else if ((0, _vue_shared.isArray)(source)) {
|
|
1716
|
+
isMultiSource = true;
|
|
1717
|
+
forceTrigger = source.some((s) => /* @__PURE__ */ isReactive(s) || /* @__PURE__ */ isShallow(s));
|
|
1718
|
+
getter = () => source.map((s) => {
|
|
1719
|
+
if (/* @__PURE__ */ isRef(s)) return s.value;
|
|
1720
|
+
else if (/* @__PURE__ */ isReactive(s)) return reactiveGetter(s, deep);
|
|
1721
|
+
else if ((0, _vue_shared.isFunction)(s)) return call ? call(s, 2) : s();
|
|
1722
|
+
});
|
|
1723
|
+
} else if ((0, _vue_shared.isFunction)(source)) if (cb) getter = call ? () => call(source, 2) : source;
|
|
1724
|
+
else getter = () => {
|
|
1725
|
+
if (this.cleanupsLength) {
|
|
1726
|
+
const prevSub = setActiveSub();
|
|
1727
|
+
try {
|
|
1728
|
+
cleanup(this);
|
|
1729
|
+
} finally {
|
|
1730
|
+
setActiveSub(prevSub);
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
const currentEffect = activeWatcher;
|
|
1734
|
+
activeWatcher = this;
|
|
1735
|
+
try {
|
|
1736
|
+
return call ? call(source, 3, [this.boundCleanup]) : source(this.boundCleanup);
|
|
1737
|
+
} finally {
|
|
1738
|
+
activeWatcher = currentEffect;
|
|
1739
|
+
}
|
|
1740
|
+
};
|
|
1741
|
+
else getter = _vue_shared.NOOP;
|
|
1742
|
+
if (cb && deep) {
|
|
1743
|
+
const baseGetter = getter;
|
|
1744
|
+
const depth = deep === true ? Infinity : deep;
|
|
1745
|
+
getter = () => traverse(baseGetter(), depth);
|
|
1746
|
+
}
|
|
1747
|
+
super(getter);
|
|
1748
|
+
this.cb = cb;
|
|
1749
|
+
this.options = options;
|
|
1750
|
+
this.boundCleanup = (fn) => onWatcherCleanup(fn, false, this);
|
|
1751
|
+
this.forceTrigger = forceTrigger;
|
|
1752
|
+
this.isMultiSource = isMultiSource;
|
|
1753
|
+
if (once && cb) {
|
|
1754
|
+
const _cb = cb;
|
|
1755
|
+
cb = (...args) => {
|
|
1756
|
+
_cb(...args);
|
|
1757
|
+
this.stop();
|
|
1758
|
+
};
|
|
1759
|
+
}
|
|
1760
|
+
this.cb = cb;
|
|
1761
|
+
this.oldValue = isMultiSource ? new Array(source.length).fill(INITIAL_WATCHER_VALUE) : INITIAL_WATCHER_VALUE;
|
|
1762
|
+
}
|
|
1763
|
+
run(initialRun = false) {
|
|
1764
|
+
const oldValue = this.oldValue;
|
|
1765
|
+
const newValue = this.oldValue = super.run();
|
|
1766
|
+
if (!this.cb) return;
|
|
1767
|
+
const { immediate, deep, call } = this.options;
|
|
1768
|
+
if (initialRun && !immediate) return;
|
|
1769
|
+
if (deep || this.forceTrigger || (this.isMultiSource ? newValue.some((v, i) => (0, _vue_shared.hasChanged)(v, oldValue[i])) : (0, _vue_shared.hasChanged)(newValue, oldValue))) {
|
|
1770
|
+
cleanup(this);
|
|
1771
|
+
const currentWatcher = activeWatcher;
|
|
1772
|
+
activeWatcher = this;
|
|
1773
|
+
try {
|
|
1774
|
+
const args = [
|
|
1775
|
+
newValue,
|
|
1776
|
+
oldValue === INITIAL_WATCHER_VALUE ? void 0 : this.isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE ? [] : oldValue,
|
|
1777
|
+
this.boundCleanup
|
|
1778
|
+
];
|
|
1779
|
+
call ? call(this.cb, 3, args) : this.cb(...args);
|
|
1780
|
+
} finally {
|
|
1781
|
+
activeWatcher = currentWatcher;
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
}
|
|
1785
|
+
};
|
|
1806
1786
|
function reactiveGetter(source, deep) {
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
return stop;
|
|
1787
|
+
if (deep) return source;
|
|
1788
|
+
if (/* @__PURE__ */ isShallow(source) || deep === false || deep === 0) return traverse(source, 1);
|
|
1789
|
+
return traverse(source);
|
|
1790
|
+
}
|
|
1791
|
+
function watch(source, cb, options = _vue_shared.EMPTY_OBJ) {
|
|
1792
|
+
const effect = new WatcherEffect(source, cb, options);
|
|
1793
|
+
effect.run(true);
|
|
1794
|
+
const stop = effect.stop.bind(effect);
|
|
1795
|
+
stop.pause = effect.pause.bind(effect);
|
|
1796
|
+
stop.resume = effect.resume.bind(effect);
|
|
1797
|
+
stop.stop = stop;
|
|
1798
|
+
return stop;
|
|
1820
1799
|
}
|
|
1821
1800
|
function traverse(value, depth = Infinity, seen) {
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
} else if (shared.isSet(value) || shared.isMap(value)) {
|
|
1838
|
-
value.forEach((v) => {
|
|
1839
|
-
traverse(v, depth, seen);
|
|
1840
|
-
});
|
|
1841
|
-
} else if (shared.isPlainObject(value)) {
|
|
1842
|
-
for (const key in value) {
|
|
1843
|
-
traverse(value[key], depth, seen);
|
|
1844
|
-
}
|
|
1845
|
-
for (const key of Object.getOwnPropertySymbols(value)) {
|
|
1846
|
-
if (Object.prototype.propertyIsEnumerable.call(value, key)) {
|
|
1847
|
-
traverse(value[key], depth, seen);
|
|
1848
|
-
}
|
|
1849
|
-
}
|
|
1850
|
-
}
|
|
1851
|
-
return value;
|
|
1801
|
+
if (depth <= 0 || !(0, _vue_shared.isObject)(value) || value["__v_skip"]) return value;
|
|
1802
|
+
seen = seen || /* @__PURE__ */ new Map();
|
|
1803
|
+
if ((seen.get(value) || 0) >= depth) return value;
|
|
1804
|
+
seen.set(value, depth);
|
|
1805
|
+
depth--;
|
|
1806
|
+
if (/* @__PURE__ */ isRef(value)) traverse(value.value, depth, seen);
|
|
1807
|
+
else if ((0, _vue_shared.isArray)(value)) for (let i = 0; i < value.length; i++) traverse(value[i], depth, seen);
|
|
1808
|
+
else if ((0, _vue_shared.isSet)(value) || (0, _vue_shared.isMap)(value)) value.forEach((v) => {
|
|
1809
|
+
traverse(v, depth, seen);
|
|
1810
|
+
});
|
|
1811
|
+
else if ((0, _vue_shared.isPlainObject)(value)) {
|
|
1812
|
+
for (const key in value) traverse(value[key], depth, seen);
|
|
1813
|
+
for (const key of Object.getOwnPropertySymbols(value)) if (Object.prototype.propertyIsEnumerable.call(value, key)) traverse(value[key], depth, seen);
|
|
1814
|
+
}
|
|
1815
|
+
return value;
|
|
1852
1816
|
}
|
|
1853
1817
|
|
|
1818
|
+
//#endregion
|
|
1854
1819
|
exports.ARRAY_ITERATE_KEY = ARRAY_ITERATE_KEY;
|
|
1855
1820
|
exports.EffectFlags = EffectFlags;
|
|
1856
1821
|
exports.EffectScope = EffectScope;
|
|
@@ -1903,4 +1868,4 @@ exports.traverse = traverse;
|
|
|
1903
1868
|
exports.trigger = trigger;
|
|
1904
1869
|
exports.triggerRef = triggerRef;
|
|
1905
1870
|
exports.unref = unref;
|
|
1906
|
-
exports.watch = watch;
|
|
1871
|
+
exports.watch = watch;
|