silentium-components 0.0.65 → 0.0.67
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 +15 -0
- package/dist/silentium-components.cjs +215 -215
- package/dist/silentium-components.cjs.map +1 -1
- package/dist/silentium-components.d.ts +47 -47
- package/dist/silentium-components.js +181 -181
- 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 +181 -181
- package/dist/silentium-components.mjs.map +1 -1
- package/package.json +2 -2
- package/src/behaviors/Branch._main.test.ts +7 -7
- package/src/behaviors/Branch.branchesDontAffectResult.test.ts +7 -7
- package/src/behaviors/Branch.dontRespondAfterRespond.test.ts +7 -7
- package/src/behaviors/Branch.ts +9 -9
- package/src/behaviors/BranchLazy._main.test.ts +7 -7
- package/src/behaviors/BranchLazy.ts +9 -9
- package/src/behaviors/Const.test.ts +4 -4
- package/src/behaviors/Const.ts +5 -5
- package/src/behaviors/Deadline._main.test.ts +4 -4
- package/src/behaviors/Deadline._value.test.ts +4 -4
- package/src/behaviors/Deadline.ts +8 -8
- package/src/behaviors/Deferred.test.ts +6 -6
- package/src/behaviors/Deferred.ts +8 -8
- package/src/behaviors/Detached.test.ts +4 -4
- package/src/behaviors/Detached.ts +4 -4
- package/src/behaviors/Dirty.test.ts +4 -4
- package/src/behaviors/Dirty.ts +9 -9
- package/src/behaviors/Loading.test.ts +5 -5
- package/src/behaviors/Loading.ts +7 -7
- package/src/behaviors/Lock.test.ts +6 -6
- package/src/behaviors/Lock.ts +7 -7
- package/src/behaviors/Memo.test.ts +4 -4
- package/src/behaviors/Memo.ts +5 -5
- package/src/behaviors/OnlyChanged.test.ts +4 -4
- package/src/behaviors/OnlyChanged.ts +4 -4
- package/src/behaviors/Part.test.ts +5 -5
- package/src/behaviors/Part.ts +10 -14
- package/src/behaviors/Path._main.test.ts +3 -3
- package/src/behaviors/Path.index.test.ts +3 -3
- package/src/behaviors/Path.nested.test.ts +3 -3
- package/src/behaviors/Path.ts +8 -12
- package/src/behaviors/Polling.test.ts +4 -4
- package/src/behaviors/Polling.ts +5 -5
- package/src/behaviors/Shot._main.test.ts +5 -5
- package/src/behaviors/Shot._onlyChanged.test.ts +6 -6
- package/src/behaviors/Shot.ts +8 -8
- package/src/behaviors/Task.ts +7 -7
- package/src/behaviors/Tick.test.ts +5 -5
- package/src/behaviors/Tick.ts +5 -5
- package/src/boolean/And.test.ts +5 -5
- package/src/boolean/And.ts +7 -7
- package/src/boolean/Bool.test.ts +3 -3
- package/src/boolean/Bool.ts +6 -6
- package/src/boolean/Not.test.ts +4 -4
- package/src/boolean/Not.ts +4 -4
- package/src/boolean/Or.test.ts +5 -5
- package/src/boolean/Or.ts +7 -7
- package/src/formats/FromJson.test.ts +4 -4
- package/src/formats/FromJson.ts +5 -5
- package/src/formats/ToJson.test.ts +4 -4
- package/src/formats/ToJson.ts +5 -5
- package/src/lists/First.test.ts +3 -3
- package/src/lists/First.ts +7 -7
- package/src/navigation/Router._main.test.ts +9 -9
- package/src/navigation/Router._nested.test.ts +20 -20
- package/src/navigation/Router.ts +23 -23
- package/src/strings/Concatenated.test.ts +5 -5
- package/src/strings/Concatenated.ts +9 -9
- package/src/strings/Template._main.test.ts +11 -11
- package/src/strings/Template._place.test.ts +4 -4
- package/src/strings/Template.ts +19 -19
- package/src/structures/HashTable.test.ts +4 -4
- package/src/structures/HashTable.ts +5 -5
- package/src/structures/Record._main.test.ts +6 -6
- package/src/structures/Record.concatenated.test.ts +10 -10
- package/src/structures/Record.nested.test.ts +9 -9
- package/src/structures/RecordOf.ts +8 -8
- package/src/system/RegexpMatch._group.test.ts +5 -5
- package/src/system/RegexpMatch._main.test.ts +5 -5
- package/src/system/RegexpMatch.ts +9 -9
- package/src/system/RegexpMatched.test.ts +4 -4
- package/src/system/RegexpMatched.ts +8 -8
- package/src/system/RegexpReplaced.test.ts +4 -4
- package/src/system/RegexpReplaced.ts +8 -8
- package/src/system/Set.test.ts +4 -4
- package/src/system/Set.ts +7 -7
- package/docs/assets/js/components/linkDynamic.mjs +0 -14
- package/docs/assets/js/components/linkReloadable.mjs +0 -17
- package/docs/assets/js/components.mjs +0 -2
- package/docs/assets/js/index.mjs +0 -271
package/src/boolean/Not.test.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Late } from "silentium";
|
|
2
|
+
import { Not } from "../boolean/Not";
|
|
3
3
|
import { expect, test, vi } from "vitest";
|
|
4
4
|
|
|
5
5
|
test("Not.test", () => {
|
|
6
|
-
const one =
|
|
7
|
-
const result =
|
|
6
|
+
const one = Late<boolean>(false);
|
|
7
|
+
const result = Not(one.event);
|
|
8
8
|
const g = vi.fn();
|
|
9
9
|
result(g);
|
|
10
10
|
expect(g).toHaveBeenLastCalledWith(true);
|
package/src/boolean/Not.ts
CHANGED
|
@@ -3,10 +3,10 @@ import { EventType } from "silentium";
|
|
|
3
3
|
/**
|
|
4
4
|
* https://silentium-lab.github.io/silentium-components/#/boolean/not
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
7
|
-
return (
|
|
6
|
+
export function Not(baseSrc: EventType<boolean>): EventType<boolean> {
|
|
7
|
+
return (user) => {
|
|
8
8
|
baseSrc((v) => {
|
|
9
|
-
|
|
9
|
+
user(!v);
|
|
10
10
|
});
|
|
11
11
|
};
|
|
12
|
-
}
|
|
12
|
+
}
|
package/src/boolean/Or.test.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Late } from "silentium";
|
|
2
|
+
import { Or } from "../boolean/Or";
|
|
3
3
|
import { expect, test, vi } from "vitest";
|
|
4
4
|
|
|
5
5
|
test("Or.test", () => {
|
|
6
|
-
const one =
|
|
7
|
-
const two =
|
|
8
|
-
const result =
|
|
6
|
+
const one = Late<boolean>(false);
|
|
7
|
+
const two = Late<boolean>(false);
|
|
8
|
+
const result = Or(one.event, two.event);
|
|
9
9
|
const g = vi.fn();
|
|
10
10
|
result(g);
|
|
11
11
|
expect(g).toHaveBeenLastCalledWith(false);
|
package/src/boolean/Or.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { All, EventType } from "silentium";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* https://silentium-lab.github.io/silentium-components/#/boolean/or
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
6
|
+
export function Or(
|
|
7
7
|
oneSrc: EventType<boolean>,
|
|
8
8
|
twoSrc: EventType<boolean>,
|
|
9
|
-
): EventType<boolean>
|
|
10
|
-
return (
|
|
11
|
-
|
|
9
|
+
): EventType<boolean> {
|
|
10
|
+
return (user) => {
|
|
11
|
+
All(
|
|
12
12
|
oneSrc,
|
|
13
13
|
twoSrc,
|
|
14
14
|
)(([one, two]) => {
|
|
15
|
-
|
|
15
|
+
user(one || two);
|
|
16
16
|
});
|
|
17
17
|
};
|
|
18
|
-
}
|
|
18
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Of, Primitive } from "silentium";
|
|
2
|
+
import { FromJson } from "../formats/FromJson";
|
|
3
3
|
import { expect, test } from "vitest";
|
|
4
4
|
|
|
5
5
|
test("FromJson.test", () => {
|
|
6
|
-
const one =
|
|
7
|
-
const objectSync =
|
|
6
|
+
const one = Of('{"hello": "world"}');
|
|
7
|
+
const objectSync = Primitive(FromJson<{ hello: string }>(one));
|
|
8
8
|
|
|
9
9
|
expect(objectSync.primitive()?.hello).toBe("world");
|
|
10
10
|
});
|
package/src/formats/FromJson.ts
CHANGED
|
@@ -3,17 +3,17 @@ import { EventType, EventUserType } from "silentium";
|
|
|
3
3
|
/**
|
|
4
4
|
* Represents object from json
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
6
|
+
export function FromJson<T = Record<string, unknown>>(
|
|
7
7
|
jsonSrc: EventType<string>,
|
|
8
8
|
errorOwner?: EventUserType,
|
|
9
|
-
): EventType<T>
|
|
10
|
-
return (
|
|
9
|
+
): EventType<T> {
|
|
10
|
+
return (user) => {
|
|
11
11
|
jsonSrc((json) => {
|
|
12
12
|
try {
|
|
13
|
-
|
|
13
|
+
user(JSON.parse(json));
|
|
14
14
|
} catch (error) {
|
|
15
15
|
errorOwner?.(new Error(`Failed to parse JSON: ${error}`));
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
};
|
|
19
|
-
}
|
|
19
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Of, Primitive } from "silentium";
|
|
2
2
|
import { expect, test } from "vitest";
|
|
3
|
-
import {
|
|
3
|
+
import { ToJson } from "../formats/ToJson";
|
|
4
4
|
|
|
5
5
|
test("ToJson.test", () => {
|
|
6
|
-
const one =
|
|
7
|
-
const objectSync =
|
|
6
|
+
const one = Of({ hello: "world" });
|
|
7
|
+
const objectSync = Primitive(ToJson(one));
|
|
8
8
|
|
|
9
9
|
expect(objectSync.primitive()).toBe('{"hello":"world"}');
|
|
10
10
|
});
|
package/src/formats/ToJson.ts
CHANGED
|
@@ -3,17 +3,17 @@ import { EventType, EventUserType } from "silentium";
|
|
|
3
3
|
/**
|
|
4
4
|
* Represents json from object
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
6
|
+
export function ToJson(
|
|
7
7
|
dataSrc: EventType,
|
|
8
8
|
errorOwner?: EventUserType,
|
|
9
|
-
): EventType<string>
|
|
10
|
-
return (
|
|
9
|
+
): EventType<string> {
|
|
10
|
+
return (user) => {
|
|
11
11
|
dataSrc((data: unknown) => {
|
|
12
12
|
try {
|
|
13
|
-
|
|
13
|
+
user(JSON.stringify(data));
|
|
14
14
|
} catch {
|
|
15
15
|
errorOwner?.(new Error("Failed to convert to JSON"));
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
};
|
|
19
|
-
}
|
|
19
|
+
}
|
package/src/lists/First.test.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Of } from "silentium";
|
|
2
2
|
import { expect, test, vi } from "vitest";
|
|
3
|
-
import {
|
|
3
|
+
import { First } from "./First";
|
|
4
4
|
|
|
5
5
|
test("first", () => {
|
|
6
|
-
const f =
|
|
6
|
+
const f = First(Of([1, 2, 3]));
|
|
7
7
|
const g = vi.fn();
|
|
8
8
|
f(g);
|
|
9
9
|
expect(g).toHaveBeenCalledWith(1);
|
package/src/lists/First.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Applied, EventType } from "silentium";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Represents the first element
|
|
4
|
+
* Represents the first element Of an array.
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
6
|
+
export function First<T extends Array<unknown>>(
|
|
7
7
|
baseSrc: EventType<T>,
|
|
8
|
-
): EventType<T[0]>
|
|
9
|
-
return (
|
|
10
|
-
|
|
8
|
+
): EventType<T[0]> {
|
|
9
|
+
return (user) => {
|
|
10
|
+
Applied(baseSrc, (a) => a[0])(user);
|
|
11
11
|
};
|
|
12
|
-
}
|
|
12
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Applied, Late, Of, Shared } from "silentium";
|
|
2
|
+
import { Router } from "../navigation/Router";
|
|
3
3
|
import { expect, test, vi } from "vitest";
|
|
4
4
|
|
|
5
5
|
const drop = (dropPart: string) => (value: string) => {
|
|
@@ -7,24 +7,24 @@ const drop = (dropPart: string) => (value: string) => {
|
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
test("Router._main.test", () => {
|
|
10
|
-
const urlSrc =
|
|
11
|
-
const urlPathSrc =
|
|
10
|
+
const urlSrc = Late<string>("http://domain.com/");
|
|
11
|
+
const urlPathSrc = Shared(Applied(urlSrc.event, drop("http://domain.com")));
|
|
12
12
|
const g = vi.fn();
|
|
13
13
|
urlPathSrc.event(g);
|
|
14
14
|
|
|
15
|
-
const routerSrc =
|
|
15
|
+
const routerSrc = Router(
|
|
16
16
|
urlPathSrc.event,
|
|
17
|
-
|
|
17
|
+
Of([
|
|
18
18
|
{
|
|
19
19
|
pattern: "^/$",
|
|
20
|
-
template: () =>
|
|
20
|
+
template: () => Of("page/home.html"),
|
|
21
21
|
},
|
|
22
22
|
{
|
|
23
23
|
pattern: "/some/contacts",
|
|
24
|
-
template: () =>
|
|
24
|
+
template: () => Of("page/contacts.html"),
|
|
25
25
|
},
|
|
26
26
|
]),
|
|
27
|
-
() =>
|
|
27
|
+
() => Of<string>("page/404.html"),
|
|
28
28
|
);
|
|
29
29
|
const g2 = vi.fn();
|
|
30
30
|
routerSrc(g2);
|
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LateShared, Of } from "silentium";
|
|
2
2
|
import { describe, expect, test } from "vitest";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { Detached } from "../behaviors/Detached";
|
|
4
|
+
import { Router } from "../navigation/Router";
|
|
5
5
|
|
|
6
6
|
describe("Router._nested.test", () => {
|
|
7
7
|
test("Вложенные роуты", () => {
|
|
8
|
-
const urlSrc =
|
|
9
|
-
const routerSrc =
|
|
8
|
+
const urlSrc = LateShared("/");
|
|
9
|
+
const routerSrc = Router(
|
|
10
10
|
urlSrc.event,
|
|
11
|
-
|
|
11
|
+
Of([
|
|
12
12
|
{
|
|
13
13
|
pattern: "^/$",
|
|
14
|
-
template: () =>
|
|
14
|
+
template: () => Of<string>("home"),
|
|
15
15
|
},
|
|
16
16
|
{
|
|
17
17
|
pattern: "/admin.*",
|
|
18
18
|
template: () => {
|
|
19
19
|
return (user) => {
|
|
20
20
|
// need to replace with detached component
|
|
21
|
-
const localUrlSrc =
|
|
21
|
+
const localUrlSrc = Detached(urlSrc.event);
|
|
22
22
|
|
|
23
|
-
const r =
|
|
23
|
+
const r = Router(
|
|
24
24
|
localUrlSrc,
|
|
25
|
-
|
|
25
|
+
Of([
|
|
26
26
|
{
|
|
27
27
|
pattern: "^/admin/articles$",
|
|
28
|
-
template: () =>
|
|
28
|
+
template: () => Of("articles list"),
|
|
29
29
|
},
|
|
30
30
|
{
|
|
31
31
|
pattern: "^/admin/articles/create$",
|
|
32
|
-
template: () =>
|
|
32
|
+
template: () => Of("articles create"),
|
|
33
33
|
},
|
|
34
34
|
{
|
|
35
35
|
pattern: "^/admin/articles/update$",
|
|
36
|
-
template: () =>
|
|
36
|
+
template: () => Of("articles update"),
|
|
37
37
|
},
|
|
38
38
|
{
|
|
39
39
|
pattern: "^/admin/nested/.*$",
|
|
40
40
|
template: () => {
|
|
41
41
|
return (user) => {
|
|
42
|
-
const localUrlSrc =
|
|
42
|
+
const localUrlSrc = Detached(urlSrc.event);
|
|
43
43
|
|
|
44
|
-
const r =
|
|
44
|
+
const r = Router(
|
|
45
45
|
localUrlSrc,
|
|
46
|
-
|
|
46
|
+
Of([
|
|
47
47
|
{
|
|
48
48
|
pattern: "^/admin/nested/list$",
|
|
49
|
-
template: () =>
|
|
49
|
+
template: () => Of("admin nested list"),
|
|
50
50
|
},
|
|
51
51
|
]),
|
|
52
|
-
() =>
|
|
52
|
+
() => Of<string>("admin nested not found"),
|
|
53
53
|
);
|
|
54
54
|
const rDestructor = r(user);
|
|
55
55
|
|
|
@@ -60,7 +60,7 @@ describe("Router._nested.test", () => {
|
|
|
60
60
|
},
|
|
61
61
|
},
|
|
62
62
|
]),
|
|
63
|
-
() =>
|
|
63
|
+
() => Of<string>("admin not found"),
|
|
64
64
|
);
|
|
65
65
|
const rDestructor = r(user);
|
|
66
66
|
|
|
@@ -71,7 +71,7 @@ describe("Router._nested.test", () => {
|
|
|
71
71
|
},
|
|
72
72
|
},
|
|
73
73
|
]),
|
|
74
|
-
() =>
|
|
74
|
+
() => Of("not found"),
|
|
75
75
|
);
|
|
76
76
|
const d: string[] = [];
|
|
77
77
|
routerSrc((v) => {
|
package/src/navigation/Router.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
All,
|
|
3
|
+
Applied,
|
|
4
4
|
EventType,
|
|
5
|
-
|
|
5
|
+
Destructor,
|
|
6
6
|
DestructorType,
|
|
7
|
-
|
|
7
|
+
Of,
|
|
8
8
|
ConstructorType,
|
|
9
9
|
} from "silentium";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
10
|
+
import { RegexpMatched } from "../system";
|
|
11
|
+
import { BranchLazy } from "../behaviors";
|
|
12
12
|
|
|
13
13
|
export interface Route<T> {
|
|
14
14
|
pattern: string;
|
|
@@ -16,51 +16,51 @@ export interface Route<T> {
|
|
|
16
16
|
template: ConstructorType<[], EventType<T>>;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
const emptySrc = () =>
|
|
19
|
+
const emptySrc = () => Of(false);
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Router component what will return template if url matches pattern
|
|
23
23
|
* https://silentium-lab.github.io/silentium-components/#/navigation/router
|
|
24
24
|
*/
|
|
25
|
-
export
|
|
25
|
+
export function Router<T = "string">(
|
|
26
26
|
urlSrc: EventType<string>,
|
|
27
27
|
routesSrc: EventType<Route<T>[]>,
|
|
28
28
|
defaultSrc: ConstructorType<[], EventType<T>>,
|
|
29
|
-
): EventType<T>
|
|
30
|
-
return (
|
|
29
|
+
): EventType<T> {
|
|
30
|
+
return (user) => {
|
|
31
31
|
const destructors: DestructorType[] = [];
|
|
32
32
|
const destroyAllData = () => {
|
|
33
33
|
destructors.forEach((d) => d());
|
|
34
34
|
destructors.length = 0;
|
|
35
35
|
};
|
|
36
|
-
|
|
36
|
+
All(
|
|
37
37
|
routesSrc,
|
|
38
38
|
urlSrc,
|
|
39
39
|
)(([routes, url]) => {
|
|
40
40
|
destroyAllData();
|
|
41
|
-
const instance =
|
|
41
|
+
const instance = All(
|
|
42
42
|
defaultSrc(),
|
|
43
|
-
|
|
43
|
+
All(
|
|
44
44
|
...routes.map(
|
|
45
45
|
(r) =>
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
r.patternFlags ?
|
|
46
|
+
Destructor(
|
|
47
|
+
BranchLazy(
|
|
48
|
+
RegexpMatched(
|
|
49
|
+
Of(r.pattern),
|
|
50
|
+
Of(url),
|
|
51
|
+
r.patternFlags ? Of(r.patternFlags) : undefined,
|
|
52
52
|
),
|
|
53
53
|
r.template,
|
|
54
54
|
emptySrc,
|
|
55
55
|
),
|
|
56
56
|
(d: DestructorType) => destructors.push(d),
|
|
57
|
-
).
|
|
57
|
+
).event,
|
|
58
58
|
),
|
|
59
59
|
),
|
|
60
60
|
);
|
|
61
61
|
|
|
62
62
|
// Return first not false or default
|
|
63
|
-
|
|
63
|
+
Applied(instance, (r) => {
|
|
64
64
|
const firstReal = r[1].find((r) => r !== false);
|
|
65
65
|
|
|
66
66
|
if (firstReal) {
|
|
@@ -68,9 +68,9 @@ export const router = <T = "string">(
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
return r[0];
|
|
71
|
-
})(
|
|
71
|
+
})(user);
|
|
72
72
|
});
|
|
73
73
|
|
|
74
74
|
return destroyAllData;
|
|
75
75
|
};
|
|
76
|
-
}
|
|
76
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Of } from "silentium";
|
|
2
|
+
import { Concatenated } from "../strings/Concatenated";
|
|
3
3
|
import { expect, test, vi } from "vitest";
|
|
4
4
|
|
|
5
5
|
test("Concatenated.test", () => {
|
|
6
|
-
const concatenatedSrc =
|
|
7
|
-
[
|
|
8
|
-
|
|
6
|
+
const concatenatedSrc = Concatenated(
|
|
7
|
+
[Of("one"), Of("two"), Of("three")],
|
|
8
|
+
Of("-"),
|
|
9
9
|
);
|
|
10
10
|
const g = vi.fn();
|
|
11
11
|
concatenatedSrc(g);
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { All, EventType, Of } from "silentium";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Join sources
|
|
4
|
+
* Join sources Of strings to one source
|
|
5
5
|
* https://silentium-lab.github.io/silentium-components/#/string/concatenated
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
7
|
+
export function Concatenated(
|
|
8
8
|
sources: EventType<string>[],
|
|
9
|
-
joinPartSrc: EventType<string> =
|
|
10
|
-
): EventType<string>
|
|
11
|
-
return (
|
|
12
|
-
|
|
9
|
+
joinPartSrc: EventType<string> = Of(""),
|
|
10
|
+
): EventType<string> {
|
|
11
|
+
return (user) => {
|
|
12
|
+
All(
|
|
13
13
|
joinPartSrc,
|
|
14
14
|
...sources,
|
|
15
15
|
)(([joinPart, ...strings]) => {
|
|
16
|
-
|
|
16
|
+
user(strings.join(joinPart));
|
|
17
17
|
});
|
|
18
18
|
};
|
|
19
|
-
}
|
|
19
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { Of } from "silentium";
|
|
2
|
+
import { Template } from "../strings/Template";
|
|
3
|
+
import { RecordOf } from "../structures";
|
|
4
4
|
import { expect, test, vi } from "vitest";
|
|
5
5
|
|
|
6
6
|
test("Template._main.test", () => {
|
|
7
|
-
const tpl =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
$1:
|
|
7
|
+
const tpl = Template(
|
|
8
|
+
Of("<h1>$1</h1>"),
|
|
9
|
+
RecordOf({
|
|
10
|
+
$1: Of("one value"),
|
|
11
11
|
}),
|
|
12
12
|
);
|
|
13
13
|
const g = vi.fn();
|
|
@@ -15,10 +15,10 @@ test("Template._main.test", () => {
|
|
|
15
15
|
|
|
16
16
|
expect(g).toHaveBeenLastCalledWith("<h1>one value</h1>");
|
|
17
17
|
|
|
18
|
-
const tpl2 =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
$1:
|
|
18
|
+
const tpl2 = Template(
|
|
19
|
+
Of("<h2>$1</h2>"),
|
|
20
|
+
RecordOf({
|
|
21
|
+
$1: Of("second value"),
|
|
22
22
|
}),
|
|
23
23
|
);
|
|
24
24
|
const g2 = vi.fn();
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Of } from "silentium";
|
|
2
|
+
import { Template } from "../strings/Template";
|
|
3
3
|
import { expect, test, vi } from "vitest";
|
|
4
4
|
|
|
5
5
|
test("Template._place.test", () => {
|
|
6
|
-
const t =
|
|
7
|
-
t.template(`<div class="greeting">Hello ${t.var(
|
|
6
|
+
const t = Template();
|
|
7
|
+
t.template(`<div class="greeting">Hello ${t.var(Of("User"))}</div>`);
|
|
8
8
|
const g = vi.fn();
|
|
9
9
|
t.value(g);
|
|
10
10
|
|
package/src/strings/Template.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
All,
|
|
3
|
+
Applied,
|
|
4
4
|
EventType,
|
|
5
|
-
|
|
5
|
+
Destructor,
|
|
6
6
|
DestructorType,
|
|
7
|
-
|
|
7
|
+
Of,
|
|
8
8
|
} from "silentium";
|
|
9
|
-
import {
|
|
9
|
+
import { RecordOf } from "../structures";
|
|
10
10
|
|
|
11
|
-
export
|
|
12
|
-
theSrc: EventType<string> =
|
|
13
|
-
placesSrc: EventType<Record<string, unknown>> =
|
|
14
|
-
)
|
|
11
|
+
export function Template(
|
|
12
|
+
theSrc: EventType<string> = Of(""),
|
|
13
|
+
placesSrc: EventType<Record<string, unknown>> = Of({}),
|
|
14
|
+
) {
|
|
15
15
|
let placesCounter = 0;
|
|
16
16
|
const vars: Record<string, EventType> = {
|
|
17
|
-
$TPL:
|
|
17
|
+
$TPL: Of("$TPL"),
|
|
18
18
|
};
|
|
19
19
|
const destructors: DestructorType[] = [];
|
|
20
20
|
return {
|
|
21
|
-
value: <EventType<string>>((
|
|
22
|
-
const varsSrc =
|
|
23
|
-
|
|
21
|
+
value: <EventType<string>>((user) => {
|
|
22
|
+
const varsSrc = RecordOf(vars);
|
|
23
|
+
Applied(All(theSrc, placesSrc, varsSrc), ([base, rules, vars]) => {
|
|
24
24
|
Object.entries(rules).forEach(([ph, val]) => {
|
|
25
25
|
base = base.replaceAll(ph, String(val));
|
|
26
26
|
});
|
|
@@ -29,25 +29,25 @@ export const template = (
|
|
|
29
29
|
});
|
|
30
30
|
|
|
31
31
|
return base;
|
|
32
|
-
})(
|
|
32
|
+
})(user);
|
|
33
33
|
}),
|
|
34
34
|
template: (value: string) => {
|
|
35
|
-
theSrc =
|
|
35
|
+
theSrc = Of(value);
|
|
36
36
|
},
|
|
37
37
|
/**
|
|
38
38
|
* Ability to register variable
|
|
39
|
-
* in concrete place
|
|
39
|
+
* in concrete place Of template
|
|
40
40
|
*/
|
|
41
41
|
var: (src: EventType<string>) => {
|
|
42
42
|
const varName = `$var${placesCounter}`;
|
|
43
43
|
placesCounter += 1;
|
|
44
|
-
vars[varName] =
|
|
44
|
+
vars[varName] = Destructor(src, (d: DestructorType) => {
|
|
45
45
|
destructors.push(d);
|
|
46
|
-
}).
|
|
46
|
+
}).event;
|
|
47
47
|
return varName;
|
|
48
48
|
},
|
|
49
49
|
destroy() {
|
|
50
50
|
destructors.forEach((d) => d());
|
|
51
51
|
},
|
|
52
52
|
};
|
|
53
|
-
}
|
|
53
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Late } from "silentium";
|
|
2
|
+
import { HashTable } from "../structures/HashTable";
|
|
3
3
|
import { expect, test, vi } from "vitest";
|
|
4
4
|
|
|
5
5
|
test("HashTable.test", () => {
|
|
6
|
-
const entrySource =
|
|
7
|
-
const hashTableSrc =
|
|
6
|
+
const entrySource = Late<[string, string]>();
|
|
7
|
+
const hashTableSrc = HashTable(entrySource.event);
|
|
8
8
|
const g = vi.fn();
|
|
9
9
|
hashTableSrc(g);
|
|
10
10
|
entrySource.use(["key-one", "value-one"]);
|
|
@@ -3,15 +3,15 @@ import { EventType } from "silentium";
|
|
|
3
3
|
/**
|
|
4
4
|
* https://silentium-lab.github.io/silentium-components/#/structures/hash-table
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
6
|
+
export function HashTable<T>(
|
|
7
7
|
baseSrc: EventType<[string, unknown]>,
|
|
8
|
-
): EventType<T>
|
|
9
|
-
return (
|
|
8
|
+
): EventType<T> {
|
|
9
|
+
return (user) => {
|
|
10
10
|
const record: Record<string, unknown> = {};
|
|
11
11
|
|
|
12
12
|
baseSrc(([key, value]) => {
|
|
13
13
|
record[key] = value;
|
|
14
|
-
|
|
14
|
+
user(record as T);
|
|
15
15
|
});
|
|
16
16
|
};
|
|
17
|
-
}
|
|
17
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Late, Of } from "silentium";
|
|
2
2
|
import { expect, test, vi } from "vitest";
|
|
3
|
-
import {
|
|
3
|
+
import { RecordOf } from "./RecordOf";
|
|
4
4
|
|
|
5
5
|
test("Record._main.test", () => {
|
|
6
|
-
const three =
|
|
7
|
-
const recordSrc =
|
|
8
|
-
one:
|
|
9
|
-
two:
|
|
6
|
+
const three = Late<string>("three");
|
|
7
|
+
const recordSrc = RecordOf({
|
|
8
|
+
one: Of("one"),
|
|
9
|
+
two: Of(2),
|
|
10
10
|
three: three.event,
|
|
11
11
|
});
|
|
12
12
|
const g = vi.fn();
|