var c=Object.defineProperty;var u=(h,t,s)=>t in h?c(h,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):h[t]=s;var e=(h,t,s)=>(u(h,typeof t!="symbol"?t+"":t,s),s);class r{constructor(){e(this,"topics");e(this,"subUid");this.topics={},this.subUid=-1}subscribe(t,s){const i=typeof t=="string"?[t]:t,n=(++this.subUid).toString();return i.forEach(a=>{this.topics[a]||(this.topics[a]=[]),this.topics[a].push({token:n,func:s})}),n}async publish(t,s){if(!this.topics[t])return!1;const i=this.topics[t];let n=i?i.length:0;for(;n--;)await i[n].func(s);return!0}unsubscribe(t){for(const s in this.topics)if(this.topics[s]){for(let i=0,n=this.topics[s].length;i<n;i++)if(this.topics[s][i].token===t)return this.topics[s].splice(i,1),t}return!1}}class b{constructor(t,s,i){e(this,"initialState");e(this,"changes");e(this,"api");e(this,"idKey");e(this,"pubsub");this.initialState=s,this.changes={},this.api=t,this.idKey=i,this.pubsub=new r}get(t){var s;return(s=this.changes[t])!=null?s:this.initialState[t]}set(t,s){this.changes[t]=s}async save(){Object.keys(this.changes).length!==0&&(this.initialState=await this.api.update(this.initialState[this.idKey],this.changes),this.changes={},this.pubsub.publish("update"))}hasChanges(){return Object.keys(this.changes).length>0}get state(){return{...this.initialState,...this.changes}}}export{b as A};
//# sourceMappingURL=utils.3371dfe5.js.map
