UNPKG

15.9 kBJavaScriptView Raw
1/* Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.*/
2(function(a){function b(a){return a&&a.Object===Object?a:null}var c={"function":!0,object:!0},d=c[typeof exports]&&exports&&!exports.nodeType?exports:null,e=c[typeof module]&&module&&!module.nodeType?module:null,f=b(d&&e&&"object"==typeof global&&global),g=b(c[typeof self]&&self),h=b(c[typeof window]&&window),i=(e&&e.exports===d?d:null,b(c[typeof this]&&this)),j=f||h!==(i&&i.window)&&h||g||i||Function("return this")();"function"==typeof define&&define.amd?define(["./rx"],function(b,c){return a(j,c,b)}):"object"==typeof module&&module&&module.exports===d?module.exports=a(j,module.exports,require("./rx")):j.Rx=a(j,{},j.Rx)}).call(this,function(a,b,c,d){function e(a){return function(){try{return a.apply(this,arguments)}catch(b){return N.e=b,N}}}function f(a,b){return new P(a,b)}function g(a,b,c){return new u(function(d){var e=a,f=H(b);return c.scheduleRecursiveFuture(0,e,function(a,b){if(f>0){var g=c.now();e=new Date(e.getTime()+f),e.getTime()<=g&&(e=new Date(g+f))}d.onNext(a),b(a+1,new Date(e))})})}function h(a,b,c){return a===b?new u(function(a){return c.schedulePeriodic(0,b,function(b){return a.onNext(b),b+1})}):w(function(){return g(new Date(c.now()+a),b,c)})}function i(a,b,c){return new u(function(d){var e,f=!1,g=new B,h=null,i=[],j=!1;return e=a.materialize().timestamp(c).subscribe(function(a){var e,k;"E"===a.value.kind?(i=[],i.push(a),h=a.value.error,k=!j):(i.push({value:a.value,timestamp:a.timestamp+b}),k=!f,f=!0),k&&(null!==h?d.onError(h):(e=new A,g.setDisposable(e),e.setDisposable(c.scheduleRecursiveFuture(null,b,function(a,b){var e,g,k,l;if(null===h){j=!0;do k=null,i.length>0&&i[0].timestamp-c.now()<=0&&(k=i.shift().value),null!==k&&k.accept(d);while(null!==k);l=!1,g=0,i.length>0?(l=!0,g=Math.max(0,i[0].timestamp-c.now())):f=!1,e=h,j=!1,null!==e?d.onError(e):l&&b(null,g)}}))))}),new D(e,g)},a)}function j(a,b,c){return w(function(){return i(a,b-c.now(),c)})}function k(a,b,c){var d,e;return K(b)?e=b:(d=b,e=c),new u(function(b){function c(){i.setDisposable(a.subscribe(function(a){var c=O(e)(a);if(c===N)return b.onError(c.e);var d=new A;g.add(d),d.setDisposable(c.subscribe(function(){b.onNext(a),g.remove(d),f()},function(a){b.onError(a)},function(){b.onNext(a),g.remove(d),f()}))},function(a){b.onError(a)},function(){h=!0,i.dispose(),f()}))}function f(){h&&0===g.length&&b.onCompleted()}var g=new C,h=!1,i=new B;return d?i.setDisposable(d.subscribe(c,function(a){b.onError(a)},c)):c(),new D(i,g)},this)}function l(a,b){return new u(function(c){var d,e=!1,f=new B,g=0,h=a.subscribe(function(a){var h=O(b)(a);if(h===N)return c.onError(h.e);J(h)&&(h=M(h)),e=!0,d=a,g++;var i=g,j=new A;f.setDisposable(j),j.setDisposable(h.subscribe(function(){e&&g===i&&c.onNext(d),e=!1,j.dispose()},function(a){c.onError(a)},function(){e&&g===i&&c.onNext(d),e=!1,j.dispose()}))},function(a){f.dispose(),c.onError(a),e=!1,g++},function(){f.dispose(),e&&c.onNext(d),c.onCompleted(),e=!1,g++});return new D(h,f)},a)}function m(a){return a.toArray()}function m(a){return a.toArray()}function n(a,b){return new u(function(c){function d(){g&&(g=!1,c.onNext(e)),f&&c.onCompleted()}var e,f=!1,g=!1,h=new A;return h.setDisposable(a.subscribe(function(a){g=!0,e=a},function(a){c.onError(a)},function(){f=!0,h.dispose()})),new D(h,b.subscribe(d,function(a){c.onError(a)},d))},a)}function o(a,b,c,d){return K(b)&&(d=c,c=b,b=x()),s.isObservable(d)||(d=y(new X)),new u(function(e){function f(a){function b(){return l=c===k}var c=k,f=new A;i.setDisposable(f),f.setDisposable(a.subscribe(function(){b()&&h.setDisposable(d.subscribe(e)),f.dispose()},function(a){b()&&e.onError(a)},function(){b()&&h.setDisposable(d.subscribe(e))}))}function g(){var a=!l;return a&&k++,a}var h=new B,i=new B,j=new A;h.setDisposable(j);var k=0,l=!1;return f(b),j.setDisposable(a.subscribe(function(a){if(g()){e.onNext(a);var b=O(c)(a);if(b===N)return e.onError(b.e);f(J(b)?M(b):b)}},function(a){g()&&e.onError(a)},function(){g()&&e.onCompleted()})),new D(h,i)},a)}function p(a,b,c,d){return L(c)&&(d=c,c=y(new X)),c instanceof Error&&(c=y(c)),L(d)||(d=z),s.isObservable(c)||(c=y(new X)),new u(function(e){function f(){var a=g;k.setDisposable(d.scheduleFuture(null,b,function(){j=g===a,j&&(J(c)&&(c=M(c)),i.setDisposable(c.subscribe(e)))}))}var g=0,h=new A,i=new B,j=!1,k=new B;return i.setDisposable(h),f(),h.setDisposable(a.subscribe(function(a){j||(g++,e.onNext(a),f())},function(a){j||(g++,e.onError(a))},function(){j||(g++,e.onCompleted())})),new D(i,k)},a)}var q=c.internals.inherits,r=c.internals.AbstractObserver,s=c.Observable,t=s.prototype,u=c.AnonymousObservable,v=c.ObservableBase,w=s.defer,x=(s.empty,s.never),y=s["throw"],z=(s.fromArray,c.Scheduler["default"]),A=c.SingleAssignmentDisposable,B=c.SerialDisposable,C=c.CompositeDisposable,D=c.BinaryDisposable,E=c.RefCountDisposable,F=c.Subject,G=c.internals.addRef,H=c.Scheduler.normalize,I=c.helpers,J=I.isPromise,K=I.isFunction,L=c.Scheduler.isScheduler,M=s.fromPromise,N={e:{}},O=c.internals.tryCatch=function(a){if(!K(a))throw new TypeError("fn must be a function");return e(a)},P=function(a){function b(b,c){this._dt=b,this._s=c,a.call(this)}function c(a,b){b.onNext(0),b.onCompleted()}return q(b,a),b.prototype.subscribeCore=function(a){return this._s.scheduleFuture(a,this._dt,c)},b}(v),Q=s.interval=function(a,b){return h(a,a,L(b)?b:z)};s.timer=function(a,b,c){var e;return L(c)||(c=z),null!=b&&"number"==typeof b?e=b:L(b)&&(c=b),(a instanceof Date||"number"==typeof a)&&e===d?f(a,c):a instanceof Date&&e!==d?g(a.getTime(),b,c):h(a,e,c)};t.delay=function(){var a=arguments[0];if("number"==typeof a||a instanceof Date){var b=a,c=arguments[1];return L(c)||(c=z),b instanceof Date?j(this,b,c):i(this,b,c)}if(s.isObservable(a)||K(a))return k(this,a,arguments[1]);throw new Error("Invalid arguments")};var R=function(a){function b(b,c,d){L(d)||(d=z),this.source=b,this._dt=c,this._s=d,a.call(this)}return q(b,a),b.prototype.subscribeCore=function(a){var b=new B;return new D(this.source.subscribe(new S(a,this.source,this._dt,this._s,b)),b)},b}(v),S=function(a){function b(b,c,d,e,f){this._o=b,this._s=c,this._d=d,this._scheduler=e,this._c=f,this._v=null,this._hv=!1,this._id=0,a.call(this)}return q(b,a),b.prototype.next=function(a){this._hv=!0,this._v=a;var b=++this._id,c=new A;this._c.setDisposable(c),c.setDisposable(this._scheduler.scheduleFuture(this,this._d,function(c,d){d._hv&&d._id===b&&d._o.onNext(a),d._hv=!1}))},b.prototype.error=function(a){this._c.dispose(),this._o.onError(a),this._hv=!1,this._id++},b.prototype.completed=function(){this._c.dispose(),this._hv&&this._o.onNext(this._v),this._o.onCompleted(),this._hv=!1,this._id++},b}(r);t.debounce=function(){if(K(arguments[0]))return l(this,arguments[0]);if("number"==typeof arguments[0])return new R(this,arguments[0],arguments[1]);throw new Error("Invalid arguments")},t.windowWithTime=function(a,b,c){var d,e=this;return null==b&&(d=a),L(c)||(c=z),"number"==typeof b?d=b:L(b)&&(d=a,c=b),new u(function(b){function f(){var a=new A,e=!1,g=!1;l.setDisposable(a),j===i?(e=!0,g=!0):i>j?e=!0:g=!0;var n=e?j:i,o=n-m;m=n,e&&(j+=d),g&&(i+=d),a.setDisposable(c.scheduleFuture(null,o,function(){if(g){var a=new F;k.push(a),b.onNext(G(a,h))}e&&k.shift().onCompleted(),f()}))}var g,h,i=d,j=a,k=[],l=new B,m=0;return g=new C(l),h=new E(g),k.push(new F),b.onNext(G(k[0],h)),f(),g.add(e.subscribe(function(a){for(var b=0,c=k.length;c>b;b++)k[b].onNext(a)},function(a){for(var c=0,d=k.length;d>c;c++)k[c].onError(a);b.onError(a)},function(){for(var a=0,c=k.length;c>a;a++)k[a].onCompleted();b.onCompleted()})),h},e)},t.windowWithTimeOrCount=function(a,b,c){var d=this;return L(c)||(c=z),new u(function(e){function f(b){var d=new A;g.setDisposable(d),d.setDisposable(c.scheduleFuture(null,a,function(){if(b===k){j=0;var a=++k;l.onCompleted(),l=new F,e.onNext(G(l,i)),f(a)}}))}var g=new B,h=new C(g),i=new E(h),j=0,k=0,l=new F;return e.onNext(G(l,i)),f(0),h.add(d.subscribe(function(a){var c=0,d=!1;l.onNext(a),++j===b&&(d=!0,j=0,c=++k,l.onCompleted(),l=new F,e.onNext(G(l,i))),d&&f(c)},function(a){l.onError(a),e.onError(a)},function(){l.onCompleted(),e.onCompleted()})),i},d)},t.bufferWithTime=function(a,b,c){return this.windowWithTime(a,b,c).flatMap(m)},t.bufferWithTimeOrCount=function(a,b,c){return this.windowWithTimeOrCount(a,b,c).flatMap(m)};var T=function(a){function b(b,c){this.source=b,this._s=c,a.call(this)}return q(b,a),b.prototype.subscribeCore=function(a){return this.source.subscribe(new U(a,this._s))},b}(v),U=function(a){function b(b,c){this._o=b,this._s=c,this._l=c.now(),a.call(this)}return q(b,a),b.prototype.next=function(a){var b=this._s.now(),c=b-this._l;this._l=b,this._o.onNext({value:a,interval:c})},b.prototype.error=function(a){this._o.onError(a)},b.prototype.completed=function(){this._o.onCompleted()},b}(r);t.timeInterval=function(a){return L(a)||(a=z),new T(this,a)};var V=function(a){function b(b,c){this.source=b,this._s=c,a.call(this)}return q(b,a),b.prototype.subscribeCore=function(a){return this.source.subscribe(new W(a,this._s))},b}(v),W=function(a){function b(b,c){this._o=b,this._s=c,a.call(this)}return q(b,a),b.prototype.next=function(a){this._o.onNext({value:a,timestamp:this._s.now()})},b.prototype.error=function(a){this._o.onError(a)},b.prototype.completed=function(){this._o.onCompleted()},b}(r);t.timestamp=function(a){return L(a)||(a=z),new V(this,a)},t.sample=t.throttleLatest=function(a,b){return L(b)||(b=z),"number"==typeof a?n(this,Q(a,b)):n(this,a)};var X=c.TimeoutError=function(a){this.message=a||"Timeout has occurred",this.name="TimeoutError",Error.call(this)};X.prototype=Object.create(Error.prototype),t.timeout=function(){var a=arguments[0];if(a instanceof Date||"number"==typeof a)return p(this,a,arguments[1],arguments[2]);if(s.isObservable(a)||K(a))return o(this,a,arguments[1],arguments[2]);throw new Error("Invalid arguments")};var Y=function(a){function b(b,c,d,e,f,g){this._state=b,this._cndFn=c,this._itrFn=d,this._resFn=e,this._timeFn=f,this._s=g,this._first=!0,this._hasResult=!1,a.call(this)}function c(a,b){if(a._hasResult&&a._o.onNext(a._state),a._first)a._first=!1;else if(a._state=O(a._itrFn)(a._state),a._state===N)return a._o.onError(a._state.e);if(a._hasResult=O(a._cndFn)(a._state),a._hasResult===N)return a._o.onError(a._hasResult.e);if(a._hasResult){var c=O(a._resFn)(a._state);if(c===N)return a._o.onError(c.e);var d=O(a._timeFn)(a._state);if(d===N)return a._o.onError(d.e);b(a,d)}else a._o.onCompleted()}return q(b,a),b.prototype.subscribeCore=function(a){return this._o=a,this._s.scheduleRecursiveFuture(this,new Date(this._s.now()),c)},b}(v);s.generateWithAbsoluteTime=function(a,b,c,d,e,f){return L(f)||(f=z),new Y(a,b,c,d,e,f)};var Z=function(a){function b(b,c,d,e,f,g){this._state=b,this._cndFn=c,this._itrFn=d,this._resFn=e,this._timeFn=f,this._s=g,this._first=!0,this._hasResult=!1,a.call(this)}function c(a,b){if(a._hasResult&&a._o.onNext(a._state),a._first)a._first=!1;else if(a._state=O(a._itrFn)(a._state),a._state===N)return a._o.onError(a._state.e);if(a._hasResult=O(a._cndFn)(a._state),a._hasResult===N)return a._o.onError(a._hasResult.e);if(a._hasResult){var c=O(a._resFn)(a._state);if(c===N)return a._o.onError(c.e);var d=O(a._timeFn)(a._state);if(d===N)return a._o.onError(d.e);b(a,d)}else a._o.onCompleted()}return q(b,a),b.prototype.subscribeCore=function(a){return this._o=a,this._s.scheduleRecursiveFuture(this,0,c)},b}(v);s.generateWithRelativeTime=function(a,b,c,d,e,f){return L(f)||(f=z),new Z(a,b,c,d,e,f)};var $=function(a){function b(b,c,d){this.source=b,this._dt=c,this._s=d,a.call(this)}function c(a,b){var c=b[0],d=b[1],e=b[2];e.setDisposable(c.subscribe(d))}return q(b,a),b.prototype.subscribeCore=function(a){var b=new B;return b.setDisposable(this._s.scheduleFuture([this.source,a,b],this._dt,c)),b},b}(v);t.delaySubscription=function(a,b){return L(b)||(b=z),new $(this,a,b)};var _=function(a){function b(b,c,d){this.source=b,this._d=c,this._s=d,a.call(this)}return q(b,a),b.prototype.subscribeCore=function(a){return this.source.subscribe(new aa(a,this))},b}(v),aa=function(a){function b(b,c){this._o=b,this._s=c._s,this._d=c._d,this._q=[],a.call(this)}return q(b,a),b.prototype.next=function(a){var b=this._s.now();for(this._q.push({interval:b,value:a});this._q.length>0&&b-this._q[0].interval>=this._d;)this._o.onNext(this._q.shift().value)},b.prototype.error=function(a){this._o.onError(a)},b.prototype.completed=function(){for(var a=this._s.now();this._q.length>0&&a-this._q[0].interval>=this._d;)this._o.onNext(this._q.shift().value);this._o.onCompleted()},b}(r);t.skipLastWithTime=function(a,b){return L(b)||(b=z),new _(this,a,b)};var ba=function(a){function b(b,c,d){this.source=b,this._d=c,this._s=d,a.call(this)}return q(b,a),b.prototype.subscribeCore=function(a){return this.source.subscribe(new ca(a,this._d,this._s))},b}(v),ca=function(a){function b(b,c,d){this._o=b,this._d=c,this._s=d,this._q=[],a.call(this)}return q(b,a),b.prototype.next=function(a){var b=this._s.now();for(this._q.push({interval:b,value:a});this._q.length>0&&b-this._q[0].interval>=this._d;)this._q.shift()},b.prototype.error=function(a){this._o.onError(a)},b.prototype.completed=function(){for(var a=this._s.now();this._q.length>0;){var b=this._q.shift();a-b.interval<=this._d&&this._o.onNext(b.value)}this._o.onCompleted()},b}(r);t.takeLastWithTime=function(a,b){return L(b)||(b=z),new ba(this,a,b)},t.takeLastBufferWithTime=function(a,b){var c=this;return L(b)||(b=z),new u(function(d){var e=[];return c.subscribe(function(c){var d=b.now();for(e.push({interval:d,value:c});e.length>0&&d-e[0].interval>=a;)e.shift()},function(a){d.onError(a)},function(){for(var c=b.now(),f=[];e.length>0;){var g=e.shift();c-g.interval<=a&&f.push(g.value)}d.onNext(f),d.onCompleted()})},c)};var da=function(a){function b(b,c,d){this.source=b,this._d=c,this._s=d,a.call(this)}function c(a,b){b.onCompleted()}return q(b,a),b.prototype.subscribeCore=function(a){return new D(this._s.scheduleFuture(a,this._d,c),this.source.subscribe(a))},b}(v);t.takeWithTime=function(a,b){return L(b)||(b=z),new da(this,a,b)};var ea=function(a){function b(b,c,d){this.source=b,this._d=c,this._s=d,this._open=!1,a.call(this)}function c(a,b){b._open=!0}return q(b,a),b.prototype.subscribeCore=function(a){return new D(this._s.scheduleFuture(this,this._d,c),this.source.subscribe(new fa(a,this)))},b}(v),fa=function(a){function b(b,c){this._o=b,this._p=c,a.call(this)}return q(b,a),b.prototype.next=function(a){this._p._open&&this._o.onNext(a)},b.prototype.error=function(a){this._o.onError(a)},b.prototype.completed=function(){this._o.onCompleted()},b}(r);t.skipWithTime=function(a,b){return L(b)||(b=z),new ea(this,a,b)};var ga=function(a){function b(b,c,d){this.source=b,this._st=c,this._s=d,a.call(this)}function c(a,b){b._open=!0}return q(b,a),b.prototype.subscribeCore=function(a){return this._open=!1,new D(this._s.scheduleFuture(this,this._st,c),this.source.subscribe(new ha(a,this)))},b}(v),ha=function(a){function b(b,c){this._o=b,this._p=c,a.call(this)}return q(b,a),b.prototype.next=function(a){this._p._open&&this._o.onNext(a)},b.prototype.error=function(a){this._o.onError(a)},b.prototype.completed=function(){this._o.onCompleted()},b}(r);return t.skipUntilWithTime=function(a,b){return L(b)||(b=z),new ga(this,a,b)},t.takeUntilWithTime=function(a,b){L(b)||(b=z);var c=this;return new u(function(d){return new D(b.scheduleFuture(d,a,function(a,b){b.onCompleted()}),c.subscribe(d))},c)},t.throttle=function(a,b){L(b)||(b=z);var c=+a||0;if(0>=c)throw new RangeError("windowDuration cannot be less or equal zero.");var d=this;return new u(function(a){var e=0;return d.subscribe(function(d){var f=b.now();(0===e||f-e>=c)&&(e=f,a.onNext(d))},function(b){a.onError(b)},function(){a.onCompleted()})},d)},c});
3//# sourceMappingURL=rx.time.map
\No newline at end of file