silentium-components 0.0.83 → 0.0.85

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 (102) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/silentium-components.cjs +326 -411
  3. package/dist/silentium-components.cjs.map +1 -1
  4. package/dist/silentium-components.d.ts +80 -87
  5. package/dist/silentium-components.js +328 -412
  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 +328 -412
  11. package/dist/silentium-components.mjs.map +1 -1
  12. package/eslint.config.mjs +26 -12
  13. package/package.json +4 -2
  14. package/rollup.config.js +2 -1
  15. package/src/behaviors/Branch._main.test.ts +4 -3
  16. package/src/behaviors/Branch._values.test.ts +3 -2
  17. package/src/behaviors/Branch.branchesDontAffectResult.test.ts +4 -3
  18. package/src/behaviors/Branch.ts +13 -21
  19. package/src/behaviors/BranchLazy._main.test.ts +5 -4
  20. package/src/behaviors/BranchLazy.ts +17 -20
  21. package/src/behaviors/Const.test.ts +6 -7
  22. package/src/behaviors/Const.ts +5 -7
  23. package/src/behaviors/Deadline._main.test.ts +5 -4
  24. package/src/behaviors/Deadline._value.test.ts +4 -3
  25. package/src/behaviors/Deadline.ts +20 -27
  26. package/src/behaviors/Deferred.test.ts +5 -4
  27. package/src/behaviors/Deferred.ts +8 -10
  28. package/src/behaviors/Detached.test.ts +4 -3
  29. package/src/behaviors/Detached.ts +2 -2
  30. package/src/behaviors/Dirty.test.ts +4 -3
  31. package/src/behaviors/Dirty.ts +18 -45
  32. package/src/behaviors/Loading.test.ts +4 -3
  33. package/src/behaviors/Loading.ts +4 -4
  34. package/src/behaviors/Lock.test.ts +4 -3
  35. package/src/behaviors/Lock.ts +6 -8
  36. package/src/behaviors/Memo.test.ts +7 -8
  37. package/src/behaviors/Memo.ts +8 -10
  38. package/src/behaviors/OnlyChanged.test.ts +5 -4
  39. package/src/behaviors/OnlyChanged.ts +9 -11
  40. package/src/behaviors/Part.test.ts +12 -15
  41. package/src/behaviors/Part.ts +23 -40
  42. package/src/behaviors/Path._keyRaw.test.ts +3 -2
  43. package/src/behaviors/Path._main.test.ts +3 -2
  44. package/src/behaviors/Path.index.test.ts +3 -2
  45. package/src/behaviors/Path.nested.test.ts +4 -3
  46. package/src/behaviors/Path.ts +11 -14
  47. package/src/behaviors/Polling.test.ts +3 -2
  48. package/src/behaviors/Polling.ts +5 -7
  49. package/src/behaviors/Shot._main.test.ts +5 -4
  50. package/src/behaviors/Shot._onlyChanged.test.ts +9 -10
  51. package/src/behaviors/Shot.ts +8 -10
  52. package/src/behaviors/Task.test.ts +9 -12
  53. package/src/behaviors/Task.ts +11 -5
  54. package/src/behaviors/Tick.test.ts +5 -4
  55. package/src/behaviors/Tick.ts +9 -11
  56. package/src/behaviors/index.ts +0 -1
  57. package/src/boolean/And.test.ts +3 -2
  58. package/src/boolean/And.ts +5 -7
  59. package/src/boolean/Bool.test.ts +4 -3
  60. package/src/boolean/Bool.ts +2 -2
  61. package/src/boolean/Not.test.ts +4 -3
  62. package/src/boolean/Not.ts +5 -7
  63. package/src/boolean/Or.test.ts +4 -3
  64. package/src/boolean/Or.ts +5 -7
  65. package/src/boolean/index.ts +2 -2
  66. package/src/formats/FromJson.test.ts +2 -1
  67. package/src/formats/FromJson.ts +9 -12
  68. package/src/formats/ToJson.test.ts +1 -0
  69. package/src/formats/ToJson.ts +10 -12
  70. package/src/index.ts +4 -4
  71. package/src/lists/First.test.ts +3 -2
  72. package/src/lists/First.ts +2 -2
  73. package/src/navigation/Router._destroy.test.ts +14 -24
  74. package/src/navigation/Router._firstMatch.test.ts +7 -13
  75. package/src/navigation/Router._main.test.ts +7 -13
  76. package/src/navigation/Router._nested.test.ts +19 -30
  77. package/src/navigation/Router.ts +30 -34
  78. package/src/strings/Concatenated.test.ts +4 -3
  79. package/src/strings/Concatenated.ts +5 -7
  80. package/src/strings/Template._main.test.ts +5 -4
  81. package/src/strings/Template._place.test.ts +4 -3
  82. package/src/strings/Template.ts +21 -9
  83. package/src/structures/HashTable.test.ts +4 -3
  84. package/src/structures/HashTable.ts +6 -8
  85. package/src/structures/Record._main.test.ts +3 -2
  86. package/src/structures/Record._mixed.test.ts +3 -2
  87. package/src/structures/Record.concatenated.test.ts +7 -8
  88. package/src/structures/Record.nested.test.ts +3 -2
  89. package/src/structures/Record.ts +10 -14
  90. package/src/system/RegexpMatch._group.test.ts +3 -2
  91. package/src/system/RegexpMatch._main.test.ts +3 -2
  92. package/src/system/RegexpMatch.ts +12 -11
  93. package/src/system/RegexpMatched.test.ts +4 -3
  94. package/src/system/RegexpMatched.ts +11 -10
  95. package/src/system/RegexpReplaced.test.ts +4 -3
  96. package/src/system/RegexpReplaced.ts +6 -8
  97. package/src/system/Set.test.ts +4 -3
  98. package/src/system/Set.ts +9 -8
  99. package/src/system/index.ts +1 -1
  100. package/src/behaviors/Branch.dontRespondAfterRespond.test.ts +0 -35
  101. package/src/behaviors/Transaction.test.ts +0 -44
  102. package/src/behaviors/Transaction.ts +0 -42
