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.49 KB
/
rx.time.min.js
1
(function(t,e){var n="object"==typeof exports&&exports,r=("object"==typeof module&&module&&module.exports==n&&module,"object"==typeof global&&global);r.global===r&&(window=r),"function"==typeof define&&define.amd?define(["rx","exports"],function(n,r){return t.Rx=e(t,r,n),t.Rx}):"object"==typeof module&&module&&module.exports===n?module.exports=e(t,module.exports,require("./rx")):t.Rx=e(t,{},t.Rx)})(this,function(t,e,n,r){function i(t,e){return new p(function(n){return e.scheduleWithAbsolute(t,function(){n.onNext(0),n.onCompleted()})})}function o(t,e,n){var r=A(e);return new p(function(e){var i=0,o=t;return n.scheduleRecursiveWithAbsolute(o,function(t){var s;r>0&&(s=n.now(),o+=r,s>=o&&(o=s+r)),e.onNext(i++),t(o)})})}function s(t,e){var n=A(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 o(n.now()+t,e,n)})}function c(t,e){var n=this;return new p(function(r){var i,o=!1,s=new g,u=null,c=[],a=!1;return i=n.materialize().timestamp(e).subscribe(function(n){var i,h;"E"===n.value.kind?(c=[],c.push(n),u=n.value.exception,h=!a):(c.push({value:n.value,timestamp:n.timestamp+t}),h=!o,o=!0),h&&(null!==u?r.onError(u):(i=new w,s.disposable(i),i.disposable(e.scheduleRecursiveWithRelative(t,function(t){var n,i,s,h;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);h=!1,i=0,c.length>0?(h=!0,i=Math.max(0,c[0].timestamp-e.now())):o=!1,n=u,a=!1,null!==n?r.onError(n):h&&t(i)}}))))}),new x(i,s)})}function a(t,e){var n=this;return d(function(){var r=t-e.now();return c.call(n,r,e)})}function h(t,e){return new p(function(n){function r(){s&&(s=!1,n.onNext(o)),i&&n.onCompleted()}var i,o,s;return new x(t.subscribe(function(t){s=!0,o=t},n.onError.bind(n),function(){i=!0}),e.subscribe(r,n.onError.bind(n),r))})}var l=n.Observable,f=l.prototype,p=n.Internals.AnonymousObservable,d=l.defer,b=l.empty,v=l.throwException,m=l.fromArray,y=n.Scheduler.timeout,w=n.SingleAssignmentDisposable,g=n.SerialDisposable,x=n.CompositeDisposable,E=n.RefCountDisposable,C=n.Subject,D=(n.Internals.BinaryObserver,n.Internals.addRef),A=n.Scheduler.normalize,N=l.interval=function(t,e){return e||(e=y),u(t,t,e)},S=l.timer=function(t,e,n){var c;return n||(n=y),e!==r&&"number"==typeof e?c=e:e!==r&&"object"==typeof e&&(n=e),t instanceof Date&&c===r?i(t.getTime(),n):t instanceof Date&&c!==r?(c=e,o(t.getTime(),c,n)):c===r?s(t,n):u(t,c,n)};return f.delay=function(t,e){return e||(e=y),t instanceof Date?a.call(this,t.getTime(),e):c.call(this,t,e)},f.throttle=function(t,e){e||(e=y);var n=this;return new p(function(r){var i,o=new g,s=!1,u=0,c=null;return i=n.subscribe(function(n){var i,a;s=!0,c=n,u++,i=u,a=new w,o.disposable(a),a.disposable(e.scheduleWithRelative(t,function(){s&&u===i&&r.onNext(c),s=!1}))},function(t){o.dispose(),r.onError(t),s=!1,u++},function(){o.dispose(),s&&r.onNext(c),r.onCompleted(),s=!1,u++}),new x(i,o)})},f.windowWithTime=function(t,e,n){var i,o=this;return e===r&&(i=t),n===r&&(n=y),"number"==typeof e?i=e:"object"==typeof e&&(i=t,n=e),new p(function(e){var r,s,u,c=i,a=t,h=[],l=new g,f=0;return s=new x(l),u=new E(s),r=function(){var t,o,s,p,d;s=new w,l.disposable(s),o=!1,t=!1,a===c?(o=!0,t=!0):c>a?o=!0:t=!0,p=o?a:c,d=p-f,f=p,o&&(a+=i),t&&(c+=i),s.disposable(n.scheduleWithRelative(d,function(){var n;t&&(n=new C,h.push(n),e.onNext(D(n,u))),o&&(n=h.shift(),n.onCompleted()),r()}))},h.push(new C),e.onNext(D(h[0],u)),r(),s.add(o.subscribe(function(t){var e,n;for(e=0;h.length>e;e++)n=h[e],n.onNext(t)},function(t){var n,r;for(n=0;h.length>n;n++)r=h[n],r.onError(t);e.onError(t)},function(){var t,n;for(t=0;h.length>t;t++)n=h[t],n.onCompleted();e.onCompleted()})),u})},f.windowWithTimeOrCount=function(t,e,n){var r=this;return n||(n=y),new p(function(i){var o,s,u,c,a=0,h=new g,l=0;return s=new x(h),u=new E(s),o=function(e){var r=new w;h.disposable(r),r.disposable(n.scheduleWithRelative(t,function(){var t;e===l&&(a=0,t=++l,c.onCompleted(),c=new C,i.onNext(D(c,u)),o(t))}))},c=new C,i.onNext(D(c,u)),o(0),s.add(r.subscribe(function(t){var n=0,r=!1;c.onNext(t),a++,a===e&&(r=!0,a=0,n=++l,c.onCompleted(),c=new C,i.onNext(D(c,u))),r&&o(n)},function(t){c.onError(t),i.onError(t)},function(){c.onCompleted(),i.onCompleted()})),u})},f.bufferWithTime=function(t,e,n){var i;return e===r&&(i=t),n||(n=y),"number"==typeof e?i=e:"object"==typeof e&&(i=t,n=e),this.windowWithTime(t,i,n).selectMany(function(t){return t.toArray()})},f.bufferWithTimeOrCount=function(t,e,n){return n||(n=y),this.windowWithTimeOrCount(t,e,n).selectMany(function(t){return t.toArray()})},f.timeInterval=function(t){var e=this;return t||(t=y),d(function(){var n=t.now();return e.select(function(e){var r=t.now(),i=r-n;return n=r,{value:e,interval:i}})})},f.timestamp=function(t){return t||(t=y),this.select(function(e){return{value:e,timestamp:t.now()}})},f.sample=function(t,e){return e||(e=y),"number"==typeof t?h(this,N(t,e)):h(this,t)},f.timeout=function(t,e,n){var r,i=this;return e||(e=v(Error("Timeout"))),n||(n=y),r=t instanceof Date?function(t,e){n.scheduleWithAbsolute(t,e)}:function(t,e){n.scheduleWithRelative(t,e)},new p(function(n){var o,s=0,u=new w,c=new g,a=!1,h=new g;return c.disposable(u),o=function(){var i=s;h.disposable(r(t,function(){a=s===i;var t=a;t&&c.disposable(e.subscribe(n))}))},o(),u.disposable(i.subscribe(function(t){var e=!a;e&&(s++,n.onNext(t),o())},function(t){var e=!a;e&&(s++,n.onError(t))},function(){var t=!a;t&&(s++,n.onCompleted())})),new x(c,h)})},l.generateWithAbsoluteTime=function(t,e,n,i,o,s){return s||(s=y),new p(function(u){var c,a,h=!0,l=!1,f=t;return s.scheduleRecursiveWithAbsolute(s.now(),function(t){l&&u.onNext(c);try{h?h=!1:f=n(f),l=e(f),l&&(c=i(f),a=o(f))}catch(s){return u.onError(s),r}l?t(a):u.onCompleted()})})},l.generateWithRelativeTime=function(t,e,n,i,o,s){return s||(s=y),new p(function(u){var c,a,h=!0,l=!1,f=t;return s.scheduleRecursiveWithRelative(0,function(t){l&&u.onNext(c);try{h?h=!1:f=n(f),l=e(f),l&&(c=i(f),a=o(f))}catch(s){return u.onError(s),r}l?t(a):u.onCompleted()})})},f.delaySubscription=function(t,e){return e||(e=y),this.delayWithSelector(S(t,e),function(){return b()})},f.delayWithSelector=function(t,e){var n,i,o=this;return"function"==typeof t?i=t:(n=t,i=e),new p(function(t){var e=new x,s=!1,u=function(){s&&0===e.length&&t.onCompleted()},c=new g,a=function(){c.setDisposable(o.subscribe(function(n){var o;try{o=i(n)}catch(s){return t.onError(s),r}var c=new w;e.add(c),c.setDisposable(o.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 x(c,e)})},f.timeoutWithSelector=function(t,e,n){t||(t=observableNever()),n||(n=v(Error("Timeout")));var i=this;return new p(function(o){var s=new g,u=new g,c=new w;s.setDisposable(c);var a=0,h=!1,l=function(t){var e=a,r=function(){return a===e},i=new w;u.setDisposable(i),i.setDisposable(t.subscribe(function(){r()&&s.setDisposable(n.subscribe(o)),i.dispose()},function(t){r()&&o.onError(t)},function(){r()&&s.setDisposable(n.subscribe(o))}))};l(t);var f=function(){var t=!h;return t&&a++,t};return c.setDisposable(i.subscribe(function(t){if(f()){o.onNext(t);var n;try{n=e(t)}catch(i){return o.onError(i),r}l(n)}},function(t){f()&&o.onError(t)},function(){f()&&o.onCompleted()})),new x(s,u)})},f.throttleWithSelector=function(t){var e=this;return new p(function(n){var i,o=!1,s=new g,u=0,c=e.subscribe(function(e){var c;try{c=t(e)}catch(a){return n.onError(a),r}o=!0,i=e,u++;var h=u,l=new w;s.setDisposable(l),l.setDisposable(c.subscribe(function(){o&&u===h&&n.onNext(i),o=!1,l.dispose()},n.onError.bind(n),function(){o&&u===h&&n.onNext(i),o=!1,l.dispose()}))},function(t){s.dispose(),n.onError(t),o=!1,u++},function(){s.dispose(),o&&n.onNext(i),n.onCompleted(),o=!1,u++});return new x(c,s)})},f.skipLastWithTime=function(t,e){e||(e=y);var n=this;return new p(function(r){var i=[];return n.subscribe(function(n){var o=e.now();for(i.push({interval:o,value:n});i.length>0&&o-i[0].interval>=t;)r.onNext(i.shift().value)},r.onError.bind(r),function(){for(var n=e.now();i.length>0&&n-i[0].interval>=t;)r.onNext(i.shift().value);r.onCompleted()})})},f.takeLastWithTime=function(t,e,n){return this.takeLastBufferWithTime(t,e).selectMany(function(t){return m(t,n)})},f.takeLastBufferWithTime=function(t,e){var n=this;return e||(e=y),new p(function(r){var i=[];return n.subscribe(function(n){var r=e.now();for(i.push({interval:r,value:n});i.length>0&&r-i[0].interval>=t;)i.shift()},r.onError.bind(r),function(){for(var n=e.now(),o=[];i.length>0;){var s=i.shift();t>=n-s.interval&&o.push(s.value)}r.onNext(o),r.onCompleted()})})},f.takeWithTime=function(t,e){var n=this;return e||(e=y),new p(function(r){var i=e.scheduleWithRelative(t,function(){r.onCompleted()});return new x(i,n.subscribe(r))})},f.skipWithTime=function(t,e){var n=this;return e||(e=y),new p(function(r){var i=!1,o=e.scheduleWithRelative(t,function(){i=!0}),s=n.subscribe(function(t){i&&r.onNext(t)},r.onError.bind(r),r.onCompleted.bind(r));return new x(o,s)})},f.skipUntilWithTime=function(t,e){e||(e=y);var n=this;return new p(function(r){var i=!1,o=e.scheduleWithAbsolute(t,function(){i=!0}),s=n.subscribe(function(t){i&&r.onNext(t)},r.onError.bind(r),r.onCompleted.bind(r));return new x(o,s)})},f.takeUntilWithTime=function(t,e){e||(e=y);var n=this;return new p(function(r){return new x(e.scheduleWithAbsolute(t,function(){r.onCompleted()}),n.subscribe(r))})},n});