silentium-components 0.0.82 → 0.0.83
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 +7 -0
- package/dist/silentium-components.cjs +130 -130
- package/dist/silentium-components.cjs.map +1 -1
- package/dist/silentium-components.d.ts +9 -9
- package/dist/silentium-components.js +131 -131
- 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 +131 -131
- package/dist/silentium-components.mjs.map +1 -1
- package/package.json +2 -2
- package/src/behaviors/Branch._main.test.ts +2 -2
- package/src/behaviors/Branch._values.test.ts +2 -2
- package/src/behaviors/Branch.branchesDontAffectResult.test.ts +2 -2
- package/src/behaviors/Branch.dontRespondAfterRespond.test.ts +5 -5
- package/src/behaviors/Branch.ts +5 -5
- package/src/behaviors/BranchLazy._main.test.ts +4 -4
- package/src/behaviors/BranchLazy.ts +8 -8
- package/src/behaviors/Const.test.ts +3 -3
- package/src/behaviors/Const.ts +5 -5
- package/src/behaviors/Deadline._main.test.ts +2 -2
- package/src/behaviors/Deadline._value.test.ts +3 -3
- package/src/behaviors/Deadline.ts +9 -9
- package/src/behaviors/Deferred.test.ts +3 -3
- package/src/behaviors/Deferred.ts +5 -11
- package/src/behaviors/Detached.test.ts +3 -3
- package/src/behaviors/Detached.ts +2 -2
- package/src/behaviors/Dirty.test.ts +2 -2
- package/src/behaviors/Dirty.ts +5 -5
- package/src/behaviors/Loading.test.ts +2 -2
- package/src/behaviors/Loading.ts +6 -6
- package/src/behaviors/Lock.test.ts +2 -2
- package/src/behaviors/Lock.ts +5 -5
- package/src/behaviors/Memo.test.ts +4 -4
- package/src/behaviors/Memo.ts +5 -5
- package/src/behaviors/OnlyChanged.test.ts +3 -3
- package/src/behaviors/OnlyChanged.ts +5 -5
- package/src/behaviors/Part.test.ts +3 -3
- package/src/behaviors/Part.ts +5 -5
- package/src/behaviors/Path._keyRaw.test.ts +2 -2
- 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 +5 -5
- package/src/behaviors/Polling.ts +5 -5
- package/src/behaviors/Shot._main.test.ts +3 -3
- package/src/behaviors/Shot._onlyChanged.test.ts +3 -3
- package/src/behaviors/Shot.ts +5 -11
- package/src/behaviors/Task.test.ts +5 -5
- package/src/behaviors/Task.ts +2 -2
- package/src/behaviors/Tick.test.ts +2 -2
- package/src/behaviors/Tick.ts +5 -5
- package/src/behaviors/Transaction.ts +6 -6
- package/src/boolean/And.test.ts +2 -2
- package/src/boolean/And.ts +5 -5
- package/src/boolean/Bool.test.ts +2 -2
- package/src/boolean/Bool.ts +2 -2
- package/src/boolean/Not.test.ts +2 -2
- package/src/boolean/Not.ts +5 -5
- package/src/boolean/Or.test.ts +2 -2
- package/src/boolean/Or.ts +5 -5
- package/src/formats/FromJson.ts +6 -6
- package/src/formats/ToJson.ts +6 -6
- package/src/lists/First.test.ts +2 -2
- package/src/lists/First.ts +2 -2
- package/src/navigation/Router._destroy.test.ts +7 -7
- package/src/navigation/Router._firstMatch.test.ts +7 -7
- package/src/navigation/Router._main.test.ts +7 -7
- package/src/navigation/Router._nested.test.ts +16 -16
- package/src/navigation/Router.ts +11 -11
- package/src/strings/Concatenated.test.ts +2 -2
- package/src/strings/Concatenated.ts +5 -5
- package/src/strings/Template._main.test.ts +3 -3
- package/src/strings/Template._place.test.ts +2 -2
- package/src/strings/Template.ts +3 -3
- package/src/structures/HashTable.test.ts +2 -2
- package/src/structures/HashTable.ts +5 -5
- package/src/structures/Record._main.test.ts +2 -2
- package/src/structures/Record._mixed.test.ts +2 -2
- package/src/structures/Record.concatenated.test.ts +4 -4
- package/src/structures/Record.nested.test.ts +2 -2
- package/src/structures/Record.ts +5 -5
- package/src/system/RegexpMatch._group.test.ts +2 -2
- package/src/system/RegexpMatch._main.test.ts +2 -2
- package/src/system/RegexpMatch.ts +5 -5
- package/src/system/RegexpMatched.test.ts +2 -2
- package/src/system/RegexpMatched.ts +5 -5
- package/src/system/RegexpReplaced.test.ts +2 -2
- package/src/system/RegexpReplaced.ts +5 -5
- package/src/system/Set.test.ts +2 -2
- package/src/system/Set.ts +5 -5
package/src/behaviors/Dirty.ts
CHANGED
|
@@ -4,8 +4,8 @@ import {
|
|
|
4
4
|
Late,
|
|
5
5
|
MessageType,
|
|
6
6
|
SourceType,
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
Tap,
|
|
8
|
+
TapType,
|
|
9
9
|
} from "silentium";
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -39,10 +39,10 @@ class DirtySource<T> implements SourceType<T> {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
public
|
|
42
|
+
public pipe(transport: TapType<T>) {
|
|
43
43
|
const $comparing = Applied(this.$comparing, this.cloner);
|
|
44
|
-
All($comparing, this.$base).
|
|
45
|
-
|
|
44
|
+
All($comparing, this.$base).pipe(
|
|
45
|
+
Tap(([comparing, base]) => {
|
|
46
46
|
if (!comparing) {
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Late,
|
|
1
|
+
import { Late, Tap } from "silentium";
|
|
2
2
|
import { Loading } from "../behaviors/Loading";
|
|
3
3
|
import { expect, test, vi } from "vitest";
|
|
4
4
|
|
|
@@ -7,7 +7,7 @@ test("Loading.test", () => {
|
|
|
7
7
|
const $loadingFinish = Late();
|
|
8
8
|
const $loading = Loading($loadingStart, $loadingFinish);
|
|
9
9
|
const g = vi.fn();
|
|
10
|
-
$loading.
|
|
10
|
+
$loading.pipe(Tap(g));
|
|
11
11
|
$loadingStart.use({});
|
|
12
12
|
expect(g).toHaveBeenLastCalledWith(true);
|
|
13
13
|
$loadingFinish.use({});
|
package/src/behaviors/Loading.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Message, MessageType,
|
|
1
|
+
import { Message, MessageType, Tap } from "silentium";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Representation Of loading process
|
|
@@ -7,11 +7,11 @@ import { Message, MessageType, Transport } from "silentium";
|
|
|
7
7
|
* https://silentium-lab.github.io/silentium-components/#/behaviors/loading
|
|
8
8
|
*/
|
|
9
9
|
export function Loading(
|
|
10
|
-
$
|
|
11
|
-
$
|
|
10
|
+
$start: MessageType<unknown>,
|
|
11
|
+
$finish: MessageType<unknown>,
|
|
12
12
|
) {
|
|
13
|
-
return Message<boolean>((
|
|
14
|
-
$
|
|
15
|
-
$
|
|
13
|
+
return Message<boolean>(function () {
|
|
14
|
+
$start.pipe(Tap(() => this.use(true)));
|
|
15
|
+
$finish.pipe(Tap(() => this.use(false)));
|
|
16
16
|
});
|
|
17
17
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Late, Shared,
|
|
1
|
+
import { Late, Shared, Tap } from "silentium";
|
|
2
2
|
import { Lock } from "../behaviors/Lock";
|
|
3
3
|
import { expect, test, vi } from "vitest";
|
|
4
4
|
|
|
@@ -9,7 +9,7 @@ test("Lock.test", () => {
|
|
|
9
9
|
const ls = Lock(source, lockSrc);
|
|
10
10
|
const lockedSrc = Shared(ls);
|
|
11
11
|
const g = vi.fn();
|
|
12
|
-
lockedSrc.
|
|
12
|
+
lockedSrc.pipe(Tap(g));
|
|
13
13
|
|
|
14
14
|
expect(g).toHaveBeenLastCalledWith(1);
|
|
15
15
|
|
package/src/behaviors/Lock.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Filtered, Message, MessageType,
|
|
1
|
+
import { Filtered, Message, MessageType, Tap } from "silentium";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Allows locking messages
|
|
@@ -6,14 +6,14 @@ import { Filtered, Message, MessageType, Transport } from "silentium";
|
|
|
6
6
|
* https://silentium-lab.github.io/silentium-components/#/behaviors/lock
|
|
7
7
|
*/
|
|
8
8
|
export function Lock<T>($base: MessageType<T>, $lock: MessageType<boolean>) {
|
|
9
|
-
return Message<T>((
|
|
9
|
+
return Message<T>(function () {
|
|
10
10
|
let locked = false;
|
|
11
|
-
$lock.
|
|
12
|
-
|
|
11
|
+
$lock.pipe(
|
|
12
|
+
Tap((newLock) => {
|
|
13
13
|
locked = newLock;
|
|
14
14
|
}),
|
|
15
15
|
);
|
|
16
16
|
const i = Filtered($base, () => !locked);
|
|
17
|
-
i.
|
|
17
|
+
i.pipe(this);
|
|
18
18
|
});
|
|
19
19
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Late, Shared,
|
|
1
|
+
import { Late, Shared, Tap } from "silentium";
|
|
2
2
|
import { Memo } from "../behaviors/Memo";
|
|
3
3
|
import { expect, test, vi } from "vitest";
|
|
4
4
|
|
|
@@ -6,11 +6,11 @@ test("Memo.test", () => {
|
|
|
6
6
|
const l = Late<number>(1);
|
|
7
7
|
const mem = Shared(Memo(l));
|
|
8
8
|
const g = vi.fn();
|
|
9
|
-
mem.
|
|
9
|
+
mem.pipe(Tap(g));
|
|
10
10
|
let counter = 0;
|
|
11
11
|
|
|
12
|
-
mem.
|
|
13
|
-
|
|
12
|
+
mem.pipe(
|
|
13
|
+
Tap(() => {
|
|
14
14
|
counter += 1;
|
|
15
15
|
}),
|
|
16
16
|
);
|
package/src/behaviors/Memo.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { isFilled, Message, MessageType,
|
|
1
|
+
import { isFilled, Message, MessageType, Tap } from "silentium";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
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
7
|
export function Memo<T>($base: MessageType<T>) {
|
|
8
|
-
return Message<T>((
|
|
8
|
+
return Message<T>(function () {
|
|
9
9
|
let last: T | null = null;
|
|
10
|
-
$base.
|
|
11
|
-
|
|
10
|
+
$base.pipe(
|
|
11
|
+
Tap((v) => {
|
|
12
12
|
if (v !== last && isFilled(v)) {
|
|
13
|
-
|
|
13
|
+
this.use(v);
|
|
14
14
|
last = v;
|
|
15
15
|
}
|
|
16
16
|
}),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Late, Shared,
|
|
1
|
+
import { Late, Shared, Tap } from "silentium";
|
|
2
2
|
import { OnlyChanged } from "../behaviors/OnlyChanged";
|
|
3
3
|
import { expect, test, vi } from "vitest";
|
|
4
4
|
|
|
@@ -7,12 +7,12 @@ test("OnlyChanged.test", () => {
|
|
|
7
7
|
const changedSrc = Shared(OnlyChanged(src));
|
|
8
8
|
|
|
9
9
|
const g = vi.fn();
|
|
10
|
-
changedSrc.
|
|
10
|
+
changedSrc.pipe(Tap(g));
|
|
11
11
|
expect(g).not.toBeCalled();
|
|
12
12
|
|
|
13
13
|
src.use(2);
|
|
14
14
|
|
|
15
15
|
const g2 = vi.fn();
|
|
16
|
-
changedSrc.
|
|
16
|
+
changedSrc.pipe(Tap(g2));
|
|
17
17
|
expect(g2).toBeCalledWith(2);
|
|
18
18
|
});
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { Message, MessageType,
|
|
1
|
+
import { Message, MessageType, Tap } from "silentium";
|
|
2
2
|
|
|
3
3
|
/**
|
|
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
7
|
export function OnlyChanged<T>($base: MessageType<T>) {
|
|
8
|
-
return Message<T>((
|
|
8
|
+
return Message<T>(function () {
|
|
9
9
|
let first = false;
|
|
10
|
-
$base.
|
|
11
|
-
|
|
10
|
+
$base.pipe(
|
|
11
|
+
Tap((v) => {
|
|
12
12
|
if (first === false) {
|
|
13
13
|
first = true;
|
|
14
14
|
} else {
|
|
15
|
-
|
|
15
|
+
this.use(v);
|
|
16
16
|
}
|
|
17
17
|
}),
|
|
18
18
|
);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Late, Of, SharedSource,
|
|
1
|
+
import { Late, Of, SharedSource, Tap } from "silentium";
|
|
2
2
|
import { describe, expect, test, vi } from "vitest";
|
|
3
3
|
import { Part } from "../behaviors/Part";
|
|
4
4
|
|
|
@@ -12,7 +12,7 @@ describe("Part.test", () => {
|
|
|
12
12
|
);
|
|
13
13
|
const $name = Part<string>($record, Of("name"));
|
|
14
14
|
const g = vi.fn();
|
|
15
|
-
$record.
|
|
15
|
+
$record.pipe(Tap(g));
|
|
16
16
|
expect(g).toHaveBeenLastCalledWith({ name: "Peter", surname: "Parker" });
|
|
17
17
|
|
|
18
18
|
$name.use("Shmiter");
|
|
@@ -28,7 +28,7 @@ describe("Part.test", () => {
|
|
|
28
28
|
);
|
|
29
29
|
const $name = Part<string>($record, "name");
|
|
30
30
|
const g = vi.fn();
|
|
31
|
-
$record.
|
|
31
|
+
$record.pipe(Tap(g));
|
|
32
32
|
expect(g).toHaveBeenLastCalledWith({ name: "Peter", surname: "Parker" });
|
|
33
33
|
|
|
34
34
|
$name.use("Shmiter");
|
package/src/behaviors/Part.ts
CHANGED
|
@@ -8,8 +8,8 @@ import {
|
|
|
8
8
|
Shared,
|
|
9
9
|
SharedSource,
|
|
10
10
|
SourceType,
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
Tap,
|
|
12
|
+
TapType,
|
|
13
13
|
} from "silentium";
|
|
14
14
|
|
|
15
15
|
/**
|
|
@@ -35,9 +35,9 @@ class PartImpl<R, T extends object | Array<any>, K extends string = any>
|
|
|
35
35
|
this.$keyed = Shared($key);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
public
|
|
39
|
-
All(this.$base, this.$keyed).
|
|
40
|
-
|
|
38
|
+
public pipe(transport: TapType<R, null>): this {
|
|
39
|
+
All(this.$base, this.$keyed).pipe(
|
|
40
|
+
Tap(([base, keyed]) => {
|
|
41
41
|
const keys = keyed.split(".");
|
|
42
42
|
let value: unknown = base;
|
|
43
43
|
keys.forEach((key) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Of,
|
|
1
|
+
import { Of, Tap } from "silentium";
|
|
2
2
|
import { expect, test, vi } from "vitest";
|
|
3
3
|
import { Path } from "./Path";
|
|
4
4
|
|
|
@@ -9,6 +9,6 @@ test("Path._keyRaw.test", () => {
|
|
|
9
9
|
};
|
|
10
10
|
const name = Path<string>(Of(record), "name");
|
|
11
11
|
const g = vi.fn();
|
|
12
|
-
name.
|
|
12
|
+
name.pipe(Tap(g));
|
|
13
13
|
expect(g).toHaveBeenLastCalledWith("Peter");
|
|
14
14
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Of,
|
|
1
|
+
import { Of, Tap } from "silentium";
|
|
2
2
|
import { expect, test, vi } from "vitest";
|
|
3
3
|
import { Path } from "./Path";
|
|
4
4
|
|
|
@@ -9,6 +9,6 @@ test("Path._main.test", () => {
|
|
|
9
9
|
};
|
|
10
10
|
const name = Path<string>(Of(record), Of("name"));
|
|
11
11
|
const g = vi.fn();
|
|
12
|
-
name.
|
|
12
|
+
name.pipe(Tap(g));
|
|
13
13
|
expect(g).toHaveBeenLastCalledWith("Peter");
|
|
14
14
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Of,
|
|
1
|
+
import { Of, Tap } from "silentium";
|
|
2
2
|
import { expect, test, vi } from "vitest";
|
|
3
3
|
import { Path } from "./Path";
|
|
4
4
|
|
|
@@ -13,6 +13,6 @@ test("Path.index.test", () => {
|
|
|
13
13
|
};
|
|
14
14
|
const bestColor = Path(Of(record), Of("colors.0"));
|
|
15
15
|
const g = vi.fn();
|
|
16
|
-
bestColor.
|
|
16
|
+
bestColor.pipe(Tap(g));
|
|
17
17
|
expect(g).toHaveBeenLastCalledWith("blue");
|
|
18
18
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Of,
|
|
1
|
+
import { Of, Tap } from "silentium";
|
|
2
2
|
import { Path } from "../behaviors/Path";
|
|
3
3
|
import { expect, test, vi } from "vitest";
|
|
4
4
|
|
|
@@ -12,6 +12,6 @@ test("Path.nested.test", () => {
|
|
|
12
12
|
};
|
|
13
13
|
const typeName = Path(Of(record), Of("type.name"));
|
|
14
14
|
const g = vi.fn();
|
|
15
|
-
typeName.
|
|
15
|
+
typeName.pipe(Tap(g));
|
|
16
16
|
expect(g).toHaveBeenLastCalledWith("spider-man");
|
|
17
17
|
});
|
package/src/behaviors/Path.ts
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
MaybeMessage,
|
|
5
5
|
Message,
|
|
6
6
|
MessageType,
|
|
7
|
-
|
|
7
|
+
Tap,
|
|
8
8
|
} from "silentium";
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -17,16 +17,16 @@ export function Path<
|
|
|
17
17
|
K extends string = any,
|
|
18
18
|
>($base: MessageType<T>, _keyed: MaybeMessage<K>) {
|
|
19
19
|
const $keyed = ActualMessage(_keyed);
|
|
20
|
-
return Message<R>((
|
|
21
|
-
All($base, $keyed).
|
|
22
|
-
|
|
20
|
+
return Message<R>(function () {
|
|
21
|
+
All($base, $keyed).pipe(
|
|
22
|
+
Tap(([base, keyed]) => {
|
|
23
23
|
const keys = keyed.split(".");
|
|
24
24
|
let value: unknown = base;
|
|
25
25
|
keys.forEach((key) => {
|
|
26
26
|
value = (value as Record<string, unknown>)[key];
|
|
27
27
|
});
|
|
28
28
|
if (value !== undefined && value !== base) {
|
|
29
|
-
|
|
29
|
+
this.use(value as R);
|
|
30
30
|
}
|
|
31
31
|
}),
|
|
32
32
|
);
|
package/src/behaviors/Polling.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { Message, MessageType,
|
|
1
|
+
import { Message, MessageType, Tap } from "silentium";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Active polling of $base message
|
|
5
5
|
* synchronized with $trigger message
|
|
6
6
|
*/
|
|
7
7
|
export function Polling<T>($base: MessageType<T>, $trigger: MessageType<T>) {
|
|
8
|
-
return Message<T>((
|
|
9
|
-
$trigger.
|
|
10
|
-
|
|
11
|
-
$base.
|
|
8
|
+
return Message<T>(function () {
|
|
9
|
+
$trigger.pipe(
|
|
10
|
+
Tap(() => {
|
|
11
|
+
$base.pipe(this);
|
|
12
12
|
}),
|
|
13
13
|
);
|
|
14
14
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Late, Shared,
|
|
1
|
+
import { Late, Shared, Tap } from "silentium";
|
|
2
2
|
import { Shot } from "../behaviors/Shot";
|
|
3
3
|
import { expect, test, vi } from "vitest";
|
|
4
4
|
|
|
@@ -8,7 +8,7 @@ test("Shot._main.test", () => {
|
|
|
8
8
|
|
|
9
9
|
const $shotted = Shared(Shot($base, $trigger));
|
|
10
10
|
const g = vi.fn();
|
|
11
|
-
$shotted.
|
|
11
|
+
$shotted.pipe(Tap(g));
|
|
12
12
|
|
|
13
13
|
$base.use(1);
|
|
14
14
|
$trigger.use(1);
|
|
@@ -24,6 +24,6 @@ test("Shot._main.test", () => {
|
|
|
24
24
|
expect(g).toHaveBeenLastCalledWith(2);
|
|
25
25
|
|
|
26
26
|
const g2 = vi.fn();
|
|
27
|
-
$shotted.
|
|
27
|
+
$shotted.pipe(Tap(g2));
|
|
28
28
|
expect(g2).toHaveBeenLastCalledWith(2);
|
|
29
29
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Late, Shared,
|
|
1
|
+
import { Late, Shared, Tap } from "silentium";
|
|
2
2
|
import { OnlyChanged } from "../behaviors/OnlyChanged";
|
|
3
3
|
import { Shot } from "../behaviors/Shot";
|
|
4
4
|
import { expect, test } from "vitest";
|
|
@@ -10,8 +10,8 @@ test("Shot._onlyChanged.test", () => {
|
|
|
10
10
|
|
|
11
11
|
const vals: number[] = [];
|
|
12
12
|
|
|
13
|
-
$result.
|
|
14
|
-
|
|
13
|
+
$result.pipe(
|
|
14
|
+
Tap((v) => {
|
|
15
15
|
vals.push(v);
|
|
16
16
|
}),
|
|
17
17
|
);
|
package/src/behaviors/Shot.ts
CHANGED
|
@@ -1,24 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
isFilled,
|
|
3
|
-
Message,
|
|
4
|
-
MessageType,
|
|
5
|
-
Primitive,
|
|
6
|
-
Transport,
|
|
7
|
-
} from "silentium";
|
|
1
|
+
import { isFilled, Message, MessageType, Primitive, Tap } from "silentium";
|
|
8
2
|
|
|
9
3
|
/**
|
|
10
4
|
* Helps to represent only last fresh value Of some source, refreshing controls by shotSrc
|
|
11
5
|
* https://silentium-lab.github.io/silentium-components/#/behaviors/shot
|
|
12
6
|
*/
|
|
13
7
|
export function Shot<T>($target: MessageType<T>, $trigger: MessageType) {
|
|
14
|
-
return Message<T>((
|
|
8
|
+
return Message<T>(function () {
|
|
15
9
|
const targetSync = Primitive($target);
|
|
16
10
|
targetSync.primitive();
|
|
17
|
-
$trigger.
|
|
18
|
-
|
|
11
|
+
$trigger.pipe(
|
|
12
|
+
Tap(() => {
|
|
19
13
|
const value = targetSync.primitive();
|
|
20
14
|
if (isFilled(value)) {
|
|
21
|
-
|
|
15
|
+
this.use(value);
|
|
22
16
|
}
|
|
23
17
|
}),
|
|
24
18
|
);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Late,
|
|
1
|
+
import { Late, Tap } from "silentium";
|
|
2
2
|
import { Task } from "../behaviors/Task";
|
|
3
3
|
import { afterEach, beforeEach, expect, test, vi } from "vitest";
|
|
4
4
|
|
|
@@ -15,8 +15,8 @@ test("Task delays emission", () => {
|
|
|
15
15
|
const $trigger = Late<string>();
|
|
16
16
|
const delayed = Task($trigger, 100);
|
|
17
17
|
const data: string[] = [];
|
|
18
|
-
delayed.
|
|
19
|
-
|
|
18
|
+
delayed.pipe(
|
|
19
|
+
Tap((v) => {
|
|
20
20
|
data.push(v);
|
|
21
21
|
}),
|
|
22
22
|
);
|
|
@@ -36,8 +36,8 @@ test("Task emits only last value when multiple before delay", () => {
|
|
|
36
36
|
const $trigger = Late<string>();
|
|
37
37
|
const delayed = Task($trigger, 100);
|
|
38
38
|
const data: string[] = [];
|
|
39
|
-
delayed.
|
|
40
|
-
|
|
39
|
+
delayed.pipe(
|
|
40
|
+
Tap((v) => {
|
|
41
41
|
data.push(v);
|
|
42
42
|
}),
|
|
43
43
|
);
|
package/src/behaviors/Task.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { ExecutorApplied, Message, MessageType } from "silentium";
|
|
|
6
6
|
* a certain timer firing interval
|
|
7
7
|
*/
|
|
8
8
|
export function Task<T>(baseSrc: MessageType<T>, delay: number = 0) {
|
|
9
|
-
return Message<T>((
|
|
9
|
+
return Message<T>(function () {
|
|
10
10
|
let prevTimer: unknown | null = null;
|
|
11
11
|
ExecutorApplied(baseSrc, (fn) => {
|
|
12
12
|
return (v) => {
|
|
@@ -17,6 +17,6 @@ export function Task<T>(baseSrc: MessageType<T>, delay: number = 0) {
|
|
|
17
17
|
fn(v);
|
|
18
18
|
}, delay);
|
|
19
19
|
};
|
|
20
|
-
}).
|
|
20
|
+
}).pipe(this);
|
|
21
21
|
});
|
|
22
22
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Any, Late, Shared,
|
|
1
|
+
import { Any, Late, Shared, Tap } from "silentium";
|
|
2
2
|
import { Tick } from "../behaviors/Tick";
|
|
3
3
|
import { afterEach, beforeEach, expect, test, vi } from "vitest";
|
|
4
4
|
|
|
@@ -17,7 +17,7 @@ test("Tick.test", async () => {
|
|
|
17
17
|
const $tick = Shared(Tick(Any($s1, $s2)), true);
|
|
18
18
|
|
|
19
19
|
const g = vi.fn();
|
|
20
|
-
$tick.
|
|
20
|
+
$tick.pipe(Tap(g));
|
|
21
21
|
|
|
22
22
|
$s1.use(3);
|
|
23
23
|
$s2.use(4);
|
package/src/behaviors/Tick.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Message, MessageType,
|
|
1
|
+
import { Message, MessageType, Tap } from "silentium";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
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
7
|
export function Tick<T>($base: MessageType<T>) {
|
|
8
|
-
return Message((
|
|
8
|
+
return Message(function () {
|
|
9
9
|
let microtaskScheduled = false;
|
|
10
10
|
let lastValue: T | null = null;
|
|
11
11
|
|
|
@@ -14,14 +14,14 @@ export function Tick<T>($base: MessageType<T>) {
|
|
|
14
14
|
queueMicrotask(() => {
|
|
15
15
|
microtaskScheduled = false;
|
|
16
16
|
if (lastValue !== null) {
|
|
17
|
-
|
|
17
|
+
this.use(lastValue);
|
|
18
18
|
lastValue = null;
|
|
19
19
|
}
|
|
20
20
|
});
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
$base.
|
|
24
|
-
|
|
23
|
+
$base.pipe(
|
|
24
|
+
Tap((v) => {
|
|
25
25
|
lastValue = v;
|
|
26
26
|
if (!microtaskScheduled) {
|
|
27
27
|
scheduleMicrotask();
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
Message,
|
|
6
6
|
MessageType,
|
|
7
7
|
Of,
|
|
8
|
-
|
|
8
|
+
Tap,
|
|
9
9
|
} from "silentium";
|
|
10
10
|
import { Detached } from "../behaviors/Detached";
|
|
11
11
|
|
|
@@ -21,18 +21,18 @@ export function Transaction<T, R = unknown>(
|
|
|
21
21
|
>,
|
|
22
22
|
...args: MessageType[]
|
|
23
23
|
) {
|
|
24
|
-
return Message<R>((
|
|
24
|
+
return Message<R>(function () {
|
|
25
25
|
const $res = LateShared<R>();
|
|
26
26
|
const destructors: DestroyableType[] = [];
|
|
27
27
|
|
|
28
|
-
$base.
|
|
29
|
-
|
|
28
|
+
$base.pipe(
|
|
29
|
+
Tap((v) => {
|
|
30
30
|
const $msg = builder(Of(v), ...args.map((a) => Detached(a)));
|
|
31
31
|
destructors.push($msg as unknown as DestroyableType);
|
|
32
|
-
$msg.
|
|
32
|
+
$msg.pipe($res);
|
|
33
33
|
}),
|
|
34
34
|
);
|
|
35
|
-
$res.
|
|
35
|
+
$res.pipe(this);
|
|
36
36
|
|
|
37
37
|
return () => {
|
|
38
38
|
destructors.forEach((d) => d?.destroy());
|
package/src/boolean/And.test.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Late,
|
|
1
|
+
import { Late, Tap } from "silentium";
|
|
2
2
|
import { expect, test, vi } from "vitest";
|
|
3
3
|
import { And } from "../boolean/And";
|
|
4
4
|
|
|
@@ -7,7 +7,7 @@ test("And.test", () => {
|
|
|
7
7
|
const $two = Late<boolean>(false);
|
|
8
8
|
const result = And($one, $two);
|
|
9
9
|
const g = vi.fn();
|
|
10
|
-
result.
|
|
10
|
+
result.pipe(Tap(g));
|
|
11
11
|
expect(g).toHaveBeenLastCalledWith(false);
|
|
12
12
|
|
|
13
13
|
$one.use(true);
|
package/src/boolean/And.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { All, Message, MessageType,
|
|
1
|
+
import { All, Message, MessageType, Tap } from "silentium";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Logical AND over two messages
|
|
5
5
|
* https://silentium-lab.github.io/silentium-components/#/boolean/and
|
|
6
6
|
*/
|
|
7
7
|
export function And($one: MessageType<boolean>, $two: MessageType<boolean>) {
|
|
8
|
-
return Message<boolean>((
|
|
9
|
-
All($one, $two).
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
return Message<boolean>(function () {
|
|
9
|
+
All($one, $two).pipe(
|
|
10
|
+
Tap(([one, two]) => {
|
|
11
|
+
this.use(!!(one && two));
|
|
12
12
|
}),
|
|
13
13
|
);
|
|
14
14
|
});
|
package/src/boolean/Bool.test.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Of,
|
|
1
|
+
import { Of, Tap } from "silentium";
|
|
2
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
|
-
Bool(Of(1)).
|
|
7
|
+
Bool(Of(1)).pipe(Tap(o));
|
|
8
8
|
expect(o).toHaveBeenCalledWith(true);
|
|
9
9
|
});
|
package/src/boolean/Bool.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { Applied, Message, MessageType } from "silentium";
|
|
|
5
5
|
* https://silentium-lab.github.io/silentium-components/#/boolean/bool
|
|
6
6
|
*/
|
|
7
7
|
export function Bool($base: MessageType) {
|
|
8
|
-
return Message<boolean>((
|
|
9
|
-
Applied($base, Boolean).
|
|
8
|
+
return Message<boolean>(function () {
|
|
9
|
+
Applied($base, Boolean).pipe(this);
|
|
10
10
|
});
|
|
11
11
|
}
|
package/src/boolean/Not.test.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Late,
|
|
1
|
+
import { Late, Tap } from "silentium";
|
|
2
2
|
import { Not } from "../boolean/Not";
|
|
3
3
|
import { expect, test, vi } from "vitest";
|
|
4
4
|
|
|
@@ -6,7 +6,7 @@ test("Not.test", () => {
|
|
|
6
6
|
const one = Late<boolean>(false);
|
|
7
7
|
const result = Not(one);
|
|
8
8
|
const g = vi.fn();
|
|
9
|
-
result.
|
|
9
|
+
result.pipe(Tap(g));
|
|
10
10
|
expect(g).toHaveBeenLastCalledWith(true);
|
|
11
11
|
|
|
12
12
|
one.use(true);
|
package/src/boolean/Not.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { Message, MessageType,
|
|
1
|
+
import { Message, MessageType, Tap } from "silentium";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Logical negation of message
|
|
5
5
|
* https://silentium-lab.github.io/silentium-components/#/boolean/not
|
|
6
6
|
*/
|
|
7
7
|
export function Not($base: MessageType<boolean>) {
|
|
8
|
-
return Message<boolean>((
|
|
9
|
-
$base.
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
return Message<boolean>(function () {
|
|
9
|
+
$base.pipe(
|
|
10
|
+
Tap((v) => {
|
|
11
|
+
this.use(!v);
|
|
12
12
|
}),
|
|
13
13
|
);
|
|
14
14
|
});
|