"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t,s,r=require("./utils/default-map.js"),i=require("./utils/disposables.js"),o=require("./utils/env.js"),n=Object.defineProperty,a=(e,t,s)=>(((e,t,s)=>{t in e?n(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s})(e,"symbol"!=typeof t?t+"":t,s),s),l=(e,t,s)=>{if(!t.has(e))throw TypeError("Cannot "+s)},c=(e,t,s)=>(l(e,t,"read from private field"),s?s.call(e):t.get(e)),u=(e,t,s)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,s)},d=(e,t,s,r)=>(l(e,t,"write to private field"),r?r.call(e,s):t.set(e,s),s);function p(e,t){return!!Object.is(e,t)||"object"==typeof e&&null!==e&&"object"==typeof t&&null!==t&&(Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&b(e[Symbol.iterator](),t[Symbol.iterator]()):e instanceof Map&&t instanceof Map||e instanceof Set&&t instanceof Set?e.size===t.size&&b(e.entries(),t.entries()):!(!f(e)||!f(t))&&b(Object.entries(e)[Symbol.iterator](),Object.entries(t)[Symbol.iterator]()))}function b(e,t){for(;;){let s=e.next(),r=t.next();if(s.done&&r.done)return!0;if(s.done||r.done||!Object.is(s.value,r.value))return!1}}function f(e){if("[object Object]"!==Object.prototype.toString.call(e))return!1;let t=Object.getPrototypeOf(e);return null===t||null===Object.getPrototypeOf(t)}e=new WeakMap,t=new WeakMap,s=new WeakMap,exports.Machine=class{constructor(n){u(this,e,{}),u(this,t,new r.DefaultMap((()=>new Set))),u(this,s,new Set),a(this,"disposables",i.disposables()),d(this,e,n),o.env.isServer&&this.disposables.microTask((()=>{this.dispose()}))}dispose(){this.disposables.dispose()}get state(){return c(this,e)}subscribe(t,r){if(o.env.isServer)return()=>{};let i={selector:t,callback:r,current:t(c(this,e))};return c(this,s).add(i),this.disposables.add((()=>{c(this,s).delete(i)}))}on(e,s){return o.env.isServer?()=>{}:(c(this,t).get(e).add(s),this.disposables.add((()=>{c(this,t).get(e).delete(s)})))}send(r){let i=this.reduce(c(this,e),r);if(i!==c(this,e)){d(this,e,i);for(let t of c(this,s)){let s=t.selector(c(this,e));p(t.current,s)||(t.current=s,t.callback(s))}for(let s of c(this,t).get(r.type))s(c(this,e),r)}}},exports.batch=function(e){let[t,s]=e(),r=i.disposables();return function(){t(...arguments),r.dispose(),r.microTask(s)}},exports.shallowEqual=p;
//# sourceMappingURL=machine.js.map
