@solidjs/signals 0.0.7 → 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 +215 -80
- package/dist/node.cjs +495 -356
- package/dist/prod.js +488 -356
- 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 +0 -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;
|
|
@@ -636,7 +636,6 @@ var Queue = class {
|
|
|
636
636
|
try {
|
|
637
637
|
while (this.run(EFFECT_PURE)) {
|
|
638
638
|
}
|
|
639
|
-
;
|
|
640
639
|
incrementClock();
|
|
641
640
|
scheduled = false;
|
|
642
641
|
this.run(EFFECT_RENDER);
|
|
@@ -655,22 +654,14 @@ var Queue = class {
|
|
|
655
654
|
}
|
|
656
655
|
};
|
|
657
656
|
var globalQueue = new Queue();
|
|
658
|
-
var globalTasks = [];
|
|
659
657
|
function flushSync() {
|
|
660
658
|
let count = 0;
|
|
661
659
|
while (scheduled) {
|
|
662
660
|
if (++count === 1e5)
|
|
663
661
|
throw new Error("Potential Infinite Loop Detected.");
|
|
664
662
|
globalQueue.flush();
|
|
665
|
-
for (let i = 0; i < globalTasks.length; i++)
|
|
666
|
-
globalTasks[i]();
|
|
667
|
-
globalTasks.length = 0;
|
|
668
663
|
}
|
|
669
664
|
}
|
|
670
|
-
function queueTask(fn) {
|
|
671
|
-
globalTasks.push(fn);
|
|
672
|
-
schedule();
|
|
673
|
-
}
|
|
674
665
|
function createBoundary(fn, queue) {
|
|
675
666
|
const owner = new Owner();
|
|
676
667
|
const parentQueue = owner._queue || globalQueue;
|
|
@@ -704,18 +695,23 @@ function runEffectQueue(queue) {
|
|
|
704
695
|
// src/core/effect.ts
|
|
705
696
|
var Effect = class extends Computation {
|
|
706
697
|
_effect;
|
|
698
|
+
_error;
|
|
699
|
+
_cleanup;
|
|
707
700
|
_modified = false;
|
|
708
701
|
_prevValue;
|
|
709
702
|
_type;
|
|
710
703
|
_queue;
|
|
711
|
-
constructor(initialValue, compute2, effect, options) {
|
|
704
|
+
constructor(initialValue, compute2, effect, error, options) {
|
|
712
705
|
super(initialValue, compute2, options);
|
|
713
706
|
this._effect = effect;
|
|
707
|
+
this._error = error;
|
|
714
708
|
this._prevValue = initialValue;
|
|
715
709
|
this._type = options?.render ? EFFECT_RENDER : EFFECT_USER;
|
|
716
710
|
this._queue = getOwner()?._queue || globalQueue;
|
|
717
|
-
|
|
718
|
-
|
|
711
|
+
if (!options?.defer) {
|
|
712
|
+
this._updateIfNecessary();
|
|
713
|
+
this._type === EFFECT_USER ? this._queue.enqueue(this._type, this) : this._runEffect();
|
|
714
|
+
}
|
|
719
715
|
if (!this._parent)
|
|
720
716
|
console.warn("Effects created outside a reactive context will never be disposed");
|
|
721
717
|
}
|
|
@@ -731,26 +727,49 @@ var Effect = class extends Computation {
|
|
|
731
727
|
this._modified = true;
|
|
732
728
|
return value;
|
|
733
729
|
}
|
|
734
|
-
_notify(state) {
|
|
735
|
-
if (this._state >= state)
|
|
730
|
+
_notify(state, skipQueue) {
|
|
731
|
+
if (this._state >= state || skipQueue)
|
|
736
732
|
return;
|
|
737
733
|
if (this._state === STATE_CLEAN)
|
|
738
734
|
this._queue.enqueue(this._type, this);
|
|
739
735
|
this._state = state;
|
|
740
736
|
}
|
|
741
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
|
+
}
|
|
742
750
|
this.handleError(error);
|
|
743
751
|
}
|
|
744
752
|
_disposeNode() {
|
|
753
|
+
if (this._state === STATE_DISPOSED)
|
|
754
|
+
return;
|
|
745
755
|
this._effect = void 0;
|
|
746
756
|
this._prevValue = void 0;
|
|
757
|
+
this._error = void 0;
|
|
758
|
+
this._cleanup?.();
|
|
759
|
+
this._cleanup = void 0;
|
|
747
760
|
super._disposeNode();
|
|
748
761
|
}
|
|
749
762
|
_runEffect() {
|
|
750
763
|
if (this._modified && this._state !== STATE_DISPOSED) {
|
|
751
|
-
this.
|
|
752
|
-
|
|
753
|
-
|
|
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
|
+
}
|
|
754
773
|
}
|
|
755
774
|
}
|
|
756
775
|
};
|
|
@@ -763,12 +782,12 @@ var EagerComputation = class extends Computation {
|
|
|
763
782
|
if (!this._parent)
|
|
764
783
|
console.warn("Eager Computations created outside a reactive context will never be disposed");
|
|
765
784
|
}
|
|
766
|
-
_notify(state) {
|
|
767
|
-
if (this._state >= state)
|
|
785
|
+
_notify(state, skipQueue) {
|
|
786
|
+
if (this._state >= state && !this._forceNotify)
|
|
768
787
|
return;
|
|
769
|
-
if (this._state === STATE_CLEAN)
|
|
788
|
+
if (this._state === STATE_CLEAN && !skipQueue)
|
|
770
789
|
this._queue.enqueue(EFFECT_PURE, this);
|
|
771
|
-
super._notify(state);
|
|
790
|
+
super._notify(state, skipQueue);
|
|
772
791
|
}
|
|
773
792
|
};
|
|
774
793
|
|
|
@@ -787,13 +806,13 @@ var SuspenseQueue = class extends Queue {
|
|
|
787
806
|
this._nodes.add(node);
|
|
788
807
|
if (!this._fallback) {
|
|
789
808
|
this._fallback = true;
|
|
790
|
-
|
|
809
|
+
this._signal.write(true);
|
|
791
810
|
}
|
|
792
811
|
} else {
|
|
793
812
|
this._nodes.delete(node);
|
|
794
813
|
if (this._nodes.size === 0) {
|
|
795
814
|
this._fallback = false;
|
|
796
|
-
|
|
815
|
+
this._signal.write(false);
|
|
797
816
|
}
|
|
798
817
|
}
|
|
799
818
|
}
|
|
@@ -875,6 +894,14 @@ function createAsync(compute2, value, options) {
|
|
|
875
894
|
};
|
|
876
895
|
}
|
|
877
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
|
+
};
|
|
878
905
|
signal.write(UNCHANGED, LOADING_BIT);
|
|
879
906
|
if (isPromise) {
|
|
880
907
|
source.then(
|
|
@@ -905,16 +932,17 @@ function createAsync(compute2, value, options) {
|
|
|
905
932
|
);
|
|
906
933
|
return () => lhs.wait().wait();
|
|
907
934
|
}
|
|
908
|
-
function createEffect(compute2, effect, value, options) {
|
|
935
|
+
function createEffect(compute2, effect, error, value, options) {
|
|
909
936
|
void new Effect(
|
|
910
937
|
value,
|
|
911
938
|
compute2,
|
|
912
939
|
effect,
|
|
940
|
+
error,
|
|
913
941
|
{ name: options?.name ?? "effect" }
|
|
914
942
|
);
|
|
915
943
|
}
|
|
916
944
|
function createRenderEffect(compute2, effect, value, options) {
|
|
917
|
-
void new Effect(value, compute2, effect, {
|
|
945
|
+
void new Effect(value, compute2, effect, void 0, {
|
|
918
946
|
render: true,
|
|
919
947
|
...{ name: options?.name ?? "effect" }
|
|
920
948
|
});
|
|
@@ -962,6 +990,71 @@ function createErrorBoundary(fn, fallback) {
|
|
|
962
990
|
});
|
|
963
991
|
return decision.read.bind(decision);
|
|
964
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
|
+
}
|
|
965
1058
|
|
|
966
1059
|
// src/store/store.ts
|
|
967
1060
|
var $RAW = Symbol("STORE_RAW" );
|
|
@@ -971,7 +1064,7 @@ var $PROXY = Symbol("STORE_PROXY" );
|
|
|
971
1064
|
var STORE_VALUE = "v";
|
|
972
1065
|
var STORE_NODE = "n";
|
|
973
1066
|
var STORE_HAS = "h";
|
|
974
|
-
function
|
|
1067
|
+
function wrap2(value) {
|
|
975
1068
|
let p = value[$PROXY];
|
|
976
1069
|
if (!p) {
|
|
977
1070
|
let target;
|
|
@@ -1080,7 +1173,7 @@ var proxyTraps = {
|
|
|
1080
1173
|
}
|
|
1081
1174
|
if (Writing.has(storeValue)) {
|
|
1082
1175
|
const value2 = tracked ? tracked._value : storeValue[property];
|
|
1083
|
-
return isWrappable(value2) ? (Writing.add(value2[$RAW] || value2),
|
|
1176
|
+
return isWrappable(value2) ? (Writing.add(value2[$RAW] || value2), wrap2(value2)) : value2;
|
|
1084
1177
|
}
|
|
1085
1178
|
let value = tracked ? nodes[property].read() : storeValue[property];
|
|
1086
1179
|
if (!tracked) {
|
|
@@ -1088,10 +1181,10 @@ var proxyTraps = {
|
|
|
1088
1181
|
let proto;
|
|
1089
1182
|
return !Array.isArray(storeValue) && (proto = Object.getPrototypeOf(storeValue)) && proto !== Object.prototype ? value.bind(storeValue) : value;
|
|
1090
1183
|
} else if (getObserver()) {
|
|
1091
|
-
value = getNode(nodes, property, isWrappable(value) ?
|
|
1184
|
+
value = getNode(nodes, property, isWrappable(value) ? wrap2(value) : value).read();
|
|
1092
1185
|
}
|
|
1093
1186
|
}
|
|
1094
|
-
return isWrappable(value) ?
|
|
1187
|
+
return isWrappable(value) ? wrap2(value) : value;
|
|
1095
1188
|
},
|
|
1096
1189
|
has(target, property) {
|
|
1097
1190
|
if (property === $RAW || property === $PROXY || property === $TRACK || property === "__proto__")
|
|
@@ -1133,13 +1226,16 @@ function setProperty(state, property, value, deleting = false) {
|
|
|
1133
1226
|
const nodes = getNodes(target, STORE_NODE);
|
|
1134
1227
|
let node;
|
|
1135
1228
|
if (node = nodes[property])
|
|
1136
|
-
node.write(isWrappable(value) ?
|
|
1229
|
+
node.write(isWrappable(value) ? wrap2(value) : value);
|
|
1137
1230
|
Array.isArray(state) && state.length !== len && (node = nodes.length) && node.write(state.length);
|
|
1138
1231
|
(node = nodes[$TRACK]) && node.write(void 0);
|
|
1139
1232
|
}
|
|
1140
1233
|
function createStore(first, second) {
|
|
1141
|
-
const derived = typeof first === "function", store = derived ? second : first
|
|
1142
|
-
|
|
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);
|
|
1143
1239
|
const setStore = (fn) => {
|
|
1144
1240
|
try {
|
|
1145
1241
|
Writing.add(unwrappedStore);
|
|
@@ -1148,15 +1244,8 @@ function createStore(first, second) {
|
|
|
1148
1244
|
Writing.clear();
|
|
1149
1245
|
}
|
|
1150
1246
|
};
|
|
1151
|
-
if (derived) {
|
|
1152
|
-
new EagerComputation(void 0, () => setStore(first));
|
|
1153
|
-
}
|
|
1154
1247
|
return [wrappedStore, setStore];
|
|
1155
1248
|
}
|
|
1156
|
-
function createProjection(fn, initialValue = {}) {
|
|
1157
|
-
const [store] = createStore(fn, initialValue);
|
|
1158
|
-
return store;
|
|
1159
|
-
}
|
|
1160
1249
|
|
|
1161
1250
|
// src/store/reconcile.ts
|
|
1162
1251
|
function applyState(next, state, keyFn) {
|
|
@@ -1177,7 +1266,7 @@ function applyState(next, state, keyFn) {
|
|
|
1177
1266
|
if (next.length && previous.length && next[0] && keyFn(next[0]) != null) {
|
|
1178
1267
|
let i, j, start, end, newEnd, item, newIndicesNext, keyVal;
|
|
1179
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++) {
|
|
1180
|
-
applyState(next[start],
|
|
1269
|
+
applyState(next[start], wrap2(previous[start]), keyFn);
|
|
1181
1270
|
}
|
|
1182
1271
|
const temp = new Array(next.length), newIndices = /* @__PURE__ */ new Map();
|
|
1183
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--) {
|
|
@@ -1186,11 +1275,11 @@ function applyState(next, state, keyFn) {
|
|
|
1186
1275
|
if (start > newEnd || start > end) {
|
|
1187
1276
|
for (j = start; j <= newEnd; j++) {
|
|
1188
1277
|
changed = true;
|
|
1189
|
-
target[STORE_NODE][j]?.write(
|
|
1278
|
+
target[STORE_NODE][j]?.write(wrap2(next[j]));
|
|
1190
1279
|
}
|
|
1191
1280
|
for (; j < next.length; j++) {
|
|
1192
1281
|
changed = true;
|
|
1193
|
-
const wrapped =
|
|
1282
|
+
const wrapped = wrap2(temp[j]);
|
|
1194
1283
|
target[STORE_NODE][j]?.write(wrapped);
|
|
1195
1284
|
applyState(next[j], wrapped, keyFn);
|
|
1196
1285
|
}
|
|
@@ -1218,17 +1307,17 @@ function applyState(next, state, keyFn) {
|
|
|
1218
1307
|
}
|
|
1219
1308
|
for (j = start; j < next.length; j++) {
|
|
1220
1309
|
if (j in temp) {
|
|
1221
|
-
const wrapped =
|
|
1310
|
+
const wrapped = wrap2(temp[j]);
|
|
1222
1311
|
target[STORE_NODE][j]?.write(wrapped);
|
|
1223
1312
|
applyState(next[j], wrapped, keyFn);
|
|
1224
1313
|
} else
|
|
1225
|
-
target[STORE_NODE][j]?.write(
|
|
1314
|
+
target[STORE_NODE][j]?.write(wrap2(next[j]));
|
|
1226
1315
|
}
|
|
1227
1316
|
if (start < next.length)
|
|
1228
1317
|
changed = true;
|
|
1229
1318
|
} else if (previous.length && next.length) {
|
|
1230
1319
|
for (let i = 0, len = next.length; i < len; i++) {
|
|
1231
|
-
isWrappable(previous[i]) && applyState(next[i],
|
|
1320
|
+
isWrappable(previous[i]) && applyState(next[i], wrap2(previous[i]), keyFn);
|
|
1232
1321
|
}
|
|
1233
1322
|
}
|
|
1234
1323
|
if (previous.length !== next.length) {
|
|
@@ -1248,9 +1337,9 @@ function applyState(next, state, keyFn) {
|
|
|
1248
1337
|
if (previousValue === nextValue)
|
|
1249
1338
|
continue;
|
|
1250
1339
|
if (!previousValue || !isWrappable(previousValue) || keyFn(previousValue) != null && keyFn(previousValue) !== keyFn(nextValue))
|
|
1251
|
-
node.write(isWrappable(nextValue) ?
|
|
1340
|
+
node.write(isWrappable(nextValue) ? wrap2(nextValue) : nextValue);
|
|
1252
1341
|
else
|
|
1253
|
-
applyState(nextValue,
|
|
1342
|
+
applyState(nextValue, wrap2(previousValue), keyFn);
|
|
1254
1343
|
}
|
|
1255
1344
|
}
|
|
1256
1345
|
if (nodes = target[STORE_HAS]) {
|
|
@@ -1537,8 +1626,54 @@ function updateKeyedMap() {
|
|
|
1537
1626
|
});
|
|
1538
1627
|
return this._mappings;
|
|
1539
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
|
+
}
|
|
1540
1675
|
function compare(key, a, b) {
|
|
1541
1676
|
return key ? key(a) === key(b) : true;
|
|
1542
1677
|
}
|
|
1543
1678
|
|
|
1544
|
-
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 };
|