@@ -4,7 +4,6 @@ import {
4
4
  MaybeMessage,
5
5
  Message,
6
6
  MessageType,
7
- Tap,
8
7
  } from "silentium";
9
8
 
10
9
  /**
@@ -17,18 +16,16 @@ export function Path<
17
16
  K extends string = any,
18
17
  >($base: MessageType<T>, _keyed: MaybeMessage<K>) {
19
18
  const $keyed = ActualMessage(_keyed);
20
- return Message<R>(function () {
21
- All($base, $keyed).pipe(
22
- Tap(([base, keyed]) => {
23
- const keys = keyed.split(".");
24
- let value: unknown = base;
25
- keys.forEach((key) => {
26
- value = (value as Record<string, unknown>)[key];
27
- });
28
- if (value !== undefined && value !== base) {
29
- this.use(value as R);
30
- }
31
- }),
32
- );
19
+ return Message<R>(function PathImpl(r) {
20
+ All($base, $keyed).then(([base, keyed]) => {
21
+ const keys = keyed.split(".");
22
+ let value: unknown = base;
23
+ keys.forEach((key) => {
24
+ value = (value as Record<string, unknown>)[key];
25
+ });
26
+ if (value !== undefined && value !== base) {
27
+ r(value as R);
28
+ }
29
+ });
33
30
  });
34
31
  }
@@ -1,13 +1,14 @@
1
1
  import { Late, Message, MessageType, Primitive } from "silentium";
2
2
  import { expect, test } from "vitest";
3
+
3
4
  import { Polling } from "../behaviors/Polling";
4
5
 
5
6
  test("Polling.test", () => {
6
7
  const $trigger = Late(1);
7
8
  let calls = 0;
8
- const $calls: MessageType<number> = Message((o) => {
9
+ const $calls: MessageType<number> = Message((r) => {
9
10
  calls += 1;
10
- o.use(calls);
11
+ r(calls);
11
12
  });
12
13
  const s = Primitive(Polling($calls, $trigger));
13
14
 
@@ -1,15 +1,13 @@
1
- import { Message, MessageType, Tap } from "silentium";
1
+ import { Message, MessageType } from "silentium";
2
2
 
3
3
  /**
4
4
  * Active polling of $base message
5
5
  * synchronized with $trigger message
6
6
  */
