UNPKG

@nethesis/phone-island

Version:
3 lines (2 loc) 986 B
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./batch.js");const t={notify(){},get:()=>[]};exports.createSubscription=function(n,r){let u,c=t;function o(){i.onStateChange&&i.onStateChange()}function s(){u||(u=r?r.addNestedSub(o):n.subscribe(o),c=function(){const t=e.getBatch();let n=null,r=null;return{clear(){n=null,r=null},notify(){t((()=>{let e=n;for(;e;)e.callback(),e=e.next}))},get(){let e=[],t=n;for(;t;)e.push(t),t=t.next;return e},subscribe(e){let t=!0,u=r={callback:e,next:null,prev:r};return u.prev?u.prev.next=u:n=u,function(){t&&null!==n&&(t=!1,u.next?u.next.prev=u.prev:r=u.prev,u.prev?u.prev.next=u.next:n=u.next)}}}}())}const i={addNestedSub:function(e){return s(),c.subscribe(e)},notifyNestedSubs:function(){c.notify()},handleChangeWrapper:o,isSubscribed:function(){return Boolean(u)},trySubscribe:s,tryUnsubscribe:function(){u&&(u(),u=void 0,c.clear(),c=t)},getListeners:()=>c};return i}; //# sourceMappingURL=Subscription.js.map