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.
- package/CHANGELOG.md +12 -0
- package/dist/silentium-components.cjs +491 -436
- package/dist/silentium-components.cjs.map +1 -1
- package/dist/silentium-components.d.ts +42 -36
- package/dist/silentium-components.js +493 -438
- 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 +493 -438
- package/dist/silentium-components.mjs.map +1 -1
- package/package.json +2 -2
- package/src/behaviors/Branch._main.test.ts +3 -3
- package/src/behaviors/Branch.branchesDontAffectResult.test.ts +4 -4
- package/src/behaviors/Branch.dontRespondAfterRespond.test.ts +6 -6
- package/src/behaviors/Branch.ts +23 -24
- package/src/behaviors/BranchLazy._main.test.ts +5 -5
- package/src/behaviors/BranchLazy.ts +31 -23
- package/src/behaviors/Const.test.ts +10 -8
- package/src/behaviors/Const.ts +9 -10
- package/src/behaviors/Deadline._main.test.ts +4 -4
- package/src/behaviors/Deadline._value.test.ts +5 -5
- package/src/behaviors/Deadline.ts +37 -28
- package/src/behaviors/Deferred.test.ts +10 -10
- package/src/behaviors/Deferred.ts +14 -12
- package/src/behaviors/Detached.test.ts +4 -4
- package/src/behaviors/Detached.ts +6 -6
- package/src/behaviors/Dirty.test.ts +3 -3
- package/src/behaviors/Dirty.ts +46 -26
- package/src/behaviors/Loading.test.ts +7 -10
- package/src/behaviors/Loading.ts +9 -9
- package/src/behaviors/Lock.test.ts +3 -3
- package/src/behaviors/Lock.ts +12 -10
- package/src/behaviors/Memo.test.ts +8 -6
- package/src/behaviors/Memo.ts +13 -12
- package/src/behaviors/OnlyChanged.test.ts +4 -4
- package/src/behaviors/OnlyChanged.ts +14 -13
- package/src/behaviors/Part.test.ts +6 -6
- package/src/behaviors/Part.ts +53 -30
- 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 +20 -21
- package/src/behaviors/Polling.test.ts +10 -10
- package/src/behaviors/Polling.ts +10 -8
- package/src/behaviors/Shot._main.test.ts +10 -10
- package/src/behaviors/Shot._onlyChanged.test.ts +13 -11
- package/src/behaviors/Shot.ts +15 -12
- package/src/behaviors/Task.ts +4 -4
- package/src/behaviors/Tick.test.ts +7 -7
- package/src/behaviors/Tick.ts +13 -11
- package/src/behaviors/Transaction.test.ts +3 -3
- package/src/behaviors/Transaction.ts +13 -12
- package/src/boolean/And.test.ts +11 -11
- package/src/boolean/And.ts +10 -11
- package/src/boolean/Bool.test.ts +2 -2
- package/src/boolean/Bool.ts +5 -5
- package/src/boolean/Not.test.ts +3 -3
- package/src/boolean/Not.ts +9 -7
- package/src/boolean/Or.test.ts +3 -3
- package/src/boolean/Or.ts +10 -11
- package/src/formats/FromJson.ts +14 -12
- package/src/formats/ToJson.ts +14 -12
- package/src/lists/First.test.ts +2 -2
- package/src/lists/First.ts +5 -5
- package/src/navigation/Router._main.test.ts +20 -13
- package/src/navigation/Router._nested.test.ts +41 -33
- package/src/navigation/Router.ts +48 -50
- package/src/strings/Concatenated.test.ts +3 -3
- package/src/strings/Concatenated.ts +8 -9
- package/src/strings/Template._main.test.ts +3 -3
- package/src/strings/Template._place.test.ts +2 -2
- package/src/strings/Template.ts +54 -40
- package/src/structures/HashTable.test.ts +6 -6
- package/src/structures/HashTable.ts +10 -8
- package/src/structures/Record._main.test.ts +6 -6
- package/src/structures/Record.concatenated.test.ts +12 -10
- package/src/structures/Record.nested.test.ts +5 -5
- package/src/structures/RecordOf.ts +14 -12
- package/src/system/RegexpMatch._group.test.ts +4 -4
- package/src/system/RegexpMatch._main.test.ts +4 -4
- package/src/system/RegexpMatch.ts +9 -11
- package/src/system/RegexpMatched.test.ts +5 -5
- package/src/system/RegexpMatched.ts +8 -10
- package/src/system/RegexpReplaced.test.ts +5 -5
- package/src/system/RegexpReplaced.ts +10 -11
- package/src/system/Set.test.ts +5 -5
- package/src/system/Set.ts +9 -11
package/src/lists/First.test.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Of } from "silentium";
|
|
1
|
+
import { Of, Transport } 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(g);
|
|
8
|
+
f.event(Transport(g));
|
|
9
9
|
expect(g).toHaveBeenCalledWith(1);
|
|
10
10
|
});
|
package/src/lists/First.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Applied, EventType } from "silentium";
|
|
1
|
+
import { Applied, Event, EventType } from "silentium";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Represents the first element Of an array.
|
|
5
5
|
*/
|
|
6
6
|
export function First<T extends Array<unknown>>(
|
|
7
|
-
|
|
7
|
+
$base: EventType<T>,
|
|
8
8
|
): EventType<T[0]> {
|
|
9
|
-
return (
|
|
10
|
-
Applied(
|
|
11
|
-
};
|
|
9
|
+
return Event((transport) => {
|
|
10
|
+
Applied($base, (a) => a[0]).event(transport);
|
|
11
|
+
});
|
|
12
12
|
}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Applied,
|
|
3
|
+
Late,
|
|
4
|
+
Of,
|
|
5
|
+
Shared,
|
|
6
|
+
Transport,
|
|
7
|
+
TransportEvent,
|
|
8
|
+
} from "silentium";
|
|
2
9
|
import { Router } from "../navigation/Router";
|
|
3
10
|
import { expect, test, vi } from "vitest";
|
|
4
11
|
|
|
@@ -7,40 +14,40 @@ const drop = (dropPart: string) => (value: string) => {
|
|
|
7
14
|
};
|
|
8
15
|
|
|
9
16
|
test("Router._main.test", () => {
|
|
10
|
-
const
|
|
11
|
-
const
|
|
17
|
+
const $url = Late<string>("http://domain.com/");
|
|
18
|
+
const $urlPath = Shared(Applied($url, drop("http://domain.com")));
|
|
12
19
|
const g = vi.fn();
|
|
13
|
-
|
|
20
|
+
$urlPath.event(Transport(g));
|
|
14
21
|
|
|
15
|
-
const
|
|
16
|
-
|
|
22
|
+
const $router = Router(
|
|
23
|
+
$urlPath,
|
|
17
24
|
Of([
|
|
18
25
|
{
|
|
19
26
|
pattern: "^/$",
|
|
20
|
-
|
|
27
|
+
event: TransportEvent(() => Of("page/home.html")),
|
|
21
28
|
},
|
|
22
29
|
{
|
|
23
30
|
pattern: "/some/contacts",
|
|
24
|
-
|
|
31
|
+
event: TransportEvent(() => Of("page/contacts.html")),
|
|
25
32
|
},
|
|
26
33
|
]),
|
|
27
|
-
() => Of<string>("page/404.html"),
|
|
34
|
+
TransportEvent(() => Of<string>("page/404.html")),
|
|
28
35
|
);
|
|
29
36
|
const g2 = vi.fn();
|
|
30
|
-
|
|
37
|
+
$router.event(Transport(g2));
|
|
31
38
|
|
|
32
39
|
expect(g2).toHaveBeenLastCalledWith("page/home.html");
|
|
33
40
|
|
|
34
|
-
|
|
41
|
+
$url.use("http://domain.com/some/contacts");
|
|
35
42
|
|
|
36
43
|
expect(g).toHaveBeenLastCalledWith("/some/contacts");
|
|
37
44
|
expect(g2).toHaveBeenLastCalledWith("page/contacts.html");
|
|
38
45
|
|
|
39
|
-
|
|
46
|
+
$url.use("http://domain.com/some/unknown/");
|
|
40
47
|
|
|
41
48
|
expect(g2).toHaveBeenLastCalledWith("page/404.html");
|
|
42
49
|
|
|
43
|
-
|
|
50
|
+
$url.use("http://domain.com/");
|
|
44
51
|
|
|
45
52
|
expect(g2).toHaveBeenLastCalledWith("page/home.html");
|
|
46
53
|
});
|
|
@@ -1,88 +1,96 @@
|
|
|
1
|
-
import { LateShared, Of } from "silentium";
|
|
1
|
+
import { Event, LateShared, Of, Transport, TransportEvent } from "silentium";
|
|
2
2
|
import { describe, expect, test } from "vitest";
|
|
3
3
|
import { Detached } from "../behaviors/Detached";
|
|
4
4
|
import { Router } from "../navigation/Router";
|
|
5
5
|
|
|
6
6
|
describe("Router._nested.test", () => {
|
|
7
7
|
test("Вложенные роуты", () => {
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
8
|
+
const $url = LateShared("/");
|
|
9
|
+
const $router = Router(
|
|
10
|
+
$url,
|
|
11
11
|
Of([
|
|
12
12
|
{
|
|
13
13
|
pattern: "^/$",
|
|
14
|
-
|
|
14
|
+
event: TransportEvent(() => Of<string>("home")),
|
|
15
15
|
},
|
|
16
16
|
{
|
|
17
17
|
pattern: "/admin.*",
|
|
18
|
-
|
|
19
|
-
return (
|
|
18
|
+
event: TransportEvent(() => {
|
|
19
|
+
return Event((transport) => {
|
|
20
20
|
// need to replace with detached component
|
|
21
|
-
const localUrlSrc = Detached(
|
|
21
|
+
const localUrlSrc = Detached($url);
|
|
22
22
|
|
|
23
23
|
const r = Router(
|
|
24
24
|
localUrlSrc,
|
|
25
25
|
Of([
|
|
26
26
|
{
|
|
27
27
|
pattern: "^/admin/articles$",
|
|
28
|
-
|
|
28
|
+
event: TransportEvent(() => Of("articles list")),
|
|
29
29
|
},
|
|
30
30
|
{
|
|
31
31
|
pattern: "^/admin/articles/create$",
|
|
32
|
-
|
|
32
|
+
event: TransportEvent(() => Of("articles create")),
|
|
33
33
|
},
|
|
34
34
|
{
|
|
35
35
|
pattern: "^/admin/articles/update$",
|
|
36
|
-
|
|
36
|
+
event: TransportEvent(() => Of("articles update")),
|
|
37
37
|
},
|
|
38
38
|
{
|
|
39
39
|
pattern: "^/admin/nested/.*$",
|
|
40
|
-
|
|
41
|
-
return (
|
|
42
|
-
const localUrlSrc = Detached(
|
|
40
|
+
event: TransportEvent(() => {
|
|
41
|
+
return Event((transport) => {
|
|
42
|
+
const localUrlSrc = Detached($url);
|
|
43
43
|
|
|
44
44
|
const r = Router(
|
|
45
45
|
localUrlSrc,
|
|
46
46
|
Of([
|
|
47
47
|
{
|
|
48
48
|
pattern: "^/admin/nested/list$",
|
|
49
|
-
|
|
49
|
+
event: TransportEvent(() =>
|
|
50
|
+
Of("admin nested list"),
|
|
51
|
+
),
|
|
50
52
|
},
|
|
51
53
|
]),
|
|
52
|
-
() =>
|
|
54
|
+
TransportEvent(() =>
|
|
55
|
+
Of<string>("admin nested not found"),
|
|
56
|
+
),
|
|
53
57
|
);
|
|
54
|
-
|
|
58
|
+
|
|
59
|
+
r.event(transport);
|
|
55
60
|
|
|
56
61
|
return function AdminDestroy() {
|
|
57
|
-
|
|
62
|
+
r.destroy();
|
|
58
63
|
};
|
|
59
|
-
};
|
|
60
|
-
},
|
|
64
|
+
});
|
|
65
|
+
}),
|
|
61
66
|
},
|
|
62
67
|
]),
|
|
63
|
-
() => Of<string>("admin not found"),
|
|
68
|
+
TransportEvent(() => Of<string>("admin not found")),
|
|
64
69
|
);
|
|
65
|
-
|
|
70
|
+
|
|
71
|
+
r.event(transport);
|
|
66
72
|
|
|
67
73
|
return function AdminDestroy() {
|
|
68
|
-
|
|
74
|
+
r.destroy();
|
|
69
75
|
};
|
|
70
|
-
};
|
|
71
|
-
},
|
|
76
|
+
});
|
|
77
|
+
}),
|
|
72
78
|
},
|
|
73
79
|
]),
|
|
74
|
-
() => Of("not found"),
|
|
80
|
+
TransportEvent(() => Of("not found")),
|
|
75
81
|
);
|
|
76
82
|
const d: string[] = [];
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
83
|
+
$router.event(
|
|
84
|
+
Transport((v) => {
|
|
85
|
+
d.push(v);
|
|
86
|
+
}),
|
|
87
|
+
);
|
|
80
88
|
const pd = () => d.join("\n");
|
|
81
89
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
90
|
+
$url.use("/admin/articles");
|
|
91
|
+
$url.use("/admin/nested/list");
|
|
92
|
+
$url.use("/admin/articles/create");
|
|
93
|
+
$url.use("/admin/articles/update");
|
|
86
94
|
|
|
87
95
|
expect(pd()).toBe(`home
|
|
88
96
|
articles list
|
package/src/navigation/Router.ts
CHANGED
|
@@ -1,76 +1,74 @@
|
|
|
1
1
|
import {
|
|
2
2
|
All,
|
|
3
3
|
Applied,
|
|
4
|
+
DestroyableType,
|
|
5
|
+
Event,
|
|
4
6
|
EventType,
|
|
5
|
-
Destructor,
|
|
6
|
-
DestructorType,
|
|
7
7
|
Of,
|
|
8
|
-
|
|
8
|
+
Transport,
|
|
9
|
+
TransportDestroyable,
|
|
10
|
+
TransportEvent,
|
|
11
|
+
TransportType,
|
|
9
12
|
} from "silentium";
|
|
10
|
-
import { RegexpMatched } from "../system";
|
|
11
13
|
import { BranchLazy } from "../behaviors";
|
|
14
|
+
import { RegexpMatched } from "../system";
|
|
12
15
|
|
|
13
16
|
export interface Route<T> {
|
|
14
17
|
pattern: string;
|
|
15
18
|
patternFlags?: string;
|
|
16
|
-
|
|
19
|
+
event: TransportType<[], EventType<T>>;
|
|
17
20
|
}
|
|
18
21
|
|
|
19
|
-
const
|
|
22
|
+
const $empty = TransportEvent(() => Of(false));
|
|
20
23
|
|
|
21
24
|
/**
|
|
22
25
|
* Router component what will return template if url matches pattern
|
|
23
26
|
* https://silentium-lab.github.io/silentium-components/#/navigation/router
|
|
24
27
|
*/
|
|
25
28
|
export function Router<T = "string">(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
): EventType<T> {
|
|
30
|
-
return (
|
|
31
|
-
const destructors:
|
|
32
|
-
const
|
|
33
|
-
destructors.forEach((d) => d());
|
|
29
|
+
$url: EventType<string>,
|
|
30
|
+
$routes: EventType<Route<T>[]>,
|
|
31
|
+
$default: TransportType<void, EventType<T>>,
|
|
32
|
+
): EventType<T> & DestroyableType {
|
|
33
|
+
return Event<T>((transport) => {
|
|
34
|
+
const destructors: DestroyableType[] = [];
|
|
35
|
+
const destructor = () => {
|
|
36
|
+
destructors.forEach((d) => d.destroy());
|
|
34
37
|
destructors.length = 0;
|
|
35
38
|
};
|
|
36
|
-
All(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
Of(url),
|
|
51
|
-
r.patternFlags ? Of(r.patternFlags) : undefined,
|
|
52
|
-
),
|
|
53
|
-
r.template,
|
|
54
|
-
emptySrc,
|
|
39
|
+
All($routes, $url).event(
|
|
40
|
+
Transport(([routes, url]) => {
|
|
41
|
+
destructor();
|
|
42
|
+
const instance = All(
|
|
43
|
+
$default.use(),
|
|
44
|
+
All(
|
|
45
|
+
...routes.map((r) => {
|
|
46
|
+
const $template = TransportDestroyable(r.event);
|
|
47
|
+
destructors.push($template);
|
|
48
|
+
return BranchLazy(
|
|
49
|
+
RegexpMatched(
|
|
50
|
+
Of(r.pattern),
|
|
51
|
+
Of(url),
|
|
52
|
+
r.patternFlags ? Of(r.patternFlags) : undefined,
|
|
55
53
|
),
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
$template,
|
|
55
|
+
$empty,
|
|
56
|
+
);
|
|
57
|
+
}),
|
|
58
58
|
),
|
|
59
|
-
)
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
// Return first not false or default
|
|
63
|
-
Applied(instance, (r) => {
|
|
64
|
-
const firstReal = r[1].find((r) => r !== false);
|
|
65
|
-
|
|
66
|
-
if (firstReal) {
|
|
67
|
-
return firstReal as T;
|
|
68
|
-
}
|
|
59
|
+
);
|
|
69
60
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
61
|
+
// Return first not false or default
|
|
62
|
+
Applied(instance, (r) => {
|
|
63
|
+
const first = r[1].find((r: unknown) => r !== false);
|
|
64
|
+
if (first) {
|
|
65
|
+
return first as T;
|
|
66
|
+
}
|
|
67
|
+
return r[0];
|
|
68
|
+
}).event(transport);
|
|
69
|
+
}),
|
|
70
|
+
);
|
|
73
71
|
|
|
74
|
-
return
|
|
75
|
-
};
|
|
72
|
+
return destructor;
|
|
73
|
+
});
|
|
76
74
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { Of } from "silentium";
|
|
1
|
+
import { Of, Transport } from "silentium";
|
|
2
2
|
import { Concatenated } from "../strings/Concatenated";
|
|
3
3
|
import { expect, test, vi } from "vitest";
|
|
4
4
|
|
|
5
5
|
test("Concatenated.test", () => {
|
|
6
|
-
const
|
|
6
|
+
const $concatenated = Concatenated(
|
|
7
7
|
[Of("one"), Of("two"), Of("three")],
|
|
8
8
|
Of("-"),
|
|
9
9
|
);
|
|
10
10
|
const g = vi.fn();
|
|
11
|
-
|
|
11
|
+
$concatenated.event(Transport(g));
|
|
12
12
|
|
|
13
13
|
expect(g).toHaveBeenLastCalledWith("one-two-three");
|
|
14
14
|
});
|
|
@@ -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
|
* Join sources Of strings to one source
|
|
@@ -8,12 +8,11 @@ export function Concatenated(
|
|
|
8
8
|
sources: EventType<string>[],
|
|
9
9
|
joinPartSrc: EventType<string> = Of(""),
|
|
10
10
|
): EventType<string> {
|
|
11
|
-
return (
|
|
12
|
-
All(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
};
|
|
11
|
+
return Event((transport) => {
|
|
12
|
+
All(joinPartSrc, ...sources).event(
|
|
13
|
+
Transport(([joinPart, ...strings]) => {
|
|
14
|
+
transport.use(strings.join(joinPart));
|
|
15
|
+
}),
|
|
16
|
+
);
|
|
17
|
+
});
|
|
19
18
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Of } from "silentium";
|
|
1
|
+
import { Of, Transport } from "silentium";
|
|
2
2
|
import { Template } from "../strings/Template";
|
|
3
3
|
import { RecordOf } 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.event(Transport(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.event(Transport(g2));
|
|
26
26
|
|
|
27
27
|
expect(g2).toHaveBeenLastCalledWith("<h2>second value</h2>");
|
|
28
28
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Of } from "silentium";
|
|
1
|
+
import { Of, Transport } 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.event(Transport(g));
|
|
10
10
|
|
|
11
11
|
expect(g).toHaveBeenLastCalledWith('<div class="greeting">Hello User</div>');
|
|
12
12
|
});
|
package/src/strings/Template.ts
CHANGED
|
@@ -1,53 +1,67 @@
|
|
|
1
1
|
import {
|
|
2
2
|
All,
|
|
3
3
|
Applied,
|
|
4
|
+
DestroyableType,
|
|
5
|
+
DestroyContainer,
|
|
4
6
|
EventType,
|
|
5
|
-
|
|
6
|
-
DestructorType,
|
|
7
|
+
isDestroyable,
|
|
7
8
|
Of,
|
|
9
|
+
TransportType,
|
|
8
10
|
} from "silentium";
|
|
9
11
|
import { RecordOf } from "../structures";
|
|
10
12
|
|
|
11
13
|
export function Template(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
$src: EventType<string> = Of(""),
|
|
15
|
+
$places: EventType<Record<string, unknown>> = Of({}),
|
|
14
16
|
) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
return new TemplateEvent($src, $places);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
class TemplateEvent implements EventType<string>, DestroyableType {
|
|
21
|
+
private dc = DestroyContainer();
|
|
22
|
+
private vars: Record<string, EventType> = {
|
|
17
23
|
$TPL: Of("$TPL"),
|
|
18
24
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
25
|
+
|
|
26
|
+
public constructor(
|
|
27
|
+
private $src: EventType<string> = Of(""),
|
|
28
|
+
private $places: EventType<Record<string, unknown>> = Of({}),
|
|
29
|
+
) {}
|
|
30
|
+
|
|
31
|
+
public event(transport: TransportType<string, null>): this {
|
|
32
|
+
const $vars = RecordOf(this.vars);
|
|
33
|
+
Applied(All(this.$src, this.$places, $vars), ([base, rules, vars]) => {
|
|
34
|
+
Object.entries(rules).forEach(([ph, val]) => {
|
|
35
|
+
base = base.replaceAll(ph, String(val));
|
|
36
|
+
});
|
|
37
|
+
Object.entries(vars).forEach(([ph, val]) => {
|
|
38
|
+
base = base.replaceAll(ph, String(val));
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
return base;
|
|
42
|
+
}).event(transport);
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public template(value: string) {
|
|
47
|
+
this.$src = Of(value);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Ability to register variable
|
|
52
|
+
* in concrete place Of template
|
|
53
|
+
*/
|
|
54
|
+
public var(src: EventType<string>) {
|
|
55
|
+
const places = Object.keys(this.vars).length;
|
|
56
|
+
const varName = `$var${places}`;
|
|
57
|
+
if (isDestroyable(src)) {
|
|
58
|
+
this.dc.add(src);
|
|
59
|
+
}
|
|
60
|
+
this.vars[varName] = src;
|
|
61
|
+
return varName;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public destroy(): this {
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
53
67
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { Late } from "silentium";
|
|
1
|
+
import { Late, Transport } from "silentium";
|
|
2
2
|
import { HashTable } from "../structures/HashTable";
|
|
3
3
|
import { expect, test, vi } from "vitest";
|
|
4
4
|
|
|
5
5
|
test("HashTable.test", () => {
|
|
6
|
-
const
|
|
7
|
-
const
|
|
6
|
+
const $entry = Late<[string, string]>();
|
|
7
|
+
const $hash = HashTable($entry);
|
|
8
8
|
const g = vi.fn();
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
$hash.event(Transport(g));
|
|
10
|
+
$entry.use(["key-one", "value-one"]);
|
|
11
|
+
$entry.use(["key-two", "value-two"]);
|
|
12
12
|
|
|
13
13
|
expect(g).toHaveBeenLastCalledWith({
|
|
14
14
|
"key-one": "value-one",
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
import { EventType } from "silentium";
|
|
1
|
+
import { Event, EventType, Transport } from "silentium";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* https://silentium-lab.github.io/silentium-components/#/structures/hash-table
|
|
5
5
|
*/
|
|
6
6
|
export function HashTable<T>(
|
|
7
|
-
|
|
7
|
+
$base: EventType<[string, unknown]>,
|
|
8
8
|
): EventType<T> {
|
|
9
|
-
return (
|
|
9
|
+
return Event((transport) => {
|
|
10
10
|
const record: Record<string, unknown> = {};
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
$base.event(
|
|
13
|
+
Transport(([key, value]) => {
|
|
14
|
+
record[key] = value;
|
|
15
|
+
transport.use(record as T);
|
|
16
|
+
}),
|
|
17
|
+
);
|
|
18
|
+
});
|
|
17
19
|
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { Late, Of } from "silentium";
|
|
1
|
+
import { Late, Of, Transport } from "silentium";
|
|
2
2
|
import { expect, test, vi } from "vitest";
|
|
3
3
|
import { RecordOf } from "./RecordOf";
|
|
4
4
|
|
|
5
5
|
test("Record._main.test", () => {
|
|
6
|
-
const three = Late<string>("three");
|
|
7
|
-
const
|
|
6
|
+
const $three = Late<string>("three");
|
|
7
|
+
const $record = RecordOf({
|
|
8
8
|
one: Of("one"),
|
|
9
9
|
two: Of(2),
|
|
10
|
-
three: three
|
|
10
|
+
three: $three,
|
|
11
11
|
});
|
|
12
12
|
const g = vi.fn();
|
|
13
|
-
|
|
13
|
+
$record.event(Transport(g));
|
|
14
14
|
|
|
15
15
|
expect(g).toHaveBeenLastCalledWith({
|
|
16
16
|
one: "one",
|
|
@@ -18,7 +18,7 @@ test("Record._main.test", () => {
|
|
|
18
18
|
three: "three",
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
-
three.use("three-changed");
|
|
21
|
+
$three.use("three-changed");
|
|
22
22
|
|
|
23
23
|
expect(g).toHaveBeenLastCalledWith({
|
|
24
24
|
one: "one",
|