import{getBatch as n}from"./batch.js";var t={notify:function(){}};var e=function(){function e(n,e){this.store=n,this.parentSub=e,this.unsubscribe=null,this.listeners=t,this.handleChangeWrapper=this.handleChangeWrapper.bind(this)}var s=e.prototype;return s.addNestedSub=function(n){return this.trySubscribe(),this.listeners.subscribe(n)},s.notifyNestedSubs=function(){this.listeners.notify()},s.handleChangeWrapper=function(){this.onStateChange&&this.onStateChange()},s.isSubscribed=function(){return Boolean(this.unsubscribe)},s.trySubscribe=function(){var t,e,s;this.unsubscribe||(this.unsubscribe=this.parentSub?this.parentSub.addNestedSub(this.handleChangeWrapper):this.store.subscribe(this.handleChangeWrapper),this.listeners=(t=n(),e=null,s=null,{clear:function(){e=null,s=null},notify:function(){t((function(){for(var n=e;n;)n.callback(),n=n.next}))},get:function(){for(var n=[],t=e;t;)n.push(t),t=t.next;return n},subscribe:function(n){var t=!0,r=s={callback:n,next:null,prev:s};return r.prev?r.prev.next=r:e=r,function(){t&&null!==e&&(t=!1,r.next?r.next.prev=r.prev:s=r.prev,r.prev?r.prev.next=r.next:e=r.next)}}}))},s.tryUnsubscribe=function(){this.unsubscribe&&(this.unsubscribe(),this.unsubscribe=null,this.listeners.clear(),this.listeners=t)},e}();export default e;
//# sourceMappingURL=Subscription.js.map
