@estjs/signals 0.0.15-beta.9 → 0.0.15
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 +20 -18
- package/dist/signals.d.ts +20 -18
- package/dist/signals.dev.cjs.js +193 -203
- package/dist/signals.dev.esm.js +194 -204
- package/dist/signals.esm.js +3 -3
- package/dist/signals.esm.js.map +1 -1
- package/package.json +2 -2
package/dist/signals.dev.cjs.js
CHANGED
|
@@ -29,58 +29,62 @@ var TriggerOpTypes = {
|
|
|
29
29
|
DELETE: "DELETE",
|
|
30
30
|
CLEAR: "CLEAR"
|
|
31
31
|
};
|
|
32
|
-
var SIGNAL_KEY = /* @__PURE__ */ Symbol("Signal_Key" );
|
|
33
32
|
var ARRAY_KEY = /* @__PURE__ */ Symbol("Array_Key" );
|
|
34
33
|
var COLLECTION_KEY = /* @__PURE__ */ Symbol("Collection_Key" );
|
|
35
34
|
var WEAK_COLLECTION_KEY = /* @__PURE__ */ Symbol("WeakCollection_Key" );
|
|
35
|
+
var ITERATE_KEY = /* @__PURE__ */ Symbol("Iterate_Key" );
|
|
36
36
|
var ARRAY_ITERATE_KEY = /* @__PURE__ */ Symbol("Array_Iterate_Key" );
|
|
37
37
|
|
|
38
38
|
// src/propagation.ts
|
|
39
|
+
function enqueueEffect(effect2) {
|
|
40
|
+
var _a5;
|
|
41
|
+
(_a5 = effect2 == null ? void 0 : effect2.notify) == null ? void 0 : _a5.call(effect2);
|
|
42
|
+
}
|
|
39
43
|
function propagate(link) {
|
|
40
44
|
let next = link.nextSubLink;
|
|
41
45
|
let stack;
|
|
42
46
|
top: do {
|
|
43
47
|
const sub = link.subNode;
|
|
44
|
-
const queueBit = sub.flag & 64 /* QUEUED */;
|
|
45
48
|
const watcherBit = sub.flag & 2 /* WATCHING */;
|
|
46
|
-
let flags = sub.flag
|
|
49
|
+
let flags = sub.flag;
|
|
47
50
|
if (!(flags & (16 /* DIRTY */ | 32 /* PENDING */ | 8 /* RECURSED */ | 4 /* RECURSED_CHECK */))) {
|
|
48
|
-
sub.flag =
|
|
49
|
-
|
|
51
|
+
sub.flag = flags | 32 /* PENDING */;
|
|
52
|
+
if (watcherBit) {
|
|
53
|
+
enqueueEffect(sub);
|
|
54
|
+
}
|
|
55
|
+
} else if (!(flags & (8 /* RECURSED */ | 4 /* RECURSED_CHECK */))) {
|
|
50
56
|
flags = 0 /* NONE */;
|
|
51
|
-
sub.flag = queueBit | watcherBit;
|
|
52
57
|
} else if (!(flags & 4 /* RECURSED_CHECK */)) {
|
|
53
|
-
sub.flag =
|
|
58
|
+
sub.flag = flags & -9 /* RECURSED */ | 32 /* PENDING */;
|
|
54
59
|
} else if (!(flags & (16 /* DIRTY */ | 32 /* PENDING */)) && isValidLink(link, sub)) {
|
|
55
|
-
sub.flag =
|
|
60
|
+
sub.flag = flags | (8 /* RECURSED */ | 32 /* PENDING */);
|
|
61
|
+
if (watcherBit) {
|
|
62
|
+
enqueueEffect(sub);
|
|
63
|
+
}
|
|
56
64
|
flags &= 1 /* MUTABLE */;
|
|
57
65
|
} else {
|
|
58
66
|
flags = 0 /* NONE */;
|
|
59
|
-
sub.flag = queueBit | watcherBit;
|
|
60
|
-
}
|
|
61
|
-
if (sub.flag & 2 /* WATCHING */) {
|
|
62
|
-
enqueueEffect(sub);
|
|
63
67
|
}
|
|
64
68
|
if (flags & 1 /* MUTABLE */) {
|
|
65
69
|
const subSubs = sub.subLink;
|
|
66
|
-
if (subSubs) {
|
|
67
|
-
const nextSub =
|
|
68
|
-
if (nextSub) {
|
|
70
|
+
if (subSubs !== void 0) {
|
|
71
|
+
const nextSub = subSubs.nextSubLink;
|
|
72
|
+
if (nextSub !== void 0) {
|
|
69
73
|
stack = { value: next, prev: stack };
|
|
70
74
|
next = nextSub;
|
|
71
75
|
}
|
|
76
|
+
link = subSubs;
|
|
72
77
|
continue;
|
|
73
78
|
}
|
|
74
79
|
}
|
|
75
|
-
if (next) {
|
|
76
|
-
link = next;
|
|
80
|
+
if ((link = next) !== void 0) {
|
|
77
81
|
next = link.nextSubLink;
|
|
78
82
|
continue;
|
|
79
83
|
}
|
|
80
|
-
while (stack) {
|
|
84
|
+
while (stack !== void 0) {
|
|
81
85
|
link = stack.value;
|
|
82
86
|
stack = stack.prev;
|
|
83
|
-
if (link) {
|
|
87
|
+
if (link !== void 0) {
|
|
84
88
|
next = link.nextSubLink;
|
|
85
89
|
continue top;
|
|
86
90
|
}
|
|
@@ -91,27 +95,16 @@ function propagate(link) {
|
|
|
91
95
|
function shallowPropagate(link) {
|
|
92
96
|
while (link) {
|
|
93
97
|
const sub = link.subNode;
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
sub.flag = newFlags;
|
|
99
|
-
if (newFlags & 2 /* WATCHING */) {
|
|
98
|
+
const flags = sub.flag;
|
|
99
|
+
if ((flags & (32 /* PENDING */ | 16 /* DIRTY */)) === 32 /* PENDING */) {
|
|
100
|
+
sub.flag = flags | 16 /* DIRTY */;
|
|
101
|
+
if ((flags & (2 /* WATCHING */ | 4 /* RECURSED_CHECK */)) === 2 /* WATCHING */) {
|
|
100
102
|
enqueueEffect(sub);
|
|
101
103
|
}
|
|
102
|
-
if (flags & 1 /* MUTABLE */ && sub.subLink) {
|
|
103
|
-
shallowPropagate(sub.subLink);
|
|
104
|
-
}
|
|
105
104
|
}
|
|
106
105
|
link = link.nextSubLink;
|
|
107
106
|
}
|
|
108
107
|
}
|
|
109
|
-
function enqueueEffect(effect2) {
|
|
110
|
-
if (!effect2.active) {
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
effect2.notify();
|
|
114
|
-
}
|
|
115
108
|
|
|
116
109
|
// src/link.ts
|
|
117
110
|
var currentLinkVersion = 0;
|
|
@@ -215,67 +208,76 @@ function unlinkReactiveNode(linkNode, subNode = linkNode.subNode) {
|
|
|
215
208
|
}
|
|
216
209
|
}
|
|
217
210
|
}
|
|
218
|
-
linkNode.depNode = void 0;
|
|
219
|
-
linkNode.subNode = void 0;
|
|
220
|
-
linkNode.prevSubLink = void 0;
|
|
221
|
-
linkNode.nextSubLink = void 0;
|
|
222
|
-
linkNode.prevDepLink = void 0;
|
|
223
|
-
linkNode.nextDepLink = void 0;
|
|
224
211
|
return nextDep;
|
|
225
212
|
}
|
|
226
213
|
function checkDirty(link, sub) {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
let
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
214
|
+
let stack;
|
|
215
|
+
let checkDepth = 0;
|
|
216
|
+
let dirty = false;
|
|
217
|
+
top: do {
|
|
218
|
+
let currentDirty = false;
|
|
219
|
+
if (sub.flag & 16 /* DIRTY */) {
|
|
220
|
+
currentDirty = true;
|
|
221
|
+
} else {
|
|
222
|
+
const dep = link.depNode;
|
|
235
223
|
const depFlags = dep.flag;
|
|
236
|
-
if (owner.flag & 16 /* DIRTY */) {
|
|
237
|
-
return true;
|
|
238
|
-
}
|
|
239
224
|
if ((depFlags & (1 /* MUTABLE */ | 16 /* DIRTY */)) === (1 /* MUTABLE */ | 16 /* DIRTY */)) {
|
|
240
225
|
const subs = dep.subLink;
|
|
241
226
|
if (subs && subs.nextSubLink) {
|
|
242
227
|
shallowPropagate2(subs);
|
|
243
228
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
node.flag = node.flag & -33 /* PENDING */ | 16 /* DIRTY */;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
return true;
|
|
250
|
-
}
|
|
251
|
-
if ((depFlags & (1 /* MUTABLE */ | 32 /* PENDING */)) === (1 /* MUTABLE */ | 32 /* PENDING */)) {
|
|
229
|
+
currentDirty = true;
|
|
230
|
+
} else if ((depFlags & (1 /* MUTABLE */ | 32 /* PENDING */)) === (1 /* MUTABLE */ | 32 /* PENDING */)) {
|
|
252
231
|
if (dep.depLink) {
|
|
253
|
-
|
|
254
|
-
|
|
232
|
+
stack = { link, prev: stack };
|
|
233
|
+
link = dep.depLink;
|
|
234
|
+
sub = dep;
|
|
235
|
+
++checkDepth;
|
|
236
|
+
continue top;
|
|
255
237
|
} else {
|
|
256
238
|
dep.flag &= -33 /* PENDING */;
|
|
257
239
|
}
|
|
258
240
|
} else if (depFlags & 32 /* PENDING */) {
|
|
259
241
|
dep.flag &= -33 /* PENDING */;
|
|
260
242
|
}
|
|
261
|
-
current = current.nextDepLink;
|
|
262
243
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
244
|
+
if (!currentDirty && link.nextDepLink !== void 0) {
|
|
245
|
+
link = link.nextDepLink;
|
|
246
|
+
continue top;
|
|
247
|
+
}
|
|
248
|
+
dirty = currentDirty;
|
|
249
|
+
while (checkDepth--) {
|
|
250
|
+
link = stack.link;
|
|
251
|
+
stack = stack.prev;
|
|
252
|
+
sub = link.subNode;
|
|
253
|
+
const checkedDep = link.depNode;
|
|
254
|
+
if (dirty) {
|
|
255
|
+
checkedDep.flag = checkedDep.flag & -33 /* PENDING */ | 16 /* DIRTY */;
|
|
256
|
+
} else {
|
|
257
|
+
checkedDep.flag &= -33 /* PENDING */;
|
|
258
|
+
}
|
|
259
|
+
if (checkedDep.flag & 16 /* DIRTY */) {
|
|
260
|
+
dirty = true;
|
|
261
|
+
}
|
|
262
|
+
if (!dirty && link.nextDepLink !== void 0) {
|
|
263
|
+
link = link.nextDepLink;
|
|
264
|
+
continue top;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
if (dirty) {
|
|
268
|
+
sub.flag = sub.flag & -33 /* PENDING */ | 16 /* DIRTY */;
|
|
269
|
+
} else {
|
|
270
|
+
sub.flag &= -33 /* PENDING */;
|
|
271
|
+
}
|
|
272
|
+
return dirty;
|
|
273
|
+
} while (true);
|
|
271
274
|
}
|
|
272
275
|
function shallowPropagate2(link) {
|
|
273
276
|
while (link) {
|
|
274
277
|
const sub = link.subNode;
|
|
275
|
-
const
|
|
276
|
-
const flags = sub.flag & -65 /* QUEUED */;
|
|
278
|
+
const flags = sub.flag;
|
|
277
279
|
if ((flags & (32 /* PENDING */ | 16 /* DIRTY */)) === 32 /* PENDING */) {
|
|
278
|
-
sub.flag =
|
|
280
|
+
sub.flag = flags | 16 /* DIRTY */;
|
|
279
281
|
}
|
|
280
282
|
link = link.nextSubLink;
|
|
281
283
|
}
|
|
@@ -322,6 +324,23 @@ function isValidLink(checkLink, sub) {
|
|
|
322
324
|
return false;
|
|
323
325
|
}
|
|
324
326
|
var targetMap = /* @__PURE__ */ new WeakMap();
|
|
327
|
+
var triggerVersion = 0;
|
|
328
|
+
function collectTriggeredEffects(dep, effects, version) {
|
|
329
|
+
if (!dep) {
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
dep.forEach((effect2) => {
|
|
333
|
+
if (effect2.flag & 2 /* WATCHING */ && !effect2._active) {
|
|
334
|
+
dep.delete(effect2);
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
if (effect2._triggerVersion === version) {
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
effect2._triggerVersion = version;
|
|
341
|
+
effects.push(effect2);
|
|
342
|
+
});
|
|
343
|
+
}
|
|
325
344
|
function track(target, key) {
|
|
326
345
|
if (!activeSub || isUntracking) {
|
|
327
346
|
return;
|
|
@@ -336,50 +355,39 @@ function track(target, key) {
|
|
|
336
355
|
dep = /* @__PURE__ */ new Set();
|
|
337
356
|
depsMap.set(key, dep);
|
|
338
357
|
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
}
|
|
358
|
+
const sizeBefore = dep.size ;
|
|
359
|
+
dep.add(activeSub);
|
|
360
|
+
if (dep.size !== sizeBefore && shared.isFunction(activeSub.onTrack)) {
|
|
361
|
+
activeSub.onTrack({
|
|
362
|
+
effect: activeSub,
|
|
363
|
+
target,
|
|
364
|
+
type: "get",
|
|
365
|
+
key
|
|
366
|
+
});
|
|
349
367
|
}
|
|
350
368
|
}
|
|
351
369
|
function trigger(target, type, key, newValue) {
|
|
370
|
+
var _a5;
|
|
352
371
|
const depsMap = targetMap.get(target);
|
|
353
372
|
if (!depsMap) {
|
|
354
373
|
return;
|
|
355
374
|
}
|
|
356
|
-
const effects =
|
|
375
|
+
const effects = [];
|
|
376
|
+
const version = ++triggerVersion;
|
|
357
377
|
if (key !== void 0) {
|
|
358
378
|
if (Array.isArray(key)) {
|
|
359
|
-
key
|
|
360
|
-
|
|
361
|
-
if (dep) {
|
|
362
|
-
dep.forEach((effect2) => effects.add(effect2));
|
|
363
|
-
}
|
|
364
|
-
});
|
|
365
|
-
} else {
|
|
366
|
-
const dep = depsMap.get(key);
|
|
367
|
-
if (dep) {
|
|
368
|
-
dep.forEach((effect2) => effects.add(effect2));
|
|
379
|
+
for (const element of key) {
|
|
380
|
+
collectTriggeredEffects(depsMap.get(element), effects, version);
|
|
369
381
|
}
|
|
382
|
+
} else {
|
|
383
|
+
collectTriggeredEffects(depsMap.get(key), effects, version);
|
|
370
384
|
}
|
|
371
385
|
}
|
|
372
386
|
if (type === "ADD" || type === "DELETE" || type === "CLEAR") {
|
|
373
|
-
const
|
|
374
|
-
|
|
375
|
-
const iterationKey = Array.isArray(target) ? ARRAY_ITERATE_KEY2 : ITERATE_KEY;
|
|
376
|
-
const iterationDep = depsMap.get(iterationKey);
|
|
377
|
-
if (iterationDep) {
|
|
378
|
-
iterationDep.forEach((effect2) => effects.add(effect2));
|
|
379
|
-
}
|
|
387
|
+
const iterationKey = Array.isArray(target) ? ARRAY_ITERATE_KEY : ITERATE_KEY;
|
|
388
|
+
collectTriggeredEffects(depsMap.get(iterationKey), effects, version);
|
|
380
389
|
}
|
|
381
|
-
|
|
382
|
-
var _a5;
|
|
390
|
+
for (const effect2 of effects) {
|
|
383
391
|
if (shared.isFunction(effect2.onTrigger)) {
|
|
384
392
|
effect2.onTrigger({
|
|
385
393
|
effect: effect2,
|
|
@@ -397,7 +405,7 @@ function trigger(target, type, key, newValue) {
|
|
|
397
405
|
propagate(effect2.subLink);
|
|
398
406
|
}
|
|
399
407
|
}
|
|
400
|
-
}
|
|
408
|
+
}
|
|
401
409
|
}
|
|
402
410
|
var reactiveCaches = /* @__PURE__ */ new WeakMap();
|
|
403
411
|
function toRaw(value) {
|
|
@@ -445,8 +453,7 @@ function createArrayInstrumentations() {
|
|
|
445
453
|
instrumentations[key] = function(...args) {
|
|
446
454
|
const arr = toRaw(this);
|
|
447
455
|
const res = Array.prototype[key].apply(arr, args);
|
|
448
|
-
trigger(arr, TriggerOpTypes.SET, ARRAY_KEY);
|
|
449
|
-
trigger(arr, TriggerOpTypes.SET, ARRAY_ITERATE_KEY);
|
|
456
|
+
trigger(arr, TriggerOpTypes.SET, [ARRAY_KEY, ARRAY_ITERATE_KEY]);
|
|
450
457
|
return res;
|
|
451
458
|
};
|
|
452
459
|
}
|
|
@@ -849,6 +856,8 @@ var objectHandlers = (shallow) => ({
|
|
|
849
856
|
return result;
|
|
850
857
|
}
|
|
851
858
|
});
|
|
859
|
+
var shallowObjectHandlers = objectHandlers(true);
|
|
860
|
+
var deepObjectHandlers = objectHandlers(false);
|
|
852
861
|
function reactiveImpl(target, shallow = false) {
|
|
853
862
|
if (!shared.isObject(target)) {
|
|
854
863
|
return target;
|
|
@@ -868,7 +877,7 @@ function reactiveImpl(target, shallow = false) {
|
|
|
868
877
|
} else if (shared.isWeakMap(target) || shared.isWeakSet(target)) {
|
|
869
878
|
handler = weakCollectionHandlers;
|
|
870
879
|
} else {
|
|
871
|
-
handler =
|
|
880
|
+
handler = shallow ? shallowObjectHandlers : deepObjectHandlers;
|
|
872
881
|
}
|
|
873
882
|
const proxy = new Proxy(target, handler);
|
|
874
883
|
reactiveCaches.set(target, proxy);
|
|
@@ -904,7 +913,6 @@ var toReactive = (value) => shared.isObject(value) ? reactive(value) : value;
|
|
|
904
913
|
var _a;
|
|
905
914
|
_a = "_IS_SIGNAL" /* IS_SIGNAL */;
|
|
906
915
|
var SignalImpl = class {
|
|
907
|
-
// Mark as Signal
|
|
908
916
|
/**
|
|
909
917
|
* Create a new Signal with the given initial value.
|
|
910
918
|
*
|
|
@@ -914,15 +922,20 @@ var SignalImpl = class {
|
|
|
914
922
|
constructor(value, shallow = false) {
|
|
915
923
|
this.flag = 1 /* MUTABLE */;
|
|
916
924
|
// Mark whether it's shallow reactive
|
|
917
|
-
// @ts-ignore
|
|
925
|
+
// @ts-ignore: used internally by isSignal typeguard
|
|
918
926
|
this[_a] = true;
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
927
|
+
const unwrapped = toRaw(value);
|
|
928
|
+
this._rawValue = unwrapped;
|
|
929
|
+
this["_IS_SHALLOW" /* IS_SHALLOW */] = shallow;
|
|
930
|
+
if (!shared.isObject(unwrapped)) {
|
|
931
|
+
this._value = unwrapped;
|
|
922
932
|
} else {
|
|
923
|
-
|
|
933
|
+
if (isReactive(value)) {
|
|
934
|
+
this._value = value;
|
|
935
|
+
} else {
|
|
936
|
+
this._value = shallow ? shallowReactive(unwrapped) : reactive(unwrapped);
|
|
937
|
+
}
|
|
924
938
|
}
|
|
925
|
-
this["_IS_SHALLOW" /* IS_SHALLOW */] = shallow;
|
|
926
939
|
}
|
|
927
940
|
// dep getter, returns itself for dependency collection
|
|
928
941
|
get dep() {
|
|
@@ -943,37 +956,37 @@ var SignalImpl = class {
|
|
|
943
956
|
return this._value;
|
|
944
957
|
}
|
|
945
958
|
// value setter, triggers update when value changes
|
|
946
|
-
set value(
|
|
947
|
-
if (isSignal(
|
|
959
|
+
set value(newValue) {
|
|
960
|
+
if (isSignal(newValue)) {
|
|
948
961
|
{
|
|
949
962
|
shared.warn(
|
|
950
963
|
"Setting a signal value to another signal is not recommended. The value will be unwrapped automatically."
|
|
951
964
|
);
|
|
952
965
|
}
|
|
953
|
-
|
|
966
|
+
newValue = newValue.peek();
|
|
954
967
|
}
|
|
955
|
-
|
|
956
|
-
|
|
968
|
+
const originalValue = newValue;
|
|
969
|
+
const rawValue = toRaw(newValue);
|
|
970
|
+
if (!shared.hasChanged(this._rawValue, rawValue)) {
|
|
957
971
|
return;
|
|
958
972
|
}
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
if (shallow) {
|
|
967
|
-
this._value = shared.isObject(value) ? shallowReactive(value) : value;
|
|
973
|
+
this._oldValue = this._rawValue;
|
|
974
|
+
this._rawValue = rawValue;
|
|
975
|
+
this.flag |= 16 /* DIRTY */;
|
|
976
|
+
if (!shared.isObject(rawValue)) {
|
|
977
|
+
this._value = rawValue;
|
|
978
|
+
} else if (isReactive(originalValue)) {
|
|
979
|
+
this._value = originalValue;
|
|
968
980
|
} else {
|
|
969
|
-
|
|
981
|
+
const shallow = this["_IS_SHALLOW" /* IS_SHALLOW */];
|
|
982
|
+
this._value = shallow ? shallowReactive(rawValue) : reactive(rawValue);
|
|
970
983
|
}
|
|
971
984
|
const subs = this.subLink;
|
|
972
985
|
if (subs) {
|
|
973
986
|
propagate(subs);
|
|
974
987
|
}
|
|
975
988
|
}
|
|
976
|
-
// Check if the value should be
|
|
989
|
+
// Check if the value should be updated
|
|
977
990
|
shouldUpdate() {
|
|
978
991
|
this.flag &= -17 /* DIRTY */;
|
|
979
992
|
if (!("_oldValue" in this)) {
|
|
@@ -1031,19 +1044,7 @@ var activePreFlushCbs = /* @__PURE__ */ new Set();
|
|
|
1031
1044
|
var p = Promise.resolve();
|
|
1032
1045
|
var isFlushPending = false;
|
|
1033
1046
|
function nextTick(fn) {
|
|
1034
|
-
|
|
1035
|
-
return new Promise((resolve, reject) => {
|
|
1036
|
-
queueMicrotask(() => {
|
|
1037
|
-
try {
|
|
1038
|
-
fn();
|
|
1039
|
-
resolve();
|
|
1040
|
-
} catch (error5) {
|
|
1041
|
-
reject(error5);
|
|
1042
|
-
}
|
|
1043
|
-
});
|
|
1044
|
-
});
|
|
1045
|
-
}
|
|
1046
|
-
return p;
|
|
1047
|
+
return fn ? p.then(fn) : p;
|
|
1047
1048
|
}
|
|
1048
1049
|
function queueJob(job) {
|
|
1049
1050
|
queue.add(job);
|
|
@@ -1063,9 +1064,7 @@ function flushJobs() {
|
|
|
1063
1064
|
isFlushPending = false;
|
|
1064
1065
|
flushPreFlushCbs();
|
|
1065
1066
|
while (queue.size > 0) {
|
|
1066
|
-
const
|
|
1067
|
-
queue.clear();
|
|
1068
|
-
for (const job of jobs) {
|
|
1067
|
+
for (const job of queue) {
|
|
1069
1068
|
try {
|
|
1070
1069
|
job();
|
|
1071
1070
|
} catch (_error) {
|
|
@@ -1074,6 +1073,7 @@ function flushJobs() {
|
|
|
1074
1073
|
}
|
|
1075
1074
|
}
|
|
1076
1075
|
}
|
|
1076
|
+
queue.clear();
|
|
1077
1077
|
}
|
|
1078
1078
|
}
|
|
1079
1079
|
function flushPreFlushCbs() {
|
|
@@ -1149,16 +1149,22 @@ var EffectImpl = class {
|
|
|
1149
1149
|
*/
|
|
1150
1150
|
constructor(fn, options) {
|
|
1151
1151
|
this.flag = 2 /* WATCHING */ | 16 /* DIRTY */;
|
|
1152
|
-
// @ts-ignore
|
|
1152
|
+
// @ts-ignore: used internally by isEffect typeguard
|
|
1153
1153
|
this[_a2] = true;
|
|
1154
|
-
//
|
|
1154
|
+
// State management
|
|
1155
1155
|
this._active = true;
|
|
1156
|
+
var _a5;
|
|
1156
1157
|
this.fn = fn;
|
|
1157
1158
|
if (options) {
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1159
|
+
const scheduler = (_a5 = options.scheduler) != null ? _a5 : options.flush;
|
|
1160
|
+
if (scheduler) {
|
|
1161
|
+
this._flushScheduler = shared.isFunction(scheduler) ? () => scheduler(this) : createScheduler(() => this.run(), scheduler);
|
|
1162
|
+
}
|
|
1163
|
+
if (options.onStop) this.onStop = options.onStop;
|
|
1164
|
+
{
|
|
1165
|
+
if (options.onTrack) this.onTrack = options.onTrack;
|
|
1166
|
+
if (options.onTrigger) this.onTrigger = options.onTrigger;
|
|
1167
|
+
}
|
|
1162
1168
|
}
|
|
1163
1169
|
}
|
|
1164
1170
|
/**
|
|
@@ -1168,9 +1174,8 @@ var EffectImpl = class {
|
|
|
1168
1174
|
return this._active;
|
|
1169
1175
|
}
|
|
1170
1176
|
/**
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
*/
|
|
1177
|
+
* Check if the Effect is dirty (needs re-execution)
|
|
1178
|
+
*/
|
|
1174
1179
|
get dirty() {
|
|
1175
1180
|
const flags = this.flag;
|
|
1176
1181
|
if (flags & 16 /* DIRTY */) {
|
|
@@ -1265,7 +1270,7 @@ var EffectImpl = class {
|
|
|
1265
1270
|
return this.fn();
|
|
1266
1271
|
}
|
|
1267
1272
|
const flags = this.flag;
|
|
1268
|
-
this.flag = flags & -
|
|
1273
|
+
this.flag = flags & -49 | 512 /* RUNNING */;
|
|
1269
1274
|
const prevSub = startTracking(this);
|
|
1270
1275
|
try {
|
|
1271
1276
|
return this.fn();
|
|
@@ -1273,7 +1278,7 @@ var EffectImpl = class {
|
|
|
1273
1278
|
this.flag |= 16 /* DIRTY */;
|
|
1274
1279
|
throw error5;
|
|
1275
1280
|
} finally {
|
|
1276
|
-
this.flag &= -
|
|
1281
|
+
this.flag &= -513 /* RUNNING */;
|
|
1277
1282
|
endTracking(this, prevSub);
|
|
1278
1283
|
}
|
|
1279
1284
|
}
|
|
@@ -1293,25 +1298,21 @@ var EffectImpl = class {
|
|
|
1293
1298
|
* Decides whether to execute immediately or defer based on scheduling strategy.
|
|
1294
1299
|
*/
|
|
1295
1300
|
notify() {
|
|
1301
|
+
var _a5;
|
|
1296
1302
|
const flags = this.flag;
|
|
1297
|
-
if (!this._active || flags & (256 /* PAUSED */ |
|
|
1303
|
+
if (!this._active || flags & (256 /* PAUSED */ | 512 /* RUNNING */ | 16 /* DIRTY */)) {
|
|
1298
1304
|
return;
|
|
1299
1305
|
}
|
|
1300
1306
|
this.flag = flags | 16 /* DIRTY */;
|
|
1301
|
-
if (this.onTrigger) {
|
|
1307
|
+
if (this == null ? void 0 : this.onTrigger) {
|
|
1302
1308
|
this.onTrigger({
|
|
1303
1309
|
effect: this,
|
|
1304
1310
|
target: {},
|
|
1305
1311
|
type: "set"
|
|
1306
1312
|
});
|
|
1307
1313
|
}
|
|
1308
|
-
if (this.
|
|
1309
|
-
|
|
1310
|
-
this.scheduler(this);
|
|
1311
|
-
} else {
|
|
1312
|
-
const schedulerFn = createScheduler(() => this.run(), this.scheduler);
|
|
1313
|
-
schedulerFn();
|
|
1314
|
-
}
|
|
1314
|
+
if (this._flushScheduler) {
|
|
1315
|
+
(_a5 = this._flushScheduler) == null ? void 0 : _a5.call(this);
|
|
1315
1316
|
} else if (isBatching()) {
|
|
1316
1317
|
queueJob(this.getJob());
|
|
1317
1318
|
} else {
|
|
@@ -1345,6 +1346,7 @@ var EffectImpl = class {
|
|
|
1345
1346
|
sub = unlinkReactiveNode(sub);
|
|
1346
1347
|
}
|
|
1347
1348
|
this._job = void 0;
|
|
1349
|
+
this._flushScheduler = void 0;
|
|
1348
1350
|
this.depLinkTail = void 0;
|
|
1349
1351
|
this.subLinkTail = void 0;
|
|
1350
1352
|
{
|
|
@@ -1359,7 +1361,7 @@ var EffectImpl = class {
|
|
|
1359
1361
|
);
|
|
1360
1362
|
}
|
|
1361
1363
|
}
|
|
1362
|
-
if (this.onStop) {
|
|
1364
|
+
if (this == null ? void 0 : this.onStop) {
|
|
1363
1365
|
this.onStop();
|
|
1364
1366
|
}
|
|
1365
1367
|
}
|
|
@@ -1411,7 +1413,7 @@ var ComputedImpl = class {
|
|
|
1411
1413
|
*/
|
|
1412
1414
|
constructor(getter, setter, onTrack, onTrigger) {
|
|
1413
1415
|
this.flag = 1 /* MUTABLE */ | 16 /* DIRTY */;
|
|
1414
|
-
|
|
1416
|
+
// @ts-ignore: used internally by isComputed typeguard
|
|
1415
1417
|
this[_a3] = true;
|
|
1416
1418
|
// Cache
|
|
1417
1419
|
// Use symbol sentinel to distinguish "no value" from undefined/null values
|
|
@@ -1472,7 +1474,7 @@ var ComputedImpl = class {
|
|
|
1472
1474
|
/**
|
|
1473
1475
|
* Recompute the value
|
|
1474
1476
|
*
|
|
1475
|
-
*
|
|
1477
|
+
* computation logic:
|
|
1476
1478
|
* 1. Start tracking dependencies
|
|
1477
1479
|
* 2. Execute getter function
|
|
1478
1480
|
* 3. Check if value changed using optimized comparison
|
|
@@ -1511,7 +1513,7 @@ var ComputedImpl = class {
|
|
|
1511
1513
|
} catch (_error) {
|
|
1512
1514
|
const clearMask = -49;
|
|
1513
1515
|
this.flag &= clearMask;
|
|
1514
|
-
this.
|
|
1516
|
+
this._value = NO_VALUE;
|
|
1515
1517
|
{
|
|
1516
1518
|
shared.error(
|
|
1517
1519
|
"[Computed] Error occurred while computing value.\nThe computed will retry on next access.\nCommon causes:\n - Accessing undefined properties\n - Circular dependencies\n - Exceptions in getter function\nCheck your getter function for errors.",
|
|
@@ -1635,39 +1637,23 @@ function createOptionsStore(options) {
|
|
|
1635
1637
|
if (getters) {
|
|
1636
1638
|
for (const key in getters) {
|
|
1637
1639
|
const getter = getters[key];
|
|
1638
|
-
if (getter)
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
accessCount++;
|
|
1645
|
-
const now = Date.now();
|
|
1646
|
-
if (accessCount > 100 && now - lastWarnTime > 1e3) {
|
|
1647
|
-
shared.warn(
|
|
1648
|
-
`Getter '${key}' has been accessed ${accessCount} times. Consider caching the result if the value is used frequently. Note: Getters are computed properties that recalculate on every access.`
|
|
1649
|
-
);
|
|
1650
|
-
lastWarnTime = now;
|
|
1651
|
-
accessCount = 0;
|
|
1652
|
-
}
|
|
1653
|
-
}
|
|
1654
|
-
return computed(() => getter.call(store, reactiveState)).value;
|
|
1655
|
-
},
|
|
1656
|
-
enumerable: true,
|
|
1657
|
-
configurable: true
|
|
1658
|
-
});
|
|
1659
|
-
}
|
|
1640
|
+
if (!getter) continue;
|
|
1641
|
+
Object.defineProperty(store, key, {
|
|
1642
|
+
get: () => computed(() => getter.call(store, reactiveState)).value,
|
|
1643
|
+
enumerable: true,
|
|
1644
|
+
configurable: true
|
|
1645
|
+
});
|
|
1660
1646
|
}
|
|
1661
1647
|
}
|
|
1662
1648
|
if (actions) {
|
|
1663
1649
|
for (const key in actions) {
|
|
1664
1650
|
const action = actions[key];
|
|
1665
1651
|
if (action) {
|
|
1666
|
-
store
|
|
1652
|
+
Reflect.set(store, key, (...args) => {
|
|
1667
1653
|
const result = action.apply(reactiveState, args);
|
|
1668
1654
|
actionCallbacks.forEach((callback) => callback(reactiveState));
|
|
1669
1655
|
return result;
|
|
1670
|
-
};
|
|
1656
|
+
});
|
|
1671
1657
|
}
|
|
1672
1658
|
}
|
|
1673
1659
|
}
|
|
@@ -1708,15 +1694,15 @@ function createStore(storeDefinition) {
|
|
|
1708
1694
|
}
|
|
1709
1695
|
return () => {
|
|
1710
1696
|
let options;
|
|
1711
|
-
if (
|
|
1697
|
+
if (shared.isFunction(storeDefinition)) {
|
|
1712
1698
|
options = createClassStore(storeDefinition);
|
|
1713
1699
|
} else {
|
|
1714
1700
|
options = storeDefinition;
|
|
1715
1701
|
}
|
|
1716
1702
|
const store = createOptionsStore(options);
|
|
1717
|
-
if (
|
|
1718
|
-
Object.keys(options.actions
|
|
1719
|
-
store
|
|
1703
|
+
if (shared.isFunction(storeDefinition) && options.actions) {
|
|
1704
|
+
Object.keys(options.actions).forEach((key) => {
|
|
1705
|
+
Reflect.set(store, key, options.actions[key].bind(store));
|
|
1720
1706
|
});
|
|
1721
1707
|
}
|
|
1722
1708
|
return store;
|
|
@@ -1731,26 +1717,30 @@ var RefImpl = class extends (_b = SignalImpl, _a4 = "_IS_REF" /* IS_REF */, _b)
|
|
|
1731
1717
|
*/
|
|
1732
1718
|
constructor(value) {
|
|
1733
1719
|
super(value, true);
|
|
1734
|
-
// @ts-ignore
|
|
1720
|
+
// @ts-ignore: used internally by isRef typeguard
|
|
1735
1721
|
this[_a4] = true;
|
|
1736
1722
|
}
|
|
1737
1723
|
get value() {
|
|
1738
|
-
|
|
1724
|
+
const sub = activeSub;
|
|
1725
|
+
if (sub) {
|
|
1726
|
+
linkReactiveNode(this, sub);
|
|
1727
|
+
}
|
|
1739
1728
|
return this._value;
|
|
1740
1729
|
}
|
|
1741
1730
|
set value(newValue) {
|
|
1742
1731
|
if (isSignal(newValue)) {
|
|
1743
|
-
newValue = newValue.
|
|
1732
|
+
newValue = newValue.peek();
|
|
1744
1733
|
}
|
|
1745
1734
|
if (isRef(newValue)) {
|
|
1746
1735
|
newValue = newValue.value;
|
|
1747
1736
|
}
|
|
1748
1737
|
if (shared.hasChanged(this._value, newValue)) {
|
|
1738
|
+
this._rawValue = newValue;
|
|
1749
1739
|
this._value = newValue;
|
|
1740
|
+
this.flag |= 16 /* DIRTY */;
|
|
1750
1741
|
if (this.subLink) {
|
|
1751
|
-
|
|
1742
|
+
propagate(this.subLink);
|
|
1752
1743
|
}
|
|
1753
|
-
trigger(this, "SET", SIGNAL_KEY);
|
|
1754
1744
|
}
|
|
1755
1745
|
}
|
|
1756
1746
|
};
|