patron-oop 1.44.1 → 1.46.0
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 +20 -0
- package/dist/patron.cjs +359 -268
- package/dist/patron.cjs.map +1 -1
- package/dist/patron.d.ts +215 -150
- package/dist/patron.js +343 -261
- package/dist/patron.js.map +1 -1
- package/dist/patron.min.js +1 -1
- package/dist/patron.min.mjs +1 -1
- package/dist/patron.min.mjs.map +1 -1
- package/dist/patron.mjs +343 -261
- package/dist/patron.mjs.map +1 -1
- package/docs/README.md +3 -0
- package/docs/assets/css/base.css +42 -0
- package/docs/assets/favicon/android-icon-144x144.png +0 -0
- package/docs/assets/favicon/android-icon-192x192.png +0 -0
- package/docs/assets/favicon/android-icon-36x36.png +0 -0
- package/docs/assets/favicon/android-icon-48x48.png +0 -0
- package/docs/assets/favicon/android-icon-72x72.png +0 -0
- package/docs/assets/favicon/android-icon-96x96.png +0 -0
- package/docs/assets/favicon/apple-icon-114x114.png +0 -0
- package/docs/assets/favicon/apple-icon-120x120.png +0 -0
- package/docs/assets/favicon/apple-icon-144x144.png +0 -0
- package/docs/assets/favicon/apple-icon-152x152.png +0 -0
- package/docs/assets/favicon/apple-icon-180x180.png +0 -0
- package/docs/assets/favicon/apple-icon-57x57.png +0 -0
- package/docs/assets/favicon/apple-icon-60x60.png +0 -0
- package/docs/assets/favicon/apple-icon-72x72.png +0 -0
- package/docs/assets/favicon/apple-icon-76x76.png +0 -0
- package/docs/assets/favicon/apple-icon-precomposed.png +0 -0
- package/docs/assets/favicon/apple-icon.png +0 -0
- package/docs/assets/favicon/browserconfig.xml +2 -0
- package/docs/assets/favicon/favicon-16x16.png +0 -0
- package/docs/assets/favicon/favicon-32x32.png +0 -0
- package/docs/assets/favicon/favicon-96x96.png +0 -0
- package/docs/assets/favicon/favicon.ico +0 -0
- package/docs/assets/favicon/manifest.json +41 -0
- package/docs/assets/favicon/ms-icon-144x144.png +0 -0
- package/docs/assets/favicon/ms-icon-150x150.png +0 -0
- package/docs/assets/favicon/ms-icon-310x310.png +0 -0
- package/docs/assets/favicon/ms-icon-70x70.png +0 -0
- package/docs/assets/img/404.jpg +0 -0
- package/docs/assets/img/angular_16.jpg +0 -0
- package/docs/assets/img/angular_32.jpg +0 -0
- package/docs/assets/img/eo_16.jpg +0 -0
- package/docs/assets/img/eo_big.png +0 -0
- package/docs/assets/img/github_16.jpg +0 -0
- package/docs/assets/img/logo.jpg +0 -0
- package/docs/assets/img/philosofy/observable.jpg +0 -0
- package/docs/assets/img/philosofy/responsible.jpg +0 -0
- package/docs/assets/img/philosofy/result.jpg +0 -0
- package/docs/assets/img/philosofy/tell.jpg +0 -0
- package/docs/assets/img/react_16.jpg +0 -0
- package/docs/assets/img/react_32.jpg +0 -0
- package/docs/assets/img/vue_16.jpg +0 -0
- package/docs/assets/img/vue_32.jpg +0 -0
- package/docs/assets/js/components/linkDynamic.mjs +11 -0
- package/docs/assets/js/components/linkReloadable.mjs +13 -0
- package/docs/assets/js/entrypoints/compatibility.mjs +31 -0
- package/docs/assets/js/entrypoints/components.mjs +2 -0
- package/docs/assets/js/entrypoints/examples.mjs +25 -0
- package/docs/assets/js/entrypoints/factory.mjs +20 -0
- package/docs/assets/js/entrypoints/guest.mjs +61 -0
- package/docs/assets/js/entrypoints/index.mjs +110 -0
- package/docs/assets/js/entrypoints/integrations.mjs +36 -0
- package/docs/assets/js/entrypoints/patron.mjs +46 -0
- package/docs/assets/js/entrypoints/source.mjs +76 -0
- package/docs/assets/js/entrypoints/terminology.mjs +51 -0
- package/docs/assets/js/entrypoints/utils.mjs +61 -0
- package/docs/assets/js/lib/StyleFetched.mjs +14 -0
- package/docs/assets/js/routing.mjs +110 -0
- package/docs/assets/schemes/dip.html +28 -0
- package/docs/favicon.ico +0 -0
- package/docs/index-dev.html +346 -0
- package/docs/index.html +346 -0
- package/docs/manifest.json +41 -0
- package/docs/pages/404.html +9 -0
- package/docs/pages/common/layout.html +17 -0
- package/docs/pages/compatibility/dip.html +82 -0
- package/docs/pages/compatibility/elegant-objects.html +373 -0
- package/docs/pages/compatibility/layout.html +17 -0
- package/docs/pages/examples/errors.html +167 -0
- package/docs/pages/examples/index.html +10 -0
- package/docs/pages/examples.html +41 -0
- package/docs/pages/factory/index.html +18 -0
- package/docs/pages/factory.html +36 -0
- package/docs/pages/guest/guest-applied.html +51 -0
- package/docs/pages/guest/guest-cast.html +219 -0
- package/docs/pages/guest/guest-disposable.html +147 -0
- package/docs/pages/guest/guest-executor-applied.html +65 -0
- package/docs/pages/guest/guest-object.html +101 -0
- package/docs/pages/guest/guest-pool.html +107 -0
- package/docs/pages/guest/guest-sync.html +66 -0
- package/docs/pages/guest/index.html +115 -0
- package/docs/pages/guest.html +59 -0
- package/docs/pages/index.html +72 -0
- package/docs/pages/integrations/angular.html +5 -0
- package/docs/pages/integrations/layout.html +17 -0
- package/docs/pages/integrations/react.html +7 -0
- package/docs/pages/integrations/vue.html +102 -0
- package/docs/pages/patron/index.html +140 -0
- package/docs/pages/patron/patron-applied.html +66 -0
- package/docs/pages/patron/patron-executor-applied.html +94 -0
- package/docs/pages/patron/patron-once.html +110 -0
- package/docs/pages/patron/patron-pool.html +99 -0
- package/docs/pages/patron.html +50 -0
- package/docs/pages/philosofy.html +210 -0
- package/docs/pages/source/index.html +167 -0
- package/docs/pages/source/source-active.html +113 -0
- package/docs/pages/source/source-all.html +129 -0
- package/docs/pages/source/source-applied.html +73 -0
- package/docs/pages/source/source-dynamic.html +93 -0
- package/docs/pages/source/source-executor-applied.html +64 -0
- package/docs/pages/source/source-map.html +192 -0
- package/docs/pages/source/source-once.html +73 -0
- package/docs/pages/source/source-race.html +171 -0
- package/docs/pages/source/source-sequence.html +160 -0
- package/docs/pages/source/source-with-pool.html +102 -0
- package/docs/pages/source/source.html +167 -0
- package/docs/pages/source.html +68 -0
- package/docs/pages/terminology/guest.html +14 -0
- package/docs/pages/terminology/index.html +6 -0
- package/docs/pages/terminology/introduction.html +25 -0
- package/docs/pages/terminology/patron.html +10 -0
- package/docs/pages/terminology/source.html +55 -0
- package/docs/pages/terminology/visitor.html +19 -0
- package/docs/pages/terminology.html +53 -0
- package/docs/pages/utils/give.html +47 -0
- package/docs/pages/utils/index.html +24 -0
- package/docs/pages/utils/is-guest-aware.html +22 -0
- package/docs/pages/utils/is-guest.html +21 -0
- package/docs/pages/utils/is-patron-in-pools.html +53 -0
- package/docs/pages/utils/private.html +44 -0
- package/docs/pages/utils/remove-patron-from-pools.html +57 -0
- package/docs/pages/utils/value.html +47 -0
- package/docs/pages/utils.html +61 -0
- package/eslint.config.mjs +6 -0
- package/package.json +1 -1
- package/src/Guest/Guest.test.ts +11 -6
- package/src/Guest/Guest.ts +7 -14
- package/src/Guest/GuestApplied.test.ts +13 -0
- package/src/Guest/GuestApplied.ts +16 -0
- package/src/Guest/GuestCast.test.ts +4 -5
- package/src/Guest/GuestCast.ts +3 -10
- package/src/Guest/GuestDisposable.test.ts +13 -17
- package/src/Guest/GuestDisposable.ts +3 -3
- package/src/Guest/GuestExecutorApplied.test.ts +27 -0
- package/src/Guest/GuestExecutorApplied.ts +23 -0
- package/src/Guest/GuestObject.test.ts +6 -6
- package/src/Guest/GuestObject.ts +3 -3
- package/src/Guest/GuestPool.test.ts +5 -22
- package/src/Guest/GuestPool.ts +7 -8
- package/src/Guest/GuestSync.test.ts +2 -2
- package/src/Patron/Patron.test.ts +4 -5
- package/src/Patron/Patron.ts +11 -3
- package/src/Patron/PatronApplied.ts +22 -0
- package/src/Patron/PatronExecutorApplied.ts +25 -0
- package/src/Patron/PatronOnce.sourceEmpty.test.ts +2 -2
- package/src/Patron/PatronOnce.test.ts +2 -2
- package/src/Patron/PatronOnce.ts +3 -9
- package/src/Patron/PatronPool.test.ts +2 -1
- package/src/Patron/PatronPool.ts +22 -27
- package/src/Private/PrivateClass.modules.test.ts +11 -8
- package/src/Private/PrivateClass.test.ts +7 -6
- package/src/Source/Source.test.ts +9 -5
- package/src/Source/Source.ts +46 -30
- package/src/Source/SourceActive.test.ts +13 -0
- package/src/Source/SourceActive.ts +41 -0
- package/src/Source/SourceAll._asArray.test.ts +22 -0
- package/src/Source/SourceAll._twoValuesAfter.test.ts +19 -0
- package/src/Source/SourceAll._twoValuesBefore.test.ts +19 -0
- package/src/Source/SourceAll._withPatron.test.ts +25 -0
- package/src/{Guest/GuestAwareAll.ts → Source/SourceAll.ts} +11 -11
- package/src/Source/SourceApplied.test.ts +14 -0
- package/src/Source/SourceApplied.ts +23 -0
- package/src/Source/SourceDynamic.ofSource.test.ts +12 -12
- package/src/Source/SourceDynamic.test.ts +9 -9
- package/src/Source/SourceDynamic.ts +7 -7
- package/src/Source/SourceExecutorApplied.test.ts +30 -0
- package/src/Source/SourceExecutorApplied.ts +22 -0
- package/src/Source/SourceMap.defered.test.ts +46 -0
- package/src/Source/SourceMap.fn.test.ts +27 -0
- package/src/Source/SourceMap.test.ts +32 -0
- package/src/Source/SourceMap.ts +48 -0
- package/src/Source/SourceOnce.notcalled.test.ts +4 -4
- package/src/Source/SourceOnce.test.ts +4 -5
- package/src/Source/SourceOnce.ts +7 -13
- package/src/Source/SourceRace.test.ts +46 -0
- package/src/Source/SourceRace.ts +30 -0
- package/src/Source/SourceSequence.defered.test.ts +53 -0
- package/src/Source/SourceSequence.test.ts +30 -0
- package/src/{Guest/GuestAwareSequence.ts → Source/SourceSequence.ts} +14 -19
- package/src/Source/SourceWithPool.empty.test.ts +14 -0
- package/src/Source/SourceWithPool.test.ts +10 -0
- package/src/Source/SourceWithPool.ts +58 -0
- package/src/index.ts +13 -7
- package/test-utils/debounce.ts +11 -0
- package/test-utils/id.ts +1 -0
- package/test-utils/wait.ts +6 -3
- package/src/Guest/GuestAware.test.ts +0 -13
- package/src/Guest/GuestAware.ts +0 -59
- package/src/Guest/GuestAwareActive.test.ts +0 -12
- package/src/Guest/GuestAwareActive.ts +0 -42
- package/src/Guest/GuestAwareAll._asArray.test.ts +0 -19
- package/src/Guest/GuestAwareAll._twoValuesAfter.test.ts +0 -16
- package/src/Guest/GuestAwareAll._twoValuesBefore.test.ts +0 -16
- package/src/Guest/GuestAwareAll._withPatron.test.ts +0 -22
- package/src/Guest/GuestAwareMap.defered.test.ts +0 -46
- package/src/Guest/GuestAwareMap.fn.test.ts +0 -27
- package/src/Guest/GuestAwareMap.test.ts +0 -29
- package/src/Guest/GuestAwareMap.ts +0 -48
- package/src/Guest/GuestAwareRace.test.ts +0 -46
- package/src/Guest/GuestAwareRace.ts +0 -33
- package/src/Guest/GuestAwareSequence.defered.test.ts +0 -58
- package/src/Guest/GuestAwareSequence.test.ts +0 -30
- package/src/Source/SourceEmpty.test.ts +0 -20
- package/src/Source/SourceEmpty.ts +0 -31
@@ -1,4 +1,4 @@
|
|
1
|
-
import { expect, test, vi } from "vitest";
|
1
|
+
import { expect, test, vi, vitest } from "vitest";
|
2
2
|
import { SourceOnce } from "./SourceOnce";
|
3
3
|
|
4
4
|
test("SourceOnce.notcalled.test", () => {
|
@@ -7,7 +7,7 @@ test("SourceOnce.notcalled.test", () => {
|
|
7
7
|
source.value(guestNotCalled);
|
8
8
|
expect(guestNotCalled).not.toHaveBeenCalled();
|
9
9
|
source.give(111);
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
const g = vitest.fn();
|
11
|
+
source.value(g);
|
12
|
+
expect(g).toBeCalledWith(111);
|
13
13
|
});
|
@@ -1,11 +1,10 @@
|
|
1
1
|
import { SourceOnce } from "./SourceOnce";
|
2
|
-
import { expect, test } from "vitest";
|
2
|
+
import { expect, test, vitest } from "vitest";
|
3
3
|
|
4
4
|
test("SourceOnce.test", () => {
|
5
5
|
const source = new SourceOnce(123);
|
6
6
|
source.give(321);
|
7
|
-
|
8
|
-
source.value(
|
9
|
-
|
10
|
-
});
|
7
|
+
const g = vitest.fn();
|
8
|
+
source.value(g);
|
9
|
+
expect(g).toBeCalledWith(123);
|
11
10
|
});
|
package/src/Source/SourceOnce.ts
CHANGED
@@ -1,21 +1,16 @@
|
|
1
|
-
import { PatronPool } from "../Patron/PatronPool";
|
2
1
|
import { GuestType } from "../Guest/Guest";
|
3
|
-
import {
|
4
|
-
import {
|
5
|
-
import {
|
2
|
+
import { PatronPool } from "../Patron/PatronPool";
|
3
|
+
import { value } from "./Source";
|
4
|
+
import { SourceWithPool, SourceWithPoolType } from "./SourceWithPool";
|
6
5
|
|
7
6
|
/**
|
8
7
|
* @url https://kosukhin.github.io/patron.site/#/source/source-once
|
9
8
|
*/
|
10
|
-
export class SourceOnce<T> implements
|
11
|
-
private source
|
12
|
-
private isFilled = false;
|
9
|
+
export class SourceOnce<T> implements SourceWithPoolType<T> {
|
10
|
+
private source: SourceWithPool<T>;
|
13
11
|
|
14
12
|
public constructor(initialValue?: T) {
|
15
|
-
|
16
|
-
this.isFilled = true;
|
17
|
-
this.source.give(initialValue);
|
18
|
-
}
|
13
|
+
this.source = new SourceWithPool(initialValue);
|
19
14
|
}
|
20
15
|
|
21
16
|
public value(guest: GuestType<T>) {
|
@@ -24,8 +19,7 @@ export class SourceOnce<T> implements SourceType<T> {
|
|
24
19
|
}
|
25
20
|
|
26
21
|
public give(value: T): this {
|
27
|
-
if (!this.
|
28
|
-
this.isFilled = true;
|
22
|
+
if (!this.source.filled()) {
|
29
23
|
this.source.give(value);
|
30
24
|
}
|
31
25
|
return this;
|
@@ -0,0 +1,46 @@
|
|
1
|
+
import { SourceWithPool } from "../Source/SourceWithPool";
|
2
|
+
import { SourceRace } from "./SourceRace";
|
3
|
+
import { afterEach, beforeEach, expect, test, vi, vitest } from "vitest";
|
4
|
+
|
5
|
+
beforeEach(() => {
|
6
|
+
vi.useFakeTimers();
|
7
|
+
});
|
8
|
+
|
9
|
+
afterEach(() => {
|
10
|
+
vi.useRealTimers();
|
11
|
+
});
|
12
|
+
|
13
|
+
test("SourceRace.test", async () => {
|
14
|
+
const sBuild = (result: number, delay: number) => {
|
15
|
+
const s = new SourceWithPool();
|
16
|
+
|
17
|
+
setTimeout(() => {
|
18
|
+
s.give(result);
|
19
|
+
}, delay);
|
20
|
+
|
21
|
+
return s;
|
22
|
+
};
|
23
|
+
|
24
|
+
const s2 = sBuild(2, 100);
|
25
|
+
const s1 = sBuild(1, 200);
|
26
|
+
|
27
|
+
const sAny = new SourceRace([s1, s2]);
|
28
|
+
|
29
|
+
await vi.advanceTimersByTime(201);
|
30
|
+
|
31
|
+
const g1 = vitest.fn();
|
32
|
+
sAny.value(g1);
|
33
|
+
expect(g1).toBeCalledWith(1);
|
34
|
+
|
35
|
+
setTimeout(() => {
|
36
|
+
s1.give(3);
|
37
|
+
s2.give(4);
|
38
|
+
}, 300);
|
39
|
+
|
40
|
+
await vi.advanceTimersByTime(301);
|
41
|
+
|
42
|
+
const g2 = vitest.fn();
|
43
|
+
sAny.value(g2);
|
44
|
+
// ignores second value
|
45
|
+
expect(g2).toBeCalledWith(3);
|
46
|
+
});
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import { give, GuestType } from "../Guest/Guest";
|
2
|
+
import { SourceObjectType, SourceType, value } from "./Source";
|
3
|
+
import { GuestCast } from "../Guest/GuestCast";
|
4
|
+
|
5
|
+
/**
|
6
|
+
* @url https://kosukhin.github.io/patron.site/#/guest/source-race
|
7
|
+
*/
|
8
|
+
export class SourceRace<T> implements SourceObjectType<T> {
|
9
|
+
public constructor(private sources: SourceType<T>[]) {
|
10
|
+
if (sources === undefined) {
|
11
|
+
throw new Error("SourceRace didnt receive sources argument");
|
12
|
+
}
|
13
|
+
}
|
14
|
+
|
15
|
+
public value(guest: GuestType<T>): this {
|
16
|
+
let connectedWithSource: SourceType | null = null;
|
17
|
+
this.sources.forEach((source) => {
|
18
|
+
value(
|
19
|
+
source,
|
20
|
+
new GuestCast(<GuestType>guest, (value) => {
|
21
|
+
if (!connectedWithSource || connectedWithSource === source) {
|
22
|
+
give(value as T, guest);
|
23
|
+
connectedWithSource = source;
|
24
|
+
}
|
25
|
+
}),
|
26
|
+
);
|
27
|
+
});
|
28
|
+
return this;
|
29
|
+
}
|
30
|
+
}
|
@@ -0,0 +1,53 @@
|
|
1
|
+
import { SourceSequence } from "./SourceSequence";
|
2
|
+
import { give } from "../Guest/Guest";
|
3
|
+
import { Source, SourceObjectType, SourceType, value } from "./Source";
|
4
|
+
import { GuestCast } from "../Guest/GuestCast";
|
5
|
+
import { GuestType } from "../Guest/Guest";
|
6
|
+
import { afterEach, beforeEach, expect, test, vi } from "vitest";
|
7
|
+
import { SourceWithPool } from "./SourceWithPool";
|
8
|
+
import { PrivateClass } from "../Private/PrivateClass";
|
9
|
+
import { wait } from "../../test-utils/wait";
|
10
|
+
|
11
|
+
beforeEach(() => {
|
12
|
+
vi.useFakeTimers({ shouldAdvanceTime: true });
|
13
|
+
});
|
14
|
+
|
15
|
+
afterEach(() => {
|
16
|
+
vi.runOnlyPendingTimers();
|
17
|
+
vi.useRealTimers();
|
18
|
+
});
|
19
|
+
|
20
|
+
class X2 implements SourceObjectType<number> {
|
21
|
+
public constructor(private baseNumber: SourceType<number>) {}
|
22
|
+
|
23
|
+
public value(guest: GuestType<number>) {
|
24
|
+
value(
|
25
|
+
this.baseNumber,
|
26
|
+
new GuestCast(<GuestType>guest, (v) => {
|
27
|
+
give(v * 2, guest);
|
28
|
+
}),
|
29
|
+
);
|
30
|
+
return this;
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
test("SourceSequence.defered.test", async () => {
|
35
|
+
const sourceOf = (val: number) =>
|
36
|
+
new Source((guest) => {
|
37
|
+
setTimeout(() => {
|
38
|
+
give(val, guest);
|
39
|
+
}, 10);
|
40
|
+
});
|
41
|
+
const source = new SourceWithPool([1, 2, 3, 9].map(sourceOf));
|
42
|
+
|
43
|
+
const sequence = new SourceSequence(source, new PrivateClass(X2));
|
44
|
+
|
45
|
+
const callFn = vi.fn();
|
46
|
+
sequence.value((v) => {
|
47
|
+
callFn(v.join());
|
48
|
+
});
|
49
|
+
|
50
|
+
await wait(51);
|
51
|
+
expect(callFn).toBeCalled();
|
52
|
+
expect(callFn).toBeCalledWith("2,4,6,18");
|
53
|
+
});
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import { SourceSequence } from "./SourceSequence";
|
2
|
+
import { give } from "../Guest/Guest";
|
3
|
+
import { SourceObjectType, SourceType, value } from "./Source";
|
4
|
+
import { GuestCast } from "../Guest/GuestCast";
|
5
|
+
import { GuestType } from "../Guest/Guest";
|
6
|
+
import { expect, test, vitest } from "vitest";
|
7
|
+
import { SourceWithPool } from "./SourceWithPool";
|
8
|
+
import { PrivateClass } from "../Private/PrivateClass";
|
9
|
+
|
10
|
+
class X2 implements SourceObjectType<number> {
|
11
|
+
public constructor(private baseNumber: SourceType<number>) {}
|
12
|
+
|
13
|
+
public value(guest: GuestType<number>) {
|
14
|
+
value(
|
15
|
+
this.baseNumber,
|
16
|
+
new GuestCast(<GuestType>guest, (v) => {
|
17
|
+
give(v * 2, guest);
|
18
|
+
}),
|
19
|
+
);
|
20
|
+
return this;
|
21
|
+
}
|
22
|
+
}
|
23
|
+
|
24
|
+
test("SourceSequence.test", () => {
|
25
|
+
const source = new SourceWithPool([1, 2, 3, 9]);
|
26
|
+
const guestMapped = new SourceSequence(source, new PrivateClass(X2));
|
27
|
+
const g = vitest.fn();
|
28
|
+
guestMapped.value(g);
|
29
|
+
expect(g).toBeCalledWith([2, 4, 6, 18]);
|
30
|
+
});
|
@@ -1,35 +1,30 @@
|
|
1
|
+
import { SourceWithPool } from "../Source/SourceWithPool";
|
2
|
+
import { give, GuestType } from "../Guest/Guest";
|
3
|
+
import { GuestCast } from "../Guest/GuestCast";
|
1
4
|
import { PatronOnce } from "../Patron/PatronOnce";
|
2
5
|
import { PrivateType } from "../Private/Private";
|
3
|
-
import {
|
4
|
-
import {
|
5
|
-
import {
|
6
|
-
GuestAwareObjectType,
|
7
|
-
GuestAwareType,
|
8
|
-
isGuestAware,
|
9
|
-
value,
|
10
|
-
} from "./GuestAware";
|
11
|
-
import { GuestAwareAll } from "./GuestAwareAll";
|
12
|
-
import { GuestCast } from "./GuestCast";
|
6
|
+
import { isSource, SourceObjectType, SourceType, value } from "./Source";
|
7
|
+
import { SourceAll } from "./SourceAll";
|
13
8
|
|
14
9
|
/**
|
15
|
-
* @url https://kosukhin.github.io/patron.site/#/guest/
|
10
|
+
* @url https://kosukhin.github.io/patron.site/#/guest/source-sequence
|
16
11
|
*/
|
17
|
-
export class
|
12
|
+
export class SourceSequence<T, TG> implements SourceObjectType<TG[]> {
|
18
13
|
public constructor(
|
19
|
-
private baseSource:
|
20
|
-
private targetSource: PrivateType<
|
14
|
+
private baseSource: SourceType<T[]>,
|
15
|
+
private targetSource: PrivateType<SourceType<TG>>,
|
21
16
|
) {
|
22
17
|
if (baseSource === undefined) {
|
23
|
-
throw new Error("
|
18
|
+
throw new Error("SourceSequence didnt receive baseSource argument");
|
24
19
|
}
|
25
20
|
if (targetSource === undefined) {
|
26
|
-
throw new Error("
|
21
|
+
throw new Error("SourceSequence didnt receive targetSource argument");
|
27
22
|
}
|
28
23
|
}
|
29
24
|
|
30
25
|
public value(guest: GuestType<TG[]>) {
|
31
|
-
const all = new
|
32
|
-
const sequenceSource = new
|
26
|
+
const all = new SourceAll<TG[]>();
|
27
|
+
const sequenceSource = new SourceWithPool();
|
33
28
|
const targetSource = this.targetSource.get(sequenceSource);
|
34
29
|
|
35
30
|
value(
|
@@ -49,7 +44,7 @@ export class GuestAwareSequence<T, TG> implements GuestAwareObjectType<TG[]> {
|
|
49
44
|
function handle() {
|
50
45
|
sequenceSource.give(null);
|
51
46
|
const nextValue = theValue[index];
|
52
|
-
if (
|
47
|
+
if (isSource(nextValue)) {
|
53
48
|
value(
|
54
49
|
nextValue,
|
55
50
|
new PatronOnce((theNextValue) => {
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { expect, test, vitest } from "vitest";
|
2
|
+
import { SourceWithPool } from "./SourceWithPool";
|
3
|
+
import { Patron } from "../Patron/Patron";
|
4
|
+
|
5
|
+
test("SourceChangeable.test", () => {
|
6
|
+
const source = new SourceWithPool();
|
7
|
+
const guest = vitest.fn();
|
8
|
+
|
9
|
+
source.value(new Patron(guest));
|
10
|
+
source.give(42);
|
11
|
+
|
12
|
+
expect(guest).toBeCalled();
|
13
|
+
expect(guest).toBeCalledWith(42);
|
14
|
+
});
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { expect, test, vitest } from "vitest";
|
2
|
+
import { SourceWithPool } from "./SourceWithPool";
|
3
|
+
|
4
|
+
test("SourceChangeable.test", () => {
|
5
|
+
const source = new SourceWithPool(42);
|
6
|
+
|
7
|
+
const g = vitest.fn();
|
8
|
+
source.value(g);
|
9
|
+
expect(g).toBeCalledWith(42);
|
10
|
+
});
|
@@ -0,0 +1,58 @@
|
|
1
|
+
import { Guest, GuestObjectType, GuestType } from "../Guest/Guest";
|
2
|
+
import { SourceObjectType } from "./Source";
|
3
|
+
import { PatronPool } from "../Patron/PatronPool";
|
4
|
+
import { isPatron } from "../Patron/Patron";
|
5
|
+
|
6
|
+
export interface PoolAwareType<T = any> {
|
7
|
+
pool(): PatronPool<T>;
|
8
|
+
}
|
9
|
+
|
10
|
+
/**
|
11
|
+
* @url https://kosukhin.github.io/patron.site/#/source-with-pool
|
12
|
+
*/
|
13
|
+
export type SourceWithPoolType<T = any> = SourceObjectType<T> &
|
14
|
+
GuestObjectType<T> &
|
15
|
+
PoolAwareType<T>;
|
16
|
+
|
17
|
+
export class SourceWithPool<T> implements SourceWithPoolType<T> {
|
18
|
+
private thePool = new PatronPool(this);
|
19
|
+
private theEmptyPool = new PatronPool(this);
|
20
|
+
private isEmpty: boolean;
|
21
|
+
|
22
|
+
public constructor(private sourceDocument?: T) {
|
23
|
+
this.isEmpty = sourceDocument === undefined;
|
24
|
+
}
|
25
|
+
|
26
|
+
public pool() {
|
27
|
+
return this.thePool;
|
28
|
+
}
|
29
|
+
|
30
|
+
public give(value: T): this {
|
31
|
+
this.isEmpty = false;
|
32
|
+
this.sourceDocument = value;
|
33
|
+
this.thePool.give(this.sourceDocument);
|
34
|
+
this.theEmptyPool.give(this.sourceDocument);
|
35
|
+
return this;
|
36
|
+
}
|
37
|
+
|
38
|
+
public value(guest: GuestType<T>): this {
|
39
|
+
if (this.isEmpty) {
|
40
|
+
if (isPatron(guest)) {
|
41
|
+
this.theEmptyPool.add(guest);
|
42
|
+
}
|
43
|
+
return this;
|
44
|
+
}
|
45
|
+
|
46
|
+
if (typeof guest === "function") {
|
47
|
+
this.thePool.distribute(this.sourceDocument, new Guest(guest));
|
48
|
+
} else {
|
49
|
+
this.thePool.distribute(this.sourceDocument, guest);
|
50
|
+
}
|
51
|
+
|
52
|
+
return this;
|
53
|
+
}
|
54
|
+
|
55
|
+
public filled() {
|
56
|
+
return !this.isEmpty;
|
57
|
+
}
|
58
|
+
}
|
package/src/index.ts
CHANGED
@@ -1,20 +1,26 @@
|
|
1
|
-
export * from "./Guest/GuestAware";
|
2
|
-
export * from "./Guest/GuestAwareSequence";
|
3
|
-
export * from "./Guest/GuestAwareMap";
|
4
|
-
export * from "./Guest/GuestAwareRace";
|
5
|
-
export * from "./Guest/GuestAwareActive";
|
6
1
|
export * from "./Guest/Guest";
|
7
2
|
export * from "./Guest/GuestCast";
|
8
|
-
export * from "./Guest/GuestAwareAll";
|
9
3
|
export * from "./Guest/GuestPool";
|
10
4
|
export * from "./Guest/GuestSync";
|
11
5
|
export * from "./Guest/GuestObject";
|
12
6
|
export * from "./Guest/GuestDisposable";
|
7
|
+
export * from "./Guest/GuestApplied";
|
8
|
+
export * from "./Guest/GuestExecutorApplied";
|
13
9
|
export * from "./Patron/Patron";
|
14
10
|
export * from "./Patron/PatronOnce";
|
15
11
|
export * from "./Patron/PatronPool";
|
12
|
+
export * from "./Patron/PatronApplied";
|
13
|
+
export * from "./Patron/PatronExecutorApplied";
|
14
|
+
export * from "./Source/SourceAll";
|
16
15
|
export * from "./Source/Source";
|
16
|
+
export * from "./Source/SourceSequence";
|
17
|
+
export * from "./Source/SourceMap";
|
18
|
+
export * from "./Source/SourceRace";
|
19
|
+
export * from "./Source/SourceActive";
|
20
|
+
export * from "./Source/SourceWithPool";
|
17
21
|
export * from "./Source/SourceDynamic";
|
18
|
-
export * from "./Source/
|
22
|
+
export * from "./Source/SourceApplied";
|
23
|
+
export * from "./Source/SourceExecutorApplied";
|
24
|
+
export * from "./Source/SourceOnce";
|
19
25
|
export * from "./Private/PrivateClass";
|
20
26
|
export * from "./Private/Private";
|
package/test-utils/id.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export const id = (v: unknown) => v;
|
package/test-utils/wait.ts
CHANGED
@@ -1,13 +0,0 @@
|
|
1
|
-
import { expect, test } from "vitest";
|
2
|
-
import { GuestAware } from "./GuestAware";
|
3
|
-
import { give } from "./Guest";
|
4
|
-
|
5
|
-
test("GuestAware.test", () => {
|
6
|
-
const aware = new GuestAware((guest) => {
|
7
|
-
give(111, guest);
|
8
|
-
});
|
9
|
-
|
10
|
-
aware.value((value) => {
|
11
|
-
expect(value).toBe(111);
|
12
|
-
});
|
13
|
-
});
|
package/src/Guest/GuestAware.ts
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
import { GuestType } from "./Guest";
|
2
|
-
|
3
|
-
export type GuestAwareExecutorType<T> = (guest: GuestType<T>) => unknown;
|
4
|
-
|
5
|
-
export interface GuestAwareObjectType<T> {
|
6
|
-
value: GuestAwareExecutorType<T>;
|
7
|
-
}
|
8
|
-
|
9
|
-
export type GuestAwareType<T = any> =
|
10
|
-
| GuestAwareExecutorType<T>
|
11
|
-
| GuestAwareObjectType<T>;
|
12
|
-
|
13
|
-
/**
|
14
|
-
* @url https://kosukhin.github.io/patron.site/#/utils/give
|
15
|
-
*/
|
16
|
-
export function value<T>(guestAware: GuestAwareType<T>, guest: GuestType<T>) {
|
17
|
-
if (guestAware === undefined) {
|
18
|
-
throw new Error("value didnt receive guestAware argument");
|
19
|
-
}
|
20
|
-
if (guest === undefined) {
|
21
|
-
throw new Error("value didnt receive guest argument");
|
22
|
-
}
|
23
|
-
if (typeof guestAware === "function") {
|
24
|
-
return guestAware(guest);
|
25
|
-
} else {
|
26
|
-
return guestAware.value(guest);
|
27
|
-
}
|
28
|
-
}
|
29
|
-
|
30
|
-
/**
|
31
|
-
* @url https://kosukhin.github.io/patron.site/#/utils/is-guest-aware
|
32
|
-
*/
|
33
|
-
export function isGuestAware(
|
34
|
-
mbGuestAware: any,
|
35
|
-
): mbGuestAware is GuestAwareType {
|
36
|
-
if (mbGuestAware === undefined) {
|
37
|
-
throw new Error("isGuestAware didnt receive mbGuestAware argument");
|
38
|
-
}
|
39
|
-
return (
|
40
|
-
typeof mbGuestAware === "function" ||
|
41
|
-
typeof mbGuestAware?.value === "function"
|
42
|
-
);
|
43
|
-
}
|
44
|
-
|
45
|
-
/**
|
46
|
-
* @url https://kosukhin.github.io/patron.site/#/guest/guest-aware
|
47
|
-
*/
|
48
|
-
export class GuestAware<T = any> implements GuestAwareObjectType<T> {
|
49
|
-
public constructor(private guestAware: GuestAwareType<T>) {
|
50
|
-
if (guestAware === undefined) {
|
51
|
-
throw new Error("GuestAware constructor didnt receive executor function");
|
52
|
-
}
|
53
|
-
}
|
54
|
-
|
55
|
-
public value(guest: GuestType<T>): GuestType<T> {
|
56
|
-
value(this.guestAware, guest);
|
57
|
-
return guest;
|
58
|
-
}
|
59
|
-
}
|
@@ -1,12 +0,0 @@
|
|
1
|
-
import { GuestAwareActive } from "./GuestAwareActive";
|
2
|
-
import { expect, test } from "vitest";
|
3
|
-
|
4
|
-
test("GuestAwareActive.test", () => {
|
5
|
-
const active = new GuestAwareActive<number, number>((config, source) => {
|
6
|
-
source.give(config * 3);
|
7
|
-
});
|
8
|
-
|
9
|
-
active.do(4).value((v) => {
|
10
|
-
expect(v).toBe(12);
|
11
|
-
});
|
12
|
-
});
|
@@ -1,42 +0,0 @@
|
|
1
|
-
import { SourceType } from "../Source/Source";
|
2
|
-
import { SourceEmpty } from "../Source/SourceEmpty";
|
3
|
-
import { GuestType } from "./Guest";
|
4
|
-
import { GuestAwareObjectType } from "./GuestAware";
|
5
|
-
|
6
|
-
/**
|
7
|
-
* @url https://kosukhin.github.io/patron.site/#/utils/action-type
|
8
|
-
*/
|
9
|
-
export interface ActionType<P = any> {
|
10
|
-
do(config: P): this;
|
11
|
-
}
|
12
|
-
|
13
|
-
export interface GuestAwareAcitveType<R = unknown, T = unknown>
|
14
|
-
extends GuestAwareObjectType<T>,
|
15
|
-
ActionType<R> {}
|
16
|
-
|
17
|
-
/**
|
18
|
-
* @url https://kosukhin.github.io/patron.site/#/guest/guest-aware-active
|
19
|
-
*/
|
20
|
-
export class GuestAwareActive<R, T> implements GuestAwareAcitveType<R, T> {
|
21
|
-
private source = new SourceEmpty<T>();
|
22
|
-
|
23
|
-
public constructor(
|
24
|
-
private configExecutor: (config: R, source: SourceType<T>) => void,
|
25
|
-
) {
|
26
|
-
if (configExecutor === undefined) {
|
27
|
-
throw new Error(
|
28
|
-
"GuestAwareActive constructor didnt receive executor function",
|
29
|
-
);
|
30
|
-
}
|
31
|
-
}
|
32
|
-
|
33
|
-
public do(config: R): this {
|
34
|
-
this.configExecutor(config, this.source);
|
35
|
-
return this;
|
36
|
-
}
|
37
|
-
|
38
|
-
public value(guest: GuestType<T>): this {
|
39
|
-
this.source.value(guest);
|
40
|
-
return this;
|
41
|
-
}
|
42
|
-
}
|
@@ -1,19 +0,0 @@
|
|
1
|
-
import { expect, test } from "vitest";
|
2
|
-
import { GuestAwareAll } from "./GuestAwareAll";
|
3
|
-
import { Source } from "../Source/Source";
|
4
|
-
import { Patron } from "../Patron/Patron";
|
5
|
-
|
6
|
-
test("GuestAwareAll._asArray.test", () => {
|
7
|
-
const one = new Source(1);
|
8
|
-
const two = new Source(2);
|
9
|
-
const all = new GuestAwareAll<[number, number]>();
|
10
|
-
|
11
|
-
one.value(new Patron(all.guestKey("0")));
|
12
|
-
two.value(new Patron(all.guestKey("1")));
|
13
|
-
|
14
|
-
all.valueArray(
|
15
|
-
new Patron((value) => {
|
16
|
-
expect(JSON.stringify(value)).toBe("[1,2]");
|
17
|
-
}),
|
18
|
-
);
|
19
|
-
});
|
@@ -1,16 +0,0 @@
|
|
1
|
-
import { expect, test } from "vitest";
|
2
|
-
import { Source } from "../Source/Source";
|
3
|
-
import { GuestAwareAll } from "./GuestAwareAll";
|
4
|
-
|
5
|
-
test("GuestAwareAll._twoValuesAfter.test", () => {
|
6
|
-
const one = new Source(1);
|
7
|
-
const two = new Source(2);
|
8
|
-
const all = new GuestAwareAll<{ one: number; two: number }>(["one", "two"]);
|
9
|
-
|
10
|
-
all.value((value) => {
|
11
|
-
expect(Object.values(value).join()).toBe("1,2");
|
12
|
-
});
|
13
|
-
|
14
|
-
one.value(all.guestKey("one"));
|
15
|
-
two.value(all.guestKey("two"));
|
16
|
-
});
|
@@ -1,16 +0,0 @@
|
|
1
|
-
import { expect, test } from "vitest";
|
2
|
-
import { Source } from "../Source/Source";
|
3
|
-
import { GuestAwareAll } from "./GuestAwareAll";
|
4
|
-
|
5
|
-
test("GuestAwareAll._twoValuesBefore.test", () => {
|
6
|
-
const one = new Source(1);
|
7
|
-
const two = new Source(2);
|
8
|
-
const all = new GuestAwareAll<{ one: number; two: number }>();
|
9
|
-
|
10
|
-
one.value(all.guestKey("one"));
|
11
|
-
two.value(all.guestKey("two"));
|
12
|
-
|
13
|
-
all.value((value) => {
|
14
|
-
expect(Object.values(value).join()).toBe("1,2");
|
15
|
-
});
|
16
|
-
});
|
@@ -1,22 +0,0 @@
|
|
1
|
-
import { expect, test } from "vitest";
|
2
|
-
import { GuestAwareAll } from "./GuestAwareAll";
|
3
|
-
import { Source } from "../Source/Source";
|
4
|
-
import { Patron } from "../Patron/Patron";
|
5
|
-
|
6
|
-
test("GuestAwareAll._withPatron.test", () => {
|
7
|
-
const one = new Source(1);
|
8
|
-
const two = new Source(2);
|
9
|
-
const all = new GuestAwareAll<{ one: number; two: number }>();
|
10
|
-
|
11
|
-
one.value(new Patron(all.guestKey("one")));
|
12
|
-
two.value(new Patron(all.guestKey("two")));
|
13
|
-
|
14
|
-
one.give(3);
|
15
|
-
one.give(4);
|
16
|
-
|
17
|
-
all.value(
|
18
|
-
new Patron((value: Record<string, unknown>) => {
|
19
|
-
expect(Object.values(value).length).toBe(2);
|
20
|
-
}),
|
21
|
-
);
|
22
|
-
});
|