patron-oop 1.5.1 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,17 @@
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
+
14
+ ### [1.5.2](https://github.com/kosukhin/patron/compare/v1.5.1...v1.5.2) (2024-10-20)
15
+
5
16
  ### [1.5.1](https://github.com/kosukhin/patron/compare/v1.5.0...v1.5.1) (2024-10-20)
6
17
 
7
18
  ## [1.5.0](https://github.com/kosukhin/patron/compare/v1.4.0...v1.5.0) (2024-10-20)
package/dist/patron.d.ts CHANGED
@@ -63,6 +63,11 @@ declare class PatronPool<T> implements PoolType<T> {
63
63
  interface GuestAwareType<T = unknown> {
64
64
  receiving(guest: GuestType<T>): unknown;
65
65
  }
66
+ declare class GuestAware<T = unknown> implements GuestAwareType<T> {
67
+ private guestReceiver;
68
+ constructor(guestReceiver: (guest: GuestType<T>) => void);
69
+ receiving(guest: GuestType<T>): GuestType<T>;
70
+ }
66
71
 
67
72
  type SourceType<T = unknown> = GuestAwareType<T> & GuestType<T>;
68
73
  declare class SourceOfValue<T> implements SourceType<T> {
@@ -73,4 +78,70 @@ declare class SourceOfValue<T> implements SourceType<T> {
73
78
  receiving(guest: GuestType<T>): this;
74
79
  }
75
80
 
76
- export { type ChainType, GuestCallback, GuestChain, type GuestExecutorType, GuestSync, type GuestType, type GuestValueType, PatronPool, type PoolType, type ReceiveOptions, SourceOfValue, type SourceType, removePatronFromPools };
81
+ declare class GuestCast<T> implements GuestType<T> {
82
+ private sourceGuest;
83
+ private targetGuest;
84
+ constructor(sourceGuest: GuestType<unknown>, targetGuest: GuestType<T>);
85
+ introduction(): "guest" | "patron";
86
+ receive(value: T, options?: ReceiveOptions): this;
87
+ }
88
+
89
+ declare class GuestInTheMiddle<T> implements GuestType<T> {
90
+ private baseGuest;
91
+ private middleFn;
92
+ constructor(baseGuest: GuestType<unknown>, middleFn: (value: T, options?: ReceiveOptions) => void);
93
+ introduction(): "guest" | "patron";
94
+ receive(value: T, options?: ReceiveOptions): this;
95
+ }
96
+
97
+ declare class GuestPool<T> implements GuestType<T>, PoolType<T> {
98
+ private guests;
99
+ private patronPool;
100
+ constructor(initiator: unknown);
101
+ receive(value: T, options?: ReceiveOptions): this;
102
+ add(guest: GuestType<T>): this;
103
+ remove(patron: GuestType<T>): this;
104
+ distribute(receiving: T, possiblePatron: GuestType<T>): this;
105
+ private deliverToGuests;
106
+ }
107
+
108
+ declare class Guest {
109
+ callback<P>(receiver: GuestExecutorType<P>): GuestCallback<P>;
110
+ chain(): GuestChain<unknown>;
111
+ cast<P>(sourceGuest: GuestType<unknown>, targetGuest: GuestType<P>): GuestCast<P>;
112
+ middleware<P>(baseGuest: GuestType<unknown>, middleFn: (value: P, options?: ReceiveOptions) => void): GuestInTheMiddle<P>;
113
+ pool(initiator: unknown): GuestPool<unknown>;
114
+ aware<P>(guestReceiver: (guest: GuestType<P>) => void): GuestAware<P>;
115
+ sync<P>(value: P): GuestSync<P>;
116
+ }
117
+
118
+ /**
119
+ * Патрон - это постоянный посетитель
120
+ */
121
+ declare class PatronOfGuest<T> implements GuestType<T> {
122
+ private willBePatron;
123
+ constructor(willBePatron: GuestType<T>);
124
+ introduction(): "patron";
125
+ receive(value: T, options?: ReceiveOptions): this;
126
+ }
127
+
128
+ declare class PatronOnce<T> implements GuestType<T> {
129
+ private baseGuest;
130
+ private received;
131
+ constructor(baseGuest: GuestType<T>);
132
+ introduction(): "patron";
133
+ receive(value: T, options?: ReceiveOptions): this;
134
+ }
135
+
136
+ declare class Patron {
137
+ ofGuest<P>(willBePatron: GuestType<P>): PatronOfGuest<P>;
138
+ once<P>(baseGuest: GuestType<P>): PatronOnce<P>;
139
+ pool(initiator: unknown): PatronPool<unknown>;
140
+ }
141
+
142
+ declare class Source {
143
+ ofValue<P>(sourceDocument: P): SourceOfValue<P>;
144
+ applySources<P>(target: P, methodsSources: Record<string, unknown[]>): any;
145
+ }
146
+
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 Object.fromEntries(
326
- Object.entries(target).map(([key, value]) => {
327
- if (value instanceof Function && methodsSources[key]) {
328
- methodsSources[key];
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 [key, value];
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 {
@@ -353,15 +349,20 @@ class Source {
353
349
  }
354
350
 
355
351
  if (window) {
356
- window["guest"] = new Guest();
357
- window["patron"] = new Patron();
358
- window["source"] = new Source();
352
+ window["GUEST_LIBRARY"] = {
353
+ guest: new Guest(),
354
+ patron: new Patron(),
355
+ source: new Source()
356
+ };
359
357
  }
360
358
 
359
+ exports.Guest = Guest;
361
360
  exports.GuestCallback = GuestCallback;
362
361
  exports.GuestChain = GuestChain;
363
362
  exports.GuestSync = GuestSync;
363
+ exports.Patron = Patron;
364
364
  exports.PatronPool = PatronPool;
365
+ exports.Source = Source;
365
366
  exports.SourceOfValue = SourceOfValue;
366
367
  exports.removePatronFromPools = removePatronFromPools;
367
368
  //# sourceMappingURL=patron.js.map
@@ -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\ndeclare var window: any;\n\nif (window) {\n window[\"guest\"] = new Guest();\n window[\"patron\"] = new Patron();\n window[\"source\"] = new Source();\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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AI,MAAM,KAAO,EAAA;AAAA,YACf,KAAA,CAAMC,OAAkB,EAAA,OAAA,EAAc,QAAsB,EAAA;AAC1D,cAAOA,OAAAA,OAAAA,CAAO,MAAM,OAAS,EAAA;AAAA,gBAC3B,GAAG,eAAe,GAAG,CAAA;AAAA,gBACrB,GAAG,QAAA;AAAA,eACJ,CAAA,CAAA;AAAA,aACH;AAAA,WACD,CAAA;AAAA,SACH,CAAA;AAAA,OACF;AAEA,MAAO,OAAA,CAAC,KAAK,KAAK,CAAA,CAAA;AAAA,KACnB,CAAA;AAAA,GACH,CAAA;AACF,CAAA;;ACpCO,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;;ACCA,IAAI,MAAQ,EAAA;AACV,EAAO,MAAA,CAAA,OAAO,CAAI,GAAA,IAAI,KAAM,EAAA,CAAA;AAC5B,EAAO,MAAA,CAAA,QAAQ,CAAI,GAAA,IAAI,MAAO,EAAA,CAAA;AAC9B,EAAO,MAAA,CAAA,QAAQ,CAAI,GAAA,IAAI,MAAO,EAAA,CAAA;AAChC;;;;;;;;;"}
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,GAA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;;;;;"}
@@ -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,s=(e,t,s)=>((e,t,s)=>t in e?i(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s)(e,"symbol"!=typeof t?t+"":t,s);const r=new Map;class n{constructor(e){this.initiator=e,s(this,"patrons",new Set),s(this,"receive"),r.set(this,this.patrons);let t=null;const i=(e,t)=>{this.patrons.forEach((i=>{this.sendValueToGuest(e,i,t)}))};this.receive=(e,s)=>{const r=()=>{r===t&&i(e,s)};return t=r,queueMicrotask(r),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 a{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 c{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 p{constructor(){w(this,"theChain"),w(this,"keysKnown",new Set),w(this,"keysFilled",new Set),w(this,"filledChainPool",new a(this)),this.theChain=new d({})}resultArray(e){return this.filledChainPool.add(new c(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 s={...t,[e]:i};this.theChain.receive(s),this.isChainFilled()&&this.filledChainPool.receive(s)})))}))}))}isChainFilled(){return this.keysFilled.size>0&&this.keysFilled.size===this.keysKnown.size}}class b{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 p}cast(e,t){return new f(e,t)}middleware(e,t){return new c(e,t)}pool(e){return new a(e)}aware(e){return new y(e)}sync(e){return new b(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,C=(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 G{constructor(e){this.baseGuest=e,C(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 F{ofGuest(e){return new g(e)}once(e){return new G(e)}pool(e){return new n(e)}}class k{ofValue(e){return new d(e)}applySources(e,t){return((e,t)=>Object.fromEntries(Object.entries(e).map((([e,i])=>i instanceof Function&&t[e]?(t[e],[e,new Proxy(i,{apply:(i,s,r)=>i.apply(s,[...t[e],...r])})]):[e,i]))))(e,t)}}window&&(window.guest=new P,window.patron=new F,window.source=new k),e.GuestCallback=t,e.GuestChain=p,e.GuestSync=b,e.PatronPool=n,e.SourceOfValue=d,e.removePatronFromPools=e=>{r.forEach((t=>{t.delete(e)}))}}({});
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 Object.fromEntries(
324
- Object.entries(target).map(([key, value]) => {
325
- if (value instanceof Function && methodsSources[key]) {
326
- methodsSources[key];
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 [key, value];
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 {
@@ -351,10 +347,12 @@ class Source {
351
347
  }
352
348
 
353
349
  if (window) {
354
- window["guest"] = new Guest();
355
- window["patron"] = new Patron();
356
- window["source"] = new Source();
350
+ window["GUEST_LIBRARY"] = {
351
+ guest: new Guest(),
352
+ patron: new Patron(),
353
+ source: new Source()
354
+ };
357
355
  }
358
356
 
359
- export { GuestCallback, GuestChain, GuestSync, PatronPool, SourceOfValue, removePatronFromPools };
357
+ export { Guest, GuestCallback, GuestChain, GuestSync, Patron, PatronPool, Source, SourceOfValue, removePatronFromPools };
360
358
  //# sourceMappingURL=patron.mjs.map
@@ -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\ndeclare var window: any;\n\nif (window) {\n window[\"guest\"] = new Guest();\n window[\"patron\"] = new Patron();\n window[\"source\"] = new Source();\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;AA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B,CAAA,CAAE,IAAI,CAAC,CAAC,GAAK,EAAA,KAAK,CAAM,KAAA;AACrD,MAAA,IAAI,KAAiB,YAAA,QAAA,IAAY,cAAe,CAAA,GAAG,CAAG,EAAA;AACpD,QAAmB,eAAe,GAAG,EAAA;AACrC,QAAO,OAAA;AAAA,UACL,GAAA;AAAA,UACA,IAAI,MAAM,KAAO,EAAA;AAAA,YACf,KAAA,CAAMC,OAAkB,EAAA,OAAA,EAAc,QAAsB,EAAA;AAC1D,cAAOA,OAAAA,OAAAA,CAAO,MAAM,OAAS,EAAA;AAAA,gBAC3B,GAAG,eAAe,GAAG,CAAA;AAAA,gBACrB,GAAG,QAAA;AAAA,eACJ,CAAA,CAAA;AAAA,aACH;AAAA,WACD,CAAA;AAAA,SACH,CAAA;AAAA,OACF;AAEA,MAAO,OAAA,CAAC,KAAK,KAAK,CAAA,CAAA;AAAA,KACnB,CAAA;AAAA,GACH,CAAA;AACF,CAAA;;ACpCO,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;;ACCA,IAAI,MAAQ,EAAA;AACV,EAAO,MAAA,CAAA,OAAO,CAAI,GAAA,IAAI,KAAM,EAAA,CAAA;AAC5B,EAAO,MAAA,CAAA,QAAQ,CAAI,GAAA,IAAI,MAAO,EAAA,CAAA;AAC9B,EAAO,MAAA,CAAA,QAAQ,CAAI,GAAA,IAAI,MAAO,EAAA,CAAA;AAChC;;;;"}
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 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,OA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AQ,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,126 +1,128 @@
1
- <!DOCTYPE html>
1
+ <!doctype html>
2
2
  <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>Document</title>
7
- </head>
8
- <body>
7
+ </head>
8
+ <body>
9
9
  <h1>Elegant Objects</h1>
10
- <p>
11
- Композиция объектов описывает поведение
12
- </p>
13
- <p>
14
- Умножение: num1 * num2 = result
15
- </p>
10
+ <p>Композиция объектов описывает поведение</p>
11
+ <p>Умножение: num1 * num2 = result</p>
16
12
  <div>
17
- <label>
18
- num1:
19
- <input type="number" class="input-1" />
20
- </label>
13
+ <label>
14
+ num1:
15
+ <input type="number" class="input-1" />
16
+ </label>
21
17
  </div>
22
18
  <div>
23
- <label>
24
- num2:
25
- <input type="number" class="input-2" />
26
- </label>
27
- </div>
28
- <div>
29
- result = <b class="result"></b>
19
+ <label>
20
+ num2:
21
+ <input type="number" class="input-2" />
22
+ </label>
30
23
  </div>
24
+ <div>result = <b class="result"></b></div>
31
25
  <script type="module">
32
- import {Guest, Source, Patron} from 'https://cdn.jsdelivr.net/npm/patron-oop@1.5.0/dist/patron.mjs';
33
-
26
+ import "https://cdn.jsdelivr.net/npm/patron-oop@1.5.2/dist/patron.min.js";
34
27
 
28
+ const gl = window.GUEST_LIBRARY;
35
29
 
36
- // Presentation of text in document
37
- class TextInDocument {
38
- bindTo(selector) {
39
- const element = document.querySelector(selector);
40
- return new Guest((value) => {
41
- element.innerText = value;
42
- });
43
- }
30
+ // Presentation of text in document
31
+ class TextInDocument {
32
+ bindTo(selector) {
33
+ const element = document.querySelector(selector);
34
+ return gl.guest.callback((value) => {
35
+ element.innerText = value;
36
+ });
44
37
  }
38
+ }
45
39
 
46
- // Presentation of input with relation to source value
47
- class Input {
48
- #source;
40
+ // Presentation of input with relation to source value
41
+ class Input {
42
+ #source;
49
43
 
50
- constructor(source) {
51
- this.#source = source;
52
- }
53
-
54
- bindTo(selector) {
55
- const el = document.querySelector(selector);
56
- this.#source.receiving(new Patron(new Guest((value) => {
57
- el.value = value;
58
- })));
59
- el.addEventListener('keyup', (e) => {
60
- this.receive(e.target.value);
61
- });
62
- el.addEventListener('change', (e) => {
63
- this.receive(e.target.value);
64
- });
65
- return this;
66
- }
44
+ constructor(source) {
45
+ this.#source = source;
46
+ }
67
47
 
68
- receiving(guest) {
69
- this.#source.receiving(guest);
70
- return this;
71
- }
48
+ bindTo(selector) {
49
+ const el = document.querySelector(selector);
50
+ this.#source.receiving(
51
+ gl.patron.ofGuest(
52
+ gl.guest.callback((value) => {
53
+ el.value = value;
54
+ }),
55
+ ),
56
+ );
57
+ el.addEventListener("keyup", (e) => {
58
+ this.receive(e.target.value);
59
+ });
60
+ el.addEventListener("change", (e) => {
61
+ this.receive(e.target.value);
62
+ });
63
+ return this;
64
+ }
72
65
 
73
- receive(value) {
74
- this.#source.receive(value);
75
- return this;
76
- }
66
+ receiving(guest) {
67
+ this.#source.receiving(guest);
68
+ return this;
77
69
  }
78
70
 
79
- // Number presentation
80
- class NumberOf {
81
- #source;
71
+ receive(value) {
72
+ this.#source.receive(value);
73
+ return this;
74
+ }
75
+ }
82
76
 
83
- constructor(source) {
84
- this.#source = source;
85
- }
77
+ // Number presentation
78
+ class NumberOf {
79
+ #source;
86
80
 
87
- number(guest) {
88
- this.#source.receiving(guest);
89
- return this;
90
- }
81
+ constructor(source) {
82
+ this.#source = source;
83
+ }
91
84
 
92
- receive(value) {
93
- this.#source.receive(value);
94
- }
85
+ number(guest) {
86
+ this.#source.receiving(guest);
87
+ return this;
95
88
  }
96
89
 
97
- // Multiplication
98
- class Mul {
99
- #num1;
100
- #num2;
90
+ receive(value) {
91
+ this.#source.receive(value);
92
+ }
93
+ }
101
94
 
102
- constructor(num1, num2) {
103
- this.#num1 = num1;
104
- this.#num2 = num2;
105
- }
95
+ // Multiplication
96
+ class Mul {
97
+ #num1;
98
+ #num2;
106
99
 
107
- result(guest) {
108
- const chain = new Chain();
109
- this.#num1.number(new GuestCast(guest, chain.receiveKey('num1')));
110
- this.#num2.number(new GuestCast(guest, chain.receiveKey('num2')));
111
- chain.result(new GuestInTheMiddle(guest, ({num1, num2}) => {
112
- guest.receive(num1 * num2)
113
- }));
114
- }
100
+ constructor(num1, num2) {
101
+ this.#num1 = num1;
102
+ this.#num2 = num2;
115
103
  }
116
104
 
117
- window.input1 = new Input(new Source(2)).bindTo('.input-1');
118
- window.input2 = new Input(new Source(2)).bindTo('.input-2');
119
- const multiplication = new Mul(
120
- new NumberOf(window.input1),
121
- new NumberOf(window.input2)
122
- )
123
- multiplication.result(new Patron(new TextInDocument().bindTo('.result')));
105
+ result(guest) {
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")));
109
+ chain.result(
110
+ gl.guest.middleware(guest, ({ num1, num2 }) => {
111
+ guest.receive(num1 * num2);
112
+ }),
113
+ );
114
+ }
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");
119
+ const multiplication = new Mul(
120
+ new NumberOf(input1),
121
+ new NumberOf(input2),
122
+ );
123
+ multiplication.result(
124
+ gl.patron.ofGuest(new TextInDocument().bindTo(".result")),
125
+ );
124
126
  </script>
125
- </body>
127
+ </body>
126
128
  </html>
@@ -1,69 +1,74 @@
1
- <!DOCTYPE html>
1
+ <!doctype html>
2
2
  <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>Reactive Patron</title>
7
- </head>
8
- <body>
7
+ </head>
8
+ <body>
9
9
  <h1>Reactive example</h1>
10
10
  <div>
11
- <label>
12
- Поле ввода:
13
- <input class="input-1">
14
- </label>
15
- </div>
16
- <div>
17
- Результат ввода: <span class="result"></span>
11
+ <label>
12
+ Поле ввода:
13
+ <input class="input-1" />
14
+ </label>
18
15
  </div>
16
+ <div>Результат ввода: <span class="result"></span></div>
19
17
  <script type="module">
20
- import {Guest, Source, Patron} from 'https://cdn.jsdelivr.net/npm/patron-oop@1.2.0/dist/patron.mjs';
18
+ import "https://cdn.jsdelivr.net/npm/patron-oop@1.5.2/dist/patron.min.js";
19
+
20
+ const gl = window.GUEST_LIBRARY;
21
21
 
22
- // Presentation of input with relation to source value
23
- class Input {
24
- #source;
22
+ // Presentation of input with relation to source value
23
+ class Input {
24
+ #source;
25
25
 
26
- constructor(source) {
27
- this.#source = source;
28
- }
26
+ constructor(source) {
27
+ this.#source = source;
28
+ }
29
29
 
30
- bindTo(selector) {
31
- const el = document.querySelector(selector);
32
- this.#source.receiving(new Patron(new Guest((value) => {
33
- el.value = value;
34
- })));
35
- el.addEventListener('keyup', (e) => {
36
- this.receive(e.target.value);
37
- });
38
- el.addEventListener('change', (e) => {
39
- this.receive(e.target.value);
40
- });
41
- return this;
42
- }
30
+ bindTo(selector) {
31
+ const el = document.querySelector(selector);
32
+ this.#source.receiving(
33
+ gl.patron.ofGuest(
34
+ gl.guest.callback((value) => {
35
+ el.value = value;
36
+ }),
37
+ ),
38
+ );
39
+ el.addEventListener("keyup", (e) => {
40
+ this.receive(e.target.value);
41
+ });
42
+ el.addEventListener("change", (e) => {
43
+ this.receive(e.target.value);
44
+ });
45
+ return this;
46
+ }
43
47
 
44
- receiving(guest) {
45
- this.#source.receiving(guest);
46
- return this;
47
- }
48
+ receiving(guest) {
49
+ this.#source.receiving(guest);
50
+ return this;
51
+ }
48
52
 
49
- receive(value) {
50
- this.#source.receive(value);
51
- return this;
52
- }
53
+ receive(value) {
54
+ this.#source.receive(value);
55
+ return this;
53
56
  }
57
+ }
54
58
 
55
- class Text {
56
- constructor(selector) {
57
- this.element = document.querySelector(selector);
58
- }
59
+ class Text {
60
+ constructor(selector) {
61
+ this.element = document.querySelector(selector);
62
+ }
59
63
 
60
- receive(value) {
61
- this.element.innerText = value;
62
- }
64
+ receive(value) {
65
+ this.element.innerText = value;
63
66
  }
67
+ }
64
68
 
65
- window.input = new Input(new Source(2)).bindTo('.input-1');
66
- input.receiving(new Patron(new Text('.result')));
69
+ new Input(gl.source.ofValue(2))
70
+ .bindTo(".input-1")
71
+ .receiving(gl.patron.ofGuest(new Text(".result")));
67
72
  </script>
68
- </body>
73
+ </body>
69
74
  </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "patron-oop",
3
- "version": "1.5.1",
3
+ "version": "1.6.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/patron.js",
@@ -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 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
- ];
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 [key, value];
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
  };
package/src/index.ts CHANGED
@@ -8,10 +8,14 @@ import { Guest } from "./Guest/Guest";
8
8
  import { Patron } from "./Patron/Patron";
9
9
  import { Source } from "./Source/Source";
10
10
 
11
+ export { Guest, Patron, Source };
12
+
11
13
  declare var window: any;
12
14
 
13
15
  if (window) {
14
- window["guest"] = new Guest();
15
- window["patron"] = new Patron();
16
- window["source"] = new Source();
16
+ window["GUEST_LIBRARY"] = {
17
+ guest: new Guest(),
18
+ patron: new Patron(),
19
+ source: new Source(),
20
+ };
17
21
  }