patron-oop 1.5.2 → 1.7.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 +18 -0
- package/dist/patron.d.ts +61 -82
- package/dist/patron.js +75 -114
- package/dist/patron.js.map +1 -1
- package/dist/patron.min.js +1 -1
- package/dist/patron.mjs +70 -113
- package/dist/patron.mjs.map +1 -1
- package/examples/elegant_objects.html +15 -13
- package/examples/reactive.html +6 -6
- package/package.json +1 -1
- package/src/Guest/Guest.test.ts +10 -0
- package/src/Guest/Guest.ts +28 -35
- package/src/Guest/GuestAware.test.ts +6 -8
- package/src/Guest/GuestAware.ts +1 -1
- package/src/Guest/GuestCast.test.ts +6 -6
- package/src/Guest/GuestCast.ts +7 -3
- package/src/Guest/GuestChain.test.ts +12 -12
- package/src/Guest/GuestChain.ts +11 -11
- package/src/Guest/GuestInTheMiddle.test.ts +9 -9
- package/src/Guest/GuestInTheMiddle.ts +3 -3
- package/src/Guest/GuestPool.test.ts +10 -17
- package/src/Guest/GuestPool.ts +10 -6
- package/src/Guest/GuestSync.test.ts +2 -2
- package/src/Guest/GuestSync.ts +2 -2
- package/src/Patron/{PatronOfGuest.test.ts → Patron.test.ts} +4 -7
- package/src/Patron/Patron.ts +16 -12
- package/src/Patron/PatronOnce.test.ts +3 -6
- package/src/Patron/PatronOnce.ts +8 -3
- package/src/Patron/PatronPool.test.ts +9 -14
- package/src/Patron/PatronPool.ts +16 -10
- package/src/Source/SourceOfValue.test.ts +3 -6
- package/src/Source/SourceOfValue.ts +7 -3
- package/src/index.ts +35 -13
- package/src/Guest/GuestCallback.test.ts +0 -13
- package/src/Guest/GuestCallback.ts +0 -21
- package/src/Patron/PatronOfGuest.ts +0 -17
- package/src/Source/Source.ts +0 -12
- package/src/Source/SourcesApplied.test.ts +0 -14
- package/src/Source/SourcesApplied.ts +0 -40
package/src/index.ts
CHANGED
@@ -1,21 +1,43 @@
|
|
1
|
-
|
1
|
+
import { give, Guest } from "./Guest/Guest";
|
2
|
+
import { PatronPool, removePatronFromPools } from "./Patron/PatronPool";
|
3
|
+
import { GuestAware } from "./Guest/GuestAware";
|
4
|
+
import { GuestCast } from "./Guest/GuestCast";
|
5
|
+
import { GuestChain } from "./Guest/GuestChain";
|
6
|
+
import { GuestInTheMiddle } from "./Guest/GuestInTheMiddle";
|
7
|
+
import { GuestPool } from "./Guest/GuestPool";
|
8
|
+
import { GuestSync } from "./Guest/GuestSync";
|
9
|
+
import { Patron } from "./Patron/Patron";
|
10
|
+
import { PatronOnce } from "./Patron/PatronOnce";
|
11
|
+
import { SourceOfValue } from "./Source/SourceOfValue";
|
12
|
+
|
13
|
+
export * from "./Guest/GuestAware";
|
14
|
+
export * from "./Guest/Guest";
|
15
|
+
export * from "./Guest/GuestCast";
|
2
16
|
export * from "./Guest/GuestChain";
|
17
|
+
export * from "./Guest/GuestInTheMiddle";
|
18
|
+
export * from "./Guest/GuestPool";
|
3
19
|
export * from "./Guest/GuestSync";
|
20
|
+
export * from "./Patron/Patron";
|
21
|
+
export * from "./Patron/PatronOnce";
|
4
22
|
export * from "./Patron/PatronPool";
|
5
23
|
export * from "./Source/SourceOfValue";
|
6
24
|
|
7
|
-
|
8
|
-
import { Patron } from "./Patron/Patron";
|
9
|
-
import { Source } from "./Source/Source";
|
10
|
-
|
11
|
-
export { Guest, Patron, Source };
|
12
|
-
|
13
|
-
declare var window: any;
|
25
|
+
declare var globalThis: any;
|
14
26
|
|
15
|
-
if (
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
27
|
+
if (globalThis) {
|
28
|
+
globalThis["GUEST_LIBRARY"] = {
|
29
|
+
give,
|
30
|
+
removePatronFromPools,
|
31
|
+
GuestAware,
|
32
|
+
Guest,
|
33
|
+
GuestCast,
|
34
|
+
GuestChain,
|
35
|
+
GuestInTheMiddle,
|
36
|
+
GuestPool,
|
37
|
+
GuestSync,
|
38
|
+
Patron,
|
39
|
+
PatronOnce,
|
40
|
+
PatronPool,
|
41
|
+
SourceOfValue,
|
20
42
|
};
|
21
43
|
}
|
@@ -1,13 +0,0 @@
|
|
1
|
-
import { expect, test } from "vitest";
|
2
|
-
import { GuestCallback } from "./GuestCallback";
|
3
|
-
import { SourceOfValue } from "../Source/SourceOfValue";
|
4
|
-
|
5
|
-
test("guest dynamic", () => {
|
6
|
-
const one = new SourceOfValue(1);
|
7
|
-
|
8
|
-
one.receiving(
|
9
|
-
new GuestCallback((value) => {
|
10
|
-
expect(value).toBe(1);
|
11
|
-
}),
|
12
|
-
);
|
13
|
-
});
|
@@ -1,21 +0,0 @@
|
|
1
|
-
type GuestIntroduction = "guest" | "patron";
|
2
|
-
|
3
|
-
export interface ReceiveOptions {
|
4
|
-
data?: unknown;
|
5
|
-
}
|
6
|
-
|
7
|
-
export type GuestExecutorType<T> = (value: T, options?: ReceiveOptions) => void;
|
8
|
-
|
9
|
-
export interface GuestType<T = unknown> {
|
10
|
-
receive(value: T, options?: ReceiveOptions): this;
|
11
|
-
introduction?(): GuestIntroduction;
|
12
|
-
}
|
13
|
-
|
14
|
-
export class GuestCallback<T> implements GuestType<T> {
|
15
|
-
public constructor(private receiver: GuestExecutorType<T>) {}
|
16
|
-
|
17
|
-
public receive(value: T, options?: ReceiveOptions) {
|
18
|
-
this.receiver(value, options);
|
19
|
-
return this;
|
20
|
-
}
|
21
|
-
}
|
@@ -1,17 +0,0 @@
|
|
1
|
-
import { GuestType, ReceiveOptions } from "../Guest/GuestCallback";
|
2
|
-
|
3
|
-
/**
|
4
|
-
* Патрон - это постоянный посетитель
|
5
|
-
*/
|
6
|
-
export class PatronOfGuest<T> implements GuestType<T> {
|
7
|
-
public constructor(private willBePatron: GuestType<T>) {}
|
8
|
-
|
9
|
-
public introduction() {
|
10
|
-
return "patron" as const;
|
11
|
-
}
|
12
|
-
|
13
|
-
public receive(value: T, options?: ReceiveOptions): this {
|
14
|
-
this.willBePatron.receive(value, options);
|
15
|
-
return this;
|
16
|
-
}
|
17
|
-
}
|
package/src/Source/Source.ts
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
import { SourceOfValue } from "./SourceOfValue";
|
2
|
-
import { sourcesApplied } from "./SourcesApplied";
|
3
|
-
|
4
|
-
export class Source {
|
5
|
-
public ofValue<P>(sourceDocument: P) {
|
6
|
-
return new SourceOfValue(sourceDocument);
|
7
|
-
}
|
8
|
-
|
9
|
-
public applySources<P>(target: P, methodsSources: Record<string, unknown[]>) {
|
10
|
-
return sourcesApplied(target, methodsSources);
|
11
|
-
}
|
12
|
-
}
|
@@ -1,14 +0,0 @@
|
|
1
|
-
import { expect, test } from "vitest";
|
2
|
-
import { sourcesApplied } from "./SourcesApplied";
|
3
|
-
|
4
|
-
test("sources applied", () => {
|
5
|
-
const target = {
|
6
|
-
one(data: { one: string }, after: string) {
|
7
|
-
return data.one + " " + after;
|
8
|
-
},
|
9
|
-
};
|
10
|
-
const targetApplied = sourcesApplied(target, {
|
11
|
-
one: [{ one: "hello world" }, "after"],
|
12
|
-
});
|
13
|
-
expect(targetApplied.one()).toBe("hello world after");
|
14
|
-
});
|
@@ -1,40 +0,0 @@
|
|
1
|
-
type TupleSplit<
|
2
|
-
T,
|
3
|
-
N extends number,
|
4
|
-
O extends readonly any[] = readonly [],
|
5
|
-
> = O["length"] extends N
|
6
|
-
? [O, T]
|
7
|
-
: T extends readonly [infer F, ...infer R]
|
8
|
-
? TupleSplit<readonly [...R], N, readonly [...O, F]>
|
9
|
-
: [O, T];
|
10
|
-
|
11
|
-
type SkipFirst<T extends readonly any[], N extends number> = TupleSplit<
|
12
|
-
T,
|
13
|
-
N
|
14
|
-
>[1];
|
15
|
-
|
16
|
-
export const sourcesApplied = <T>(
|
17
|
-
target: T,
|
18
|
-
methodsSources: Record<string, unknown[]>,
|
19
|
-
) => {
|
20
|
-
return Object.fromEntries(
|
21
|
-
Object.entries(target as object).map(([key, value]) => {
|
22
|
-
if (value instanceof Function && methodsSources[key]) {
|
23
|
-
const methodArgs = methodsSources[key];
|
24
|
-
return [
|
25
|
-
key,
|
26
|
-
new Proxy(value, {
|
27
|
-
apply(target: Function, thisArg: any, argArray: any[]): any {
|
28
|
-
return target.apply(thisArg, [
|
29
|
-
...methodsSources[key],
|
30
|
-
...argArray,
|
31
|
-
]);
|
32
|
-
},
|
33
|
-
}) as (...args: Parameters<typeof value>) => ReturnType<typeof value>,
|
34
|
-
];
|
35
|
-
}
|
36
|
-
|
37
|
-
return [key, value];
|
38
|
-
}),
|
39
|
-
);
|
40
|
-
};
|