@solidjs/signals 0.4.3 → 0.4.5
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/dev.js +194 -84
- package/dist/node.cjs +655 -545
- package/dist/prod.js +655 -545
- package/dist/types/boundaries.d.ts +2 -1
- package/dist/types/core/core.d.ts +3 -2
- package/dist/types/core/scheduler.d.ts +9 -3
- package/package.json +1 -1
package/dist/dev.js
CHANGED
|
@@ -39,7 +39,7 @@ function incrementClock() {
|
|
|
39
39
|
clock++;
|
|
40
40
|
}
|
|
41
41
|
var ActiveTransition = null;
|
|
42
|
-
var
|
|
42
|
+
var Unobserved = [];
|
|
43
43
|
var scheduled = false;
|
|
44
44
|
function schedule() {
|
|
45
45
|
if (scheduled)
|
|
@@ -49,12 +49,12 @@ function schedule() {
|
|
|
49
49
|
queueMicrotask(flush);
|
|
50
50
|
}
|
|
51
51
|
function notifyUnobserved() {
|
|
52
|
-
for (let i = 0; i <
|
|
53
|
-
const source =
|
|
52
|
+
for (let i = 0; i < Unobserved.length; i++) {
|
|
53
|
+
const source = Unobserved[i];
|
|
54
54
|
if (!source._observers || !source._observers.length)
|
|
55
|
-
|
|
55
|
+
Unobserved[i]._unobserved?.();
|
|
56
56
|
}
|
|
57
|
-
|
|
57
|
+
Unobserved = [];
|
|
58
58
|
}
|
|
59
59
|
var pureQueue = [];
|
|
60
60
|
var Queue = class {
|
|
@@ -64,8 +64,8 @@ var Queue = class {
|
|
|
64
64
|
_children = [];
|
|
65
65
|
created = clock;
|
|
66
66
|
enqueue(type, fn) {
|
|
67
|
-
if (ActiveTransition)
|
|
68
|
-
return ActiveTransition.enqueue(type, fn);
|
|
67
|
+
if (ActiveTransition && ActiveTransition._clonedQueues.has(this))
|
|
68
|
+
return ActiveTransition._clonedQueues.get(this).enqueue(type, fn);
|
|
69
69
|
pureQueue.push(fn);
|
|
70
70
|
if (type)
|
|
71
71
|
this._queues[type - 1].push(fn);
|
|
@@ -97,7 +97,7 @@ var Queue = class {
|
|
|
97
97
|
this.run(EFFECT_USER);
|
|
98
98
|
} finally {
|
|
99
99
|
this._running = false;
|
|
100
|
-
|
|
100
|
+
Unobserved.length && notifyUnobserved();
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
addChild(child) {
|
|
@@ -110,10 +110,23 @@ var Queue = class {
|
|
|
110
110
|
this._children.splice(index, 1);
|
|
111
111
|
}
|
|
112
112
|
notify(...args) {
|
|
113
|
+
if (ActiveTransition && ActiveTransition._clonedQueues.has(this))
|
|
114
|
+
return ActiveTransition._clonedQueues.get(this).notify(...args);
|
|
113
115
|
if (this._parent)
|
|
114
116
|
return this._parent.notify(...args);
|
|
115
117
|
return false;
|
|
116
118
|
}
|
|
119
|
+
merge(queue) {
|
|
120
|
+
this._queues[0].push.apply(this._queues[0], queue._queues[0]);
|
|
121
|
+
this._queues[1].push.apply(this._queues[1], queue._queues[1]);
|
|
122
|
+
for (let i = 0; i < queue._children.length; i++) {
|
|
123
|
+
const og = this._children.find((c) => c._cloned === queue._children[i]._cloned);
|
|
124
|
+
if (og)
|
|
125
|
+
og.merge(queue._children[i]);
|
|
126
|
+
else
|
|
127
|
+
this.addChild(queue._children[i]);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
117
130
|
};
|
|
118
131
|
var globalQueue = new Queue();
|
|
119
132
|
function flush() {
|
|
@@ -135,12 +148,19 @@ var Transition = class _Transition {
|
|
|
135
148
|
_optimistic = /* @__PURE__ */ new Set();
|
|
136
149
|
_done = false;
|
|
137
150
|
_queues = [[], []];
|
|
151
|
+
_clonedQueues = /* @__PURE__ */ new Map();
|
|
138
152
|
_pureQueue = [];
|
|
139
153
|
_children = [];
|
|
140
154
|
_parent = null;
|
|
141
155
|
_running = false;
|
|
142
156
|
_scheduled = false;
|
|
143
157
|
created = clock;
|
|
158
|
+
constructor() {
|
|
159
|
+
this._clonedQueues.set(globalQueue, this);
|
|
160
|
+
for (const child of globalQueue._children) {
|
|
161
|
+
cloneQueue(child, this, this._clonedQueues);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
144
164
|
enqueue(type, fn) {
|
|
145
165
|
this._pureQueue.push(fn);
|
|
146
166
|
if (type)
|
|
@@ -197,6 +217,18 @@ var Transition = class _Transition {
|
|
|
197
217
|
}
|
|
198
218
|
return true;
|
|
199
219
|
}
|
|
220
|
+
merge(queue) {
|
|
221
|
+
this._queues[0].push.apply(this._queues[0], queue._queues[0]);
|
|
222
|
+
this._queues[1].push.apply(this._queues[1], queue._queues[1]);
|
|
223
|
+
this._pureQueue.push.apply(this._pureQueue, queue._pureQueue);
|
|
224
|
+
for (let i = 0; i < queue._children.length; i++) {
|
|
225
|
+
const og = this._children.find((c) => c._cloned === queue._children[i]._cloned);
|
|
226
|
+
if (og)
|
|
227
|
+
og.merge(queue._children[i]);
|
|
228
|
+
else
|
|
229
|
+
this.addChild(queue._children[i]);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
200
232
|
schedule() {
|
|
201
233
|
if (this._scheduled)
|
|
202
234
|
return;
|
|
@@ -240,10 +272,8 @@ var Transition = class _Transition {
|
|
|
240
272
|
this._optimistic.add(fn);
|
|
241
273
|
}
|
|
242
274
|
};
|
|
243
|
-
var Transitions = /* @__PURE__ */ new Set();
|
|
244
275
|
function transition(fn) {
|
|
245
276
|
let t = new Transition();
|
|
246
|
-
Transitions.add(t);
|
|
247
277
|
queueMicrotask(() => t.runTransition(() => fn((fn2) => t.runTransition(fn2))));
|
|
248
278
|
}
|
|
249
279
|
function cloneGraph(node) {
|
|
@@ -255,29 +285,80 @@ function cloneGraph(node) {
|
|
|
255
285
|
return node._transition._sources.get(node);
|
|
256
286
|
}
|
|
257
287
|
const clone = Object.create(Object.getPrototypeOf(node));
|
|
258
|
-
Object.assign(clone, node, {
|
|
288
|
+
Object.assign(clone, node, {
|
|
289
|
+
_disposal: null,
|
|
290
|
+
_nextSibling: null,
|
|
291
|
+
_observers: null,
|
|
292
|
+
_sources: node._sources ? [...node._sources] : null,
|
|
293
|
+
_cloned: node
|
|
294
|
+
});
|
|
259
295
|
ActiveTransition._sources.set(node, clone);
|
|
260
296
|
node._transition = ActiveTransition;
|
|
297
|
+
if (node._sources) {
|
|
298
|
+
for (let i = 0; i < node._sources.length; i++)
|
|
299
|
+
node._sources[i]._observers.push(clone);
|
|
300
|
+
}
|
|
261
301
|
if (node._observers) {
|
|
302
|
+
clone._observers = [];
|
|
262
303
|
for (let i = 0, length = node._observers.length; i < length; i++) {
|
|
263
|
-
|
|
264
|
-
node._observers.push(cloneGraph(o));
|
|
304
|
+
!node._observers[i]._cloned && clone._observers.push(cloneGraph(node._observers[i]));
|
|
265
305
|
}
|
|
266
306
|
}
|
|
267
307
|
return clone;
|
|
268
308
|
}
|
|
269
|
-
function
|
|
309
|
+
function replaceSourceObservers(node, transition2) {
|
|
270
310
|
let source;
|
|
311
|
+
let transitionSource;
|
|
271
312
|
let swap;
|
|
272
|
-
for (let i =
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
313
|
+
for (let i = 0; i < node._sources.length; i++) {
|
|
314
|
+
transitionSource = transition2._sources.get(node._sources[i]);
|
|
315
|
+
source = transitionSource || node._sources[i];
|
|
316
|
+
if (source._observers && (swap = source._observers.indexOf(node)) !== -1) {
|
|
317
|
+
source._observers[swap] = transitionSource ? node._cloned : source._observers[source._observers.length - 1];
|
|
318
|
+
!transitionSource && source._observers.pop();
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
function cloneQueue(queue, parent, clonedQueues) {
|
|
323
|
+
const clone = Object.create(Object.getPrototypeOf(queue));
|
|
324
|
+
Object.assign(clone, queue, {
|
|
325
|
+
_cloned: queue,
|
|
326
|
+
_parent: parent,
|
|
327
|
+
_children: [],
|
|
328
|
+
enqueue(type, fn) {
|
|
329
|
+
ActiveTransition?.enqueue(type, fn);
|
|
330
|
+
},
|
|
331
|
+
notify(node, type, flags) {
|
|
332
|
+
node = node._cloned || node;
|
|
333
|
+
if (!clone._collectionType || type & LOADING_BIT) {
|
|
334
|
+
type &= ~LOADING_BIT;
|
|
335
|
+
ActiveTransition?.notify(node, LOADING_BIT, flags);
|
|
336
|
+
if (!type)
|
|
337
|
+
return true;
|
|
278
338
|
}
|
|
279
|
-
|
|
280
|
-
|
|
339
|
+
return queue.notify.call(this, node, type, flags);
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
parent._children.push(clone);
|
|
343
|
+
clonedQueues.set(queue, clone);
|
|
344
|
+
for (const child of queue._children) {
|
|
345
|
+
cloneQueue(child, clone, clonedQueues);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
function resolveQueues(children) {
|
|
349
|
+
for (const child of children) {
|
|
350
|
+
const og = child._cloned;
|
|
351
|
+
if (og) {
|
|
352
|
+
const clonedChildren = child._children;
|
|
353
|
+
delete child.enqueue;
|
|
354
|
+
delete child.notify;
|
|
355
|
+
delete child._parent;
|
|
356
|
+
delete child._children;
|
|
357
|
+
Object.assign(og, child);
|
|
358
|
+
delete og._cloned;
|
|
359
|
+
resolveQueues(clonedChildren);
|
|
360
|
+
} else if (child._parent._cloned) {
|
|
361
|
+
child._parent._cloned.addChild(child);
|
|
281
362
|
}
|
|
282
363
|
}
|
|
283
364
|
}
|
|
@@ -292,12 +373,8 @@ function mergeTransitions(t1, t2) {
|
|
|
292
373
|
});
|
|
293
374
|
t2._promises.forEach((p) => t1._promises.add(p));
|
|
294
375
|
t2._pendingNodes.forEach((n) => t1._pendingNodes.add(n));
|
|
295
|
-
|
|
296
|
-
t2._queues[1].forEach((f) => t1._queues[1].push(f));
|
|
297
|
-
t2._pureQueue.forEach((f) => t1._pureQueue.push(f));
|
|
298
|
-
t2._children.forEach((c) => t1.addChild(c));
|
|
376
|
+
t1.merge(t2);
|
|
299
377
|
t2._done = t1;
|
|
300
|
-
Transitions.delete(t2);
|
|
301
378
|
}
|
|
302
379
|
function finishTransition(transition2) {
|
|
303
380
|
if (transition2._done || transition2._scheduled || transition2._promises.size || transition2._pendingNodes.size)
|
|
@@ -306,21 +383,22 @@ function finishTransition(transition2) {
|
|
|
306
383
|
if (source === clone || source._transition !== transition2)
|
|
307
384
|
continue;
|
|
308
385
|
if (clone._sources)
|
|
309
|
-
|
|
386
|
+
replaceSourceObservers(clone, transition2);
|
|
310
387
|
source.dispose(false);
|
|
311
388
|
source.emptyDisposal();
|
|
312
389
|
Object.assign(source, clone);
|
|
313
390
|
delete source._cloned;
|
|
314
391
|
delete source._transition;
|
|
315
392
|
}
|
|
393
|
+
globalQueue._queues[0].push.apply(globalQueue._queues[0], transition2._queues[0]);
|
|
394
|
+
globalQueue._queues[1].push.apply(globalQueue._queues[1], transition2._queues[1]);
|
|
395
|
+
resolveQueues(transition2._children);
|
|
316
396
|
transition2._done = true;
|
|
317
|
-
Transitions.delete(transition2);
|
|
318
|
-
transition2.run(EFFECT_RENDER);
|
|
319
|
-
transition2.run(EFFECT_USER);
|
|
320
397
|
for (const reset of transition2._optimistic) {
|
|
321
398
|
delete reset._transition;
|
|
322
399
|
reset();
|
|
323
400
|
}
|
|
401
|
+
globalQueue.flush();
|
|
324
402
|
}
|
|
325
403
|
|
|
326
404
|
// src/core/owner.ts
|
|
@@ -527,8 +605,8 @@ var Computation = class extends Owner {
|
|
|
527
605
|
* Automatically re-executes the surrounding computation when the value changes
|
|
528
606
|
*/
|
|
529
607
|
read() {
|
|
530
|
-
if (ActiveTransition && ActiveTransition._sources.has(this)) {
|
|
531
|
-
const clone = ActiveTransition._sources.get(this);
|
|
608
|
+
if (ActiveTransition && (ActiveTransition._sources.has(this) || !this._cloned && this._stateFlags & UNINITIALIZED_BIT)) {
|
|
609
|
+
const clone = ActiveTransition._sources.get(this) || cloneGraph(this);
|
|
532
610
|
if (clone !== this)
|
|
533
611
|
return clone.read();
|
|
534
612
|
}
|
|
@@ -548,8 +626,8 @@ var Computation = class extends Owner {
|
|
|
548
626
|
* before continuing
|
|
549
627
|
*/
|
|
550
628
|
wait() {
|
|
551
|
-
if (ActiveTransition && ActiveTransition._sources.has(this)) {
|
|
552
|
-
const clone = ActiveTransition._sources.get(this);
|
|
629
|
+
if (ActiveTransition && (ActiveTransition._sources.has(this) || !this._cloned && this._stateFlags & UNINITIALIZED_BIT)) {
|
|
630
|
+
const clone = ActiveTransition._sources.get(this) || cloneGraph(this);
|
|
553
631
|
if (clone !== this)
|
|
554
632
|
return clone.wait();
|
|
555
633
|
}
|
|
@@ -572,7 +650,8 @@ var Computation = class extends Owner {
|
|
|
572
650
|
write(value, flags = 0, raw = false) {
|
|
573
651
|
if (ActiveTransition && !this._cloned) {
|
|
574
652
|
const clone = cloneGraph(this);
|
|
575
|
-
|
|
653
|
+
if (clone !== this)
|
|
654
|
+
return clone.write(value, flags, raw);
|
|
576
655
|
}
|
|
577
656
|
if (!this._compute && !this._pureWrite && getOwner() && !getOwner().firewall)
|
|
578
657
|
console.warn("A Signal was written to in an owned scope.");
|
|
@@ -601,11 +680,6 @@ var Computation = class extends Owner {
|
|
|
601
680
|
* Set the current node's state, and recursively mark all of this node's observers as STATE_CHECK
|
|
602
681
|
*/
|
|
603
682
|
_notify(state, skipQueue) {
|
|
604
|
-
if (ActiveTransition && ActiveTransition._sources.has(this)) {
|
|
605
|
-
const clone = ActiveTransition._sources.get(this);
|
|
606
|
-
if (clone !== this)
|
|
607
|
-
return clone._notify(state, skipQueue);
|
|
608
|
-
}
|
|
609
683
|
if (this._state >= state && !this._forceNotify)
|
|
610
684
|
return;
|
|
611
685
|
this._forceNotify = !!skipQueue;
|
|
@@ -645,6 +719,11 @@ var Computation = class extends Owner {
|
|
|
645
719
|
}
|
|
646
720
|
}
|
|
647
721
|
_setError(error) {
|
|
722
|
+
if (ActiveTransition && !this._cloned) {
|
|
723
|
+
const clone = cloneGraph(this);
|
|
724
|
+
if (clone !== this)
|
|
725
|
+
return clone._setError(error);
|
|
726
|
+
}
|
|
648
727
|
this._error = error;
|
|
649
728
|
this.write(UNCHANGED, this._stateFlags & ~LOADING_BIT | ERROR_BIT | UNINITIALIZED_BIT);
|
|
650
729
|
}
|
|
@@ -670,7 +749,7 @@ var Computation = class extends Owner {
|
|
|
670
749
|
for (let i = 0; i < this._sources.length; i++) {
|
|
671
750
|
const source = ActiveTransition && ActiveTransition._sources.get(this._sources[i]) || this._sources[i];
|
|
672
751
|
source._updateIfNecessary();
|
|
673
|
-
observerFlags |= source._stateFlags;
|
|
752
|
+
observerFlags |= source._stateFlags & ~UNINITIALIZED_BIT;
|
|
674
753
|
if (this._state === STATE_DIRTY) {
|
|
675
754
|
break;
|
|
676
755
|
}
|
|
@@ -740,7 +819,7 @@ function update(node) {
|
|
|
740
819
|
}
|
|
741
820
|
let source;
|
|
742
821
|
for (let i = newSourcesIndex; i < node._sources.length; i++) {
|
|
743
|
-
source = node._sources[i];
|
|
822
|
+
source = ActiveTransition && ActiveTransition._sources.get(node._sources[i]) || node._sources[i];
|
|
744
823
|
if (!source._observers)
|
|
745
824
|
source._observers = [node];
|
|
746
825
|
else
|
|
@@ -757,6 +836,21 @@ function update(node) {
|
|
|
757
836
|
node._state = STATE_CLEAN;
|
|
758
837
|
}
|
|
759
838
|
}
|
|
839
|
+
function removeSourceObservers(node, index) {
|
|
840
|
+
let source;
|
|
841
|
+
let swap;
|
|
842
|
+
for (let i = index; i < node._sources.length; i++) {
|
|
843
|
+
source = ActiveTransition && ActiveTransition._sources.get(node._sources[i]) || node._sources[i];
|
|
844
|
+
if (source._observers) {
|
|
845
|
+
if ((swap = source._observers.indexOf(node)) !== -1) {
|
|
846
|
+
source._observers[swap] = source._observers[source._observers.length - 1];
|
|
847
|
+
source._observers.pop();
|
|
848
|
+
}
|
|
849
|
+
if (!source._observers.length)
|
|
850
|
+
Unobserved.push(source);
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
}
|
|
760
854
|
function isEqual(a, b) {
|
|
761
855
|
return a === b;
|
|
762
856
|
}
|
|
@@ -860,7 +954,7 @@ function compute(owner, fn, observer) {
|
|
|
860
954
|
currentMask = observer?._handlerMask ?? DEFAULT_FLAGS;
|
|
861
955
|
notStale = true;
|
|
862
956
|
try {
|
|
863
|
-
return fn(observer ? observer._value : void 0);
|
|
957
|
+
return fn.call(observer, observer ? observer._value : void 0);
|
|
864
958
|
} finally {
|
|
865
959
|
setOwner(prevOwner);
|
|
866
960
|
currentObserver = prevObserver;
|
|
@@ -884,10 +978,12 @@ var Effect = class extends Computation {
|
|
|
884
978
|
this._prevValue = initialValue;
|
|
885
979
|
this._type = options?.render ? EFFECT_RENDER : EFFECT_USER;
|
|
886
980
|
if (this._type === EFFECT_RENDER) {
|
|
887
|
-
this._compute = (p)
|
|
981
|
+
this._compute = function(p) {
|
|
982
|
+
return !this._cloned && clock > this._queue.created && !(this._stateFlags & ERROR_BIT) ? latest(() => compute2(p)) : compute2(p);
|
|
983
|
+
};
|
|
888
984
|
}
|
|
889
985
|
this._updateIfNecessary();
|
|
890
|
-
!options?.defer && (this._type === EFFECT_USER ?
|
|
986
|
+
!options?.defer && (this._type === EFFECT_USER ? this._queue.enqueue(this._type, this._run.bind(this)) : this._run(this._type));
|
|
891
987
|
if (!this._parent)
|
|
892
988
|
console.warn("Effects created outside a reactive context will never be disposed");
|
|
893
989
|
}
|
|
@@ -895,28 +991,26 @@ var Effect = class extends Computation {
|
|
|
895
991
|
if (this._state == STATE_DIRTY) {
|
|
896
992
|
this._stateFlags = flags;
|
|
897
993
|
if (this._type === EFFECT_RENDER) {
|
|
898
|
-
|
|
994
|
+
this._queue.notify(this, LOADING_BIT | ERROR_BIT, this._stateFlags);
|
|
899
995
|
}
|
|
900
996
|
}
|
|
901
997
|
if (value === UNCHANGED)
|
|
902
998
|
return this._value;
|
|
903
999
|
this._value = value;
|
|
904
1000
|
this._modified = true;
|
|
1001
|
+
this._error = void 0;
|
|
905
1002
|
return value;
|
|
906
1003
|
}
|
|
907
1004
|
_notify(state, skipQueue) {
|
|
908
|
-
if (ActiveTransition && ActiveTransition._sources.has(this)) {
|
|
909
|
-
return ActiveTransition._sources.get(this)._notify(state, skipQueue);
|
|
910
|
-
}
|
|
911
1005
|
if (this._state >= state || skipQueue)
|
|
912
1006
|
return;
|
|
913
1007
|
if (this._state === STATE_CLEAN)
|
|
914
|
-
|
|
1008
|
+
this._queue.enqueue(this._type, this._run.bind(this));
|
|
915
1009
|
this._state = state;
|
|
916
1010
|
}
|
|
917
1011
|
_notifyFlags(mask, newFlags2) {
|
|
918
|
-
if (
|
|
919
|
-
if (this._state >=
|
|
1012
|
+
if (this._cloned) {
|
|
1013
|
+
if (this._state >= STATE_DIRTY)
|
|
920
1014
|
return;
|
|
921
1015
|
if (mask & 3) {
|
|
922
1016
|
this._notify(STATE_DIRTY);
|
|
@@ -927,7 +1021,7 @@ var Effect = class extends Computation {
|
|
|
927
1021
|
}
|
|
928
1022
|
_setError(error) {
|
|
929
1023
|
this._error = error;
|
|
930
|
-
|
|
1024
|
+
this._queue.notify(this, LOADING_BIT, 0);
|
|
931
1025
|
this._stateFlags = ERROR_BIT;
|
|
932
1026
|
if (this._type === EFFECT_USER) {
|
|
933
1027
|
try {
|
|
@@ -939,7 +1033,7 @@ var Effect = class extends Computation {
|
|
|
939
1033
|
error = e;
|
|
940
1034
|
}
|
|
941
1035
|
}
|
|
942
|
-
if (!
|
|
1036
|
+
if (!this._queue.notify(this, ERROR_BIT, ERROR_BIT))
|
|
943
1037
|
throw error;
|
|
944
1038
|
}
|
|
945
1039
|
_disposeNode() {
|
|
@@ -954,16 +1048,17 @@ var Effect = class extends Computation {
|
|
|
954
1048
|
}
|
|
955
1049
|
_run(type) {
|
|
956
1050
|
if (type) {
|
|
957
|
-
|
|
958
|
-
|
|
1051
|
+
const effect = this._cloned || this;
|
|
1052
|
+
if (effect._modified && effect._state !== STATE_DISPOSED) {
|
|
1053
|
+
effect._cleanup?.();
|
|
959
1054
|
try {
|
|
960
|
-
|
|
1055
|
+
effect._cleanup = effect._effect(effect._value, effect._prevValue);
|
|
961
1056
|
} catch (e) {
|
|
962
|
-
if (!
|
|
1057
|
+
if (!effect._queue.notify(effect, ERROR_BIT, ERROR_BIT))
|
|
963
1058
|
throw e;
|
|
964
1059
|
} finally {
|
|
965
|
-
|
|
966
|
-
|
|
1060
|
+
effect._prevValue = effect._value;
|
|
1061
|
+
effect._modified = false;
|
|
967
1062
|
}
|
|
968
1063
|
}
|
|
969
1064
|
} else
|
|
@@ -978,13 +1073,10 @@ var EagerComputation = class extends Computation {
|
|
|
978
1073
|
console.warn("Eager Computations created outside a reactive context will never be disposed");
|
|
979
1074
|
}
|
|
980
1075
|
_notify(state, skipQueue) {
|
|
981
|
-
if (ActiveTransition && ActiveTransition._sources.has(this)) {
|
|
982
|
-
return ActiveTransition._sources.get(this)._notify(state, skipQueue);
|
|
983
|
-
}
|
|
984
1076
|
if (this._state >= state && !this._forceNotify)
|
|
985
1077
|
return;
|
|
986
1078
|
if (!skipQueue && (this._state === STATE_CLEAN || this._state === STATE_CHECK && this._forceNotify))
|
|
987
|
-
|
|
1079
|
+
this._queue.enqueue(EFFECT_PURE, this._run.bind(this));
|
|
988
1080
|
super._notify(state, skipQueue);
|
|
989
1081
|
}
|
|
990
1082
|
_run() {
|
|
@@ -999,13 +1091,10 @@ var FirewallComputation = class extends Computation {
|
|
|
999
1091
|
console.warn("Eager Computations created outside a reactive context will never be disposed");
|
|
1000
1092
|
}
|
|
1001
1093
|
_notify(state, skipQueue) {
|
|
1002
|
-
if (ActiveTransition && ActiveTransition._sources.has(this)) {
|
|
1003
|
-
return ActiveTransition._sources.get(this)._notify(state, skipQueue);
|
|
1004
|
-
}
|
|
1005
1094
|
if (this._state >= state && !this._forceNotify)
|
|
1006
1095
|
return;
|
|
1007
1096
|
if (!skipQueue && (this._state === STATE_CLEAN || this._state === STATE_CHECK && this._forceNotify))
|
|
1008
|
-
|
|
1097
|
+
this._queue.enqueue(EFFECT_PURE, this._run.bind(this));
|
|
1009
1098
|
super._notify(state, true);
|
|
1010
1099
|
this._forceNotify = !!skipQueue;
|
|
1011
1100
|
}
|
|
@@ -1447,6 +1536,8 @@ function applyState(next, state, keyFn, all) {
|
|
|
1447
1536
|
}
|
|
1448
1537
|
function reconcile(value, key, all = false) {
|
|
1449
1538
|
return (state) => {
|
|
1539
|
+
if (state == null)
|
|
1540
|
+
throw new Error("Cannot reconcile null or undefined state");
|
|
1450
1541
|
const keyFn = typeof key === "string" ? (item) => item[key] : key;
|
|
1451
1542
|
const eq = keyFn(state);
|
|
1452
1543
|
if (eq !== void 0 && keyFn(value) !== keyFn(state))
|
|
@@ -1691,7 +1782,7 @@ function createMemo(compute2, value, options) {
|
|
|
1691
1782
|
return resolvedValue;
|
|
1692
1783
|
}
|
|
1693
1784
|
resolvedValue = node.wait();
|
|
1694
|
-
if (!node._sources?.length && node._nextSibling?._parent !== node) {
|
|
1785
|
+
if (!node._sources?.length && node._nextSibling?._parent !== node && !(node._stateFlags & UNINITIALIZED_BIT)) {
|
|
1695
1786
|
node.dispose();
|
|
1696
1787
|
node = void 0;
|
|
1697
1788
|
}
|
|
@@ -1752,9 +1843,13 @@ function createAsync(compute2, value, options) {
|
|
|
1752
1843
|
);
|
|
1753
1844
|
const read = node.wait.bind(node);
|
|
1754
1845
|
read.refresh = () => {
|
|
1755
|
-
|
|
1846
|
+
let n = node;
|
|
1847
|
+
if (ActiveTransition && !node._cloned) {
|
|
1848
|
+
n = cloneGraph(node);
|
|
1849
|
+
}
|
|
1850
|
+
n._state = STATE_DIRTY;
|
|
1756
1851
|
refreshing = true;
|
|
1757
|
-
|
|
1852
|
+
n._updateIfNecessary();
|
|
1758
1853
|
};
|
|
1759
1854
|
return read;
|
|
1760
1855
|
}
|
|
@@ -1835,7 +1930,7 @@ function createOptimistic(initial, compute2, key) {
|
|
|
1835
1930
|
(s) => {
|
|
1836
1931
|
const value = initial();
|
|
1837
1932
|
if (!ActiveTransition)
|
|
1838
|
-
|
|
1933
|
+
reconcile({ value }, key)(s);
|
|
1839
1934
|
},
|
|
1840
1935
|
{ value: void 0 }
|
|
1841
1936
|
);
|
|
@@ -1843,9 +1938,9 @@ function createOptimistic(initial, compute2, key) {
|
|
|
1843
1938
|
[store, setStore] = createStore({ value: initial });
|
|
1844
1939
|
const reset = () => setStore(
|
|
1845
1940
|
(s) => reconcile(
|
|
1846
|
-
typeof initial === "function" ? initial() : initial,
|
|
1941
|
+
{ value: typeof initial === "function" ? initial() : initial },
|
|
1847
1942
|
key
|
|
1848
|
-
)(s
|
|
1943
|
+
)(s)
|
|
1849
1944
|
);
|
|
1850
1945
|
let lastChange = void 0;
|
|
1851
1946
|
function write(v) {
|
|
@@ -2104,6 +2199,8 @@ var ConditionalQueue = class extends Queue {
|
|
|
2104
2199
|
return super.run(type);
|
|
2105
2200
|
}
|
|
2106
2201
|
notify(node, type, flags) {
|
|
2202
|
+
if (ActiveTransition && ActiveTransition._clonedQueues.has(this))
|
|
2203
|
+
return ActiveTransition._clonedQueues.get(this).notify(node, type, flags);
|
|
2107
2204
|
if (this._disabled.read()) {
|
|
2108
2205
|
if (type & LOADING_BIT) {
|
|
2109
2206
|
if (flags & LOADING_BIT) {
|
|
@@ -2122,6 +2219,11 @@ var ConditionalQueue = class extends Queue {
|
|
|
2122
2219
|
}
|
|
2123
2220
|
return type ? super.notify(node, type, flags) : true;
|
|
2124
2221
|
}
|
|
2222
|
+
merge(queue) {
|
|
2223
|
+
queue._pendingNodes.forEach((n) => this.notify(n, LOADING_BIT, LOADING_BIT));
|
|
2224
|
+
queue._errorNodes.forEach((n) => this.notify(n, ERROR_BIT, ERROR_BIT));
|
|
2225
|
+
super.merge(queue);
|
|
2226
|
+
}
|
|
2125
2227
|
};
|
|
2126
2228
|
var CollectionQueue = class extends Queue {
|
|
2127
2229
|
_collectionType;
|
|
@@ -2137,6 +2239,8 @@ var CollectionQueue = class extends Queue {
|
|
|
2137
2239
|
return super.run(type);
|
|
2138
2240
|
}
|
|
2139
2241
|
notify(node, type, flags) {
|
|
2242
|
+
if (ActiveTransition && ActiveTransition._clonedQueues.has(this))
|
|
2243
|
+
return ActiveTransition._clonedQueues.get(this).notify(node, type, flags);
|
|
2140
2244
|
if (!(type & this._collectionType))
|
|
2141
2245
|
return super.notify(node, type, flags);
|
|
2142
2246
|
if (flags & this._collectionType) {
|
|
@@ -2151,6 +2255,10 @@ var CollectionQueue = class extends Queue {
|
|
|
2151
2255
|
type &= ~this._collectionType;
|
|
2152
2256
|
return type ? super.notify(node, type, flags) : true;
|
|
2153
2257
|
}
|
|
2258
|
+
merge(queue) {
|
|
2259
|
+
queue._nodes.forEach((n) => this.notify(n, this._collectionType, this._collectionType));
|
|
2260
|
+
super.merge(queue);
|
|
2261
|
+
}
|
|
2154
2262
|
};
|
|
2155
2263
|
function createBoundary(fn, condition) {
|
|
2156
2264
|
const owner = new Owner();
|
|
@@ -2188,17 +2296,19 @@ function createSuspense(fn, fallback) {
|
|
|
2188
2296
|
return createCollectionBoundary(LOADING_BIT, fn, () => fallback());
|
|
2189
2297
|
}
|
|
2190
2298
|
function createErrorBoundary(fn, fallback) {
|
|
2191
|
-
return createCollectionBoundary(
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2299
|
+
return createCollectionBoundary(ERROR_BIT, fn, (queue) => {
|
|
2300
|
+
let node = queue._nodes.values().next().value;
|
|
2301
|
+
ActiveTransition && ActiveTransition._sources.has(node) && (node = ActiveTransition._sources.get(node));
|
|
2302
|
+
return fallback(node._error, () => {
|
|
2195
2303
|
incrementClock();
|
|
2196
|
-
for (let
|
|
2197
|
-
|
|
2198
|
-
|
|
2304
|
+
for (let node2 of queue._nodes) {
|
|
2305
|
+
if (ActiveTransition && !node2._cloned)
|
|
2306
|
+
node2 = cloneGraph(node2);
|
|
2307
|
+
node2._state = STATE_DIRTY;
|
|
2308
|
+
node2._queue?.enqueue(node2._type, node2._run.bind(node2));
|
|
2199
2309
|
}
|
|
2200
|
-
})
|
|
2201
|
-
);
|
|
2310
|
+
});
|
|
2311
|
+
});
|
|
2202
2312
|
}
|
|
2203
2313
|
function flatten(children, options) {
|
|
2204
2314
|
if (typeof children === "function" && !children.length) {
|