silentium 0.0.162 → 0.0.164

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.162",
3
+ "version": "0.0.164",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/base/Local.ts CHANGED
@@ -7,13 +7,14 @@ import { MaybeMessage } from "types/MessageType";
7
7
  */
8
8
  export function Local<T>(_base: MaybeMessage<T>) {
9
9
  const $base = ActualMessage(_base);
10
- return Message<T>(function LocalImpl(r) {
10
+ return Message<T>(function LocalImpl(resolve, reject) {
11
11
  let destroyed = false;
12
12
  $base.then((v) => {
13
13
  if (!destroyed) {
14
- r(v);
14
+ resolve(v);
15
15
  }
16
16
  });
17
+ $base.catch(reject);
17
18
  return () => {
18
19
  destroyed = true;
19
20
  };
@@ -21,4 +21,13 @@ describe("Applied.test", () => {
21
21
 
22
22
  expect(g).toBeCalledWith(4);
23
23
  });
24
+
25
+ test("value with applied function", () => {
26
+ const doubled = Applied(2, String);
27
+
28
+ const g = vi.fn();
29
+ doubled.then(g);
30
+
31
+ expect(g).toBeCalledWith("2");
32
+ });
24
33
  });
@@ -1,6 +1,7 @@
1
1
  import { describe, expect, test, vi } from "vitest";
2
2
  import { AppliedDestructured } from "components/AppliedDestructured";
3
3
  import { Of } from "base/Of";
4
+ import { All } from "components/All";
4
5
 
5
6
  describe("AppliedDestructured.test", () => {
6
7
  test("message with destructured applied function", () => {
@@ -24,8 +25,14 @@ describe("AppliedDestructured.test", () => {
24
25
 
25
26
  test("values with destructured applied function", async () => {
26
27
  const sum = AppliedDestructured([1, 2, 3], (a, b, c) => a + b + c);
27
- const r = await sum;
28
+ expect(await sum).toBe(6);
29
+ });
28
30
 
29
- expect(r).toBe(6);
31
+ test("values with destructured applied function", async () => {
32
+ const sum = AppliedDestructured(
33
+ All(Of(1), Of(2), Of(3)),
34
+ (a, b, c) => a + b + c,
35
+ );
36
+ expect(await sum).toBe(6);
30
37
  });
31
38
  });
@@ -8,7 +8,7 @@ import { MaybeMessage } from "types/MessageType";
8
8
  */
9
9
  export function AppliedDestructured<const T extends any[], R>(
10
10
  $base: MaybeMessage<T>,
11
- applier: ConstructorType<T[number][], R>,
11
+ applier: ConstructorType<any[], R>,
12
12
  ) {
13
13
  return Applied($base, function AppliedDestructuredImpl(args) {
14
14
  return applier(...args);
@@ -1,6 +1,7 @@
1
1
  import { Message } from "base/Message";
2
2
  import { Of } from "base/Of";
3
3
  import { Applied } from "components/Applied";
4
+ import { LateShared } from "components/LateShared";
4
5
  import { Map } from "components/Map";
5
6
  import { Diagram } from "testing/Diagram";
6
7
  import { wait } from "testing/wait";
@@ -62,4 +63,16 @@ describe("Map.test", () => {
62
63
 
63
64
  expect(d.toString()).toBe("2,4,6,18");
64
65
  });
66
+
67
+ test("map preserves array length", () => {
68
+ const d = Diagram();
69
+ const input = LateShared([1, 2, 3, 4, 5]);
70
+ const infoMapped = Map(input, x2);
71
+
72
+ Applied(infoMapped, (arr) => arr.length).then(d.resolver);
73
+ expect(d.toString()).toBe("5");
74
+
75
+ input.use([6, 7, 9]);
76
+ expect(d.toString()).toBe("5|3");
77
+ });
65
78
  });
@@ -21,6 +21,7 @@ export function Map<T, TG>(
21
21
  const infos: MessageType<TG>[] = [];
22
22
  const dc = DestroyContainer();
23
23
  $base.then((v) => {
24
+ infos.length = 0;
24
25
  dc.destroy();
25
26
  v.forEach((val) => {
26
27
  let $val: MessageType<T> | T = val;