silentium 0.0.2 → 0.0.3
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 +19 -0
- package/beforeRelease.sh +11 -0
- package/dist/silentium.cjs +39 -63
- package/dist/silentium.cjs.map +1 -1
- package/dist/silentium.d.ts +34 -53
- package/dist/silentium.js +40 -63
- package/dist/silentium.js.map +1 -1
- package/dist/silentium.min.js +1 -1
- package/dist/silentium.min.mjs +1 -1
- package/dist/silentium.min.mjs.map +1 -1
- package/dist/silentium.mjs +40 -63
- package/dist/silentium.mjs.map +1 -1
- package/docs/assets/css/base.css +15 -0
- package/docs/assets/css/custom.css +72 -0
- package/docs/assets/img/logo.svg +1522 -0
- package/docs/assets/js/components/linkDynamic.mjs +14 -0
- package/docs/assets/js/components/linkReloadable.mjs +17 -0
- package/docs/assets/js/components.mjs +2 -0
- package/docs/assets/js/index.mjs +74 -0
- package/docs/assets/js/lib/StyleFetched.mjs +19 -0
- package/docs/build.sh +7 -3
- package/docs/buildRoutes.sh +15 -0
- package/docs/favicon.ico +0 -0
- package/docs/index-dev.html +4 -80
- package/docs/index.html +6 -82
- package/docs/pages/compatibility/elegant-objects.html +4 -4
- package/docs/pages/examples/errors.html +2 -2
- package/docs/pages/examples.html +12 -14
- package/docs/pages/guest/guest-applied.html +9 -5
- package/docs/pages/guest/guest-cast.html +20 -26
- package/docs/pages/guest/guest-disposable.html +32 -42
- package/docs/pages/guest/guest-executor-applied.html +21 -17
- package/docs/pages/guest/guest-object.html +22 -26
- package/docs/pages/guest/guest-pool.html +17 -18
- package/docs/pages/guest/guest-sync.html +7 -2
- package/docs/pages/guest/index.html +18 -29
- package/docs/pages/guest.html +112 -18
- package/docs/pages/index.html +24 -52
- package/docs/pages/integrations/vue.html +5 -8
- package/docs/pages/patron/index.html +14 -20
- package/docs/pages/patron/patron-applied.html +2 -2
- package/docs/pages/patron/patron-executor-applied.html +2 -2
- package/docs/pages/patron/patron-once.html +12 -18
- package/docs/pages/patron/patron-pool.html +12 -18
- package/docs/pages/patron.html +137 -16
- package/docs/pages/philosofy.html +30 -49
- package/docs/pages/source/index.html +11 -14
- package/docs/pages/source/source-all.html +9 -12
- package/docs/pages/source/source-applied.html +2 -2
- package/docs/pages/source/source-dynamic.html +3 -3
- package/docs/pages/source/source-executor-applied.html +2 -2
- package/docs/pages/source/source-map.html +5 -5
- package/docs/pages/source/source-once.html +2 -2
- package/docs/pages/source/source-race.html +10 -10
- package/docs/pages/source/source-sequence.html +2 -2
- package/docs/pages/source/source-with-pool.html +8 -11
- package/docs/pages/source/source.html +11 -14
- package/docs/pages/source.html +162 -31
- package/docs/pages/terminology/source.html +5 -9
- package/docs/pages/terminology.html +12 -18
- package/docs/pages/utils.html +33 -21
- package/docs/routes.json +1 -0
- package/docs/template.html +4 -80
- package/eslint.config.mjs +3 -0
- package/package.json +2 -2
- package/src/Guest/Guest.ts +3 -3
- package/src/Guest/GuestApplied.ts +1 -1
- package/src/Guest/GuestCast.ts +1 -1
- package/src/Guest/GuestDisposable.ts +1 -1
- package/src/Guest/GuestExecutorApplied.ts +1 -1
- package/src/Guest/GuestObject.ts +1 -1
- package/src/Guest/GuestPool.ts +1 -1
- package/src/Guest/GuestSync.ts +1 -1
- package/src/Patron/Patron.ts +2 -2
- package/src/Patron/PatronApplied.ts +1 -1
- package/src/Patron/PatronExecutorApplied.ts +1 -1
- package/src/Patron/PatronOnce.ts +1 -1
- package/src/Patron/PatronPool.ts +4 -4
- package/src/Private/Private.ts +1 -1
- package/src/Source/Source.ts +4 -4
- package/src/Source/SourceAll.ts +1 -1
- package/src/Source/SourceApplied.ts +1 -1
- package/src/Source/SourceDynamic.ts +1 -1
- package/src/Source/SourceExecutorApplied.ts +1 -1
- package/src/Source/SourceMap.ts +1 -1
- package/src/Source/SourceOnce.ts +1 -1
- package/src/Source/SourceRace.ts +1 -1
- package/src/Source/SourceSequence.ts +1 -1
- package/src/Source/SourceWithPool.ts +1 -1
- package/src/index.ts +0 -1
- package/docs/pages/source/source-active.html +0 -120
- package/src/Source/SourceActive.test.ts +0 -13
- package/src/Source/SourceActive.ts +0 -41
package/src/Patron/Patron.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { give, GuestType } from "../Guest/Guest";
|
|
|
2
2
|
import { GuestDisposableType } from "../Guest/GuestDisposable";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* @url https://
|
|
5
|
+
* @url https://silentium-lab.github.io/silentium/#/patron
|
|
6
6
|
*/
|
|
7
7
|
export class Patron<T> implements GuestDisposableType<T> {
|
|
8
8
|
public constructor(private willBePatron: GuestType<T>) {
|
|
@@ -27,7 +27,7 @@ export class Patron<T> implements GuestDisposableType<T> {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
|
-
* @url https://
|
|
30
|
+
* @url https://silentium-lab.github.io/silentium/#/utils/is-patron
|
|
31
31
|
*/
|
|
32
32
|
export const isPatron = (guest: GuestType): guest is Patron<unknown> =>
|
|
33
33
|
typeof guest === "object" &&
|
|
@@ -2,7 +2,7 @@ import { GuestObjectType, GuestType } from "../Guest/Guest";
|
|
|
2
2
|
import { GuestApplied } from "../Guest/GuestApplied";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* @url https://
|
|
5
|
+
* @url https://silentium-lab.github.io/silentium/#/patron/patron-applied
|
|
6
6
|
*/
|
|
7
7
|
export class PatronApplied<T, R> implements GuestObjectType<T> {
|
|
8
8
|
private guestApplied: GuestApplied<T, R>;
|
|
@@ -2,7 +2,7 @@ import { GuestExecutorType, GuestObjectType, GuestType } from "../Guest/Guest";
|
|
|
2
2
|
import { GuestExecutorApplied } from "../Guest/GuestExecutorApplied";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* @url https://
|
|
5
|
+
* @url https://silentium-lab.github.io/silentium/#/patron/patron-executor-applied
|
|
6
6
|
*/
|
|
7
7
|
export class PatronExecutorApplied<T> implements GuestObjectType<T> {
|
|
8
8
|
private guestApplied: GuestExecutorApplied<T>;
|
package/src/Patron/PatronOnce.ts
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
} from "../Guest/GuestDisposable";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* @url https://
|
|
8
|
+
* @url https://silentium-lab.github.io/silentium/#/patron/patron-once
|
|
9
9
|
*/
|
|
10
10
|
export class PatronOnce<T> implements GuestDisposableType<T> {
|
|
11
11
|
private received = false;
|
package/src/Patron/PatronPool.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { GuestDisposableType } from "../Guest/GuestDisposable";
|
|
|
4
4
|
const poolSets = new Map<PoolType, Set<GuestObjectType>>();
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* @url https://
|
|
7
|
+
* @url https://silentium-lab.github.io/silentium/#/utils/patron-pools
|
|
8
8
|
*/
|
|
9
9
|
export const patronPools = (patron: GuestObjectType) => {
|
|
10
10
|
const pools: PoolType[] = [];
|
|
@@ -17,7 +17,7 @@ export const patronPools = (patron: GuestObjectType) => {
|
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
* @url https://
|
|
20
|
+
* @url https://silentium-lab.github.io/silentium/#/utils/remove-patron-from-pools
|
|
21
21
|
*/
|
|
22
22
|
export const removePatronFromPools = (patron: GuestObjectType) => {
|
|
23
23
|
if (patron === undefined) {
|
|
@@ -29,7 +29,7 @@ export const removePatronFromPools = (patron: GuestObjectType) => {
|
|
|
29
29
|
};
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
|
-
* @url https://
|
|
32
|
+
* @url https://silentium-lab.github.io/silentium/#/utils/is-patron-in-pools
|
|
33
33
|
*/
|
|
34
34
|
export const isPatronInPools = (patron: GuestObjectType) => {
|
|
35
35
|
if (patron === undefined) {
|
|
@@ -52,7 +52,7 @@ export interface PoolType<T = any> extends GuestObjectType<T> {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
|
-
* @url https://
|
|
55
|
+
* @url https://silentium-lab.github.io/silentium/#/patron/patron-pool
|
|
56
56
|
*/
|
|
57
57
|
export class PatronPool<T> implements PoolType<T> {
|
|
58
58
|
private patrons: Set<GuestObjectType<T>>;
|
package/src/Private/Private.ts
CHANGED
package/src/Source/Source.ts
CHANGED
|
@@ -9,7 +9,7 @@ export interface SourceObjectType<T> {
|
|
|
9
9
|
export type SourceType<T = any> = SourceExecutorType<T> | SourceObjectType<T>;
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
* @url https://
|
|
12
|
+
* @url https://silentium-lab.github.io/silentium/#/utils/value
|
|
13
13
|
*/
|
|
14
14
|
export function value<T>(source: SourceType<T>, guest: GuestType<T>) {
|
|
15
15
|
if (source === undefined) {
|
|
@@ -26,7 +26,7 @@ export function value<T>(source: SourceType<T>, guest: GuestType<T>) {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
|
-
* @url https://
|
|
29
|
+
* @url https://silentium-lab.github.io/silentium/#/utils/is-source
|
|
30
30
|
*/
|
|
31
31
|
export function isSource(mbSource: any): mbSource is SourceType {
|
|
32
32
|
if (mbSource === undefined) {
|
|
@@ -38,7 +38,7 @@ export function isSource(mbSource: any): mbSource is SourceType {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
|
-
* @url https://
|
|
41
|
+
* @url https://silentium-lab.github.io/silentium/#/guest/source
|
|
42
42
|
*/
|
|
43
43
|
export class Source<T = any> implements SourceObjectType<T> {
|
|
44
44
|
public constructor(private source: SourceType<T>) {
|
|
@@ -54,6 +54,6 @@ export class Source<T = any> implements SourceObjectType<T> {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
|
-
* @url https://
|
|
57
|
+
* @url https://silentium-lab.github.io/silentium/#/utils/source-of
|
|
58
58
|
*/
|
|
59
59
|
export const sourceOf = <T>(value: T) => new Source<T>((g) => give(value, g));
|
package/src/Source/SourceAll.ts
CHANGED
|
@@ -11,7 +11,7 @@ export interface SourceAllType<T = any> extends SourceObjectType<T> {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
* @url https://
|
|
14
|
+
* @url https://silentium-lab.github.io/silentium/#/guest/source-all
|
|
15
15
|
*/
|
|
16
16
|
export class SourceAll<T> implements SourceAllType<T> {
|
|
17
17
|
private theAll: SourceWithPool<Record<string, unknown>>;
|
|
@@ -3,7 +3,7 @@ import { GuestCast } from "../Guest/GuestCast";
|
|
|
3
3
|
import { SourceObjectType, SourceType, value } from "../Source/Source";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* @url https://
|
|
6
|
+
* @url https://silentium-lab.github.io/silentium/#/source/source-applied
|
|
7
7
|
*/
|
|
8
8
|
export class SourceApplied<T, R> implements SourceObjectType<R> {
|
|
9
9
|
public constructor(
|
|
@@ -4,7 +4,7 @@ import { PatronPool } from "../Patron/PatronPool";
|
|
|
4
4
|
import { SourceWithPoolType } from "./SourceWithPool";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* @url https://
|
|
7
|
+
* @url https://silentium-lab.github.io/silentium/#/source-dynamic
|
|
8
8
|
*/
|
|
9
9
|
export class SourceDynamic<T = unknown> implements SourceWithPoolType<T> {
|
|
10
10
|
public constructor(
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
} from "../Source/Source";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* @url https://
|
|
9
|
+
* @url https://silentium-lab.github.io/silentium/#/source/source-executor-applied
|
|
10
10
|
*/
|
|
11
11
|
export class SourceExecutorApplied<T> implements SourceObjectType<T> {
|
|
12
12
|
public value: SourceExecutorType<T>;
|
package/src/Source/SourceMap.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { SourceAll } from "./SourceAll";
|
|
|
11
11
|
import { GuestCast } from "../Guest/GuestCast";
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
* @url https://
|
|
14
|
+
* @url https://silentium-lab.github.io/silentium/#/guest/source-map
|
|
15
15
|
*/
|
|
16
16
|
export class SourceMap<T, TG> implements SourceObjectType<TG[]> {
|
|
17
17
|
public constructor(
|
package/src/Source/SourceOnce.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { value } from "./Source";
|
|
|
4
4
|
import { SourceWithPool, SourceWithPoolType } from "./SourceWithPool";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* @url https://
|
|
7
|
+
* @url https://silentium-lab.github.io/silentium/#/source/source-once
|
|
8
8
|
*/
|
|
9
9
|
export class SourceOnce<T> implements SourceWithPoolType<T> {
|
|
10
10
|
private source: SourceWithPool<T>;
|
package/src/Source/SourceRace.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { SourceObjectType, SourceType, value } from "./Source";
|
|
|
3
3
|
import { GuestCast } from "../Guest/GuestCast";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* @url https://
|
|
6
|
+
* @url https://silentium-lab.github.io/silentium/#/guest/source-race
|
|
7
7
|
*/
|
|
8
8
|
export class SourceRace<T> implements SourceObjectType<T> {
|
|
9
9
|
public constructor(private sources: SourceType<T>[]) {
|
|
@@ -7,7 +7,7 @@ import { isSource, SourceObjectType, SourceType, value } from "./Source";
|
|
|
7
7
|
import { SourceAll } from "./SourceAll";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* @url https://
|
|
10
|
+
* @url https://silentium-lab.github.io/silentium/#/guest/source-sequence
|
|
11
11
|
*/
|
|
12
12
|
export class SourceSequence<T, TG> implements SourceObjectType<TG[]> {
|
|
13
13
|
public constructor(
|
|
@@ -8,7 +8,7 @@ export interface PoolAwareType<T = any> {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* @url https://
|
|
11
|
+
* @url https://silentium-lab.github.io/silentium/#/source-with-pool
|
|
12
12
|
*/
|
|
13
13
|
export type SourceWithPoolType<T = any> = SourceObjectType<T> &
|
|
14
14
|
GuestObjectType<T> &
|
package/src/index.ts
CHANGED
|
@@ -16,7 +16,6 @@ export * from "./Source/Source";
|
|
|
16
16
|
export * from "./Source/SourceSequence";
|
|
17
17
|
export * from "./Source/SourceMap";
|
|
18
18
|
export * from "./Source/SourceRace";
|
|
19
|
-
export * from "./Source/SourceActive";
|
|
20
19
|
export * from "./Source/SourceWithPool";
|
|
21
20
|
export * from "./Source/SourceDynamic";
|
|
22
21
|
export * from "./Source/SourceApplied";
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
<h1 class="pb-3 text-xl font-semibold text-gray-600">Класс SourceActive</h1>
|
|
2
|
-
|
|
3
|
-
<a
|
|
4
|
-
href="https://github.com/kosukhin/patron/blob/main/src/Source/SourceActive.ts"
|
|
5
|
-
target="_blank"
|
|
6
|
-
class="inline-flex gap-1 items-center bg-gray-100 border-0 py-1 px-3 focus:outline-none hover:bg-gray-200 rounded text-base mt-4 md:mt-0 mb-4"
|
|
7
|
-
>
|
|
8
|
-
<img
|
|
9
|
-
src="./assets/img/github_16.jpg"
|
|
10
|
-
width="16"
|
|
11
|
-
height="16"
|
|
12
|
-
/>
|
|
13
|
-
SourceActive на GitHub
|
|
14
|
-
</a>
|
|
15
|
-
|
|
16
|
-
<p class="text-gray-600 text-lg mb-4">
|
|
17
|
-
Планируется убрать этот класс из библиотеке, и вместе с ним ActionType.
|
|
18
|
-
Потому что можно добиться того же эффекта с использованием источника, который ожидает другой источник.
|
|
19
|
-
Например источник FetchResopnse может ожидать источник FetchRequest и когда в FetchRequest появится значение запроса
|
|
20
|
-
FetchResopnse с использованием своего внутреннего посетителя сделает fetch и получив ответ отдаст ответ своим посетителям.
|
|
21
|
-
</p>
|
|
22
|
-
|
|
23
|
-
<p class="text-gray-600 text-lg mb-4">
|
|
24
|
-
Класс
|
|
25
|
-
<link-dynamic href="/source">Source</link-dynamic> можно
|
|
26
|
-
назвать пассивным
|
|
27
|
-
<link-dynamic href="/terminology/the-source">источником данных</link-dynamic>,
|
|
28
|
-
потому что мы только вызываем его метод <b>value</b> и надеемся получить
|
|
29
|
-
данные, либо говорим что нас нужно уведомлять о новых данных. При этом никаких
|
|
30
|
-
активных действий совершать не требуется
|
|
31
|
-
</p>
|
|
32
|
-
|
|
33
|
-
<p class="text-gray-600 text-lg mb-4">
|
|
34
|
-
Класс <b>SourceActive</b> можно назвать активным источником данных. Чтобы
|
|
35
|
-
значение было рассчитано мы должны явно вызывать метод <b>do</b>. Подобные
|
|
36
|
-
классы полезны в случаях, когда вычисление нужно выполнить не сразу а по
|
|
37
|
-
событию
|
|
38
|
-
</p>
|
|
39
|
-
|
|
40
|
-
<p class="text-gray-600 text-lg mb-4">
|
|
41
|
-
Также можно отдельно использовать
|
|
42
|
-
<link-reloadable
|
|
43
|
-
target-blank
|
|
44
|
-
href="https://github.com/kosukhin/patron/blob/main/src/Guest/SourceActive.ts#L9"
|
|
45
|
-
>ActionType</link-reloadable
|
|
46
|
-
>
|
|
47
|
-
интерфейс для объявления своих собственных классов - активных источников
|
|
48
|
-
данных, имеющих метод do
|
|
49
|
-
</p>
|
|
50
|
-
|
|
51
|
-
<p class="text-gray-600 text-lg mb-0 font-bold">Пример 1.</p>
|
|
52
|
-
<pre
|
|
53
|
-
class="mb-4"
|
|
54
|
-
><code class="language-js">import { SourceActive, Patron } from "patron-oop";
|
|
55
|
-
|
|
56
|
-
const eur = new SourceActive((_, source) => {
|
|
57
|
-
source.give("Loading...");
|
|
58
|
-
fetch("https://www.cbr.ru/scripts/XML_daily.asp")
|
|
59
|
-
.then((r) => r.text())
|
|
60
|
-
.then((r) => {
|
|
61
|
-
const parser = new DOMParser();
|
|
62
|
-
const doc = parser.parseFromString(r, "application/xml");
|
|
63
|
-
const eurNode = doc.querySelector('[ID="R01239"] Value');
|
|
64
|
-
source.give(eurNode.textContent);
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
eur.value(
|
|
69
|
-
new Patron((val) => {
|
|
70
|
-
document.querySelector(".guest-result").textContent = `EUR/RUB = ${val}`;
|
|
71
|
-
})
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
document
|
|
75
|
-
.getElementById("get-eur")
|
|
76
|
-
.addEventListener("click", eur.do.bind(eur));
|
|
77
|
-
</code></pre>
|
|
78
|
-
|
|
79
|
-
<p class="text-gray-600 text-lg mb-1 font-bold">Результат 1.</p>
|
|
80
|
-
<button
|
|
81
|
-
class="inline-flex gap-1 items-center bg-gray-100 border-0 py-1 px-3 focus:outline-none hover:bg-gray-200 rounded text-base mt-4 md:mt-0 mb-4"
|
|
82
|
-
id="get-eur"
|
|
83
|
-
>
|
|
84
|
-
Get EUR
|
|
85
|
-
</button>
|
|
86
|
-
<div class="example mb-4">
|
|
87
|
-
<span class="guest-result"> Нажмите кнопку "Get EUR" </span>
|
|
88
|
-
</div>
|
|
89
|
-
|
|
90
|
-
<script type="module">
|
|
91
|
-
import { SourceActive, Patron } from "patron-oop";
|
|
92
|
-
|
|
93
|
-
const eur = new SourceActive((_, source) => {
|
|
94
|
-
source.give("Loading...");
|
|
95
|
-
fetch("https://www.cbr.ru/scripts/XML_daily.asp")
|
|
96
|
-
.then((r) => r.text())
|
|
97
|
-
.then((r) => {
|
|
98
|
-
const parser = new DOMParser();
|
|
99
|
-
const doc = parser.parseFromString(r, "application/xml");
|
|
100
|
-
const eurNode = doc.querySelector('[ID="R01239"] Value');
|
|
101
|
-
source.give(eurNode.textContent);
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
eur.value(
|
|
106
|
-
new Patron((val) => {
|
|
107
|
-
document.querySelector(".guest-result").textContent = `EUR/RUB = ${val}`;
|
|
108
|
-
})
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
document
|
|
112
|
-
.getElementById("get-eur")
|
|
113
|
-
.addEventListener("click", eur.do.bind(eur));
|
|
114
|
-
</script>
|
|
115
|
-
|
|
116
|
-
<div class="font-bold mt-8">Смотрите также</div>
|
|
117
|
-
|
|
118
|
-
<p class="text-gray-600 text-lg mb-4 dynamic-navigation">
|
|
119
|
-
<link-dynamic href="/source">Source</link-dynamic>
|
|
120
|
-
</p>
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { SourceActive } from "./SourceActive";
|
|
2
|
-
import { expect, test, vitest } from "vitest";
|
|
3
|
-
|
|
4
|
-
test("SourceActive.test", () => {
|
|
5
|
-
const active = new SourceActive<number, number>((config, source) => {
|
|
6
|
-
source.give(config * 3);
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
const guest = vitest.fn();
|
|
10
|
-
active.do(4).value(guest);
|
|
11
|
-
|
|
12
|
-
expect(guest).toBeCalledWith(12);
|
|
13
|
-
});
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { GuestType } from "../Guest/Guest";
|
|
2
|
-
import { SourceObjectType } from "./Source";
|
|
3
|
-
import { SourceWithPool, SourceWithPoolType } from "./SourceWithPool";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @url https://kosukhin.github.io/patron.site/#/utils/action-type
|
|
7
|
-
*/
|
|
8
|
-
export interface ActionType<P = any> {
|
|
9
|
-
do(config: P): this;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface SourceAcitveType<R = unknown, T = unknown>
|
|
13
|
-
extends SourceObjectType<T>,
|
|
14
|
-
ActionType<R> {}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @url https://kosukhin.github.io/patron.site/#/guest/source-active
|
|
18
|
-
*/
|
|
19
|
-
export class SourceActive<R, T> implements SourceAcitveType<R, T> {
|
|
20
|
-
private source = new SourceWithPool<T>();
|
|
21
|
-
|
|
22
|
-
public constructor(
|
|
23
|
-
private configExecutor: (config: R, source: SourceWithPoolType<T>) => void,
|
|
24
|
-
) {
|
|
25
|
-
if (configExecutor === undefined) {
|
|
26
|
-
throw new Error(
|
|
27
|
-
"SourceActive constructor didnt receive executor function",
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
public do(config: R): this {
|
|
33
|
-
this.configExecutor(config, this.source);
|
|
34
|
-
return this;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
public value(guest: GuestType<T>): this {
|
|
38
|
-
this.source.value(guest);
|
|
39
|
-
return this;
|
|
40
|
-
}
|
|
41
|
-
}
|