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
|
@@ -1,25 +1,27 @@
|
|
|
1
|
-
import { Late, Of, Shared } from "silentium";
|
|
1
|
+
import { Late, Of, Shared, Transport } from "silentium";
|
|
2
2
|
import { Concatenated } from "../strings";
|
|
3
3
|
import { RecordOf } from "../structures/RecordOf";
|
|
4
4
|
import { expect, test, vi } from "vitest";
|
|
5
5
|
|
|
6
6
|
test("Record.concatenated.test", () => {
|
|
7
|
-
const three = Of<string>("three");
|
|
8
|
-
const
|
|
7
|
+
const $three = Of<string>("three");
|
|
8
|
+
const $part = Late<string>("part");
|
|
9
9
|
const r = Shared(
|
|
10
10
|
RecordOf({
|
|
11
11
|
one: Of("one"),
|
|
12
12
|
two: Of("two"),
|
|
13
|
-
three,
|
|
14
|
-
nested: Concatenated([Of("one"),
|
|
13
|
+
three: $three,
|
|
14
|
+
nested: Concatenated([Of("one"), $part]),
|
|
15
15
|
}),
|
|
16
16
|
);
|
|
17
17
|
const g = vi.fn();
|
|
18
|
-
r.event(g);
|
|
18
|
+
r.event(Transport(g));
|
|
19
19
|
let counter = 0;
|
|
20
|
-
r.event(
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
r.event(
|
|
21
|
+
Transport(() => {
|
|
22
|
+
counter += 1;
|
|
23
|
+
}),
|
|
24
|
+
);
|
|
23
25
|
|
|
24
26
|
expect(g).toHaveBeenLastCalledWith({
|
|
25
27
|
one: "one",
|
|
@@ -28,7 +30,7 @@ test("Record.concatenated.test", () => {
|
|
|
28
30
|
nested: "onepart",
|
|
29
31
|
});
|
|
30
32
|
|
|
31
|
-
|
|
33
|
+
$part.use("changed");
|
|
32
34
|
|
|
33
35
|
expect(g).toHaveBeenLastCalledWith({
|
|
34
36
|
one: "one",
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { Of } from "silentium";
|
|
1
|
+
import { Of, Transport } from "silentium";
|
|
2
2
|
import { expect, test, vi } from "vitest";
|
|
3
3
|
import { RecordOf } from "./RecordOf";
|
|
4
4
|
|
|
5
5
|
test("Record.nested.test", () => {
|
|
6
|
-
const three = Of<string>("three");
|
|
7
|
-
const
|
|
6
|
+
const $three = Of<string>("three");
|
|
7
|
+
const $record = RecordOf({
|
|
8
8
|
one: Of("one"),
|
|
9
9
|
two: Of("two"),
|
|
10
|
-
three,
|
|
10
|
+
three: $three,
|
|
11
11
|
nested: RecordOf({
|
|
12
12
|
four: Of("four"),
|
|
13
13
|
five: Of("five"),
|
|
14
14
|
}),
|
|
15
15
|
});
|
|
16
16
|
const g = vi.fn();
|
|
17
|
-
|
|
17
|
+
$record.event(Transport(g));
|
|
18
18
|
|
|
19
19
|
expect(g).toHaveBeenLastCalledWith({
|
|
20
20
|
one: "one",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { All, EventType } from "silentium";
|
|
1
|
+
import { All, Event, EventType, Transport } from "silentium";
|
|
2
2
|
|
|
3
3
|
type UnInformation<T> = T extends EventType<infer U> ? U : never;
|
|
4
4
|
|
|
@@ -7,16 +7,18 @@ type UnInformation<T> = T extends EventType<infer U> ? U : never;
|
|
|
7
7
|
* https://silentium-lab.github.io/silentium-components/#/structures/record
|
|
8
8
|
*/
|
|
9
9
|
export function RecordOf<T extends EventType>(
|
|
10
|
-
|
|
10
|
+
record: Record<string, T>,
|
|
11
11
|
): EventType<Record<string, UnInformation<T>>> {
|
|
12
|
-
return (
|
|
13
|
-
const keys = Object.keys(
|
|
14
|
-
All(...Object.values(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
return Event((transport) => {
|
|
13
|
+
const keys = Object.keys(record);
|
|
14
|
+
All(...Object.values(record)).event(
|
|
15
|
+
Transport((entries) => {
|
|
16
|
+
const record: Record<string, any> = {};
|
|
17
|
+
entries.forEach((entry, index) => {
|
|
18
|
+
record[keys[index]] = entry;
|
|
19
|
+
});
|
|
20
|
+
transport.use(record);
|
|
21
|
+
}),
|
|
22
|
+
);
|
|
23
|
+
});
|
|
22
24
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { Of } from "silentium";
|
|
1
|
+
import { Of, Transport } from "silentium";
|
|
2
2
|
import { expect, test, vi } from "vitest";
|
|
3
3
|
import { Path } from "../behaviors";
|
|
4
4
|
import { RegexpMatch } from "./RegexpMatch";
|
|
5
5
|
|
|
6
6
|
test("RegexpMatch._group.test", () => {
|
|
7
|
-
const
|
|
8
|
-
const
|
|
7
|
+
const $url = Of<string>("http://domain.com/some/url/");
|
|
8
|
+
const $matched = Path(RegexpMatch(Of("/(s\\w+)/"), $url), Of("1"));
|
|
9
9
|
const g = vi.fn();
|
|
10
|
-
|
|
10
|
+
$matched.event(Transport(g));
|
|
11
11
|
|
|
12
12
|
expect(g).toHaveBeenLastCalledWith("some");
|
|
13
13
|
});
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { Of } from "silentium";
|
|
1
|
+
import { Of, Transport } from "silentium";
|
|
2
2
|
import { expect, test, vi } from "vitest";
|
|
3
3
|
import { Path } from "../behaviors";
|
|
4
4
|
import { RegexpMatch } from "./RegexpMatch";
|
|
5
5
|
|
|
6
6
|
test("RegexpMatch._main.test", () => {
|
|
7
|
-
const
|
|
8
|
-
const
|
|
7
|
+
const $url = Of<string>("http://domain.com/some/url/");
|
|
8
|
+
const $matched = Path(RegexpMatch(Of("/(s\\w+)/"), $url), Of("0"));
|
|
9
9
|
const g = vi.fn();
|
|
10
|
-
|
|
10
|
+
$matched.event(Transport(g));
|
|
11
11
|
|
|
12
12
|
expect(g).toHaveBeenLastCalledWith("/some/");
|
|
13
13
|
});
|
|
@@ -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
|
* First match Of regexp
|
|
@@ -9,14 +9,12 @@ export function RegexpMatch(
|
|
|
9
9
|
valueSrc: EventType<string>,
|
|
10
10
|
flagsSrc: EventType<string> = Of(""),
|
|
11
11
|
): EventType<string[]> {
|
|
12
|
-
return (
|
|
13
|
-
All(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
});
|
|
21
|
-
};
|
|
12
|
+
return Event((transport) => {
|
|
13
|
+
All(patternSrc, valueSrc, flagsSrc).event(
|
|
14
|
+
Transport(([pattern, value, flags]) => {
|
|
15
|
+
const result = new RegExp(pattern, flags).exec(value);
|
|
16
|
+
transport.use(result ?? []);
|
|
17
|
+
}),
|
|
18
|
+
);
|
|
19
|
+
});
|
|
22
20
|
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { Late, Of } from "silentium";
|
|
1
|
+
import { Late, Of, Transport } from "silentium";
|
|
2
2
|
import { RegexpMatched } from "../system/RegexpMatched";
|
|
3
3
|
import { expect, test, vi } from "vitest";
|
|
4
4
|
|
|
5
5
|
test("RegexpMatched.test", () => {
|
|
6
|
-
const
|
|
7
|
-
const
|
|
6
|
+
const $url = Late<string>("http://domain.com/some/url/");
|
|
7
|
+
const $matched = RegexpMatched(Of("/some/url"), $url);
|
|
8
8
|
const g = vi.fn();
|
|
9
|
-
|
|
9
|
+
$matched.event(Transport(g));
|
|
10
10
|
|
|
11
11
|
expect(g).toHaveBeenLastCalledWith(true);
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
$url.use("http://domain.com/changed");
|
|
14
14
|
|
|
15
15
|
expect(g).toHaveBeenLastCalledWith(false);
|
|
16
16
|
});
|
|
@@ -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
|
* Boolean source what checks what string matches pattern
|
|
@@ -9,13 +9,11 @@ export function RegexpMatched(
|
|
|
9
9
|
valueSrc: EventType<string>,
|
|
10
10
|
flagsSrc: EventType<string> = Of(""),
|
|
11
11
|
): EventType<boolean> {
|
|
12
|
-
return (
|
|
13
|
-
All(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
});
|
|
20
|
-
};
|
|
12
|
+
return Event((transport) => {
|
|
13
|
+
All(patternSrc, valueSrc, flagsSrc).event(
|
|
14
|
+
Transport(([pattern, value, flags]) => {
|
|
15
|
+
transport.use(new RegExp(pattern, flags).test(value));
|
|
16
|
+
}),
|
|
17
|
+
);
|
|
18
|
+
});
|
|
21
19
|
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { Late, Of } from "silentium";
|
|
1
|
+
import { Late, Of, Transport } from "silentium";
|
|
2
2
|
import { RegexpReplaced } from "../system/RegexpReplaced";
|
|
3
3
|
import { expect, test, vi } from "vitest";
|
|
4
4
|
|
|
5
5
|
test("RegexpReplaced.test", () => {
|
|
6
|
-
const
|
|
7
|
-
const
|
|
6
|
+
const $url = Late<string>("http://domain.com/some/url/");
|
|
7
|
+
const $matched = RegexpReplaced($url, Of("some/url/"), Of(""));
|
|
8
8
|
const g = vi.fn();
|
|
9
|
-
|
|
9
|
+
$matched.event(Transport(g));
|
|
10
10
|
|
|
11
11
|
expect(g).toHaveBeenLastCalledWith("http://domain.com/");
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
$url.use("http://domain.com/some/url/changed/");
|
|
14
14
|
|
|
15
15
|
expect(g).toHaveBeenLastCalledWith("http://domain.com/changed/");
|
|
16
16
|
});
|
|
@@ -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
|
* Returns string replaced by regular expression pattern
|
|
@@ -10,14 +10,13 @@ export function RegexpReplaced(
|
|
|
10
10
|
replaceValueSrc: EventType<string>,
|
|
11
11
|
flagsSrc: EventType<string> = Of(""),
|
|
12
12
|
): EventType<string> {
|
|
13
|
-
return (
|
|
14
|
-
All(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
};
|
|
13
|
+
return Event((transport) => {
|
|
14
|
+
All(patternSrc, valueSrc, replaceValueSrc, flagsSrc).event(
|
|
15
|
+
Transport(([pattern, value, replaceValue, flags]) => {
|
|
16
|
+
transport.use(
|
|
17
|
+
String(value).replace(new RegExp(pattern, flags), replaceValue),
|
|
18
|
+
);
|
|
19
|
+
}),
|
|
20
|
+
);
|
|
21
|
+
});
|
|
23
22
|
}
|
package/src/system/Set.test.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { Late, Of } from "silentium";
|
|
1
|
+
import { Late, Of, Transport } from "silentium";
|
|
2
2
|
import { Set } from "../system/Set";
|
|
3
3
|
import { expect, test, vi } from "vitest";
|
|
4
4
|
|
|
5
5
|
test("Set.test", () => {
|
|
6
|
-
const value = Late<string>();
|
|
6
|
+
const $value = Late<string>();
|
|
7
7
|
const object = {
|
|
8
8
|
value: "hello",
|
|
9
9
|
};
|
|
10
|
-
const obj = Set(Of(object), Of("value"), value
|
|
10
|
+
const obj = Set(Of(object), Of("value"), $value);
|
|
11
11
|
const g = vi.fn();
|
|
12
|
-
obj(g);
|
|
12
|
+
obj.event(Transport(g));
|
|
13
13
|
|
|
14
14
|
expect(object.value).toBe("hello");
|
|
15
15
|
|
|
16
|
-
value.use("bue!");
|
|
16
|
+
$value.use("bue!");
|
|
17
17
|
|
|
18
18
|
expect(object.value).toBe("bue!");
|
|
19
19
|
});
|
package/src/system/Set.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { All, EventType } from "silentium";
|
|
1
|
+
import { All, Event, EventType, Transport } from "silentium";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Ability to mutate some object, helpful when integrate to procedure systems
|
|
@@ -9,14 +9,12 @@ export function Set<T extends Record<string, unknown>>(
|
|
|
9
9
|
keySrc: EventType<string>,
|
|
10
10
|
valueSrc: EventType<unknown>,
|
|
11
11
|
): EventType<T> {
|
|
12
|
-
return (
|
|
13
|
-
All(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
});
|
|
21
|
-
};
|
|
12
|
+
return Event((transport) => {
|
|
13
|
+
All(baseSrc, keySrc, valueSrc).event(
|
|
14
|
+
Transport(([base, key, value]) => {
|
|
15
|
+
(base as Record<string, unknown>)[key] = value;
|
|
16
|
+
transport.use(base);
|
|
17
|
+
}),
|
|
18
|
+
);
|
|
19
|
+
});
|
|
22
20
|
}
|