silentium-components 0.0.70 → 0.0.71

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 (88) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/silentium-components.cjs +491 -436
  3. package/dist/silentium-components.cjs.map +1 -1
  4. package/dist/silentium-components.d.ts +42 -36
  5. package/dist/silentium-components.js +493 -438
  6. package/dist/silentium-components.js.map +1 -1
  7. package/dist/silentium-components.min.js +1 -1
  8. package/dist/silentium-components.min.mjs +1 -1
  9. package/dist/silentium-components.min.mjs.map +1 -1
  10. package/dist/silentium-components.mjs +493 -438
  11. package/dist/silentium-components.mjs.map +1 -1
  12. package/package.json +2 -2
  13. package/src/behaviors/Branch._main.test.ts +3 -3
  14. package/src/behaviors/Branch.branchesDontAffectResult.test.ts +4 -4
  15. package/src/behaviors/Branch.dontRespondAfterRespond.test.ts +6 -6
  16. package/src/behaviors/Branch.ts +23 -24
  17. package/src/behaviors/BranchLazy._main.test.ts +5 -5
  18. package/src/behaviors/BranchLazy.ts +31 -23
  19. package/src/behaviors/Const.test.ts +10 -8
  20. package/src/behaviors/Const.ts +9 -10
  21. package/src/behaviors/Deadline._main.test.ts +4 -4
  22. package/src/behaviors/Deadline._value.test.ts +5 -5
  23. package/src/behaviors/Deadline.ts +37 -28
  24. package/src/behaviors/Deferred.test.ts +10 -10
  25. package/src/behaviors/Deferred.ts +14 -12
  26. package/src/behaviors/Detached.test.ts +4 -4
  27. package/src/behaviors/Detached.ts +6 -6
  28. package/src/behaviors/Dirty.test.ts +3 -3
  29. package/src/behaviors/Dirty.ts +46 -26
  30. package/src/behaviors/Loading.test.ts +7 -10
  31. package/src/behaviors/Loading.ts +9 -9
  32. package/src/behaviors/Lock.test.ts +3 -3
  33. package/src/behaviors/Lock.ts +12 -10
  34. package/src/behaviors/Memo.test.ts +8 -6
  35. package/src/behaviors/Memo.ts +13 -12
  36. package/src/behaviors/OnlyChanged.test.ts +4 -4
  37. package/src/behaviors/OnlyChanged.ts +14 -13
  38. package/src/behaviors/Part.test.ts +6 -6
  39. package/src/behaviors/Part.ts +53 -30
  40. package/src/behaviors/Path._main.test.ts +2 -2
  41. package/src/behaviors/Path.index.test.ts +2 -2
  42. package/src/behaviors/Path.nested.test.ts +2 -2
  43. package/src/behaviors/Path.ts +20 -21
  44. package/src/behaviors/Polling.test.ts +10 -10
  45. package/src/behaviors/Polling.ts +10 -8
  46. package/src/behaviors/Shot._main.test.ts +10 -10
  47. package/src/behaviors/Shot._onlyChanged.test.ts +13 -11
  48. package/src/behaviors/Shot.ts +15 -12
  49. package/src/behaviors/Task.ts +4 -4
  50. package/src/behaviors/Tick.test.ts +7 -7
  51. package/src/behaviors/Tick.ts +13 -11
  52. package/src/behaviors/Transaction.test.ts +3 -3
  53. package/src/behaviors/Transaction.ts +13 -12
  54. package/src/boolean/And.test.ts +11 -11
  55. package/src/boolean/And.ts +10 -11
  56. package/src/boolean/Bool.test.ts +2 -2
  57. package/src/boolean/Bool.ts +5 -5
  58. package/src/boolean/Not.test.ts +3 -3
  59. package/src/boolean/Not.ts +9 -7
  60. package/src/boolean/Or.test.ts +3 -3
  61. package/src/boolean/Or.ts +10 -11
  62. package/src/formats/FromJson.ts +14 -12
  63. package/src/formats/ToJson.ts +14 -12
  64. package/src/lists/First.test.ts +2 -2
  65. package/src/lists/First.ts +5 -5
  66. package/src/navigation/Router._main.test.ts +20 -13
  67. package/src/navigation/Router._nested.test.ts +41 -33
  68. package/src/navigation/Router.ts +48 -50
  69. package/src/strings/Concatenated.test.ts +3 -3
  70. package/src/strings/Concatenated.ts +8 -9
  71. package/src/strings/Template._main.test.ts +3 -3
  72. package/src/strings/Template._place.test.ts +2 -2
  73. package/src/strings/Template.ts +54 -40
  74. package/src/structures/HashTable.test.ts +6 -6
  75. package/src/structures/HashTable.ts +10 -8
  76. package/src/structures/Record._main.test.ts +6 -6
  77. package/src/structures/Record.concatenated.test.ts +12 -10
  78. package/src/structures/Record.nested.test.ts +5 -5
  79. package/src/structures/RecordOf.ts +14 -12
  80. package/src/system/RegexpMatch._group.test.ts +4 -4
  81. package/src/system/RegexpMatch._main.test.ts +4 -4
  82. package/src/system/RegexpMatch.ts +9 -11
  83. package/src/system/RegexpMatched.test.ts +5 -5
  84. package/src/system/RegexpMatched.ts +8 -10
  85. package/src/system/RegexpReplaced.test.ts +5 -5
  86. package/src/system/RegexpReplaced.ts +10 -11
  87. package/src/system/Set.test.ts +5 -5
  88. package/src/system/Set.ts +9 -11
