UNPKG

rxjs-autorun

Version:

Autorun expressions with RxJS Observables

1 lines 4.01 kB
!function(r,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("rxjs/operators"),require("rxjs")):"function"==typeof define&&define.amd?define("rxjs-autorun",["rxjs/operators","rxjs"],t):"object"==typeof exports?exports["rxjs-autorun"]=t(require("rxjs/operators"),require("rxjs")):r["rxjs-autorun"]=t(r.rxjs.operators,r.rxjs)}(window,(function(r,t){return function(r){var t={};function e(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return r[n].call(o.exports,o,o.exports,e),o.l=!0,o.exports}return e.m=r,e.c=t,e.d=function(r,t,n){e.o(r,t)||Object.defineProperty(r,t,{enumerable:!0,get:n})},e.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})},e.t=function(r,t){if(1&t&&(r=e(r)),8&t)return r;if(4&t&&"object"==typeof r&&r&&r.__esModule)return r;var n=Object.create(null);if(e.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:r}),2&t&&"string"!=typeof r)for(var o in r)e.d(n,o,function(t){return r[t]}.bind(null,o));return n},e.n=function(r){var t=r&&r.__esModule?function(){return r.default}:function(){return r};return e.d(t,"a",t),t},e.o=function(r,t){return Object.prototype.hasOwnProperty.call(r,t)},e.p="/dist/",e(e.s=2)}([function(t,e){t.exports=r},function(r,e){r.exports=t},function(r,t,e){"use strict";e.r(t),e.d(t,"$",(function(){return d})),e.d(t,"_",(function(){return p})),e.d(t,"autorun",(function(){return b})),e.d(t,"combined",(function(){return v})),e.d(t,"computed",(function(){return h}));var n=e(0),o=e(1),u=function(r){var t="function"==typeof Symbol&&Symbol.iterator,e=t&&r[t],n=0;if(e)return e.call(r);if(r&&"number"==typeof r.length)return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")},i=Object.create(null),c=new Error("$ or _ can only be called within computed or autorun context"),a=function(){throw c};a.weak=a,a.normal=a,a.strong=a;var f={_:a,$:a},s=function(r){var t=function(t){return f[r](t)};return t.weak=function(t){return f[r].weak(t)},t.normal=function(t){return f[r].normal(t)},t.strong=function(t){return f[r].strong(t)},t},l=function(r,t){return void 0===t&&(t=!1),new o.Observable((function(e){var c=new Map,a={$:v(!0),_:v(!1)},s=new o.Subscription((function(){c.forEach((function(r){r.subscription.unsubscribe()}))})),l=!0;return d(),s;function d(){var t=[];c.forEach((function(r){r.track=!1,r.used=!1,1===r.strength&&(r.strength=0,t.push(r))}));var n=f;f=a;try{var o=r();b(1),e.next(o)}catch(r){r===i?(t.forEach((function(r){r.strength=1})),b(0)):(e.error(r),l=!1)}finally{f=n,l&&p()}}function p(){var r,t;l=!1;try{for(var n=u(c.values()),o=n.next();!o.done;o=n.next()){var i=o.value;if(i.track&&!i.completed)return}}catch(t){r={error:t}}finally{try{o&&!o.done&&(t=n.return)&&t.call(n)}finally{if(r)throw r.error}}e.complete()}function b(r){c.forEach((function(t,e){t.used||t.strength>r||(t.subscription.unsubscribe(),c.delete(e))}))}function v(r){var t=h(r,1);return t.weak=h(r,0),t.normal=h(r,1),t.strong=h(r,2),t}function h(r,u){return function(a){if(c.has(a)){var f=c.get(a);if(f.used=!0,r&&!f.track&&(f.track=!0),u>f.strength&&(f.strength=u),f.hasValue)return f.value;throw i}var s={hasValue:!1,value:void 0,subscription:new o.Subscription,strength:u,track:!0,used:!0,completed:!1};c.set(a,s);var b=!1,v=!1,h=void 0;if(s.subscription.add((t?a.pipe(Object(n.distinctUntilChanged)()):a).subscribe({next:function(t){var e=s.hasValue;s.hasValue=!0,s.value=t;var n=!e&&!r;n&&(l=!0),b&&s.track&&d(),n&&(s.track=!1)},error:function(r){b?e.error(r):(h=r,v=!0)},complete:function(){s.completed=!0,s.hasValue||(e.complete(),b||(v=!0,h=i)),b&&s.track&&p()}})),v)throw h;if(b=!0,s.hasValue)return s.value;throw i}}}))},d=s("$"),p=s("_");function b(r){return v(r).subscribe()}function v(r){return l(r)}function h(r){return l(r,!0).pipe(Object(n.distinctUntilChanged)())}}])}));