silentium-components 0.0.26 → 0.0.28
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 +34 -0
- package/dist/silentium-components.cjs +570 -342
- package/dist/silentium-components.cjs.map +1 -1
- package/dist/silentium-components.d.ts +169 -30
- package/dist/silentium-components.js +546 -319
- 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 +546 -319
- package/dist/silentium-components.mjs.map +1 -1
- package/package.json +2 -2
- package/src/behaviors/Branch._main.test.ts +22 -0
- package/src/behaviors/Branch.branchesDontAffectResult.test.ts +11 -11
- package/src/behaviors/Branch.dontRespondAfterRespond.test.ts +15 -17
- package/src/behaviors/Branch.ts +28 -21
- package/src/behaviors/{Deadline.test.ts → Deadline._main.test.ts} +5 -5
- package/src/behaviors/Deadline._value.test.ts +6 -6
- package/src/behaviors/Deadline.ts +45 -41
- package/src/behaviors/Deferred.test.ts +14 -14
- package/src/behaviors/Deferred.ts +21 -15
- package/src/behaviors/Dirty.test.ts +8 -8
- package/src/behaviors/Dirty.ts +43 -35
- package/src/behaviors/Loading.test.ts +8 -8
- package/src/behaviors/Loading.ts +24 -14
- package/src/behaviors/Lock.test.ts +14 -14
- package/src/behaviors/Lock.ts +21 -14
- package/src/behaviors/Memo.test.ts +16 -14
- package/src/behaviors/Memo.ts +20 -12
- package/src/behaviors/OnlyChanged.test.ts +7 -7
- package/src/behaviors/OnlyChanged.ts +22 -15
- package/src/behaviors/Path._main.test.ts +14 -0
- package/src/behaviors/Path.index.test.ts +4 -4
- package/src/behaviors/Path.nested.test.ts +4 -4
- package/src/behaviors/Path.ts +27 -22
- package/src/behaviors/Shot._main.test.ts +29 -0
- package/src/behaviors/Shot._onlyChanged.test.ts +15 -13
- package/src/behaviors/Shot.ts +24 -15
- package/src/behaviors/Sync.test.ts +10 -0
- package/src/behaviors/Sync.ts +38 -15
- package/src/behaviors/Tick.test.ts +8 -8
- package/src/behaviors/Tick.ts +20 -12
- package/src/boolean/And.test.ts +12 -12
- package/src/boolean/And.ts +18 -14
- package/src/boolean/Bool.ts +11 -2
- package/src/boolean/Not.test.ts +6 -6
- package/src/boolean/Not.ts +15 -10
- package/src/boolean/Or.test.ts +12 -12
- package/src/boolean/Or.ts +18 -14
- package/src/boolean/index.ts +1 -0
- package/src/formats/FromJson.test.ts +11 -0
- package/src/formats/FromJson.ts +22 -15
- package/src/formats/ToJson.test.ts +11 -0
- package/src/formats/ToJson.ts +23 -16
- package/src/lists/First.test.ts +4 -4
- package/src/lists/First.ts +11 -6
- package/src/navigation/Router.test.ts +13 -13
- package/src/navigation/Router.ts +36 -29
- package/src/strings/Concatenated.test.ts +6 -6
- package/src/strings/Concatenated.ts +18 -14
- package/src/structures/HashTable.test.ts +7 -7
- package/src/structures/HashTable.ts +17 -11
- package/src/structures/Record._main.test.ts +28 -0
- package/src/structures/Record.concatenated.test.ts +17 -15
- package/src/structures/Record.nested.test.ts +10 -10
- package/src/structures/RecordOf.ts +29 -0
- package/src/structures/index.ts +1 -1
- package/src/system/RegexpMatch._group.test.ts +9 -6
- package/src/system/RegexpMatch._main.test.ts +16 -0
- package/src/system/RegexpMatch.ts +20 -17
- package/src/system/RegexpMatched.test.ts +6 -6
- package/src/system/RegexpMatched.ts +19 -16
- package/src/system/RegexpReplaced.test.ts +10 -6
- package/src/system/RegexpReplaced.ts +25 -18
- package/src/system/Set.test.ts +6 -6
- package/src/system/Set.ts +20 -17
- package/src/behaviors/Branch.test.ts +0 -22
- package/src/behaviors/Path.test.ts +0 -14
- package/src/behaviors/Shot.test.ts +0 -29
- package/src/structures/Record.test.ts +0 -28
- package/src/structures/Record.ts +0 -22
- package/src/system/RegexpMatch.test.ts +0 -13
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { From, Of } from "silentium";
|
|
2
2
|
import { expect, test, vi } from "vitest";
|
|
3
|
-
import {
|
|
3
|
+
import { Concatenated } from "../strings/Concatenated";
|
|
4
4
|
|
|
5
5
|
test("Concatenated.test", () => {
|
|
6
|
-
const concatenatedSrc =
|
|
7
|
-
[
|
|
8
|
-
|
|
6
|
+
const concatenatedSrc = new Concatenated(
|
|
7
|
+
[new Of("one"), new Of("two"), new Of("three")],
|
|
8
|
+
new Of("-"),
|
|
9
9
|
);
|
|
10
10
|
const g = vi.fn();
|
|
11
|
-
concatenatedSrc(g);
|
|
11
|
+
concatenatedSrc.value(new From(g));
|
|
12
12
|
|
|
13
13
|
expect(g).toHaveBeenLastCalledWith("one-two-three");
|
|
14
14
|
});
|
|
@@ -1,19 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { All, From, Of, TheInformation, TheOwner } from "silentium";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Join sources of strings to one source
|
|
5
5
|
* https://silentium-lab.github.io/silentium-components/#/string/concatenated
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
7
|
+
export class Concatenated extends TheInformation<string> {
|
|
8
|
+
public constructor(
|
|
9
|
+
private sources: TheInformation<string>[],
|
|
10
|
+
private joinPartSrc: TheInformation<string> = new Of(""),
|
|
11
|
+
) {
|
|
12
|
+
super(...sources, joinPartSrc);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public value(o: TheOwner<string>): this {
|
|
16
|
+
new All(this.joinPartSrc, ...this.sources).value(
|
|
17
|
+
new From(([joinPart, ...strings]) => {
|
|
18
|
+
o.give(strings.join(joinPart));
|
|
19
|
+
}),
|
|
20
|
+
);
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { From, Late } from "silentium";
|
|
2
2
|
import { expect, test, vi } from "vitest";
|
|
3
|
-
import {
|
|
3
|
+
import { HashTable } from "../structures/HashTable";
|
|
4
4
|
|
|
5
5
|
test("HashTable.test", () => {
|
|
6
|
-
const
|
|
7
|
-
const hashTableSrc =
|
|
6
|
+
const entrySource = new Late<[string, string]>();
|
|
7
|
+
const hashTableSrc = new HashTable(entrySource);
|
|
8
8
|
const g = vi.fn();
|
|
9
|
-
hashTableSrc(g);
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
hashTableSrc.value(new From(g));
|
|
10
|
+
entrySource.owner().give(["key-one", "value-one"]);
|
|
11
|
+
entrySource.owner().give(["key-two", "value-two"]);
|
|
12
12
|
|
|
13
13
|
expect(g).toHaveBeenLastCalledWith({
|
|
14
14
|
"key-one": "value-one",
|
|
@@ -1,17 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { From, TheInformation, TheOwner } from "silentium";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* https://silentium-lab.github.io/silentium-components/#/structures/hash-table
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
)
|
|
9
|
-
|
|
6
|
+
export class HashTable<T> extends TheInformation<T> {
|
|
7
|
+
public constructor(private baseSrc: TheInformation<[string, unknown]>) {
|
|
8
|
+
super(baseSrc);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
public value(o: TheOwner<T>): this {
|
|
10
12
|
const record: Record<string, unknown> = {};
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
this.baseSrc.value(
|
|
15
|
+
new From(([key, value]) => {
|
|
16
|
+
record[key] = value;
|
|
17
|
+
o.give(record as T);
|
|
18
|
+
}),
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { From, Late, Of } from "silentium";
|
|
2
|
+
import { expect, test, vi } from "vitest";
|
|
3
|
+
import { RecordOf } from "./RecordOf";
|
|
4
|
+
|
|
5
|
+
test("Record._main.test", () => {
|
|
6
|
+
const three = new Late<string>("three");
|
|
7
|
+
const recordSrc = new RecordOf({
|
|
8
|
+
one: new Of("one"),
|
|
9
|
+
two: new Of(2),
|
|
10
|
+
three,
|
|
11
|
+
});
|
|
12
|
+
const g = vi.fn();
|
|
13
|
+
recordSrc.value(new From(g));
|
|
14
|
+
|
|
15
|
+
expect(g).toHaveBeenLastCalledWith({
|
|
16
|
+
one: "one",
|
|
17
|
+
two: 2,
|
|
18
|
+
three: "three",
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
three.owner().give("three-changed");
|
|
22
|
+
|
|
23
|
+
expect(g).toHaveBeenLastCalledWith({
|
|
24
|
+
one: "one",
|
|
25
|
+
two: 2,
|
|
26
|
+
three: "three-changed",
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -1,25 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { From, Late, Of, Shared } from "silentium";
|
|
2
2
|
import { expect, test, vi } from "vitest";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { Concatenated } from "../strings";
|
|
4
|
+
import { RecordOf } from "./RecordOf";
|
|
5
5
|
|
|
6
6
|
test("Record.concatenated.test", () => {
|
|
7
|
-
const three =
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
one:
|
|
12
|
-
two:
|
|
7
|
+
const three = new Of<string>("three");
|
|
8
|
+
const concatPart = new Late<string>("part");
|
|
9
|
+
const r = new Shared(
|
|
10
|
+
new RecordOf({
|
|
11
|
+
one: new Of("one"),
|
|
12
|
+
two: new Of("two"),
|
|
13
13
|
three,
|
|
14
|
-
nested:
|
|
14
|
+
nested: new Concatenated([new Of("one"), concatPart]),
|
|
15
15
|
}),
|
|
16
16
|
);
|
|
17
17
|
const g = vi.fn();
|
|
18
|
-
r(g);
|
|
18
|
+
r.value(new From(g));
|
|
19
19
|
let counter = 0;
|
|
20
|
-
r(
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
r.value(
|
|
21
|
+
new From(() => {
|
|
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
|
+
concatPart.owner().give("changed");
|
|
32
34
|
|
|
33
35
|
expect(g).toHaveBeenLastCalledWith({
|
|
34
36
|
one: "one",
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { From, Of } from "silentium";
|
|
2
2
|
import { expect, test, vi } from "vitest";
|
|
3
|
-
import {
|
|
3
|
+
import { RecordOf } from "./RecordOf";
|
|
4
4
|
|
|
5
5
|
test("Record.nested.test", () => {
|
|
6
|
-
const three =
|
|
7
|
-
const recordSrc =
|
|
8
|
-
one:
|
|
9
|
-
two:
|
|
6
|
+
const three = new Of<string>("three");
|
|
7
|
+
const recordSrc = new RecordOf({
|
|
8
|
+
one: new Of("one"),
|
|
9
|
+
two: new Of("two"),
|
|
10
10
|
three,
|
|
11
|
-
nested:
|
|
12
|
-
four:
|
|
13
|
-
five:
|
|
11
|
+
nested: new RecordOf({
|
|
12
|
+
four: new Of("four"),
|
|
13
|
+
five: new Of("five"),
|
|
14
14
|
}),
|
|
15
15
|
});
|
|
16
16
|
const g = vi.fn();
|
|
17
|
-
recordSrc(g);
|
|
17
|
+
recordSrc.value(new From(g));
|
|
18
18
|
|
|
19
19
|
expect(g).toHaveBeenLastCalledWith({
|
|
20
20
|
one: "one",
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { All, From, TheInformation, TheOwner } from "silentium";
|
|
2
|
+
|
|
3
|
+
type UnInformation<T> = T extends TheInformation<infer U> ? U : never;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Returns record of data from record of sources
|
|
7
|
+
* https://silentium-lab.github.io/silentium-components/#/structures/record
|
|
8
|
+
*/
|
|
9
|
+
export class RecordOf<T extends TheInformation> extends TheInformation<
|
|
10
|
+
Record<string, UnInformation<T>>
|
|
11
|
+
> {
|
|
12
|
+
public constructor(private recordSrc: Record<string, T>) {
|
|
13
|
+
super(...Object.values(recordSrc));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public value(o: TheOwner<Record<string, UnInformation<T>>>): this {
|
|
17
|
+
const keys = Object.keys(this.recordSrc);
|
|
18
|
+
new All(...Object.values(this.recordSrc)).value(
|
|
19
|
+
new From((entries) => {
|
|
20
|
+
const record: Record<string, any> = {};
|
|
21
|
+
entries.forEach((entry, index) => {
|
|
22
|
+
record[keys[index]] = entry;
|
|
23
|
+
});
|
|
24
|
+
o.give(record);
|
|
25
|
+
}),
|
|
26
|
+
);
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
}
|
package/src/structures/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from "./HashTable";
|
|
2
|
-
export * from "./
|
|
2
|
+
export * from "./RecordOf";
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { From, Of } from "silentium";
|
|
2
2
|
import { expect, test, vi } from "vitest";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { Path } from "../behaviors";
|
|
4
|
+
import { RegexpMatch } from "./RegexpMatch";
|
|
5
5
|
|
|
6
6
|
test("RegexpMatch._group.test", () => {
|
|
7
|
-
const urlSrc =
|
|
8
|
-
const matchedSrc =
|
|
7
|
+
const urlSrc = new Of<string>("http://domain.com/some/url/");
|
|
8
|
+
const matchedSrc = new Path(
|
|
9
|
+
new RegexpMatch(new Of("/(s\\w+)/"), urlSrc),
|
|
10
|
+
new Of("1"),
|
|
11
|
+
);
|
|
9
12
|
const g = vi.fn();
|
|
10
|
-
matchedSrc(g);
|
|
13
|
+
matchedSrc.value(new From(g));
|
|
11
14
|
|
|
12
15
|
expect(g).toHaveBeenLastCalledWith("some");
|
|
13
16
|
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { From, Of } from "silentium";
|
|
2
|
+
import { expect, test, vi } from "vitest";
|
|
3
|
+
import { Path } from "../behaviors";
|
|
4
|
+
import { RegexpMatch } from "./RegexpMatch";
|
|
5
|
+
|
|
6
|
+
test("RegexpMatch._main.test", () => {
|
|
7
|
+
const urlSrc = new Of<string>("http://domain.com/some/url/");
|
|
8
|
+
const matchedSrc = new Path(
|
|
9
|
+
new RegexpMatch(new Of("/(s\\w+)/"), urlSrc),
|
|
10
|
+
new Of("0"),
|
|
11
|
+
);
|
|
12
|
+
const g = vi.fn();
|
|
13
|
+
matchedSrc.value(new From(g));
|
|
14
|
+
|
|
15
|
+
expect(g).toHaveBeenLastCalledWith("/some/");
|
|
16
|
+
});
|
|
@@ -1,22 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { All, From, Of, TheInformation, TheOwner } from "silentium";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* First match of regexp
|
|
5
5
|
* https://silentium-lab.github.io/silentium-components/#/system/regexp-matched
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
8
|
-
(
|
|
9
|
-
patternSrc:
|
|
10
|
-
valueSrc:
|
|
11
|
-
flagsSrc:
|
|
12
|
-
)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
7
|
+
export class RegexpMatch extends TheInformation<string[]> {
|
|
8
|
+
public constructor(
|
|
9
|
+
private patternSrc: TheInformation<string>,
|
|
10
|
+
private valueSrc: TheInformation<string>,
|
|
11
|
+
private flagsSrc: TheInformation<string> = new Of(""),
|
|
12
|
+
) {
|
|
13
|
+
super(patternSrc, valueSrc, flagsSrc);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public value(o: TheOwner<string[]>): this {
|
|
17
|
+
new All(this.patternSrc, this.valueSrc, this.flagsSrc).value(
|
|
18
|
+
new From(([pattern, value, flags]) => {
|
|
19
|
+
const result = new RegExp(pattern, flags).exec(value);
|
|
20
|
+
o.give(result ?? []);
|
|
21
|
+
}),
|
|
22
|
+
);
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { From, Late, Of } from "silentium";
|
|
2
2
|
import { expect, test, vi } from "vitest";
|
|
3
|
-
import {
|
|
3
|
+
import { RegexpMatched } from "../system/RegexpMatched";
|
|
4
4
|
|
|
5
5
|
test("RegexpMatched.test", () => {
|
|
6
|
-
const
|
|
7
|
-
const matchedSrc =
|
|
6
|
+
const urlI = new Late<string>("http://domain.com/some/url/");
|
|
7
|
+
const matchedSrc = new RegexpMatched(new Of("/some/url"), urlI);
|
|
8
8
|
const g = vi.fn();
|
|
9
|
-
matchedSrc(g);
|
|
9
|
+
matchedSrc.value(new From(g));
|
|
10
10
|
|
|
11
11
|
expect(g).toHaveBeenLastCalledWith(true);
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
urlI.owner().give("http://domain.com/changed");
|
|
14
14
|
|
|
15
15
|
expect(g).toHaveBeenLastCalledWith(false);
|
|
16
16
|
});
|
|
@@ -1,21 +1,24 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { All, From, Of, TheInformation, TheOwner } from "silentium";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Boolean source what checks what string matches pattern
|
|
5
5
|
* https://silentium-lab.github.io/silentium-components/#/system/regexp-matched
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
8
|
-
(
|
|
9
|
-
patternSrc:
|
|
10
|
-
valueSrc:
|
|
11
|
-
flagsSrc:
|
|
12
|
-
)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
7
|
+
export class RegexpMatched extends TheInformation<boolean> {
|
|
8
|
+
public constructor(
|
|
9
|
+
private patternSrc: TheInformation<string>,
|
|
10
|
+
private valueSrc: TheInformation<string>,
|
|
11
|
+
private flagsSrc: TheInformation<string> = new Of(""),
|
|
12
|
+
) {
|
|
13
|
+
super(patternSrc, valueSrc, flagsSrc);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public value(o: TheOwner<boolean>): this {
|
|
17
|
+
new All(this.patternSrc, this.valueSrc, this.flagsSrc).value(
|
|
18
|
+
new From(([pattern, value, flags]) => {
|
|
19
|
+
o.give(new RegExp(pattern, flags).test(value));
|
|
20
|
+
}),
|
|
21
|
+
);
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { From, Late, Of } from "silentium";
|
|
2
2
|
import { expect, test, vi } from "vitest";
|
|
3
|
-
import {
|
|
3
|
+
import { RegexpReplaced } from "../system/RegexpReplaced";
|
|
4
4
|
|
|
5
5
|
test("RegexpReplaced.test", () => {
|
|
6
|
-
const
|
|
7
|
-
const matchedSrc =
|
|
6
|
+
const urlSrc = new Late<string>("http://domain.com/some/url/");
|
|
7
|
+
const matchedSrc = new RegexpReplaced(
|
|
8
|
+
urlSrc,
|
|
9
|
+
new Of("some/url/"),
|
|
10
|
+
new Of(""),
|
|
11
|
+
);
|
|
8
12
|
const g = vi.fn();
|
|
9
|
-
matchedSrc(g);
|
|
13
|
+
matchedSrc.value(new From(g));
|
|
10
14
|
|
|
11
15
|
expect(g).toHaveBeenLastCalledWith("http://domain.com/");
|
|
12
16
|
|
|
13
|
-
|
|
17
|
+
urlSrc.owner().give("http://domain.com/some/url/changed/");
|
|
14
18
|
|
|
15
19
|
expect(g).toHaveBeenLastCalledWith("http://domain.com/changed/");
|
|
16
20
|
});
|
|
@@ -1,23 +1,30 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { All, From, Of, TheInformation, TheOwner } from "silentium";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Returns string replaced by regular expression pattern
|
|
5
5
|
* https://silentium-lab.github.io/silentium-components/#/system/regexp-replaced
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
8
|
-
(
|
|
9
|
-
valueSrc:
|
|
10
|
-
patternSrc:
|
|
11
|
-
replaceValueSrc:
|
|
12
|
-
flagsSrc:
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
7
|
+
export class RegexpReplaced extends TheInformation<string> {
|
|
8
|
+
public constructor(
|
|
9
|
+
private valueSrc: TheInformation<string>,
|
|
10
|
+
private patternSrc: TheInformation<string>,
|
|
11
|
+
private replaceValueSrc: TheInformation<string>,
|
|
12
|
+
private flagsSrc: TheInformation<string> = new Of(""),
|
|
13
|
+
) {
|
|
14
|
+
super(valueSrc, patternSrc, replaceValueSrc, flagsSrc);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public value(o: TheOwner<string>): this {
|
|
18
|
+
new All(
|
|
19
|
+
this.patternSrc,
|
|
20
|
+
this.valueSrc,
|
|
21
|
+
this.replaceValueSrc,
|
|
22
|
+
this.flagsSrc,
|
|
23
|
+
).value(
|
|
24
|
+
new From(([pattern, value, replaceValue, flags]) => {
|
|
25
|
+
o.give(String(value).replace(new RegExp(pattern, flags), replaceValue));
|
|
26
|
+
}),
|
|
27
|
+
);
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
}
|
package/src/system/Set.test.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { From, Late, Of } from "silentium";
|
|
2
|
+
import { Set } from "../system/Set";
|
|
2
3
|
import { expect, test, vi } from "vitest";
|
|
3
|
-
import { set } from "../system/Set";
|
|
4
4
|
|
|
5
5
|
test("Set.test", () => {
|
|
6
|
-
const
|
|
6
|
+
const value = new Late<string>();
|
|
7
7
|
const object = {
|
|
8
8
|
value: "hello",
|
|
9
9
|
};
|
|
10
|
-
const obj =
|
|
10
|
+
const obj = new Set(new Of(object), new Of("value"), value);
|
|
11
11
|
const g = vi.fn();
|
|
12
|
-
obj(g);
|
|
12
|
+
obj.value(new From(g));
|
|
13
13
|
|
|
14
14
|
expect(object.value).toBe("hello");
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
value.owner().give("bue!");
|
|
17
17
|
|
|
18
18
|
expect(object.value).toBe("bue!");
|
|
19
19
|
});
|
package/src/system/Set.ts
CHANGED
|
@@ -1,22 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { All, From, TheInformation, TheOwner } from "silentium";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Ability to mutate some object, helpful when integrate to procedure systems
|
|
5
5
|
* https://silentium-lab.github.io/silentium-components/#/system/set
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
(base
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
7
|
+
export class Set<T extends Record<string, unknown>> extends TheInformation<T> {
|
|
8
|
+
public constructor(
|
|
9
|
+
private baseSrc: TheInformation<T>,
|
|
10
|
+
private keySrc: TheInformation<string>,
|
|
11
|
+
private valueSrc: TheInformation<unknown>,
|
|
12
|
+
) {
|
|
13
|
+
super(baseSrc, keySrc, valueSrc);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public value(o: TheOwner<T>): this {
|
|
17
|
+
new All(this.baseSrc, this.keySrc, this.valueSrc).value(
|
|
18
|
+
new From(([base, key, value]) => {
|
|
19
|
+
(base as Record<string, unknown>)[key] = value;
|
|
20
|
+
o.give(base);
|
|
21
|
+
}),
|
|
22
|
+
);
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { applied, i, of } from "silentium";
|
|
2
|
-
import { expect, test, vi } from "vitest";
|
|
3
|
-
import { branch } from "../behaviors/Branch";
|
|
4
|
-
|
|
5
|
-
test("Branch.test", () => {
|
|
6
|
-
const [dts, dto] = of<number>(2);
|
|
7
|
-
const res = branch(
|
|
8
|
-
applied(dts, (t) => {
|
|
9
|
-
return t === 2;
|
|
10
|
-
}),
|
|
11
|
-
i("Then ветка"),
|
|
12
|
-
i("Else ветка"),
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
const g = vi.fn();
|
|
16
|
-
res(g);
|
|
17
|
-
expect(g).toBeCalledWith("Then ветка");
|
|
18
|
-
|
|
19
|
-
dto(1);
|
|
20
|
-
|
|
21
|
-
expect(g).toBeCalledWith("Else ветка");
|
|
22
|
-
});
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { i } from "silentium";
|
|
2
|
-
import { expect, test, vi } from "vitest";
|
|
3
|
-
import { path } from "../behaviors/Path";
|
|
4
|
-
|
|
5
|
-
test("Path.test", () => {
|
|
6
|
-
const record = {
|
|
7
|
-
name: "Peter",
|
|
8
|
-
surname: "Parker",
|
|
9
|
-
};
|
|
10
|
-
const name = path<string>(i(record), i("name"));
|
|
11
|
-
const g = vi.fn();
|
|
12
|
-
name(g);
|
|
13
|
-
expect(g).toHaveBeenLastCalledWith("Peter");
|
|
14
|
-
});
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { of } from "silentium";
|
|
2
|
-
import { expect, test, vi } from "vitest";
|
|
3
|
-
import { shot } from "../behaviors/Shot";
|
|
4
|
-
|
|
5
|
-
test("Shot.test", () => {
|
|
6
|
-
const [baseSrc, bo] = of();
|
|
7
|
-
const [shotSrc, so] = of();
|
|
8
|
-
|
|
9
|
-
const shotResult = shot(baseSrc, shotSrc);
|
|
10
|
-
const g = vi.fn();
|
|
11
|
-
shotResult(g);
|
|
12
|
-
|
|
13
|
-
bo(1);
|
|
14
|
-
so(1);
|
|
15
|
-
|
|
16
|
-
expect(g).toHaveBeenLastCalledWith(1);
|
|
17
|
-
|
|
18
|
-
bo(2);
|
|
19
|
-
|
|
20
|
-
expect(g).toHaveBeenLastCalledWith(1);
|
|
21
|
-
|
|
22
|
-
so(1);
|
|
23
|
-
|
|
24
|
-
expect(g).toHaveBeenLastCalledWith(2);
|
|
25
|
-
|
|
26
|
-
const g2 = vi.fn();
|
|
27
|
-
shotResult(g2);
|
|
28
|
-
expect(g2).toHaveBeenLastCalledWith(2);
|
|
29
|
-
});
|