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 +9 -0
- package/dist/patron.min.js +1 -1
- package/examples/reactive.html +37 -4
- package/package.json +1 -1
- package/rollup.config.js +1 -1
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
|
|
package/dist/patron.min.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";var
|
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)}))}}({});
|
package/examples/reactive.html
CHANGED
@@ -10,14 +10,47 @@
|
|
10
10
|
<div>
|
11
11
|
<label>
|
12
12
|
Поле ввода:
|
13
|
-
<input
|
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.
|
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