patron-oop 1.5.2 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +9 -0
- package/dist/patron.d.ts +1 -3
- package/dist/patron.js +14 -18
- package/dist/patron.js.map +1 -1
- package/dist/patron.min.js +1 -1
- package/dist/patron.mjs +14 -18
- 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/Source/SourcesApplied.test.ts +12 -0
- package/src/Source/SourcesApplied.ts +17 -18
package/CHANGELOG.md
CHANGED
@@ -2,6 +2,15 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
4
4
|
|
5
|
+
## [1.6.0](https://github.com/kosukhin/patron/compare/v1.5.2...v1.6.0) (2024-10-21)
|
6
|
+
|
7
|
+
|
8
|
+
### Features
|
9
|
+
|
10
|
+
* **main:** добавил выгрузку из библиотек в window ([71fe03d](https://github.com/kosukhin/patron/commit/71fe03d74725f676a245161b5305577182ecb2a0))
|
11
|
+
* **main:** исправить применение источников чтобы классы работали ([ab9e58b](https://github.com/kosukhin/patron/commit/ab9e58b71615dd9c4374ad4d2feb04baeb0d1dec))
|
12
|
+
* **main:** обновить примеры ([9003280](https://github.com/kosukhin/patron/commit/900328076b634b54b1457d8f6d80b27dcaec76aa))
|
13
|
+
|
5
14
|
### [1.5.2](https://github.com/kosukhin/patron/compare/v1.5.1...v1.5.2) (2024-10-20)
|
6
15
|
|
7
16
|
### [1.5.1](https://github.com/kosukhin/patron/compare/v1.5.0...v1.5.1) (2024-10-20)
|
package/dist/patron.d.ts
CHANGED
@@ -141,9 +141,7 @@ declare class Patron {
|
|
141
141
|
|
142
142
|
declare class Source {
|
143
143
|
ofValue<P>(sourceDocument: P): SourceOfValue<P>;
|
144
|
-
applySources<P>(target: P, methodsSources: Record<string, unknown[]>):
|
145
|
-
[k: string]: any;
|
146
|
-
};
|
144
|
+
applySources<P>(target: P, methodsSources: Record<string, unknown[]>): any;
|
147
145
|
}
|
148
146
|
|
149
147
|
export { type ChainType, Guest, GuestCallback, GuestChain, type GuestExecutorType, GuestSync, type GuestType, type GuestValueType, Patron, PatronPool, type PoolType, type ReceiveOptions, Source, SourceOfValue, type SourceType, removePatronFromPools };
|
package/dist/patron.js
CHANGED
@@ -322,25 +322,21 @@ class Patron {
|
|
322
322
|
}
|
323
323
|
|
324
324
|
const sourcesApplied = (target, methodsSources) => {
|
325
|
-
return
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
return
|
330
|
-
key,
|
331
|
-
new Proxy(value, {
|
332
|
-
apply(target2, thisArg, argArray) {
|
333
|
-
return target2.apply(thisArg, [
|
334
|
-
...methodsSources[key],
|
335
|
-
...argArray
|
336
|
-
]);
|
337
|
-
}
|
338
|
-
})
|
339
|
-
];
|
325
|
+
return new Proxy(target, {
|
326
|
+
get: function(target2, property) {
|
327
|
+
const maybeMethod = target2[property];
|
328
|
+
if (typeof maybeMethod !== "function") {
|
329
|
+
return maybeMethod;
|
340
330
|
}
|
341
|
-
return
|
342
|
-
|
343
|
-
|
331
|
+
return (...args) => {
|
332
|
+
const appliedArgs = methodsSources[property];
|
333
|
+
if (appliedArgs) {
|
334
|
+
return maybeMethod(...appliedArgs, ...args);
|
335
|
+
}
|
336
|
+
return maybeMethod(...args);
|
337
|
+
};
|
338
|
+
}
|
339
|
+
});
|
344
340
|
};
|
345
341
|
|
346
342
|
class Source {
|
package/dist/patron.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"patron.js","sources":["../src/Guest/GuestCallback.ts","../src/Patron/PatronPool.ts","../src/Guest/GuestPool.ts","../src/Guest/GuestInTheMiddle.ts","../src/Source/SourceOfValue.ts","../src/Guest/GuestChain.ts","../src/Guest/GuestSync.ts","../src/Guest/GuestCast.ts","../src/Guest/GuestAware.ts","../src/Guest/Guest.ts","../src/Patron/PatronOfGuest.ts","../src/Patron/PatronOnce.ts","../src/Patron/Patron.ts","../src/Source/SourcesApplied.ts","../src/Source/Source.ts","../src/index.ts"],"sourcesContent":["type GuestIntroduction = \"guest\" | \"patron\";\n\nexport interface ReceiveOptions {\n data?: unknown;\n}\n\nexport type GuestExecutorType<T> = (value: T, options?: ReceiveOptions) => void;\n\nexport interface GuestType<T = unknown> {\n receive(value: T, options?: ReceiveOptions): this;\n introduction?(): GuestIntroduction;\n}\n\nexport class GuestCallback<T> implements GuestType<T> {\n public constructor(private receiver: GuestExecutorType<T>) {}\n\n public receive(value: T, options?: ReceiveOptions) {\n this.receiver(value, options);\n return this;\n }\n}\n","import { GuestType, ReceiveOptions } from \"../Guest/GuestCallback\";\n\nconst poolSets = new Map<PoolType, Set<GuestType>>();\n\n/**\n * Удалить патрон из всех пулов\n */\nexport const removePatronFromPools = (patron: GuestType) => {\n poolSets.forEach((pool) => {\n pool.delete(patron);\n });\n};\n\nexport interface PoolType<T = unknown> extends GuestType<T> {\n add(guest: GuestType<T>): this;\n distribute(receiving: T, possiblePatron: GuestType<T>): this;\n remove(patron: GuestType<T>): this;\n}\n\nexport class PatronPool<T> implements PoolType<T> {\n private patrons = new Set<GuestType<T>>();\n\n public receive: (value: T, options?: ReceiveOptions) => this;\n\n public constructor(private initiator: unknown) {\n poolSets.set(this, this.patrons);\n\n let lastMicrotask: (() => void) | null = null;\n const doReceive = (value: T, options?: ReceiveOptions) => {\n this.patrons.forEach((target) => {\n this.sendValueToGuest(value, target, options);\n });\n };\n this.receive = (value: T, options?: ReceiveOptions) => {\n const currentMicroTask = () => {\n if (currentMicroTask === lastMicrotask) {\n doReceive(value, options);\n }\n };\n lastMicrotask = currentMicroTask;\n queueMicrotask(currentMicroTask);\n return this;\n };\n }\n\n public add(shouldBePatron: GuestType<T>) {\n if (\n shouldBePatron.introduction &&\n shouldBePatron.introduction() === \"patron\"\n ) {\n this.patrons.add(shouldBePatron);\n }\n return this;\n }\n\n public remove(patron: GuestType<T>) {\n this.patrons.delete(patron);\n return this;\n }\n\n public distribute(receiving: T, possiblePatron: GuestType<T>): this {\n this.add(possiblePatron);\n this.sendValueToGuest(receiving, possiblePatron, {});\n return this;\n }\n\n private sendValueToGuest(\n value: T,\n guest: GuestType<T>,\n options?: ReceiveOptions,\n ) {\n guest.receive(value, {\n ...options,\n data: {\n ...((options?.data as Record<string, unknown>) ?? {}),\n initiator: this.initiator,\n pool: this,\n },\n });\n }\n}\n","import { PatronPool } from \"../Patron/PatronPool\";\nimport { PoolType } from \"../Patron/PatronPool\";\nimport { GuestType, ReceiveOptions } from \"./GuestCallback\";\n\nexport class GuestPool<T> implements GuestType<T>, PoolType<T> {\n private guests = new Set<GuestType<T>>();\n\n private patronPool: PatronPool<T>;\n\n public constructor(initiator: unknown) {\n this.patronPool = new PatronPool(initiator);\n }\n\n public receive(value: T, options?: ReceiveOptions): this {\n this.deliverToGuests(value, options);\n this.patronPool.receive(value, options);\n return this;\n }\n\n public add(guest: GuestType<T>): this {\n if (!guest.introduction || guest.introduction() === \"guest\") {\n this.guests.add(guest);\n }\n this.patronPool.add(guest);\n return this;\n }\n\n public remove(patron: GuestType<T>): this {\n this.guests.delete(patron);\n this.patronPool.remove(patron);\n return this;\n }\n\n public distribute(receiving: T, possiblePatron: GuestType<T>): this {\n this.add(possiblePatron);\n this.receive(receiving);\n return this;\n }\n\n private deliverToGuests(value: T, options?: ReceiveOptions) {\n this.guests.forEach((target) => {\n target.receive(value, options);\n });\n this.guests.clear();\n }\n}\n","import { GuestType, ReceiveOptions } from \"./GuestCallback\";\n\nexport class GuestInTheMiddle<T> implements GuestType<T> {\n public constructor(\n private baseGuest: GuestType<unknown>,\n private middleFn: (value: T, options?: ReceiveOptions) => void,\n ) {}\n\n introduction() {\n if (!this.baseGuest.introduction) {\n return \"guest\";\n }\n return this.baseGuest.introduction();\n }\n\n receive(value: T, options?: ReceiveOptions): this {\n this.middleFn(value, options);\n return this;\n }\n}\n","import { GuestAwareType } from \"../Guest/GuestAware\";\nimport { GuestType } from \"../Guest/GuestCallback\";\nimport { PatronPool } from \"../Patron/PatronPool\";\n\nexport type SourceType<T = unknown> = GuestAwareType<T> & GuestType<T>;\n\nexport class SourceOfValue<T> implements SourceType<T> {\n private pool = new PatronPool(this);\n\n public constructor(private sourceDocument: T) {}\n\n public receive(value: T): this {\n this.sourceDocument = value;\n this.pool.receive(this.sourceDocument);\n return this;\n }\n\n public receiving(guest: GuestType<T>): this {\n this.pool.distribute(this.sourceDocument, guest);\n return this;\n }\n}\n","import { GuestCallback, GuestType } from \"./GuestCallback\";\nimport { GuestPool } from \"./GuestPool\";\nimport { GuestInTheMiddle } from \"./GuestInTheMiddle\";\nimport { SourceOfValue } from \"../Source/SourceOfValue\";\n\nexport interface ChainType<T = unknown> {\n result(guest: GuestType<T>): this;\n resultArray(guest: GuestType<T>): this;\n receiveKey<R>(key: string): GuestType<R>;\n}\n\nexport class GuestChain<T> implements ChainType<T> {\n private theChain: SourceOfValue<Record<string, unknown>>;\n\n private keysKnown = new Set();\n\n private keysFilled = new Set();\n\n private filledChainPool = new GuestPool(this);\n\n public constructor() {\n this.theChain = new SourceOfValue<Record<string, unknown>>({});\n }\n\n public resultArray(guest: GuestType<T>) {\n this.filledChainPool.add(\n new GuestInTheMiddle(guest, (value: Record<string, unknown>) =>\n Object.values(value),\n ),\n );\n if (this.isChainFilled()) {\n this.theChain.receiving(\n new GuestCallback((chain: Record<string, unknown>) => {\n this.filledChainPool.receive(Object.values(chain));\n }),\n );\n }\n\n return this;\n }\n\n public result(guest: GuestType<T>) {\n if (this.isChainFilled()) {\n this.filledChainPool.add(guest);\n this.theChain.receiving(\n new GuestCallback((chain) => {\n this.filledChainPool.receive(chain);\n }),\n );\n } else {\n this.filledChainPool.add(guest);\n }\n return this;\n }\n\n public receiveKey<R>(key: string): GuestType<R> {\n this.keysKnown.add(key);\n return new GuestCallback((value) => {\n // Обернул в очередь чтобы можно было синхронно наполнить очередь известных ключей\n queueMicrotask(() => {\n this.theChain.receiving(\n new GuestCallback((chain: Record<string, unknown>) => {\n this.keysFilled.add(key);\n const lastChain = {\n ...chain,\n [key]: value,\n };\n this.theChain.receive(lastChain);\n if (this.isChainFilled()) {\n this.filledChainPool.receive(lastChain);\n }\n }),\n );\n });\n });\n }\n\n private isChainFilled() {\n return (\n this.keysFilled.size > 0 && this.keysFilled.size === this.keysKnown.size\n );\n }\n}\n","import { GuestType } from \"./GuestCallback\";\n\nexport interface GuestValueType<T = unknown> extends GuestType<T> {\n value(): T;\n}\n\nexport class GuestSync<T> implements GuestValueType<T> {\n public constructor(private theValue: T) {}\n\n public receive(value: T): this {\n this.theValue = value;\n return this;\n }\n\n public value() {\n return this.theValue;\n }\n}\n","import { GuestType, ReceiveOptions } from \"./GuestCallback\";\n\nexport class GuestCast<T> implements GuestType<T> {\n public constructor(\n private sourceGuest: GuestType<unknown>,\n private targetGuest: GuestType<T>,\n ) {}\n\n introduction() {\n if (!this.sourceGuest.introduction) {\n return \"guest\";\n }\n return this.sourceGuest.introduction();\n }\n\n receive(value: T, options?: ReceiveOptions): this {\n this.targetGuest.receive(value, options);\n return this;\n }\n}\n","import { GuestType } from \"./GuestCallback\";\n\nexport interface GuestAwareType<T = unknown> {\n receiving(guest: GuestType<T>): unknown;\n}\n\nexport class GuestAware<T = unknown> implements GuestAwareType<T> {\n public constructor(private guestReceiver: (guest: GuestType<T>) => void) {}\n\n public receiving(guest: GuestType<T>): GuestType<T> {\n this.guestReceiver(guest);\n return guest;\n }\n}\n","import {\n GuestCallback,\n GuestExecutorType,\n GuestType,\n ReceiveOptions,\n} from \"./GuestCallback\";\nimport { GuestChain } from \"./GuestChain\";\nimport { GuestCast } from \"./GuestCast\";\nimport { GuestInTheMiddle } from \"./GuestInTheMiddle\";\nimport { GuestPool } from \"./GuestPool\";\nimport { GuestAware } from \"./GuestAware\";\nimport { GuestSync } from \"./GuestSync\";\n\nexport class Guest {\n public callback<P>(receiver: GuestExecutorType<P>) {\n return new GuestCallback(receiver);\n }\n\n public chain() {\n return new GuestChain();\n }\n\n public cast<P>(sourceGuest: GuestType<unknown>, targetGuest: GuestType<P>) {\n return new GuestCast(sourceGuest, targetGuest);\n }\n\n public middleware<P>(\n baseGuest: GuestType<unknown>,\n middleFn: (value: P, options?: ReceiveOptions) => void,\n ) {\n return new GuestInTheMiddle(baseGuest, middleFn);\n }\n\n public pool(initiator: unknown) {\n return new GuestPool(initiator);\n }\n\n public aware<P>(guestReceiver: (guest: GuestType<P>) => void) {\n return new GuestAware(guestReceiver);\n }\n\n public sync<P>(value: P) {\n return new GuestSync(value);\n }\n}\n","import { GuestType, ReceiveOptions } from \"../Guest/GuestCallback\";\n\n/**\n * Патрон - это постоянный посетитель\n */\nexport class PatronOfGuest<T> implements GuestType<T> {\n public constructor(private willBePatron: GuestType<T>) {}\n\n public introduction() {\n return \"patron\" as const;\n }\n\n public receive(value: T, options?: ReceiveOptions): this {\n this.willBePatron.receive(value, options);\n return this;\n }\n}\n","import { PoolType } from \"./PatronPool\";\nimport { GuestType, ReceiveOptions } from \"../Guest/GuestCallback\";\n\ntype PoolAware = {\n pool?: PoolType;\n};\n\nexport class PatronOnce<T> implements GuestType<T> {\n private received = false;\n\n public constructor(private baseGuest: GuestType<T>) {}\n\n public introduction() {\n return \"patron\" as const;\n }\n\n public receive(value: T, options?: ReceiveOptions): this {\n if (!this.received) {\n this.baseGuest.receive(value, options);\n }\n\n const data = options?.data as PoolAware;\n\n if (data?.pool) {\n data.pool.remove(this);\n }\n\n return this;\n }\n}\n","import { PatronOfGuest } from \"./PatronOfGuest\";\nimport { GuestType } from \"../Guest/GuestCallback\";\nimport { PatronOnce } from \"./PatronOnce\";\nimport { PatronPool } from \"./PatronPool\";\n\nexport class Patron {\n public ofGuest<P>(willBePatron: GuestType<P>) {\n return new PatronOfGuest(willBePatron);\n }\n\n public once<P>(baseGuest: GuestType<P>) {\n return new PatronOnce(baseGuest);\n }\n\n public pool(initiator: unknown) {\n return new PatronPool(initiator);\n }\n}\n","type TupleSplit<\n T,\n N extends number,\n O extends readonly any[] = readonly [],\n> = O[\"length\"] extends N\n ? [O, T]\n : T extends readonly [infer F, ...infer R]\n ? TupleSplit<readonly [...R], N, readonly [...O, F]>\n : [O, T];\n\ntype SkipFirst<T extends readonly any[], N extends number> = TupleSplit<\n T,\n N\n>[1];\n\nexport const sourcesApplied = <T>(\n target: T,\n methodsSources: Record<string, unknown[]>,\n) => {\n return Object.fromEntries(\n Object.entries(target as object).map(([key, value]) => {\n if (value instanceof Function && methodsSources[key]) {\n const methodArgs = methodsSources[key];\n return [\n key,\n new Proxy(value, {\n apply(target: Function, thisArg: any, argArray: any[]): any {\n return target.apply(thisArg, [\n ...methodsSources[key],\n ...argArray,\n ]);\n },\n }) as (...args: Parameters<typeof value>) => ReturnType<typeof value>,\n ];\n }\n\n return [key, value];\n }),\n );\n};\n","import { SourceOfValue } from \"./SourceOfValue\";\nimport { sourcesApplied } from \"./SourcesApplied\";\n\nexport class Source {\n public ofValue<P>(sourceDocument: P) {\n return new SourceOfValue(sourceDocument);\n }\n\n public applySources<P>(target: P, methodsSources: Record<string, unknown[]>) {\n return sourcesApplied(target, methodsSources);\n }\n}\n","export * from \"./Guest/GuestCallback\";\nexport * from \"./Guest/GuestChain\";\nexport * from \"./Guest/GuestSync\";\nexport * from \"./Patron/PatronPool\";\nexport * from \"./Source/SourceOfValue\";\n\nimport { Guest } from \"./Guest/Guest\";\nimport { Patron } from \"./Patron/Patron\";\nimport { Source } from \"./Source/Source\";\n\nexport { Guest, Patron, Source };\n\ndeclare var window: any;\n\nif (window) {\n window[\"GUEST_LIBRARY\"] = {\n guest: new Guest(),\n patron: new Patron(),\n source: new Source(),\n };\n}\n"],"names":["__publicField","target"],"mappings":";;AAaO,MAAM,aAAyC,CAAA;AAAA,EAC7C,YAAoB,QAAgC,EAAA;AAAhC,IAAA,IAAA,CAAA,QAAA,GAAA,QAAA,CAAA;AAAA,GAAiC;AAAA,EAErD,OAAA,CAAQ,OAAU,OAA0B,EAAA;AACjD,IAAK,IAAA,CAAA,QAA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AAAA,GAC9C;AACF;;ACGA,IAAI,MAAQ,EAAA;AACV,EAAA,MAAA,CAAO,eAAe,CAAI,GAAA;AAAA,IACxB,KAAA,EAAO,IAAI,KAAM,EAAA;AAAA,IACjB,MAAA,EAAQ,IAAI,MAAO,EAAA;AAAA,IACnB,MAAA,EAAQ,IAAI,MAAO,EAAA;AAAA,GACrB,CAAA;AACF;;;;;;;;;;;;"}
|
1
|
+
{"version":3,"file":"patron.js","sources":["../src/Guest/GuestCallback.ts","../src/Patron/PatronPool.ts","../src/Guest/GuestPool.ts","../src/Guest/GuestInTheMiddle.ts","../src/Source/SourceOfValue.ts","../src/Guest/GuestChain.ts","../src/Guest/GuestSync.ts","../src/Guest/GuestCast.ts","../src/Guest/GuestAware.ts","../src/Guest/Guest.ts","../src/Patron/PatronOfGuest.ts","../src/Patron/PatronOnce.ts","../src/Patron/Patron.ts","../src/Source/SourcesApplied.ts","../src/Source/Source.ts","../src/index.ts"],"sourcesContent":["type GuestIntroduction = \"guest\" | \"patron\";\n\nexport interface ReceiveOptions {\n data?: unknown;\n}\n\nexport type GuestExecutorType<T> = (value: T, options?: ReceiveOptions) => void;\n\nexport interface GuestType<T = unknown> {\n receive(value: T, options?: ReceiveOptions): this;\n introduction?(): GuestIntroduction;\n}\n\nexport class GuestCallback<T> implements GuestType<T> {\n public constructor(private receiver: GuestExecutorType<T>) {}\n\n public receive(value: T, options?: ReceiveOptions) {\n this.receiver(value, options);\n return this;\n }\n}\n","import { GuestType, ReceiveOptions } from \"../Guest/GuestCallback\";\n\nconst poolSets = new Map<PoolType, Set<GuestType>>();\n\n/**\n * Удалить патрон из всех пулов\n */\nexport const removePatronFromPools = (patron: GuestType) => {\n poolSets.forEach((pool) => {\n pool.delete(patron);\n });\n};\n\nexport interface PoolType<T = unknown> extends GuestType<T> {\n add(guest: GuestType<T>): this;\n distribute(receiving: T, possiblePatron: GuestType<T>): this;\n remove(patron: GuestType<T>): this;\n}\n\nexport class PatronPool<T> implements PoolType<T> {\n private patrons = new Set<GuestType<T>>();\n\n public receive: (value: T, options?: ReceiveOptions) => this;\n\n public constructor(private initiator: unknown) {\n poolSets.set(this, this.patrons);\n\n let lastMicrotask: (() => void) | null = null;\n const doReceive = (value: T, options?: ReceiveOptions) => {\n this.patrons.forEach((target) => {\n this.sendValueToGuest(value, target, options);\n });\n };\n this.receive = (value: T, options?: ReceiveOptions) => {\n const currentMicroTask = () => {\n if (currentMicroTask === lastMicrotask) {\n doReceive(value, options);\n }\n };\n lastMicrotask = currentMicroTask;\n queueMicrotask(currentMicroTask);\n return this;\n };\n }\n\n public add(shouldBePatron: GuestType<T>) {\n if (\n shouldBePatron.introduction &&\n shouldBePatron.introduction() === \"patron\"\n ) {\n this.patrons.add(shouldBePatron);\n }\n return this;\n }\n\n public remove(patron: GuestType<T>) {\n this.patrons.delete(patron);\n return this;\n }\n\n public distribute(receiving: T, possiblePatron: GuestType<T>): this {\n this.add(possiblePatron);\n this.sendValueToGuest(receiving, possiblePatron, {});\n return this;\n }\n\n private sendValueToGuest(\n value: T,\n guest: GuestType<T>,\n options?: ReceiveOptions,\n ) {\n guest.receive(value, {\n ...options,\n data: {\n ...((options?.data as Record<string, unknown>) ?? {}),\n initiator: this.initiator,\n pool: this,\n },\n });\n }\n}\n","import { PatronPool } from \"../Patron/PatronPool\";\nimport { PoolType } from \"../Patron/PatronPool\";\nimport { GuestType, ReceiveOptions } from \"./GuestCallback\";\n\nexport class GuestPool<T> implements GuestType<T>, PoolType<T> {\n private guests = new Set<GuestType<T>>();\n\n private patronPool: PatronPool<T>;\n\n public constructor(initiator: unknown) {\n this.patronPool = new PatronPool(initiator);\n }\n\n public receive(value: T, options?: ReceiveOptions): this {\n this.deliverToGuests(value, options);\n this.patronPool.receive(value, options);\n return this;\n }\n\n public add(guest: GuestType<T>): this {\n if (!guest.introduction || guest.introduction() === \"guest\") {\n this.guests.add(guest);\n }\n this.patronPool.add(guest);\n return this;\n }\n\n public remove(patron: GuestType<T>): this {\n this.guests.delete(patron);\n this.patronPool.remove(patron);\n return this;\n }\n\n public distribute(receiving: T, possiblePatron: GuestType<T>): this {\n this.add(possiblePatron);\n this.receive(receiving);\n return this;\n }\n\n private deliverToGuests(value: T, options?: ReceiveOptions) {\n this.guests.forEach((target) => {\n target.receive(value, options);\n });\n this.guests.clear();\n }\n}\n","import { GuestType, ReceiveOptions } from \"./GuestCallback\";\n\nexport class GuestInTheMiddle<T> implements GuestType<T> {\n public constructor(\n private baseGuest: GuestType<unknown>,\n private middleFn: (value: T, options?: ReceiveOptions) => void,\n ) {}\n\n introduction() {\n if (!this.baseGuest.introduction) {\n return \"guest\";\n }\n return this.baseGuest.introduction();\n }\n\n receive(value: T, options?: ReceiveOptions): this {\n this.middleFn(value, options);\n return this;\n }\n}\n","import { GuestAwareType } from \"../Guest/GuestAware\";\nimport { GuestType } from \"../Guest/GuestCallback\";\nimport { PatronPool } from \"../Patron/PatronPool\";\n\nexport type SourceType<T = unknown> = GuestAwareType<T> & GuestType<T>;\n\nexport class SourceOfValue<T> implements SourceType<T> {\n private pool = new PatronPool(this);\n\n public constructor(private sourceDocument: T) {}\n\n public receive(value: T): this {\n this.sourceDocument = value;\n this.pool.receive(this.sourceDocument);\n return this;\n }\n\n public receiving(guest: GuestType<T>): this {\n this.pool.distribute(this.sourceDocument, guest);\n return this;\n }\n}\n","import { GuestCallback, GuestType } from \"./GuestCallback\";\nimport { GuestPool } from \"./GuestPool\";\nimport { GuestInTheMiddle } from \"./GuestInTheMiddle\";\nimport { SourceOfValue } from \"../Source/SourceOfValue\";\n\nexport interface ChainType<T = unknown> {\n result(guest: GuestType<T>): this;\n resultArray(guest: GuestType<T>): this;\n receiveKey<R>(key: string): GuestType<R>;\n}\n\nexport class GuestChain<T> implements ChainType<T> {\n private theChain: SourceOfValue<Record<string, unknown>>;\n\n private keysKnown = new Set();\n\n private keysFilled = new Set();\n\n private filledChainPool = new GuestPool(this);\n\n public constructor() {\n this.theChain = new SourceOfValue<Record<string, unknown>>({});\n }\n\n public resultArray(guest: GuestType<T>) {\n this.filledChainPool.add(\n new GuestInTheMiddle(guest, (value: Record<string, unknown>) =>\n Object.values(value),\n ),\n );\n if (this.isChainFilled()) {\n this.theChain.receiving(\n new GuestCallback((chain: Record<string, unknown>) => {\n this.filledChainPool.receive(Object.values(chain));\n }),\n );\n }\n\n return this;\n }\n\n public result(guest: GuestType<T>) {\n if (this.isChainFilled()) {\n this.filledChainPool.add(guest);\n this.theChain.receiving(\n new GuestCallback((chain) => {\n this.filledChainPool.receive(chain);\n }),\n );\n } else {\n this.filledChainPool.add(guest);\n }\n return this;\n }\n\n public receiveKey<R>(key: string): GuestType<R> {\n this.keysKnown.add(key);\n return new GuestCallback((value) => {\n // Обернул в очередь чтобы можно было синхронно наполнить очередь известных ключей\n queueMicrotask(() => {\n this.theChain.receiving(\n new GuestCallback((chain: Record<string, unknown>) => {\n this.keysFilled.add(key);\n const lastChain = {\n ...chain,\n [key]: value,\n };\n this.theChain.receive(lastChain);\n if (this.isChainFilled()) {\n this.filledChainPool.receive(lastChain);\n }\n }),\n );\n });\n });\n }\n\n private isChainFilled() {\n return (\n this.keysFilled.size > 0 && this.keysFilled.size === this.keysKnown.size\n );\n }\n}\n","import { GuestType } from \"./GuestCallback\";\n\nexport interface GuestValueType<T = unknown> extends GuestType<T> {\n value(): T;\n}\n\nexport class GuestSync<T> implements GuestValueType<T> {\n public constructor(private theValue: T) {}\n\n public receive(value: T): this {\n this.theValue = value;\n return this;\n }\n\n public value() {\n return this.theValue;\n }\n}\n","import { GuestType, ReceiveOptions } from \"./GuestCallback\";\n\nexport class GuestCast<T> implements GuestType<T> {\n public constructor(\n private sourceGuest: GuestType<unknown>,\n private targetGuest: GuestType<T>,\n ) {}\n\n introduction() {\n if (!this.sourceGuest.introduction) {\n return \"guest\";\n }\n return this.sourceGuest.introduction();\n }\n\n receive(value: T, options?: ReceiveOptions): this {\n this.targetGuest.receive(value, options);\n return this;\n }\n}\n","import { GuestType } from \"./GuestCallback\";\n\nexport interface GuestAwareType<T = unknown> {\n receiving(guest: GuestType<T>): unknown;\n}\n\nexport class GuestAware<T = unknown> implements GuestAwareType<T> {\n public constructor(private guestReceiver: (guest: GuestType<T>) => void) {}\n\n public receiving(guest: GuestType<T>): GuestType<T> {\n this.guestReceiver(guest);\n return guest;\n }\n}\n","import {\n GuestCallback,\n GuestExecutorType,\n GuestType,\n ReceiveOptions,\n} from \"./GuestCallback\";\nimport { GuestChain } from \"./GuestChain\";\nimport { GuestCast } from \"./GuestCast\";\nimport { GuestInTheMiddle } from \"./GuestInTheMiddle\";\nimport { GuestPool } from \"./GuestPool\";\nimport { GuestAware } from \"./GuestAware\";\nimport { GuestSync } from \"./GuestSync\";\n\nexport class Guest {\n public callback<P>(receiver: GuestExecutorType<P>) {\n return new GuestCallback(receiver);\n }\n\n public chain() {\n return new GuestChain();\n }\n\n public cast<P>(sourceGuest: GuestType<unknown>, targetGuest: GuestType<P>) {\n return new GuestCast(sourceGuest, targetGuest);\n }\n\n public middleware<P>(\n baseGuest: GuestType<unknown>,\n middleFn: (value: P, options?: ReceiveOptions) => void,\n ) {\n return new GuestInTheMiddle(baseGuest, middleFn);\n }\n\n public pool(initiator: unknown) {\n return new GuestPool(initiator);\n }\n\n public aware<P>(guestReceiver: (guest: GuestType<P>) => void) {\n return new GuestAware(guestReceiver);\n }\n\n public sync<P>(value: P) {\n return new GuestSync(value);\n }\n}\n","import { GuestType, ReceiveOptions } from \"../Guest/GuestCallback\";\n\n/**\n * Патрон - это постоянный посетитель\n */\nexport class PatronOfGuest<T> implements GuestType<T> {\n public constructor(private willBePatron: GuestType<T>) {}\n\n public introduction() {\n return \"patron\" as const;\n }\n\n public receive(value: T, options?: ReceiveOptions): this {\n this.willBePatron.receive(value, options);\n return this;\n }\n}\n","import { PoolType } from \"./PatronPool\";\nimport { GuestType, ReceiveOptions } from \"../Guest/GuestCallback\";\n\ntype PoolAware = {\n pool?: PoolType;\n};\n\nexport class PatronOnce<T> implements GuestType<T> {\n private received = false;\n\n public constructor(private baseGuest: GuestType<T>) {}\n\n public introduction() {\n return \"patron\" as const;\n }\n\n public receive(value: T, options?: ReceiveOptions): this {\n if (!this.received) {\n this.baseGuest.receive(value, options);\n }\n\n const data = options?.data as PoolAware;\n\n if (data?.pool) {\n data.pool.remove(this);\n }\n\n return this;\n }\n}\n","import { PatronOfGuest } from \"./PatronOfGuest\";\nimport { GuestType } from \"../Guest/GuestCallback\";\nimport { PatronOnce } from \"./PatronOnce\";\nimport { PatronPool } from \"./PatronPool\";\n\nexport class Patron {\n public ofGuest<P>(willBePatron: GuestType<P>) {\n return new PatronOfGuest(willBePatron);\n }\n\n public once<P>(baseGuest: GuestType<P>) {\n return new PatronOnce(baseGuest);\n }\n\n public pool(initiator: unknown) {\n return new PatronPool(initiator);\n }\n}\n","type TupleSplit<\n T,\n N extends number,\n O extends readonly any[] = readonly [],\n> = O[\"length\"] extends N\n ? [O, T]\n : T extends readonly [infer F, ...infer R]\n ? TupleSplit<readonly [...R], N, readonly [...O, F]>\n : [O, T];\n\ntype SkipFirst<T extends readonly any[], N extends number> = TupleSplit<\n T,\n N\n>[1];\n\nexport const sourcesApplied = <T>(\n target: T,\n methodsSources: Record<string, unknown[]>,\n) => {\n return new Proxy(target as object, {\n get: function (target: any, property) {\n const maybeMethod = target[property];\n\n if (typeof maybeMethod !== \"function\") {\n return maybeMethod;\n }\n\n return (...args: any[]) => {\n const appliedArgs = (methodsSources as any)[property];\n\n if (appliedArgs) {\n return maybeMethod(...appliedArgs, ...args);\n }\n\n return maybeMethod(...args);\n };\n },\n });\n};\n","import { SourceOfValue } from \"./SourceOfValue\";\nimport { sourcesApplied } from \"./SourcesApplied\";\n\nexport class Source {\n public ofValue<P>(sourceDocument: P) {\n return new SourceOfValue(sourceDocument);\n }\n\n public applySources<P>(target: P, methodsSources: Record<string, unknown[]>) {\n return sourcesApplied(target, methodsSources);\n }\n}\n","export * from \"./Guest/GuestCallback\";\nexport * from \"./Guest/GuestChain\";\nexport * from \"./Guest/GuestSync\";\nexport * from \"./Patron/PatronPool\";\nexport * from \"./Source/SourceOfValue\";\n\nimport { Guest } from \"./Guest/Guest\";\nimport { Patron } from \"./Patron/Patron\";\nimport { Source } from \"./Source/Source\";\n\nexport { Guest, Patron, Source };\n\ndeclare var window: any;\n\nif (window) {\n window[\"GUEST_LIBRARY\"] = {\n guest: new Guest(),\n patron: new Patron(),\n source: new Source(),\n };\n}\n"],"names":["__publicField","target"],"mappings":";;AAaO,MAAM,aAAyC,CAAA;AAAA,EAC7C,YAAoB,QAAgC,EAAA;AAAhC,IAAA,IAAA,CAAA,QAAA,GAAA,QAAA,CAAA;AAAA,GAAiC;AAAA,EAErD,OAAA,CAAQ,OAAU,OAA0B,EAAA;AACjD,IAAK,IAAA,CAAA,QAAA,CAAS,OAAO,OAAO,CAAA,CAAA;AAC5B,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AACF;;;;;AClBA,MAAM,QAAA,uBAAe,GAA8B,EAAA,CAAA;AAKtC,MAAA,qBAAA,GAAwB,CAAC,MAAsB,KAAA;AAC1D,EAAS,QAAA,CAAA,OAAA,CAAQ,CAAC,IAAS,KAAA;AACzB,IAAA,IAAA,CAAK,OAAO,MAAM,CAAA,CAAA;AAAA,GACnB,CAAA,CAAA;AACH,EAAA;AAQO,MAAM,UAAqC,CAAA;AAAA,EAKzC,YAAoB,SAAoB,EAAA;AAApB,IAAA,IAAA,CAAA,SAAA,GAAA,SAAA,CAAA;AAJ3B,IAAQA,eAAA,CAAA,IAAA,EAAA,SAAA,sBAAc,GAAkB,EAAA,CAAA,CAAA;AAExC,IAAOA,eAAA,CAAA,IAAA,EAAA,SAAA,CAAA,CAAA;AAGL,IAAS,QAAA,CAAA,GAAA,CAAI,IAAM,EAAA,IAAA,CAAK,OAAO,CAAA,CAAA;AAE/B,IAAA,IAAI,aAAqC,GAAA,IAAA,CAAA;AACzC,IAAM,MAAA,SAAA,GAAY,CAAC,KAAA,EAAU,OAA6B,KAAA;AACxD,MAAK,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AG,WAAa,EAAA,GAAG,IAAI,CAAA,CAAA;AAAA,SAC5C;AAEA,QAAO,OAAA,WAAA,CAAY,GAAG,IAAI,CAAA,CAAA;AAAA,OAC5B,CAAA;AAAA,KACF;AAAA,GACD,CAAA,CAAA;AACH,CAAA;;ACnCO,MAAM,MAAO,CAAA;AAAA,EACX,QAAW,cAAmB,EAAA;AACnC,IAAO,OAAA,IAAI,cAAc,cAAc,CAAA,CAAA;AAAA,GACzC;AAAA,EAEO,YAAA,CAAgB,QAAW,cAA2C,EAAA;AAC3E,IAAO,OAAA,cAAA,CAAe,QAAQ,cAAc,CAAA,CAAA;AAAA,GAC9C;AACF;;ACGA,IAAI,MAAQ,EAAA;AACV,EAAA,MAAA,CAAO,eAAe,CAAI,GAAA;AAAA,IACxB,KAAA,EAAO,IAAI,KAAM,EAAA;AAAA,IACjB,MAAA,EAAQ,IAAI,MAAO,EAAA;AAAA,IACnB,MAAA,EAAQ,IAAI,MAAO,EAAA;AAAA,GACrB,CAAA;AACF;;;;;;;;;;;;"}
|
package/dist/patron.min.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
!function(e){"use strict";class t{constructor(e){this.receiver=e}receive(e,t){return this.receiver(e,t),this}}var i=Object.defineProperty,
|
1
|
+
!function(e){"use strict";class t{constructor(e){this.receiver=e}receive(e,t){return this.receiver(e,t),this}}var i=Object.defineProperty,r=(e,t,r)=>((e,t,r)=>t in e?i(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r)(e,"symbol"!=typeof t?t+"":t,r);const s=new Map;class n{constructor(e){this.initiator=e,r(this,"patrons",new Set),r(this,"receive"),s.set(this,this.patrons);let t=null;const i=(e,t)=>{this.patrons.forEach((i=>{this.sendValueToGuest(e,i,t)}))};this.receive=(e,r)=>{const s=()=>{s===t&&i(e,r)};return t=s,queueMicrotask(s),this}}add(e){return e.introduction&&"patron"===e.introduction()&&this.patrons.add(e),this}remove(e){return this.patrons.delete(e),this}distribute(e,t){return this.add(t),this.sendValueToGuest(e,t,{}),this}sendValueToGuest(e,t,i){t.receive(e,{...i,data:{...i?.data??{},initiator:this.initiator,pool:this}})}}var o=Object.defineProperty,u=(e,t,i)=>((e,t,i)=>t in e?o(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i)(e,"symbol"!=typeof t?t+"":t,i);class c{constructor(e){u(this,"guests",new Set),u(this,"patronPool"),this.patronPool=new n(e)}receive(e,t){return this.deliverToGuests(e,t),this.patronPool.receive(e,t),this}add(e){return e.introduction&&"guest"!==e.introduction()||this.guests.add(e),this.patronPool.add(e),this}remove(e){return this.guests.delete(e),this.patronPool.remove(e),this}distribute(e,t){return this.add(t),this.receive(e),this}deliverToGuests(e,t){this.guests.forEach((i=>{i.receive(e,t)})),this.guests.clear()}}class a{constructor(e,t){this.baseGuest=e,this.middleFn=t}introduction(){return this.baseGuest.introduction?this.baseGuest.introduction():"guest"}receive(e,t){return this.middleFn(e,t),this}}var h=Object.defineProperty,l=(e,t,i)=>((e,t,i)=>t in e?h(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i)(e,t+"",i);class d{constructor(e){this.sourceDocument=e,l(this,"pool",new n(this))}receive(e){return this.sourceDocument=e,this.pool.receive(this.sourceDocument),this}receiving(e){return this.pool.distribute(this.sourceDocument,e),this}}var v=Object.defineProperty,w=(e,t,i)=>((e,t,i)=>t in e?v(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i)(e,"symbol"!=typeof t?t+"":t,i);class b{constructor(){w(this,"theChain"),w(this,"keysKnown",new Set),w(this,"keysFilled",new Set),w(this,"filledChainPool",new c(this)),this.theChain=new d({})}resultArray(e){return this.filledChainPool.add(new a(e,(e=>Object.values(e)))),this.isChainFilled()&&this.theChain.receiving(new t((e=>{this.filledChainPool.receive(Object.values(e))}))),this}result(e){return this.isChainFilled()?(this.filledChainPool.add(e),this.theChain.receiving(new t((e=>{this.filledChainPool.receive(e)})))):this.filledChainPool.add(e),this}receiveKey(e){return this.keysKnown.add(e),new t((i=>{queueMicrotask((()=>{this.theChain.receiving(new t((t=>{this.keysFilled.add(e);const r={...t,[e]:i};this.theChain.receive(r),this.isChainFilled()&&this.filledChainPool.receive(r)})))}))}))}isChainFilled(){return this.keysFilled.size>0&&this.keysFilled.size===this.keysKnown.size}}class p{constructor(e){this.theValue=e}receive(e){return this.theValue=e,this}value(){return this.theValue}}class f{constructor(e,t){this.sourceGuest=e,this.targetGuest=t}introduction(){return this.sourceGuest.introduction?this.sourceGuest.introduction():"guest"}receive(e,t){return this.targetGuest.receive(e,t),this}}class y{constructor(e){this.guestReceiver=e}receiving(e){return this.guestReceiver(e),e}}class P{callback(e){return new t(e)}chain(){return new b}cast(e,t){return new f(e,t)}middleware(e,t){return new a(e,t)}pool(e){return new c(e)}aware(e){return new y(e)}sync(e){return new p(e)}}class g{constructor(e){this.willBePatron=e}introduction(){return"patron"}receive(e,t){return this.willBePatron.receive(e,t),this}}var m=Object.defineProperty,G=(e,t,i)=>((e,t,i)=>t in e?m(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i)(e,t+"",i);class C{constructor(e){this.baseGuest=e,G(this,"received",!1)}introduction(){return"patron"}receive(e,t){this.received||this.baseGuest.receive(e,t);const i=t?.data;return i?.pool&&i.pool.remove(this),this}}class k{ofGuest(e){return new g(e)}once(e){return new C(e)}pool(e){return new n(e)}}class F{ofValue(e){return new d(e)}applySources(e,t){return((e,t)=>new Proxy(e,{get:function(e,i){const r=e[i];return"function"!=typeof r?r:(...e)=>{const s=t[i];return s?r(...s,...e):r(...e)}}}))(e,t)}}window&&(window.GUEST_LIBRARY={guest:new P,patron:new k,source:new F}),e.Guest=P,e.GuestCallback=t,e.GuestChain=b,e.GuestSync=p,e.Patron=k,e.PatronPool=n,e.Source=F,e.SourceOfValue=d,e.removePatronFromPools=e=>{s.forEach((t=>{t.delete(e)}))}}({});
|
package/dist/patron.mjs
CHANGED
@@ -320,25 +320,21 @@ class Patron {
|
|
320
320
|
}
|
321
321
|
|
322
322
|
const sourcesApplied = (target, methodsSources) => {
|
323
|
-
return
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
return
|
328
|
-
key,
|
329
|
-
new Proxy(value, {
|
330
|
-
apply(target2, thisArg, argArray) {
|
331
|
-
return target2.apply(thisArg, [
|
332
|
-
...methodsSources[key],
|
333
|
-
...argArray
|
334
|
-
]);
|
335
|
-
}
|
336
|
-
})
|
337
|
-
];
|
323
|
+
return new Proxy(target, {
|
324
|
+
get: function(target2, property) {
|
325
|
+
const maybeMethod = target2[property];
|
326
|
+
if (typeof maybeMethod !== "function") {
|
327
|
+
return maybeMethod;
|
338
328
|
}
|
339
|
-
return
|
340
|
-
|
341
|
-
|
329
|
+
return (...args) => {
|
330
|
+
const appliedArgs = methodsSources[property];
|
331
|
+
if (appliedArgs) {
|
332
|
+
return maybeMethod(...appliedArgs, ...args);
|
333
|
+
}
|
334
|
+
return maybeMethod(...args);
|
335
|
+
};
|
336
|
+
}
|
337
|
+
});
|
342
338
|
};
|
343
339
|
|
344
340
|
class Source {
|
package/dist/patron.mjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"patron.mjs","sources":["../src/Guest/GuestCallback.ts","../src/Patron/PatronPool.ts","../src/Guest/GuestPool.ts","../src/Guest/GuestInTheMiddle.ts","../src/Source/SourceOfValue.ts","../src/Guest/GuestChain.ts","../src/Guest/GuestSync.ts","../src/Guest/GuestCast.ts","../src/Guest/GuestAware.ts","../src/Guest/Guest.ts","../src/Patron/PatronOfGuest.ts","../src/Patron/PatronOnce.ts","../src/Patron/Patron.ts","../src/Source/SourcesApplied.ts","../src/Source/Source.ts","../src/index.ts"],"sourcesContent":["type GuestIntroduction = \"guest\" | \"patron\";\n\nexport interface ReceiveOptions {\n data?: unknown;\n}\n\nexport type GuestExecutorType<T> = (value: T, options?: ReceiveOptions) => void;\n\nexport interface GuestType<T = unknown> {\n receive(value: T, options?: ReceiveOptions): this;\n introduction?(): GuestIntroduction;\n}\n\nexport class GuestCallback<T> implements GuestType<T> {\n public constructor(private receiver: GuestExecutorType<T>) {}\n\n public receive(value: T, options?: ReceiveOptions) {\n this.receiver(value, options);\n return this;\n }\n}\n","import { GuestType, ReceiveOptions } from \"../Guest/GuestCallback\";\n\nconst poolSets = new Map<PoolType, Set<GuestType>>();\n\n/**\n * Удалить патрон из всех пулов\n */\nexport const removePatronFromPools = (patron: GuestType) => {\n poolSets.forEach((pool) => {\n pool.delete(patron);\n });\n};\n\nexport interface PoolType<T = unknown> extends GuestType<T> {\n add(guest: GuestType<T>): this;\n distribute(receiving: T, possiblePatron: GuestType<T>): this;\n remove(patron: GuestType<T>): this;\n}\n\nexport class PatronPool<T> implements PoolType<T> {\n private patrons = new Set<GuestType<T>>();\n\n public receive: (value: T, options?: ReceiveOptions) => this;\n\n public constructor(private initiator: unknown) {\n poolSets.set(this, this.patrons);\n\n let lastMicrotask: (() => void) | null = null;\n const doReceive = (value: T, options?: ReceiveOptions) => {\n this.patrons.forEach((target) => {\n this.sendValueToGuest(value, target, options);\n });\n };\n this.receive = (value: T, options?: ReceiveOptions) => {\n const currentMicroTask = () => {\n if (currentMicroTask === lastMicrotask) {\n doReceive(value, options);\n }\n };\n lastMicrotask = currentMicroTask;\n queueMicrotask(currentMicroTask);\n return this;\n };\n }\n\n public add(shouldBePatron: GuestType<T>) {\n if (\n shouldBePatron.introduction &&\n shouldBePatron.introduction() === \"patron\"\n ) {\n this.patrons.add(shouldBePatron);\n }\n return this;\n }\n\n public remove(patron: GuestType<T>) {\n this.patrons.delete(patron);\n return this;\n }\n\n public distribute(receiving: T, possiblePatron: GuestType<T>): this {\n this.add(possiblePatron);\n this.sendValueToGuest(receiving, possiblePatron, {});\n return this;\n }\n\n private sendValueToGuest(\n value: T,\n guest: GuestType<T>,\n options?: ReceiveOptions,\n ) {\n guest.receive(value, {\n ...options,\n data: {\n ...((options?.data as Record<string, unknown>) ?? {}),\n initiator: this.initiator,\n pool: this,\n },\n });\n }\n}\n","import { PatronPool } from \"../Patron/PatronPool\";\nimport { PoolType } from \"../Patron/PatronPool\";\nimport { GuestType, ReceiveOptions } from \"./GuestCallback\";\n\nexport class GuestPool<T> implements GuestType<T>, PoolType<T> {\n private guests = new Set<GuestType<T>>();\n\n private patronPool: PatronPool<T>;\n\n public constructor(initiator: unknown) {\n this.patronPool = new PatronPool(initiator);\n }\n\n public receive(value: T, options?: ReceiveOptions): this {\n this.deliverToGuests(value, options);\n this.patronPool.receive(value, options);\n return this;\n }\n\n public add(guest: GuestType<T>): this {\n if (!guest.introduction || guest.introduction() === \"guest\") {\n this.guests.add(guest);\n }\n this.patronPool.add(guest);\n return this;\n }\n\n public remove(patron: GuestType<T>): this {\n this.guests.delete(patron);\n this.patronPool.remove(patron);\n return this;\n }\n\n public distribute(receiving: T, possiblePatron: GuestType<T>): this {\n this.add(possiblePatron);\n this.receive(receiving);\n return this;\n }\n\n private deliverToGuests(value: T, options?: ReceiveOptions) {\n this.guests.forEach((target) => {\n target.receive(value, options);\n });\n this.guests.clear();\n }\n}\n","import { GuestType, ReceiveOptions } from \"./GuestCallback\";\n\nexport class GuestInTheMiddle<T> implements GuestType<T> {\n public constructor(\n private baseGuest: GuestType<unknown>,\n private middleFn: (value: T, options?: ReceiveOptions) => void,\n ) {}\n\n introduction() {\n if (!this.baseGuest.introduction) {\n return \"guest\";\n }\n return this.baseGuest.introduction();\n }\n\n receive(value: T, options?: ReceiveOptions): this {\n this.middleFn(value, options);\n return this;\n }\n}\n","import { GuestAwareType } from \"../Guest/GuestAware\";\nimport { GuestType } from \"../Guest/GuestCallback\";\nimport { PatronPool } from \"../Patron/PatronPool\";\n\nexport type SourceType<T = unknown> = GuestAwareType<T> & GuestType<T>;\n\nexport class SourceOfValue<T> implements SourceType<T> {\n private pool = new PatronPool(this);\n\n public constructor(private sourceDocument: T) {}\n\n public receive(value: T): this {\n this.sourceDocument = value;\n this.pool.receive(this.sourceDocument);\n return this;\n }\n\n public receiving(guest: GuestType<T>): this {\n this.pool.distribute(this.sourceDocument, guest);\n return this;\n }\n}\n","import { GuestCallback, GuestType } from \"./GuestCallback\";\nimport { GuestPool } from \"./GuestPool\";\nimport { GuestInTheMiddle } from \"./GuestInTheMiddle\";\nimport { SourceOfValue } from \"../Source/SourceOfValue\";\n\nexport interface ChainType<T = unknown> {\n result(guest: GuestType<T>): this;\n resultArray(guest: GuestType<T>): this;\n receiveKey<R>(key: string): GuestType<R>;\n}\n\nexport class GuestChain<T> implements ChainType<T> {\n private theChain: SourceOfValue<Record<string, unknown>>;\n\n private keysKnown = new Set();\n\n private keysFilled = new Set();\n\n private filledChainPool = new GuestPool(this);\n\n public constructor() {\n this.theChain = new SourceOfValue<Record<string, unknown>>({});\n }\n\n public resultArray(guest: GuestType<T>) {\n this.filledChainPool.add(\n new GuestInTheMiddle(guest, (value: Record<string, unknown>) =>\n Object.values(value),\n ),\n );\n if (this.isChainFilled()) {\n this.theChain.receiving(\n new GuestCallback((chain: Record<string, unknown>) => {\n this.filledChainPool.receive(Object.values(chain));\n }),\n );\n }\n\n return this;\n }\n\n public result(guest: GuestType<T>) {\n if (this.isChainFilled()) {\n this.filledChainPool.add(guest);\n this.theChain.receiving(\n new GuestCallback((chain) => {\n this.filledChainPool.receive(chain);\n }),\n );\n } else {\n this.filledChainPool.add(guest);\n }\n return this;\n }\n\n public receiveKey<R>(key: string): GuestType<R> {\n this.keysKnown.add(key);\n return new GuestCallback((value) => {\n // Обернул в очередь чтобы можно было синхронно наполнить очередь известных ключей\n queueMicrotask(() => {\n this.theChain.receiving(\n new GuestCallback((chain: Record<string, unknown>) => {\n this.keysFilled.add(key);\n const lastChain = {\n ...chain,\n [key]: value,\n };\n this.theChain.receive(lastChain);\n if (this.isChainFilled()) {\n this.filledChainPool.receive(lastChain);\n }\n }),\n );\n });\n });\n }\n\n private isChainFilled() {\n return (\n this.keysFilled.size > 0 && this.keysFilled.size === this.keysKnown.size\n );\n }\n}\n","import { GuestType } from \"./GuestCallback\";\n\nexport interface GuestValueType<T = unknown> extends GuestType<T> {\n value(): T;\n}\n\nexport class GuestSync<T> implements GuestValueType<T> {\n public constructor(private theValue: T) {}\n\n public receive(value: T): this {\n this.theValue = value;\n return this;\n }\n\n public value() {\n return this.theValue;\n }\n}\n","import { GuestType, ReceiveOptions } from \"./GuestCallback\";\n\nexport class GuestCast<T> implements GuestType<T> {\n public constructor(\n private sourceGuest: GuestType<unknown>,\n private targetGuest: GuestType<T>,\n ) {}\n\n introduction() {\n if (!this.sourceGuest.introduction) {\n return \"guest\";\n }\n return this.sourceGuest.introduction();\n }\n\n receive(value: T, options?: ReceiveOptions): this {\n this.targetGuest.receive(value, options);\n return this;\n }\n}\n","import { GuestType } from \"./GuestCallback\";\n\nexport interface GuestAwareType<T = unknown> {\n receiving(guest: GuestType<T>): unknown;\n}\n\nexport class GuestAware<T = unknown> implements GuestAwareType<T> {\n public constructor(private guestReceiver: (guest: GuestType<T>) => void) {}\n\n public receiving(guest: GuestType<T>): GuestType<T> {\n this.guestReceiver(guest);\n return guest;\n }\n}\n","import {\n GuestCallback,\n GuestExecutorType,\n GuestType,\n ReceiveOptions,\n} from \"./GuestCallback\";\nimport { GuestChain } from \"./GuestChain\";\nimport { GuestCast } from \"./GuestCast\";\nimport { GuestInTheMiddle } from \"./GuestInTheMiddle\";\nimport { GuestPool } from \"./GuestPool\";\nimport { GuestAware } from \"./GuestAware\";\nimport { GuestSync } from \"./GuestSync\";\n\nexport class Guest {\n public callback<P>(receiver: GuestExecutorType<P>) {\n return new GuestCallback(receiver);\n }\n\n public chain() {\n return new GuestChain();\n }\n\n public cast<P>(sourceGuest: GuestType<unknown>, targetGuest: GuestType<P>) {\n return new GuestCast(sourceGuest, targetGuest);\n }\n\n public middleware<P>(\n baseGuest: GuestType<unknown>,\n middleFn: (value: P, options?: ReceiveOptions) => void,\n ) {\n return new GuestInTheMiddle(baseGuest, middleFn);\n }\n\n public pool(initiator: unknown) {\n return new GuestPool(initiator);\n }\n\n public aware<P>(guestReceiver: (guest: GuestType<P>) => void) {\n return new GuestAware(guestReceiver);\n }\n\n public sync<P>(value: P) {\n return new GuestSync(value);\n }\n}\n","import { GuestType, ReceiveOptions } from \"../Guest/GuestCallback\";\n\n/**\n * Патрон - это постоянный посетитель\n */\nexport class PatronOfGuest<T> implements GuestType<T> {\n public constructor(private willBePatron: GuestType<T>) {}\n\n public introduction() {\n return \"patron\" as const;\n }\n\n public receive(value: T, options?: ReceiveOptions): this {\n this.willBePatron.receive(value, options);\n return this;\n }\n}\n","import { PoolType } from \"./PatronPool\";\nimport { GuestType, ReceiveOptions } from \"../Guest/GuestCallback\";\n\ntype PoolAware = {\n pool?: PoolType;\n};\n\nexport class PatronOnce<T> implements GuestType<T> {\n private received = false;\n\n public constructor(private baseGuest: GuestType<T>) {}\n\n public introduction() {\n return \"patron\" as const;\n }\n\n public receive(value: T, options?: ReceiveOptions): this {\n if (!this.received) {\n this.baseGuest.receive(value, options);\n }\n\n const data = options?.data as PoolAware;\n\n if (data?.pool) {\n data.pool.remove(this);\n }\n\n return this;\n }\n}\n","import { PatronOfGuest } from \"./PatronOfGuest\";\nimport { GuestType } from \"../Guest/GuestCallback\";\nimport { PatronOnce } from \"./PatronOnce\";\nimport { PatronPool } from \"./PatronPool\";\n\nexport class Patron {\n public ofGuest<P>(willBePatron: GuestType<P>) {\n return new PatronOfGuest(willBePatron);\n }\n\n public once<P>(baseGuest: GuestType<P>) {\n return new PatronOnce(baseGuest);\n }\n\n public pool(initiator: unknown) {\n return new PatronPool(initiator);\n }\n}\n","type TupleSplit<\n T,\n N extends number,\n O extends readonly any[] = readonly [],\n> = O[\"length\"] extends N\n ? [O, T]\n : T extends readonly [infer F, ...infer R]\n ? TupleSplit<readonly [...R], N, readonly [...O, F]>\n : [O, T];\n\ntype SkipFirst<T extends readonly any[], N extends number> = TupleSplit<\n T,\n N\n>[1];\n\nexport const sourcesApplied = <T>(\n target: T,\n methodsSources: Record<string, unknown[]>,\n) => {\n return Object.fromEntries(\n Object.entries(target as object).map(([key, value]) => {\n if (value instanceof Function && methodsSources[key]) {\n const methodArgs = methodsSources[key];\n return [\n key,\n new Proxy(value, {\n apply(target: Function, thisArg: any, argArray: any[]): any {\n return target.apply(thisArg, [\n ...methodsSources[key],\n ...argArray,\n ]);\n },\n }) as (...args: Parameters<typeof value>) => ReturnType<typeof value>,\n ];\n }\n\n return [key, value];\n }),\n );\n};\n","import { SourceOfValue } from \"./SourceOfValue\";\nimport { sourcesApplied } from \"./SourcesApplied\";\n\nexport class Source {\n public ofValue<P>(sourceDocument: P) {\n return new SourceOfValue(sourceDocument);\n }\n\n public applySources<P>(target: P, methodsSources: Record<string, unknown[]>) {\n return sourcesApplied(target, methodsSources);\n }\n}\n","export * from \"./Guest/GuestCallback\";\nexport * from \"./Guest/GuestChain\";\nexport * from \"./Guest/GuestSync\";\nexport * from \"./Patron/PatronPool\";\nexport * from \"./Source/SourceOfValue\";\n\nimport { Guest } from \"./Guest/Guest\";\nimport { Patron } from \"./Patron/Patron\";\nimport { Source } from \"./Source/Source\";\n\nexport { Guest, Patron, Source };\n\ndeclare var window: any;\n\nif (window) {\n window[\"GUEST_LIBRARY\"] = {\n guest: new Guest(),\n patron: new Patron(),\n source: new Source(),\n };\n}\n"],"names":["__publicField","target"],"mappings":"AAaO,MAAM,aAAyC,CAAA;AAAA,EAC7C,YAAoB,QAAgC,EAAA;AAAhC,IAAA,IAAA,CAAA,QAAA,GAAA,QAAA,CAAA;AAAA,GAAiC;AAAA,EAErD,OAAA,CAAQ,OAAU,OAA0B,EAAA;AACjD,IAAK,IAAA,CAAA,QAAA,CAAS,OAAO,OAAO,CAAA,CAAA;AAC5B,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AACF;;;;;AClBA,MAAM,QAAA,uBAAe,GAA8B,EAAA,CAAA;AAKtC,MAAA,qBAAA,GAAwB,CAAC,MAAsB,KAAA;AAC1D,EAAS,QAAA,CAAA,OAAA,CAAQ,CAAC,IAAS,KAAA;AACzB,IAAA,IAAA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|
+
{"version":3,"file":"patron.mjs","sources":["../src/Guest/GuestCallback.ts","../src/Patron/PatronPool.ts","../src/Guest/GuestPool.ts","../src/Guest/GuestInTheMiddle.ts","../src/Source/SourceOfValue.ts","../src/Guest/GuestChain.ts","../src/Guest/GuestSync.ts","../src/Guest/GuestCast.ts","../src/Guest/GuestAware.ts","../src/Guest/Guest.ts","../src/Patron/PatronOfGuest.ts","../src/Patron/PatronOnce.ts","../src/Patron/Patron.ts","../src/Source/SourcesApplied.ts","../src/Source/Source.ts","../src/index.ts"],"sourcesContent":["type GuestIntroduction = \"guest\" | \"patron\";\n\nexport interface ReceiveOptions {\n data?: unknown;\n}\n\nexport type GuestExecutorType<T> = (value: T, options?: ReceiveOptions) => void;\n\nexport interface GuestType<T = unknown> {\n receive(value: T, options?: ReceiveOptions): this;\n introduction?(): GuestIntroduction;\n}\n\nexport class GuestCallback<T> implements GuestType<T> {\n public constructor(private receiver: GuestExecutorType<T>) {}\n\n public receive(value: T, options?: ReceiveOptions) {\n this.receiver(value, options);\n return this;\n }\n}\n","import { GuestType, ReceiveOptions } from \"../Guest/GuestCallback\";\n\nconst poolSets = new Map<PoolType, Set<GuestType>>();\n\n/**\n * Удалить патрон из всех пулов\n */\nexport const removePatronFromPools = (patron: GuestType) => {\n poolSets.forEach((pool) => {\n pool.delete(patron);\n });\n};\n\nexport interface PoolType<T = unknown> extends GuestType<T> {\n add(guest: GuestType<T>): this;\n distribute(receiving: T, possiblePatron: GuestType<T>): this;\n remove(patron: GuestType<T>): this;\n}\n\nexport class PatronPool<T> implements PoolType<T> {\n private patrons = new Set<GuestType<T>>();\n\n public receive: (value: T, options?: ReceiveOptions) => this;\n\n public constructor(private initiator: unknown) {\n poolSets.set(this, this.patrons);\n\n let lastMicrotask: (() => void) | null = null;\n const doReceive = (value: T, options?: ReceiveOptions) => {\n this.patrons.forEach((target) => {\n this.sendValueToGuest(value, target, options);\n });\n };\n this.receive = (value: T, options?: ReceiveOptions) => {\n const currentMicroTask = () => {\n if (currentMicroTask === lastMicrotask) {\n doReceive(value, options);\n }\n };\n lastMicrotask = currentMicroTask;\n queueMicrotask(currentMicroTask);\n return this;\n };\n }\n\n public add(shouldBePatron: GuestType<T>) {\n if (\n shouldBePatron.introduction &&\n shouldBePatron.introduction() === \"patron\"\n ) {\n this.patrons.add(shouldBePatron);\n }\n return this;\n }\n\n public remove(patron: GuestType<T>) {\n this.patrons.delete(patron);\n return this;\n }\n\n public distribute(receiving: T, possiblePatron: GuestType<T>): this {\n this.add(possiblePatron);\n this.sendValueToGuest(receiving, possiblePatron, {});\n return this;\n }\n\n private sendValueToGuest(\n value: T,\n guest: GuestType<T>,\n options?: ReceiveOptions,\n ) {\n guest.receive(value, {\n ...options,\n data: {\n ...((options?.data as Record<string, unknown>) ?? {}),\n initiator: this.initiator,\n pool: this,\n },\n });\n }\n}\n","import { PatronPool } from \"../Patron/PatronPool\";\nimport { PoolType } from \"../Patron/PatronPool\";\nimport { GuestType, ReceiveOptions } from \"./GuestCallback\";\n\nexport class GuestPool<T> implements GuestType<T>, PoolType<T> {\n private guests = new Set<GuestType<T>>();\n\n private patronPool: PatronPool<T>;\n\n public constructor(initiator: unknown) {\n this.patronPool = new PatronPool(initiator);\n }\n\n public receive(value: T, options?: ReceiveOptions): this {\n this.deliverToGuests(value, options);\n this.patronPool.receive(value, options);\n return this;\n }\n\n public add(guest: GuestType<T>): this {\n if (!guest.introduction || guest.introduction() === \"guest\") {\n this.guests.add(guest);\n }\n this.patronPool.add(guest);\n return this;\n }\n\n public remove(patron: GuestType<T>): this {\n this.guests.delete(patron);\n this.patronPool.remove(patron);\n return this;\n }\n\n public distribute(receiving: T, possiblePatron: GuestType<T>): this {\n this.add(possiblePatron);\n this.receive(receiving);\n return this;\n }\n\n private deliverToGuests(value: T, options?: ReceiveOptions) {\n this.guests.forEach((target) => {\n target.receive(value, options);\n });\n this.guests.clear();\n }\n}\n","import { GuestType, ReceiveOptions } from \"./GuestCallback\";\n\nexport class GuestInTheMiddle<T> implements GuestType<T> {\n public constructor(\n private baseGuest: GuestType<unknown>,\n private middleFn: (value: T, options?: ReceiveOptions) => void,\n ) {}\n\n introduction() {\n if (!this.baseGuest.introduction) {\n return \"guest\";\n }\n return this.baseGuest.introduction();\n }\n\n receive(value: T, options?: ReceiveOptions): this {\n this.middleFn(value, options);\n return this;\n }\n}\n","import { GuestAwareType } from \"../Guest/GuestAware\";\nimport { GuestType } from \"../Guest/GuestCallback\";\nimport { PatronPool } from \"../Patron/PatronPool\";\n\nexport type SourceType<T = unknown> = GuestAwareType<T> & GuestType<T>;\n\nexport class SourceOfValue<T> implements SourceType<T> {\n private pool = new PatronPool(this);\n\n public constructor(private sourceDocument: T) {}\n\n public receive(value: T): this {\n this.sourceDocument = value;\n this.pool.receive(this.sourceDocument);\n return this;\n }\n\n public receiving(guest: GuestType<T>): this {\n this.pool.distribute(this.sourceDocument, guest);\n return this;\n }\n}\n","import { GuestCallback, GuestType } from \"./GuestCallback\";\nimport { GuestPool } from \"./GuestPool\";\nimport { GuestInTheMiddle } from \"./GuestInTheMiddle\";\nimport { SourceOfValue } from \"../Source/SourceOfValue\";\n\nexport interface ChainType<T = unknown> {\n result(guest: GuestType<T>): this;\n resultArray(guest: GuestType<T>): this;\n receiveKey<R>(key: string): GuestType<R>;\n}\n\nexport class GuestChain<T> implements ChainType<T> {\n private theChain: SourceOfValue<Record<string, unknown>>;\n\n private keysKnown = new Set();\n\n private keysFilled = new Set();\n\n private filledChainPool = new GuestPool(this);\n\n public constructor() {\n this.theChain = new SourceOfValue<Record<string, unknown>>({});\n }\n\n public resultArray(guest: GuestType<T>) {\n this.filledChainPool.add(\n new GuestInTheMiddle(guest, (value: Record<string, unknown>) =>\n Object.values(value),\n ),\n );\n if (this.isChainFilled()) {\n this.theChain.receiving(\n new GuestCallback((chain: Record<string, unknown>) => {\n this.filledChainPool.receive(Object.values(chain));\n }),\n );\n }\n\n return this;\n }\n\n public result(guest: GuestType<T>) {\n if (this.isChainFilled()) {\n this.filledChainPool.add(guest);\n this.theChain.receiving(\n new GuestCallback((chain) => {\n this.filledChainPool.receive(chain);\n }),\n );\n } else {\n this.filledChainPool.add(guest);\n }\n return this;\n }\n\n public receiveKey<R>(key: string): GuestType<R> {\n this.keysKnown.add(key);\n return new GuestCallback((value) => {\n // Обернул в очередь чтобы можно было синхронно наполнить очередь известных ключей\n queueMicrotask(() => {\n this.theChain.receiving(\n new GuestCallback((chain: Record<string, unknown>) => {\n this.keysFilled.add(key);\n const lastChain = {\n ...chain,\n [key]: value,\n };\n this.theChain.receive(lastChain);\n if (this.isChainFilled()) {\n this.filledChainPool.receive(lastChain);\n }\n }),\n );\n });\n });\n }\n\n private isChainFilled() {\n return (\n this.keysFilled.size > 0 && this.keysFilled.size === this.keysKnown.size\n );\n }\n}\n","import { GuestType } from \"./GuestCallback\";\n\nexport interface GuestValueType<T = unknown> extends GuestType<T> {\n value(): T;\n}\n\nexport class GuestSync<T> implements GuestValueType<T> {\n public constructor(private theValue: T) {}\n\n public receive(value: T): this {\n this.theValue = value;\n return this;\n }\n\n public value() {\n return this.theValue;\n }\n}\n","import { GuestType, ReceiveOptions } from \"./GuestCallback\";\n\nexport class GuestCast<T> implements GuestType<T> {\n public constructor(\n private sourceGuest: GuestType<unknown>,\n private targetGuest: GuestType<T>,\n ) {}\n\n introduction() {\n if (!this.sourceGuest.introduction) {\n return \"guest\";\n }\n return this.sourceGuest.introduction();\n }\n\n receive(value: T, options?: ReceiveOptions): this {\n this.targetGuest.receive(value, options);\n return this;\n }\n}\n","import { GuestType } from \"./GuestCallback\";\n\nexport interface GuestAwareType<T = unknown> {\n receiving(guest: GuestType<T>): unknown;\n}\n\nexport class GuestAware<T = unknown> implements GuestAwareType<T> {\n public constructor(private guestReceiver: (guest: GuestType<T>) => void) {}\n\n public receiving(guest: GuestType<T>): GuestType<T> {\n this.guestReceiver(guest);\n return guest;\n }\n}\n","import {\n GuestCallback,\n GuestExecutorType,\n GuestType,\n ReceiveOptions,\n} from \"./GuestCallback\";\nimport { GuestChain } from \"./GuestChain\";\nimport { GuestCast } from \"./GuestCast\";\nimport { GuestInTheMiddle } from \"./GuestInTheMiddle\";\nimport { GuestPool } from \"./GuestPool\";\nimport { GuestAware } from \"./GuestAware\";\nimport { GuestSync } from \"./GuestSync\";\n\nexport class Guest {\n public callback<P>(receiver: GuestExecutorType<P>) {\n return new GuestCallback(receiver);\n }\n\n public chain() {\n return new GuestChain();\n }\n\n public cast<P>(sourceGuest: GuestType<unknown>, targetGuest: GuestType<P>) {\n return new GuestCast(sourceGuest, targetGuest);\n }\n\n public middleware<P>(\n baseGuest: GuestType<unknown>,\n middleFn: (value: P, options?: ReceiveOptions) => void,\n ) {\n return new GuestInTheMiddle(baseGuest, middleFn);\n }\n\n public pool(initiator: unknown) {\n return new GuestPool(initiator);\n }\n\n public aware<P>(guestReceiver: (guest: GuestType<P>) => void) {\n return new GuestAware(guestReceiver);\n }\n\n public sync<P>(value: P) {\n return new GuestSync(value);\n }\n}\n","import { GuestType, ReceiveOptions } from \"../Guest/GuestCallback\";\n\n/**\n * Патрон - это постоянный посетитель\n */\nexport class PatronOfGuest<T> implements GuestType<T> {\n public constructor(private willBePatron: GuestType<T>) {}\n\n public introduction() {\n return \"patron\" as const;\n }\n\n public receive(value: T, options?: ReceiveOptions): this {\n this.willBePatron.receive(value, options);\n return this;\n }\n}\n","import { PoolType } from \"./PatronPool\";\nimport { GuestType, ReceiveOptions } from \"../Guest/GuestCallback\";\n\ntype PoolAware = {\n pool?: PoolType;\n};\n\nexport class PatronOnce<T> implements GuestType<T> {\n private received = false;\n\n public constructor(private baseGuest: GuestType<T>) {}\n\n public introduction() {\n return \"patron\" as const;\n }\n\n public receive(value: T, options?: ReceiveOptions): this {\n if (!this.received) {\n this.baseGuest.receive(value, options);\n }\n\n const data = options?.data as PoolAware;\n\n if (data?.pool) {\n data.pool.remove(this);\n }\n\n return this;\n }\n}\n","import { PatronOfGuest } from \"./PatronOfGuest\";\nimport { GuestType } from \"../Guest/GuestCallback\";\nimport { PatronOnce } from \"./PatronOnce\";\nimport { PatronPool } from \"./PatronPool\";\n\nexport class Patron {\n public ofGuest<P>(willBePatron: GuestType<P>) {\n return new PatronOfGuest(willBePatron);\n }\n\n public once<P>(baseGuest: GuestType<P>) {\n return new PatronOnce(baseGuest);\n }\n\n public pool(initiator: unknown) {\n return new PatronPool(initiator);\n }\n}\n","type TupleSplit<\n T,\n N extends number,\n O extends readonly any[] = readonly [],\n> = O[\"length\"] extends N\n ? [O, T]\n : T extends readonly [infer F, ...infer R]\n ? TupleSplit<readonly [...R], N, readonly [...O, F]>\n : [O, T];\n\ntype SkipFirst<T extends readonly any[], N extends number> = TupleSplit<\n T,\n N\n>[1];\n\nexport const sourcesApplied = <T>(\n target: T,\n methodsSources: Record<string, unknown[]>,\n) => {\n return new Proxy(target as object, {\n get: function (target: any, property) {\n const maybeMethod = target[property];\n\n if (typeof maybeMethod !== \"function\") {\n return maybeMethod;\n }\n\n return (...args: any[]) => {\n const appliedArgs = (methodsSources as any)[property];\n\n if (appliedArgs) {\n return maybeMethod(...appliedArgs, ...args);\n }\n\n return maybeMethod(...args);\n };\n },\n });\n};\n","import { SourceOfValue } from \"./SourceOfValue\";\nimport { sourcesApplied } from \"./SourcesApplied\";\n\nexport class Source {\n public ofValue<P>(sourceDocument: P) {\n return new SourceOfValue(sourceDocument);\n }\n\n public applySources<P>(target: P, methodsSources: Record<string, unknown[]>) {\n return sourcesApplied(target, methodsSources);\n }\n}\n","export * from \"./Guest/GuestCallback\";\nexport * from \"./Guest/GuestChain\";\nexport * from \"./Guest/GuestSync\";\nexport * from \"./Patron/PatronPool\";\nexport * from \"./Source/SourceOfValue\";\n\nimport { Guest } from \"./Guest/Guest\";\nimport { Patron } from \"./Patron/Patron\";\nimport { Source } from \"./Source/Source\";\n\nexport { Guest, Patron, Source };\n\ndeclare var window: any;\n\nif (window) {\n window[\"GUEST_LIBRARY\"] = {\n guest: new Guest(),\n patron: new Patron(),\n source: new Source(),\n };\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cAAc,CAAA,CAAA;AAAA,GACzC;AAAA,EAEO,YAAA,CAAgB,QAAW,cAA2C,EAAA;AAC3E,IAAO,OAAA,cAAA,CAAe,QAAQ,cAAc,CAAA,CAAA;AAAA,GAC9C;AACF;;ACGA,IAAI,MAAQ,EAAA;AACV,EAAA,MAAA,CAAO,eAAe,CAAI,GAAA;AAAA,IACxB,KAAA,EAAO,IAAI,KAAM,EAAA;AAAA,IACjB,MAAA,EAAQ,IAAI,MAAO,EAAA;AAAA,IACnB,MAAA,EAAQ,IAAI,MAAO,EAAA;AAAA,GACrB,CAAA;AACF;;;;"}
|
@@ -23,13 +23,15 @@
|
|
23
23
|
</div>
|
24
24
|
<div>result = <b class="result"></b></div>
|
25
25
|
<script type="module">
|
26
|
-
import "https://cdn.jsdelivr.net/npm/patron-oop@1.5.
|
26
|
+
import "https://cdn.jsdelivr.net/npm/patron-oop@1.5.2/dist/patron.min.js";
|
27
|
+
|
28
|
+
const gl = window.GUEST_LIBRARY;
|
27
29
|
|
28
30
|
// Presentation of text in document
|
29
31
|
class TextInDocument {
|
30
32
|
bindTo(selector) {
|
31
33
|
const element = document.querySelector(selector);
|
32
|
-
return guest.callback((value) => {
|
34
|
+
return gl.guest.callback((value) => {
|
33
35
|
element.innerText = value;
|
34
36
|
});
|
35
37
|
}
|
@@ -46,8 +48,8 @@
|
|
46
48
|
bindTo(selector) {
|
47
49
|
const el = document.querySelector(selector);
|
48
50
|
this.#source.receiving(
|
49
|
-
patron.ofGuest(
|
50
|
-
guest.callback((value) => {
|
51
|
+
gl.patron.ofGuest(
|
52
|
+
gl.guest.callback((value) => {
|
51
53
|
el.value = value;
|
52
54
|
}),
|
53
55
|
),
|
@@ -101,25 +103,25 @@
|
|
101
103
|
}
|
102
104
|
|
103
105
|
result(guest) {
|
104
|
-
const chain =
|
105
|
-
this.#num1.number(
|
106
|
-
this.#num2.number(
|
106
|
+
const chain = gl.guest.chain();
|
107
|
+
this.#num1.number(gl.guest.cast(guest, chain.receiveKey("num1")));
|
108
|
+
this.#num2.number(gl.guest.cast(guest, chain.receiveKey("num2")));
|
107
109
|
chain.result(
|
108
|
-
|
110
|
+
gl.guest.middleware(guest, ({ num1, num2 }) => {
|
109
111
|
guest.receive(num1 * num2);
|
110
112
|
}),
|
111
113
|
);
|
112
114
|
}
|
113
115
|
}
|
114
116
|
|
115
|
-
|
116
|
-
|
117
|
+
const input1 = new Input(gl.source.ofValue(2)).bindTo(".input-1");
|
118
|
+
const input2 = new Input(gl.source.ofValue(2)).bindTo(".input-2");
|
117
119
|
const multiplication = new Mul(
|
118
|
-
new NumberOf(
|
119
|
-
new NumberOf(
|
120
|
+
new NumberOf(input1),
|
121
|
+
new NumberOf(input2),
|
120
122
|
);
|
121
123
|
multiplication.result(
|
122
|
-
patron.ofGuest(new TextInDocument().bindTo(".result")),
|
124
|
+
gl.patron.ofGuest(new TextInDocument().bindTo(".result")),
|
123
125
|
);
|
124
126
|
</script>
|
125
127
|
</body>
|
package/examples/reactive.html
CHANGED
@@ -15,9 +15,9 @@
|
|
15
15
|
</div>
|
16
16
|
<div>Результат ввода: <span class="result"></span></div>
|
17
17
|
<script type="module">
|
18
|
-
import "https://cdn.jsdelivr.net/npm/patron-oop@1.5.
|
18
|
+
import "https://cdn.jsdelivr.net/npm/patron-oop@1.5.2/dist/patron.min.js";
|
19
19
|
|
20
|
-
|
20
|
+
const gl = window.GUEST_LIBRARY;
|
21
21
|
|
22
22
|
// Presentation of input with relation to source value
|
23
23
|
class Input {
|
@@ -30,8 +30,8 @@
|
|
30
30
|
bindTo(selector) {
|
31
31
|
const el = document.querySelector(selector);
|
32
32
|
this.#source.receiving(
|
33
|
-
patron.ofGuest(
|
34
|
-
guest.callback((value) => {
|
33
|
+
gl.patron.ofGuest(
|
34
|
+
gl.guest.callback((value) => {
|
35
35
|
el.value = value;
|
36
36
|
}),
|
37
37
|
),
|
@@ -66,9 +66,9 @@
|
|
66
66
|
}
|
67
67
|
}
|
68
68
|
|
69
|
-
new Input(source.ofValue(2))
|
69
|
+
new Input(gl.source.ofValue(2))
|
70
70
|
.bindTo(".input-1")
|
71
|
-
.receiving(patron.ofGuest(new Text(".result")));
|
71
|
+
.receiving(gl.patron.ofGuest(new Text(".result")));
|
72
72
|
</script>
|
73
73
|
</body>
|
74
74
|
</html>
|
package/package.json
CHANGED
@@ -12,3 +12,15 @@ test("sources applied", () => {
|
|
12
12
|
});
|
13
13
|
expect(targetApplied.one()).toBe("hello world after");
|
14
14
|
});
|
15
|
+
|
16
|
+
test("sources applied classes", () => {
|
17
|
+
class Target {
|
18
|
+
one(data: { one: string }, after: string) {
|
19
|
+
return data.one + " " + after;
|
20
|
+
}
|
21
|
+
}
|
22
|
+
const targetApplied = sourcesApplied(new Target(), {
|
23
|
+
one: [{ one: "good bye" }, "after"],
|
24
|
+
});
|
25
|
+
expect(targetApplied.one()).toBe("good bye after");
|
26
|
+
});
|
@@ -17,24 +17,23 @@ export const sourcesApplied = <T>(
|
|
17
17
|
target: T,
|
18
18
|
methodsSources: Record<string, unknown[]>,
|
19
19
|
) => {
|
20
|
-
return
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
-
];
|
20
|
+
return new Proxy(target as object, {
|
21
|
+
get: function (target: any, property) {
|
22
|
+
const maybeMethod = target[property];
|
23
|
+
|
24
|
+
if (typeof maybeMethod !== "function") {
|
25
|
+
return maybeMethod;
|
35
26
|
}
|
36
27
|
|
37
|
-
return [
|
38
|
-
|
39
|
-
|
28
|
+
return (...args: any[]) => {
|
29
|
+
const appliedArgs = (methodsSources as any)[property];
|
30
|
+
|
31
|
+
if (appliedArgs) {
|
32
|
+
return maybeMethod(...appliedArgs, ...args);
|
33
|
+
}
|
34
|
+
|
35
|
+
return maybeMethod(...args);
|
36
|
+
};
|
37
|
+
},
|
38
|
+
});
|
40
39
|
};
|