forked from Reactive-Extensions/RxJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rx.time.min.js
1 lines (1 loc) · 9.27 KB
/
rx.time.min.js
1
(function(t){var e={"boolean":!1,"function":!0,object:!0,number:!1,string:!1,undefined:!1},n=e[typeof window]&&window||this,r=e[typeof exports]&&exports&&!exports.nodeType&&exports,o=e[typeof module]&&module&&!module.nodeType&&module,i=(o&&o.exports===r&&r,e[typeof global]&&global);!i||i.global!==i&&i.window!==i||(n=i),"function"==typeof define&&define.amd?define(["rx","exports"],function(e,r){return n.Rx=t(n,r,e),n.Rx}):"object"==typeof module&&module&&module.exports===r?module.exports=t(n,module.exports,require("./rx")):n.Rx=t(n,{},n.Rx)}).call(this,function(t,e,n,r){function o(t,e){return new p(function(n){return e.scheduleWithAbsolute(t,function(){n.onNext(0),n.onCompleted()})})}function i(t,e,n){var r=N(e);return new p(function(e){var o=0,i=t;return n.scheduleRecursiveWithAbsolute(i,function(t){var s;r>0&&(s=n.now(),i+=r,s>=i&&(i=s+r)),e.onNext(o++),t(i)})})}function s(t,e){var n=N(t);return new p(function(t){return e.scheduleWithRelative(n,function(){t.onNext(0),t.onCompleted()})})}function u(t,e,n){return t===e?new p(function(t){return n.schedulePeriodicWithState(0,e,function(e){return t.onNext(e),e+1})}):d(function(){return i(n.now()+t,e,n)})}function c(t,e){var n=this;return new p(function(r){var o,i=!1,s=new x,u=null,c=[],a=!1;return o=n.materialize().timestamp(e).subscribe(function(n){var o,l;"E"===n.value.kind?(c=[],c.push(n),u=n.value.exception,l=!a):(c.push({value:n.value,timestamp:n.timestamp+t}),l=!i,i=!0),l&&(null!==u?r.onError(u):(o=new g,s.setDisposable(o),o.setDisposable(e.scheduleRecursiveWithRelative(t,function(t){var n,o,s,l;if(null===u){a=!0;do s=null,c.length>0&&0>=c[0].timestamp-e.now()&&(s=c.shift().value),null!==s&&s.accept(r);while(null!==s);l=!1,o=0,c.length>0?(l=!0,o=Math.max(0,c[0].timestamp-e.now())):i=!1,n=u,a=!1,null!==n?r.onError(n):l&&t(o)}}))))}),new E(o,s)})}function a(t,e){var n=this;return d(function(){var r=t-e.now();return c.call(n,r,e)})}function l(t,e){return new p(function(n){function r(){s&&(s=!1,n.onNext(i)),o&&n.onCompleted()}var o,i,s;return new E(t.subscribe(function(t){s=!0,i=t},n.onError.bind(n),function(){o=!0}),e.subscribe(r,n.onError.bind(n),r))})}var f=n.Observable,h=f.prototype,p=n.AnonymousObservable,d=f.defer,b=f.empty,v=f.never,m=f.throwException,y=f.fromArray,w=n.Scheduler.timeout,g=n.SingleAssignmentDisposable,x=n.SerialDisposable,E=n.CompositeDisposable,C=n.RefCountDisposable,D=n.Subject,A=n.internals.addRef,N=n.Scheduler.normalize,S=f.interval=function(t,e){return e||(e=w),u(t,t,e)},O=f.timer=function(t,e,n){var c;return n||(n=w),e!==r&&"number"==typeof e?c=e:e!==r&&"object"==typeof e&&(n=e),t instanceof Date&&c===r?o(t.getTime(),n):t instanceof Date&&c!==r?(c=e,i(t.getTime(),c,n)):c===r?s(t,n):u(t,c,n)};return h.delay=function(t,e){return e||(e=w),t instanceof Date?a.call(this,t.getTime(),e):c.call(this,t,e)},h.throttle=function(t,e){return e||(e=w),this.throttleWithSelector(function(){return O(t,e)})},h.windowWithTime=function(t,e,n){var o,i=this;return e===r&&(o=t),n===r&&(n=w),"number"==typeof e?o=e:"object"==typeof e&&(o=t,n=e),new p(function(e){function r(){var t=new g,i=!1,s=!1;f.setDisposable(t),a===c?(i=!0,s=!0):c>a?i=!0:s=!0;var p=i?a:c,d=p-h;h=p,i&&(a+=o),s&&(c+=o),t.setDisposable(n.scheduleWithRelative(d,function(){var t;s&&(t=new D,l.push(t),e.onNext(A(t,u))),i&&(t=l.shift(),t.onCompleted()),r()}))}var s,u,c=o,a=t,l=[],f=new x,h=0;return s=new E(f),u=new C(s),l.push(new D),e.onNext(A(l[0],u)),r(),s.add(i.subscribe(function(t){var e,n;for(e=0;l.length>e;e++)n=l[e],n.onNext(t)},function(t){var n,r;for(n=0;l.length>n;n++)r=l[n],r.onError(t);e.onError(t)},function(){var t,n;for(t=0;l.length>t;t++)n=l[t],n.onCompleted();e.onCompleted()})),u})},h.windowWithTimeOrCount=function(t,e,n){var r=this;return n||(n=w),new p(function(o){var i,s,u,c,a=0,l=new x,f=0;return s=new E(l),u=new C(s),i=function(e){var r=new g;l.setDisposable(r),r.setDisposable(n.scheduleWithRelative(t,function(){var t;e===f&&(a=0,t=++f,c.onCompleted(),c=new D,o.onNext(A(c,u)),i(t))}))},c=new D,o.onNext(A(c,u)),i(0),s.add(r.subscribe(function(t){var n=0,r=!1;c.onNext(t),a++,a===e&&(r=!0,a=0,n=++f,c.onCompleted(),c=new D,o.onNext(A(c,u))),r&&i(n)},function(t){c.onError(t),o.onError(t)},function(){c.onCompleted(),o.onCompleted()})),u})},h.bufferWithTime=function(){return this.windowWithTime.apply(this,arguments).selectMany(function(t){return t.toArray()})},h.bufferWithTimeOrCount=function(t,e,n){return this.windowWithTimeOrCount(t,e,n).selectMany(function(t){return t.toArray()})},h.timeInterval=function(t){var e=this;return t||(t=w),d(function(){var n=t.now();return e.select(function(e){var r=t.now(),o=r-n;return n=r,{value:e,interval:o}})})},h.timestamp=function(t){return t||(t=w),this.select(function(e){return{value:e,timestamp:t.now()}})},h.sample=function(t,e){return e||(e=w),"number"==typeof t?l(this,S(t,e)):l(this,t)},h.timeout=function(t,e,n){var r,o=this;return e||(e=m(Error("Timeout"))),n||(n=w),r=t instanceof Date?function(t,e){n.scheduleWithAbsolute(t,e)}:function(t,e){n.scheduleWithRelative(t,e)},new p(function(n){var i,s=0,u=new g,c=new x,a=!1,l=new x;return c.setDisposable(u),i=function(){var o=s;l.setDisposable(r(t,function(){a=s===o;var t=a;t&&c.setDisposable(e.subscribe(n))}))},i(),u.setDisposable(o.subscribe(function(t){var e=!a;e&&(s++,n.onNext(t),i())},function(t){var e=!a;e&&(s++,n.onError(t))},function(){var t=!a;t&&(s++,n.onCompleted())})),new E(c,l)})},f.generateWithAbsoluteTime=function(t,e,n,o,i,s){return s||(s=w),new p(function(u){var c,a,l=!0,f=!1,h=t;return s.scheduleRecursiveWithAbsolute(s.now(),function(t){f&&u.onNext(c);try{l?l=!1:h=n(h),f=e(h),f&&(c=o(h),a=i(h))}catch(s){return u.onError(s),r}f?t(a):u.onCompleted()})})},f.generateWithRelativeTime=function(t,e,n,o,i,s){return s||(s=w),new p(function(u){var c,a,l=!0,f=!1,h=t;return s.scheduleRecursiveWithRelative(0,function(t){f&&u.onNext(c);try{l?l=!1:h=n(h),f=e(h),f&&(c=o(h),a=i(h))}catch(s){return u.onError(s),r}f?t(a):u.onCompleted()})})},h.delaySubscription=function(t,e){return e||(e=w),this.delayWithSelector(O(t,e),function(){return b()})},h.delayWithSelector=function(t,e){var n,o,i=this;return"function"==typeof t?o=t:(n=t,o=e),new p(function(t){var e=new E,s=!1,u=function(){s&&0===e.length&&t.onCompleted()},c=new x,a=function(){c.setDisposable(i.subscribe(function(n){var i;try{i=o(n)}catch(s){return t.onError(s),r}var c=new g;e.add(c),c.setDisposable(i.subscribe(function(){t.onNext(n),e.remove(c),u()},t.onError.bind(t),function(){t.onNext(n),e.remove(c),u()}))},t.onError.bind(t),function(){s=!0,c.dispose(),u()}))};return n?c.setDisposable(n.subscribe(function(){a()},t.onError.bind(t),function(){a()})):a(),new E(c,e)})},h.timeoutWithSelector=function(t,e,n){if(1===arguments.length){e=t;var t=v()}n||(n=m(Error("Timeout")));var o=this;return new p(function(i){var s=new x,u=new x,c=new g;s.setDisposable(c);var a=0,l=!1,f=function(t){var e=a,r=function(){return a===e},o=new g;u.setDisposable(o),o.setDisposable(t.subscribe(function(){r()&&s.setDisposable(n.subscribe(i)),o.dispose()},function(t){r()&&i.onError(t)},function(){r()&&s.setDisposable(n.subscribe(i))}))};f(t);var h=function(){var t=!l;return t&&a++,t};return c.setDisposable(o.subscribe(function(t){if(h()){i.onNext(t);var n;try{n=e(t)}catch(o){return i.onError(o),r}f(n)}},function(t){h()&&i.onError(t)},function(){h()&&i.onCompleted()})),new E(s,u)})},h.throttleWithSelector=function(t){var e=this;return new p(function(n){var o,i=!1,s=new x,u=0,c=e.subscribe(function(e){var c;try{c=t(e)}catch(a){return n.onError(a),r}i=!0,o=e,u++;var l=u,f=new g;s.setDisposable(f),f.setDisposable(c.subscribe(function(){i&&u===l&&n.onNext(o),i=!1,f.dispose()},n.onError.bind(n),function(){i&&u===l&&n.onNext(o),i=!1,f.dispose()}))},function(t){s.dispose(),n.onError(t),i=!1,u++},function(){s.dispose(),i&&n.onNext(o),n.onCompleted(),i=!1,u++});return new E(c,s)})},h.skipLastWithTime=function(t,e){e||(e=w);var n=this;return new p(function(r){var o=[];return n.subscribe(function(n){var i=e.now();for(o.push({interval:i,value:n});o.length>0&&i-o[0].interval>=t;)r.onNext(o.shift().value)},r.onError.bind(r),function(){for(var n=e.now();o.length>0&&n-o[0].interval>=t;)r.onNext(o.shift().value);r.onCompleted()})})},h.takeLastWithTime=function(t,e,n){return this.takeLastBufferWithTime(t,e).selectMany(function(t){return y(t,n)})},h.takeLastBufferWithTime=function(t,e){var n=this;return e||(e=w),new p(function(r){var o=[];return n.subscribe(function(n){var r=e.now();for(o.push({interval:r,value:n});o.length>0&&r-o[0].interval>=t;)o.shift()},r.onError.bind(r),function(){for(var n=e.now(),i=[];o.length>0;){var s=o.shift();t>=n-s.interval&&i.push(s.value)}r.onNext(i),r.onCompleted()})})},h.takeWithTime=function(t,e){var n=this;return e||(e=w),new p(function(r){var o=e.scheduleWithRelative(t,function(){r.onCompleted()});return new E(o,n.subscribe(r))})},h.skipWithTime=function(t,e){var n=this;return e||(e=w),new p(function(r){var o=!1,i=e.scheduleWithRelative(t,function(){o=!0}),s=n.subscribe(function(t){o&&r.onNext(t)},r.onError.bind(r),r.onCompleted.bind(r));return new E(i,s)})},h.skipUntilWithTime=function(t,e){e||(e=w);var n=this;return new p(function(r){var o=!1,i=e.scheduleWithAbsolute(t,function(){o=!0}),s=n.subscribe(function(t){o&&r.onNext(t)},r.onError.bind(r),r.onCompleted.bind(r));return new E(i,s)})},h.takeUntilWithTime=function(t,e){e||(e=w);var n=this;return new p(function(r){return new E(e.scheduleWithAbsolute(t,function(){r.onCompleted()}),n.subscribe(r))})},n});