silentium-components 0.0.82 → 0.0.83
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/CHANGELOG.md +7 -0
- package/dist/silentium-components.cjs +130 -130
- package/dist/silentium-components.cjs.map +1 -1
- package/dist/silentium-components.d.ts +9 -9
- package/dist/silentium-components.js +131 -131
- package/dist/silentium-components.js.map +1 -1
- package/dist/silentium-components.min.js +1 -1
- package/dist/silentium-components.min.mjs +1 -1
- package/dist/silentium-components.min.mjs.map +1 -1
- package/dist/silentium-components.mjs +131 -131
- package/dist/silentium-components.mjs.map +1 -1
- package/package.json +2 -2
- package/src/behaviors/Branch._main.test.ts +2 -2
- package/src/behaviors/Branch._values.test.ts +2 -2
- package/src/behaviors/Branch.branchesDontAffectResult.test.ts +2 -2
- package/src/behaviors/Branch.dontRespondAfterRespond.test.ts +5 -5
- package/src/behaviors/Branch.ts +5 -5
- package/src/behaviors/BranchLazy._main.test.ts +4 -4
- package/src/behaviors/BranchLazy.ts +8 -8
- package/src/behaviors/Const.test.ts +3 -3
- package/src/behaviors/Const.ts +5 -5
- package/src/behaviors/Deadline._main.test.ts +2 -2
- package/src/behaviors/Deadline._value.test.ts +3 -3
- package/src/behaviors/Deadline.ts +9 -9
- package/src/behaviors/Deferred.test.ts +3 -3
- package/src/behaviors/Deferred.ts +5 -11
- package/src/behaviors/Detached.test.ts +3 -3
- package/src/behaviors/Detached.ts +2 -2
- package/src/behaviors/Dirty.test.ts +2 -2
- package/src/behaviors/Dirty.ts +5 -5
- package/src/behaviors/Loading.test.ts +2 -2
- package/src/behaviors/Loading.ts +6 -6
- package/src/behaviors/Lock.test.ts +2 -2
- package/src/behaviors/Lock.ts +5 -5
- package/src/behaviors/Memo.test.ts +4 -4
- package/src/behaviors/Memo.ts +5 -5
- package/src/behaviors/OnlyChanged.test.ts +3 -3
- package/src/behaviors/OnlyChanged.ts +5 -5
- package/src/behaviors/Part.test.ts +3 -3
- package/src/behaviors/Part.ts +5 -5
- package/src/behaviors/Path._keyRaw.test.ts +2 -2
- package/src/behaviors/Path._main.test.ts +2 -2
- package/src/behaviors/Path.index.test.ts +2 -2
- package/src/behaviors/Path.nested.test.ts +2 -2
- package/src/behaviors/Path.ts +5 -5
- package/src/behaviors/Polling.ts +5 -5
- package/src/behaviors/Shot._main.test.ts +3 -3
- package/src/behaviors/Shot._onlyChanged.test.ts +3 -3
- package/src/behaviors/Shot.ts +5 -11
- package/src/behaviors/Task.test.ts +5 -5
- package/src/behaviors/Task.ts +2 -2
- package/src/behaviors/Tick.test.ts +2 -2
- package/src/behaviors/Tick.ts +5 -5
- package/src/behaviors/Transaction.ts +6 -6
- package/src/boolean/And.test.ts +2 -2
- package/src/boolean/And.ts +5 -5
- package/src/boolean/Bool.test.ts +2 -2
- package/src/boolean/Bool.ts +2 -2
- package/src/boolean/Not.test.ts +2 -2
- package/src/boolean/Not.ts +5 -5
- package/src/boolean/Or.test.ts +2 -2
- package/src/boolean/Or.ts +5 -5
- package/src/formats/FromJson.ts +6 -6
- package/src/formats/ToJson.ts +6 -6
- package/src/lists/First.test.ts +2 -2
- package/src/lists/First.ts +2 -2
- package/src/navigation/Router._destroy.test.ts +7 -7
- package/src/navigation/Router._firstMatch.test.ts +7 -7
- package/src/navigation/Router._main.test.ts +7 -7
- package/src/navigation/Router._nested.test.ts +16 -16
- package/src/navigation/Router.ts +11 -11
- package/src/strings/Concatenated.test.ts +2 -2
- package/src/strings/Concatenated.ts +5 -5
- package/src/strings/Template._main.test.ts +3 -3
- package/src/strings/Template._place.test.ts +2 -2
- package/src/strings/Template.ts +3 -3
- package/src/structures/HashTable.test.ts +2 -2
- package/src/structures/HashTable.ts +5 -5
- package/src/structures/Record._main.test.ts +2 -2
- package/src/structures/Record._mixed.test.ts +2 -2
- package/src/structures/Record.concatenated.test.ts +4 -4
- package/src/structures/Record.nested.test.ts +2 -2
- package/src/structures/Record.ts +5 -5
- package/src/system/RegexpMatch._group.test.ts +2 -2
- package/src/system/RegexpMatch._main.test.ts +2 -2
- package/src/system/RegexpMatch.ts +5 -5
- package/src/system/RegexpMatched.test.ts +2 -2
- package/src/system/RegexpMatched.ts +5 -5
- package/src/system/RegexpReplaced.test.ts +2 -2
- package/src/system/RegexpReplaced.ts +5 -5
- package/src/system/Set.test.ts +2 -2
- package/src/system/Set.ts +5 -5
package/src/boolean/Or.test.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Late,
|
|
1
|
+
import { Late, Tap } from "silentium";
|
|
2
2
|
import { Or } from "../boolean/Or";
|
|
3
3
|
import { expect, test, vi } from "vitest";
|
|
4
4
|
|
|
@@ -7,7 +7,7 @@ test("Or.test", () => {
|
|
|
7
7
|
const two = Late<boolean>(false);
|
|
8
8
|
const result = Or(one, two);
|
|
9
9
|
const g = vi.fn();
|
|
10
|
-
result.
|
|
10
|
+
result.pipe(Tap(g));
|
|
11
11
|
expect(g).toHaveBeenLastCalledWith(false);
|
|
12
12
|
|
|
13
13
|
one.use(true);
|
package/src/boolean/Or.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { All, Message, MessageType,
|
|
1
|
+
import { All, Message, MessageType, Tap } 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>((
|
|
9
|
-
All($one, $two).
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
return Message<boolean>(function () {
|
|
9
|
+
All($one, $two).pipe(
|
|
10
|
+
Tap(([one, two]) => {
|
|
11
|
+
this.use(!!(one || two));
|
|
12
12
|
}),
|
|
13
13
|
);
|
|
14
14
|
});
|
package/src/formats/FromJson.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { Message, MessageType,
|
|
1
|
+
import { Message, MessageType, Tap, TapType } 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?:
|
|
8
|
+
error?: TapType,
|
|
9
9
|
) {
|
|
10
|
-
return Message<T>((
|
|
11
|
-
$json.
|
|
12
|
-
|
|
10
|
+
return Message<T>(function () {
|
|
11
|
+
$json.pipe(
|
|
12
|
+
Tap((json) => {
|
|
13
13
|
try {
|
|
14
|
-
|
|
14
|
+
this.use(JSON.parse(json));
|
|
15
15
|
} catch (e) {
|
|
16
16
|
error?.use(new Error(`Failed to parse JSON: ${e}`));
|
|
17
17
|
}
|
package/src/formats/ToJson.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { Message, MessageType,
|
|
1
|
+
import { Message, MessageType, Tap, TapType } from "silentium";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Represents json from object
|
|
5
5
|
*/
|
|
6
|
-
export function ToJson($data: MessageType, error?:
|
|
7
|
-
return Message<string>((
|
|
8
|
-
$data.
|
|
9
|
-
|
|
6
|
+
export function ToJson($data: MessageType, error?: TapType) {
|
|
7
|
+
return Message<string>(function () {
|
|
8
|
+
$data.pipe(
|
|
9
|
+
Tap((data: unknown) => {
|
|
10
10
|
try {
|
|
11
|
-
|
|
11
|
+
this.use(JSON.stringify(data));
|
|
12
12
|
} catch {
|
|
13
13
|
error?.use(new Error("Failed to convert to JSON"));
|
|
14
14
|
}
|
package/src/lists/First.test.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Of,
|
|
1
|
+
import { Of, Tap } from "silentium";
|
|
2
2
|
import { expect, test, vi } from "vitest";
|
|
3
3
|
import { First } from "./First";
|
|
4
4
|
|
|
5
5
|
test("first", () => {
|
|
6
6
|
const f = First(Of([1, 2, 3]));
|
|
7
7
|
const g = vi.fn();
|
|
8
|
-
f.
|
|
8
|
+
f.pipe(Tap(g));
|
|
9
9
|
expect(g).toHaveBeenCalledWith(1);
|
|
10
10
|
});
|
package/src/lists/First.ts
CHANGED
|
@@ -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]>((
|
|
8
|
-
Applied($base, (a) => a[0]).
|
|
7
|
+
return Message<T[0]>(function () {
|
|
8
|
+
Applied($base, (a) => a[0]).pipe(this);
|
|
9
9
|
});
|
|
10
10
|
}
|
|
@@ -4,8 +4,8 @@ import {
|
|
|
4
4
|
Message,
|
|
5
5
|
Of,
|
|
6
6
|
Shared,
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
Tap,
|
|
8
|
+
TapMessage,
|
|
9
9
|
} from "silentium";
|
|
10
10
|
import { Router } from "../navigation/Router";
|
|
11
11
|
import { expect, test, vi } from "vitest";
|
|
@@ -18,28 +18,28 @@ test("Router destroys previous route messages when switching routes", () => {
|
|
|
18
18
|
const $url = Late<string>("http://domain.com/");
|
|
19
19
|
const $urlPath = Shared(Applied($url, drop("http://domain.com")));
|
|
20
20
|
const g = vi.fn();
|
|
21
|
-
$urlPath.
|
|
21
|
+
$urlPath.pipe(Tap(g));
|
|
22
22
|
|
|
23
23
|
// Create mock destroyable messages for routes
|
|
24
24
|
const firstRouteDestroy = vi.fn();
|
|
25
25
|
const secondRouteDestroy = vi.fn();
|
|
26
26
|
const defaultDestroy = vi.fn();
|
|
27
27
|
|
|
28
|
-
const $firstRoute =
|
|
28
|
+
const $firstRoute = TapMessage(() =>
|
|
29
29
|
Message<string>((transport) => {
|
|
30
30
|
transport.use("first-route-response");
|
|
31
31
|
return firstRouteDestroy;
|
|
32
32
|
}),
|
|
33
33
|
);
|
|
34
34
|
|
|
35
|
-
const $secondRoute =
|
|
35
|
+
const $secondRoute = TapMessage(() =>
|
|
36
36
|
Message<string>((transport) => {
|
|
37
37
|
transport.use("second-route-response");
|
|
38
38
|
return secondRouteDestroy;
|
|
39
39
|
}),
|
|
40
40
|
);
|
|
41
41
|
|
|
42
|
-
const $default =
|
|
42
|
+
const $default = TapMessage(() =>
|
|
43
43
|
Message<string>((transport) => {
|
|
44
44
|
transport.use("default-response");
|
|
45
45
|
return defaultDestroy;
|
|
@@ -62,7 +62,7 @@ test("Router destroys previous route messages when switching routes", () => {
|
|
|
62
62
|
);
|
|
63
63
|
|
|
64
64
|
const g2 = vi.fn();
|
|
65
|
-
$router.
|
|
65
|
+
$router.pipe(Tap(g2));
|
|
66
66
|
|
|
67
67
|
// Initially no route matches, should use default
|
|
68
68
|
expect(g2).toHaveBeenLastCalledWith("default-response");
|
|
@@ -3,8 +3,8 @@ import {
|
|
|
3
3
|
Late,
|
|
4
4
|
Of,
|
|
5
5
|
Shared,
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
Tap,
|
|
7
|
+
TapMessage,
|
|
8
8
|
} from "silentium";
|
|
9
9
|
import { expect, test, vi } from "vitest";
|
|
10
10
|
import { Router } from "../navigation/Router";
|
|
@@ -17,7 +17,7 @@ test("Router first matching route responds, not subsequent matches", () => {
|
|
|
17
17
|
const $url = Late<string>("http://domain.com/page/general");
|
|
18
18
|
const $urlPath = Shared(Applied($url, drop("http://domain.com")));
|
|
19
19
|
const g = vi.fn();
|
|
20
|
-
$urlPath.
|
|
20
|
+
$urlPath.pipe(Tap(g));
|
|
21
21
|
|
|
22
22
|
const firstRouteMock = vi.fn(() => Of("first-route-response"));
|
|
23
23
|
const secondRouteMock = vi.fn(() => Of("second-route-response"));
|
|
@@ -27,17 +27,17 @@ test("Router first matching route responds, not subsequent matches", () => {
|
|
|
27
27
|
Of([
|
|
28
28
|
{
|
|
29
29
|
pattern: "^/page/.*", // This matches /page/anything
|
|
30
|
-
message:
|
|
30
|
+
message: TapMessage(firstRouteMock),
|
|
31
31
|
},
|
|
32
32
|
{
|
|
33
33
|
pattern: "^/page/specific$", // This also matches /page/specific
|
|
34
|
-
message:
|
|
34
|
+
message: TapMessage(secondRouteMock),
|
|
35
35
|
},
|
|
36
36
|
]),
|
|
37
|
-
|
|
37
|
+
TapMessage(() => Of<string>("page/404.html")),
|
|
38
38
|
);
|
|
39
39
|
const g2 = vi.fn();
|
|
40
|
-
$router.
|
|
40
|
+
$router.pipe(Tap(g2));
|
|
41
41
|
|
|
42
42
|
// Initial URL should match first route
|
|
43
43
|
expect(g2).toHaveBeenLastCalledWith("first-route-response");
|
|
@@ -3,8 +3,8 @@ import {
|
|
|
3
3
|
Late,
|
|
4
4
|
Of,
|
|
5
5
|
Shared,
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
Tap,
|
|
7
|
+
TapMessage,
|
|
8
8
|
} from "silentium";
|
|
9
9
|
import { expect, test, vi } from "vitest";
|
|
10
10
|
import { Router } from "../navigation/Router";
|
|
@@ -17,24 +17,24 @@ test("Router._main.test", () => {
|
|
|
17
17
|
const $url = Late<string>("http://domain.com/");
|
|
18
18
|
const $urlPath = Shared(Applied($url, drop("http://domain.com")));
|
|
19
19
|
const g = vi.fn();
|
|
20
|
-
$urlPath.
|
|
20
|
+
$urlPath.pipe(Tap(g));
|
|
21
21
|
|
|
22
22
|
const $router = Router(
|
|
23
23
|
$urlPath,
|
|
24
24
|
Of([
|
|
25
25
|
{
|
|
26
26
|
pattern: "^/$",
|
|
27
|
-
message:
|
|
27
|
+
message: TapMessage(() => Of("page/home.html")),
|
|
28
28
|
},
|
|
29
29
|
{
|
|
30
30
|
pattern: "/some/contacts",
|
|
31
|
-
message:
|
|
31
|
+
message: TapMessage(() => Of("page/contacts.html")),
|
|
32
32
|
},
|
|
33
33
|
]),
|
|
34
|
-
|
|
34
|
+
TapMessage(() => Of<string>("page/404.html")),
|
|
35
35
|
);
|
|
36
36
|
const g2 = vi.fn();
|
|
37
|
-
$router.
|
|
37
|
+
$router.pipe(Tap(g2));
|
|
38
38
|
|
|
39
39
|
expect(g2).toHaveBeenLastCalledWith("page/home.html");
|
|
40
40
|
|
|
@@ -2,8 +2,8 @@ import {
|
|
|
2
2
|
LateShared,
|
|
3
3
|
Message,
|
|
4
4
|
Of,
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
Tap,
|
|
6
|
+
TapMessage,
|
|
7
7
|
} from "silentium";
|
|
8
8
|
import { describe, expect, test } from "vitest";
|
|
9
9
|
import { Detached } from "../behaviors/Detached";
|
|
@@ -17,11 +17,11 @@ describe("Router._nested.test", () => {
|
|
|
17
17
|
Of([
|
|
18
18
|
{
|
|
19
19
|
pattern: "^/$",
|
|
20
|
-
message:
|
|
20
|
+
message: TapMessage(() => Of<string>("home")),
|
|
21
21
|
},
|
|
22
22
|
{
|
|
23
23
|
pattern: "/admin.*",
|
|
24
|
-
message:
|
|
24
|
+
message: TapMessage(() => {
|
|
25
25
|
return Message((transport) => {
|
|
26
26
|
// need to replace with detached component
|
|
27
27
|
const localUrlSrc = Detached($url);
|
|
@@ -31,19 +31,19 @@ describe("Router._nested.test", () => {
|
|
|
31
31
|
Of([
|
|
32
32
|
{
|
|
33
33
|
pattern: "^/admin/articles$",
|
|
34
|
-
message:
|
|
34
|
+
message: TapMessage(() => Of("articles list")),
|
|
35
35
|
},
|
|
36
36
|
{
|
|
37
37
|
pattern: "^/admin/articles/create$",
|
|
38
|
-
message:
|
|
38
|
+
message: TapMessage(() => Of("articles create")),
|
|
39
39
|
},
|
|
40
40
|
{
|
|
41
41
|
pattern: "^/admin/articles/update$",
|
|
42
|
-
message:
|
|
42
|
+
message: TapMessage(() => Of("articles update")),
|
|
43
43
|
},
|
|
44
44
|
{
|
|
45
45
|
pattern: "^/admin/nested/.*$",
|
|
46
|
-
message:
|
|
46
|
+
message: TapMessage(() => {
|
|
47
47
|
return Message((transport) => {
|
|
48
48
|
const localUrlSrc = Detached($url);
|
|
49
49
|
|
|
@@ -52,17 +52,17 @@ describe("Router._nested.test", () => {
|
|
|
52
52
|
Of([
|
|
53
53
|
{
|
|
54
54
|
pattern: "^/admin/nested/list$",
|
|
55
|
-
message:
|
|
55
|
+
message: TapMessage(() =>
|
|
56
56
|
Of("admin nested list"),
|
|
57
57
|
),
|
|
58
58
|
},
|
|
59
59
|
]),
|
|
60
|
-
|
|
60
|
+
TapMessage(() =>
|
|
61
61
|
Of<string>("admin nested not found"),
|
|
62
62
|
),
|
|
63
63
|
);
|
|
64
64
|
|
|
65
|
-
r.
|
|
65
|
+
r.pipe(transport);
|
|
66
66
|
|
|
67
67
|
return function AdminDestroy() {
|
|
68
68
|
r.destroy();
|
|
@@ -71,10 +71,10 @@ describe("Router._nested.test", () => {
|
|
|
71
71
|
}),
|
|
72
72
|
},
|
|
73
73
|
]),
|
|
74
|
-
|
|
74
|
+
TapMessage(() => Of<string>("admin not found")),
|
|
75
75
|
);
|
|
76
76
|
|
|
77
|
-
r.
|
|
77
|
+
r.pipe(transport);
|
|
78
78
|
|
|
79
79
|
return function AdminDestroy() {
|
|
80
80
|
r.destroy();
|
|
@@ -83,11 +83,11 @@ describe("Router._nested.test", () => {
|
|
|
83
83
|
}),
|
|
84
84
|
},
|
|
85
85
|
]),
|
|
86
|
-
|
|
86
|
+
TapMessage(() => Of("not found")),
|
|
87
87
|
);
|
|
88
88
|
const d: string[] = [];
|
|
89
|
-
$router.
|
|
90
|
-
|
|
89
|
+
$router.pipe(
|
|
90
|
+
Tap((v) => {
|
|
91
91
|
d.push(v);
|
|
92
92
|
}),
|
|
93
93
|
);
|
package/src/navigation/Router.ts
CHANGED
|
@@ -5,15 +5,15 @@ import {
|
|
|
5
5
|
Message,
|
|
6
6
|
MessageType,
|
|
7
7
|
Of,
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
Tap,
|
|
9
|
+
TapType,
|
|
10
10
|
} from "silentium";
|
|
11
11
|
import { RegexpMatched } from "../system";
|
|
12
12
|
|
|
13
13
|
export interface Route<T> {
|
|
14
14
|
pattern: string;
|
|
15
15
|
patternFlags?: string;
|
|
16
|
-
message:
|
|
16
|
+
message: TapType<void, MessageType<T>>;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/**
|
|
@@ -23,15 +23,15 @@ export interface Route<T> {
|
|
|
23
23
|
export function Router<T = "string">(
|
|
24
24
|
$url: MessageType<string>,
|
|
25
25
|
$routes: MessageType<Route<T>[]>,
|
|
26
|
-
$default:
|
|
26
|
+
$default: TapType<void, MessageType<T>>,
|
|
27
27
|
): MessageType<T> & DestroyableType {
|
|
28
|
-
return Message<T>((
|
|
28
|
+
return Message<T>(function () {
|
|
29
29
|
const dc = DestroyContainer();
|
|
30
30
|
const destructor = () => {
|
|
31
31
|
dc.destroy();
|
|
32
32
|
};
|
|
33
|
-
All($routes, $url).
|
|
34
|
-
|
|
33
|
+
All($routes, $url).pipe(
|
|
34
|
+
Tap(([routes, url]) => {
|
|
35
35
|
destructor();
|
|
36
36
|
const $matches = All(
|
|
37
37
|
...routes.map((r) =>
|
|
@@ -42,20 +42,20 @@ export function Router<T = "string">(
|
|
|
42
42
|
),
|
|
43
43
|
),
|
|
44
44
|
);
|
|
45
|
-
$matches.
|
|
46
|
-
|
|
45
|
+
$matches.pipe(
|
|
46
|
+
Tap((matches) => {
|
|
47
47
|
const index = matches.findIndex((v) => v === true);
|
|
48
48
|
|
|
49
49
|
if (index === -1) {
|
|
50
50
|
const instance = $default.use();
|
|
51
51
|
dc.add(instance);
|
|
52
|
-
instance.
|
|
52
|
+
instance.pipe(this);
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
if (index > -1) {
|
|
56
56
|
const instance = routes[index].message.use();
|
|
57
57
|
dc.add(instance);
|
|
58
|
-
instance.
|
|
58
|
+
instance.pipe(this);
|
|
59
59
|
}
|
|
60
60
|
}),
|
|
61
61
|
);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Of,
|
|
1
|
+
import { Of, Tap } from "silentium";
|
|
2
2
|
import { Concatenated } from "../strings/Concatenated";
|
|
3
3
|
import { expect, test, vi } from "vitest";
|
|
4
4
|
|
|
@@ -8,7 +8,7 @@ test("Concatenated.test", () => {
|
|
|
8
8
|
Of("-"),
|
|
9
9
|
);
|
|
10
10
|
const g = vi.fn();
|
|
11
|
-
$concatenated.
|
|
11
|
+
$concatenated.pipe(Tap(g));
|
|
12
12
|
|
|
13
13
|
expect(g).toHaveBeenLastCalledWith("one-two-three");
|
|
14
14
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { All, Message, MessageType, Of,
|
|
1
|
+
import { All, Message, MessageType, Of, Tap } from "silentium";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Join sources Of strings to one source
|
|
@@ -8,10 +8,10 @@ export function Concatenated(
|
|
|
8
8
|
sources: MessageType<string>[],
|
|
9
9
|
joinPartSrc: MessageType<string> = Of(""),
|
|
10
10
|
) {
|
|
11
|
-
return Message<string>((
|
|
12
|
-
All(joinPartSrc, ...sources).
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
return Message<string>(function () {
|
|
12
|
+
All(joinPartSrc, ...sources).pipe(
|
|
13
|
+
Tap(([joinPart, ...strings]) => {
|
|
14
|
+
this.use(strings.join(joinPart));
|
|
15
15
|
}),
|
|
16
16
|
);
|
|
17
17
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Of,
|
|
1
|
+
import { Of, Tap } from "silentium";
|
|
2
2
|
import { Template } from "../strings/Template";
|
|
3
3
|
import { Record } from "../structures";
|
|
4
4
|
import { expect, test, vi } from "vitest";
|
|
@@ -11,7 +11,7 @@ test("Template._main.test", () => {
|
|
|
11
11
|
}),
|
|
12
12
|
);
|
|
13
13
|
const g = vi.fn();
|
|
14
|
-
tpl.
|
|
14
|
+
tpl.pipe(Tap(g));
|
|
15
15
|
|
|
16
16
|
expect(g).toHaveBeenLastCalledWith("<h1>one value</h1>");
|
|
17
17
|
|
|
@@ -22,7 +22,7 @@ test("Template._main.test", () => {
|
|
|
22
22
|
}),
|
|
23
23
|
);
|
|
24
24
|
const g2 = vi.fn();
|
|
25
|
-
tpl2.
|
|
25
|
+
tpl2.pipe(Tap(g2));
|
|
26
26
|
|
|
27
27
|
expect(g2).toHaveBeenLastCalledWith("<h2>second value</h2>");
|
|
28
28
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Of,
|
|
1
|
+
import { Of, Tap } from "silentium";
|
|
2
2
|
import { Template } from "../strings/Template";
|
|
3
3
|
import { expect, test, vi } from "vitest";
|
|
4
4
|
|
|
@@ -6,7 +6,7 @@ test("Template._place.test", () => {
|
|
|
6
6
|
const t = Template();
|
|
7
7
|
t.template(`<div class="greeting">Hello ${t.var(Of("User"))}</div>`);
|
|
8
8
|
const g = vi.fn();
|
|
9
|
-
t.
|
|
9
|
+
t.pipe(Tap(g));
|
|
10
10
|
|
|
11
11
|
expect(g).toHaveBeenLastCalledWith('<div class="greeting">Hello User</div>');
|
|
12
12
|
});
|
package/src/strings/Template.ts
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
isDestroyable,
|
|
7
7
|
MessageType,
|
|
8
8
|
Of,
|
|
9
|
-
|
|
9
|
+
TapType,
|
|
10
10
|
} from "silentium";
|
|
11
11
|
import { Record } from "../structures";
|
|
12
12
|
|
|
@@ -33,7 +33,7 @@ class TemplateImpl implements MessageType<string>, DestroyableType {
|
|
|
33
33
|
private $places: MessageType<Record<string, unknown>> = Of({}),
|
|
34
34
|
) {}
|
|
35
35
|
|
|
36
|
-
public
|
|
36
|
+
public pipe(transport: TapType<string>): this {
|
|
37
37
|
const $vars = Record(this.vars);
|
|
38
38
|
Applied(All(this.$src, this.$places, $vars), ([base, rules, vars]) => {
|
|
39
39
|
Object.entries(rules).forEach(([ph, val]) => {
|
|
@@ -44,7 +44,7 @@ class TemplateImpl implements MessageType<string>, DestroyableType {
|
|
|
44
44
|
});
|
|
45
45
|
|
|
46
46
|
return base;
|
|
47
|
-
}).
|
|
47
|
+
}).pipe(transport);
|
|
48
48
|
return this;
|
|
49
49
|
}
|
|
50
50
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Late,
|
|
1
|
+
import { Late, Tap } from "silentium";
|
|
2
2
|
import { HashTable } from "../structures/HashTable";
|
|
3
3
|
import { expect, test, vi } from "vitest";
|
|
4
4
|
|
|
@@ -6,7 +6,7 @@ test("HashTable.test", () => {
|
|
|
6
6
|
const $entry = Late<[string, string]>();
|
|
7
7
|
const $hash = HashTable($entry);
|
|
8
8
|
const g = vi.fn();
|
|
9
|
-
$hash.
|
|
9
|
+
$hash.pipe(Tap(g));
|
|
10
10
|
$entry.use(["key-one", "value-one"]);
|
|
11
11
|
$entry.use(["key-two", "value-two"]);
|
|
12
12
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Message, MessageType,
|
|
1
|
+
import { Message, MessageType, Tap } from "silentium";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* By receiving a message with a key and value, collects a table
|
|
@@ -6,13 +6,13 @@ import { Message, MessageType, Transport } from "silentium";
|
|
|
6
6
|
* https://silentium-lab.github.io/silentium-components/#/structures/hash-table
|
|
7
7
|
*/
|
|
8
8
|
export function HashTable<T>($base: MessageType<[string, unknown]>) {
|
|
9
|
-
return Message<T>((
|
|
9
|
+
return Message<T>(function () {
|
|
10
10
|
const record: Record<string, unknown> = {};
|
|
11
11
|
|
|
12
|
-
$base.
|
|
13
|
-
|
|
12
|
+
$base.pipe(
|
|
13
|
+
Tap(([key, value]) => {
|
|
14
14
|
record[key] = value;
|
|
15
|
-
|
|
15
|
+
this.use(record as T);
|
|
16
16
|
}),
|
|
17
17
|
);
|
|
18
18
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Late, Of,
|
|
1
|
+
import { Late, Of, Tap } from "silentium";
|
|
2
2
|
import { expect, test, vi } from "vitest";
|
|
3
3
|
import { Record } from "./Record";
|
|
4
4
|
|
|
@@ -10,7 +10,7 @@ test("Record._main.test", () => {
|
|
|
10
10
|
three: $three,
|
|
11
11
|
});
|
|
12
12
|
const g = vi.fn();
|
|
13
|
-
$record.
|
|
13
|
+
$record.pipe(Tap(g));
|
|
14
14
|
|
|
15
15
|
expect(g).toHaveBeenLastCalledWith({
|
|
16
16
|
one: "one",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Late,
|
|
1
|
+
import { Late, Tap } from "silentium";
|
|
2
2
|
import { expect, test, vi } from "vitest";
|
|
3
3
|
import { Record } from "./Record";
|
|
4
4
|
|
|
@@ -10,7 +10,7 @@ test("Record._mixed.test", () => {
|
|
|
10
10
|
three: $three,
|
|
11
11
|
});
|
|
12
12
|
const g = vi.fn();
|
|
13
|
-
$record.
|
|
13
|
+
$record.pipe(Tap(g));
|
|
14
14
|
|
|
15
15
|
expect(g).toHaveBeenLastCalledWith({
|
|
16
16
|
one: "one",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Late, Of, Shared,
|
|
1
|
+
import { Late, Of, Shared, Tap } from "silentium";
|
|
2
2
|
import { Concatenated } from "../strings";
|
|
3
3
|
import { Record } from "./Record";
|
|
4
4
|
import { expect, test, vi } from "vitest";
|
|
@@ -15,10 +15,10 @@ test("Record.concatenated.test", () => {
|
|
|
15
15
|
}),
|
|
16
16
|
);
|
|
17
17
|
const g = vi.fn();
|
|
18
|
-
r.
|
|
18
|
+
r.pipe(Tap(g));
|
|
19
19
|
let counter = 0;
|
|
20
|
-
r.
|
|
21
|
-
|
|
20
|
+
r.pipe(
|
|
21
|
+
Tap(() => {
|
|
22
22
|
counter += 1;
|
|
23
23
|
}),
|
|
24
24
|
);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Of,
|
|
1
|
+
import { Of, Tap } from "silentium";
|
|
2
2
|
import { expect, test, vi } from "vitest";
|
|
3
3
|
import { Record } from "./Record";
|
|
4
4
|
|
|
@@ -14,7 +14,7 @@ test("Record.nested.test", () => {
|
|
|
14
14
|
}),
|
|
15
15
|
});
|
|
16
16
|
const g = vi.fn();
|
|
17
|
-
$record.
|
|
17
|
+
$record.pipe(Tap(g));
|
|
18
18
|
|
|
19
19
|
expect(g).toHaveBeenLastCalledWith({
|
|
20
20
|
one: "one",
|
package/src/structures/Record.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { All, isMessage, Message, MessageType, Of,
|
|
1
|
+
import { All, isMessage, Message, MessageType, Of, Tap } from "silentium";
|
|
2
2
|
|
|
3
3
|
type UnWrap<T> = T extends MessageType<infer U> ? U : T;
|
|
4
4
|
|
|
@@ -7,20 +7,20 @@ type UnWrap<T> = T extends MessageType<infer U> ? U : T;
|
|
|
7
7
|
* https://silentium-lab.github.io/silentium-components/#/structures/record
|
|
8
8
|
*/
|
|
9
9
|
export function Record<T>(record: Record<string, T>) {
|
|
10
|
-
return Message<Record<string, UnWrap<T>>>((
|
|
10
|
+
return Message<Record<string, UnWrap<T>>>(function () {
|
|
11
11
|
const keys = Object.keys(record);
|
|
12
12
|
keys.forEach((key) => {
|
|
13
13
|
if (!isMessage(record[key])) {
|
|
14
14
|
record[key] = Of(record[key]) as any;
|
|
15
15
|
}
|
|
16
16
|
});
|
|
17
|
-
All(...(Object.values(record) as any)).
|
|
18
|
-
|
|
17
|
+
All(...(Object.values(record) as any)).pipe(
|
|
18
|
+
Tap((entries) => {
|
|
19
19
|
const record: Record<string, any> = {};
|
|
20
20
|
entries.forEach((entry, index) => {
|
|
21
21
|
record[keys[index]] = entry;
|
|
22
22
|
});
|
|
23
|
-
|
|
23
|
+
this.use(record);
|
|
24
24
|
}),
|
|
25
25
|
);
|
|
26
26
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Of,
|
|
1
|
+
import { Of, Tap } from "silentium";
|
|
2
2
|
import { expect, test, vi } from "vitest";
|
|
3
3
|
import { Path } from "../behaviors";
|
|
4
4
|
import { RegexpMatch } from "./RegexpMatch";
|
|
@@ -7,7 +7,7 @@ test("RegexpMatch._group.test", () => {
|
|
|
7
7
|
const $url = Of<string>("http://domain.com/some/url/");
|
|
8
8
|
const $matched = Path(RegexpMatch(Of("/(s\\w+)/"), $url), Of("1"));
|
|
9
9
|
const g = vi.fn();
|
|
10
|
-
$matched.
|
|
10
|
+
$matched.pipe(Tap(g));
|
|
11
11
|
|
|
12
12
|
expect(g).toHaveBeenLastCalledWith("some");
|
|
13
13
|
});
|