@solidjs/signals 0.0.6 → 0.0.8
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 +222 -82
- package/dist/node.cjs +501 -357
- package/dist/prod.js +494 -357
- package/dist/types/core/core.d.ts +13 -9
- package/dist/types/core/effect.d.ts +7 -4
- package/dist/types/core/error.d.ts +3 -0
- package/dist/types/core/index.d.ts +2 -2
- package/dist/types/core/scheduler.d.ts +2 -3
- package/dist/types/core/suspense.d.ts +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/map.d.ts +9 -1
- package/dist/types/signals.d.ts +24 -3
- package/dist/types/store/index.d.ts +2 -1
- package/dist/types/store/projection.d.ts +6 -0
- package/dist/types/store/store.d.ts +0 -6
- package/package.json +1 -1
package/dist/dev.js
CHANGED
|
@@ -13,6 +13,15 @@ var ContextNotFoundError = class extends Error {
|
|
|
13
13
|
);
|
|
14
14
|
}
|
|
15
15
|
};
|
|
16
|
+
var EffectError = class extends Error {
|
|
17
|
+
constructor(effect, cause) {
|
|
18
|
+
super(`Uncaught error while running effect:
|
|
19
|
+
|
|
20
|
+
${effect.toString()}
|
|
21
|
+
` );
|
|
22
|
+
this.cause = cause;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
16
25
|
|
|
17
26
|
// src/core/constants.ts
|
|
18
27
|
var STATE_CLEAN = 0;
|
|
@@ -242,6 +251,9 @@ var updateCheck = null;
|
|
|
242
251
|
function getObserver() {
|
|
243
252
|
return currentObserver;
|
|
244
253
|
}
|
|
254
|
+
function getClock() {
|
|
255
|
+
return clock;
|
|
256
|
+
}
|
|
245
257
|
function incrementClock() {
|
|
246
258
|
clock++;
|
|
247
259
|
}
|
|
@@ -261,9 +273,9 @@ var Computation = class extends Owner {
|
|
|
261
273
|
_stateFlags = 0;
|
|
262
274
|
/** Which flags raised by sources are handled, vs. being passed through. */
|
|
263
275
|
_handlerMask = DEFAULT_FLAGS;
|
|
264
|
-
_error = null;
|
|
265
276
|
_loading = null;
|
|
266
277
|
_time = -1;
|
|
278
|
+
_forceNotify = false;
|
|
267
279
|
constructor(initialValue, compute2, options) {
|
|
268
280
|
super(compute2 === null);
|
|
269
281
|
this._compute = compute2;
|
|
@@ -302,6 +314,9 @@ var Computation = class extends Owner {
|
|
|
302
314
|
* before continuing
|
|
303
315
|
*/
|
|
304
316
|
wait() {
|
|
317
|
+
if (this._compute && this._stateFlags & ERROR_BIT && this._time <= clock) {
|
|
318
|
+
update(this);
|
|
319
|
+
}
|
|
305
320
|
if (!syncResolve && this.loading()) {
|
|
306
321
|
throw new NotReadyError();
|
|
307
322
|
}
|
|
@@ -320,16 +335,6 @@ var Computation = class extends Owner {
|
|
|
320
335
|
}
|
|
321
336
|
return this._loading.read();
|
|
322
337
|
}
|
|
323
|
-
/**
|
|
324
|
-
* Return true if the computation is the computation threw an error
|
|
325
|
-
* Triggers re-execution of the computation when the error state changes
|
|
326
|
-
*/
|
|
327
|
-
error() {
|
|
328
|
-
if (this._error === null) {
|
|
329
|
-
this._error = errorState(this);
|
|
330
|
-
}
|
|
331
|
-
return this._error.read();
|
|
332
|
-
}
|
|
333
338
|
/** Update the computation with a new value. */
|
|
334
339
|
write(value, flags = 0, raw = false) {
|
|
335
340
|
const newValue = !raw && typeof value === "function" ? value(this._value) : value;
|
|
@@ -353,13 +358,14 @@ var Computation = class extends Owner {
|
|
|
353
358
|
/**
|
|
354
359
|
* Set the current node's state, and recursively mark all of this node's observers as STATE_CHECK
|
|
355
360
|
*/
|
|
356
|
-
_notify(state) {
|
|
357
|
-
if (this._state >= state)
|
|
361
|
+
_notify(state, skipQueue) {
|
|
362
|
+
if (this._state >= state && !this._forceNotify)
|
|
358
363
|
return;
|
|
364
|
+
this._forceNotify = !!skipQueue;
|
|
359
365
|
this._state = state;
|
|
360
366
|
if (this._observers) {
|
|
361
367
|
for (let i = 0; i < this._observers.length; i++) {
|
|
362
|
-
this._observers[i]._notify(STATE_CHECK);
|
|
368
|
+
this._observers[i]._notify(STATE_CHECK, skipQueue);
|
|
363
369
|
}
|
|
364
370
|
}
|
|
365
371
|
}
|
|
@@ -392,7 +398,7 @@ var Computation = class extends Owner {
|
|
|
392
398
|
}
|
|
393
399
|
}
|
|
394
400
|
_setError(error) {
|
|
395
|
-
this.write(error, this._stateFlags | ERROR_BIT);
|
|
401
|
+
this.write(error, this._stateFlags & ~LOADING_BIT | ERROR_BIT);
|
|
396
402
|
}
|
|
397
403
|
/**
|
|
398
404
|
* This is the core part of the reactivity system, which makes sure that the values are updated
|
|
@@ -452,22 +458,6 @@ function loadingState(node) {
|
|
|
452
458
|
setOwner(prevOwner);
|
|
453
459
|
return computation;
|
|
454
460
|
}
|
|
455
|
-
function errorState(node) {
|
|
456
|
-
const prevOwner = setOwner(node._parent);
|
|
457
|
-
const options = { name: node._name ? `error ${node._name}` : "error" } ;
|
|
458
|
-
const computation = new Computation(
|
|
459
|
-
void 0,
|
|
460
|
-
() => {
|
|
461
|
-
track(node);
|
|
462
|
-
node._updateIfNecessary();
|
|
463
|
-
return !!(node._stateFlags & ERROR_BIT);
|
|
464
|
-
},
|
|
465
|
-
options
|
|
466
|
-
);
|
|
467
|
-
computation._handlerMask = ERROR_BIT;
|
|
468
|
-
setOwner(prevOwner);
|
|
469
|
-
return computation;
|
|
470
|
-
}
|
|
471
461
|
function track(computation) {
|
|
472
462
|
if (currentObserver) {
|
|
473
463
|
if (!newSources && currentObserver._sources && currentObserver._sources[newSourcesIndex] === computation) {
|
|
@@ -525,6 +515,7 @@ function update(node) {
|
|
|
525
515
|
newSources = prevSources;
|
|
526
516
|
newSourcesIndex = prevSourcesIndex;
|
|
527
517
|
newFlags = prevFlags;
|
|
518
|
+
node._time = clock + 1;
|
|
528
519
|
node._state = STATE_CLEAN;
|
|
529
520
|
}
|
|
530
521
|
}
|
|
@@ -568,7 +559,7 @@ function isPending(fn) {
|
|
|
568
559
|
return e instanceof NotReadyError;
|
|
569
560
|
}
|
|
570
561
|
}
|
|
571
|
-
function
|
|
562
|
+
function resolveSync(fn) {
|
|
572
563
|
const prevFlags = newFlags;
|
|
573
564
|
syncResolve = true;
|
|
574
565
|
try {
|
|
@@ -579,6 +570,15 @@ function latest(fn) {
|
|
|
579
570
|
syncResolve = false;
|
|
580
571
|
}
|
|
581
572
|
}
|
|
573
|
+
function catchError(fn) {
|
|
574
|
+
try {
|
|
575
|
+
fn();
|
|
576
|
+
} catch (e) {
|
|
577
|
+
if (e instanceof NotReadyError)
|
|
578
|
+
throw e;
|
|
579
|
+
return e;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
582
|
function compute(owner, compute2, observer) {
|
|
583
583
|
const prevOwner = setOwner(owner), prevObserver = currentObserver, prevMask = currentMask;
|
|
584
584
|
currentObserver = observer;
|
|
@@ -622,16 +622,20 @@ var Queue = class {
|
|
|
622
622
|
runEffectQueue(effects);
|
|
623
623
|
}
|
|
624
624
|
}
|
|
625
|
+
let rerun = false;
|
|
625
626
|
for (let i = 0; i < this._children.length; i++) {
|
|
626
|
-
this._children[i].run(type);
|
|
627
|
+
rerun = this._children[i].run(type) || rerun;
|
|
627
628
|
}
|
|
629
|
+
if (type === EFFECT_PURE && this._queues[type].length)
|
|
630
|
+
return true;
|
|
628
631
|
}
|
|
629
632
|
flush() {
|
|
630
633
|
if (this._running)
|
|
631
634
|
return;
|
|
632
635
|
this._running = true;
|
|
633
636
|
try {
|
|
634
|
-
this.run(EFFECT_PURE)
|
|
637
|
+
while (this.run(EFFECT_PURE)) {
|
|
638
|
+
}
|
|
635
639
|
incrementClock();
|
|
636
640
|
scheduled = false;
|
|
637
641
|
this.run(EFFECT_RENDER);
|
|
@@ -650,22 +654,14 @@ var Queue = class {
|
|
|
650
654
|
}
|
|
651
655
|
};
|
|
652
656
|
var globalQueue = new Queue();
|
|
653
|
-
var globalTasks = [];
|
|
654
657
|
function flushSync() {
|
|
655
658
|
let count = 0;
|
|
656
659
|
while (scheduled) {
|
|
657
660
|
if (++count === 1e5)
|
|
658
661
|
throw new Error("Potential Infinite Loop Detected.");
|
|
659
662
|
globalQueue.flush();
|
|
660
|
-
for (let i = 0; i < globalTasks.length; i++)
|
|
661
|
-
globalTasks[i]();
|
|
662
|
-
globalTasks.length = 0;
|
|
663
663
|
}
|
|
664
664
|
}
|
|
665
|
-
function queueTask(fn) {
|
|
666
|
-
globalTasks.push(fn);
|
|
667
|
-
schedule();
|
|
668
|
-
}
|
|
669
665
|
function createBoundary(fn, queue) {
|
|
670
666
|
const owner = new Owner();
|
|
671
667
|
const parentQueue = owner._queue || globalQueue;
|
|
@@ -699,18 +695,23 @@ function runEffectQueue(queue) {
|
|
|
699
695
|
// src/core/effect.ts
|
|
700
696
|
var Effect = class extends Computation {
|
|
701
697
|
_effect;
|
|
698
|
+
_error;
|
|
699
|
+
_cleanup;
|
|
702
700
|
_modified = false;
|
|
703
701
|
_prevValue;
|
|
704
702
|
_type;
|
|
705
703
|
_queue;
|
|
706
|
-
constructor(initialValue, compute2, effect, options) {
|
|
704
|
+
constructor(initialValue, compute2, effect, error, options) {
|
|
707
705
|
super(initialValue, compute2, options);
|
|
708
706
|
this._effect = effect;
|
|
707
|
+
this._error = error;
|
|
709
708
|
this._prevValue = initialValue;
|
|
710
709
|
this._type = options?.render ? EFFECT_RENDER : EFFECT_USER;
|
|
711
710
|
this._queue = getOwner()?._queue || globalQueue;
|
|
712
|
-
|
|
713
|
-
|
|
711
|
+
if (!options?.defer) {
|
|
712
|
+
this._updateIfNecessary();
|
|
713
|
+
this._type === EFFECT_USER ? this._queue.enqueue(this._type, this) : this._runEffect();
|
|
714
|
+
}
|
|
714
715
|
if (!this._parent)
|
|
715
716
|
console.warn("Effects created outside a reactive context will never be disposed");
|
|
716
717
|
}
|
|
@@ -726,26 +727,49 @@ var Effect = class extends Computation {
|
|
|
726
727
|
this._modified = true;
|
|
727
728
|
return value;
|
|
728
729
|
}
|
|
729
|
-
_notify(state) {
|
|
730
|
-
if (this._state >= state)
|
|
730
|
+
_notify(state, skipQueue) {
|
|
731
|
+
if (this._state >= state || skipQueue)
|
|
731
732
|
return;
|
|
732
733
|
if (this._state === STATE_CLEAN)
|
|
733
734
|
this._queue.enqueue(this._type, this);
|
|
734
735
|
this._state = state;
|
|
735
736
|
}
|
|
736
737
|
_setError(error) {
|
|
738
|
+
this._cleanup?.();
|
|
739
|
+
if (this._stateFlags & LOADING_BIT) {
|
|
740
|
+
this._stateFlags = 0;
|
|
741
|
+
this._queue._update?.(this);
|
|
742
|
+
}
|
|
743
|
+
if (this._type === EFFECT_USER) {
|
|
744
|
+
try {
|
|
745
|
+
return this._error ? this._cleanup = this._error(error) : console.error(new EffectError(this._effect, error));
|
|
746
|
+
} catch (e) {
|
|
747
|
+
error = e;
|
|
748
|
+
}
|
|
749
|
+
}
|
|
737
750
|
this.handleError(error);
|
|
738
751
|
}
|
|
739
752
|
_disposeNode() {
|
|
753
|
+
if (this._state === STATE_DISPOSED)
|
|
754
|
+
return;
|
|
740
755
|
this._effect = void 0;
|
|
741
756
|
this._prevValue = void 0;
|
|
757
|
+
this._error = void 0;
|
|
758
|
+
this._cleanup?.();
|
|
759
|
+
this._cleanup = void 0;
|
|
742
760
|
super._disposeNode();
|
|
743
761
|
}
|
|
744
762
|
_runEffect() {
|
|
745
763
|
if (this._modified && this._state !== STATE_DISPOSED) {
|
|
746
|
-
this.
|
|
747
|
-
|
|
748
|
-
|
|
764
|
+
this._cleanup?.();
|
|
765
|
+
try {
|
|
766
|
+
this._cleanup = this._effect(this._value, this._prevValue);
|
|
767
|
+
} catch (e) {
|
|
768
|
+
this.handleError(e);
|
|
769
|
+
} finally {
|
|
770
|
+
this._prevValue = this._value;
|
|
771
|
+
this._modified = false;
|
|
772
|
+
}
|
|
749
773
|
}
|
|
750
774
|
}
|
|
751
775
|
};
|
|
@@ -758,12 +782,12 @@ var EagerComputation = class extends Computation {
|
|
|
758
782
|
if (!this._parent)
|
|
759
783
|
console.warn("Eager Computations created outside a reactive context will never be disposed");
|
|
760
784
|
}
|
|
761
|
-
_notify(state) {
|
|
762
|
-
if (this._state >= state)
|
|
785
|
+
_notify(state, skipQueue) {
|
|
786
|
+
if (this._state >= state && !this._forceNotify)
|
|
763
787
|
return;
|
|
764
|
-
if (this._state === STATE_CLEAN)
|
|
788
|
+
if (this._state === STATE_CLEAN && !skipQueue)
|
|
765
789
|
this._queue.enqueue(EFFECT_PURE, this);
|
|
766
|
-
super._notify(state);
|
|
790
|
+
super._notify(state, skipQueue);
|
|
767
791
|
}
|
|
768
792
|
};
|
|
769
793
|
|
|
@@ -775,20 +799,20 @@ var SuspenseQueue = class extends Queue {
|
|
|
775
799
|
run(type) {
|
|
776
800
|
if (type && this._fallback)
|
|
777
801
|
return;
|
|
778
|
-
super.run(type);
|
|
802
|
+
return super.run(type);
|
|
779
803
|
}
|
|
780
804
|
_update(node) {
|
|
781
805
|
if (node._stateFlags & LOADING_BIT) {
|
|
782
806
|
this._nodes.add(node);
|
|
783
807
|
if (!this._fallback) {
|
|
784
808
|
this._fallback = true;
|
|
785
|
-
|
|
809
|
+
this._signal.write(true);
|
|
786
810
|
}
|
|
787
811
|
} else {
|
|
788
812
|
this._nodes.delete(node);
|
|
789
813
|
if (this._nodes.size === 0) {
|
|
790
814
|
this._fallback = false;
|
|
791
|
-
|
|
815
|
+
this._signal.write(false);
|
|
792
816
|
}
|
|
793
817
|
}
|
|
794
818
|
}
|
|
@@ -870,6 +894,14 @@ function createAsync(compute2, value, options) {
|
|
|
870
894
|
};
|
|
871
895
|
}
|
|
872
896
|
const signal = new Computation(value2, null, options);
|
|
897
|
+
const w = signal.wait;
|
|
898
|
+
signal.wait = function() {
|
|
899
|
+
if (signal._stateFlags & ERROR_BIT && signal._time <= getClock()) {
|
|
900
|
+
lhs._notify(STATE_DIRTY);
|
|
901
|
+
throw new NotReadyError();
|
|
902
|
+
}
|
|
903
|
+
return w.call(this);
|
|
904
|
+
};
|
|
873
905
|
signal.write(UNCHANGED, LOADING_BIT);
|
|
874
906
|
if (isPromise) {
|
|
875
907
|
source.then(
|
|
@@ -900,16 +932,17 @@ function createAsync(compute2, value, options) {
|
|
|
900
932
|
);
|
|
901
933
|
return () => lhs.wait().wait();
|
|
902
934
|
}
|
|
903
|
-
function createEffect(compute2, effect, value, options) {
|
|
935
|
+
function createEffect(compute2, effect, error, value, options) {
|
|
904
936
|
void new Effect(
|
|
905
937
|
value,
|
|
906
938
|
compute2,
|
|
907
939
|
effect,
|
|
940
|
+
error,
|
|
908
941
|
{ name: options?.name ?? "effect" }
|
|
909
942
|
);
|
|
910
943
|
}
|
|
911
944
|
function createRenderEffect(compute2, effect, value, options) {
|
|
912
|
-
void new Effect(value, compute2, effect, {
|
|
945
|
+
void new Effect(value, compute2, effect, void 0, {
|
|
913
946
|
render: true,
|
|
914
947
|
...{ name: options?.name ?? "effect" }
|
|
915
948
|
});
|
|
@@ -957,6 +990,71 @@ function createErrorBoundary(fn, fallback) {
|
|
|
957
990
|
});
|
|
958
991
|
return decision.read.bind(decision);
|
|
959
992
|
}
|
|
993
|
+
function resolve(fn) {
|
|
994
|
+
return new Promise((res, rej) => {
|
|
995
|
+
let node = new EagerComputation(void 0, () => {
|
|
996
|
+
try {
|
|
997
|
+
res(fn());
|
|
998
|
+
} catch (err) {
|
|
999
|
+
if (err instanceof NotReadyError)
|
|
1000
|
+
throw err;
|
|
1001
|
+
rej(err);
|
|
1002
|
+
}
|
|
1003
|
+
node.dispose(true);
|
|
1004
|
+
});
|
|
1005
|
+
});
|
|
1006
|
+
}
|
|
1007
|
+
function createReaction(effect, error, options) {
|
|
1008
|
+
const node = new Effect(void 0, () => {
|
|
1009
|
+
}, effect, error, {
|
|
1010
|
+
defer: true,
|
|
1011
|
+
...{ name: options?.name ?? "reaction" }
|
|
1012
|
+
});
|
|
1013
|
+
return (tracking) => {
|
|
1014
|
+
node._compute = tracking;
|
|
1015
|
+
node._state = STATE_DIRTY;
|
|
1016
|
+
node._updateIfNecessary();
|
|
1017
|
+
node._compute = null;
|
|
1018
|
+
};
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
// src/store/projection.ts
|
|
1022
|
+
var ProjectionComputation = class extends EagerComputation {
|
|
1023
|
+
_notify(state, skipQueue) {
|
|
1024
|
+
if (this._state >= state && !this._forceNotify)
|
|
1025
|
+
return;
|
|
1026
|
+
if (this._state === STATE_CLEAN && !skipQueue)
|
|
1027
|
+
this._queue.enqueue(EFFECT_PURE, this);
|
|
1028
|
+
super._notify(state, true);
|
|
1029
|
+
}
|
|
1030
|
+
};
|
|
1031
|
+
function createProjection(fn, initialValue = {}) {
|
|
1032
|
+
const [store, setStore] = createStore(initialValue);
|
|
1033
|
+
const node = new ProjectionComputation(void 0, () => {
|
|
1034
|
+
setStore(fn);
|
|
1035
|
+
});
|
|
1036
|
+
const wrapped = /* @__PURE__ */ new WeakMap();
|
|
1037
|
+
return wrap(store, node, wrapped);
|
|
1038
|
+
}
|
|
1039
|
+
function wrap(source, node, wrapped) {
|
|
1040
|
+
if (wrapped.has(source))
|
|
1041
|
+
return wrapped.get(source);
|
|
1042
|
+
const wrap3 = new Proxy(source, {
|
|
1043
|
+
get(target, property) {
|
|
1044
|
+
node.read();
|
|
1045
|
+
const v = target[property];
|
|
1046
|
+
return isWrappable(v) ? wrap3(v, node, wrapped) : v;
|
|
1047
|
+
},
|
|
1048
|
+
set() {
|
|
1049
|
+
throw new Error("Projections are readonly");
|
|
1050
|
+
},
|
|
1051
|
+
deleteProperty() {
|
|
1052
|
+
throw new Error("Projections are readonly");
|
|
1053
|
+
}
|
|
1054
|
+
});
|
|
1055
|
+
wrapped.set(source, wrap3);
|
|
1056
|
+
return wrap3;
|
|
1057
|
+
}
|
|
960
1058
|
|
|
961
1059
|
// src/store/store.ts
|
|
962
1060
|
var $RAW = Symbol("STORE_RAW" );
|
|
@@ -966,7 +1064,7 @@ var $PROXY = Symbol("STORE_PROXY" );
|
|
|
966
1064
|
var STORE_VALUE = "v";
|
|
967
1065
|
var STORE_NODE = "n";
|
|
968
1066
|
var STORE_HAS = "h";
|
|
969
|
-
function
|
|
1067
|
+
function wrap2(value) {
|
|
970
1068
|
let p = value[$PROXY];
|
|
971
1069
|
if (!p) {
|
|
972
1070
|
let target;
|
|
@@ -1075,7 +1173,7 @@ var proxyTraps = {
|
|
|
1075
1173
|
}
|
|
1076
1174
|
if (Writing.has(storeValue)) {
|
|
1077
1175
|
const value2 = tracked ? tracked._value : storeValue[property];
|
|
1078
|
-
return isWrappable(value2) ? (Writing.add(value2[$RAW] || value2),
|
|
1176
|
+
return isWrappable(value2) ? (Writing.add(value2[$RAW] || value2), wrap2(value2)) : value2;
|
|
1079
1177
|
}
|
|
1080
1178
|
let value = tracked ? nodes[property].read() : storeValue[property];
|
|
1081
1179
|
if (!tracked) {
|
|
@@ -1083,10 +1181,10 @@ var proxyTraps = {
|
|
|
1083
1181
|
let proto;
|
|
1084
1182
|
return !Array.isArray(storeValue) && (proto = Object.getPrototypeOf(storeValue)) && proto !== Object.prototype ? value.bind(storeValue) : value;
|
|
1085
1183
|
} else if (getObserver()) {
|
|
1086
|
-
value = getNode(nodes, property, isWrappable(value) ?
|
|
1184
|
+
value = getNode(nodes, property, isWrappable(value) ? wrap2(value) : value).read();
|
|
1087
1185
|
}
|
|
1088
1186
|
}
|
|
1089
|
-
return isWrappable(value) ?
|
|
1187
|
+
return isWrappable(value) ? wrap2(value) : value;
|
|
1090
1188
|
},
|
|
1091
1189
|
has(target, property) {
|
|
1092
1190
|
if (property === $RAW || property === $PROXY || property === $TRACK || property === "__proto__")
|
|
@@ -1128,13 +1226,16 @@ function setProperty(state, property, value, deleting = false) {
|
|
|
1128
1226
|
const nodes = getNodes(target, STORE_NODE);
|
|
1129
1227
|
let node;
|
|
1130
1228
|
if (node = nodes[property])
|
|
1131
|
-
node.write(isWrappable(value) ?
|
|
1229
|
+
node.write(isWrappable(value) ? wrap2(value) : value);
|
|
1132
1230
|
Array.isArray(state) && state.length !== len && (node = nodes.length) && node.write(state.length);
|
|
1133
1231
|
(node = nodes[$TRACK]) && node.write(void 0);
|
|
1134
1232
|
}
|
|
1135
1233
|
function createStore(first, second) {
|
|
1136
|
-
const derived = typeof first === "function", store = derived ? second : first
|
|
1137
|
-
|
|
1234
|
+
const derived = typeof first === "function", store = derived ? second : first;
|
|
1235
|
+
if (derived)
|
|
1236
|
+
return createProjection(first, store);
|
|
1237
|
+
const unwrappedStore = unwrap(store, false);
|
|
1238
|
+
const wrappedStore = wrap2(unwrappedStore);
|
|
1138
1239
|
const setStore = (fn) => {
|
|
1139
1240
|
try {
|
|
1140
1241
|
Writing.add(unwrappedStore);
|
|
@@ -1143,15 +1244,8 @@ function createStore(first, second) {
|
|
|
1143
1244
|
Writing.clear();
|
|
1144
1245
|
}
|
|
1145
1246
|
};
|
|
1146
|
-
if (derived) {
|
|
1147
|
-
new EagerComputation(void 0, () => setStore(first));
|
|
1148
|
-
}
|
|
1149
1247
|
return [wrappedStore, setStore];
|
|
1150
1248
|
}
|
|
1151
|
-
function createProjection(fn, initialValue = {}) {
|
|
1152
|
-
const [store] = createStore(fn, initialValue);
|
|
1153
|
-
return store;
|
|
1154
|
-
}
|
|
1155
1249
|
|
|
1156
1250
|
// src/store/reconcile.ts
|
|
1157
1251
|
function applyState(next, state, keyFn) {
|
|
@@ -1172,7 +1266,7 @@ function applyState(next, state, keyFn) {
|
|
|
1172
1266
|
if (next.length && previous.length && next[0] && keyFn(next[0]) != null) {
|
|
1173
1267
|
let i, j, start, end, newEnd, item, newIndicesNext, keyVal;
|
|
1174
1268
|
for (start = 0, end = Math.min(previous.length, next.length); start < end && (previous[start] === next[start] || previous[start] && next[start] && keyFn(previous[start]) === keyFn(next[start])); start++) {
|
|
1175
|
-
applyState(next[start],
|
|
1269
|
+
applyState(next[start], wrap2(previous[start]), keyFn);
|
|
1176
1270
|
}
|
|
1177
1271
|
const temp = new Array(next.length), newIndices = /* @__PURE__ */ new Map();
|
|
1178
1272
|
for (end = previous.length - 1, newEnd = next.length - 1; end >= start && newEnd >= start && (previous[end] === next[newEnd] || previous[end] && next[newEnd] && keyFn(previous[end]) === keyFn(next[newEnd])); end--, newEnd--) {
|
|
@@ -1181,11 +1275,11 @@ function applyState(next, state, keyFn) {
|
|
|
1181
1275
|
if (start > newEnd || start > end) {
|
|
1182
1276
|
for (j = start; j <= newEnd; j++) {
|
|
1183
1277
|
changed = true;
|
|
1184
|
-
target[STORE_NODE][j]?.write(
|
|
1278
|
+
target[STORE_NODE][j]?.write(wrap2(next[j]));
|
|
1185
1279
|
}
|
|
1186
1280
|
for (; j < next.length; j++) {
|
|
1187
1281
|
changed = true;
|
|
1188
|
-
const wrapped =
|
|
1282
|
+
const wrapped = wrap2(temp[j]);
|
|
1189
1283
|
target[STORE_NODE][j]?.write(wrapped);
|
|
1190
1284
|
applyState(next[j], wrapped, keyFn);
|
|
1191
1285
|
}
|
|
@@ -1213,17 +1307,17 @@ function applyState(next, state, keyFn) {
|
|
|
1213
1307
|
}
|
|
1214
1308
|
for (j = start; j < next.length; j++) {
|
|
1215
1309
|
if (j in temp) {
|
|
1216
|
-
const wrapped =
|
|
1310
|
+
const wrapped = wrap2(temp[j]);
|
|
1217
1311
|
target[STORE_NODE][j]?.write(wrapped);
|
|
1218
1312
|
applyState(next[j], wrapped, keyFn);
|
|
1219
1313
|
} else
|
|
1220
|
-
target[STORE_NODE][j]?.write(
|
|
1314
|
+
target[STORE_NODE][j]?.write(wrap2(next[j]));
|
|
1221
1315
|
}
|
|
1222
1316
|
if (start < next.length)
|
|
1223
1317
|
changed = true;
|
|
1224
1318
|
} else if (previous.length && next.length) {
|
|
1225
1319
|
for (let i = 0, len = next.length; i < len; i++) {
|
|
1226
|
-
isWrappable(previous[i]) && applyState(next[i],
|
|
1320
|
+
isWrappable(previous[i]) && applyState(next[i], wrap2(previous[i]), keyFn);
|
|
1227
1321
|
}
|
|
1228
1322
|
}
|
|
1229
1323
|
if (previous.length !== next.length) {
|
|
@@ -1243,9 +1337,9 @@ function applyState(next, state, keyFn) {
|
|
|
1243
1337
|
if (previousValue === nextValue)
|
|
1244
1338
|
continue;
|
|
1245
1339
|
if (!previousValue || !isWrappable(previousValue) || keyFn(previousValue) != null && keyFn(previousValue) !== keyFn(nextValue))
|
|
1246
|
-
node.write(isWrappable(nextValue) ?
|
|
1340
|
+
node.write(isWrappable(nextValue) ? wrap2(nextValue) : nextValue);
|
|
1247
1341
|
else
|
|
1248
|
-
applyState(nextValue,
|
|
1342
|
+
applyState(nextValue, wrap2(previousValue), keyFn);
|
|
1249
1343
|
}
|
|
1250
1344
|
}
|
|
1251
1345
|
if (nodes = target[STORE_HAS]) {
|
|
@@ -1532,8 +1626,54 @@ function updateKeyedMap() {
|
|
|
1532
1626
|
});
|
|
1533
1627
|
return this._mappings;
|
|
1534
1628
|
}
|
|
1629
|
+
function repeat(count, map, options) {
|
|
1630
|
+
return updateRepeat.bind({
|
|
1631
|
+
_owner: new Owner(),
|
|
1632
|
+
_len: 0,
|
|
1633
|
+
_count: count,
|
|
1634
|
+
_map: map,
|
|
1635
|
+
_nodes: [],
|
|
1636
|
+
_mappings: [],
|
|
1637
|
+
_fallback: options?.fallback
|
|
1638
|
+
});
|
|
1639
|
+
}
|
|
1640
|
+
function updateRepeat() {
|
|
1641
|
+
const newLen = this._count();
|
|
1642
|
+
runWithOwner(this._owner, () => {
|
|
1643
|
+
if (newLen === 0) {
|
|
1644
|
+
if (this._len !== 0) {
|
|
1645
|
+
this._owner.dispose(false);
|
|
1646
|
+
this._nodes = [];
|
|
1647
|
+
this._mappings = [];
|
|
1648
|
+
this._len = 0;
|
|
1649
|
+
}
|
|
1650
|
+
if (this._fallback && !this._mappings[0]) {
|
|
1651
|
+
this._mappings[0] = compute(
|
|
1652
|
+
this._nodes[0] = new Owner(),
|
|
1653
|
+
this._fallback,
|
|
1654
|
+
null
|
|
1655
|
+
);
|
|
1656
|
+
}
|
|
1657
|
+
} else {
|
|
1658
|
+
if (this._len === 0 && this._nodes[0])
|
|
1659
|
+
this._nodes[0].dispose();
|
|
1660
|
+
for (let i = this._len; i < newLen; i++) {
|
|
1661
|
+
this._mappings[i] = compute(
|
|
1662
|
+
this._nodes[i] = new Owner(),
|
|
1663
|
+
() => this._map(i),
|
|
1664
|
+
null
|
|
1665
|
+
);
|
|
1666
|
+
}
|
|
1667
|
+
for (let i = newLen; i < this._len; i++)
|
|
1668
|
+
this._nodes[i].dispose();
|
|
1669
|
+
this._mappings = this._mappings.slice(0, newLen);
|
|
1670
|
+
this._len = newLen;
|
|
1671
|
+
}
|
|
1672
|
+
});
|
|
1673
|
+
return this._mappings;
|
|
1674
|
+
}
|
|
1535
1675
|
function compare(key, a, b) {
|
|
1536
1676
|
return key ? key(a) === key(b) : true;
|
|
1537
1677
|
}
|
|
1538
1678
|
|
|
1539
|
-
export { $PROXY, $RAW, $TARGET, $TRACK, Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, SUPPORTS_PROXY, createAsync, createBoundary, createContext, createEffect, createErrorBoundary, createMemo, createProjection, createRenderEffect, createRoot, createSignal, createStore, createSuspense, flatten, flushSync, getContext, getObserver, getOwner, hasContext, hasUpdated, isEqual, isPending, isWrappable,
|
|
1679
|
+
export { $PROXY, $RAW, $TARGET, $TRACK, Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, SUPPORTS_PROXY, catchError, createAsync, createBoundary, createContext, createEffect, createErrorBoundary, createMemo, createProjection, createReaction, createRenderEffect, createRoot, createSignal, createStore, createSuspense, flatten, flushSync, getContext, getObserver, getOwner, hasContext, hasUpdated, isEqual, isPending, isWrappable, mapArray, merge, omit, onCleanup, reconcile, repeat, resolve, resolveSync, runWithOwner, setContext, untrack, unwrap };
|