subsiphon
Version:
RxJS subscription manager
3 lines (2 loc) • 3.98 kB
JavaScript
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("rxjs")):"function"==typeof define&&define.amd?define(["exports","rxjs"],n):n((e||self).subsiphon={},e.rxjs)}(this,function(e,n){function t(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=Array(n);t<n;t++)r[t]=e[t];return r}function r(e){var n=function(e){if("object"!=typeof e||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var t=n.call(e,"string");if("object"!=typeof t)return t;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof n?n:n+""}var o=/*#__PURE__*/function(){function e(){return this.subs={},this.index=0,new Proxy(this,{set:function(e,t,r){return t in e?"add"===t?(e.add=r,!0):(console.error("Attempted to add Subscription value to SubSiphon class methods: "+String(t)+" =",r),!1):r instanceof n.Subscription?(t in e.subs&&(e.subs[t].unsubscribe(),delete e.subs[t]),e.subs[t]=r,!0):(console.error("Attempted to add non-Subscription value to SubSiphon: "+String(t)+" =",r),!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 t,o,i=e.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]},t=e,(o=[{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 t=0;t<n.length;t++){var o=n[t];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,r(o.key),o)}}(t.prototype,o),Object.defineProperty(t,"prototype",{writable:!1}),t}(),i=new WeakMap,s=function(e){return e&&"function"==typeof e.unsubscribe},u=function(e,n,t){if(s(e))try{e.unsubscribe(),t.log&&console.debug("[Siphon] Unsubscribed: "+n)}catch(e){console.error("[Siphon] Error unsubscribing "+n,e)}else if(Array.isArray(e))for(var r=0;r<e.length;r++){var o=e[r];if(s(o))try{o.unsubscribe(),t.log&&console.debug("[Siphon] Unsubscribed: "+n+"["+r+"]")}catch(e){console.error("[Siphon] Error unsubscribing "+n+"["+r+"]",e)}else t.log&&console.warn("[Siphon] Skipped non-unsubscribable item in "+n+"["+r+"]")}else t.log&&console.warn("[Siphon] "+n+" is not unsubscribable")};e.Siphon=function(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 t;return!(null!=(t=e.exclude)&&t.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 c=n.value;o.includes(c)?u(this[c],c,e):console.warn('[Siphon] Property "'+c+'" does not exist on instance.')}"function"==typeof r&&r.apply(this)}}},e.SubSiphon=o,e.createSubSiphon=function(){return new o},e.siphon=function(e){if(!i.has(e)){var t=new n.Subject;i.set(e,t);var r=e.ngOnDestroy;e.ngOnDestroy=function(){t.next(),t.complete(),i.delete(e),"function"==typeof r&&r.apply(this)}}return n.takeUntil(i.get(e))}});
//# sourceMappingURL=index.umd.js.map