silentium 0.0.13 → 0.0.14

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "silentium",
3
- "version": "0.0.13",
3
+ "version": "0.0.14",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/silentium.js",
@@ -15,7 +15,8 @@
15
15
  "build-doc": "./docs/build.sh",
16
16
  "lint": "eslint src",
17
17
  "lint-fix": "eslint src --fix",
18
- "test": "vitest",
18
+ "test": "vitest run",
19
+ "test:watch": "vitest watch",
19
20
  "cz": "git add . && git cz",
20
21
  "push-head": "git push origin HEAD",
21
22
  "test-debug": "env DEBUG=app:* vitest",
@@ -40,6 +40,11 @@ export const patronPoolsStatistic = source<{
40
40
  * @url https://silentium-lab.github.io/silentium/#/utils/sub-source
41
41
  */
42
42
  export const subSource = (source: SourceType, subSource: SourceType) => {
43
+ // sub sources can appear only on SourceObjectType
44
+ if (source !== null && typeof source !== "object") {
45
+ return;
46
+ }
47
+
43
48
  if (!subSources.has(source)) {
44
49
  subSources.set(source, []);
45
50
  }
@@ -47,6 +52,15 @@ export const subSource = (source: SourceType, subSource: SourceType) => {
47
52
  subSources.get(source)?.push(subSource);
48
53
  };
49
54
 
55
+ /**
56
+ * Helps to define many sources of one sub source
57
+ */
58
+ export const subSourceMany = (subSource: SourceType, sources: SourceType[]) => {
59
+ sources.forEach((source) => {
60
+ subSource(source, subSource);
61
+ });
62
+ };
63
+
50
64
  /**
51
65
  * Helps to remove all pools of related initiators
52
66
  * @url https://silentium-lab.github.io/silentium/#/utils/destroy
@@ -0,0 +1,20 @@
1
+ import { value } from "../Source/Source";
2
+ import { sourceAll } from "../Source/SourceAll";
3
+ import { expect, test, vi } from "vitest";
4
+
5
+ test("SourceAll._primitives.test", () => {
6
+ const one = 1;
7
+ const two = 2;
8
+ const all = sourceAll<{ one: number; two: number }>({
9
+ one,
10
+ two,
11
+ });
12
+
13
+ const g = vi.fn();
14
+ value(all, g);
15
+
16
+ expect(g).toBeCalledWith({
17
+ one: 1,
18
+ two: 2,
19
+ });
20
+ });
@@ -0,0 +1,14 @@
1
+ import { value } from "./Source";
2
+ import { sourceAll } from "./SourceAll";
3
+ import { expect, test, vi } from "vitest";
4
+
5
+ test("SourceAll._primitivesArray.test", () => {
6
+ const one = 1;
7
+ const two = 2;
8
+ const all = sourceAll([one, two]);
9
+
10
+ const g = vi.fn();
11
+ value(all, g);
12
+
13
+ expect(g).toBeCalledWith([1, 2]);
14
+ });
@@ -0,0 +1,28 @@
1
+ import { afterEach, beforeEach, expect, test, vi } from "vitest";
2
+ import { patron } from "../Patron/Patron";
3
+ import { sourceChangeable } from "../Source/SourceChangeable";
4
+ import { value } from "./Source";
5
+ import { sourceAll } from "./SourceAll";
6
+
7
+ beforeEach(() => {
8
+ vi.useFakeTimers();
9
+ });
10
+
11
+ afterEach(() => {
12
+ vi.useRealTimers();
13
+ });
14
+
15
+ test("SourceAll._primitivesArray.test", async () => {
16
+ const one = 1;
17
+ const two = sourceChangeable<number>();
18
+
19
+ const all = sourceAll([one, two]);
20
+ Promise.resolve(2).then(two.give);
21
+
22
+ const g = vi.fn();
23
+ await vi.advanceTimersByTime(10);
24
+
25
+ value(all, patron(g));
26
+
27
+ expect(g).toBeCalledWith([1, 2]);
28
+ });
@@ -1,3 +1,4 @@
1
+ import { subSource } from "../Patron/PatronPool";
1
2
  import { give, guest, GuestType } from "../Guest/Guest";
2
3
  import { guestCast } from "../Guest/GuestCast";
3
4
  import { patron } from "../Patron/Patron";
@@ -21,6 +22,7 @@ export const sourceAll = <T>(
21
22
  const theAll = sourceChangeable<Record<string, unknown>>({});
22
23
 
23
24
  Object.entries(sources).forEach(([key, source]) => {
25
+ subSource(source, theAll);
24
26
  keysKnown.add(key);
25
27
  value(
26
28
  source,