patron-oop 1.41.0 → 1.43.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,10 +4,10 @@ export interface GiveOptions {
4
4
  data?: unknown;
5
5
  }
6
6
 
7
- export type GuestExecutorType<T = any> = (
7
+ export type GuestExecutorType<T = any, This = void> = (
8
8
  value: T,
9
9
  options?: GiveOptions,
10
- ) => void;
10
+ ) => This;
11
11
 
12
12
  export interface GuestObjectType<T = any> {
13
13
  give(value: T, options?: GiveOptions): this;
@@ -5,7 +5,7 @@ import { GuestAwareAll } from "./GuestAwareAll";
5
5
  test("GuestAwareAll._twoValuesAfter.test", () => {
6
6
  const one = new Source(1);
7
7
  const two = new Source(2);
8
- const all = new GuestAwareAll<{ one: number; two: number }>();
8
+ const all = new GuestAwareAll<{ one: number; two: number }>(["one", "two"]);
9
9
 
10
10
  all.value((value) => {
11
11
  expect(Object.values(value).join()).toBe("1,2");
@@ -16,14 +16,15 @@ export interface GuestAwareAllType<T = any> extends GuestAwareObjectType<T> {
16
16
  export class GuestAwareAll<T> implements GuestAwareAllType<T> {
17
17
  private theAll: Source<Record<string, unknown>>;
18
18
 
19
- private keysKnown = new Set();
19
+ private keysKnown: Set<string>;
20
20
 
21
21
  private keysFilled = new Set();
22
22
 
23
23
  private filledAllPool = new GuestPool(this);
24
24
 
25
- public constructor() {
25
+ public constructor(initialKnownKeys: string[] = []) {
26
26
  this.theAll = new Source<Record<string, unknown>>({});
27
+ this.keysKnown = new Set(initialKnownKeys);
27
28
  }
28
29
 
29
30
  public valueArray(guest: GuestType<T>) {
@@ -61,22 +62,19 @@ export class GuestAwareAll<T> implements GuestAwareAllType<T> {
61
62
  public guestKey<R>(key: string): GuestObjectType<R> {
62
63
  this.keysKnown.add(key);
63
64
  return new Guest((value) => {
64
- // Обернул в очередь чтобы можно было синхронно наполнить очередь известных ключей
65
- queueMicrotask(() => {
66
- this.theAll.value(
67
- new Guest((all: Record<string, unknown>) => {
68
- this.keysFilled.add(key);
69
- const lastAll = {
70
- ...all,
71
- [key]: value,
72
- };
73
- this.theAll.give(lastAll);
74
- if (this.isAllFilled()) {
75
- this.filledAllPool.give(lastAll);
76
- }
77
- }),
78
- );
79
- });
65
+ this.theAll.value(
66
+ new Guest((all: Record<string, unknown>) => {
67
+ this.keysFilled.add(key);
68
+ const lastAll = {
69
+ ...all,
70
+ [key]: value,
71
+ };
72
+ this.theAll.give(lastAll);
73
+ if (this.isAllFilled()) {
74
+ this.filledAllPool.give(lastAll);
75
+ }
76
+ }),
77
+ );
80
78
  });
81
79
  }
82
80