silentium 0.0.35 → 0.0.37

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.
Files changed (112) hide show
  1. package/.github/workflows/node.js.yml +31 -0
  2. package/CHANGELOG.md +19 -0
  3. package/README.md +32 -2
  4. package/dist/silentium.cjs +118 -75
  5. package/dist/silentium.cjs.map +1 -1
  6. package/dist/silentium.d.ts +16 -7
  7. package/dist/silentium.js +118 -76
  8. package/dist/silentium.js.map +1 -1
  9. package/dist/silentium.min.js +1 -1
  10. package/dist/silentium.min.mjs +1 -1
  11. package/dist/silentium.min.mjs.map +1 -1
  12. package/dist/silentium.mjs +118 -76
  13. package/dist/silentium.mjs.map +1 -1
  14. package/docs/build.sh +1 -1
  15. package/docs/buildRoutes.sh +1 -1
  16. package/docs/index-dev.html +2 -2
  17. package/docs/index.html +3 -3
  18. package/docs/pages/compatibility/dip.html +3 -3
  19. package/docs/pages/en/compatibility/dip.html +3 -3
  20. package/docs/pages/en/guest/guest-applied.html +1 -1
  21. package/docs/pages/en/guest/guest-cast.html +1 -1
  22. package/docs/pages/en/guest/guest-disposable.html +1 -1
  23. package/docs/pages/en/guest/guest-executor-applied.html +1 -1
  24. package/docs/pages/en/guest/guest-sync.html +1 -1
  25. package/docs/pages/en/guest/index.html +3 -3
  26. package/docs/pages/en/guest.html +3 -3
  27. package/docs/pages/en/patron/index.html +1 -1
  28. package/docs/pages/en/patron/patron-applied.html +1 -1
  29. package/docs/pages/en/patron/patron-executor-applied.html +1 -1
  30. package/docs/pages/en/patron/patron-once.html +1 -1
  31. package/docs/pages/en/patron/patron-pool.html +1 -1
  32. package/docs/pages/en/patron.html +1 -1
  33. package/docs/pages/en/philosofy.html +2 -2
  34. package/docs/pages/en/source/index.html +2 -2
  35. package/docs/pages/en/source/source-all.html +1 -1
  36. package/docs/pages/en/source/source-applied.html +1 -1
  37. package/docs/pages/en/source/source-changeable.html +1 -1
  38. package/docs/pages/en/source/source-dynamic.html +3 -3
  39. package/docs/pages/en/source/source-executor-applied.html +1 -1
  40. package/docs/pages/en/source/source-filtered.html +1 -1
  41. package/docs/pages/en/source/source-map.html +1 -1
  42. package/docs/pages/en/source/source-once.html +1 -1
  43. package/docs/pages/en/source/source-race.html +1 -1
  44. package/docs/pages/en/source/source-sequence.html +1 -1
  45. package/docs/pages/en/source/source-sync.html +1 -1
  46. package/docs/pages/en/source/source.html +2 -2
  47. package/docs/pages/en/source.html +2 -2
  48. package/docs/pages/en/terminology/introduction.html +1 -1
  49. package/docs/pages/en/terminology/source.html +2 -2
  50. package/docs/pages/en/utils/give.html +2 -2
  51. package/docs/pages/en/utils/is-guest-aware.html +1 -1
  52. package/docs/pages/en/utils/is-guest.html +1 -1
  53. package/docs/pages/en/utils/is-patron-in-pools.html +1 -1
  54. package/docs/pages/en/utils/is-source.html +1 -1
  55. package/docs/pages/en/utils/private.html +2 -2
  56. package/docs/pages/en/utils/remove-patron-from-pools.html +1 -1
  57. package/docs/pages/en/utils/source-of.html +1 -1
  58. package/docs/pages/en/utils/value.html +2 -2
  59. package/docs/pages/guest/guest-applied.html +2 -4
  60. package/docs/pages/guest/guest-cast.html +1 -1
  61. package/docs/pages/guest/guest-disposable.html +1 -1
  62. package/docs/pages/guest/guest-executor-applied.html +1 -1
  63. package/docs/pages/guest/guest-sync.html +1 -1
  64. package/docs/pages/guest/index.html +3 -3
  65. package/docs/pages/guest.html +3 -3
  66. package/docs/pages/patron/index.html +1 -1
  67. package/docs/pages/patron/patron-applied.html +1 -1
  68. package/docs/pages/patron/patron-executor-applied.html +1 -1
  69. package/docs/pages/patron/patron-once.html +1 -1
  70. package/docs/pages/patron/patron-pool.html +1 -1
  71. package/docs/pages/patron.html +1 -1
  72. package/docs/pages/philosofy.html +2 -2
  73. package/docs/pages/source/index.html +2 -2
  74. package/docs/pages/source/source-all.html +1 -1
  75. package/docs/pages/source/source-applied.html +1 -1
  76. package/docs/pages/source/source-changeable.html +1 -1
  77. package/docs/pages/source/source-dynamic.html +3 -3
  78. package/docs/pages/source/source-executor-applied.html +1 -1
  79. package/docs/pages/source/source-filtered.html +1 -1
  80. package/docs/pages/source/source-map.html +1 -1
  81. package/docs/pages/source/source-once.html +1 -1
  82. package/docs/pages/source/source-race.html +1 -1
  83. package/docs/pages/source/source-sequence.html +1 -1
  84. package/docs/pages/source/source-sync.html +1 -1
  85. package/docs/pages/source/source.html +2 -2
  86. package/docs/pages/source.html +2 -2
  87. package/docs/pages/terminology/introduction.html +1 -1
  88. package/docs/pages/terminology/source.html +2 -2
  89. package/docs/pages/utils/give.html +2 -2
  90. package/docs/pages/utils/is-guest-aware.html +1 -1
  91. package/docs/pages/utils/is-guest.html +1 -1
  92. package/docs/pages/utils/is-patron-in-pools.html +1 -1
  93. package/docs/pages/utils/is-source.html +1 -1
  94. package/docs/pages/utils/private.html +2 -2
  95. package/docs/pages/utils/remove-patron-from-pools.html +1 -1
  96. package/docs/pages/utils/source-of.html +1 -1
  97. package/docs/pages/utils/value.html +2 -2
  98. package/docs/routes.json +1 -1
  99. package/docs/template.html +2 -2
  100. package/package.json +1 -1
  101. package/src/Guest/Guest.firstVisit.test.ts +16 -0
  102. package/src/Guest/Guest.ts +16 -0
  103. package/src/Source/SourceAll.ts +27 -18
  104. package/src/Source/SourceAny.ts +10 -3
  105. package/src/Source/SourceChain.ts +24 -17
  106. package/src/Source/SourceDynamic._ofSource.test.ts +1 -1
  107. package/src/Source/SourceLazy.ts +27 -14
  108. package/src/Source/SourceMap.ts +25 -20
  109. package/src/Source/SourceResettable.test.ts +3 -2
  110. package/src/Source/SourceResettable.ts +15 -10
  111. package/src/Source/SourceSync.ts +1 -1
  112. package/docs/assets/js/lib/StyleFetched.mjs +0 -19
