forked from Reactive-Extensions/RxJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rx.backpressure.min.js
1 lines (1 loc) · 4.64 KB
/
rx.backpressure.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,i=e[typeof module]&&module&&!module.nodeType&&module,o=(i&&i.exports===r&&r,e[typeof global]&&global);!o||o.global!==o&&o.window!==o||(n=o),"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){function r(){if(this.isDisposed)throw Error(v)}function i(t,e,n){return new u(function(r){function i(t,e){h[e]=t;var i;if(s[e]=!0,u||(u=s.every(b))){try{i=n.apply(null,h)}catch(o){return r.onError(o),undefined}r.onNext(i)}else a&&r.onCompleted()}var o=2,s=[!1,!1],u=!1,a=!1,h=Array(o);return new c(t.subscribe(function(t){i(t,0)},r.onError.bind(r),function(){a=!0,r.onCompleted()}),e.subscribe(function(t){i(t,1)},r.onError.bind(r)))})}var o=n.Observable,s=o.prototype,u=n.AnonymousObservable,c=n.CompositeDisposable,a=n.Subject,h=n.Observer,l=n.Disposable.empty,f=n.Disposable.create,p=n.internals.inherits,d=n.internals.addProperties,b=(n.Scheduler.timeout,n.helpers.identity),v="Object has been disposed",m=function(t){function e(t){var e=this.source.publish(),n=e.subscribe(t),r=l,i=this.subject.distinctUntilChanged().subscribe(function(t){t?r=e.connect():(r.dispose(),r=l)});return new c(n,r,i)}function n(n,r){this.source=n,this.subject=r||new a,this.isPaused=!0,t.call(this,e)}return p(n,t),n.prototype.pause=function(){this.isPaused!==!0&&(this.isPaused=!0,this.subject.onNext(!1))},n.prototype.resume=function(){this.isPaused!==!1&&(this.isPaused=!1,this.subject.onNext(!0))},n}(o);s.pausable=function(t){return new m(this,t)};var y=function(t){function e(t){var e=[],n=!0,r=i(this.source,this.subject.distinctUntilChanged(),function(t,e){return{data:t,shouldFire:e}}).subscribe(function(r){if(r.shouldFire&&n&&t.onNext(r.data),r.shouldFire&&!n){for(;e.length>0;)t.onNext(e.shift());n=!0}else r.shouldFire||n?!r.shouldFire&&n&&(n=!1):e.push(r.data)},function(n){for(;e.length>0;)t.onNext(e.shift());t.onError(n)},function(){for(;e.length>0;)t.onNext(e.shift());t.onCompleted()});return this.subject.onNext(!1),r}function n(n,r){this.source=n,this.subject=r||new a,this.isPaused=!0,t.call(this,e)}return p(n,t),n.prototype.pause=function(){this.isPaused!==!0&&(this.isPaused=!0,this.subject.onNext(!1))},n.prototype.resume=function(){this.isPaused!==!1&&(this.isPaused=!1,this.subject.onNext(!0))},n}(o);s.pausableBuffered=function(t){return new y(this,t)},s.controlled=function(t){return null==t&&(t=!0),new w(this,t)};var w=function(t){function e(t){return this.source.subscribe(t)}function n(n,r){t.call(this,e),this.subject=new g(r),this.source=n.multicast(this.subject).refCount()}return p(n,t),n.prototype.request=function(t){return null==t&&(t=-1),this.subject.request(t)},n}(o),g=n.ControlledSubject=function(t){function e(t){return this.subject.subscribe(t)}function n(n){null==n&&(n=!0),t.call(this,e),this.subject=new a,this.enableQueue=n,this.queue=n?[]:null,this.requestedCount=0,this.requestedDisposable=l,this.error=null,this.hasFailed=!1,this.hasCompleted=!1,this.controlledDisposable=l}return p(n,t),d(n.prototype,h,{onCompleted:function(){r.call(this),this.hasCompleted=!0,this.enableQueue&&0!==this.queue.length||this.subject.onCompleted()},onError:function(t){r.call(this),this.hasFailed=!0,this.error=t,this.enableQueue&&0!==this.queue.length||this.subject.onError(t)},onNext:function(t){r.call(this);var e=!1;0===this.requestedCount?this.enableQueue&&this.queue.push(t):(-1!==this.requestedCount&&0===this.requestedCount--&&this.disposeCurrentRequest(),e=!0),e&&this.subject.onNext(t)},_processRequest:function(t){if(this.enableQueue){for(;this.queue.length>=t&&t>0;)this.subject.onNext(this.queue.shift()),t--;return 0!==this.queue.length?{numberOfItems:t,returnValue:!0}:{numberOfItems:t,returnValue:!1}}return this.hasFailed?(this.subject.onError(this.error),this.controlledDisposable.dispose(),this.controlledDisposable=l):this.hasCompleted&&(this.subject.onCompleted(),this.controlledDisposable.dispose(),this.controlledDisposable=l),{numberOfItems:t,returnValue:!1}},request:function(t){r.call(this),this.disposeCurrentRequest();var e=this,n=this._processRequest(t);return t=n.numberOfItems,n.returnValue?l:(this.requestedCount=t,this.requestedDisposable=f(function(){e.requestedCount=0}),this.requestedDisposable)},disposeCurrentRequest:function(){this.requestedDisposable.dispose(),this.requestedDisposable=l},dispose:function(){this.isDisposed=!0,this.error=null,this.subject.dispose(),this.requestedDisposable.dispose()}}),n}(o);return n});