patron-oop 1.33.0 → 1.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/patron.cjs +62 -51
  3. package/dist/patron.cjs.map +1 -1
  4. package/dist/patron.d.ts +28 -24
  5. package/dist/patron.js +61 -51
  6. package/dist/patron.js.map +1 -1
  7. package/dist/patron.min.js +1 -1
  8. package/dist/patron.min.mjs +1 -1
  9. package/dist/patron.min.mjs.map +1 -1
  10. package/dist/patron.mjs +61 -51
  11. package/dist/patron.mjs.map +1 -1
  12. package/package.json +1 -1
  13. package/src/Factory/Module.test.ts +0 -2
  14. package/src/Guest/GuestAware.ts +17 -5
  15. package/src/Guest/GuestAwareActive.ts +2 -2
  16. package/src/Guest/{GuestChain._asArray.test.ts → GuestAwareAll._asArray.test.ts} +6 -6
  17. package/src/Guest/GuestAwareAll._twoValuesAfter.test.ts +16 -0
  18. package/src/Guest/GuestAwareAll._twoValuesBefore.test.ts +16 -0
  19. package/src/Guest/{GuestChain._withPatron.test.ts → GuestAwareAll._withPatron.test.ts} +6 -6
  20. package/src/Guest/GuestAwareAll.ts +88 -0
  21. package/src/Guest/GuestAwareMap.fn.test.ts +31 -0
  22. package/src/Guest/GuestAwareMap.test.ts +4 -3
  23. package/src/Guest/GuestAwareMap.ts +12 -11
  24. package/src/Guest/GuestAwareRace.ts +6 -6
  25. package/src/Guest/GuestAwareSequence.test.ts +5 -4
  26. package/src/Guest/GuestAwareSequence.ts +13 -13
  27. package/src/Source/Source.ts +2 -2
  28. package/src/Source/SourceDynamic.ts +2 -2
  29. package/src/index.ts +1 -1
  30. package/examples/elegant_objects.html +0 -118
  31. package/examples/reactive.html +0 -65
  32. package/src/Guest/GuestChain._twoValuesAfter.test.ts +0 -16
  33. package/src/Guest/GuestChain._twoValuesBefore.test.ts +0 -16
  34. package/src/Guest/GuestChain.ts +0 -88
