silentium 0.0.175 → 0.0.176

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.
@@ -5,6 +5,6 @@ import { describe, expect, test } from "vitest";
5
5
  describe("DevTools.test", () => {
6
6
  DevTools();
7
7
  test("raw value of silentium message", () => {
8
- expect(silentiumValue(Of(123))).toBe(123);
8
+ expect(silentiumDebug.value(Of(123))).toBe(123);
9
9
  });
10
10
  });
@@ -2,30 +2,69 @@ import { All } from "components/All";
2
2
  import { Applied } from "components/Applied";
3
3
  import { Primitive } from "components/Primitive";
4
4
  import { Shared } from "components/Shared";
5
+ import { DestroyableType } from "types/DestroyableType";
5
6
  import { MessageType } from "types/MessageType";
6
7
 
7
8
  declare global {
8
9
  interface GlobalThis {
9
- silentiumValue: ($message: MessageType) => unknown;
10
- silentiumPrint: (...messages: MessageType[]) => void;
10
+ silentiumDebug: {
11
+ value: ($message: MessageType) => unknown;
12
+ print: (...messages: MessageType[]) => void;
13
+ destroyable: (
14
+ onDestroy: () => void,
15
+ ) => MessageType<any> & DestroyableType;
16
+ };
11
17
  }
12
18
  }
13
19
 
20
+ /**
21
+ * Helps to print message value
22
+ */
14
23
  const silentiumPrint = (...messages: MessageType[]) => {
15
24
  Applied(All(...messages.map((e) => Shared(e))), JSON.stringify).then(
16
25
  console.log,
17
26
  );
18
27
  };
28
+
29
+ /**
30
+ * Helps to debug current value of message
31
+ */
19
32
  const silentiumValue = ($message: MessageType) =>
20
33
  Primitive($message).primitive();
21
34
 
35
+ class MessageDestroyable implements MessageType<any>, DestroyableType {
36
+ public constructor(private onDestroy: () => void) {}
37
+
38
+ public then() {
39
+ return this;
40
+ }
41
+
42
+ public catch() {
43
+ return this;
44
+ }
45
+
46
+ public destroy() {
47
+ this.onDestroy();
48
+ return this;
49
+ }
50
+ }
51
+
52
+ /**
53
+ * Helps to debug destroying
54
+ */
55
+ const silentiumDestroyable = (onDestroy: () => void) =>
56
+ new MessageDestroyable(onDestroy);
57
+
22
58
  /**
23
59
  * global functions for debuging
24
60
  * silentium programs
25
61
  */
26
62
  export function DevTools() {
27
63
  if (typeof globalThis !== "undefined") {
28
- (globalThis as any).silentiumValue = silentiumValue;
29
- (globalThis as any).silentiumPrint = silentiumPrint;
64
+ (globalThis as any).silentiumDebug = {
65
+ value: silentiumValue,
66
+ print: silentiumPrint,
67
+ destroyable: silentiumDestroyable,
68
+ };
30
69
  }
31
70
  }