subsiphon
Version:
RxJS subscription manager
3 lines (2 loc) • 3.83 kB
JavaScript
import{Subscription as e,Subject as n,takeUntil as r}from"rxjs";function t(e,n){(null==n||n>e.length)&&(n=e.length);for(var r=0,t=Array(n);r<n;r++)t[r]=e[r];return t}function o(e){var n=function(e){if("object"!=typeof e||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof n?n:n+""}var i=/*#__PURE__*/function(){function n(){return this.subs={},this.index=0,new Proxy(this,{set:function(n,r,t){return r in n?"add"===r?(n.add=t,!0):(console.error("Attempted to add Subscription value to SubSiphon class methods: "+String(r)+" =",t),!1):t instanceof e?(r in n.subs&&(n.subs[r].unsubscribe(),delete n.subs[r]),n.subs[r]=t,!0):(console.error("Attempted to add non-Subscription value to SubSiphon: "+String(r)+" =",t),!1)},get:function(e,n){return n in e?e[n]:e.subs.hasOwnProperty(n)?e.subs[n]:void 0},has:function(e,n){return n in e.subs},deleteProperty:function(e,n){return e.subs[n]&&(e.subs[n].unsubscribe(),delete e.subs[n]),!0},ownKeys:function(e){return Object.keys(e.subs)},getOwnPropertyDescriptor:function(e,n){if(n in e.subs)return{configurable:!0,enumerable:!0,writable:!0,value:e.subs[n]}}})}var r,t,i=n.prototype;return i.unsubscribe=function(){for(var e in this.subs)this.subs[e].unsubscribe()},i.destroy=function(){for(var e in this.subs)this.subs[e].unsubscribe(),delete this.subs[e]},r=n,(t=[{key:"add",set:function(e){for(var n=this.index;n in this.subs;)n+=1;this.index=n,this.subs[n]=e}}])&&function(e,n){for(var r=0;r<n.length;r++){var t=n[r];t.enumerable=t.enumerable||!1,t.configurable=!0,"value"in t&&(t.writable=!0),Object.defineProperty(e,o(t.key),t)}}(r.prototype,t),Object.defineProperty(r,"prototype",{writable:!1}),r}();function s(){return new i}var u=new WeakMap;function a(e){if(!u.has(e)){var t=new n;u.set(e,t);var o=e.ngOnDestroy;e.ngOnDestroy=function(){t.next(),t.complete(),u.delete(e),"function"==typeof o&&o.apply(this)}}return r(u.get(e))}var c=function(e){return e&&"function"==typeof e.unsubscribe},b=function(e,n,r){if(c(e))try{e.unsubscribe(),r.log&&console.debug("[Siphon] Unsubscribed: "+n)}catch(e){console.error("[Siphon] Error unsubscribing "+n,e)}else if(Array.isArray(e))for(var t=0;t<e.length;t++){var o=e[t];if(c(o))try{o.unsubscribe(),r.log&&console.debug("[Siphon] Unsubscribed: "+n+"["+t+"]")}catch(e){console.error("[Siphon] Error unsubscribing "+n+"["+t+"]",e)}else r.log&&console.warn("[Siphon] Skipped non-unsubscribable item in "+n+"["+t+"]")}else r.log&&console.warn("[Siphon] "+n+" is not unsubscribable")};function l(e){return void 0===e&&(e={}),function(n){var r=n.prototype.ngOnDestroy;n.prototype.ngOnDestroy=function(){for(var n,o=Object.keys(this),i=e.include?e.include:o.filter(function(n){var r;return!(null!=(r=e.exclude)&&r.includes(n))}),s=function(e){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,n){if(e){if("string"==typeof e)return t(e,n);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?t(e,n):void 0}}(e))){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(i);!(n=s()).done;){var u=n.value;o.includes(u)?b(this[u],u,e):console.warn('[Siphon] Property "'+u+'" does not exist on instance.')}"function"==typeof r&&r.apply(this)}}}export{l as Siphon,i as SubSiphon,s as createSubSiphon,a as siphon};
//# sourceMappingURL=index.esm.mjs.map