patron-oop 1.31.0 → 1.32.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 +8 -0
- package/dist/patron.cjs +40 -0
- package/dist/patron.cjs.map +1 -1
- package/dist/patron.d.ts +22 -1
- package/dist/patron.js +39 -1
- 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 +39 -1
- package/dist/patron.mjs.map +1 -1
- package/package.json +1 -1
- package/src/Guest/Guest.test.ts +1 -1
- package/src/Guest/GuestAware.test.ts +1 -1
- package/src/Guest/GuestAwareRace.test.ts +47 -0
- package/src/Guest/GuestAwareRace.ts +26 -0
- package/src/Guest/GuestCast.test.ts +1 -1
- package/src/Guest/GuestChain._asArray.test.ts +19 -0
- package/src/Guest/GuestChain._twoValuesAfter.test.ts +16 -0
- package/src/Guest/GuestChain._twoValuesBefore.test.ts +16 -0
- package/src/Guest/GuestChain._withPatron.test.ts +22 -0
- package/src/Guest/GuestDisposable.test.ts +1 -1
- package/src/Guest/GuestObject.test.ts +1 -1
- package/src/Guest/GuestPool.test.ts +1 -1
- package/src/Guest/GuestSync.test.ts +1 -1
- package/src/Patron/Patron.test.ts +1 -1
- package/src/Patron/PatronOnce.test.ts +1 -1
- package/src/Patron/PatronPool.test.ts +1 -1
- package/src/Source/Source.test.ts +1 -1
- package/src/Source/SourceDynamic.ofSource.test.ts +21 -0
- package/src/Source/SourceDynamic.test.ts +26 -0
- package/src/Source/SourceDynamic.ts +28 -0
- package/src/Source/SourceEmpty.test.ts +1 -1
- package/src/index.ts +2 -0
- package/src/Guest/GuestChain.test.ts +0 -63
@@ -0,0 +1,22 @@
|
|
1
|
+
import { expect, test } from "vitest";
|
2
|
+
import { GuestChain } from "./GuestChain";
|
3
|
+
import { Source } from "../Source/Source";
|
4
|
+
import { Patron } from "../Patron/Patron";
|
5
|
+
|
6
|
+
test("GuestChain._withPatron.test", () => {
|
7
|
+
const one = new Source(1);
|
8
|
+
const two = new Source(2);
|
9
|
+
const chain = new GuestChain<{ one: number; two: number }>();
|
10
|
+
|
11
|
+
one.value(new Patron(chain.receiveKey("one")));
|
12
|
+
two.value(new Patron(chain.receiveKey("two")));
|
13
|
+
|
14
|
+
one.give(3);
|
15
|
+
one.give(4);
|
16
|
+
|
17
|
+
chain.result(
|
18
|
+
new Patron((value: Record<string, unknown>) => {
|
19
|
+
expect(Object.values(value).length).toBe(2);
|
20
|
+
}),
|
21
|
+
);
|
22
|
+
});
|
@@ -3,7 +3,7 @@ import { Patron } from "../Patron/Patron";
|
|
3
3
|
import { Source } from "../Source/Source";
|
4
4
|
import { expect, test } from "vitest";
|
5
5
|
|
6
|
-
test("
|
6
|
+
test("GuestDisposable.test", () => {
|
7
7
|
const source = new Source(1);
|
8
8
|
|
9
9
|
// Работает проверка один раз, потом патром себя удаляет
|
@@ -2,7 +2,7 @@ import { expect, test } from "vitest";
|
|
2
2
|
import { Source } from "../Source/Source";
|
3
3
|
import { GuestObject } from "./GuestObject";
|
4
4
|
|
5
|
-
test("
|
5
|
+
test("GuestObject.test", () => {
|
6
6
|
const source = new Source(1);
|
7
7
|
const fnGuest = (value: number) => {
|
8
8
|
expect(value).toBe(1);
|
@@ -2,7 +2,7 @@ import { expect, test } from "vitest";
|
|
2
2
|
import { GuestPool } from "./GuestPool";
|
3
3
|
import { Patron } from "../Patron/Patron";
|
4
4
|
|
5
|
-
test("
|
5
|
+
test("GuestPool.test", () => {
|
6
6
|
const pool = new GuestPool<number>(null);
|
7
7
|
let receivedCount = 0;
|
8
8
|
|
@@ -2,7 +2,7 @@ import { expect, test } from "vitest";
|
|
2
2
|
import { GuestSync } from "./GuestSync";
|
3
3
|
import { Source } from "../Source/Source";
|
4
4
|
|
5
|
-
test("
|
5
|
+
test("GuestSync.test", () => {
|
6
6
|
const source = new Source(123);
|
7
7
|
const syncGuest = new GuestSync(111);
|
8
8
|
syncGuest.give(222);
|
@@ -2,7 +2,7 @@ import { expect, test } from "vitest";
|
|
2
2
|
import { Patron } from "./Patron";
|
3
3
|
import { Source } from "../Source/Source";
|
4
4
|
|
5
|
-
test("
|
5
|
+
test("Patron.test", () => {
|
6
6
|
const one = new Source(1);
|
7
7
|
let patronCalledTimes = 0;
|
8
8
|
const patron = new Patron(() => {
|
@@ -2,7 +2,7 @@ import { expect, test } from "vitest";
|
|
2
2
|
import { PatronOnce } from "./PatronOnce";
|
3
3
|
import { Source } from "../Source/Source";
|
4
4
|
|
5
|
-
test("
|
5
|
+
test("PatronOnce.test", () => {
|
6
6
|
const source = new Source(42);
|
7
7
|
let calls = 0;
|
8
8
|
const patron = new PatronOnce(() => {
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import { SourceDynamic } from './SourceDynamic';
|
2
|
+
import { Source } from './Source';
|
3
|
+
import { expect, test } from 'vitest';
|
4
|
+
|
5
|
+
test('SourceDynamic.ofSource.test', () => {
|
6
|
+
const source = new Source(1);
|
7
|
+
const sourceDynamic = new SourceDynamic(source, source);
|
8
|
+
|
9
|
+
sourceDynamic.value((value) => {
|
10
|
+
expect(value).toBe(1);
|
11
|
+
});
|
12
|
+
|
13
|
+
sourceDynamic.give(2);
|
14
|
+
|
15
|
+
sourceDynamic.value((value) => {
|
16
|
+
expect(value).toBe(2);
|
17
|
+
});
|
18
|
+
source.value((value) => {
|
19
|
+
expect(value).toBe(2);
|
20
|
+
});
|
21
|
+
});
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { SourceDynamic } from "./SourceDynamic";
|
2
|
+
import { expect, test } from 'vitest';
|
3
|
+
import { give, Guest } from "../Guest/Guest";
|
4
|
+
import { GuestAware } from "../Guest/GuestAware";
|
5
|
+
|
6
|
+
test('SourceDynamic', () => {
|
7
|
+
let theValue = 1;
|
8
|
+
const sourceDynamic = new SourceDynamic(
|
9
|
+
new Guest((value: number) => {
|
10
|
+
theValue = value;
|
11
|
+
}),
|
12
|
+
new GuestAware((guest) => {
|
13
|
+
give(theValue, guest);
|
14
|
+
}),
|
15
|
+
);
|
16
|
+
|
17
|
+
sourceDynamic.value((value) => {
|
18
|
+
expect(value).toBe(1);
|
19
|
+
});
|
20
|
+
|
21
|
+
sourceDynamic.give(2);
|
22
|
+
|
23
|
+
sourceDynamic.value((value) => {
|
24
|
+
expect(value).toBe(2);
|
25
|
+
});
|
26
|
+
});
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import { give, GuestType } from "../Guest/Guest";
|
2
|
+
import { GuestAwareType } from "../Guest/GuestAware";
|
3
|
+
import { PatronPool } from "../Patron/PatronPool";
|
4
|
+
import { SourceType } from "./Source";
|
5
|
+
|
6
|
+
/**
|
7
|
+
* @url https://kosukhin.github.io/patron.site/#/source-dynamic
|
8
|
+
*/
|
9
|
+
export class SourceDynamic<T = unknown> implements SourceType<T> {
|
10
|
+
public constructor(
|
11
|
+
private baseGuest: GuestType<T>,
|
12
|
+
private baseGuestAware: GuestAwareType<T>,
|
13
|
+
) { }
|
14
|
+
|
15
|
+
public value(guest: GuestType<T>) {
|
16
|
+
this.baseGuestAware.value(guest);
|
17
|
+
return this;
|
18
|
+
}
|
19
|
+
|
20
|
+
public give(value: T) {
|
21
|
+
give(value, this.baseGuest);
|
22
|
+
return this;
|
23
|
+
}
|
24
|
+
|
25
|
+
public pool(): PatronPool<T> {
|
26
|
+
throw Error('No pool in SourceDynamic');
|
27
|
+
}
|
28
|
+
}
|
package/src/index.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
export * from "./Guest/GuestAware";
|
2
2
|
export * from "./Guest/GuestAwareSequence";
|
3
3
|
export * from "./Guest/GuestAwareMap";
|
4
|
+
export * from "./Guest/GuestAwareRace";
|
4
5
|
export * from "./Guest/Guest";
|
5
6
|
export * from "./Guest/GuestCast";
|
6
7
|
export * from "./Guest/GuestChain";
|
@@ -12,6 +13,7 @@ export * from "./Patron/Patron";
|
|
12
13
|
export * from "./Patron/PatronOnce";
|
13
14
|
export * from "./Patron/PatronPool";
|
14
15
|
export * from "./Source/Source";
|
16
|
+
export * from "./Source/SourceDynamic";
|
15
17
|
export * from "./Source/SourceEmpty";
|
16
18
|
export * from "./Factory/Factory";
|
17
19
|
export * from "./Factory/Module";
|
@@ -1,63 +0,0 @@
|
|
1
|
-
import { expect, test } from "vitest";
|
2
|
-
import { GuestChain } from "./GuestChain";
|
3
|
-
import { Source } from "../Source/Source";
|
4
|
-
import { Patron } from "../Patron/Patron";
|
5
|
-
|
6
|
-
test("chain guest returns 2 values after result guest", () => {
|
7
|
-
const one = new Source(1);
|
8
|
-
const two = new Source(2);
|
9
|
-
const chain = new GuestChain<{ one: number; two: number }>();
|
10
|
-
|
11
|
-
chain.result((value) => {
|
12
|
-
expect(Object.values(value).join()).toBe("1,2");
|
13
|
-
});
|
14
|
-
|
15
|
-
one.value(chain.receiveKey("one"));
|
16
|
-
two.value(chain.receiveKey("two"));
|
17
|
-
});
|
18
|
-
|
19
|
-
test("chain guest returns 2 values before result guest", () => {
|
20
|
-
const one = new Source(1);
|
21
|
-
const two = new Source(2);
|
22
|
-
const chain = new GuestChain<{ one: number; two: number }>();
|
23
|
-
|
24
|
-
one.value(chain.receiveKey("one"));
|
25
|
-
two.value(chain.receiveKey("two"));
|
26
|
-
|
27
|
-
chain.result((value) => {
|
28
|
-
expect(Object.values(value).join()).toBe("1,2");
|
29
|
-
});
|
30
|
-
});
|
31
|
-
|
32
|
-
test("chain with patron", () => {
|
33
|
-
const one = new Source(1);
|
34
|
-
const two = new Source(2);
|
35
|
-
const chain = new GuestChain<{ one: number; two: number }>();
|
36
|
-
|
37
|
-
one.value(new Patron(chain.receiveKey("one")));
|
38
|
-
two.value(new Patron(chain.receiveKey("two")));
|
39
|
-
|
40
|
-
one.give(3);
|
41
|
-
one.give(4);
|
42
|
-
|
43
|
-
chain.result(
|
44
|
-
new Patron((value: Record<string, unknown>) => {
|
45
|
-
expect(Object.values(value).length).toBe(2);
|
46
|
-
}),
|
47
|
-
);
|
48
|
-
});
|
49
|
-
|
50
|
-
test("chain as array", () => {
|
51
|
-
const one = new Source(1);
|
52
|
-
const two = new Source(2);
|
53
|
-
const chain = new GuestChain<[number, number]>();
|
54
|
-
|
55
|
-
one.value(new Patron(chain.receiveKey("0")));
|
56
|
-
two.value(new Patron(chain.receiveKey("1")));
|
57
|
-
|
58
|
-
chain.resultArray(
|
59
|
-
new Patron((value) => {
|
60
|
-
expect(JSON.stringify(value)).toBe("[1,2]");
|
61
|
-
}),
|
62
|
-
);
|
63
|
-
});
|