@@ -1,65 +0,0 @@
1
- <!doctype html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8"/>
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
6
- <title>Reactive Patron</title>
7
- </head>
8
- <body>
9
- <h1>Reactive example</h1>
10
- <div>
11
- <label>
12
- Поле ввода:
13
- <input class="input-1"/>
14
- </label>
15
- </div>
16
- <div>Результат ввода: <span class="result"></span></div>
17
- <script type="module">
18
- import 'https://cdn.jsdelivr.net/npm/patron-oop@1.8.0/dist/patron.min.js';
19
-
20
- const {Patron, Source} = window.GUEST_LIBRARY;
21
-
22
- class Input {
23
- constructor(source, selector) {
24
- this.source = source;
25
- const el = document.querySelector(selector);
26
- this.source.value(
27
- new Patron((value) => {
28
- el.value = value;
29
- }),
30
- );
31
- el.addEventListener('keyup', (e) => {
32
- this.give(e.target.value);
33
- });
34
- el.addEventListener('change', (e) => {
35
- this.give(e.target.value);
36
- });
37
- }
38
-
39
- receiving(guest) {
40
- this.source.value(guest);
41
- return this;
42
- }
43
-
44
- receive(value) {
45
- this.source.give(value);
46
- return this;
47
- }
48
- }
49
-
50
- class Text {
51
- constructor(selector) {
52
- this.element = document.querySelector(selector);
53
- }
54
-
55
- receive(value) {
56
- this.element.innerText = value;
57
- }
58
- }
59
-
60
- new Input(new Source(2), '.input-1').value(
61
- new Patron(new Text('.result')),
62
- );
63
- </script>
64
- </body>
65
- </html>
@@ -1,16 +0,0 @@
1
- import { expect, test } from "vitest";
2
- import { Source } from "../Source/Source";
3
- import { GuestChain } from "./GuestChain";
4
-
5
- test("GuestChain._twoValuesAfter.test", () => {
6
- const one = new Source(1);
7
- const two = new Source(2);
8
- const chain = new GuestChain<{ one: number; two: number }>();
9
-
10
- chain.result((value) => {
11
- expect(Object.values(value).join()).toBe("1,2");
12
- });
13
-
14
- one.value(chain.receiveKey("one"));
15
- two.value(chain.receiveKey("two"));
16
- });
@@ -1,16 +0,0 @@
1
- import { expect, test } from "vitest";
2
- import { Source } from "../Source/Source";
3
- import { GuestChain } from "./GuestChain";
4
-
5
- test("GuestChain._twoValuesBefore.test", () => {
6
- const one = new Source(1);
7
- const two = new Source(2);
8
- const chain = new GuestChain<{ one: number; two: number }>();
9
-
10
- one.value(chain.receiveKey("one"));
11
- two.value(chain.receiveKey("two"));
12
-
13
- chain.result((value) => {
14
- expect(Object.values(value).join()).toBe("1,2");
15
- });
16
- });
@@ -1,88 +0,0 @@
1
- import { GuestCast } from "./GuestCast";
2
- import { Source } from "../Source/Source";
3
- import { Guest, GuestObjectType, GuestType } from "./Guest";
4
- import { GuestObject } from "./GuestObject";
5
- import { GuestPool } from "./GuestPool";
6
-
7
- export interface ChainType<T = any> {
8
- result(guest: GuestObjectType<T>): this;
9
- resultArray(guest: GuestObjectType<T>): this;
10
- receiveKey<R>(key: string): GuestObjectType<R>;
11
- }
12
-
13
- /**
14
- * @url https://kosukhin.github.io/patron.site/#/guest/guest-chain
15
- */
16
- export class GuestChain<T> implements ChainType<T> {
17
- private theChain: Source<Record<string, unknown>>;
18
-
19
- private keysKnown = new Set();
20
-
21
- private keysFilled = new Set();
22
-
23
- private filledChainPool = new GuestPool(this);
24
-
25
- public constructor() {
26
- this.theChain = new Source<Record<string, unknown>>({});
27
- }
28
-
29
- public resultArray(guest: GuestType<T>) {
30
- const guestObject = new GuestObject(guest);
31
- this.filledChainPool.add(
32
- new GuestCast(guestObject, (value: Record<string, unknown>) => {
33
- guestObject.give(Object.values(value) as T);
34
- }),
35
- );
36
- if (this.isChainFilled()) {
37
- this.theChain.value(
38
- new Guest((chain: Record<string, unknown>) => {
39
- this.filledChainPool.give(Object.values(chain));
40
- }),
41
- );
42
- }
43
- return this;
44
- }
45
-
46
- public result(guest: GuestType<T>) {
47
- const guestObject = new GuestObject(guest);
48
- if (this.isChainFilled()) {
49
- this.filledChainPool.add(guestObject);
50
- this.theChain.value(
51
- new Guest((chain) => {
52
- this.filledChainPool.give(chain);
53
- }),
54
- );
55
- } else {
56
- this.filledChainPool.add(guestObject);
57
- }
58
- return this;
59
- }
60
-
61
- public receiveKey<R>(key: string): GuestObjectType<R> {
62
- this.keysKnown.add(key);
63
- return new Guest((value) => {
64
- // Обернул в очередь чтобы можно было синхронно наполнить очередь известных ключей
65
- queueMicrotask(() => {
66
- this.theChain.value(
67
- new Guest((chain: Record<string, unknown>) => {
68
- this.keysFilled.add(key);
69
- const lastChain = {
70
- ...chain,
71
- [key]: value,
72
- };
73
- this.theChain.give(lastChain);
74
- if (this.isChainFilled()) {
75
- this.filledChainPool.give(lastChain);
76
- }
77
- }),
78
- );
79
- });
80
- });
81
- }
82
-
83
- private isChainFilled() {
84
- return (
85
- this.keysFilled.size > 0 && this.keysFilled.size === this.keysKnown.size
86
- );
87
- }
88
- }