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