@@ -0,0 +1,31 @@
1
+ # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2
+ # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
3
+
4
+ name: Node.js CI
5
+
6
+ on:
7
+ push:
8
+ branches: [ "main" ]
9
+ pull_request:
10
+ branches: [ "main" ]
11
+
12
+ jobs:
13
+ build:
14
+
15
+ runs-on: ubuntu-latest
16
+
17
+ strategy:
18
+ matrix:
19
+ node-version: [18.x, 20.x, 22.x]
20
+ # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
21
+
22
+ steps:
23
+ - uses: actions/checkout@v4
24
+ - name: Use Node.js ${{ matrix.node-version }}
25
+ uses: actions/setup-node@v4
26
+ with:
27
+ node-version: ${{ matrix.node-version }}
28
+ cache: 'npm'
29
+ - run: npm ci
30
+ - run: npm run build --if-present
31
+ - run: npm test
package/CHANGELOG.md CHANGED
@@ -2,6 +2,25 @@
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.37](https://github.com/silentium-lab/silentium/compare/v0.0.36...v0.0.37) (2025-05-31)
6
+
7
+
8
+ ### Features
9
+
10
+ * **49-sourcedetached:** firstVisit done and applied ([d596990](https://github.com/silentium-lab/silentium/commit/d596990daf05b0136e3860bbc6793950fb6ccaf2))
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * **49-sourcedetached:** fix tests ([e054cd6](https://github.com/silentium-lab/silentium/commit/e054cd6c63caa9b436212fc1e1e2db5e82622197))
16
+
17
+ ### [0.0.36](https://github.com/silentium-lab/silentium/compare/v0.0.35...v0.0.36) (2025-05-31)
18
+
19
+
20
+ ### Features
21
+
22
+ * **47-sourcelazy-component:** source lazy done ([ed97056](https://github.com/silentium-lab/silentium/commit/ed9705603913451e22ed6994005f6a5b656dacde))
23
+
5
24
  ### [0.0.35](https://github.com/silentium-lab/silentium/compare/v0.0.34...v0.0.35) (2025-05-25)
6
25
 
7
26
 
package/README.md CHANGED
@@ -1,3 +1,33 @@
1
- # Silentium
1
+ <p align="center">
2
+ <a href="https://silentium-lab.github.io/silentium/#/en/" target="_blank" rel="noopener noreferrer" style="display:flex">
3
+ <img width="180" src="https://silentium-lab.github.io/silentium/assets/img/logo.svg" alt="logo">
4
+ </a>
5
+ </p>
6
+ <h1 align="center">Silentium</h1>
7
+ <br/>
8
+ <p align="center">
9
+ <a href="https://npmjs.com/package/silentium"><img src="https://img.shields.io/npm/v/silentium.svg" alt="npm package"></a>
10
+ <a href="https://github.com/silentium-lab/silentium/actions/workflows/node.js.yml"><img src="https://github.com/silentium-lab/silentium/actions/workflows/node.js.yml/badge.svg?branch=main" alt="build status"></a>
11
+ </p>
12
+ <br/>
2
13
 
3
- [Документация](https://github.com/silentium-lab/)
14
+ [Documentation](https://silentium-lab.github.io/silentium/#/en/)
15
+
16
+ To install the library you can use the command.
17
+
18
+ ```bash
19
+ npm install silentium
20
+ ```
21
+
22
+ The library helps you create abstractions for information in your system. Instead of working with data abstractions and operations abstractions, you can combine them into a common information abstraction. The approach in which we combine data and operations under information abstractions is object-oriented programming.
23
+
24
+ The idea for the project was born from the ideas of eolang and was inspired by this paper, 𝜑-calculus:
25
+ https://arxiv.org/pdf/2111.13384
26
+
27
+ ## Difference from eolang
28
+
29
+ Unlike eolang, where the program starts working at the moment when some method receives data, which is called dataization, Silentium starts executing the program at the moment when a guest comes to the information source, requesting data, this difference allows the Silentium library to work on top of JavaScript events, creating abstractions of information around some event models.
30
+
31
+ ## Is silentium reactive?
32
+
33
+ Silentium is not a reactive programming library, chains of objects only interact with each other through message passing, but due to the fact that Silentium is developed with the idea of ​​working on top of events, it allows for easy integration with any reactive library or framework, transferring event sources to the reactive mechanisms of the required frameworks.
@@ -63,6 +63,15 @@ const guest = (receiver) => {
63
63
  };
64
64
  return result;
65
65
  };
66
+ const firstVisit = (afterFirstVisit) => {
67
+ let isVisited = false;
68
+ return () => {
69
+ if (!isVisited) {
70
+ afterFirstVisit();
71
+ }
72
+ isVisited = true;
73
+ };
74
+ };
66
75
 
67
76
  const guestCast = (sourceGuest, targetGuest) => {
68
77
  if (sourceGuest === void 0) {
@@ -448,26 +457,29 @@ const sourceAll = (sources) => {
448
457
  };
449
458
  const theAll = sourceOf({});
450
459
  const patrons = [];
451
- Object.entries(sources).forEach(([key, source]) => {
452
- subSource(theAll, source);
453
- keysKnown.add(key);
454
- const keyPatron = patron((v) => {
455
- theAll.value(
456
- guest((all) => {
457
- keysFilled.add(key);
458
- const lastAll = {
459
- ...all,
460
- [key]: v
461
- };
462
- theAll.give(lastAll);
463
- })
464
- );
460
+ const visited = firstVisit(() => {
461
+ Object.entries(sources).forEach(([key, source]) => {
462
+ subSource(theAll, source);
463
+ keysKnown.add(key);
464
+ const keyPatron = patron((v) => {
465
+ theAll.value(
466
+ guest((all) => {
467
+ keysFilled.add(key);
468
+ const lastAll = {
469
+ ...all,
470
+ [key]: v
471
+ };
472
+ theAll.give(lastAll);
473
+ })
474
+ );
475
+ });
476
+ patrons.push(keyPatron);
477
+ value(source, keyPatron);
465
478
  });
466
- patrons.push(keyPatron);
467
- value(source, keyPatron);
468
479
  });
469
480
  return {
470
481
  value(guest2) {
482
+ visited();
471
483
  const mbPatron = guestCast(guest2, (value2) => {
472
484
  if (isAllFilled()) {
473
485
  give(Object.values(value2), guest2);
@@ -545,25 +557,30 @@ const sourceMap = (baseSource, targetSource) => {
545
557
  throw new Error("SourceMap didn't receive targetSource argument");
546
558
  }
547
559
  const result = sourceOf();
548
- value(
549
- baseSource,
550
- patron((theValue) => {
551
- const sources = [];
552
- theValue.forEach((val) => {
553
- const source = targetSource.get(val);
554
- subSource(source, baseSource);
555
- sources.push(source);
556
- });
557
- value(
558
- sourceAll(sources),
559
- patronOnce((v) => {
560
- destroy(...sources);
561
- give(v, result);
562
- })
563
- );
564
- })
565
- );
566
- return result.value;
560
+ const visited = firstVisit(() => {
561
+ value(
562
+ baseSource,
563
+ patron((theValue) => {
564
+ const sources = [];
565
+ theValue.forEach((val) => {
566
+ const source = targetSource.get(val);
567
+ subSource(source, baseSource);
568
+ sources.push(source);
569
+ });
570
+ value(
571
+ sourceAll(sources),
572
+ patronOnce((v) => {
573
+ destroy(...sources);
574
+ give(v, result);
575
+ })
576
+ );
577
+ })
578
+ );
579
+ });
580
+ return (g) => {
581
+ visited();
582
+ result.value(g);
583
+ };
567
584
  };
568
585
 
569
586
  const sourceRace = (sources) => {
@@ -590,21 +607,26 @@ const sourceChain = (...sources) => {
590
607
  const resultSrc = sourceOf();
591
608
  const respondedSources = /* @__PURE__ */ new Set();
592
609
  let lastSourceValue = null;
593
- sources.forEach((source, index) => {
594
- value(
595
- source,
596
- patron((value2) => {
597
- respondedSources.add(index);
598
- if (index === sources.length - 1) {
599
- lastSourceValue = value2;
600
- }
601
- if (respondedSources.size === sources.length && lastSourceValue !== null) {
602
- resultSrc.give(lastSourceValue);
603
- }
604
- })
605
- );
610
+ const visited = firstVisit(() => {
611
+ sources.forEach((source, index) => {
612
+ value(
613
+ source,
614
+ patron((value2) => {
615
+ respondedSources.add(index);
616
+ if (index === sources.length - 1) {
617
+ lastSourceValue = value2;
618
+ }
619
+ if (respondedSources.size === sources.length && lastSourceValue !== null) {
620
+ resultSrc.give(lastSourceValue);
621
+ }
622
+ })
623
+ );
624
+ });
606
625
  });
607
- return resultSrc.value;
626
+ return (g) => {
627
+ visited();
628
+ resultSrc.value(g);
629
+ };
608
630
  };
609
631
 
610
632
  const sourceDynamic = (baseGuest, baseSource) => {
@@ -691,48 +713,68 @@ const sourceCombined = (...sources) => (source) => {
691
713
 
692
714
  const sourceResettable = (baseSrc, resettableSrc) => {
693
715
  const result = sourceOf();
694
- value(
695
- resettableSrc,
696
- patron(() => {
697
- give(null, result);
698
- })
699
- );
700
- value(baseSrc, patron(result));
701
- subSource(result, baseSrc);
702
- return result;
716
+ const visited = firstVisit(() => {
717
+ value(
718
+ resettableSrc,
719
+ patron(() => {
720
+ give(null, result);
721
+ })
722
+ );
723
+ value(baseSrc, patron(result));
724
+ subSource(result, baseSrc);
725
+ });
726
+ return (g) => {
727
+ visited();
728
+ result.value(g);
729
+ };
703
730
  };
704
731
 
705
732
  const sourceAny = (sources) => {
706
733
  const lastSrc = sourceOf();
707
- sources.forEach((source) => {
708
- value(source, patron(lastSrc));
734
+ const visited = firstVisit(() => {
735
+ sources.forEach((source) => {
736
+ value(source, patron(lastSrc));
737
+ });
709
738
  });
710
- return lastSrc;
739
+ return (g) => {
740
+ visited();
741
+ lastSrc.value(g);
742
+ };
711
743
  };
712
744
 
713
- const sourceLazy = (lazySrc, args, resetSrc) => {
745
+ const sourceLazy = (lazySrc, args, destroySrc) => {
714
746
  let instance = null;
715
747
  const result = sourceOf();
716
- const resultResettable = sourceResettable(result, resetSrc ?? sourceOf());
717
- value(
718
- sourceAll(args),
719
- patron(() => {
720
- if (!instance) {
721
- instance = lazySrc.get(...args);
722
- value(instance, patron(result));
723
- }
724
- })
725
- );
726
- if (resetSrc) {
748
+ const resultResettable = sourceResettable(result, destroySrc ?? sourceOf());
749
+ let wasInstantiated = false;
750
+ const instantiate = () => {
751
+ if (wasInstantiated) {
752
+ return;
753
+ }
754
+ wasInstantiated = true;
727
755
  value(
728
- resetSrc,
756
+ sourceAll(args),
757
+ patron(() => {
758
+ if (!instance) {
759
+ instance = lazySrc.get(...args);
760
+ value(instance, patron(result));
761
+ }
762
+ })
763
+ );
764
+ };
765
+ if (destroySrc) {
766
+ value(
767
+ destroySrc,
729
768
  patron(() => {
730
769
  destroy(instance);
731
770
  instance = null;
732
771
  })
733
772
  );
734
773
  }
735
- return resultResettable;
774
+ return (g) => {
775
+ instantiate();
776
+ value(resultResettable, g);
777
+ };
736
778
  };
737
779
 
738
780
  const sourceDestroyable = (source) => {
@@ -778,6 +820,7 @@ const lazy = (buildingFn) => {
778
820
 
779
821
  exports.PatronPool = PatronPool;
780
822
  exports.destroy = destroy;
823
+ exports.firstVisit = firstVisit;
781
824
  exports.give = give;
782
825
  exports.guest = guest;
783
826
  exports.guestApplied = guestApplied;