7
7
  export function Polling<T>($base: MessageType<T>, $trigger: MessageType<T>) {
8
- return Message<T>(function () {
9
- $trigger.pipe(
10
- Tap(() => {
11
- $base.pipe(this);
12
- }),
13
- );
8
+ return Message<T>(function PollingImpl(r) {
9
+ $trigger.then(() => {
10
+ $base.then(r);
11
+ });
14
12
  });
15
13
  }
@@ -1,14 +1,15 @@
1
- import { Late, Shared, Tap } from "silentium";
2
- import { Shot } from "../behaviors/Shot";
1
+ import { Late, Shared } from "silentium";
3
2
  import { expect, test, vi } from "vitest";
4
3
 
4
+ import { Shot } from "../behaviors/Shot";
5
+
5
6
  test("Shot._main.test", () => {
6
7
  const $base = Late();
7
8
  const $trigger = Late();
8
9
 
9
10
  const $shotted = Shared(Shot($base, $trigger));
10
11
  const g = vi.fn();
11
- $shotted.pipe(Tap(g));
12
+ $shotted.then(g);
12
13
 
13
14
  $base.use(1);
14
15
  $trigger.use(1);
@@ -24,6 +25,6 @@ test("Shot._main.test", () => {
24
25
  expect(g).toHaveBeenLastCalledWith(2);
25
26
 
26
27
  const g2 = vi.fn();
27
- $shotted.pipe(Tap(g2));
28
+ $shotted.then(g2);
28
29
  expect(g2).toHaveBeenLastCalledWith(2);
29
30
  });
@@ -1,24 +1,23 @@
1
- import { Late, Shared, Tap } from "silentium";
1
+ import { Late, Shared } from "silentium";
2
+ import { expect, test } from "vitest";
3
+
2
4
  import { OnlyChanged } from "../behaviors/OnlyChanged";
3
5
  import { Shot } from "../behaviors/Shot";
4
- import { expect, test } from "vitest";
5
6
 
6
7
  test("Shot._onlyChanged.test", () => {
7
- const $base = Late<number>(123);
8
- const $shared = Shared($base, true);
8
+ const $base = Late<number>();
9
+ const $shared = Shared($base);
9
10
  const $result = Shot($shared, OnlyChanged($shared));
10
11
 
11
12
  const vals: number[] = [];
12
13
 
13
- $result.pipe(
14
- Tap((v) => {
15
- vals.push(v);
16
- }),
17
- );
14
+ $result.then((v) => {
15
+ vals.push(v);
16
+ });
18
17
 
19
18
  expect(vals).toStrictEqual([]);
20
19
 
21
- $base.use(222);
20
+ $base.use(123);
22
21
 
23
22
  expect(vals).toStrictEqual([]);
24
23
 
@@ -1,20 +1,18 @@
1
- import { isFilled, Message, MessageType, Primitive, Tap } from "silentium";
1
+ import { isFilled, Message, MessageType, Primitive } from "silentium";
2
2
 
3
3
  /**
4
4
  * Helps to represent only last fresh value Of some source, refreshing controls by shotSrc
5
5
  * https://silentium-lab.github.io/silentium-components/#/behaviors/shot
6
6
  */
7
7
  export function Shot<T>($target: MessageType<T>, $trigger: MessageType) {
8
- return Message<T>(function () {
8
+ return Message<T>(function ShotImpl(r) {
9
9
  const targetSync = Primitive($target);
10
10
  targetSync.primitive();
11
- $trigger.pipe(
12
- Tap(() => {
13
- const value = targetSync.primitive();
14
- if (isFilled(value)) {
15
- this.use(value);
16
- }
17
- }),
18
- );
11
+ $trigger.then(() => {
12
+ const value = targetSync.primitive();
13
+ if (isFilled(value)) {
14
+ r(value);
15
+ }
16
+ });
19
17
  });
20
18
  }
@@ -1,7 +1,8 @@
1
- import { Late, Tap } from "silentium";
2
- import { Task } from "../behaviors/Task";
1
+ import { Late } from "silentium";
3
2
  import { afterEach, beforeEach, expect, test, vi } from "vitest";
4
3
 
4
+ import { Task } from "../behaviors/Task";
5
+
5
6
  beforeEach(() => {
6
7
  vi.useFakeTimers({ shouldAdvanceTime: true });
7
8
  });
@@ -15,11 +16,9 @@ test("Task delays emission", () => {
15
16
  const $trigger = Late<string>();
16
17
  const delayed = Task($trigger, 100);
17
18
  const data: string[] = [];
18
- delayed.pipe(
19
- Tap((v) => {
20
- data.push(v);
21
- }),
22
- );
19
+ delayed.then((v) => {
20
+ data.push(v);
21
+ });
23
22
 
24
23
  $trigger.use("first");
25
24
 
@@ -36,11 +35,9 @@ test("Task emits only last value when multiple before delay", () => {
36
35
  const $trigger = Late<string>();
37
36
  const delayed = Task($trigger, 100);
38
37
  const data: string[] = [];
39
- delayed.pipe(
40
- Tap((v) => {
41
- data.push(v);
42
- }),
43
- );
38
+ delayed.then((v) => {
39
+ data.push(v);
40
+ });
44
41
 
45
42
  $trigger.use("first");
46
43
  $trigger.use("second");
@@ -1,14 +1,20 @@
1
- import { ExecutorApplied, Message, MessageType } from "silentium";
1
+ import {
2
+ ActualMessage,
3
+ ExecutorApplied,
4
+ MaybeMessage,
5
+ Message,
6
+ } from "silentium";
2
7
 
3
8
  /**
4
9
  * Defer a message to the event loop
5
10
  * so that it executes once within
6
11
  * a certain timer firing interval
7
12
  */
8
- export function Task<T>(baseSrc: MessageType<T>, delay: number = 0) {
9
- return Message<T>(function () {
13
+ export function Task<T>(baseSrc: MaybeMessage<T>, delay: number = 0) {
14
+ const $base = ActualMessage(baseSrc);
15
+ return Message<T>(function TaskImpl(r) {
10
16
  let prevTimer: unknown | null = null;
11
- ExecutorApplied(baseSrc, (fn) => {
17
+ ExecutorApplied($base, (fn) => {
12
18
  return (v) => {
13
19
  if (prevTimer) {
14
20
  clearTimeout(prevTimer as number);
@@ -17,6 +23,6 @@ export function Task<T>(baseSrc: MessageType<T>, delay: number = 0) {
17
23
  fn(v);
18
24
  }, delay);
19
25
  };
20
- }).pipe(this);
26
+ }).then(r);
21
27
  });
22
28
  }
@@ -1,7 +1,8 @@
1
- import { Any, Late, Shared, Tap } from "silentium";
2
- import { Tick } from "../behaviors/Tick";
1
+ import { Any, Late, Shared } from "silentium";
3
2
  import { afterEach, beforeEach, expect, test, vi } from "vitest";
4
3
 
4
+ import { Tick } from "../behaviors/Tick";
5
+
5
6
  beforeEach(() => {
6
7
  vi.useFakeTimers({ shouldAdvanceTime: true });
7
8
  });
@@ -14,10 +15,10 @@ afterEach(() => {
14
15
  test("Tick.test", async () => {
15
16
  const $s1 = Late<number>(1);
16
17
  const $s2 = Late<number>(2);
17
- const $tick = Shared(Tick(Any($s1, $s2)), true);
18
+ const $tick = Shared(Tick(Any($s1, $s2)));
18
19
 
19
20
  const g = vi.fn();
20
- $tick.pipe(Tap(g));
21
+ $tick.then(g);
21
22
 
22
23
  $s1.use(3);
23
24
  $s2.use(4);
@@ -1,11 +1,11 @@
1
- import { Message, MessageType, Tap } from "silentium";
1
+ import { Message, MessageType } from "silentium";
2
2
 
3
3
  /**
4
4
  * Accumulates the last value Of the source and returns one result once per tick
5
5
  * https://silentium-lab.github.io/silentium-components/#/behaviors/tick
6
6
  */
7
7
  export function Tick<T>($base: MessageType<T>) {
8
- return Message(function () {
8
+ return Message<T>(function TickImpl(r) {
9
9
  let microtaskScheduled = false;
10
10
  let lastValue: T | null = null;
11
11
 
@@ -14,19 +14,17 @@ export function Tick<T>($base: MessageType<T>) {
14
14
  queueMicrotask(() => {
15
15
  microtaskScheduled = false;
16
16
  if (lastValue !== null) {
17
- this.use(lastValue);
17
+ r(lastValue);
18
18
  lastValue = null;
19
19
  }
20
20
  });
21
21
  };
22
22
 
23
- $base.pipe(
24
- Tap((v) => {
25
- lastValue = v;
26
- if (!microtaskScheduled) {
27
- scheduleMicrotask();
28
- }
29
- }),
30
- );
23
+ $base.then((v) => {
24
+ lastValue = v;
25
+ if (!microtaskScheduled) {
26
+ scheduleMicrotask();
27
+ }
28
+ });
31
29
  });
32
30
  }
@@ -15,4 +15,3 @@ export * from "./Polling";
15
15
  export * from "./Shot";
16
16
  export * from "./Task";
17
17
  export * from "./Tick";
18
- export * from "./Transaction";
@@ -1,5 +1,6 @@
1
- import { Late, Tap } from "silentium";
1
+ import { Late } from "silentium";
2
2
  import { expect, test, vi } from "vitest";
3
+
3
4
  import { And } from "../boolean/And";
4
5
 
5
6
  test("And.test", () => {
@@ -7,7 +8,7 @@ test("And.test", () => {
7
8
  const $two = Late<boolean>(false);
8
9
  const result = And($one, $two);
9
10
  const g = vi.fn();
10
- result.pipe(Tap(g));
11
+ result.then(g);
11
12
  expect(g).toHaveBeenLastCalledWith(false);
12
13
 
13
14
  $one.use(true);
@@ -1,15 +1,13 @@
1
- import { All, Message, MessageType, Tap } from "silentium";
1
+ import { All, Message, MessageType } from "silentium";
2
2
 
3
3
  /**
4
4
  * Logical AND over two messages
5
5
  * https://silentium-lab.github.io/silentium-components/#/boolean/and
6
6
  */
7
7
  export function And($one: MessageType<boolean>, $two: MessageType<boolean>) {
8
- return Message<boolean>(function () {
9
- All($one, $two).pipe(
10
- Tap(([one, two]) => {
11
- this.use(!!(one && two));
12
- }),
13
- );
8
+ return Message<boolean>(function AndImpl(r) {
9
+ All($one, $two).then(([one, two]) => {
10
+ r(!!(one && two));
11
+ });
14
12
  });
15
13
  }
@@ -1,9 +1,10 @@
1
- import { Of, Tap } from "silentium";
2
- import { Bool } from "../boolean/Bool";
1
+ import { Of } from "silentium";
3
2
  import { expect, test, vi } from "vitest";
4
3
 
4
+ import { Bool } from "../boolean/Bool";
5
+
5
6
  test("Bool.test", () => {
6
7
  const o = vi.fn();
7
- Bool(Of(1)).pipe(Tap(o));
8
+ Bool(Of(1)).then(o);
8
9
  expect(o).toHaveBeenCalledWith(true);
9
10
  });
@@ -5,7 +5,7 @@ import { Applied, Message, MessageType } from "silentium";
5
5
  * https://silentium-lab.github.io/silentium-components/#/boolean/bool
6
6
  */
7
7
  export function Bool($base: MessageType) {
8
- return Message<boolean>(function () {
9
- Applied($base, Boolean).pipe(this);
8
+ return Message<boolean>(function BoolImpl(r) {
9
+ Applied($base, Boolean).then(r);
10
10
  });
11
11
  }
@@ -1,12 +1,13 @@
1
- import { Late, Tap } from "silentium";
2
- import { Not } from "../boolean/Not";
1
+ import { Late } from "silentium";
3
2
  import { expect, test, vi } from "vitest";
4
3
 
4
+ import { Not } from "../boolean/Not";
5
+
5
6
  test("Not.test", () => {
6
7
  const one = Late<boolean>(false);
7
8
  const result = Not(one);
8
9
  const g = vi.fn();
9
- result.pipe(Tap(g));
10
+ result.then(g);
10
11
  expect(g).toHaveBeenLastCalledWith(true);
11
12
 
12
13
  one.use(true);
@@ -1,15 +1,13 @@
1
- import { Message, MessageType, Tap } from "silentium";
1
+ import { Message, MessageType } from "silentium";
2
2
 
3
3
  /**
4
4
  * Logical negation of message
5
5
  * https://silentium-lab.github.io/silentium-components/#/boolean/not
6
6
  */
7
7
  export function Not($base: MessageType<boolean>) {
8
- return Message<boolean>(function () {
9
- $base.pipe(
10
- Tap((v) => {
11
- this.use(!v);
12
- }),
13
- );
8
+ return Message<boolean>(function NotImpl(r) {
9
+ $base.then((v) => {
10
+ r(!v);
11
+ });
14
12
  });
15
13
  }
@@ -1,13 +1,14 @@
1
- import { Late, Tap } from "silentium";
2
- import { Or } from "../boolean/Or";
1
+ import { Late } from "silentium";
3
2
  import { expect, test, vi } from "vitest";
4
3
 
4
+ import { Or } from "../boolean/Or";
5
+
5
6
  test("Or.test", () => {
6
7
  const one = Late<boolean>(false);
7
8
  const two = Late<boolean>(false);
8
9
  const result = Or(one, two);
9
10
  const g = vi.fn();
10
- result.pipe(Tap(g));
11
+ result.then(g);
11
12
  expect(g).toHaveBeenLastCalledWith(false);
12
13
 
13
14
  one.use(true);
package/src/boolean/Or.ts CHANGED
@@ -1,15 +1,13 @@
1
- import { All, Message, MessageType, Tap } from "silentium";
1
+ import { All, Message, MessageType } from "silentium";
2
2
 
3
3
  /**
4
4
  * Logical OR over two messages
5
5
  * https://silentium-lab.github.io/silentium-components/#/boolean/or
6
6
  */
7
7
  export function Or($one: MessageType<boolean>, $two: MessageType<boolean>) {
8
- return Message<boolean>(function () {
9
- All($one, $two).pipe(
10
- Tap(([one, two]) => {
11
- this.use(!!(one || two));
12
- }),
13
- );
8
+ return Message<boolean>(function OrImpl(r) {
9
+ All($one, $two).then(([one, two]) => {
10
+ r(!!(one || two));
11
+ });
14
12
  });
15
13
  }
@@ -1,4 +1,4 @@
1
1
  export * from "./And";
2
- export * from "./Or";
3
- export * from "./Not";
4
2
  export * from "./Bool";
3
+ export * from "./Not";
4
+ export * from "./Or";
@@ -1,7 +1,8 @@
1
1
  import { Of, Primitive } from "silentium";
2
- import { FromJson } from "../formats/FromJson";
3
2
  import { expect, test } from "vitest";
4
3
 
4
+ import { FromJson } from "../formats/FromJson";
5
+
5
6
  test("FromJson.test", () => {
6
7
  const one = Of('{"hello": "world"}');
7
8
  const objectSync = Primitive(FromJson<{ hello: string }>(one));
@@ -1,21 +1,18 @@
1
- import { Message, MessageType, Tap, TapType } from "silentium";
1
+ import { Message, MessageType } from "silentium";
2
2
 
3
3
  /**
4
4
  * Represents object from json
5
5
  */
6
6
  export function FromJson<T = Record<string, unknown>>(
7
7
  $json: MessageType<string>,
8
- error?: TapType,
9
8
  ) {
10
- return Message<T>(function () {
11
- $json.pipe(
12
- Tap((json) => {
13
- try {
14
- this.use(JSON.parse(json));
15
- } catch (e) {
16
- error?.use(new Error(`Failed to parse JSON: ${e}`));
17
- }
18
- }),
19
- );
9
+ return Message<T>(function FromJsonImpl(resolve, reject) {
10
+ $json.then((json) => {
11
+ try {
12
+ resolve(JSON.parse(json));
13
+ } catch (e) {
14
+ reject(new Error(`Failed to parse JSON: ${e}`));
15
+ }
16
+ });
20
17
  });
21
18
  }
@@ -1,5 +1,6 @@
1
1
  import { Of, Primitive } from "silentium";
2
2
  import { expect, test } from "vitest";
3
+
3
4
  import { ToJson } from "../formats/ToJson";
4
5
 
5
6
  test("ToJson.test", () => {
@@ -1,18 +1,16 @@
1
- import { Message, MessageType, Tap, TapType } from "silentium";
1
+ import { Message, MessageType } from "silentium";
2
2
 
3
3
  /**
4
4
  * Represents json from object
5
5
  */
6
- export function ToJson($data: MessageType, error?: TapType) {
7
- return Message<string>(function () {
8
- $data.pipe(
9
- Tap((data: unknown) => {
10
- try {
11
- this.use(JSON.stringify(data));
12
- } catch {
13
- error?.use(new Error("Failed to convert to JSON"));
14
- }
15
- }),
16
- );
6
+ export function ToJson($data: MessageType) {
7
+ return Message<string>(function ToJsonImpl(resolve, reject) {
8
+ $data.then((data: unknown) => {
9
+ try {
10
+ resolve(JSON.stringify(data));
11
+ } catch {
12
+ reject(new Error("Failed to convert to JSON"));
13
+ }
14
+ });
17
15
  });
18
16
  }
package/src/index.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  export * from "./behaviors";
2
- export * from "./structures";
3
- export * from "./strings";
4
- export * from "./navigation";
5
- export * from "./system";
6
2
  export * from "./boolean";
7
3
  export * from "./formats";
8
4
  export * from "./lists";
5
+ export * from "./navigation";
6
+ export * from "./strings";
7
+ export * from "./structures";
8
+ export * from "./system";
@@ -1,10 +1,11 @@
1
- import { Of, Tap } from "silentium";
1
+ import { Of } from "silentium";
2
2
  import { expect, test, vi } from "vitest";
3
+
3
4
  import { First } from "./First";
4
5
 
5
6
  test("first", () => {
6
7
  const f = First(Of([1, 2, 3]));
7
8
  const g = vi.fn();
8
- f.pipe(Tap(g));
9
+ f.then(g);
9
10
  expect(g).toHaveBeenCalledWith(1);
10
11
  });
@@ -4,7 +4,7 @@ import { Applied, Message, MessageType } from "silentium";
4
4
  * Represents the first element Of an array.
5
5
  */
6
6
  export function First<T extends Array<unknown>>($base: MessageType<T>) {
7
- return Message<T[0]>(function () {
8
- Applied($base, (a) => a[0]).pipe(this);
7
+ return Message<T[0]>(function FirstImpl(r) {
8
+ Applied($base, (a) => a[0]).then(r);
9
9
  });
10
10
  }
@@ -1,15 +1,8 @@
1
- import {
2
- Applied,
3
- Late,
4
- Message,
5
- Of,
6
- Shared,
7
- Tap,
8
- TapMessage,
9
- } from "silentium";
10
- import { Router } from "../navigation/Router";
1
+ import { Applied, Late, Message, Of, Shared } from "silentium";
11
2
  import { expect, test, vi } from "vitest";
12
3
 
4
+ import { Router } from "../navigation/Router";
5
+
13
6
  const drop = (dropPart: string) => (value: string) => {
14
7
  return value.replace(dropPart, "");
15
8
  };
@@ -18,33 +11,30 @@ test("Router destroys previous route messages when switching routes", () => {
18
11
  const $url = Late<string>("http://domain.com/");
19
12
  const $urlPath = Shared(Applied($url, drop("http://domain.com")));
20
13
  const g = vi.fn();
21
- $urlPath.pipe(Tap(g));
14
+ $urlPath.then(g);
22
15
 
23
16
  // Create mock destroyable messages for routes
24
17
  const firstRouteDestroy = vi.fn();
25
18
  const secondRouteDestroy = vi.fn();
26
19
  const defaultDestroy = vi.fn();
27
20
 
28
- const $firstRoute = TapMessage(() =>
21
+ const $firstRoute = () =>
29
22
  Message<string>((transport) => {
30
- transport.use("first-route-response");
23
+ transport("first-route-response");
31
24
  return firstRouteDestroy;
32
- }),
33
- );
25
+ });
34
26
 
35
- const $secondRoute = TapMessage(() =>
27
+ const $secondRoute = () =>
36
28
  Message<string>((transport) => {
37
- transport.use("second-route-response");
29
+ transport("second-route-response");
38
30
  return secondRouteDestroy;
39
- }),
40
- );
31
+ });
41
32
 
42
- const $default = TapMessage(() =>
33
+ const $default = () =>
43
34
  Message<string>((transport) => {
44
- transport.use("default-response");
35
+ transport("default-response");
45
36
  return defaultDestroy;
46
- }),
47
- );
37
+ });
48
38
 
49
39
  const $router = Router(
50
40
  $urlPath,
@@ -62,7 +52,7 @@ test("Router destroys previous route messages when switching routes", () => {
62
52
  );
63
53
 
64
54
  const g2 = vi.fn();
65
- $router.pipe(Tap(g2));
55
+ $router.then(g2);
66
56
 
67
57
  // Initially no route matches, should use default
68
58
  expect(g2).toHaveBeenLastCalledWith("default-response");