@estjs/signals 0.0.16-beta.2 → 0.0.16-beta.3
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/signals.cjs.js +3 -3
- package/dist/signals.cjs.js.map +1 -1
- package/dist/signals.d.cts +36 -183
- package/dist/signals.d.ts +36 -183
- package/dist/signals.dev.cjs.js +243 -95
- package/dist/signals.dev.esm.js +239 -96
- package/dist/signals.esm.js +3 -3
- package/dist/signals.esm.js.map +1 -1
- package/package.json +2 -2
package/dist/signals.dev.esm.js
CHANGED
|
@@ -30,78 +30,7 @@ var WEAK_COLLECTION_KEY = /* @__PURE__ */ Symbol("WeakCollection_Key" );
|
|
|
30
30
|
var ITERATE_KEY = /* @__PURE__ */ Symbol("Iterate_Key" );
|
|
31
31
|
var ARRAY_ITERATE_KEY = /* @__PURE__ */ Symbol("Array_Iterate_Key" );
|
|
32
32
|
|
|
33
|
-
// src/
|
|
34
|
-
function enqueueEffect(effect2) {
|
|
35
|
-
var _a5;
|
|
36
|
-
(_a5 = effect2 == null ? void 0 : effect2.notify) == null ? void 0 : _a5.call(effect2);
|
|
37
|
-
}
|
|
38
|
-
function propagate(link) {
|
|
39
|
-
let next = link.nextSubLink;
|
|
40
|
-
let stack;
|
|
41
|
-
top: do {
|
|
42
|
-
const sub = link.subNode;
|
|
43
|
-
const watcherBit = sub.flag & 2 /* WATCHING */;
|
|
44
|
-
let flags = sub.flag;
|
|
45
|
-
if (!(flags & (16 /* DIRTY */ | 32 /* PENDING */ | 8 /* RECURSED */ | 4 /* RECURSED_CHECK */))) {
|
|
46
|
-
sub.flag = flags | 32 /* PENDING */;
|
|
47
|
-
if (watcherBit) {
|
|
48
|
-
enqueueEffect(sub);
|
|
49
|
-
}
|
|
50
|
-
} else if (!(flags & (8 /* RECURSED */ | 4 /* RECURSED_CHECK */))) {
|
|
51
|
-
flags = 0 /* NONE */;
|
|
52
|
-
} else if (!(flags & 4 /* RECURSED_CHECK */)) {
|
|
53
|
-
sub.flag = flags & -9 /* RECURSED */ | 32 /* PENDING */;
|
|
54
|
-
} else if (!(flags & (16 /* DIRTY */ | 32 /* PENDING */)) && isValidLink(link, sub)) {
|
|
55
|
-
sub.flag = flags | (8 /* RECURSED */ | 32 /* PENDING */);
|
|
56
|
-
if (watcherBit) {
|
|
57
|
-
enqueueEffect(sub);
|
|
58
|
-
}
|
|
59
|
-
flags &= 1 /* MUTABLE */;
|
|
60
|
-
} else {
|
|
61
|
-
flags = 0 /* NONE */;
|
|
62
|
-
}
|
|
63
|
-
if (flags & 1 /* MUTABLE */) {
|
|
64
|
-
const subSubs = sub.subLink;
|
|
65
|
-
if (subSubs !== void 0) {
|
|
66
|
-
const nextSub = subSubs.nextSubLink;
|
|
67
|
-
if (nextSub !== void 0) {
|
|
68
|
-
stack = { value: next, prev: stack };
|
|
69
|
-
next = nextSub;
|
|
70
|
-
}
|
|
71
|
-
link = subSubs;
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
if ((link = next) !== void 0) {
|
|
76
|
-
next = link.nextSubLink;
|
|
77
|
-
continue;
|
|
78
|
-
}
|
|
79
|
-
while (stack !== void 0) {
|
|
80
|
-
link = stack.value;
|
|
81
|
-
stack = stack.prev;
|
|
82
|
-
if (link !== void 0) {
|
|
83
|
-
next = link.nextSubLink;
|
|
84
|
-
continue top;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
break;
|
|
88
|
-
} while (true);
|
|
89
|
-
}
|
|
90
|
-
function shallowPropagate(link) {
|
|
91
|
-
while (link) {
|
|
92
|
-
const sub = link.subNode;
|
|
93
|
-
const flags = sub.flag;
|
|
94
|
-
if ((flags & (32 /* PENDING */ | 16 /* DIRTY */)) === 32 /* PENDING */) {
|
|
95
|
-
sub.flag = flags | 16 /* DIRTY */;
|
|
96
|
-
if ((flags & (2 /* WATCHING */ | 4 /* RECURSED_CHECK */)) === 2 /* WATCHING */) {
|
|
97
|
-
enqueueEffect(sub);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
link = link.nextSubLink;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// src/link.ts
|
|
33
|
+
// src/system.ts
|
|
105
34
|
var currentLinkVersion = 0;
|
|
106
35
|
var activeSub;
|
|
107
36
|
var isUntracking = false;
|
|
@@ -122,6 +51,10 @@ var Dep = class {
|
|
|
122
51
|
}
|
|
123
52
|
}
|
|
124
53
|
};
|
|
54
|
+
function enqueueEffect(effect2) {
|
|
55
|
+
var _a5;
|
|
56
|
+
(_a5 = effect2 == null ? void 0 : effect2.notify) == null ? void 0 : _a5.call(effect2);
|
|
57
|
+
}
|
|
125
58
|
function linkReactiveNode(depNode, subNode) {
|
|
126
59
|
if (isUntracking) {
|
|
127
60
|
return void 0;
|
|
@@ -145,10 +78,8 @@ function linkReactiveNode(depNode, subNode) {
|
|
|
145
78
|
version: currentLinkVersion,
|
|
146
79
|
depNode,
|
|
147
80
|
subNode,
|
|
148
|
-
// Subscriber chain pointers (horizontal)
|
|
149
81
|
prevSubLink: prevSub,
|
|
150
82
|
nextSubLink: void 0,
|
|
151
|
-
// Dependency chain pointers (vertical)
|
|
152
83
|
prevDepLink: prevDep,
|
|
153
84
|
nextDepLink: nextDep
|
|
154
85
|
};
|
|
@@ -167,15 +98,13 @@ function linkReactiveNode(depNode, subNode) {
|
|
|
167
98
|
}
|
|
168
99
|
depNode.subLinkTail = newLink;
|
|
169
100
|
subNode.depLinkTail = newLink;
|
|
170
|
-
{
|
|
171
|
-
|
|
172
|
-
subNode
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
});
|
|
178
|
-
}
|
|
101
|
+
if (subNode.onTrack && isFunction(subNode.onTrack)) {
|
|
102
|
+
subNode.onTrack({
|
|
103
|
+
effect: subNode,
|
|
104
|
+
target: depNode,
|
|
105
|
+
type: "get",
|
|
106
|
+
key: void 0
|
|
107
|
+
});
|
|
179
108
|
}
|
|
180
109
|
return newLink;
|
|
181
110
|
}
|
|
@@ -213,12 +142,10 @@ function unlinkReactiveNode(linkNode, subNode = linkNode.subNode) {
|
|
|
213
142
|
if (!depNode.isDep) {
|
|
214
143
|
depNode.flag |= 16 /* DIRTY */;
|
|
215
144
|
}
|
|
216
|
-
{
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
);
|
|
221
|
-
}
|
|
145
|
+
if (depNode.depLink) {
|
|
146
|
+
error(
|
|
147
|
+
"[Link] Cascading cleanup failed: depNode still has dependency links. This indicates a bug in the unlinking logic."
|
|
148
|
+
);
|
|
222
149
|
}
|
|
223
150
|
}
|
|
224
151
|
}
|
|
@@ -238,7 +165,7 @@ function checkDirty(link, sub) {
|
|
|
238
165
|
if ((depFlags & (1 /* MUTABLE */ | 16 /* DIRTY */)) === (1 /* MUTABLE */ | 16 /* DIRTY */)) {
|
|
239
166
|
const subs = dep.subLink;
|
|
240
167
|
if (subs && subs.nextSubLink) {
|
|
241
|
-
|
|
168
|
+
shallowPropagate(subs);
|
|
242
169
|
}
|
|
243
170
|
currentDirty = true;
|
|
244
171
|
} else if ((depFlags & (1 /* MUTABLE */ | 32 /* PENDING */)) === (1 /* MUTABLE */ | 32 /* PENDING */)) {
|
|
@@ -286,16 +213,71 @@ function checkDirty(link, sub) {
|
|
|
286
213
|
return dirty;
|
|
287
214
|
} while (true);
|
|
288
215
|
}
|
|
289
|
-
function
|
|
216
|
+
function shallowPropagate(link) {
|
|
290
217
|
while (link) {
|
|
291
218
|
const sub = link.subNode;
|
|
292
219
|
const flags = sub.flag;
|
|
293
220
|
if ((flags & (32 /* PENDING */ | 16 /* DIRTY */)) === 32 /* PENDING */) {
|
|
294
221
|
sub.flag = flags | 16 /* DIRTY */;
|
|
222
|
+
if ((flags & (2 /* WATCHING */ | 4 /* RECURSED_CHECK */)) === 2 /* WATCHING */) {
|
|
223
|
+
enqueueEffect(sub);
|
|
224
|
+
}
|
|
295
225
|
}
|
|
296
226
|
link = link.nextSubLink;
|
|
297
227
|
}
|
|
298
228
|
}
|
|
229
|
+
function propagate(link) {
|
|
230
|
+
let next = link.nextSubLink;
|
|
231
|
+
let stack;
|
|
232
|
+
top: do {
|
|
233
|
+
const sub = link.subNode;
|
|
234
|
+
const watcherBit = sub.flag & 2 /* WATCHING */;
|
|
235
|
+
let flags = sub.flag;
|
|
236
|
+
if (!(flags & (16 /* DIRTY */ | 32 /* PENDING */ | 8 /* RECURSED */ | 4 /* RECURSED_CHECK */))) {
|
|
237
|
+
sub.flag = flags | 32 /* PENDING */;
|
|
238
|
+
if (watcherBit) {
|
|
239
|
+
enqueueEffect(sub);
|
|
240
|
+
}
|
|
241
|
+
} else if (!(flags & (8 /* RECURSED */ | 4 /* RECURSED_CHECK */))) {
|
|
242
|
+
flags = 0 /* NONE */;
|
|
243
|
+
} else if (!(flags & 4 /* RECURSED_CHECK */)) {
|
|
244
|
+
sub.flag = flags & -9 /* RECURSED */ | 32 /* PENDING */;
|
|
245
|
+
} else if (!(flags & (16 /* DIRTY */ | 32 /* PENDING */)) && isValidLink(link, sub)) {
|
|
246
|
+
sub.flag = flags | (8 /* RECURSED */ | 32 /* PENDING */);
|
|
247
|
+
if (watcherBit) {
|
|
248
|
+
enqueueEffect(sub);
|
|
249
|
+
}
|
|
250
|
+
flags &= 1 /* MUTABLE */;
|
|
251
|
+
} else {
|
|
252
|
+
flags = 0 /* NONE */;
|
|
253
|
+
}
|
|
254
|
+
if (flags & 1 /* MUTABLE */) {
|
|
255
|
+
const subSubs = sub.subLink;
|
|
256
|
+
if (subSubs !== void 0) {
|
|
257
|
+
const nextSub = subSubs.nextSubLink;
|
|
258
|
+
if (nextSub !== void 0) {
|
|
259
|
+
stack = { value: next, prev: stack };
|
|
260
|
+
next = nextSub;
|
|
261
|
+
}
|
|
262
|
+
link = subSubs;
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
if ((link = next) !== void 0) {
|
|
267
|
+
next = link.nextSubLink;
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
while (stack !== void 0) {
|
|
271
|
+
link = stack.value;
|
|
272
|
+
stack = stack.prev;
|
|
273
|
+
if (link !== void 0) {
|
|
274
|
+
next = link.nextSubLink;
|
|
275
|
+
continue top;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
break;
|
|
279
|
+
} while (true);
|
|
280
|
+
}
|
|
299
281
|
function setActiveSub(sub) {
|
|
300
282
|
const prev = activeSub;
|
|
301
283
|
activeSub = sub;
|
|
@@ -1049,7 +1031,7 @@ var SignalImpl = class {
|
|
|
1049
1031
|
if (flags & 16 /* DIRTY */ && this.shouldUpdate()) {
|
|
1050
1032
|
const subs = this.subLink;
|
|
1051
1033
|
if (subs) {
|
|
1052
|
-
|
|
1034
|
+
shallowPropagate(subs);
|
|
1053
1035
|
}
|
|
1054
1036
|
}
|
|
1055
1037
|
return this._value;
|
|
@@ -1261,6 +1243,133 @@ function isBatching() {
|
|
|
1261
1243
|
function getBatchDepth() {
|
|
1262
1244
|
return batchDepth;
|
|
1263
1245
|
}
|
|
1246
|
+
var activeEffectScope;
|
|
1247
|
+
var EffectScope = class {
|
|
1248
|
+
constructor(detached = false, parent = void 0) {
|
|
1249
|
+
this.detached = detached;
|
|
1250
|
+
this.parent = parent;
|
|
1251
|
+
this._active = true;
|
|
1252
|
+
this.effects = [];
|
|
1253
|
+
this.scopes = [];
|
|
1254
|
+
this.cleanups = [];
|
|
1255
|
+
if (!detached && activeEffectScope) {
|
|
1256
|
+
this.parent = activeEffectScope;
|
|
1257
|
+
activeEffectScope.scopes.push(this);
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
get active() {
|
|
1261
|
+
return this._active;
|
|
1262
|
+
}
|
|
1263
|
+
pause() {
|
|
1264
|
+
var _a5, _b2;
|
|
1265
|
+
if (!this._active) {
|
|
1266
|
+
return;
|
|
1267
|
+
}
|
|
1268
|
+
for (let i = 0; i < this.scopes.length; i++) {
|
|
1269
|
+
this.scopes[i].pause();
|
|
1270
|
+
}
|
|
1271
|
+
for (let i = 0; i < this.effects.length; i++) {
|
|
1272
|
+
(_b2 = (_a5 = this.effects[i]).pause) == null ? void 0 : _b2.call(_a5);
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
resume() {
|
|
1276
|
+
var _a5, _b2;
|
|
1277
|
+
if (!this._active) {
|
|
1278
|
+
return;
|
|
1279
|
+
}
|
|
1280
|
+
for (let i = 0; i < this.scopes.length; i++) {
|
|
1281
|
+
this.scopes[i].resume();
|
|
1282
|
+
}
|
|
1283
|
+
for (let i = 0; i < this.effects.length; i++) {
|
|
1284
|
+
(_b2 = (_a5 = this.effects[i]).resume) == null ? void 0 : _b2.call(_a5);
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
run(fn) {
|
|
1288
|
+
if (!this._active) {
|
|
1289
|
+
{
|
|
1290
|
+
warn("cannot run an inactive effect scope.");
|
|
1291
|
+
}
|
|
1292
|
+
return;
|
|
1293
|
+
}
|
|
1294
|
+
const prevScope = activeEffectScope;
|
|
1295
|
+
activeEffectScope = this;
|
|
1296
|
+
try {
|
|
1297
|
+
return fn();
|
|
1298
|
+
} finally {
|
|
1299
|
+
activeEffectScope = prevScope;
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
stop(fromParent = false) {
|
|
1303
|
+
if (!this._active) {
|
|
1304
|
+
return;
|
|
1305
|
+
}
|
|
1306
|
+
this._active = false;
|
|
1307
|
+
for (let i = 0; i < this.scopes.length; i++) {
|
|
1308
|
+
this.scopes[i].stop(true);
|
|
1309
|
+
}
|
|
1310
|
+
this.scopes.length = 0;
|
|
1311
|
+
const effects = this.effects.slice();
|
|
1312
|
+
this.effects.length = 0;
|
|
1313
|
+
for (const effect2 of effects) {
|
|
1314
|
+
effect2.stop();
|
|
1315
|
+
}
|
|
1316
|
+
for (let i = 0; i < this.cleanups.length; i++) {
|
|
1317
|
+
this.cleanups[i]();
|
|
1318
|
+
}
|
|
1319
|
+
this.cleanups.length = 0;
|
|
1320
|
+
if (!fromParent && this.parent) {
|
|
1321
|
+
const index = this.parent.scopes.indexOf(this);
|
|
1322
|
+
if (index >= 0) {
|
|
1323
|
+
this.parent.scopes.splice(index, 1);
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
this.parent = void 0;
|
|
1327
|
+
}
|
|
1328
|
+
_record(effect2) {
|
|
1329
|
+
this.effects.push(effect2);
|
|
1330
|
+
effect2.scope = this;
|
|
1331
|
+
}
|
|
1332
|
+
_remove(effect2) {
|
|
1333
|
+
const index = this.effects.indexOf(effect2);
|
|
1334
|
+
if (index >= 0) {
|
|
1335
|
+
this.effects.splice(index, 1);
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
_pushCleanup(fn) {
|
|
1339
|
+
this.cleanups.push(fn);
|
|
1340
|
+
}
|
|
1341
|
+
};
|
|
1342
|
+
function effectScope(detached = false) {
|
|
1343
|
+
return new EffectScope(detached);
|
|
1344
|
+
}
|
|
1345
|
+
function getCurrentScope() {
|
|
1346
|
+
return activeEffectScope;
|
|
1347
|
+
}
|
|
1348
|
+
function setCurrentScope(scope) {
|
|
1349
|
+
const prevScope = activeEffectScope;
|
|
1350
|
+
activeEffectScope = scope;
|
|
1351
|
+
return prevScope;
|
|
1352
|
+
}
|
|
1353
|
+
function onScopeDispose(fn, failSilently = false) {
|
|
1354
|
+
if (activeEffectScope) {
|
|
1355
|
+
activeEffectScope._pushCleanup(fn);
|
|
1356
|
+
} else if (!failSilently) {
|
|
1357
|
+
warn("onScopeDispose() is called when there is no active effect scope to be associated with.");
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
function recordDisposable(effect2, scope = activeEffectScope) {
|
|
1361
|
+
if (scope && scope.active) {
|
|
1362
|
+
scope._record(effect2);
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
function releaseDisposable(effect2) {
|
|
1366
|
+
const scope = effect2.scope;
|
|
1367
|
+
if (!scope) {
|
|
1368
|
+
return;
|
|
1369
|
+
}
|
|
1370
|
+
effect2.scope = void 0;
|
|
1371
|
+
scope._remove(effect2);
|
|
1372
|
+
}
|
|
1264
1373
|
|
|
1265
1374
|
// src/effect.ts
|
|
1266
1375
|
var _a2;
|
|
@@ -1290,6 +1399,7 @@ var EffectImpl = class {
|
|
|
1290
1399
|
if (options.onTrigger) this.onTrigger = options.onTrigger;
|
|
1291
1400
|
}
|
|
1292
1401
|
}
|
|
1402
|
+
recordDisposable(this);
|
|
1293
1403
|
}
|
|
1294
1404
|
/**
|
|
1295
1405
|
* Check if the Effect is active.
|
|
@@ -1453,12 +1563,10 @@ var EffectImpl = class {
|
|
|
1453
1563
|
stop() {
|
|
1454
1564
|
var _a5;
|
|
1455
1565
|
if (!this._active) {
|
|
1456
|
-
{
|
|
1457
|
-
warn("[Effect] Attempting to stop an already stopped effect.");
|
|
1458
|
-
}
|
|
1459
1566
|
return;
|
|
1460
1567
|
}
|
|
1461
1568
|
this._active = false;
|
|
1569
|
+
releaseDisposable(this);
|
|
1462
1570
|
let dep = this.depLink;
|
|
1463
1571
|
while (dep) {
|
|
1464
1572
|
dep = unlinkReactiveNode(dep, this);
|
|
@@ -1540,11 +1648,13 @@ var ComputedImpl = class {
|
|
|
1540
1648
|
// Cache
|
|
1541
1649
|
// Use symbol sentinel to distinguish "no value" from undefined/null values
|
|
1542
1650
|
this._value = NO_VALUE;
|
|
1651
|
+
this._active = true;
|
|
1543
1652
|
this.getter = getter;
|
|
1544
1653
|
this.setter = setter;
|
|
1545
1654
|
this.onTrack = onTrack;
|
|
1546
1655
|
this.onTrigger = onTrigger;
|
|
1547
1656
|
this.flag |= 16 /* DIRTY */;
|
|
1657
|
+
recordDisposable(this);
|
|
1548
1658
|
}
|
|
1549
1659
|
/**
|
|
1550
1660
|
* Returns the current value.
|
|
@@ -1552,6 +1662,9 @@ var ComputedImpl = class {
|
|
|
1552
1662
|
* @returns {T} The current value.
|
|
1553
1663
|
*/
|
|
1554
1664
|
get value() {
|
|
1665
|
+
if (!this.active) {
|
|
1666
|
+
return this._value === NO_VALUE ? this.getter() : this._value;
|
|
1667
|
+
}
|
|
1555
1668
|
if (activeSub) {
|
|
1556
1669
|
linkReactiveNode(this, activeSub);
|
|
1557
1670
|
}
|
|
@@ -1593,11 +1706,17 @@ var ComputedImpl = class {
|
|
|
1593
1706
|
* @returns {T} The current value.
|
|
1594
1707
|
*/
|
|
1595
1708
|
peek() {
|
|
1709
|
+
if (!this.active) {
|
|
1710
|
+
return this._value === NO_VALUE ? this.getter() : this._value;
|
|
1711
|
+
}
|
|
1596
1712
|
if (this._value === NO_VALUE) {
|
|
1597
1713
|
this.recompute();
|
|
1598
1714
|
}
|
|
1599
1715
|
return this._value;
|
|
1600
1716
|
}
|
|
1717
|
+
get active() {
|
|
1718
|
+
return this._active;
|
|
1719
|
+
}
|
|
1601
1720
|
/**
|
|
1602
1721
|
* Recompute the value
|
|
1603
1722
|
*
|
|
@@ -1610,6 +1729,12 @@ var ComputedImpl = class {
|
|
|
1610
1729
|
* @private
|
|
1611
1730
|
*/
|
|
1612
1731
|
recompute() {
|
|
1732
|
+
if (!this._active) {
|
|
1733
|
+
if (this._value === NO_VALUE) {
|
|
1734
|
+
this._value = this.getter();
|
|
1735
|
+
}
|
|
1736
|
+
return;
|
|
1737
|
+
}
|
|
1613
1738
|
const oldValue = this._value;
|
|
1614
1739
|
const hadValue = oldValue !== NO_VALUE;
|
|
1615
1740
|
const prevSub = startTracking(this);
|
|
@@ -1668,6 +1793,24 @@ var ComputedImpl = class {
|
|
|
1668
1793
|
}
|
|
1669
1794
|
return hasChanged(this._value, oldValue);
|
|
1670
1795
|
}
|
|
1796
|
+
stop() {
|
|
1797
|
+
if (!this._active) {
|
|
1798
|
+
return;
|
|
1799
|
+
}
|
|
1800
|
+
this._active = false;
|
|
1801
|
+
releaseDisposable(this);
|
|
1802
|
+
let dep = this.depLink;
|
|
1803
|
+
while (dep) {
|
|
1804
|
+
dep = unlinkReactiveNode(dep, this);
|
|
1805
|
+
}
|
|
1806
|
+
let sub = this.subLink;
|
|
1807
|
+
while (sub) {
|
|
1808
|
+
sub = unlinkReactiveNode(sub);
|
|
1809
|
+
}
|
|
1810
|
+
this.depLinkTail = void 0;
|
|
1811
|
+
this.subLinkTail = void 0;
|
|
1812
|
+
this.flag &= -49;
|
|
1813
|
+
}
|
|
1671
1814
|
};
|
|
1672
1815
|
function computed(getterOrOptions) {
|
|
1673
1816
|
if (isComputed(getterOrOptions)) {
|
|
@@ -2020,4 +2163,4 @@ function watch(source, callback, options = {}) {
|
|
|
2020
2163
|
};
|
|
2021
2164
|
}
|
|
2022
2165
|
|
|
2023
|
-
export { TriggerOpTypes, batch, computed, createStore, effect, endBatch, getBatchDepth, isBatching, isComputed, isEffect, isReactive, isRef, isShallow, isSignal, memoEffect, nextTick, queueJob, queuePreFlushCb, reactive, ref, shallowReactive, shallowSignal, signal, startBatch, stop, toRaw, toReactive, trigger, untrack, watch };
|
|
2166
|
+
export { EffectScope, TriggerOpTypes, batch, computed, createStore, effect, effectScope, endBatch, getBatchDepth, getCurrentScope, isBatching, isComputed, isEffect, isReactive, isRef, isShallow, isSignal, memoEffect, nextTick, onScopeDispose, queueJob, queuePreFlushCb, reactive, ref, setCurrentScope, shallowReactive, shallowSignal, signal, startBatch, stop, toRaw, toReactive, trigger, untrack, watch };
|
package/dist/signals.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {isObject,isFunction,isPlainObject,hasChanged,isArray,isSet,isMap,isWeakMap,isWeakSet,hasOwn,isStringNumber}from'@estjs/shared';var Je=Object.defineProperty;var de=Object.getOwnPropertySymbols;var ze=Object.prototype.hasOwnProperty,Qe=Object.prototype.propertyIsEnumerable;var he=(e,t,n)=>t in e?Je(e,t,{enumerable:true,configurable:true,writable:true,value:n}):e[t]=n,Te=(e,t)=>{for(var n in t||(t={}))ze.call(t,n)&&he(e,n,t[n]);if(de)for(var n of de(t))Qe.call(t,n)&&he(e,n,t[n]);return e};var T={SET:"SET",ADD:"ADD",DELETE:"DELETE",CLEAR:"CLEAR"};var P=Symbol(""),S=Symbol(""),A=Symbol(""),ge=Symbol("");var L=Symbol("");function Z(e){var t;(t=e==null?void 0:e.notify)==null||t.call(e);}function C(e){let t=e.nextSubLink,n;e:do{let r=e.subNode,i=r.flag&2,o=r.flag;if(o&60?o&12?o&4?!(o&48)&&Se(e,r)?(r.flag=o|40,i&&Z(r),o&=1):o=0:r.flag=o&-9|32:o=0:(r.flag=o|32,i&&Z(r)),o&1){let s=r.subLink;if(s!==void 0){let c=s.nextSubLink;c!==void 0&&(n={value:t,prev:n},t=c),e=s;continue}}if((e=t)!==void 0){t=e.nextSubLink;continue}for(;n!==void 0;)if(e=n.value,n=n.prev,e!==void 0){t=e.nextSubLink;continue e}break}while(true)}function Ee(e){for(;e;){let t=e.subNode,n=t.flag;(n&48)===32&&(t.flag=n|16,(n&6)===2&&Z(t)),e=e.nextSubLink;}}var M=0,_,G=false,te=class{constructor(t,n){this.map=t;this.key=n;this.isDep=true;this.flag=0;}get subLink(){return this._subLink}set subLink(t){this._subLink=t,t===void 0&&this.map.delete(this.key);}};function R(e,t){if(G)return;let n=t.depLinkTail;if(n&&n.depNode===e)return n;let r=n?n.nextDepLink:t.depLink;if(r&&r.depNode===e)return r.version=M,t.depLinkTail=r,r;let i=e.subLinkTail;if(i&&i.version===M&&i.subNode===t)return t.depLinkTail=i,i;let o={version:M,depNode:e,subNode:t,prevSubLink:i,nextSubLink:void 0,prevDepLink:n,nextDepLink:r};return r&&(r.prevDepLink=o),n?n.nextDepLink=o:t.depLink=o,i?i.nextSubLink=o:e.subLink=o,e.subLinkTail=o,t.depLinkTail=o,o}function O(e,t=e.subNode){let n=e.depNode,r=e.prevSubLink,i=e.nextSubLink,o=e.prevDepLink,s=e.nextDepLink;if(s?s.prevDepLink=o:t.depLinkTail=o,o?o.nextDepLink=s:t.depLink=s,i?i.prevSubLink=r:n.subLinkTail=r,r)r.nextSubLink=i;else if(n.subLink=i,i===void 0){let c=n.depLink;for(;c;)c=O(c,n);n.depLinkTail=void 0,n.isDep||(n.flag|=16);}return s}function K(e,t){let n,r=0,i=false;e:do{let o=false;if(t.flag&16)o=true;else {let s=e.depNode,c=s.flag;if((c&17)===17){let u=s.subLink;u&&u.nextSubLink&&ie(u),o=true;}else if((c&33)===33)if(s.depLink){n={link:e,prev:n},e=s.depLink,t=s,++r;continue e}else s.flag&=-33;else c&32&&(s.flag&=-33);}if(!o&&e.nextDepLink!==void 0){e=e.nextDepLink;continue e}for(i=o;r--;){e=n.link,n=n.prev,t=e.subNode;let s=e.depNode;if(i?s.flag=s.flag&-33|16:s.flag&=-33,s.flag&16&&(i=true),!i&&e.nextDepLink!==void 0){e=e.nextDepLink;continue e}}return i?t.flag=t.flag&-33|16:t.flag&=-33,i}while(true)}function ie(e){for(;e;){let t=e.subNode,n=t.flag;(n&48)===32&&(t.flag=n|16),e=e.nextSubLink;}}function ne(e){let t=_;return _=e,t}function U(e){return M++,e.depLinkTail=void 0,e.flag=e.flag&-57|4,ne(e)}function W(e,t){_=t;let n=e.depLinkTail,r=n?n.nextDepLink:e.depLink;for(;r;)r=O(r,e);e.flag&=-5;}function Ze(e){let t=ne(void 0),n=G;G=true;try{return e()}finally{G=n,ne(t);}}function Se(e,t){let n=t.depLinkTail;for(;n;){if(n===e)return true;n=n.prevDepLink;}return false}var re=new WeakMap,et=0;function ee(e,t,n){if(e)for(let r=e.subLink;r;r=r.nextSubLink){let i=r.subNode;i._triggerVersion!==n&&(i._triggerVersion=n,t.push(i));}}function l(e,t){if(!_||G)return;let n=re.get(e);n||(n=new Map,re.set(e,n));let r=n.get(t);r||(r=new te(n,t),n.set(t,r)),R(r,_);}function g(e,t,n,r){var c;let i=re.get(e);if(!i)return;let o=[],s=++et;if(n!==void 0)if(Array.isArray(n))for(let u of n)ee(i.get(u),o,s);else ee(i.get(n),o,s);if(t==="ADD"||t==="DELETE"||t==="CLEAR"){let u=Array.isArray(e)?L:ge;ee(i.get(u),o,s);}for(let u of o)u.flag&2?(c=u.notify)==null||c.call(u):u.flag&1&&(u.flag|=16,u.subLink&&C(u.subLink));}var me=new WeakMap;function a(e){if(!e||!isObject(e))return e;let t=e._RAW;return t?a(t):h(e)?a(e.peek()):e}var _e=st();function st(){let e={};return ["includes","indexOf","lastIndexOf"].forEach(t=>{e[t]=function(...n){let r=a(this);l(r,L);let i=r[t](...n);if((i===-1||i===false)&&n.length>0){let o=n.map(s=>a(s));i=r[t](...o);}return i};}),["find","findIndex","findLast","findLastIndex"].forEach(t=>{e[t]=function(...n){let r=a(this),i=y(this);l(r,L);let o=r[t](...n);return (t==="find"||t==="findLast")&&isObject(o)&&!i?d(o):o};}),["push","pop","shift","unshift","splice","sort","reverse","fill","copyWithin"].forEach(t=>{e[t]=function(...n){let r=a(this),i=Array.prototype[t].apply(r,n);return g(r,T.SET,[P,L]),i};}),["toReversed","toSorted","toSpliced"].forEach(t=>{e[t]=function(...n){let r=a(this),i=y(this);if(l(r,L),t==="toSpliced")for(let s=0,c=r.length;s<c;s++)l(r,`${s}`);let o=Array.prototype[t].apply(r,n);return Array.isArray(o)?o.map(s=>isObject(s)?d(s,i):s):o};}),["concat","slice","filter","map","flatMap","flat"].forEach(t=>{e[t]=function(...n){let r=a(this);return l(r,L),Array.prototype[t].apply(this,n)};}),["join","toString","toLocaleString"].forEach(t=>{e[t]=function(...n){let r=a(this);return l(r,L),Array.prototype[t].apply(r,n)};}),["values","keys","entries",Symbol.iterator].forEach(t=>{e[t]=function(){let n=a(this),r=y(this);l(n,P);let i=t===Symbol.iterator?n[Symbol.iterator]():n[t]();return {next(){let{value:o,done:s}=i.next();return s?{value:o,done:s}:Array.isArray(o)?{value:o.map(c=>isObject(c)?d(c,r):c),done:s}:{value:isObject(o)?d(o,r):o,done:s}},[Symbol.iterator](){return this}}};}),e}var ve=e=>({get:(t,n,r)=>{if(n==="_RAW")return t;if(n==="_IS_REACTIVE")return true;if(n==="_IS_SHALLOW")return e;if(hasOwn(_e,n))return _e[n];let i=Reflect.get(t,n,r);return isStringNumber(n)&&l(t,n),l(t,P),isObject(i)&&!e?d(i):i},set:(t,n,r,i)=>{let o=Reflect.get(t,n,i),s=Reflect.set(t,n,r,i);return hasChanged(r,o)&&(isStringNumber(n)?g(t,T.SET,[n,L,P]):g(t,T.SET,n)),s}}),at=ve(true),ct=ve(false),ut={get(e,t){return t==="_IS_REACTIVE"?true:t==="_RAW"?e:Reflect.get(hasOwn(ke,t)?ke:e,t,e)}},ft={get(e,t){return t==="_IS_REACTIVE"?true:t==="_RAW"?e:Reflect.get(hasOwn(ye,t)&&t in e?ye:e,t,e)}},ke={get(e){let t=a(this);l(t,S);let n=t.get(e);return isObject(n)&&!y(this)?d(n):n},set(e,t){let n=a(this),r=n.has(e),i=n.get(e),o=a(t);return n.set(e,o),(!r||hasChanged(i,o))&&g(n,T.SET,S),this},add(e){let t=a(this),n=a(e),r=t.has(n);return t.add(n),r||g(t,T.ADD,S),this},has(e){let t=a(this);l(t,S);let n=t.has(e);return !n&&isObject(e)?t.has(a(e)):n},delete(e){let t=a(this),n=t.has(e),r=t.delete(e);return !r&&isObject(e)&&(r=t.delete(a(e))),(n||r)&&g(t,T.DELETE,S),r},clear(){let e=a(this),t=e.size>0,n=e.clear();return t&&g(e,T.CLEAR,S),n},forEach(e,t){let n=a(this),r=y(this);l(n,S),n.forEach((i,o)=>{let s=r||!isObject(i)?i:d(i),c=r||!isObject(o)?o:d(o);e.call(t,s,c,this);});},[Symbol.iterator](){let e=a(this),t=y(this);l(e,S);let n=e[Symbol.iterator]();return {next(){let{value:r,done:i}=n.next();return i?{value:r,done:i}:t?{value:r,done:i}:Array.isArray(r)?{value:r.map(o=>isObject(o)?d(o):o),done:i}:{value:isObject(r)?d(r):r,done:i}},[Symbol.iterator](){return this}}},get size(){let e=a(this);return l(e,S),e.size},keys(){let e=a(this),t=y(this);l(e,S);let n=e.keys();return {next(){let{value:r,done:i}=n.next();return i?{value:r,done:i}:{value:t||!isObject(r)?r:d(r),done:i}},[Symbol.iterator](){return this}}},values(){let e=a(this),t=y(this);l(e,S);let n=e.values();return {next(){let{value:r,done:i}=n.next();return i?{value:r,done:i}:{value:t||!isObject(r)?r:d(r),done:i}},[Symbol.iterator](){return this}}},entries(){let e=a(this),t=y(this);l(e,S);let n=e.entries();return {next(){let{value:r,done:i}=n.next();return i?{value:r,done:i}:t?{value:r,done:i}:{value:r.map(o=>isObject(o)?d(o):o),done:i}},[Symbol.iterator](){return this}}}},ye={get(e){let t=a(this);l(t,A);let n=t.get(e);return n===void 0&&v(e)&&(n=t.get(a(e))),isObject(n)&&!y(this)?d(n):n},set(e,t){let n=a(this),r=a(e),i=n.has(r),o=n.get(r),s=a(t);return n.set(r,s),(!i||hasChanged(o,s))&&g(n,T.SET,A),this},add(e){let t=a(this),n=a(e),r=t.has(n);return t.add(n),r||g(t,T.ADD,A),this},has(e){let t=a(this);l(t,A);let n=t.has(e);return !n&&v(e)&&(n=t.has(a(e))),n},delete(e){let t=a(this),n=a(e),r=t.has(n),i=t.delete(n);return (r||i)&&g(t,T.DELETE,A),i}},Le=e=>({get(t,n,r){if(n==="_RAW")return t;if(n==="_IS_REACTIVE")return true;if(n==="_IS_SHALLOW")return e;let i=Reflect.get(t,n,r),o=h(i)?i.value:i;return l(t,n),isObject(o)&&!e?d(o):o},set:(t,n,r,i)=>{let o=Reflect.get(t,n,i),s=Reflect.set(t,n,a(r),i);return hasChanged(r,o)&&g(t,T.SET,n),s},deleteProperty:(t,n)=>{let r=hasOwn(t,n),i=Reflect.deleteProperty(t,n);return r&&i&&g(t,T.DELETE,n),i}}),lt=Le(true),pt=Le(false);function d(e,t=false){if(!isObject(e)||v(e))return e;let n=me.get(e);if(n)return n;let r;isArray(e)?r=t?at:ct:isSet(e)||isMap(e)?r=ut:isWeakMap(e)||isWeakSet(e)?r=ft:r=t?lt:pt;let i=new Proxy(e,r);return me.set(e,i),i}function v(e){return !!(e&&e._IS_REACTIVE)}function D(e){return v(e)||h(e)?e:d(e)}function q(e){return v(e)||h(e)?e:d(e,true)}function y(e){return !!(e&&e._IS_SHALLOW)}var dt=e=>isObject(e)?D(e):e;var De;De="_IS_SIGNAL";var N=class{constructor(t,n=false){this.flag=1;this[De]=true;let r=a(t);this._rawValue=r,this._IS_SHALLOW=n,Re(r)?v(t)?this._value=t:this._value=n?q(r):D(r):this._value=r;}get dep(){return this}get value(){let t=_;if(t&&R(this,t),this.flag&16&&this.shouldUpdate()){let r=this.subLink;r&&ie(r);}return this._value}set value(t){h(t)&&(t=t.peek());let n=t,r=a(t);if(!hasChanged(this._rawValue,r))return;if(this._oldValue=this._rawValue,this._rawValue=r,this.flag|=16,!Re(r))this._value=r;else if(v(n))this._value=n;else {let o=this._IS_SHALLOW;this._value=o?q(r):D(r);}let i=this.subLink;i&&C(i);}shouldUpdate(){if(this.flag&=-17,!("_oldValue"in this))return true;let t=hasChanged(this._oldValue,this._rawValue);return this._oldValue=this._rawValue,t}peek(){return this._value}set(t){this.value=t;}update(t){let n=t(this.peek());h(n)?this.value=n.peek():this.value=n;}};function Re(e){return isObject(e)?isArray(e)||isMap(e)||isSet(e)||isWeakMap(e)||isWeakSet(e)||isPlainObject(e):false}function _t(e){return h(e)?e:new N(e)}function kt(e){return h(e)&&(e=e.peek()),new N(e,true)}function h(e){return !!e&&!!e._IS_SIGNAL}var B=new Set,oe=new Set,xe=Promise.resolve(),se=false;function Ie(e){return e?xe.then(e):xe}function x(e){B.add(e),Ae();}function Ae(){se||(se=true,Ie(ae));}function Ce(e){oe.add(e),Ae();}function ae(){for(se=false,yt();B.size>0;){for(let e of B)try{e();}catch(t){}B.clear();}}function yt(){let e=Array.from(oe);oe.clear();for(let t of e)try{t();}catch(n){}}function Ne(e,t){switch(t){case "sync":return ()=>e();case "pre":return ()=>Ce(e);case "post":return ()=>x(e);default:return ()=>x(e)}}var Y=0;function $(e){Ve();try{return e()}finally{Pe();}}function Ve(){Y++;}function Pe(){Y--,Y===0&&ae();}function ce(){return Y>0}function vt(){return Y}var Oe;Oe="_IS_EFFECT";var ue=class{constructor(t,n){this.flag=18;this[Oe]=true;this._active=true;if(this.fn=t,n){this.options=n;let r=n.flush||n.scheduler;r&&!isFunction(r)&&(this._flushScheduler=Ne(()=>this.run(),r));}}get active(){return this._active}get dirty(){let t=this.flag;if(t&16)return true;if(t&32){if(this.depLink&&K(this.depLink,this))return this.flag=t&-33|16,true;this.flag=t&-33;}return false}pause(){this.flag|=256;}resume(){let n=this.flag&-257;this.flag=n;let r=(n&16)!==0,i=(n&32)!==0;(r||i)&&this.notify();}run(){if(!this._active)return this.fn();let t=this.flag;this.flag=t&-49|512;let n=U(this);try{return this.fn()}catch(r){throw this.flag|=16,r}finally{this.flag&=-513,W(this,n);}}getJob(){return this._job||(this._job=()=>this.run()),this._job}notify(){var i,o,s;let t=this.flag;if(!this._active||t&784)return;this.flag=t|16;let n=((i=this.options)==null?void 0:i.flush)||((o=this.options)==null?void 0:o.scheduler);n?isFunction(n)?n(this):(s=this._flushScheduler)==null||s.call(this):ce()?x(this.getJob()):this.run();}stop(){var r;if(!this._active)return;this._active=false;let t=this.depLink;for(;t;)t=O(t,this);let n=this.subLink;for(;n;)n=O(n);this._job=void 0,this._flushScheduler=void 0,this.depLinkTail=void 0,this.subLinkTail=void 0,(r=this.options)!=null&&r.onStop&&this.options.onStop();}};function J(e,t){let n=new ue(e,t);try{n.run();}catch(i){throw n.stop(),i}let r=()=>n.run();return r.effect=n,r.stop=()=>n.stop(),r}function Lt(e){e.effect.stop();}function wt(e){return !!(e&&e._IS_EFFECT)}function Rt(e,t,n){let r=t;return J(()=>{r=e(r);},n)}var V=Symbol("computed-no-value"),Me;Me="_IS_COMPUTED";var z=class{constructor(t,n,r,i){this.flag=17;this[Me]=true;this._value=V;this.getter=t,this.setter=n,this.onTrack=r,this.onTrigger=i,this.flag|=16;}get value(){_&&R(this,_);let t=this.flag,n=this._value!==V;return n&&!(t&48)?this._value:!n||t&16?(this.recompute(),this._value):(t&32&&(this.depLink&&K(this.depLink,this)?this.recompute():this.flag=t&-33),this._value)}set value(t){this.setter&&this.setter(t);}peek(){return this._value===V&&this.recompute(),this._value}recompute(){let t=this._value,n=t!==V,r=U(this);try{let i=this.getter(),o=this.flag,s=this.subLink,c=-49;!n||hasChanged(t,i)?(this._value=i,this.flag=o&c,s&&Ee(s)):this.flag=o&c;}catch(i){let o=-49;throw this.flag&=o,this._value=V,i}finally{W(this,r);}}shouldUpdate(){let t=this._value!==V,n=this._value;return this.recompute(),t?hasChanged(this._value,n):true}};function fe(e){if(j(e))return e;if(!e)throw new Error("[Computed] Invalid argument: computed() requires a getter function or options object.");if(isFunction(e))return new z(e);if(isPlainObject(e)){let{get:t,set:n,onTrack:r,onTrigger:i}=e;if(!t)throw new Error(`[Computed] Invalid options: getter function is required.
|
|
1
|
+
import {isObject,isFunction,isPlainObject,hasChanged,isArray,isSet,isMap,isWeakMap,isWeakSet,hasOwn,isStringNumber}from'@estjs/shared';var Qe=Object.defineProperty;var Ee=Object.getOwnPropertySymbols;var Xe=Object.prototype.hasOwnProperty,Ze=Object.prototype.propertyIsEnumerable;var ge=(e,t,n)=>t in e?Qe(e,t,{enumerable:true,configurable:true,writable:true,value:n}):e[t]=n,ve=(e,t)=>{for(var n in t||(t={}))Xe.call(t,n)&&ge(e,n,t[n]);if(Ee)for(var n of Ee(t))Ze.call(t,n)&&ge(e,n,t[n]);return e};var T={SET:"SET",ADD:"ADD",DELETE:"DELETE",CLEAR:"CLEAR"};var G=Symbol(""),g=Symbol(""),V=Symbol(""),_e=Symbol("");var w=Symbol("");var U=0,b,O=false,oe=class{constructor(t,n){this.map=t;this.key=n;this.isDep=true;this.flag=0;}get subLink(){return this._subLink}set subLink(t){this._subLink=t,t===void 0&&this.map.delete(this.key);}};function se(e){var t;(t=e==null?void 0:e.notify)==null||t.call(e);}function I(e,t){if(O)return;let n=t.depLinkTail;if(n&&n.depNode===e)return n;let i=n?n.nextDepLink:t.depLink;if(i&&i.depNode===e)return i.version=U,t.depLinkTail=i,i;let r=e.subLinkTail;if(r&&r.version===U&&r.subNode===t)return t.depLinkTail=r,r;let o={version:U,depNode:e,subNode:t,prevSubLink:r,nextSubLink:void 0,prevDepLink:n,nextDepLink:i};return i&&(i.prevDepLink=o),n?n.nextDepLink=o:t.depLink=o,r?r.nextSubLink=o:e.subLink=o,e.subLinkTail=o,t.depLinkTail=o,o}function R(e,t=e.subNode){let n=e.depNode,i=e.prevSubLink,r=e.nextSubLink,o=e.prevDepLink,s=e.nextDepLink;if(s?s.prevDepLink=o:t.depLinkTail=o,o?o.nextDepLink=s:t.depLink=s,r?r.prevSubLink=i:n.subLinkTail=i,i)i.nextSubLink=r;else if(n.subLink=r,r===void 0){let c=n.depLink;for(;c;)c=R(c,n);n.depLinkTail=void 0,n.isDep||(n.flag|=16);}return s}function W(e,t){let n,i=0,r=false;e:do{let o=false;if(t.flag&16)o=true;else {let s=e.depNode,c=s.flag;if((c&17)===17){let u=s.subLink;u&&u.nextSubLink&&j(u),o=true;}else if((c&33)===33)if(s.depLink){n={link:e,prev:n},e=s.depLink,t=s,++i;continue e}else s.flag&=-33;else c&32&&(s.flag&=-33);}if(!o&&e.nextDepLink!==void 0){e=e.nextDepLink;continue e}for(r=o;i--;){e=n.link,n=n.prev,t=e.subNode;let s=e.depNode;if(r?s.flag=s.flag&-33|16:s.flag&=-33,s.flag&16&&(r=true),!r&&e.nextDepLink!==void 0){e=e.nextDepLink;continue e}}return r?t.flag=t.flag&-33|16:t.flag&=-33,r}while(true)}function j(e){for(;e;){let t=e.subNode,n=t.flag;(n&48)===32&&(t.flag=n|16,(n&6)===2&&se(t)),e=e.nextSubLink;}}function Y(e){let t=e.nextSubLink,n;e:do{let i=e.subNode,r=i.flag&2,o=i.flag;if(o&60?o&12?o&4?!(o&48)&&nt(e,i)?(i.flag=o|40,r&&se(i),o&=1):o=0:i.flag=o&-9|32:o=0:(i.flag=o|32,r&&se(i)),o&1){let s=i.subLink;if(s!==void 0){let c=s.nextSubLink;c!==void 0&&(n={value:t,prev:n},t=c),e=s;continue}}if((e=t)!==void 0){t=e.nextSubLink;continue}for(;n!==void 0;)if(e=n.value,n=n.prev,e!==void 0){t=e.nextSubLink;continue e}break}while(true)}function ae(e){let t=b;return b=e,t}function F(e){return U++,e.depLinkTail=void 0,e.flag=e.flag&-57|4,ae(e)}function H(e,t){b=t;let n=e.depLinkTail,i=n?n.nextDepLink:e.depLink;for(;i;)i=R(i,e);e.flag&=-5;}function tt(e){let t=ae(void 0),n=O;O=true;try{return e()}finally{O=n,ae(t);}}function nt(e,t){let n=t.depLinkTail;for(;n;){if(n===e)return true;n=n.prevDepLink;}return false}var ce=new WeakMap,it=0;function re(e,t,n){if(e)for(let i=e.subLink;i;i=i.nextSubLink){let r=i.subNode;r._triggerVersion!==n&&(r._triggerVersion=n,t.push(r));}}function l(e,t){if(!b||O)return;let n=ce.get(e);n||(n=new Map,ce.set(e,n));let i=n.get(t);i||(i=new oe(n,t),n.set(t,i)),I(i,b);}function S(e,t,n,i){var c;let r=ce.get(e);if(!r)return;let o=[],s=++it;if(n!==void 0)if(Array.isArray(n))for(let u of n)re(r.get(u),o,s);else re(r.get(n),o,s);if(t==="ADD"||t==="DELETE"||t==="CLEAR"){let u=Array.isArray(e)?w:_e;re(r.get(u),o,s);}for(let u of o)u.flag&2?(c=u.notify)==null||c.call(u):u.flag&1&&(u.flag|=16,u.subLink&&Y(u.subLink));}var me=new WeakMap;function a(e){if(!e||!isObject(e))return e;let t=e._RAW;return t?a(t):h(e)?a(e.peek()):e}var ye=ut();function ut(){let e={};return ["includes","indexOf","lastIndexOf"].forEach(t=>{e[t]=function(...n){let i=a(this);l(i,w);let r=i[t](...n);if((r===-1||r===false)&&n.length>0){let o=n.map(s=>a(s));r=i[t](...o);}return r};}),["find","findIndex","findLast","findLastIndex"].forEach(t=>{e[t]=function(...n){let i=a(this),r=k(this);l(i,w);let o=i[t](...n);return (t==="find"||t==="findLast")&&isObject(o)&&!r?d(o):o};}),["push","pop","shift","unshift","splice","sort","reverse","fill","copyWithin"].forEach(t=>{e[t]=function(...n){let i=a(this),r=Array.prototype[t].apply(i,n);return S(i,T.SET,[G,w]),r};}),["toReversed","toSorted","toSpliced"].forEach(t=>{e[t]=function(...n){let i=a(this),r=k(this);if(l(i,w),t==="toSpliced")for(let s=0,c=i.length;s<c;s++)l(i,`${s}`);let o=Array.prototype[t].apply(i,n);return Array.isArray(o)?o.map(s=>isObject(s)?d(s,r):s):o};}),["concat","slice","filter","map","flatMap","flat"].forEach(t=>{e[t]=function(...n){let i=a(this);return l(i,w),Array.prototype[t].apply(this,n)};}),["join","toString","toLocaleString"].forEach(t=>{e[t]=function(...n){let i=a(this);return l(i,w),Array.prototype[t].apply(i,n)};}),["values","keys","entries",Symbol.iterator].forEach(t=>{e[t]=function(){let n=a(this),i=k(this);l(n,G);let r=t===Symbol.iterator?n[Symbol.iterator]():n[t]();return {next(){let{value:o,done:s}=r.next();return s?{value:o,done:s}:Array.isArray(o)?{value:o.map(c=>isObject(c)?d(c,i):c),done:s}:{value:isObject(o)?d(o,i):o,done:s}},[Symbol.iterator](){return this}}};}),e}var we=e=>({get:(t,n,i)=>{if(n==="_RAW")return t;if(n==="_IS_REACTIVE")return true;if(n==="_IS_SHALLOW")return e;if(hasOwn(ye,n))return ye[n];let r=Reflect.get(t,n,i);return isStringNumber(n)&&l(t,n),l(t,G),isObject(r)&&!e?d(r):r},set:(t,n,i,r)=>{let o=Reflect.get(t,n,r),s=Reflect.set(t,n,i,r);return hasChanged(i,o)&&(isStringNumber(n)?S(t,T.SET,[n,w,G]):S(t,T.SET,n)),s}}),ft=we(true),lt=we(false),pt={get(e,t){return t==="_IS_REACTIVE"?true:t==="_RAW"?e:Reflect.get(hasOwn(ke,t)?ke:e,t,e)}},dt={get(e,t){return t==="_IS_REACTIVE"?true:t==="_RAW"?e:Reflect.get(hasOwn(Le,t)&&t in e?Le:e,t,e)}},ke={get(e){let t=a(this);l(t,g);let n=t.get(e);return isObject(n)&&!k(this)?d(n):n},set(e,t){let n=a(this),i=n.has(e),r=n.get(e),o=a(t);return n.set(e,o),(!i||hasChanged(r,o))&&S(n,T.SET,g),this},add(e){let t=a(this),n=a(e),i=t.has(n);return t.add(n),i||S(t,T.ADD,g),this},has(e){let t=a(this);l(t,g);let n=t.has(e);return !n&&isObject(e)?t.has(a(e)):n},delete(e){let t=a(this),n=t.has(e),i=t.delete(e);return !i&&isObject(e)&&(i=t.delete(a(e))),(n||i)&&S(t,T.DELETE,g),i},clear(){let e=a(this),t=e.size>0,n=e.clear();return t&&S(e,T.CLEAR,g),n},forEach(e,t){let n=a(this),i=k(this);l(n,g),n.forEach((r,o)=>{let s=i||!isObject(r)?r:d(r),c=i||!isObject(o)?o:d(o);e.call(t,s,c,this);});},[Symbol.iterator](){let e=a(this),t=k(this);l(e,g);let n=e[Symbol.iterator]();return {next(){let{value:i,done:r}=n.next();return r?{value:i,done:r}:t?{value:i,done:r}:Array.isArray(i)?{value:i.map(o=>isObject(o)?d(o):o),done:r}:{value:isObject(i)?d(i):i,done:r}},[Symbol.iterator](){return this}}},get size(){let e=a(this);return l(e,g),e.size},keys(){let e=a(this),t=k(this);l(e,g);let n=e.keys();return {next(){let{value:i,done:r}=n.next();return r?{value:i,done:r}:{value:t||!isObject(i)?i:d(i),done:r}},[Symbol.iterator](){return this}}},values(){let e=a(this),t=k(this);l(e,g);let n=e.values();return {next(){let{value:i,done:r}=n.next();return r?{value:i,done:r}:{value:t||!isObject(i)?i:d(i),done:r}},[Symbol.iterator](){return this}}},entries(){let e=a(this),t=k(this);l(e,g);let n=e.entries();return {next(){let{value:i,done:r}=n.next();return r?{value:i,done:r}:t?{value:i,done:r}:{value:i.map(o=>isObject(o)?d(o):o),done:r}},[Symbol.iterator](){return this}}}},Le={get(e){let t=a(this);l(t,V);let n=t.get(e);return n===void 0&&L(e)&&(n=t.get(a(e))),isObject(n)&&!k(this)?d(n):n},set(e,t){let n=a(this),i=a(e),r=n.has(i),o=n.get(i),s=a(t);return n.set(i,s),(!r||hasChanged(o,s))&&S(n,T.SET,V),this},add(e){let t=a(this),n=a(e),i=t.has(n);return t.add(n),i||S(t,T.ADD,V),this},has(e){let t=a(this);l(t,V);let n=t.has(e);return !n&&L(e)&&(n=t.has(a(e))),n},delete(e){let t=a(this),n=a(e),i=t.has(n),r=t.delete(n);return (i||r)&&S(t,T.DELETE,V),r}},xe=e=>({get(t,n,i){if(n==="_RAW")return t;if(n==="_IS_REACTIVE")return true;if(n==="_IS_SHALLOW")return e;let r=Reflect.get(t,n,i),o=h(r)?r.value:r;return l(t,n),isObject(o)&&!e?d(o):o},set:(t,n,i,r)=>{let o=Reflect.get(t,n,r),s=Reflect.set(t,n,a(i),r);return hasChanged(i,o)&&S(t,T.SET,n),s},deleteProperty:(t,n)=>{let i=hasOwn(t,n),r=Reflect.deleteProperty(t,n);return i&&r&&S(t,T.DELETE,n),r}}),ht=xe(true),Tt=xe(false);function d(e,t=false){if(!isObject(e)||L(e))return e;let n=me.get(e);if(n)return n;let i;isArray(e)?i=t?ft:lt:isSet(e)||isMap(e)?i=pt:isWeakMap(e)||isWeakSet(e)?i=dt:i=t?ht:Tt;let r=new Proxy(e,i);return me.set(e,r),r}function L(e){return !!(e&&e._IS_REACTIVE)}function C(e){return L(e)||h(e)?e:d(e)}function $(e){return L(e)||h(e)?e:d(e,true)}function k(e){return !!(e&&e._IS_SHALLOW)}var St=e=>isObject(e)?C(e):e;var Ie;Ie="_IS_SIGNAL";var P=class{constructor(t,n=false){this.flag=1;this[Ie]=true;let i=a(t);this._rawValue=i,this._IS_SHALLOW=n,De(i)?L(t)?this._value=t:this._value=n?$(i):C(i):this._value=i;}get dep(){return this}get value(){let t=b;if(t&&I(this,t),this.flag&16&&this.shouldUpdate()){let i=this.subLink;i&&j(i);}return this._value}set value(t){h(t)&&(t=t.peek());let n=t,i=a(t);if(!hasChanged(this._rawValue,i))return;if(this._oldValue=this._rawValue,this._rawValue=i,this.flag|=16,!De(i))this._value=i;else if(L(n))this._value=n;else {let o=this._IS_SHALLOW;this._value=o?$(i):C(i);}let r=this.subLink;r&&Y(r);}shouldUpdate(){if(this.flag&=-17,!("_oldValue"in this))return true;let t=hasChanged(this._oldValue,this._rawValue);return this._oldValue=this._rawValue,t}peek(){return this._value}set(t){this.value=t;}update(t){let n=t(this.peek());h(n)?this.value=n.peek():this.value=n;}};function De(e){return isObject(e)?isArray(e)||isMap(e)||isSet(e)||isWeakMap(e)||isWeakSet(e)||isPlainObject(e):false}function kt(e){return h(e)?e:new P(e)}function Lt(e){return h(e)&&(e=e.peek()),new P(e,true)}function h(e){return !!e&&!!e._IS_SIGNAL}var J=new Set,ue=new Set,Ce=Promise.resolve(),fe=false;function Ae(e){return e?Ce.then(e):Ce}function A(e){J.add(e),Ne();}function Ne(){fe||(fe=true,Ae(le));}function Ve(e){ue.add(e),Ne();}function le(){for(fe=false,wt();J.size>0;){for(let e of J)try{e();}catch(t){}J.clear();}}function wt(){let e=Array.from(ue);ue.clear();for(let t of e)try{t();}catch(n){}}function Pe(e,t){switch(t){case "sync":return ()=>e();case "pre":return ()=>Ve(e);case "post":return ()=>A(e);default:return ()=>A(e)}}var M=0;function z(e){Ge();try{return e()}finally{Oe();}}function Ge(){M++;}function Oe(){M--,M===0&&le();}function pe(){return M>0}function xt(){return M}var m,Q=class{constructor(t=false,n=void 0){this.detached=t;this.parent=n;this._active=true;this.effects=[];this.scopes=[];this.cleanups=[];!t&&m&&(this.parent=m,m.scopes.push(this));}get active(){return this._active}pause(){var t,n;if(this._active){for(let i=0;i<this.scopes.length;i++)this.scopes[i].pause();for(let i=0;i<this.effects.length;i++)(n=(t=this.effects[i]).pause)==null||n.call(t);}}resume(){var t,n;if(this._active){for(let i=0;i<this.scopes.length;i++)this.scopes[i].resume();for(let i=0;i<this.effects.length;i++)(n=(t=this.effects[i]).resume)==null||n.call(t);}}run(t){if(!this._active)return;let n=m;m=this;try{return t()}finally{m=n;}}stop(t=false){if(!this._active)return;this._active=false;for(let i=0;i<this.scopes.length;i++)this.scopes[i].stop(true);this.scopes.length=0;let n=this.effects.slice();this.effects.length=0;for(let i of n)i.stop();for(let i=0;i<this.cleanups.length;i++)this.cleanups[i]();if(this.cleanups.length=0,!t&&this.parent){let i=this.parent.scopes.indexOf(this);i>=0&&this.parent.scopes.splice(i,1);}this.parent=void 0;}_record(t){this.effects.push(t),t.scope=this;}_remove(t){let n=this.effects.indexOf(t);n>=0&&this.effects.splice(n,1);}_pushCleanup(t){this.cleanups.push(t);}};function Rt(e=false){return new Q(e)}function Dt(){return m}function It(e){let t=m;return m=e,t}function Ct(e,t=false){m&&m._pushCleanup(e);}function X(e,t=m){t&&t.active&&t._record(e);}function Z(e){let t=e.scope;t&&(e.scope=void 0,t._remove(e));}var Ye;Ye="_IS_EFFECT";var de=class{constructor(t,n){this.flag=18;this[Ye]=true;this._active=true;if(this.fn=t,n){this.options=n;let i=n.flush||n.scheduler;i&&!isFunction(i)&&(this._flushScheduler=Pe(()=>this.run(),i));}X(this);}get active(){return this._active}get dirty(){let t=this.flag;if(t&16)return true;if(t&32){if(this.depLink&&W(this.depLink,this))return this.flag=t&-33|16,true;this.flag=t&-33;}return false}pause(){this.flag|=256;}resume(){let n=this.flag&-257;this.flag=n;let i=(n&16)!==0,r=(n&32)!==0;(i||r)&&this.notify();}run(){if(!this._active)return this.fn();let t=this.flag;this.flag=t&-49|512;let n=F(this);try{return this.fn()}catch(i){throw this.flag|=16,i}finally{this.flag&=-513,H(this,n);}}getJob(){return this._job||(this._job=()=>this.run()),this._job}notify(){var r,o,s;let t=this.flag;if(!this._active||t&784)return;this.flag=t|16;let n=((r=this.options)==null?void 0:r.flush)||((o=this.options)==null?void 0:o.scheduler);n?isFunction(n)?n(this):(s=this._flushScheduler)==null||s.call(this):pe()?A(this.getJob()):this.run();}stop(){var i;if(!this._active)return;this._active=false,Z(this);let t=this.depLink;for(;t;)t=R(t,this);let n=this.subLink;for(;n;)n=R(n);this._job=void 0,this._flushScheduler=void 0,this.depLinkTail=void 0,this.subLinkTail=void 0,(i=this.options)!=null&&i.onStop&&this.options.onStop();}};function ee(e,t){let n=new de(e,t);try{n.run();}catch(r){throw n.stop(),r}let i=()=>n.run();return i.effect=n,i.stop=()=>n.stop(),i}function At(e){e.effect.stop();}function Nt(e){return !!(e&&e._IS_EFFECT)}function Vt(e,t,n){let i=t;return ee(()=>{i=e(i);},n)}var x=Symbol("computed-no-value"),Ue;Ue="_IS_COMPUTED";var te=class{constructor(t,n,i,r){this.flag=17;this[Ue]=true;this._value=x;this._active=true;this.getter=t,this.setter=n,this.onTrack=i,this.onTrigger=r,this.flag|=16,X(this);}get value(){if(!this.active)return this._value===x?this.getter():this._value;b&&I(this,b);let t=this.flag,n=this._value!==x;return n&&!(t&48)?this._value:!n||t&16?(this.recompute(),this._value):(t&32&&(this.depLink&&W(this.depLink,this)?this.recompute():this.flag=t&-33),this._value)}set value(t){this.setter&&this.setter(t);}peek(){return this.active?(this._value===x&&this.recompute(),this._value):this._value===x?this.getter():this._value}get active(){return this._active}recompute(){if(!this._active){this._value===x&&(this._value=this.getter());return}let t=this._value,n=t!==x,i=F(this);try{let r=this.getter(),o=this.flag,s=this.subLink,c=-49;!n||hasChanged(t,r)?(this._value=r,this.flag=o&c,s&&j(s)):this.flag=o&c;}catch(r){let o=-49;throw this.flag&=o,this._value=x,r}finally{H(this,i);}}shouldUpdate(){let t=this._value!==x,n=this._value;return this.recompute(),t?hasChanged(this._value,n):true}stop(){if(!this._active)return;this._active=false,Z(this);let t=this.depLink;for(;t;)t=R(t,this);let n=this.subLink;for(;n;)n=R(n);this.depLinkTail=void 0,this.subLinkTail=void 0,this.flag&=-49;}};function he(e){if(K(e))return e;if(!e)throw new Error("[Computed] Invalid argument: computed() requires a getter function or options object.");if(isFunction(e))return new te(e);if(isPlainObject(e)){let{get:t,set:n,onTrack:i,onTrigger:r}=e;if(!t)throw new Error(`[Computed] Invalid options: getter function is required.
|
|
2
2
|
Usage: computed({ get: () => value, set: (v) => { ... } })`);if(!isFunction(t))throw new TypeError(`[Computed] Invalid options: getter must be a function.
|
|
3
|
-
Received: ${typeof t}`);return new
|
|
4
|
-
Received: ${typeof e}`)}function
|
|
3
|
+
Received: ${typeof t}`);return new te(t,n,i,r)}throw new Error(`[Computed] Invalid argument: expected a function or options object.
|
|
4
|
+
Received: ${typeof e}`)}function K(e){return !!e&&!!e._IS_COMPUTED}function Gt(e){let{state:t,getters:n,actions:i}=e,r=ve({},t),o=C(t),s=new Set,c=new Set,u=f=>{s.forEach(y=>y(f)),c.forEach(y=>y(f));},D={patch$(f){z(()=>{Object.assign(o,f);}),u(o);},subscribe$(f){s.add(f);},unsubscribe$(f){s.delete(f);},onAction$(f){c.add(f);},offAction$(f){c.delete(f);},reset$(){z(()=>{Object.assign(o,r);}),u(o);}},E={};for(let f of Object.keys(r))Object.defineProperty(E,f,{get:()=>o[f],set:y=>{o[f]=y;},enumerable:true,configurable:true});if(Object.defineProperty(E,"state",{value:o,enumerable:true,configurable:true,writable:true}),Object.assign(E,D),n)for(let f in n){let y=n[f];if(!y)continue;let ie=he(()=>y.call(E,o));Object.defineProperty(E,f,{get:()=>ie.value,enumerable:true,configurable:true});}if(i)for(let f in i){let y=i[f];y&&(E[f]=(...ie)=>{let Je=y.apply(E,ie);return c.forEach(ze=>ze(o)),Je});}return E}function Ot(e){let t=new e,n=Object.create(null),i={},r={};return Object.getOwnPropertyNames(t).forEach(o=>{n[o]=t[o];}),Object.getOwnPropertyNames(e.prototype).forEach(o=>{let s=Object.getOwnPropertyDescriptor(e.prototype,o);s&&(isFunction(s.get)?i[o]=function(){return s.get.call(this)}:isFunction(s.value)&&o!=="constructor"&&(r[o]=function(...c){return s.value.apply(this,c)}));}),{state:n,getters:i,actions:r}}function jt(e){return ()=>{let t;return isFunction(e)?t=Ot(e):t=e,Gt(t)}}var We,Fe,ne=class extends(Fe=P,We="_IS_REF",Fe){constructor(n){super(n,true);this[We]=true;}get value(){let n=b;return n&&I(this,n),this._value}set value(n){h(n)&&(n=n.peek()),Se(n)&&(n=n.value),hasChanged(this._value,n)&&(this._rawValue=n,this._value=n,this.flag|=16,this.subLink&&Y(this.subLink));}};function Mt(e=void 0){return Se(e)?e:h(e)?new ne(e.peek()):new ne(e)}function Se(e){return !!e&&!!e._IS_REF}var He={},qe=new Set;function N(e,t){if(t||(qe.clear(),t=qe),!isObject(e)||t.has(e))return e;if(t.add(e),h(e)||K(e))return N(e.value,t);if(Array.isArray(e))for(let n of e)N(n,t);else isMap(e)?(e.forEach(n=>{N(n,t);}),e.keys(),e.values()):isSet(e)?(e.forEach(n=>{N(n,t);}),e.values()):Object.keys(e).forEach(n=>{N(e[n],t);});return e}function Be(e){return isFunction(e)?e:h(e)||K(e)?()=>e.value:L(e)?()=>N(e):()=>e}function Ht(e){if(Array.isArray(e)){let t=e.map(n=>Be(n));return ()=>t.map(n=>n())}return Be(e)}function qt(e,t,n={}){let{immediate:i=false,deep:r=false}=n,o=He,s=Ht(e),c=()=>{let D=u.effect;if(!D.run)return;let E=D.run();(r||isObject(E)||hasChanged(E,o))&&(t(E,o===He?void 0:o),o=E);},u=ee(()=>{let D=s();return r&&N(D),D},{scheduler:()=>A(c)});return i?c():o=u.effect.run(),()=>{u.stop();}}export{Q as EffectScope,T as TriggerOpTypes,z as batch,he as computed,jt as createStore,ee as effect,Rt as effectScope,Oe as endBatch,xt as getBatchDepth,Dt as getCurrentScope,pe as isBatching,K as isComputed,Nt as isEffect,L as isReactive,Se as isRef,k as isShallow,h as isSignal,Vt as memoEffect,Ae as nextTick,Ct as onScopeDispose,A as queueJob,Ve as queuePreFlushCb,C as reactive,Mt as ref,It as setCurrentScope,$ as shallowReactive,Lt as shallowSignal,kt as signal,Ge as startBatch,At as stop,a as toRaw,St as toReactive,S as trigger,tt as untrack,qt as watch};//# sourceMappingURL=signals.esm.js.map
|
|
5
5
|
//# sourceMappingURL=signals.esm.js.map
|