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