silentium 0.0.45 → 0.0.47
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/CHANGELOG.md +16 -0
- package/dist/silentium.cjs +101 -28
- package/dist/silentium.cjs.map +1 -1
- package/dist/silentium.d.ts +38 -15
- package/dist/silentium.js +99 -29
- package/dist/silentium.js.map +1 -1
- package/dist/silentium.min.js +1 -1
- package/dist/silentium.min.mjs +1 -1
- package/dist/silentium.min.mjs.map +1 -1
- package/dist/silentium.mjs +99 -29
- package/dist/silentium.mjs.map +1 -1
- package/package.json +2 -1
- package/src/Patron/PatronPool.ts +34 -1
- package/src/Source/Source._function.test.ts +6 -0
- package/src/Source/Source._object.test.ts +6 -0
- package/src/Source/Source.test.ts +7 -0
- package/src/Source/SourceAll._asArray.test.ts +7 -0
- package/src/Source/SourceAll._primitives.test.ts +7 -0
- package/src/Source/SourceAll._primitivesArray.test.ts +7 -0
- package/src/Source/SourceAll._promise.test.ts +7 -0
- package/src/Source/SourceAll._twoValuesAfter.test.ts +7 -0
- package/src/Source/SourceAll._twoValuesBefore.test.ts +7 -0
- package/src/Source/SourceAll._withFilter.test.ts +10 -1
- package/src/Source/SourceAll._withPatron.test.ts +10 -0
- package/src/Source/SourceAll.ts +31 -19
- package/src/Source/SourceAny.test.ts +9 -0
- package/src/Source/SourceAny.ts +6 -1
- package/src/Source/SourceApplied.test.ts +9 -0
- package/src/Source/SourceApplied.ts +5 -1
- package/src/Source/SourceChain.test.ts +9 -0
- package/src/Source/SourceChain.ts +6 -1
- package/src/Source/SourceChangeable._empty.test.ts +10 -0
- package/src/Source/SourceChangeable._memo.test.ts +12 -0
- package/src/Source/SourceChangeable._ofSource.test.ts +10 -0
- package/src/Source/SourceChangeable._ofSourceFunction.test.ts +10 -0
- package/src/Source/SourceChangeable._sequence.test.ts +51 -0
- package/src/Source/SourceChangeable.test.ts +10 -0
- package/src/Source/SourceChangeable.ts +10 -1
- package/src/Source/SourceCombined.test.ts +9 -0
- package/src/Source/SourceDestroyable.test.ts +10 -1
- package/src/Source/SourceDestroyable.ts +8 -8
- package/src/Source/SourceDynamic._ofSource.test.ts +10 -0
- package/src/Source/SourceDynamic.test.ts +10 -0
- package/src/Source/SourceExecutorApplied.test.ts +10 -0
- package/src/Source/SourceFiltered.defaultValue.test.ts +10 -0
- package/src/Source/SourceFiltered.test.ts +7 -0
- package/src/Source/SourceLazy.test.ts +12 -3
- package/src/Source/SourceLazy.ts +9 -5
- package/src/Source/SourceMap._deferred.test.ts +10 -0
- package/src/Source/SourceMap._destroy.test.ts +4 -4
- package/src/Source/SourceMap._fn.test.ts +10 -0
- package/src/Source/SourceMap.test.ts +10 -0
- package/src/Source/SourceMap.ts +4 -1
- package/src/Source/SourceOnce._notcalled.test.ts +10 -0
- package/src/Source/SourceOnce.test.ts +16 -1
- package/src/Source/SourceOnce.ts +4 -0
- package/src/Source/SourceRace.test.ts +10 -0
- package/src/Source/SourceResettable.test.ts +9 -0
- package/src/Source/SourceSequence._deferred.test.ts +10 -0
- package/src/Source/SourceSequence.test.ts +10 -0
- package/src/Source/SourceSequence.ts +9 -2
- package/src/Source/SourceSync.test.ts +9 -0
- package/src/index.ts +2 -0
- package/src/types/DestroyableType.ts +5 -0
- package/src/types/index.ts +1 -0
- package/src/utils/Nameable.test.ts +16 -0
- package/src/utils/Nameable.ts +20 -0
- package/src/utils/PrioritySet._reverse.test.ts +10 -0
- package/src/utils/PrioritySet._same.test.ts +10 -0
- package/src/utils/PrioritySet.ts +1 -1
- package/vitest.config.js +12 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [0.0.47](https://github.com/silentium-lab/silentium/compare/v0.0.46...v0.0.47) (2025-06-19)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* **41-need-to-create-destroyable-test-for-every-component:** all destructuring tests done ([7059326](https://github.com/silentium-lab/silentium/commit/70593263e6fcb09bce82de02a3e05c2f78437966))
|
|
11
|
+
* **41-need-to-create-destroyable-test-for-every-component:** work on destroying ([a957085](https://github.com/silentium-lab/silentium/commit/a95708573ff14995476f525ff74ee56faec948e1))
|
|
12
|
+
* **41-need-to-create-destroyable-test-for-every-component:** work on destructuring and leaking detection ([709ce46](https://github.com/silentium-lab/silentium/commit/709ce46fcd07298fd9993f9beeb10052cb422333))
|
|
13
|
+
|
|
14
|
+
### [0.0.46](https://github.com/silentium-lab/silentium/compare/v0.0.45...v0.0.46) (2025-06-16)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
* **main:** correct priority set when priorities are equal ([64c7fd8](https://github.com/silentium-lab/silentium/commit/64c7fd819f6cbeb79d6d3ebc482f82f29bc8b39d))
|
|
20
|
+
|
|
5
21
|
### [0.0.45](https://github.com/silentium-lab/silentium/compare/v0.0.44...v0.0.45) (2025-06-08)
|
|
6
22
|
|
|
7
23
|
|
package/dist/silentium.cjs
CHANGED
|
@@ -250,7 +250,7 @@ class PrioritySet {
|
|
|
250
250
|
let right = this.sortedItems.length;
|
|
251
251
|
while (left < right) {
|
|
252
252
|
const mid = Math.floor((left + right) / 2);
|
|
253
|
-
if (this.sortedItems[mid].priority
|
|
253
|
+
if (this.sortedItems[mid].priority >= priority) {
|
|
254
254
|
left = mid + 1;
|
|
255
255
|
} else {
|
|
256
256
|
right = mid;
|
|
@@ -351,6 +351,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
351
351
|
const poolSets = /* @__PURE__ */ new Map();
|
|
352
352
|
const poolsOfInitiators = /* @__PURE__ */ new Map();
|
|
353
353
|
const subSources = /* @__PURE__ */ new Map();
|
|
354
|
+
const subSourcesReverse = /* @__PURE__ */ new Map();
|
|
354
355
|
const poolsChangeFns = [];
|
|
355
356
|
const notifyPoolsChange = () => {
|
|
356
357
|
poolsChangeFns.forEach((fn) => fn());
|
|
@@ -375,7 +376,11 @@ const subSource = (subSource2, source2) => {
|
|
|
375
376
|
if (!subSources.has(source2)) {
|
|
376
377
|
subSources.set(source2, []);
|
|
377
378
|
}
|
|
379
|
+
if (!subSourcesReverse.has(subSource2)) {
|
|
380
|
+
subSourcesReverse.set(subSource2, []);
|
|
381
|
+
}
|
|
378
382
|
subSources.get(source2)?.push(subSource2);
|
|
383
|
+
subSourcesReverse.get(subSource2)?.push(source2);
|
|
379
384
|
return subSource2;
|
|
380
385
|
};
|
|
381
386
|
const subSourceMany = (subSourceSrc, sourcesSrc) => {
|
|
@@ -401,6 +406,15 @@ const destroy = (...initiators) => {
|
|
|
401
406
|
}
|
|
402
407
|
});
|
|
403
408
|
};
|
|
409
|
+
const destroyFromSubSource = (...initiators) => {
|
|
410
|
+
initiators.forEach((initiator) => {
|
|
411
|
+
destroy(initiator);
|
|
412
|
+
const foundSources = subSourcesReverse.get(initiator);
|
|
413
|
+
if (foundSources) {
|
|
414
|
+
destroyFromSubSource(...foundSources);
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
};
|
|
404
418
|
const patronPools = (patron) => {
|
|
405
419
|
const pools = [];
|
|
406
420
|
poolSets.forEach((pool, poolInstance) => {
|
|
@@ -431,6 +445,13 @@ const isPatronInPools = (patron) => {
|
|
|
431
445
|
});
|
|
432
446
|
return inPool;
|
|
433
447
|
};
|
|
448
|
+
const allPatrons = () => {
|
|
449
|
+
let patrons = [];
|
|
450
|
+
poolSets.forEach((pool) => {
|
|
451
|
+
patrons = patrons.concat(Array.from(pool.values()));
|
|
452
|
+
});
|
|
453
|
+
return patrons;
|
|
454
|
+
};
|
|
434
455
|
class PatronPool {
|
|
435
456
|
constructor(initiator) {
|
|
436
457
|
this.initiator = initiator;
|
|
@@ -522,6 +543,17 @@ const patronExecutorApplied = (baseGuest, applier) => {
|
|
|
522
543
|
return result;
|
|
523
544
|
};
|
|
524
545
|
|
|
546
|
+
const withName = (obj, name) => {
|
|
547
|
+
return new Proxy(obj, {
|
|
548
|
+
get(target, field) {
|
|
549
|
+
if (field === "name") {
|
|
550
|
+
return name;
|
|
551
|
+
}
|
|
552
|
+
return target[field];
|
|
553
|
+
}
|
|
554
|
+
});
|
|
555
|
+
};
|
|
556
|
+
|
|
525
557
|
const sourceSync = (baseSource, defaultValue) => {
|
|
526
558
|
const syncGuest = guestSync(defaultValue);
|
|
527
559
|
value(baseSource, systemPatron(syncGuest));
|
|
@@ -592,6 +624,14 @@ const sourceMemoOf = (source) => {
|
|
|
592
624
|
return resultMemo;
|
|
593
625
|
}
|
|
594
626
|
};
|
|
627
|
+
if (source) {
|
|
628
|
+
subSource(resultMemo, source);
|
|
629
|
+
subSource(baseSrcSync, source);
|
|
630
|
+
subSource(result, source);
|
|
631
|
+
} else {
|
|
632
|
+
subSource(result, resultMemo);
|
|
633
|
+
subSource(baseSrcSync, resultMemo);
|
|
634
|
+
}
|
|
595
635
|
return resultMemo;
|
|
596
636
|
};
|
|
597
637
|
|
|
@@ -607,18 +647,21 @@ const sourceAll = (sources) => {
|
|
|
607
647
|
Object.entries(sources).forEach(([key, source]) => {
|
|
608
648
|
subSource(theAll, source);
|
|
609
649
|
keysKnown.add(key);
|
|
610
|
-
const keyPatron =
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
650
|
+
const keyPatron = withName(
|
|
651
|
+
systemPatron((v) => {
|
|
652
|
+
theAll.value(
|
|
653
|
+
guest((all) => {
|
|
654
|
+
keysFilled.add(key);
|
|
655
|
+
const lastAll = {
|
|
656
|
+
...all,
|
|
657
|
+
[key]: v
|
|
658
|
+
};
|
|
659
|
+
theAll.give(lastAll);
|
|
660
|
+
})
|
|
661
|
+
);
|
|
662
|
+
}),
|
|
663
|
+
"all_key-patron"
|
|
664
|
+
);
|
|
622
665
|
patrons.push(keyPatron);
|
|
623
666
|
value(source, keyPatron);
|
|
624
667
|
});
|
|
@@ -626,11 +669,14 @@ const sourceAll = (sources) => {
|
|
|
626
669
|
return {
|
|
627
670
|
value(guest2) {
|
|
628
671
|
visited();
|
|
629
|
-
const mbPatron =
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
672
|
+
const mbPatron = withName(
|
|
673
|
+
guestCast(guest2, (value2) => {
|
|
674
|
+
if (isAllFilled()) {
|
|
675
|
+
give(Object.values(value2), guest2);
|
|
676
|
+
}
|
|
677
|
+
}),
|
|
678
|
+
"mb-patron"
|
|
679
|
+
);
|
|
634
680
|
patrons.push(mbPatron);
|
|
635
681
|
theAll.value(mbPatron);
|
|
636
682
|
},
|
|
@@ -638,6 +684,7 @@ const sourceAll = (sources) => {
|
|
|
638
684
|
patrons.forEach((patron) => {
|
|
639
685
|
removePatronFromPools(patron);
|
|
640
686
|
});
|
|
687
|
+
destroy(theAll);
|
|
641
688
|
}
|
|
642
689
|
};
|
|
643
690
|
};
|
|
@@ -649,16 +696,19 @@ const sourceSequence = (baseSource, targetSource) => {
|
|
|
649
696
|
if (targetSource === void 0) {
|
|
650
697
|
throw new Error("SourceSequence didn't receive targetSource argument");
|
|
651
698
|
}
|
|
652
|
-
|
|
699
|
+
const src = (guest) => {
|
|
653
700
|
const sequenceSource = sourceOf();
|
|
654
701
|
const source = targetSource.get(sequenceSource);
|
|
702
|
+
subSource(sequenceSource, baseSource);
|
|
655
703
|
value(
|
|
656
704
|
baseSource,
|
|
657
705
|
guestCast(guest, (theValue) => {
|
|
658
706
|
let index = 0;
|
|
659
707
|
const sources = [];
|
|
660
708
|
theValue.forEach(() => {
|
|
661
|
-
|
|
709
|
+
const newSrc = sourceOf();
|
|
710
|
+
sources.push(newSrc);
|
|
711
|
+
subSource(newSrc, baseSource);
|
|
662
712
|
});
|
|
663
713
|
const nextItemHandle = () => {
|
|
664
714
|
if (theValue[index + 1] !== void 0) {
|
|
@@ -693,6 +743,8 @@ const sourceSequence = (baseSource, targetSource) => {
|
|
|
693
743
|
})
|
|
694
744
|
);
|
|
695
745
|
};
|
|
746
|
+
subSource(src, baseSource);
|
|
747
|
+
return src;
|
|
696
748
|
};
|
|
697
749
|
|
|
698
750
|
const sourceMap = (baseSource, targetSource) => {
|
|
@@ -723,10 +775,12 @@ const sourceMap = (baseSource, targetSource) => {
|
|
|
723
775
|
})
|
|
724
776
|
);
|
|
725
777
|
});
|
|
726
|
-
|
|
778
|
+
const src = (g) => {
|
|
727
779
|
visited();
|
|
728
780
|
result.value(g);
|
|
729
781
|
};
|
|
782
|
+
subSource(result, src);
|
|
783
|
+
return src;
|
|
730
784
|
};
|
|
731
785
|
|
|
732
786
|
const sourceRace = (sources) => {
|
|
@@ -780,10 +834,13 @@ const sourceChain = (...sources) => {
|
|
|
780
834
|
const visited = firstVisit(() => {
|
|
781
835
|
handleSource(0);
|
|
782
836
|
});
|
|
783
|
-
|
|
837
|
+
const src = (g) => {
|
|
784
838
|
visited();
|
|
785
839
|
resultSrc.value(g);
|
|
786
840
|
};
|
|
841
|
+
subSourceMany(src, sources);
|
|
842
|
+
subSourceMany(resultSrc, sources);
|
|
843
|
+
return src;
|
|
787
844
|
};
|
|
788
845
|
|
|
789
846
|
const sourceDynamic = (baseGuest, baseSource) => {
|
|
@@ -807,7 +864,7 @@ const sourceDynamic = (baseGuest, baseSource) => {
|
|
|
807
864
|
};
|
|
808
865
|
|
|
809
866
|
const sourceApplied = (baseSource, applier) => {
|
|
810
|
-
|
|
867
|
+
const src = (guest) => {
|
|
811
868
|
value(
|
|
812
869
|
baseSource,
|
|
813
870
|
guestCast(guest, (v) => {
|
|
@@ -815,6 +872,8 @@ const sourceApplied = (baseSource, applier) => {
|
|
|
815
872
|
})
|
|
816
873
|
);
|
|
817
874
|
};
|
|
875
|
+
subSource(src, baseSource);
|
|
876
|
+
return src;
|
|
818
877
|
};
|
|
819
878
|
|
|
820
879
|
const sourceExecutorApplied = (source, applier) => {
|
|
@@ -860,6 +919,9 @@ const sourceOnce = (initialValue) => {
|
|
|
860
919
|
isFilled = true;
|
|
861
920
|
}
|
|
862
921
|
return this;
|
|
922
|
+
},
|
|
923
|
+
destroy() {
|
|
924
|
+
destroy(source);
|
|
863
925
|
}
|
|
864
926
|
};
|
|
865
927
|
};
|
|
@@ -899,12 +961,15 @@ const sourceAny = (sources) => {
|
|
|
899
961
|
const visited = firstVisit(() => {
|
|
900
962
|
sources.forEach((source) => {
|
|
901
963
|
value(source, systemPatron(lastSrc));
|
|
964
|
+
subSource(lastSrc, source);
|
|
902
965
|
});
|
|
903
966
|
});
|
|
904
|
-
|
|
967
|
+
const src = (g) => {
|
|
905
968
|
visited();
|
|
906
969
|
lastSrc.value(g);
|
|
907
970
|
};
|
|
971
|
+
subSourceMany(src, sources);
|
|
972
|
+
return src;
|
|
908
973
|
};
|
|
909
974
|
|
|
910
975
|
const sourceLazy = (lazySrc, args, destroySrc) => {
|
|
@@ -912,7 +977,7 @@ const sourceLazy = (lazySrc, args, destroySrc) => {
|
|
|
912
977
|
const result = sourceOf();
|
|
913
978
|
const resultResettable = sourceResettable(result, destroySrc ?? sourceOf());
|
|
914
979
|
let wasInstantiated = false;
|
|
915
|
-
const instantiate = () => {
|
|
980
|
+
const instantiate = (srcInstance) => {
|
|
916
981
|
if (wasInstantiated) {
|
|
917
982
|
return;
|
|
918
983
|
}
|
|
@@ -923,6 +988,8 @@ const sourceLazy = (lazySrc, args, destroySrc) => {
|
|
|
923
988
|
if (!instance) {
|
|
924
989
|
instance = lazySrc.get(...args);
|
|
925
990
|
value(instance, systemPatron(result));
|
|
991
|
+
subSource(result, srcInstance);
|
|
992
|
+
subSource(resultResettable, srcInstance);
|
|
926
993
|
}
|
|
927
994
|
})
|
|
928
995
|
);
|
|
@@ -936,15 +1003,16 @@ const sourceLazy = (lazySrc, args, destroySrc) => {
|
|
|
936
1003
|
})
|
|
937
1004
|
);
|
|
938
1005
|
}
|
|
939
|
-
|
|
940
|
-
instantiate();
|
|
1006
|
+
const src = (g) => {
|
|
1007
|
+
instantiate(src);
|
|
941
1008
|
value(resultResettable, g);
|
|
942
1009
|
};
|
|
1010
|
+
return src;
|
|
943
1011
|
};
|
|
944
1012
|
|
|
945
1013
|
const sourceDestroyable = (source) => {
|
|
946
1014
|
let destructor = null;
|
|
947
|
-
|
|
1015
|
+
const result = {
|
|
948
1016
|
value(g) {
|
|
949
1017
|
destructor = source(g);
|
|
950
1018
|
return this;
|
|
@@ -956,6 +1024,8 @@ const sourceDestroyable = (source) => {
|
|
|
956
1024
|
return this;
|
|
957
1025
|
}
|
|
958
1026
|
};
|
|
1027
|
+
subSource(result, source);
|
|
1028
|
+
return result;
|
|
959
1029
|
};
|
|
960
1030
|
|
|
961
1031
|
const lazyClass = (constructorFn, modules = {}) => {
|
|
@@ -984,7 +1054,9 @@ const lazy = (buildingFn) => {
|
|
|
984
1054
|
};
|
|
985
1055
|
|
|
986
1056
|
exports.PatronPool = PatronPool;
|
|
1057
|
+
exports.allPatrons = allPatrons;
|
|
987
1058
|
exports.destroy = destroy;
|
|
1059
|
+
exports.destroyFromSubSource = destroyFromSubSource;
|
|
988
1060
|
exports.firstVisit = firstVisit;
|
|
989
1061
|
exports.give = give;
|
|
990
1062
|
exports.guest = guest;
|
|
@@ -1032,5 +1104,6 @@ exports.subSource = subSource;
|
|
|
1032
1104
|
exports.subSourceMany = subSourceMany;
|
|
1033
1105
|
exports.systemPatron = systemPatron;
|
|
1034
1106
|
exports.value = value;
|
|
1107
|
+
exports.withName = withName;
|
|
1035
1108
|
exports.withPriority = withPriority;
|
|
1036
1109
|
//# sourceMappingURL=silentium.cjs.map
|