patron-oop 1.33.0 → 1.35.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 +15 -0
- package/dist/patron.cjs +62 -51
- package/dist/patron.cjs.map +1 -1
- package/dist/patron.d.ts +28 -24
- package/dist/patron.js +61 -51
- 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 +61 -51
- package/dist/patron.mjs.map +1 -1
- package/package.json +1 -1
- package/src/Factory/Module.test.ts +0 -2
- package/src/Guest/GuestAware.ts +17 -5
- package/src/Guest/GuestAwareActive.ts +2 -2
- package/src/Guest/{GuestChain._asArray.test.ts → GuestAwareAll._asArray.test.ts} +6 -6
- package/src/Guest/GuestAwareAll._twoValuesAfter.test.ts +16 -0
- package/src/Guest/GuestAwareAll._twoValuesBefore.test.ts +16 -0
- package/src/Guest/{GuestChain._withPatron.test.ts → GuestAwareAll._withPatron.test.ts} +6 -6
- package/src/Guest/GuestAwareAll.ts +88 -0
- package/src/Guest/GuestAwareMap.fn.test.ts +31 -0
- package/src/Guest/GuestAwareMap.test.ts +4 -3
- package/src/Guest/GuestAwareMap.ts +12 -11
- package/src/Guest/GuestAwareRace.ts +6 -6
- package/src/Guest/GuestAwareSequence.test.ts +5 -4
- package/src/Guest/GuestAwareSequence.ts +13 -13
- package/src/Source/Source.ts +2 -2
- package/src/Source/SourceDynamic.ts +2 -2
- package/src/index.ts +1 -1
- package/examples/elegant_objects.html +0 -118
- package/examples/reactive.html +0 -65
- package/src/Guest/GuestChain._twoValuesAfter.test.ts +0 -16
- package/src/Guest/GuestChain._twoValuesBefore.test.ts +0 -16
- package/src/Guest/GuestChain.ts +0 -88
package/src/Guest/GuestAware.ts
CHANGED
@@ -1,17 +1,29 @@
|
|
1
1
|
import { GuestType } from "./Guest";
|
2
2
|
|
3
|
-
export
|
4
|
-
|
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> = GuestAwareExecutorType<T> | GuestAwareObjectType<T>
|
10
|
+
|
11
|
+
export function value<T>(guestAware: GuestAwareType<T>, guest: GuestType<T>) {
|
12
|
+
if (typeof guestAware === 'function') {
|
13
|
+
return guestAware(guest);
|
14
|
+
} else {
|
15
|
+
return guestAware.value(guest);
|
16
|
+
}
|
5
17
|
}
|
6
18
|
|
7
19
|
/**
|
8
20
|
* @url https://kosukhin.github.io/patron.site/#/guest/guest-aware
|
9
21
|
*/
|
10
|
-
export class GuestAware<T = any> implements
|
11
|
-
public constructor(private
|
22
|
+
export class GuestAware<T = any> implements GuestAwareObjectType<T> {
|
23
|
+
public constructor(private guestAware: GuestAwareType<T>) { }
|
12
24
|
|
13
25
|
public value(guest: GuestType<T>): GuestType<T> {
|
14
|
-
this.
|
26
|
+
value(this.guestAware, guest);
|
15
27
|
return guest;
|
16
28
|
}
|
17
29
|
}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { SourceType } from "../Source/Source";
|
2
2
|
import { SourceEmpty } from "../Source/SourceEmpty";
|
3
3
|
import { GuestType } from "./Guest";
|
4
|
-
import {
|
4
|
+
import { GuestAwareObjectType } from "./GuestAware";
|
5
5
|
|
6
6
|
/**
|
7
7
|
* @url https://kosukhin.github.io/patron.site/#/utils/action-type
|
@@ -10,7 +10,7 @@ export interface ActionType<P = any> {
|
|
10
10
|
do(config: P): this;
|
11
11
|
}
|
12
12
|
|
13
|
-
export interface GuestAwareAcitveType<R = unknown, T = unknown> extends
|
13
|
+
export interface GuestAwareAcitveType<R = unknown, T = unknown> extends GuestAwareObjectType<T>, ActionType<R> {
|
14
14
|
}
|
15
15
|
|
16
16
|
/**
|
@@ -1,17 +1,17 @@
|
|
1
1
|
import { expect, test } from "vitest";
|
2
|
-
import {
|
2
|
+
import { GuestAwareAll } from "./GuestAwareAll";
|
3
3
|
import { Source } from "../Source/Source";
|
4
4
|
import { Patron } from "../Patron/Patron";
|
5
5
|
|
6
|
-
test("
|
6
|
+
test("GuestAwareAll._asArray.test", () => {
|
7
7
|
const one = new Source(1);
|
8
8
|
const two = new Source(2);
|
9
|
-
const
|
9
|
+
const all = new GuestAwareAll<[number, number]>();
|
10
10
|
|
11
|
-
one.value(new Patron(
|
12
|
-
two.value(new Patron(
|
11
|
+
one.value(new Patron(all.guestKey("0")));
|
12
|
+
two.value(new Patron(all.guestKey("1")));
|
13
13
|
|
14
|
-
|
14
|
+
all.valueArray(
|
15
15
|
new Patron((value) => {
|
16
16
|
expect(JSON.stringify(value)).toBe("[1,2]");
|
17
17
|
}),
|
@@ -0,0 +1,16 @@
|
|
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 }>();
|
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
|
+
});
|
@@ -0,0 +1,16 @@
|
|
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,20 +1,20 @@
|
|
1
1
|
import { expect, test } from "vitest";
|
2
|
-
import {
|
2
|
+
import { GuestAwareAll } from "./GuestAwareAll";
|
3
3
|
import { Source } from "../Source/Source";
|
4
4
|
import { Patron } from "../Patron/Patron";
|
5
5
|
|
6
|
-
test("
|
6
|
+
test("GuestAwareAll._withPatron.test", () => {
|
7
7
|
const one = new Source(1);
|
8
8
|
const two = new Source(2);
|
9
|
-
const
|
9
|
+
const all = new GuestAwareAll<{ one: number; two: number }>();
|
10
10
|
|
11
|
-
one.value(new Patron(
|
12
|
-
two.value(new Patron(
|
11
|
+
one.value(new Patron(all.guestKey("one")));
|
12
|
+
two.value(new Patron(all.guestKey("two")));
|
13
13
|
|
14
14
|
one.give(3);
|
15
15
|
one.give(4);
|
16
16
|
|
17
|
-
|
17
|
+
all.value(
|
18
18
|
new Patron((value: Record<string, unknown>) => {
|
19
19
|
expect(Object.values(value).length).toBe(2);
|
20
20
|
}),
|
@@ -0,0 +1,88 @@
|
|
1
|
+
import { GuestAwareObjectType } from "src/Guest/GuestAware";
|
2
|
+
import { Source } from "../Source/Source";
|
3
|
+
import { Guest, GuestObjectType, GuestType } from "./Guest";
|
4
|
+
import { GuestCast } from "./GuestCast";
|
5
|
+
import { GuestObject } from "./GuestObject";
|
6
|
+
import { GuestPool } from "./GuestPool";
|
7
|
+
|
8
|
+
export interface GuestAwareAllType<T = any> extends GuestAwareObjectType<T> {
|
9
|
+
valueArray(guest: GuestObjectType<T>): this;
|
10
|
+
guestKey<R>(key: string): GuestObjectType<R>;
|
11
|
+
}
|
12
|
+
|
13
|
+
/**
|
14
|
+
* @url https://kosukhin.github.io/patron.site/#/guest/guest-aware-all
|
15
|
+
*/
|
16
|
+
export class GuestAwareAll<T> implements GuestAwareAllType<T> {
|
17
|
+
private theAll: Source<Record<string, unknown>>;
|
18
|
+
|
19
|
+
private keysKnown = new Set();
|
20
|
+
|
21
|
+
private keysFilled = new Set();
|
22
|
+
|
23
|
+
private filledAllPool = new GuestPool(this);
|
24
|
+
|
25
|
+
public constructor() {
|
26
|
+
this.theAll = new Source<Record<string, unknown>>({});
|
27
|
+
}
|
28
|
+
|
29
|
+
public valueArray(guest: GuestType<T>) {
|
30
|
+
const guestObject = new GuestObject(guest);
|
31
|
+
this.filledAllPool.add(
|
32
|
+
new GuestCast(guestObject, (value: Record<string, unknown>) => {
|
33
|
+
guestObject.give(Object.values(value) as T);
|
34
|
+
}),
|
35
|
+
);
|
36
|
+
if (this.isAllFilled()) {
|
37
|
+
this.theAll.value(
|
38
|
+
new Guest((all: Record<string, unknown>) => {
|
39
|
+
this.filledAllPool.give(Object.values(all));
|
40
|
+
}),
|
41
|
+
);
|
42
|
+
}
|
43
|
+
return this;
|
44
|
+
}
|
45
|
+
|
46
|
+
public value(guest: GuestType<T>) {
|
47
|
+
const guestObject = new GuestObject(guest);
|
48
|
+
if (this.isAllFilled()) {
|
49
|
+
this.filledAllPool.add(guestObject);
|
50
|
+
this.theAll.value(
|
51
|
+
new Guest((all) => {
|
52
|
+
this.filledAllPool.give(all);
|
53
|
+
}),
|
54
|
+
);
|
55
|
+
} else {
|
56
|
+
this.filledAllPool.add(guestObject);
|
57
|
+
}
|
58
|
+
return this;
|
59
|
+
}
|
60
|
+
|
61
|
+
public guestKey<R>(key: string): GuestObjectType<R> {
|
62
|
+
this.keysKnown.add(key);
|
63
|
+
return new Guest((value) => {
|
64
|
+
// Обернул в очередь чтобы можно было синхронно наполнить очередь известных ключей
|
65
|
+
queueMicrotask(() => {
|
66
|
+
this.theAll.value(
|
67
|
+
new Guest((all: Record<string, unknown>) => {
|
68
|
+
this.keysFilled.add(key);
|
69
|
+
const lastAll = {
|
70
|
+
...all,
|
71
|
+
[key]: value,
|
72
|
+
};
|
73
|
+
this.theAll.give(lastAll);
|
74
|
+
if (this.isAllFilled()) {
|
75
|
+
this.filledAllPool.give(lastAll);
|
76
|
+
}
|
77
|
+
}),
|
78
|
+
);
|
79
|
+
});
|
80
|
+
});
|
81
|
+
}
|
82
|
+
|
83
|
+
private isAllFilled() {
|
84
|
+
return (
|
85
|
+
this.keysFilled.size > 0 && this.keysFilled.size === this.keysKnown.size
|
86
|
+
);
|
87
|
+
}
|
88
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import { Module } from "../Factory/Module";
|
2
|
+
import { expect, test } from "vitest";
|
3
|
+
import { Source } from "../Source/Source";
|
4
|
+
import { give, GuestType } from "./Guest";
|
5
|
+
import { GuestAwareType, value } from "./GuestAware";
|
6
|
+
import { GuestAwareMap } from "./GuestAwareMap";
|
7
|
+
import { GuestCast } from "./GuestCast";
|
8
|
+
|
9
|
+
function x2(baseNumber: GuestAwareType<number>) {
|
10
|
+
return (guest: GuestType<number>) => {
|
11
|
+
value(
|
12
|
+
baseNumber,
|
13
|
+
new GuestCast(<GuestType>guest, (v) => {
|
14
|
+
give(v * 2, guest);
|
15
|
+
})
|
16
|
+
);
|
17
|
+
return guest;
|
18
|
+
};
|
19
|
+
}
|
20
|
+
|
21
|
+
test('GuestAwareMap.test', () => {
|
22
|
+
const source = new Source([1, 2, 3, 9])
|
23
|
+
const guestMapped = new GuestAwareMap(
|
24
|
+
source,
|
25
|
+
new Module(x2)
|
26
|
+
);
|
27
|
+
expect(true).toBe(true);
|
28
|
+
guestMapped.value((v) => {
|
29
|
+
expect(v.join()).toBe('2,4,6,18')
|
30
|
+
});
|
31
|
+
});
|
@@ -1,16 +1,17 @@
|
|
1
1
|
import { expect, test } from "vitest";
|
2
2
|
import { give, GuestType } from "./Guest";
|
3
|
-
import { GuestAwareType } from "./GuestAware";
|
3
|
+
import { GuestAwareObjectType, GuestAwareType, value } from "./GuestAware";
|
4
4
|
import { GuestAwareMap } from "./GuestAwareMap";
|
5
5
|
import { GuestCast } from "./GuestCast";
|
6
6
|
import { Source } from "../Source/Source";
|
7
7
|
import { Factory } from "../Factory/Factory";
|
8
8
|
|
9
|
-
class X2 implements
|
9
|
+
class X2 implements GuestAwareObjectType<number> {
|
10
10
|
public constructor(private baseNumber: GuestAwareType<number>) { }
|
11
11
|
|
12
12
|
public value(guest: GuestType<number>) {
|
13
|
-
|
13
|
+
value(
|
14
|
+
this.baseNumber,
|
14
15
|
new GuestCast(<GuestType>guest, (v) => {
|
15
16
|
give(v * 2, guest);
|
16
17
|
})
|
@@ -1,35 +1,36 @@
|
|
1
1
|
import { FactoryType } from "../Factory/Factory";
|
2
2
|
import { give } from "./Guest";
|
3
|
-
import { GuestAwareType } from "./GuestAware";
|
3
|
+
import { GuestAwareObjectType, GuestAwareType, value } from "./GuestAware";
|
4
4
|
import { GuestCast } from "./GuestCast";
|
5
|
-
import {
|
5
|
+
import { GuestAwareAll } from "./GuestAwareAll";
|
6
6
|
import { GuestType } from "./Guest";
|
7
7
|
import { GuestAware } from "./GuestAware";
|
8
8
|
|
9
9
|
/**
|
10
10
|
* @url https://kosukhin.github.io/patron.site/#/guest/guest-aware-map
|
11
11
|
*/
|
12
|
-
export class GuestAwareMap<T, TG> implements
|
12
|
+
export class GuestAwareMap<T, TG> implements GuestAwareObjectType<TG[]> {
|
13
13
|
public constructor(
|
14
14
|
private baseSource: GuestAwareType<T[]>,
|
15
15
|
private targetSourceFactory: FactoryType<GuestAwareType<TG>>
|
16
16
|
) { }
|
17
17
|
|
18
|
-
value(guest: GuestType<TG[]>) {
|
19
|
-
const
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
public value(guest: GuestType<TG[]>) {
|
19
|
+
const all = new GuestAwareAll();
|
20
|
+
value(
|
21
|
+
this.baseSource,
|
22
|
+
new GuestCast(<GuestType>guest, (theValue) => {
|
23
|
+
theValue.forEach((val, index) => {
|
23
24
|
const targetSource = this.targetSourceFactory.create(
|
24
25
|
new GuestAware((innerGuest) => {
|
25
26
|
give(val, innerGuest);
|
26
27
|
})
|
27
28
|
)
|
28
|
-
targetSource.
|
29
|
+
value(targetSource, all.guestKey(index.toString()));
|
29
30
|
});
|
30
31
|
})
|
31
|
-
)
|
32
|
-
|
32
|
+
)
|
33
|
+
all.valueArray(<GuestType>guest);
|
33
34
|
return this;
|
34
35
|
}
|
35
36
|
}
|
@@ -1,26 +1,26 @@
|
|
1
1
|
import { give, GuestType } from "./Guest";
|
2
|
-
import { GuestAwareType } from "./GuestAware";
|
2
|
+
import { GuestAwareObjectType, GuestAwareType, value } from "./GuestAware";
|
3
3
|
import { GuestCast } from "./GuestCast";
|
4
4
|
|
5
5
|
/**
|
6
6
|
* @url https://kosukhin.github.io/patron.site/#/guest/guest-aware-race
|
7
7
|
*/
|
8
|
-
export class GuestAwareRace<T> implements
|
9
|
-
public constructor(private guestAwares: GuestAwareType[]) { }
|
8
|
+
export class GuestAwareRace<T> implements GuestAwareObjectType<T> {
|
9
|
+
public constructor(private guestAwares: GuestAwareType<T>[]) { }
|
10
10
|
|
11
11
|
public value(guest: GuestType<T>): this {
|
12
12
|
let connectedWithGuestAware: GuestAwareType | null = null;
|
13
13
|
this.guestAwares.forEach(guestAware => {
|
14
|
-
|
14
|
+
value(
|
15
|
+
guestAware,
|
15
16
|
new GuestCast(<GuestType>guest, (value) => {
|
16
17
|
if (!connectedWithGuestAware || connectedWithGuestAware === guestAware) {
|
17
18
|
give(value as T, guest);
|
18
19
|
connectedWithGuestAware = guestAware
|
19
20
|
}
|
20
21
|
})
|
21
|
-
)
|
22
|
+
);
|
22
23
|
});
|
23
|
-
|
24
24
|
return this;
|
25
25
|
}
|
26
26
|
}
|
@@ -1,21 +1,22 @@
|
|
1
1
|
import { GuestAwareSequence } from "./GuestAwareSequence";
|
2
2
|
import { give } from "./Guest";
|
3
|
-
import { GuestAwareType } from "./GuestAware";
|
3
|
+
import { GuestAwareObjectType, GuestAwareType, value } from "./GuestAware";
|
4
4
|
import { GuestCast } from "./GuestCast";
|
5
5
|
import { GuestType } from "./Guest";
|
6
6
|
import { expect, test } from "vitest";
|
7
7
|
import { Source } from "../Source/Source";
|
8
8
|
import { Factory } from "../Factory/Factory";
|
9
9
|
|
10
|
-
class X2 implements
|
10
|
+
class X2 implements GuestAwareObjectType<number> {
|
11
11
|
public constructor(private baseNumber: GuestAwareType<number>) { }
|
12
12
|
|
13
13
|
public value(guest: GuestType<number>) {
|
14
|
-
|
14
|
+
value(
|
15
|
+
this.baseNumber,
|
15
16
|
new GuestCast(<GuestType>guest, (v) => {
|
16
17
|
give(v * 2, guest);
|
17
18
|
})
|
18
|
-
)
|
19
|
+
);
|
19
20
|
return this;
|
20
21
|
}
|
21
22
|
}
|
@@ -1,54 +1,54 @@
|
|
1
1
|
import { FactoryType } from "../Factory/Factory";
|
2
2
|
import { give } from "./Guest";
|
3
|
-
import { GuestAwareType } from "./GuestAware";
|
3
|
+
import { GuestAwareObjectType, GuestAwareType, value } from "./GuestAware";
|
4
4
|
import { GuestCast } from "./GuestCast";
|
5
|
-
import {
|
5
|
+
import { GuestAwareAll } from "./GuestAwareAll";
|
6
6
|
import { GuestType } from "./Guest";
|
7
7
|
import { SourceEmpty } from "../Source/SourceEmpty";
|
8
8
|
|
9
9
|
/**
|
10
10
|
* @url https://kosukhin.github.io/patron.site/#/guest/guest-aware-sequence
|
11
11
|
*/
|
12
|
-
export class GuestAwareSequence<T, TG> implements
|
12
|
+
export class GuestAwareSequence<T, TG> implements GuestAwareObjectType<TG[]> {
|
13
13
|
public constructor(
|
14
14
|
private baseSource: GuestAwareType<T[]>,
|
15
15
|
private targetSourceFactory: FactoryType<GuestAwareType<TG>>
|
16
16
|
) { }
|
17
17
|
|
18
18
|
public value(guest: GuestType<TG[]>) {
|
19
|
-
const
|
19
|
+
const all = new GuestAwareAll<TG[]>();
|
20
20
|
const sequenceSource = new SourceEmpty();
|
21
21
|
const targetSource = this.targetSourceFactory.create(
|
22
22
|
sequenceSource
|
23
23
|
)
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
value(
|
26
|
+
this.baseSource,
|
27
|
+
new GuestCast(guest, (theValue) => {
|
27
28
|
let index = 0;
|
28
29
|
|
29
30
|
const nextItemHandle = () => {
|
30
|
-
if (
|
31
|
+
if (theValue[index + 1] !== undefined) {
|
31
32
|
index = index + 1;
|
32
33
|
handle();
|
33
34
|
} else {
|
34
|
-
|
35
|
+
all.valueArray(guest);
|
35
36
|
}
|
36
37
|
}
|
37
38
|
|
38
39
|
function handle() {
|
39
|
-
sequenceSource.give(
|
40
|
-
targetSource.
|
41
|
-
|
40
|
+
sequenceSource.give(theValue[index]);
|
41
|
+
value(targetSource, all.guestKey(index.toString()));
|
42
|
+
value(targetSource, nextItemHandle);
|
42
43
|
}
|
43
44
|
|
44
|
-
if (
|
45
|
+
if (theValue[index] !== undefined) {
|
45
46
|
handle();
|
46
47
|
} else {
|
47
48
|
give([], guest);
|
48
49
|
}
|
49
50
|
})
|
50
51
|
);
|
51
|
-
|
52
52
|
return this;
|
53
53
|
}
|
54
54
|
}
|
package/src/Source/Source.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { GuestAwareType } from "../Guest/GuestAware";
|
2
1
|
import { Guest, GuestObjectType, GuestType } from "../Guest/Guest";
|
2
|
+
import { GuestAwareObjectType } from "../Guest/GuestAware";
|
3
3
|
import { PatronPool } from "../Patron/PatronPool";
|
4
4
|
|
5
5
|
export interface PoolAware<T = any> {
|
@@ -9,7 +9,7 @@ export interface PoolAware<T = any> {
|
|
9
9
|
/**
|
10
10
|
* @url https://kosukhin.github.io/patron.site/#/source
|
11
11
|
*/
|
12
|
-
export type SourceType<T = any> =
|
12
|
+
export type SourceType<T = any> = GuestAwareObjectType<T> &
|
13
13
|
GuestObjectType<T> &
|
14
14
|
PoolAware<T>;
|
15
15
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { give, GuestType } from "../Guest/Guest";
|
2
|
-
import { GuestAwareType } from "../Guest/GuestAware";
|
2
|
+
import { GuestAwareType, value } from "../Guest/GuestAware";
|
3
3
|
import { PatronPool } from "../Patron/PatronPool";
|
4
4
|
import { SourceType } from "./Source";
|
5
5
|
|
@@ -13,7 +13,7 @@ export class SourceDynamic<T = unknown> implements SourceType<T> {
|
|
13
13
|
) { }
|
14
14
|
|
15
15
|
public value(guest: GuestType<T>) {
|
16
|
-
this.baseGuestAware
|
16
|
+
value(this.baseGuestAware, guest);
|
17
17
|
return this;
|
18
18
|
}
|
19
19
|
|
package/src/index.ts
CHANGED
@@ -5,7 +5,7 @@ export * from "./Guest/GuestAwareRace";
|
|
5
5
|
export * from "./Guest/GuestAwareActive";
|
6
6
|
export * from "./Guest/Guest";
|
7
7
|
export * from "./Guest/GuestCast";
|
8
|
-
export * from "./Guest/
|
8
|
+
export * from "./Guest/GuestAwareAll";
|
9
9
|
export * from "./Guest/GuestPool";
|
10
10
|
export * from "./Guest/GuestSync";
|
11
11
|
export * from "./Guest/GuestObject";
|
@@ -1,118 +0,0 @@
|
|
1
|
-
<!doctype html>
|
2
|
-
<html lang="en">
|
3
|
-
<head>
|
4
|
-
<meta charset="UTF-8"/>
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
6
|
-
<title>Document</title>
|
7
|
-
</head>
|
8
|
-
<body>
|
9
|
-
<h1>Elegant Objects</h1>
|
10
|
-
<p>Композиция объектов описывает поведение</p>
|
11
|
-
<p>Умножение: num1 * num2 = result</p>
|
12
|
-
<div>
|
13
|
-
<label>
|
14
|
-
num1:
|
15
|
-
<input type="number" class="input-1"/>
|
16
|
-
</label>
|
17
|
-
</div>
|
18
|
-
<div>
|
19
|
-
<label>
|
20
|
-
num2:
|
21
|
-
<input type="number" class="input-2"/>
|
22
|
-
</label>
|
23
|
-
</div>
|
24
|
-
<div>result = <b class="result"></b></div>
|
25
|
-
<script type="module">
|
26
|
-
import 'https://cdn.jsdelivr.net/npm/patron-oop@1.8.0/dist/patron.min.js';
|
27
|
-
|
28
|
-
const {
|
29
|
-
Patron,
|
30
|
-
Source,
|
31
|
-
GuestChain,
|
32
|
-
GuestCast,
|
33
|
-
GuestInTheMiddle,
|
34
|
-
} = window.GUEST_LIBRARY;
|
35
|
-
|
36
|
-
class TextInDocument {
|
37
|
-
constructor(selector) {
|
38
|
-
this.element = document.querySelector(selector);
|
39
|
-
}
|
40
|
-
|
41
|
-
receive(value) {
|
42
|
-
this.element.innerText = value;
|
43
|
-
}
|
44
|
-
}
|
45
|
-
|
46
|
-
class Input {
|
47
|
-
constructor(source, selector) {
|
48
|
-
this.source = source;
|
49
|
-
const el = document.querySelector(selector);
|
50
|
-
this.source.value(
|
51
|
-
new Patron((value) => {
|
52
|
-
el.value = value;
|
53
|
-
}),
|
54
|
-
);
|
55
|
-
el.addEventListener('keyup', (e) => {
|
56
|
-
this.give(e.target.value);
|
57
|
-
});
|
58
|
-
el.addEventListener('change', (e) => {
|
59
|
-
this.give(e.target.value);
|
60
|
-
});
|
61
|
-
}
|
62
|
-
|
63
|
-
receiving(guest) {
|
64
|
-
this.source.value(guest);
|
65
|
-
return this;
|
66
|
-
}
|
67
|
-
|
68
|
-
receive(value) {
|
69
|
-
this.source.give(value);
|
70
|
-
return this;
|
71
|
-
}
|
72
|
-
}
|
73
|
-
|
74
|
-
class NumberOf {
|
75
|
-
constructor(source) {
|
76
|
-
this.source = source;
|
77
|
-
}
|
78
|
-
|
79
|
-
number(guest) {
|
80
|
-
this.source.value(guest);
|
81
|
-
return this;
|
82
|
-
}
|
83
|
-
|
84
|
-
receive(value) {
|
85
|
-
this.source.give(value);
|
86
|
-
}
|
87
|
-
}
|
88
|
-
|
89
|
-
class Mul {
|
90
|
-
constructor(num1, num2) {
|
91
|
-
this.num1 = num1;
|
92
|
-
this.num2 = num2;
|
93
|
-
}
|
94
|
-
|
95
|
-
result(guest) {
|
96
|
-
const chain = new GuestChain();
|
97
|
-
this.num1.number(new GuestCast(guest, chain.receiveKey('num1')));
|
98
|
-
this.num2.number(new GuestCast(guest, chain.receiveKey('num2')));
|
99
|
-
chain.result(
|
100
|
-
new GuestInTheMiddle(guest, ({num1, num2}) => {
|
101
|
-
guest.give(num1 * num2);
|
102
|
-
}),
|
103
|
-
);
|
104
|
-
}
|
105
|
-
}
|
106
|
-
|
107
|
-
const input1 = new Input(new Source(2), '.input-1');
|
108
|
-
const input2 = new Input(new Source(2), '.input-2');
|
109
|
-
const multiplication = new Mul(
|
110
|
-
new NumberOf(input1),
|
111
|
-
new NumberOf(input2),
|
112
|
-
);
|
113
|
-
multiplication.result(
|
114
|
-
new Patron(new TextInDocument('.result')),
|
115
|
-
);
|
116
|
-
</script>
|
117
|
-
</body>
|
118
|
-
</html>
|