patron-oop 1.2.0 → 1.3.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,15 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [1.3.0](https://github.com/kosukhin/patron/compare/v1.2.1...v1.3.0) (2024-10-13)
6
+
7
+
8
+ ### Features
9
+
10
+ * **main:** сделать min версию в iife формате ([c99a5e6](https://github.com/kosukhin/patron/commit/c99a5e6e74f1ca68dd3808070e410c8799ac9d04))
11
+
12
+ ### [1.2.1](https://github.com/kosukhin/patron/compare/v1.2.0...v1.2.1) (2024-10-13)
13
+
5
14
  ## [1.2.0](https://github.com/kosukhin/patron/compare/v1.1.0...v1.2.0) (2024-10-13)
6
15
 
7
16
 
@@ -1 +1 @@
1
- "use strict";var e=Object.defineProperty,t=(t,i,s)=>((t,i,s)=>i in t?e(t,i,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[i]=s)(t,"symbol"!=typeof i?i+"":i,s);const i=new Map;class s{constructor(e){this.initiator=e,t(this,"patrons",new Set),t(this,"receive"),i.set(this,this.patrons);let s=null;const r=(e,t)=>{this.patrons.forEach((i=>{this.sendValueToGuest(e,i,t)}))};this.receive=(e,t)=>{const i=()=>{i===s&&r(e,t)};return s=i,queueMicrotask(i),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 r=Object.defineProperty,o=(e,t,i)=>((e,t,i)=>t in e?r(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i)(e,t+"",i);class n{constructor(e,t=null,i=null){this.defaultValue=t,this.theCache=i,o(this,"pool"),this.pool=new s(e)}receive(e,t){return this.theCache=e,this.pool.receive(e,t),this}receiving(e){return null!==this.theCache?e.receive(this.theCache):null!==this.defaultValue&&e.receive(this.defaultValue),this.pool.add(e),this}}class h{constructor(e){this.receiver=e}receive(e,t){return this.receiver(e,t),this}}var c=Object.defineProperty,a=(e,t,i)=>((e,t,i)=>t in e?c(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i)(e,"symbol"!=typeof t?t+"":t,i);class u{constructor(e){a(this,"guests",new Set),a(this,"patronPool"),this.patronPool=new s(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 l{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 d=Object.defineProperty,v=(e,t,i)=>((e,t,i)=>t in e?d(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i)(e,"symbol"!=typeof t?t+"":t,i);var p=Object.defineProperty,b=(e,t,i)=>((e,t,i)=>t in e?p(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i)(e,t+"",i);var f=Object.defineProperty,w=(e,t,i)=>((e,t,i)=>t in e?f(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i)(e,t+"",i);exports.Cache=n,exports.Chain=class{constructor(){v(this,"theChain"),v(this,"keysKnown",new Set),v(this,"keysFilled",new Set),v(this,"filledChainPool",new u(this)),this.theChain=new n(this,{})}resultArray(e){return this.filledChainPool.add(new l(e,(e=>Object.values(e)))),this.isChainFilled()&&this.theChain.receiving(new h((e=>{this.filledChainPool.receive(Object.values(e))}))),this}result(e){return this.isChainFilled()?(this.filledChainPool.add(e),this.theChain.receiving(new h((e=>{this.filledChainPool.receive(e)})))):this.filledChainPool.add(e),this}receiveKey(e){return this.keysKnown.add(e),new h((t=>{queueMicrotask((()=>{this.theChain.receiving(new h((i=>{this.keysFilled.add(e);const s={...i,[e]:t};this.theChain.receive(s),this.isChainFilled()&&this.filledChainPool.receive(s)})))}))}))}isChainFilled(){return this.keysFilled.size>0&&this.keysFilled.size===this.keysKnown.size}},exports.Factory=class{constructor(e){this.constructorFn=e}create(...e){return new this.constructorFn(...e)}},exports.FactoryDynamic=class{constructor(e){this.creationFn=e}create(...e){return this.creationFn(...e)}},exports.FactoryWithFactories=class{constructor(e,t={}){this.constructorFn=e,this.factories=t}create(...e){return new this.constructorFn(...e,this.factories)}},exports.Guest=h,exports.GuestAware=class{constructor(e){this.guestReceiver=e}receiving(e){return this.guestReceiver(e),e}},exports.GuestCast=class{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}},exports.GuestInTheMiddle=l,exports.GuestPool=u,exports.GuestSync=class{constructor(e){this.theValue=e}receive(e){return this.theValue=e,this}value(){return this.theValue}},exports.Patron=class{constructor(e){this.willBePatron=e}introduction(){return"patron"}receive(e,t){return this.willBePatron.receive(e,t),this}},exports.PatronOnce=class{constructor(e){this.baseGuest=e,b(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}},exports.PatronPool=s,exports.Source=class{constructor(e){this.sourceDocument=e,w(this,"pool",new s(this))}receive(e){return this.sourceDocument=e,this.pool.receive(this.sourceDocument),this}receiving(e){return this.pool.distribute(this.sourceDocument,e),this}},exports.removePatronFromPools=e=>{i.forEach((t=>{t.delete(e)}))};
1
+ !function(e){"use strict";var t=Object.defineProperty,i=(e,i,s)=>((e,i,s)=>i in e?t(e,i,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[i]=s)(e,"symbol"!=typeof i?i+"":i,s);const s=new Map;class r{constructor(e){this.initiator=e,i(this,"patrons",new Set),i(this,"receive"),s.set(this,this.patrons);let t=null;const r=(e,t)=>{this.patrons.forEach((i=>{this.sendValueToGuest(e,i,t)}))};this.receive=(e,i)=>{const s=()=>{s===t&&r(e,i)};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 n=Object.defineProperty,o=(e,t,i)=>((e,t,i)=>t in e?n(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i)(e,t+"",i);class h{constructor(e,t=null,i=null){this.defaultValue=t,this.theCache=i,o(this,"pool"),this.pool=new r(e)}receive(e,t){return this.theCache=e,this.pool.receive(e,t),this}receiving(e){return null!==this.theCache?e.receive(this.theCache):null!==this.defaultValue&&e.receive(this.defaultValue),this.pool.add(e),this}}class c{constructor(e){this.receiver=e}receive(e,t){return this.receiver(e,t),this}}var u=Object.defineProperty,a=(e,t,i)=>((e,t,i)=>t in e?u(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i)(e,"symbol"!=typeof t?t+"":t,i);class l{constructor(e){a(this,"guests",new Set),a(this,"patronPool"),this.patronPool=new r(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 d{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 v=Object.defineProperty,b=(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);var p=Object.defineProperty,f=(e,t,i)=>((e,t,i)=>t in e?p(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i)(e,t+"",i);var w=Object.defineProperty,P=(e,t,i)=>((e,t,i)=>t in e?w(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i)(e,t+"",i);e.Cache=h,e.Chain=class{constructor(){b(this,"theChain"),b(this,"keysKnown",new Set),b(this,"keysFilled",new Set),b(this,"filledChainPool",new l(this)),this.theChain=new h(this,{})}resultArray(e){return this.filledChainPool.add(new d(e,(e=>Object.values(e)))),this.isChainFilled()&&this.theChain.receiving(new c((e=>{this.filledChainPool.receive(Object.values(e))}))),this}result(e){return this.isChainFilled()?(this.filledChainPool.add(e),this.theChain.receiving(new c((e=>{this.filledChainPool.receive(e)})))):this.filledChainPool.add(e),this}receiveKey(e){return this.keysKnown.add(e),new c((t=>{queueMicrotask((()=>{this.theChain.receiving(new c((i=>{this.keysFilled.add(e);const s={...i,[e]:t};this.theChain.receive(s),this.isChainFilled()&&this.filledChainPool.receive(s)})))}))}))}isChainFilled(){return this.keysFilled.size>0&&this.keysFilled.size===this.keysKnown.size}},e.Factory=class{constructor(e){this.constructorFn=e}create(...e){return new this.constructorFn(...e)}},e.FactoryDynamic=class{constructor(e){this.creationFn=e}create(...e){return this.creationFn(...e)}},e.FactoryWithFactories=class{constructor(e,t={}){this.constructorFn=e,this.factories=t}create(...e){return new this.constructorFn(...e,this.factories)}},e.Guest=c,e.GuestAware=class{constructor(e){this.guestReceiver=e}receiving(e){return this.guestReceiver(e),e}},e.GuestCast=class{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}},e.GuestInTheMiddle=d,e.GuestPool=l,e.GuestSync=class{constructor(e){this.theValue=e}receive(e){return this.theValue=e,this}value(){return this.theValue}},e.Patron=class{constructor(e){this.willBePatron=e}introduction(){return"patron"}receive(e,t){return this.willBePatron.receive(e,t),this}},e.PatronOnce=class{constructor(e){this.baseGuest=e,f(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}},e.PatronPool=r,e.Source=class{constructor(e){this.sourceDocument=e,P(this,"pool",new r(this))}receive(e){return this.sourceDocument=e,this.pool.receive(this.sourceDocument),this}receiving(e){return this.pool.distribute(this.sourceDocument,e),this}},e.removePatronFromPools=e=>{s.forEach((t=>{t.delete(e)}))}}({});
@@ -10,14 +10,47 @@
10
10
  <div>
11
11
  <label>
12
12
  Поле ввода:
13
- <input onkeyup="input.receive(this.value)">
13
+ <input class="input-1">
14
14
  </label>
15
15
  </div>
16
- <div>
16
+ <div>
17
17
  Результат ввода: <span class="result"></span>
18
18
  </div>
19
19
  <script type="module">
20
- import {Guest, Source, Patron} from 'https://cdn.jsdelivr.net/npm/patron-oop@1.1.0/dist/patron.mjs';
20
+ import {Guest, Source, Patron} from 'https://cdn.jsdelivr.net/npm/patron-oop@1.2.0/dist/patron.mjs';
21
+
22
+ // Presentation of input with relation to source value
23
+ class Input {
24
+ #source;
25
+
26
+ constructor(source) {
27
+ this.#source = source;
28
+ }
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
+ }
43
+
44
+ receiving(guest) {
45
+ this.#source.receiving(guest);
46
+ return this;
47
+ }
48
+
49
+ receive(value) {
50
+ this.#source.receive(value);
51
+ return this;
52
+ }
53
+ }
21
54
 
22
55
  class Text {
23
56
  constructor(selector) {
@@ -29,7 +62,7 @@
29
62
  }
30
63
  }
31
64
 
32
- window.input = new Source(1);
65
+ window.input = new Input(new Source(2)).bindTo('.input-1');
33
66
  input.receiving(new Patron(new Text('.result')));
34
67
  </script>
35
68
  </body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "patron-oop",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/patron.js",
package/rollup.config.js CHANGED
@@ -26,7 +26,7 @@ export default [
26
26
  },
27
27
  {
28
28
  file: `${name}.min.js`,
29
- format: "cjs",
29
+ format: "iife",
30
30
  plugins: [terser()],
31
31
  },
32
32
  ],