@@ -1,25 +1,27 @@
1
- import { Late, Of, Shared } from "silentium";
1
+ import { Late, Of, Shared, Transport } from "silentium";
2
2
  import { Concatenated } from "../strings";
3
3
  import { RecordOf } from "../structures/RecordOf";
4
4
  import { expect, test, vi } from "vitest";
5
5
 
6
6
  test("Record.concatenated.test", () => {
7
- const three = Of<string>("three");
8
- const concatPart = Late<string>("part");
7
+ const $three = Of<string>("three");
8
+ const $part = Late<string>("part");
9
9
  const r = Shared(
10
10
  RecordOf({
11
11
  one: Of("one"),
12
12
  two: Of("two"),
13
- three,
14
- nested: Concatenated([Of("one"), concatPart.event]),
13
+ three: $three,
14
+ nested: Concatenated([Of("one"), $part]),
15
15
  }),
16
16
  );
17
17
  const g = vi.fn();
18
- r.event(g);
18
+ r.event(Transport(g));
19
19
  let counter = 0;
20
- r.event(() => {
21
- counter += 1;
22
- });
20
+ r.event(
21
+ Transport(() => {
22
+ counter += 1;
23
+ }),
24
+ );
23
25
 
24
26
  expect(g).toHaveBeenLastCalledWith({
25
27
  one: "one",
@@ -28,7 +30,7 @@ test("Record.concatenated.test", () => {
28
30
  nested: "onepart",
29
31
  });
30
32
 
31
- concatPart.use("changed");
33
+ $part.use("changed");
32
34
 
33
35
  expect(g).toHaveBeenLastCalledWith({
34
36
  one: "one",
@@ -1,20 +1,20 @@
1
- import { Of } from "silentium";
1
+ import { Of, Transport } from "silentium";
2
2
  import { expect, test, vi } from "vitest";
3
3
  import { RecordOf } from "./RecordOf";
4
4
 
5
5
  test("Record.nested.test", () => {
6
- const three = Of<string>("three");
7
- const recordSrc = RecordOf({
6
+ const $three = Of<string>("three");
7
+ const $record = RecordOf({
8
8
  one: Of("one"),
9
9
  two: Of("two"),
10
- three,
10
+ three: $three,
11
11
  nested: RecordOf({
12
12
  four: Of("four"),
13
13
  five: Of("five"),
14
14
  }),
15
15
  });
16
16
  const g = vi.fn();
17
- recordSrc(g);
17
+ $record.event(Transport(g));
18
18
 
19
19
  expect(g).toHaveBeenLastCalledWith({
20
20
  one: "one",
@@ -1,4 +1,4 @@
1
- import { All, EventType } from "silentium";
1
+ import { All, Event, EventType, Transport } from "silentium";
2
2
 
3
3
  type UnInformation<T> = T extends EventType<infer U> ? U : never;
4
4
 
@@ -7,16 +7,18 @@ type UnInformation<T> = T extends EventType<infer U> ? U : never;
7
7
  * https://silentium-lab.github.io/silentium-components/#/structures/record
8
8
  */
9
9
  export function RecordOf<T extends EventType>(
10
- recordSrc: Record<string, T>,
10
+ record: Record<string, T>,
11
11
  ): EventType<Record<string, UnInformation<T>>> {
12
- return (user) => {
13
- const keys = Object.keys(recordSrc);
14
- All(...Object.values(recordSrc))((entries) => {
15
- const record: Record<string, any> = {};
16
- entries.forEach((entry, index) => {
17
- record[keys[index]] = entry;
18
- });
19
- user(record);
20
- });
21
- };
12
+ return Event((transport) => {
13
+ const keys = Object.keys(record);
14
+ All(...Object.values(record)).event(
15
+ Transport((entries) => {
16
+ const record: Record<string, any> = {};
17
+ entries.forEach((entry, index) => {
18
+ record[keys[index]] = entry;
19
+ });
20
+ transport.use(record);
21
+ }),
22
+ );
23
+ });
22
24
  }
@@ -1,13 +1,13 @@
1
- import { Of } from "silentium";
1
+ import { Of, Transport } from "silentium";
2
2
  import { expect, test, vi } from "vitest";
3
3
  import { Path } from "../behaviors";
4
4
  import { RegexpMatch } from "./RegexpMatch";
5
5
 
6
6
  test("RegexpMatch._group.test", () => {
7
- const urlSrc = Of<string>("http://domain.com/some/url/");
8
- const matchedSrc = Path(RegexpMatch(Of("/(s\\w+)/"), urlSrc), Of("1"));
7
+ const $url = Of<string>("http://domain.com/some/url/");
8
+ const $matched = Path(RegexpMatch(Of("/(s\\w+)/"), $url), Of("1"));
9
9
  const g = vi.fn();
10
- matchedSrc(g);
10
+ $matched.event(Transport(g));
11
11
 
12
12
  expect(g).toHaveBeenLastCalledWith("some");
13
13
  });
@@ -1,13 +1,13 @@
1
- import { Of } from "silentium";
1
+ import { Of, Transport } from "silentium";
2
2
  import { expect, test, vi } from "vitest";
3
3
  import { Path } from "../behaviors";
4
4
  import { RegexpMatch } from "./RegexpMatch";
5
5
 
6
6
  test("RegexpMatch._main.test", () => {
7
- const urlSrc = Of<string>("http://domain.com/some/url/");
8
- const matchedSrc = Path(RegexpMatch(Of("/(s\\w+)/"), urlSrc), Of("0"));
7
+ const $url = Of<string>("http://domain.com/some/url/");
8
+ const $matched = Path(RegexpMatch(Of("/(s\\w+)/"), $url), Of("0"));
9
9
  const g = vi.fn();
10
- matchedSrc(g);
10
+ $matched.event(Transport(g));
11
11
 
12
12
  expect(g).toHaveBeenLastCalledWith("/some/");
13
13
  });
@@ -1,4 +1,4 @@
1
- import { All, EventType, Of } from "silentium";
1
+ import { All, Event, EventType, Of, Transport } from "silentium";
2
2
 
3
3
  /**
4
4
  * First match Of regexp
@@ -9,14 +9,12 @@ export function RegexpMatch(
9
9
  valueSrc: EventType<string>,
10
10
  flagsSrc: EventType<string> = Of(""),
11
11
  ): EventType<string[]> {
12
- return (user) => {
13
- All(
14
- patternSrc,
15
- valueSrc,
16
- flagsSrc,
17
- )(([pattern, value, flags]) => {
18
- const result = new RegExp(pattern, flags).exec(value);
19
- user(result ?? []);
20
- });
21
- };
12
+ return Event((transport) => {
13
+ All(patternSrc, valueSrc, flagsSrc).event(
14
+ Transport(([pattern, value, flags]) => {
15
+ const result = new RegExp(pattern, flags).exec(value);
16
+ transport.use(result ?? []);
17
+ }),
18
+ );
19
+ });
22
20
  }
@@ -1,16 +1,16 @@
1
- import { Late, Of } from "silentium";
1
+ import { Late, Of, Transport } from "silentium";
2
2
  import { RegexpMatched } from "../system/RegexpMatched";
3
3
  import { expect, test, vi } from "vitest";
4
4
 
5
5
  test("RegexpMatched.test", () => {
6
- const urlI = Late<string>("http://domain.com/some/url/");
7
- const matchedSrc = RegexpMatched(Of("/some/url"), urlI.event);
6
+ const $url = Late<string>("http://domain.com/some/url/");
7
+ const $matched = RegexpMatched(Of("/some/url"), $url);
8
8
  const g = vi.fn();
9
- matchedSrc(g);
9
+ $matched.event(Transport(g));
10
10
 
11
11
  expect(g).toHaveBeenLastCalledWith(true);
12
12
 
13
- urlI.use("http://domain.com/changed");
13
+ $url.use("http://domain.com/changed");
14
14
 
15
15
  expect(g).toHaveBeenLastCalledWith(false);
16
16
  });
@@ -1,4 +1,4 @@
1
- import { All, EventType, Of } from "silentium";
1
+ import { All, Event, EventType, Of, Transport } from "silentium";
2
2
 
3
3
  /**
4
4
  * Boolean source what checks what string matches pattern
@@ -9,13 +9,11 @@ export function RegexpMatched(
9
9
  valueSrc: EventType<string>,
10
10
  flagsSrc: EventType<string> = Of(""),
11
11
  ): EventType<boolean> {
12
- return (user) => {
13
- All(
14
- patternSrc,
15
- valueSrc,
16
- flagsSrc,
17
- )(([pattern, value, flags]) => {
18
- user(new RegExp(pattern, flags).test(value));
19
- });
20
- };
12
+ return Event((transport) => {
13
+ All(patternSrc, valueSrc, flagsSrc).event(
14
+ Transport(([pattern, value, flags]) => {
15
+ transport.use(new RegExp(pattern, flags).test(value));
16
+ }),
17
+ );
18
+ });
21
19
  }
@@ -1,16 +1,16 @@
1
- import { Late, Of } from "silentium";
1
+ import { Late, Of, Transport } from "silentium";
2
2
  import { RegexpReplaced } from "../system/RegexpReplaced";
3
3
  import { expect, test, vi } from "vitest";
4
4
 
5
5
  test("RegexpReplaced.test", () => {
6
- const urlSrc = Late<string>("http://domain.com/some/url/");
7
- const matchedSrc = RegexpReplaced(urlSrc.event, Of("some/url/"), Of(""));
6
+ const $url = Late<string>("http://domain.com/some/url/");
7
+ const $matched = RegexpReplaced($url, Of("some/url/"), Of(""));
8
8
  const g = vi.fn();
9
- matchedSrc(g);
9
+ $matched.event(Transport(g));
10
10
 
11
11
  expect(g).toHaveBeenLastCalledWith("http://domain.com/");
12
12
 
13
- urlSrc.use("http://domain.com/some/url/changed/");
13
+ $url.use("http://domain.com/some/url/changed/");
14
14
 
15
15
  expect(g).toHaveBeenLastCalledWith("http://domain.com/changed/");
16
16
  });
@@ -1,4 +1,4 @@
1
- import { All, EventType, Of } from "silentium";
1
+ import { All, Event, EventType, Of, Transport } from "silentium";
2
2
 
3
3
  /**
4
4
  * Returns string replaced by regular expression pattern
@@ -10,14 +10,13 @@ export function RegexpReplaced(
10
10
  replaceValueSrc: EventType<string>,
11
11
  flagsSrc: EventType<string> = Of(""),
12
12
  ): EventType<string> {
13
- return (user) => {
14
- All(
15
- patternSrc,
16
- valueSrc,
17
- replaceValueSrc,
18
- flagsSrc,
19
- )(([pattern, value, replaceValue, flags]) => {
20
- user(String(value).replace(new RegExp(pattern, flags), replaceValue));
21
- });
22
- };
13
+ return Event((transport) => {
14
+ All(patternSrc, valueSrc, replaceValueSrc, flagsSrc).event(
15
+ Transport(([pattern, value, replaceValue, flags]) => {
16
+ transport.use(
17
+ String(value).replace(new RegExp(pattern, flags), replaceValue),
18
+ );
19
+ }),
20
+ );
21
+ });
23
22
  }
@@ -1,19 +1,19 @@
1
- import { Late, Of } from "silentium";
1
+ import { Late, Of, Transport } from "silentium";
2
2
  import { Set } from "../system/Set";
3
3
  import { expect, test, vi } from "vitest";
4
4
 
5
5
  test("Set.test", () => {
6
- const value = Late<string>();
6
+ const $value = Late<string>();
7
7
  const object = {
8
8
  value: "hello",
9
9
  };
10
- const obj = Set(Of(object), Of("value"), value.event);
10
+ const obj = Set(Of(object), Of("value"), $value);
11
11
  const g = vi.fn();
12
- obj(g);
12
+ obj.event(Transport(g));
13
13
 
14
14
  expect(object.value).toBe("hello");
15
15
 
16
- value.use("bue!");
16
+ $value.use("bue!");
17
17
 
18
18
  expect(object.value).toBe("bue!");
19
19
  });
package/src/system/Set.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { All, EventType } from "silentium";
1
+ import { All, Event, EventType, Transport } from "silentium";
2
2
 
3
3
  /**
4
4
  * Ability to mutate some object, helpful when integrate to procedure systems
@@ -9,14 +9,12 @@ export function Set<T extends Record<string, unknown>>(
9
9
  keySrc: EventType<string>,
10
10
  valueSrc: EventType<unknown>,
11
11
  ): EventType<T> {
12
- return (user) => {
13
- All(
14
- baseSrc,
15
- keySrc,
16
- valueSrc,
17
- )(([base, key, value]) => {
18
- (base as Record<string, unknown>)[key] = value;
19
- user(base);
20
- });
21
- };
12
+ return Event((transport) => {
13
+ All(baseSrc, keySrc, valueSrc).event(
14
+ Transport(([base, key, value]) => {
15
+ (base as Record<string, unknown>)[key] = value;
16
+ transport.use(base);
17
+ }),
18
+ );
19
+ });
22
20
  }