insite-subscriptions-client
Version:
inSite subscriptions client side
3 lines (2 loc) • 21.4 kB
JavaScript
var Jt=Object.defineProperty;var Tt=o=>{throw TypeError(o)};var qt=(o,s,t)=>s in o?Jt(o,s,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[s]=t;var i=(o,s,t)=>qt(o,typeof s!="symbol"?s+"":s,t),yt=(o,s,t)=>s.has(o)||Tt("Cannot "+t);var a=(o,s,t)=>(yt(o,s,"read from private field"),t?t.call(o):s.get(o)),h=(o,s,t)=>s.has(o)?Tt("Cannot add the same private member more than once"):s instanceof WeakSet?s.add(o):s.set(o,t),d=(o,s,t,e)=>(yt(o,s,"write to private field"),e?e.call(o,t):s.set(o,t),t),g=(o,s,t)=>(yt(o,s,"access private method"),t);var wt,et,L,q=class{constructor(s,t,e=[],r,n=!0){i(this,"i");i(this,"type");i(this,"publicationName");i(this,"args");i(this,"handler");i(this,"immediately");i(this,"isActive");i(this,"start",()=>{L.sendMessage("s-s",this.type,this.publicationName,this.i,this.args,this.immediately),this.immediately=!0});if(!L)throw new Error("Subscription is not binded to WS. Do Subscription.bindTo(ws) first");this.i=wt++,this.type=s,this.publicationName=t,this.args=e,this.handler=r,this.immediately=n&&!globalThis.__initials,et.set(this.i,this),L.on("open",this.start),L.isOpen&&this.start(),globalThis.__initials?(this.isActive=!0,this.handler(globalThis.__initials.splice(0,1)[0])):this.isActive=!1}cancel(){et.delete(this.i),L.off("open",this.start),L.sendMessage("s-u",this.i)}static bindTo(s){L=s,wt=0,et=new Map,L.on("message:s-c",(t,e)=>{let r=et.get(t);r&&(r.isActive=!0,r.handler(e))}),L.on("close",()=>{for(let t of et.values())t.isActive=!1}),L.on("server-change",()=>{for(let t of et.values())t.handler(null)})}};function it(){}function lt(o,s=0,t={}){let{leading:e=!1,trailing:r=!0}=t,{maxWait:n=1/0}=t,u,f,p,c,b,l,m,S,ht=async()=>{let tt=Date.now();tt>=p?(u=void 0,p=void 0,clearTimeout(f),typeof m=="function"&&await m(),V.resolve(S),V.promise.isResolved=!0,l=e):(clearTimeout(u),u=setTimeout(ht,p-tt))},pt=Number.isFinite(n)?()=>{m===X&&(m=!1),X(),f=setTimeout(pt,n)}:null;async function X(){return S=await o.apply(c,b)}e&&typeof e=="boolean"&&(e=X),l=e,r&&typeof r=="boolean"&&(r=X),m=r;let V=Object.assign(function(...tt){return b=tt,c=this,p=Date.now()+s,m=r,V.promise.isResolved&&(V.promise=Object.assign(new Promise(Vt=>{V.resolve=Vt,typeof l=="function"&&(l(),l=!1,m===X&&(m=!1)),u||(u=setTimeout(ht,s),pt&&(f=setTimeout(pt,n)))}),{isResolved:!1})),V.promise},{callback:o,promise:Object.assign(Promise.resolve(),{isResolved:!0}),resolve:it,run:X,clear:async tt=>{clearTimeout(u),u=void 0,clearTimeout(f),V.promise.isResolved=!0,V.resolve(tt?await X():S)}});return V}lt.noop=Object.assign(()=>{},{callback:it,promise:Object.assign(Promise.resolve(),{isResolved:!0}),resolve:it,run:it,clear:it});function Ot(o,s,t,e,r=!0){return Array.isArray(o)&&(o=o.length),typeof e!="string"&&(r=e??!0,e=t),(r?`${o}\xA0`:"")+Ot.raw(o,s,t,e)}Ot.raw=(o,s,t,e=t)=>{o=Math.abs(o);let r=o%10,n=o%100;return r===1&&n!==11?s:r>=2&&r<=4&&!(n>=12&&n<=15)?t:e};function Q(o,s){let t=o.indexOf(s);return t>-1?(o.splice(t,1),!0):!1}var ct=new WeakMap,x=class extends Promise{constructor(t){let e,r;super((n,u)=>{e=n,r=u});i(this,"isPending",!0);i(this,"isFulfilled",!1);i(this,"isRejected",!1);i(this,"state","pending");i(this,"result");i(this,"resolve",t=>{if(this.isPending){this.isPending=!1,this.isFulfilled=!0,this.state="fulfilled",this.result=t;let e=ct.get(this);e&&(e.resolve.call(this,t),ct.delete(this))}});i(this,"reject",t=>{if(this.isPending){this.isPending=!1,this.isRejected=!0,this.state="rejected",this.result=t;let e=ct.get(this);e&&(e.reject.call(this,t),ct.delete(this))}});ct.set(this,{resolve:e,reject:r}),t?.(this.resolve,this.reject)}};function At(o){return[...new Set(o)]}var O=Symbol("update"),A=Symbol("getHandleUpdate"),U=Symbol("setHandleUpdate"),D=Symbol("getAsUpdates"),H=Symbol("getAsInitialUpdated"),_=Symbol("clear"),y=Symbol("subscribe"),I=Symbol("unsubscribe"),j=Symbol("renew"),$=Symbol("getSubscription"),zt=Symbol("getHandleSubscription"),Kt=Symbol("setHandleSubscription");var Xt=(o,s)=>o>s?1:o<s?-1:0,Qt=(o,s)=>o>s?-1:o<s?1:0,Dt,Ht,jt,Pt,P=class extends Array{constructor(t,e){super();i(this,"sorted",[]);i(this,"handleUpdate");i(this,"sortDirection",0);i(this,"sortCompareFunction",null);i(this,Pt,this.update);i(this,jt,this.getAsUpdates);i(this,Ht,this.getAsInitialUpdated);i(this,Dt,this.clear);e&&(this.handleUpdate=e),Array.isArray(t)&&this.update(t)}[A](){return this.handleUpdate}[U](t){return this.handleUpdate=t}update(t){let e=Object.assign([],{deleted:[],added:[]});if(t){let r=!1;for(let n of t)switch(n?.[0]){case"i":{let[,u,f]=n;f?(this.sortDirection=f,this.sortCompareFunction=f>0?Xt:Qt,r=!0):(this.sortDirection=0,this.sortCompareFunction=null),this.length=0;for(let p of u)this.push(p),e.push(p),e.added.push(p);break}case"a":{let[,u]=n;this.includes(u)||(this.push(u),this.sortDirection&&(r=!0),e.push(u),e.added.push(u));break}case"d":{let[,u]=n;Q(this,u)&&e.deleted.push(u);break}default:this.clear()}r&&this.sortCompareFunction&&this.sort(this.sortCompareFunction)}else this.clear();return this.handleUpdate?.(this,e,t?.[0]?t:null),this}getAsUpdates(){return this.length||this.sortDirection?[["i",[...this],this.sortDirection]]:null}getAsInitialUpdated(){return Object.assign([...this.sorted],{added:[...this.sorted],deleted:[]})}clear(){this.length=0,this.sortDirection=0,this.sortCompareFunction=null}valueOf(){return this}get[(Pt=O,jt=D,Ht=H,Dt=_,Symbol.toStringTag)](){return"SubscriptionArray"}};i(P,"updateSymbol",O),i(P,"getHandleUpdateSymbol",A),i(P,"setHandleUpdateSymbol",U),i(P,"getAsUpdatesSymbol",D),i(P,"getAsInitialUpdatedSymbol",H),i(P,"clearSymbol",_),i(P,"WithSubscription");var G=class extends P{constructor(t,e,r,n=!0){super(null,r);i(this,"publicationName");i(this,"params");i(this,"subscription",null);this.publicationName=t,this.params=e,n&&this.subscribe()}subscribe(){this.subscription||(this.subscription=new q("array",this.publicationName,this.params,t=>this.update(t)))}get[y](){return this.subscribe}unsubscribe(){this.subscription&&(this.subscription.cancel(),this.subscription=null)}get[I](){return this.unsubscribe}renew(t,e){this.subscription&&(this.unsubscribe(),t&&(Array.isArray(t)?e=t:this.publicationName=t),e&&(this.params=e),this.subscribe())}get[j](){return this.renew}[$](){return this.subscription}get[Symbol.toStringTag](){return"SubscriptionArrayWithSubscription"}};i(G,"subscribeSymbol",y),i(G,"unsubscribeSymbol",I),i(G,"renewSymbol",j),i(G,"getSubscriptionSymbol",$);P.WithSubscription=G;import te from"eventemitter3";var v={};import Zt from"eventemitter3";function Yt(o){let s=document.createElement("script");s.textContent=`window.__insite_subscription_map_sort_function = function sort(a, b) { return ${Object.entries(o).map(([e,r])=>r>0?`a.${e} > b.${e} ? 1 : a.${e} < b.${e} ? -1 :`:`a.${e} < b.${e} ? 1 : a.${e} > b.${e} ? -1 :`).concat("0").join(" ")};}`,document.head.append(s);let t=globalThis.__insite_subscription_map_sort_function;return s.remove(),delete globalThis.__insite_subscription_map_sort_function,t}var kt,_t,Lt,$t,st,Y,rt,T=class extends Map{constructor(t,e){super();i(this,"handleUpdate");h(this,st,new Map);i(this,"sortList",null);i(this,"sortCompareFunction",null);h(this,Y,[]);i(this,"sorted",[]);h(this,rt);i(this,$t,this.update);i(this,Lt,this.getAsUpdates);i(this,_t,this.getAsInitialUpdated);i(this,kt,this.clear);e&&(this.handleUpdate=e),t&&this.update(t)}sort(){this.sortCompareFunction&&this.sorted.sort(this.sortCompareFunction)}[A](){return this.handleUpdate}[U](t){return this.handleUpdate=t}set Item(t){if(d(this,rt,t),this.size)for(let[e,r]of this)this.set(e,new t(this,r))}get Item(){return a(this,rt)}update(t){let e=Object.assign([],{added:[],deleted:[]});if(t){let r=!1,n=a(this,rt),u=a(this,st);for(let f of t)switch(f?.[0]){case"i":{let[,p,c]=f;if(c?(this.sortList=c,this.sortCompareFunction=Yt(c),d(this,Y,At(Object.keys(c).map(b=>b.replace(/\..+/,"")))),r=!0):(this.sortList=null,this.sortCompareFunction=null,d(this,Y,[])),this.size){let b=new Map;for(let l of p)b.set(l._id,l);for(let[l,m]of this){let S=b.get(l);if(S){let ht=u.get(l);if(n)m.update(S);else{for(let pt in ht)delete m[pt];Object.assign(m,S)}u.set(l,S),e.push(m),b.delete(l)}else n?m.delete():this.delete(l),u.delete(l),e.deleted.push(l)}for(let[l,m]of b){let S=n?new n(this,m):{...m};this.set(l,S),u.set(l,m),e.push(S),e.added.push(S)}this.sortList&&(this.sorted=p.map(l=>this.get(l._id)))}else for(let b of p){let l=n?new n(this,b):{...b};this.set(l._id,l),this.sorted.push(l),u.set(l._id,b),e.push(l),e.added.push(l)}break}case"c":case"u":{let[,p]=f,c=this.get(p._id);if(c){let b=f[2]===!0,l=b?Object.keys(p):f[2],m=u.get(c._id);if(n)c.update(p);else{if(!b)for(let S in m)delete c[S];Object.assign(c,p)}b&&(p=Object.assign(m,p)),this.sortList&&!r&&(!l||l.some(S=>a(this,Y).includes(S)))&&(r=!0)}else c=n?new n(this,p):{...p},this.set(c._id,c),this.sorted.push(c),this.sortList&&(r=!0),e.added.push(c);u.set(c._id,p),e.push(c);break}case"d":{let[,p]=f,c=this.get(p);c&&(n?c.delete():this.delete(p),u.delete(p),Q(this.sorted,c),e.deleted.push(p));break}default:this.clear()}r&&this.sort()}else this.clear();return this.handleUpdate?.(this,e,t?.[0]?t:null),this}getAsUpdates(){return this.size||this.sortList?[["i",[...a(this,st).values()],this.sortList]]:null}getAsInitialUpdated(){return Object.assign([...this.sorted],{added:[...this.sorted],deleted:[]})}clear(){super.clear(),a(this,st).clear(),this.sorted=[],this.sortList=null,this.sortCompareFunction=null,d(this,Y,[])}valueOf(){return this.sorted}get[($t=O,Lt=D,_t=H,kt=_,Symbol.toStringTag)](){return"SubscriptionMap"}};st=new WeakMap,Y=new WeakMap,rt=new WeakMap,i(T,"updateSymbol",O),i(T,"getHandleUpdateSymbol",A),i(T,"setHandleUpdateSymbol",U),i(T,"getAsUpdatesSymbol",D),i(T,"getAsInitialUpdatedSymbol",H),i(T,"clearSymbol",_),i(T,"WithSubscription"),i(T,"Item");var M=class extends T{constructor(t,e,r,n=!0){super(null,r);i(this,"publicationName");i(this,"params");i(this,"subscription",null);this.publicationName=t,this.params=e,n&&this.subscribe()}subscribe(){this.subscription||(this.subscription=new q("map",this.publicationName,this.params,t=>this.update(t)))}get[y](){return this.subscribe}unsubscribe(){this.subscription&&(this.subscription.cancel(),this.subscription=null)}get[I](){return this.unsubscribe}renew(t,e){this.subscription&&(this.unsubscribe(),t&&(Array.isArray(t)?e=t:this.publicationName=t),e&&(this.params=e),this.subscribe())}get[j](){return this.renew}[$](){return this.subscription}get[Symbol.toStringTag](){return"SubscriptionMapWithSubscription"}};i(M,"subscribeSymbol",y),i(M,"unsubscribeSymbol",I),i(M,"renewSymbol",j),i(M,"getSubscriptionSymbol",$);T.WithSubscription=M;var dt,gt=class{constructor(s,t){i(this,"_id");h(this,dt);d(this,dt,s),this.update(t)}update(s){Object.assign(this,s)}delete(){a(this,dt).delete(this._id)}};dt=new WeakMap;T.Item=gt;var ft=Symbol("handleUpdate"),z=Symbol("updates"),Gt,Mt,k=class{constructor(s,t){i(this,Mt);i(this,Gt,null);t&&(this[ft]=t),s&&this[O](s)}[(Mt=ft,Gt=z,A)](){return this[ft]}[U](s){return this[ft]=s}[O](s){if(s){for(let t in this[z])delete this[t];for(let t in s)this[t]=s[t];this[z]=s}else this[_]();return this[ft]?.(this,this,this[z]),this}[D](){return this[z]&&{...this[z]}}[H](){return this.valueOf()}[_](){for(let s in this)delete this[s];this[z]=null}valueOf(){return this[z]&&this}get[Symbol.toStringTag](){return"SubscriptionObject"}};i(k,"updateSymbol",O),i(k,"getHandleUpdateSymbol",A),i(k,"setHandleUpdateSymbol",U),i(k,"getAsUpdatesSymbol",D),i(k,"getAsInitialUpdatedSymbol",H),i(k,"clearSymbol",_),i(k,"WithSubscription");var ot,nt,B,F=class extends k{constructor(t,e,r,n=!0){super(null,r);h(this,ot);h(this,nt);h(this,B,null);d(this,ot,t),d(this,nt,e),n&&this[y]()}[y](){a(this,B)||d(this,B,new q("object",a(this,ot),a(this,nt),t=>this[O](t)))}[I](){a(this,B)&&(a(this,B).cancel(),d(this,B,null))}[j](t,e){a(this,B)&&(this[I](),t&&(Array.isArray(t)?e=t:d(this,ot,t)),e&&d(this,nt,e),this[y]())}[$](){return a(this,B)}get[Symbol.toStringTag](){return"SubscriptionObjectWithSubscription"}};ot=new WeakMap,nt=new WeakMap,B=new WeakMap,i(F,"subscribeSymbol",y),i(F,"unsubscribeSymbol",I),i(F,"renewSymbol",j),i(F,"getSubscriptionSymbol",$);k.WithSubscription=F;function Bt(o){return Array.isArray(o)}var R,K,E,w,xt,Ft,J,at,Rt,Et,Ut,bt=class bt extends Zt{constructor(t,e){super();h(this,w);i(this,"name");i(this,"group");i(this,"value");i(this,"type");i(this,"publicationName");i(this,"params");i(this,"handle");i(this,"onBeforeInit");i(this,"preventBind");i(this,"emitUpdate");i(this,"isLoaded",!1);i(this,"isInited",!1);h(this,R);h(this,K);h(this,E);h(this,J,null);h(this,at,(t,e,r)=>{if(r)if(this.group.isLoaded){if(this.handle)switch(this.type){case"array":this.handle.call(this.group,e,this.group);break;case"map":this.handle.call(this.group,e,this.group);break;default:this.handle.call(this.group,e,this.group)}this.emitUpdate(e)}else d(this,J,e),this.isLoaded=!0,v.groupLoad(this.group);else this.isLoaded&&(this.isLoaded=!1,v.groupUnload(this.group));this.isInited||(this.isInited=!0,v.groupInit(this.group))});this.name=t.name,this.define(t,e)}define(t,e=this.group){if(!e)throw new Error("group is undefined");let{value:r,type:n="object",publicationName:u,params:f,handle:p,onBeforeInit:c,debounce:b=bt.debounceLimit,preventBind:l}=t;if(this.group){if((!r||this.value===r)&&this.type===n&&this.publicationName===u&&JSON.stringify(this.params)===JSON.stringify(f)&&this.handle===p&&this.onBeforeInit===c)return g(this,w,xt).call(this,{debounceLimit:b,preventBind:l});this.detach(),delete this.value,delete this.publicationName,delete this.params}this.type=n,this.handle=p,this.onBeforeInit=c,r?this.value=r:(this.publicationName=u??this.name,this.params=f??[]),g(this,w,xt).call(this,{debounceLimit:b,preventBind:l}),g(this,w,Ft).call(this,e)}detach(){this.group&&(this.value?.[I](),this.isLoaded=!1,g(this,w,Ut).call(this),delete this.group.values[this.name],Q(this.group.values,this.value),delete this.group.items[this.name],Q(this.group.items,this),delete this.group)}loaded(){return a(this,R)}inited(){return a(this,K)}unloaded(){return a(this,E)}subscribe(){if(this.value){if(this.value[y])return this.value[y]();{let t=this.value[A]();if(t){let e=this.value[H](),r=this.value[D]();switch(this.type){case"array":return t(this.value,e,r);case"map":return t(this.value,e,r);default:return t(this.value,e,r)}}}}}unsubscribe(){return this.value?.[I]?.()}renew(t,e){return this.value?.[j]?.(t,e)}valueOf(){return this.value}};R=new WeakMap,K=new WeakMap,E=new WeakMap,w=new WeakSet,xt=function({debounceLimit:t,preventBind:e}){let r=n=>{this.emit("update",this.value,n),this.group?.emit(`update.${this.name}`,this.value,n),this.group?.emitUpdate()};if(typeof t=="number"){let n,u,f=lt(()=>{let p=!this.group;p&&(this.group=u),r(n),p&&delete this.group,n=void 0},t);this.emitUpdate=p=>{if(p!==void 0)if(Bt(p))if(Bt(n))for(let c of p)n.push(c);else n=Object.assign([...p],{added:[...p.added],deleted:[...p.deleted]});else typeof p=="object"?n?Object.assign(n,p):n={...p}:n=p;return u=this.group,f()}}else this.emitUpdate=r;this.preventBind===void 0?delete this.preventBind:this.preventBind=e},Ft=function(t){if(!this.group){switch(this.group=t,this.group.items.push(this),this.group.items[this.name]=this,(!a(this,R)||a(this,R).isFulfilled)&&d(this,R,new x),(!a(this,K)||a(this,K).isFulfilled)&&d(this,K,new x),(!a(this,E)||a(this,E).isFulfilled)&&d(this,E,new x),this.type){case"array":{let e=a(this,at);this.value?this.value[U](e):this.value=new G(this.publicationName,this.params,e,!1);break}case"map":{let e=a(this,at);this.value?this.value[U](e):this.value=new M(this.publicationName,this.params,e,!1);break}default:{let e=a(this,at);this.value?this.value[U](e):this.value=new F(this.publicationName,this.params,e,!1)}}if(this.group.values.push(this.value),this.group.values[this.name]=this.value,this.onBeforeInit)switch(this.type){case"array":this.onBeforeInit.call(this.group,this.value);break;case"map":this.onBeforeInit.call(this.group,this.value);break;default:this.onBeforeInit.call(this.group,this.value)}}},J=new WeakMap,at=new WeakMap,Rt=function(){if(a(this,J)){if(this.handle)switch(this.type){case"array":this.handle.call(this.group,a(this,J),this.group);break;case"map":this.handle.call(this.group,a(this,J),this.group);break;default:this.handle.call(this.group,a(this,J),this.group)}d(this,J,null),this.emit("load",this.value),a(this,R).resolve(this),a(this,E).isFulfilled&&d(this,E,new x)}},Et=function(){this.emit("init",this.value),a(this,K).resolve(this)},Ut=function(){if(this.handle)switch(this.type){case"array":this.handle.call(this.group,null,this.group);break;case"map":this.handle.call(this.group,null,this.group);break;default:this.handle.call(this.group,null,this.group)}this.emit("unload",this.value),a(this,E).resolve(this),a(this,R).isFulfilled&&d(this,R,new x)},i(bt,"debounceLimit",4),v.itemLoad=t=>{var e;return g(e=t,w,Rt).call(e)},v.itemInit=t=>{var e;return g(e=t,w,Et).call(e)},v.itemUnload=t=>{var e;return g(e=t,w,Ut).call(e)};var mt=bt;function ee(o){return Array.isArray(o)}function Wt(o){if(ee(o)){let s=o.slice(),t={};if(t.name=s.shift(),typeof s[0]=="object"&&!Array.isArray(s[0])){if(t.value=s.shift(),t.type=t.value.toString().match(/Subscription(Object|Array|Map)/)?.[1].toLowerCase(),!t.type)throw new Error("Unknown value type")}else typeof s[0]=="string"&&(t.type=s.shift()),typeof s[0]=="string"&&(t.publicationName=s.shift()),Array.isArray(s[0])&&(t.params=s.shift());return typeof s[0]=="function"&&(t.handle=s.shift()),typeof s[0]=="function"&&(t.onBeforeInit=s.shift()),typeof s[0]=="number"&&(t.debounce=s.shift()),typeof s[0]=="boolean"&&(t.preventBind=s.shift()),t}return o.type??(o.type="object"),o}var W,ut,N,Z,C,It,Ct,vt,St=class St extends te{constructor(t,{target:e,debounce:r=St.debounceLimit,immediately:n}={}){super();h(this,C);i(this,"target");i(this,"emitUpdate");i(this,"items",[]);i(this,"values",[]);i(this,"isLoaded",!1);i(this,"isInited",!1);h(this,W);h(this,ut);h(this,N);h(this,Z,null);this.applyOptions({target:e,debounceLimit:r}),d(this,ut,new x),this.attach(t,!1,n)}applyOptions({target:t,debounceLimit:e}){if(this.target!==t){if(this.target)for(let r of this.items)r.isLoaded&&!r.preventBind&&delete this.target[r.name];if(this.target=t,this.target)for(let r of this.items)r.isLoaded&&!r.preventBind&&(this.target[r.name]=r.value)}if(a(this,Z)!==e)if(d(this,Z,e),typeof a(this,Z)=="number"){let r=lt(()=>this.emit("update",this.values),a(this,Z));this.emitUpdate=()=>r()}else this.emitUpdate=()=>this.emit("update",this.values)}attach(t,e=this.isLoaded,r=!0){return e&&(this.isLoaded=!1),(!a(this,W)||a(this,W).isFulfilled)&&d(this,W,new x),(!a(this,N)||a(this,N).isFulfilled)&&d(this,N,new x),Promise.all(t.map(n=>new mt(Wt(n),this)).map(n=>(r&&n.subscribe(),n.loaded())))}detach(t,e=!0){for(let r of t)this.items[r]?.detach();e&&(g(this,C,vt).call(this),g(this,C,It).call(this))}redefine(t){let e=new Map(this.items.map(u=>[u.name,u])),r=[],n=[];for(let u of t)u=Wt(u),e.delete(u.name)?r.push(u):n.push(u);return this.isLoaded=!1,this.detach([...e.keys()],!1),Promise.all([...r.map(u=>{let f=this.items[u.name];return f.define(u),f.subscribe(),f.loaded()}),...n.length?[this.attach(n,!1)]:[]])}subscribe(){return this.items.map(t=>t.subscribe())}unsubscribe(){return this.items.map(t=>t.unsubscribe())}loaded(){return a(this,W)}inited(){return a(this,ut)}unloaded(){return a(this,N)}valueOf(){return this.values}[Symbol.iterator](){return this.values[Symbol.iterator]()}};W=new WeakMap,ut=new WeakMap,N=new WeakMap,Z=new WeakMap,C=new WeakSet,It=function(){if(!this.isLoaded&&this.items.every(t=>t.isLoaded)){if(this.target)for(let t of this.items)t.preventBind||(this.target[t.name]=t.value);this.isLoaded=!0;for(let t of this.items)v.itemLoad(t);if(this.emit("load",this.values),this.isInited)if(this.items.length)for(let t of this.items)t.emitUpdate();else this.emitUpdate();a(this,W).resolve(this),a(this,N).isFulfilled&&d(this,N,new x)}},Ct=function(){if(!this.isInited&&this.items.every(t=>t.isInited)){if(this.isInited=!0,this.isLoaded)if(this.items.length)for(let t of this.items)t.emitUpdate();else this.emitUpdate();for(let t of this.items)v.itemInit(t);this.emit("init",this.values),a(this,ut).resolve(this)}},vt=function(){if(this.isLoaded&&this.items.every(t=>!t.isLoaded)){if(this.target)for(let t of this.items)t.preventBind||delete this.target[t.name];this.isLoaded=!1;for(let t of this.items)v.itemUnload(t);if(this.emit("unload",this.values),this.items.length)for(let t of this.items)t.emitUpdate();else this.emitUpdate();a(this,N).resolve(this),a(this,W).isFulfilled&&d(this,W,new x)}},i(St,"debounceLimit",8),v.groupLoad=t=>{var e;return g(e=t,C,It).call(e)},v.groupInit=t=>{var e;return g(e=t,C,Ct).call(e)},v.groupUnload=t=>{var e;return g(e=t,C,vt).call(e)};var Nt=St;export{q as Subscription,P as SubscriptionArray,G as SubscriptionArrayWithSubscription,Nt as SubscriptionGroup,T as SubscriptionMap,M as SubscriptionMapWithSubscription,k as SubscriptionObject,F as SubscriptionObjectWithSubscription,_ as clearSymbol,H as getAsInitialUpdatedSymbol,D as getAsUpdatesSymbol,zt as getHandleSubscriptionSymbol,A as getHandleUpdateSymbol,$ as getSubscriptionSymbol,j as renewSymbol,Kt as setHandleSubscriptionSymbol,U as setHandleUpdateSymbol,y as subscribeSymbol,I as unsubscribeSymbol,O as updateSymbol};
//# sourceMappingURL=index.js.map