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/behaviors/Dirty.ts
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { All, Applied, EventType, Late, SourceType } from "silentium";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Takes source and remember it first value
|
|
5
5
|
* returns new record, what will contain only fields what was changed
|
|
6
6
|
* https://silentium-lab.github.io/silentium-components/#/behaviors/dirty
|
|
7
7
|
*/
|
|
8
|
-
export
|
|
8
|
+
export function Dirty<T>(
|
|
9
9
|
baseEntitySource: EventType<T>,
|
|
10
10
|
alwaysKeep: string[] = [],
|
|
11
11
|
excludeKeys: string[] = [],
|
|
12
12
|
cloneFn?: (v: T) => T,
|
|
13
|
-
): SourceType<T>
|
|
14
|
-
const comparingSrc =
|
|
13
|
+
): SourceType<T> {
|
|
14
|
+
const comparingSrc = Late<T>();
|
|
15
15
|
|
|
16
16
|
if (cloneFn === undefined) {
|
|
17
17
|
cloneFn = (value) => JSON.parse(JSON.stringify(value));
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
return {
|
|
21
|
-
event: (
|
|
22
|
-
const comparingDetached =
|
|
21
|
+
event: (user) => {
|
|
22
|
+
const comparingDetached = Applied(comparingSrc.event, cloneFn);
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
All(
|
|
25
25
|
comparingDetached,
|
|
26
26
|
baseEntitySource,
|
|
27
27
|
)(([comparing, base]) => {
|
|
@@ -29,7 +29,7 @@ export const dirty = <T>(
|
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
user(
|
|
33
33
|
Object.fromEntries(
|
|
34
34
|
Object.entries(comparing).filter(([key, value]) => {
|
|
35
35
|
if (alwaysKeep.includes(key)) {
|
|
@@ -48,4 +48,4 @@ export const dirty = <T>(
|
|
|
48
48
|
comparingSrc.use(v);
|
|
49
49
|
},
|
|
50
50
|
};
|
|
51
|
-
}
|
|
51
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Late } from "silentium";
|
|
2
|
+
import { Loading } from "../behaviors/Loading";
|
|
3
3
|
import { expect, test, vi } from "vitest";
|
|
4
4
|
|
|
5
5
|
test("Loading.test", () => {
|
|
6
|
-
const loadingStartSource =
|
|
7
|
-
const loadingFinishSource =
|
|
8
|
-
const loadingSrc =
|
|
6
|
+
const loadingStartSource = Late();
|
|
7
|
+
const loadingFinishSource = Late();
|
|
8
|
+
const loadingSrc = Loading(
|
|
9
9
|
loadingStartSource.event,
|
|
10
10
|
loadingFinishSource.event,
|
|
11
11
|
);
|
package/src/behaviors/Loading.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { EventType } from "silentium";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Representation
|
|
4
|
+
* Representation Of loading process
|
|
5
5
|
* first informatin source begins loading
|
|
6
6
|
* second information source stops loading
|
|
7
7
|
* https://silentium-lab.github.io/silentium-components/#/behaviors/loading
|
|
8
8
|
*/
|
|
9
|
-
export
|
|
9
|
+
export function Loading(
|
|
10
10
|
loadingStartSrc: EventType<unknown>,
|
|
11
11
|
loadingFinishSrc: EventType<unknown>,
|
|
12
|
-
): EventType<boolean>
|
|
13
|
-
return (
|
|
14
|
-
loadingStartSrc(() =>
|
|
15
|
-
loadingFinishSrc(() =>
|
|
12
|
+
): EventType<boolean> {
|
|
13
|
+
return (user) => {
|
|
14
|
+
loadingStartSrc(() => user(true));
|
|
15
|
+
loadingFinishSrc(() => user(false));
|
|
16
16
|
};
|
|
17
|
-
}
|
|
17
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Late, Shared } from "silentium";
|
|
2
|
+
import { Lock } from "../behaviors/Lock";
|
|
3
3
|
import { expect, test, vi } from "vitest";
|
|
4
4
|
|
|
5
5
|
test("Lock.test", () => {
|
|
6
|
-
const source =
|
|
7
|
-
const lockSrc =
|
|
6
|
+
const source = Late<number>(1);
|
|
7
|
+
const lockSrc = Late<boolean>(false);
|
|
8
8
|
|
|
9
|
-
const ls =
|
|
10
|
-
const lockedSrc =
|
|
9
|
+
const ls = Lock(source.event, lockSrc.event);
|
|
10
|
+
const lockedSrc = Shared(ls);
|
|
11
11
|
const g = vi.fn();
|
|
12
12
|
lockedSrc.event(g);
|
|
13
13
|
|
package/src/behaviors/Lock.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { EventType,
|
|
1
|
+
import { EventType, Filtered } from "silentium";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* https://silentium-lab.github.io/silentium-components/#/behaviors/lock
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
6
|
+
export function Lock<T>(
|
|
7
7
|
baseSrc: EventType<T>,
|
|
8
8
|
lockSrc: EventType<boolean>,
|
|
9
|
-
): EventType<T>
|
|
10
|
-
return (
|
|
9
|
+
): EventType<T> {
|
|
10
|
+
return (user) => {
|
|
11
11
|
let locked = false;
|
|
12
12
|
lockSrc((newLock) => {
|
|
13
13
|
locked = newLock;
|
|
14
14
|
});
|
|
15
|
-
const i =
|
|
16
|
-
i(
|
|
15
|
+
const i = Filtered(baseSrc, () => !locked);
|
|
16
|
+
i(user);
|
|
17
17
|
};
|
|
18
|
-
}
|
|
18
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Late, Shared } from "silentium";
|
|
2
|
+
import { Memo } from "../behaviors/Memo";
|
|
3
3
|
import { expect, test, vi } from "vitest";
|
|
4
4
|
|
|
5
5
|
test("Memo.test", () => {
|
|
6
|
-
const l =
|
|
7
|
-
const mem =
|
|
6
|
+
const l = Late<number>(1);
|
|
7
|
+
const mem = Shared(Memo(l.event));
|
|
8
8
|
const g = vi.fn();
|
|
9
9
|
mem.event(g);
|
|
10
10
|
let counter = 0;
|
package/src/behaviors/Memo.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { EventType } from "silentium";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Didn't respond if new value
|
|
4
|
+
* Didn't respond if new value Of baseSrc equals to old value
|
|
5
5
|
* https://silentium-lab.github.io/silentium-components/#/behaviors/memo
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
8
|
-
return (
|
|
7
|
+
export function Memo<T>(baseSrc: EventType<T>): EventType<T> {
|
|
8
|
+
return (user) => {
|
|
9
9
|
let lastValue: T | null = null;
|
|
10
10
|
|
|
11
11
|
baseSrc((v) => {
|
|
12
12
|
if (v !== lastValue) {
|
|
13
|
-
|
|
13
|
+
user(v);
|
|
14
14
|
lastValue = v;
|
|
15
15
|
}
|
|
16
16
|
});
|
|
17
17
|
};
|
|
18
|
-
}
|
|
18
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Late, Shared } from "silentium";
|
|
2
|
+
import { OnlyChanged } from "../behaviors/OnlyChanged";
|
|
3
3
|
import { expect, test, vi } from "vitest";
|
|
4
4
|
|
|
5
5
|
test("OnlyChanged.test", () => {
|
|
6
|
-
const src =
|
|
7
|
-
const changedSrc =
|
|
6
|
+
const src = Late<number>(1);
|
|
7
|
+
const changedSrc = Shared(OnlyChanged(src.event));
|
|
8
8
|
|
|
9
9
|
const g = vi.fn();
|
|
10
10
|
changedSrc.event(g);
|
|
@@ -4,16 +4,16 @@ import { EventType } from "silentium";
|
|
|
4
4
|
* Represents source what was changed at least once
|
|
5
5
|
* https://silentium-lab.github.io/silentium-components/#/behaviors/only-changed
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
8
|
-
return (
|
|
7
|
+
export function OnlyChanged<T>(baseSrc: EventType<T>): EventType<T> {
|
|
8
|
+
return (user) => {
|
|
9
9
|
let firstValue = false;
|
|
10
10
|
|
|
11
11
|
baseSrc((v) => {
|
|
12
12
|
if (firstValue === false) {
|
|
13
13
|
firstValue = true;
|
|
14
14
|
} else {
|
|
15
|
-
|
|
15
|
+
user(v);
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
};
|
|
19
|
-
}
|
|
19
|
+
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Late, Of, SharedSource } from "silentium";
|
|
2
|
+
import { Part } from "../behaviors/Part";
|
|
3
3
|
import { expect, test, vi } from "vitest";
|
|
4
4
|
|
|
5
5
|
test("Part.test", () => {
|
|
6
|
-
const recordSrc =
|
|
7
|
-
|
|
6
|
+
const recordSrc = SharedSource(
|
|
7
|
+
Late({
|
|
8
8
|
name: "Peter",
|
|
9
9
|
surname: "Parker",
|
|
10
10
|
}),
|
|
11
11
|
);
|
|
12
|
-
const nameSrc =
|
|
12
|
+
const nameSrc = Part<string>(recordSrc, Of("name"));
|
|
13
13
|
const g = vi.fn();
|
|
14
14
|
recordSrc.event(g);
|
|
15
15
|
expect(g).toHaveBeenLastCalledWith({ name: "Peter", surname: "Parker" });
|
package/src/behaviors/Part.ts
CHANGED
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { All, EventType, isFilled, Primitive, SourceType } from "silentium";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Return source
|
|
4
|
+
* Return source Of record path
|
|
5
5
|
* https://silentium-lab.github.io/silentium-components/#/behaviors/path
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
8
|
-
R,
|
|
9
|
-
T extends Record<string, unknown> | Array<unknown> = any,
|
|
10
|
-
K extends string = any,
|
|
11
|
-
>(
|
|
7
|
+
export function Part<R, T extends object | Array<any>, K extends string = any>(
|
|
12
8
|
baseSrc: SourceType<T>,
|
|
13
9
|
keySrc: EventType<K>,
|
|
14
|
-
): SourceType<R>
|
|
15
|
-
const baseSync =
|
|
16
|
-
const keySync =
|
|
10
|
+
): SourceType<R> {
|
|
11
|
+
const baseSync = Primitive(baseSrc.event);
|
|
12
|
+
const keySync = Primitive(keySrc);
|
|
17
13
|
return {
|
|
18
|
-
event: (
|
|
19
|
-
|
|
14
|
+
event: (user) => {
|
|
15
|
+
All(
|
|
20
16
|
baseSrc.event,
|
|
21
17
|
keySrc,
|
|
22
18
|
)(([base, key]) => {
|
|
@@ -27,7 +23,7 @@ export const part = <
|
|
|
27
23
|
});
|
|
28
24
|
|
|
29
25
|
if (value !== undefined && value !== base) {
|
|
30
|
-
|
|
26
|
+
user(value as R);
|
|
31
27
|
}
|
|
32
28
|
});
|
|
33
29
|
},
|
|
@@ -41,4 +37,4 @@ export const part = <
|
|
|
41
37
|
}
|
|
42
38
|
},
|
|
43
39
|
};
|
|
44
|
-
}
|
|
40
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Of } from "silentium";
|
|
2
2
|
import { expect, test, vi } from "vitest";
|
|
3
|
-
import {
|
|
3
|
+
import { Path } from "./Path";
|
|
4
4
|
|
|
5
5
|
test("Path._main.test", () => {
|
|
6
6
|
const record = {
|
|
7
7
|
name: "Peter",
|
|
8
8
|
surname: "Parker",
|
|
9
9
|
};
|
|
10
|
-
const name =
|
|
10
|
+
const name = Path<string>(Of(record), Of("name"));
|
|
11
11
|
const g = vi.fn();
|
|
12
12
|
name(g);
|
|
13
13
|
expect(g).toHaveBeenLastCalledWith("Peter");
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Of } from "silentium";
|
|
2
2
|
import { expect, test, vi } from "vitest";
|
|
3
|
-
import {
|
|
3
|
+
import { Path } from "./Path";
|
|
4
4
|
|
|
5
5
|
test("Path.index.test", () => {
|
|
6
6
|
const record = {
|
|
@@ -11,7 +11,7 @@ test("Path.index.test", () => {
|
|
|
11
11
|
name: "spider-man",
|
|
12
12
|
},
|
|
13
13
|
};
|
|
14
|
-
const bestColor =
|
|
14
|
+
const bestColor = Path(Of(record), Of("colors.0"));
|
|
15
15
|
const g = vi.fn();
|
|
16
16
|
bestColor(g);
|
|
17
17
|
expect(g).toHaveBeenLastCalledWith("blue");
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Of } from "silentium";
|
|
2
|
+
import { Path } from "../behaviors/Path";
|
|
3
3
|
import { expect, test, vi } from "vitest";
|
|
4
4
|
|
|
5
5
|
test("Path.nested.test", () => {
|
|
@@ -10,7 +10,7 @@ test("Path.nested.test", () => {
|
|
|
10
10
|
name: "spider-man",
|
|
11
11
|
},
|
|
12
12
|
};
|
|
13
|
-
const typeName =
|
|
13
|
+
const typeName = Path(Of(record), Of("type.name"));
|
|
14
14
|
const g = vi.fn();
|
|
15
15
|
typeName(g);
|
|
16
16
|
expect(g).toHaveBeenLastCalledWith("spider-man");
|
package/src/behaviors/Path.ts
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { All, EventType } from "silentium";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Return source
|
|
4
|
+
* Return source Of record path
|
|
5
5
|
* https://silentium-lab.github.io/silentium-components/#/behaviors/path
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
8
|
-
R,
|
|
9
|
-
T extends Record<string, unknown> | Array<unknown> = any,
|
|
10
|
-
K extends string = any,
|
|
11
|
-
>(
|
|
7
|
+
export function Path<R, T extends object | Array<any>, K extends string = any>(
|
|
12
8
|
baseSrc: EventType<T>,
|
|
13
9
|
keySrc: EventType<K>,
|
|
14
|
-
): EventType<R>
|
|
15
|
-
return (
|
|
16
|
-
|
|
10
|
+
): EventType<R> {
|
|
11
|
+
return (user) => {
|
|
12
|
+
All(
|
|
17
13
|
baseSrc,
|
|
18
14
|
keySrc,
|
|
19
15
|
)(([base, key]) => {
|
|
@@ -24,8 +20,8 @@ export const path = <
|
|
|
24
20
|
});
|
|
25
21
|
|
|
26
22
|
if (value !== undefined && value !== base) {
|
|
27
|
-
|
|
23
|
+
user(value as R);
|
|
28
24
|
}
|
|
29
25
|
});
|
|
30
26
|
};
|
|
31
|
-
}
|
|
27
|
+
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { EventType,
|
|
1
|
+
import { EventType, Late, Primitive } from "silentium";
|
|
2
2
|
import { expect, test } from "vitest";
|
|
3
|
-
import {
|
|
3
|
+
import { Polling } from "../behaviors/Polling";
|
|
4
4
|
|
|
5
5
|
test("Polling.test", () => {
|
|
6
|
-
const triggerSrc =
|
|
6
|
+
const triggerSrc = Late(1);
|
|
7
7
|
let calls = 0;
|
|
8
8
|
const callsSrc: EventType<number> = (o) => {
|
|
9
9
|
calls += 1;
|
|
10
10
|
o(calls);
|
|
11
11
|
};
|
|
12
|
-
const s =
|
|
12
|
+
const s = Primitive(Polling(callsSrc, triggerSrc.event));
|
|
13
13
|
|
|
14
14
|
expect(s.primitive()).toBe(1);
|
|
15
15
|
|
package/src/behaviors/Polling.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { EventType } from "silentium";
|
|
2
2
|
|
|
3
|
-
export
|
|
3
|
+
export function Polling<T>(
|
|
4
4
|
baseSrc: EventType<T>,
|
|
5
5
|
triggerSrc: EventType<T>,
|
|
6
|
-
): EventType<T>
|
|
7
|
-
return (
|
|
6
|
+
): EventType<T> {
|
|
7
|
+
return (user) => {
|
|
8
8
|
triggerSrc(() => {
|
|
9
|
-
baseSrc(
|
|
9
|
+
baseSrc(user);
|
|
10
10
|
});
|
|
11
11
|
};
|
|
12
|
-
}
|
|
12
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Late, Shared } from "silentium";
|
|
2
|
+
import { Shot } from "../behaviors/Shot";
|
|
3
3
|
import { expect, test, vi } from "vitest";
|
|
4
4
|
|
|
5
5
|
test("Shot._main.test", () => {
|
|
6
|
-
const baseSrc =
|
|
7
|
-
const shotSrc =
|
|
6
|
+
const baseSrc = Late();
|
|
7
|
+
const shotSrc = Late();
|
|
8
8
|
|
|
9
|
-
const shotResult =
|
|
9
|
+
const shotResult = Shared(Shot(baseSrc.event, shotSrc.event));
|
|
10
10
|
const g = vi.fn();
|
|
11
11
|
shotResult.event(g);
|
|
12
12
|
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { Late, Shared } from "silentium";
|
|
2
|
+
import { OnlyChanged } from "../behaviors/OnlyChanged";
|
|
3
|
+
import { Shot } from "../behaviors/Shot";
|
|
4
4
|
import { expect, test } from "vitest";
|
|
5
5
|
|
|
6
6
|
test("Shot._onlyChanged.test", () => {
|
|
7
|
-
const baseSrc =
|
|
8
|
-
const sharedBase =
|
|
9
|
-
const resultSrc =
|
|
7
|
+
const baseSrc = Late<number>(123);
|
|
8
|
+
const sharedBase = Shared(baseSrc.event, true);
|
|
9
|
+
const resultSrc = Shot(sharedBase.event, OnlyChanged(sharedBase.event));
|
|
10
10
|
|
|
11
11
|
const vals: number[] = [];
|
|
12
12
|
|
package/src/behaviors/Shot.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { EventType, isFilled,
|
|
1
|
+
import { EventType, isFilled, Primitive } from "silentium";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Helps to represent only last fresh value
|
|
4
|
+
* Helps to represent only last fresh value Of some source, refreshing controls by shotSrc
|
|
5
5
|
* https://silentium-lab.github.io/silentium-components/#/behaviors/shot
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
7
|
+
export function Shot<T>(
|
|
8
8
|
targetSrc: EventType<T>,
|
|
9
9
|
triggerSrc: EventType,
|
|
10
|
-
): EventType<T>
|
|
11
|
-
return (
|
|
12
|
-
const targetSync =
|
|
10
|
+
): EventType<T> {
|
|
11
|
+
return (user) => {
|
|
12
|
+
const targetSync = Primitive(targetSrc);
|
|
13
13
|
|
|
14
14
|
triggerSrc(() => {
|
|
15
15
|
const value = targetSync.primitive();
|
|
16
16
|
if (isFilled(value)) {
|
|
17
|
-
|
|
17
|
+
user(value);
|
|
18
18
|
}
|
|
19
19
|
});
|
|
20
20
|
};
|
|
21
|
-
}
|
|
21
|
+
}
|
package/src/behaviors/Task.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { EventType,
|
|
1
|
+
import { EventType, ExecutorApplied } from "silentium";
|
|
2
2
|
|
|
3
|
-
export
|
|
3
|
+
export function Task<T>(
|
|
4
4
|
baseSrc: EventType<T>,
|
|
5
5
|
delay: number = 0,
|
|
6
|
-
): EventType<T>
|
|
7
|
-
return (
|
|
6
|
+
): EventType<T> {
|
|
7
|
+
return (user) => {
|
|
8
8
|
let prevTimer: unknown | null = null;
|
|
9
|
-
|
|
9
|
+
ExecutorApplied(baseSrc, (fn) => {
|
|
10
10
|
return (v) => {
|
|
11
11
|
if (prevTimer) {
|
|
12
12
|
clearTimeout(prevTimer as number);
|
|
@@ -15,6 +15,6 @@ export const task = <T>(
|
|
|
15
15
|
fn(v);
|
|
16
16
|
}, delay);
|
|
17
17
|
};
|
|
18
|
-
})(
|
|
18
|
+
})(user);
|
|
19
19
|
};
|
|
20
|
-
}
|
|
20
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Any, Late, Shared } from "silentium";
|
|
2
|
+
import { Tick } from "../behaviors/Tick";
|
|
3
3
|
import { afterEach, beforeEach, expect, test, vi } from "vitest";
|
|
4
4
|
|
|
5
5
|
beforeEach(() => {
|
|
@@ -12,9 +12,9 @@ afterEach(() => {
|
|
|
12
12
|
});
|
|
13
13
|
|
|
14
14
|
test("Tick.test", async () => {
|
|
15
|
-
const s1 =
|
|
16
|
-
const s2 =
|
|
17
|
-
const tickSrc =
|
|
15
|
+
const s1 = Late<number>(1);
|
|
16
|
+
const s2 = Late<number>(2);
|
|
17
|
+
const tickSrc = Shared(Tick(Any(s1.event, s2.event)), true);
|
|
18
18
|
|
|
19
19
|
const g = vi.fn();
|
|
20
20
|
tickSrc.event(g);
|
package/src/behaviors/Tick.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { EventType } from "silentium";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Accumulates the last value
|
|
4
|
+
* Accumulates the last value Of the source and returns one result once per tick
|
|
5
5
|
* https://silentium-lab.github.io/silentium-components/#/behaviors/tick
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
8
|
-
return (
|
|
7
|
+
export function Tick<T>(baseSrc: EventType<T>): EventType<T> {
|
|
8
|
+
return (user) => {
|
|
9
9
|
let microtaskScheduled = false;
|
|
10
10
|
let lastValue: T | null = null;
|
|
11
11
|
|
|
@@ -14,7 +14,7 @@ export const tick = <T>(baseSrc: EventType<T>): EventType<T> => {
|
|
|
14
14
|
queueMicrotask(() => {
|
|
15
15
|
microtaskScheduled = false;
|
|
16
16
|
if (lastValue !== null) {
|
|
17
|
-
|
|
17
|
+
user(lastValue);
|
|
18
18
|
lastValue = null;
|
|
19
19
|
}
|
|
20
20
|
});
|
|
@@ -27,4 +27,4 @@ export const tick = <T>(baseSrc: EventType<T>): EventType<T> => {
|
|
|
27
27
|
}
|
|
28
28
|
});
|
|
29
29
|
};
|
|
30
|
-
}
|
|
30
|
+
}
|
package/src/boolean/And.test.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Late } from "silentium";
|
|
2
2
|
import { expect, test, vi } from "vitest";
|
|
3
|
-
import {
|
|
3
|
+
import { And } from "../boolean/And";
|
|
4
4
|
|
|
5
5
|
test("And.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 = And(one.event, two.event);
|
|
9
9
|
const g = vi.fn();
|
|
10
10
|
result(g);
|
|
11
11
|
expect(g).toHaveBeenLastCalledWith(false);
|
package/src/boolean/And.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/and
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
6
|
+
export function And(
|
|
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
|
+
}
|
package/src/boolean/Bool.test.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Of } from "silentium";
|
|
2
|
+
import { Bool } from "../boolean/Bool";
|
|
3
3
|
import { expect, test, vi } from "vitest";
|
|
4
4
|
|
|
5
5
|
test("Bool.test", () => {
|
|
6
6
|
const o = vi.fn();
|
|
7
|
-
|
|
7
|
+
Bool(Of(1))(o);
|
|
8
8
|
expect(o).toHaveBeenCalledWith(true);
|
|
9
9
|
});
|
package/src/boolean/Bool.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Applied, EventType } from "silentium";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Convert
|
|
4
|
+
* Convert Any source to boolean source
|
|
5
5
|
* https://silentium-lab.github.io/silentium-components/#/boolean/bool
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
8
|
-
return (
|
|
9
|
-
|
|
7
|
+
export function Bool(baseSrc: EventType): EventType<boolean> {
|
|
8
|
+
return (user) => {
|
|
9
|
+
Applied(baseSrc, Boolean)(user);
|
|
10
10
|
};
|
|
11
|
-
}
|
|
11
|
+
}
|