3 lines
11 KiB
JavaScript
3 lines
11 KiB
JavaScript
/* Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.*/
|
|
(function(a){var b={"boolean":!1,"function":!0,object:!0,number:!1,string:!1,undefined:!1},c=b[typeof window]&&window||this,d=b[typeof exports]&&exports&&!exports.nodeType&&exports,e=b[typeof module]&&module&&!module.nodeType&&module,f=(e&&e.exports===d&&d,b[typeof global]&&global);!f||f.global!==f&&f.window!==f||(c=f),"function"==typeof define&&define.amd?define(["rx"],function(b,d){return a(c,d,b)}):"object"==typeof module&&module&&module.exports===d?module.exports=a(c,module.exports,require("./rx")):c.Rx=a(c,{},c.Rx)}).call(this,function(a,b,c,d){function e(){try{return n.apply(this,arguments)}catch(a){return H.e=a,H}}function f(a){if(!E(a))throw new TypeError("fn must be a function");return n=a,e}function g(a,b){return new q(function(c){return b.scheduleWithAbsolute(a,function(){c.onNext(0),c.onCompleted()})})}function h(a,b,c){return new q(function(d){var e=a,f=B(b);return c.scheduleRecursiveWithAbsoluteAndState(0,e,function(a,b){if(f>0){var g=c.now();e+=f,g>=e&&(e=g+f)}d.onNext(a),b(a+1,e)})})}function i(a,b){return new q(function(c){return b.scheduleWithRelative(B(a),function(){c.onNext(0),c.onCompleted()})})}function j(a,b,c){return a===b?new q(function(a){return c.schedulePeriodicWithState(0,b,function(b){return a.onNext(b),b+1})}):r(function(){return h(c.now()+a,b,c)})}function k(a,b,c){return new q(function(d){var e,f=!1,g=new w,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.exception,k=!j):(i.push({value:a.value,timestamp:a.timestamp+b}),k=!f,f=!0),k&&(null!==h?d.onError(h):(e=new v,g.setDisposable(e),e.setDisposable(c.scheduleRecursiveWithRelative(b,function(a){var b,e,g,k;if(null===h){j=!0;do g=null,i.length>0&&i[0].timestamp-c.now()<=0&&(g=i.shift().value),null!==g&&g.accept(d);while(null!==g);k=!1,e=0,i.length>0?(k=!0,e=Math.max(0,i[0].timestamp-c.now())):f=!1,b=h,j=!1,null!==b?d.onError(b):k&&a(e)}}))))}),new x(e,g)},a)}function l(a,b,c){return r(function(){return k(a,b-c.now(),c)})}function m(a,b){return new q(function(c){function d(){g&&(g=!1,c.onNext(e)),f&&c.onCompleted()}var e,f=!1,g=!1,h=new v;return h.setDisposable(a.subscribe(function(a){g=!0,e=a},function(a){c.onError(a)},function(){f=!0,h.dispose()})),new x(h,b.subscribe(d,function(a){c.onError(a)},d))},a)}{var n,o=c.Observable,p=o.prototype,q=c.AnonymousObservable,r=o.defer,s=(o.empty,o.never),t=o.throwException,u=(o.fromArray,c.Scheduler["default"]),v=c.SingleAssignmentDisposable,w=c.SerialDisposable,x=c.CompositeDisposable,y=c.RefCountDisposable,z=c.Subject,A=c.internals.addRef,B=c.Scheduler.normalize,C=c.helpers,D=C.isPromise,E=C.isFunction,F=c.Scheduler.isScheduler,G=o.fromPromise,H={e:{}},I=o.interval=function(a,b){return j(a,a,F(b)?b:u)};o.timer=function(a,b,c){var e;return F(c)||(c=u),b!==d&&"number"==typeof b?e=b:F(b)&&(c=b),a instanceof Date&&e===d?g(a.getTime(),c):a instanceof Date&&e!==d?(e=b,h(a.getTime(),e,c)):e===d?i(a,c):j(a,e,c)}}return p.delay=function(a,b){return F(b)||(b=u),a instanceof Date?l(this,a.getTime(),b):k(this,a,b)},p.debounce=p.throttleWithTimeout=function(a,b){F(b)||(b=u);var c=this;return new q(function(d){var e,f=new w,g=!1,h=0,i=c.subscribe(function(c){g=!0,e=c,h++;var i=h,j=new v;f.setDisposable(j),j.setDisposable(b.scheduleWithRelative(a,function(){g&&h===i&&d.onNext(e),g=!1}))},function(a){f.dispose(),d.onError(a),g=!1,h++},function(){f.dispose(),g&&d.onNext(e),d.onCompleted(),g=!1,h++});return new x(i,f)},this)},p.throttle=function(a,b){return this.debounce(a,b)},p.windowWithTime=function(a,b,c){var d,e=this;return null==b&&(d=a),F(c)||(c=u),"number"==typeof b?d=b:F(b)&&(d=a,c=b),new q(function(b){function f(){var a=new v,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.scheduleWithRelative(o,function(){if(g){var a=new z;k.push(a),b.onNext(A(a,h))}e&&k.shift().onCompleted(),f()}))}var g,h,i=d,j=a,k=[],l=new w,m=0;return g=new x(l),h=new y(g),k.push(new z),b.onNext(A(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)},p.windowWithTimeOrCount=function(a,b,c){var d=this;return F(c)||(c=u),new q(function(e){function f(b){var d=new v;g.setDisposable(d),d.setDisposable(c.scheduleWithRelative(a,function(){if(b===k){j=0;var a=++k;l.onCompleted(),l=new z,e.onNext(A(l,i)),f(a)}}))}var g=new w,h=new x(g),i=new y(h),j=0,k=0,l=new z;return e.onNext(A(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 z,e.onNext(A(l,i))),d&&f(c)},function(a){l.onError(a),e.onError(a)},function(){l.onCompleted(),e.onCompleted()})),i},d)},p.bufferWithTime=function(a,b,c){return this.windowWithTime.apply(this,arguments).selectMany(function(a){return a.toArray()})},p.bufferWithTimeOrCount=function(a,b,c){return this.windowWithTimeOrCount(a,b,c).selectMany(function(a){return a.toArray()})},p.timeInterval=function(a){var b=this;return F(a)||(a=u),r(function(){var c=a.now();return b.map(function(b){var d=a.now(),e=d-c;return c=d,{value:b,interval:e}})})},p.timestamp=function(a){return F(a)||(a=u),this.map(function(b){return{value:b,timestamp:a.now()}})},p.sample=p.throttleLatest=function(a,b){return F(b)||(b=u),"number"==typeof a?m(this,I(a,b)):m(this,a)},p.timeout=function(a,b,c){(null==b||"string"==typeof b)&&(b=t(new Error(b||"Timeout"))),F(c)||(c=u);var d=this,e=a instanceof Date?"scheduleWithAbsolute":"scheduleWithRelative";return new q(function(f){function g(){var d=h;l.setDisposable(c[e](a,function(){h===d&&(D(b)&&(b=G(b)),j.setDisposable(b.subscribe(f)))}))}var h=0,i=new v,j=new w,k=!1,l=new w;return j.setDisposable(i),g(),i.setDisposable(d.subscribe(function(a){k||(h++,f.onNext(a),g())},function(a){k||(h++,f.onError(a))},function(){k||(h++,f.onCompleted())})),new x(j,l)},d)},o.generateWithAbsoluteTime=function(a,b,c,d,e,f){return F(f)||(f=u),new q(function(g){var h=!0,i=!1;return f.scheduleRecursiveWithAbsoluteAndState(a,f.now(),function(a,f){i&&g.onNext(a);try{if(h?h=!1:a=c(a),i=b(a))var j=d(a),k=e(a)}catch(l){return void g.onError(l)}i?f(j,k):g.onCompleted()})})},o.generateWithRelativeTime=function(a,b,c,d,e,f){return F(f)||(f=u),new q(function(g){var h=!0,i=!1;return f.scheduleRecursiveWithRelativeAndState(a,0,function(a,f){i&&g.onNext(a);try{if(h?h=!1:a=c(a),i=b(a))var j=d(a),k=e(a)}catch(l){return void g.onError(l)}i?f(j,k):g.onCompleted()})})},p.delaySubscription=function(a,b){var c=a instanceof Date?"scheduleWithAbsolute":"scheduleWithRelative",d=this;return F(b)||(b=u),new q(function(e){var f=new w;return f.setDisposable(b[c](a,function(){f.setDisposable(d.subscribe(e))})),f},this)},p.delayWithSelector=function(a,b){var c,d,e=this;return E(a)?d=a:(c=a,d=b),new q(function(a){function b(){j.setDisposable(e.subscribe(function(b){var c=f(d)(b);if(c===H)return a.onError(c.e);var e=new v;h.add(e),e.setDisposable(c.subscribe(function(){a.onNext(b),h.remove(e),g()},function(b){a.onError(b)},function(){a.onNext(b),h.remove(e),g()}))},function(b){a.onError(b)},function(){i=!0,j.dispose(),g()}))}function g(){i&&0===h.length&&a.onCompleted()}var h=new x,i=!1,j=new w;return c?j.setDisposable(c.subscribe(b,function(b){a.onError(b)},b)):b(),new x(j,h)},this)},p.timeoutWithSelector=function(a,b,c){1===arguments.length&&(b=a,a=s()),c||(c=t(new Error("Timeout")));var d=this;return new q(function(e){function f(a){function b(){return k===d}var d=k,f=new v;i.setDisposable(f),f.setDisposable(a.subscribe(function(){b()&&h.setDisposable(c.subscribe(e)),f.dispose()},function(a){b()&&e.onError(a)},function(){b()&&h.setDisposable(c.subscribe(e))}))}function g(){var a=!l;return a&&k++,a}var h=new w,i=new w,j=new v;h.setDisposable(j);var k=0,l=!1;return f(a),j.setDisposable(d.subscribe(function(a){if(g()){e.onNext(a);var c;try{c=b(a)}catch(d){return void e.onError(d)}f(D(c)?G(c):c)}},function(a){g()&&e.onError(a)},function(){g()&&e.onCompleted()})),new x(h,i)},d)},p.debounceWithSelector=function(a){var b=this;return new q(function(c){var d,e=!1,f=new w,g=0,h=b.subscribe(function(b){var h;try{h=a(b)}catch(i){return void c.onError(i)}D(h)&&(h=G(h)),e=!0,d=b,g++;var j=g,k=new v;f.setDisposable(k),k.setDisposable(h.subscribe(function(){e&&g===j&&c.onNext(d),e=!1,k.dispose()},c.onError.bind(c),function(){e&&g===j&&c.onNext(d),e=!1,k.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 x(h,f)},b)},p.throttleWithSelector=function(a){return this.debounceWithSelector(a)},p.skipLastWithTime=function(a,b){F(b)||(b=u);var c=this;return new q(function(d){var e=[];return c.subscribe(function(c){var f=b.now();for(e.push({interval:f,value:c});e.length>0&&f-e[0].interval>=a;)d.onNext(e.shift().value)},function(a){d.onError(a)},function(){for(var c=b.now();e.length>0&&c-e[0].interval>=a;)d.onNext(e.shift().value);d.onCompleted()})},c)},p.takeLastWithTime=function(a,b){var c=this;return F(b)||(b=u),new q(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();e.length>0;){var f=e.shift();c-f.interval<=a&&d.onNext(f.value)}d.onCompleted()})},c)},p.takeLastBufferWithTime=function(a,b){var c=this;return F(b)||(b=u),new q(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)},p.takeWithTime=function(a,b){var c=this;return F(b)||(b=u),new q(function(d){return new x(b.scheduleWithRelative(a,function(){d.onCompleted()}),c.subscribe(d))},c)},p.skipWithTime=function(a,b){var c=this;return F(b)||(b=u),new q(function(d){var e=!1;return new x(b.scheduleWithRelative(a,function(){e=!0}),c.subscribe(function(a){e&&d.onNext(a)},d.onError.bind(d),d.onCompleted.bind(d)))},c)},p.skipUntilWithTime=function(a,b){F(b)||(b=u);var c=this,d=a instanceof Date?"scheduleWithAbsolute":"scheduleWithRelative";return new q(function(e){var f=!1;return new x(b[d](a,function(){f=!0}),c.subscribe(function(a){f&&e.onNext(a)},function(a){e.onError(a)},function(){e.onCompleted()}))},c)},p.takeUntilWithTime=function(a,b){F(b)||(b=u);var c=this,d=a instanceof Date?"scheduleWithAbsolute":"scheduleWithRelative";return new q(function(e){return new x(b[d](a,function(){e.onCompleted()}),c.subscribe(e))},c)},p.throttleFirst=function(a,b){F(b)||(b=u);var c=+a||0;if(0>=c)throw new RangeError("windowDuration cannot be less or equal zero.");var d=this;return new q(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});
|
|
//# sourceMappingURL=rx.time.map
|