|
3914 | 3914 | }; |
3915 | 3915 |
|
3916 | 3916 | var TakeUntilObservable = (function(__super__) { |
3917 | | - inherits(TakeUntilObservable, __super__); |
3918 | | - |
3919 | | - function TakeUntilObservable(source, other) { |
3920 | | - this.source = source; |
3921 | | - this.other = isPromise(other) ? observableFromPromise(other) : other; |
3922 | | - __super__.call(this); |
3923 | | - } |
3924 | | - |
3925 | | - TakeUntilObservable.prototype.subscribeCore = function(o) { |
3926 | | - return new CompositeDisposable( |
3927 | | - this.source.subscribe(o), |
3928 | | - this.other.subscribe(new InnerObserver(o)) |
3929 | | - ); |
3930 | | - }; |
3931 | | - |
3932 | | - function InnerObserver(o) { |
3933 | | - this.o = o; |
3934 | | - this.isStopped = false; |
3935 | | - } |
3936 | | - InnerObserver.prototype.onNext = function (x) { |
3937 | | - if (this.isStopped) { return; } |
3938 | | - this.o.onCompleted(); |
3939 | | - }; |
3940 | | - InnerObserver.prototype.onError = function (err) { |
3941 | | - if (!this.isStopped) { |
3942 | | - this.isStopped = true; |
3943 | | - this.o.onError(err); |
3944 | | - } |
3945 | | - }; |
3946 | | - InnerObserver.prototype.onCompleted = function () { |
3947 | | - !this.isStopped && (this.isStopped = true); |
3948 | | - }; |
3949 | | - InnerObserver.prototype.dispose = function() { this.isStopped = true; }; |
3950 | | - InnerObserver.prototype.fail = function (e) { |
3951 | | - if (!this.isStopped) { |
3952 | | - this.isStopped = true; |
3953 | | - this.observer.onError(e); |
3954 | | - return true; |
3955 | | - } |
3956 | | - return false; |
3957 | | - }; |
3958 | | - |
3959 | | - return TakeUntilObservable; |
3960 | | - }(ObservableBase)); |
3961 | | - |
3962 | | - /** |
| 3917 | + inherits(TakeUntilObservable, __super__); |
| 3918 | + |
| 3919 | + function TakeUntilObservable(source, other) { |
| 3920 | + this.source = source; |
| 3921 | + this.other = isPromise(other) ? observableFromPromise(other) : other; |
| 3922 | + __super__.call(this); |
| 3923 | + } |
| 3924 | + |
| 3925 | + TakeUntilObservable.prototype.subscribeCore = function(o) { |
| 3926 | + return new CompositeDisposable( |
| 3927 | + this.source.subscribe(o), |
| 3928 | + this.other.subscribe(new InnerObserver(o)) |
| 3929 | + ); |
| 3930 | + }; |
| 3931 | + |
| 3932 | + function InnerObserver(o) { |
| 3933 | + this.o = o; |
| 3934 | + this.isStopped = false; |
| 3935 | + } |
| 3936 | + InnerObserver.prototype.onNext = function (x) { |
| 3937 | + if (this.isStopped) { return; } |
| 3938 | + this.o.onCompleted(); |
| 3939 | + }; |
| 3940 | + InnerObserver.prototype.onError = function (err) { |
| 3941 | + if (!this.isStopped) { |
| 3942 | + this.isStopped = true; |
| 3943 | + this.o.onError(err); |
| 3944 | + } |
| 3945 | + }; |
| 3946 | + InnerObserver.prototype.onCompleted = function () { |
| 3947 | + !this.isStopped && (this.isStopped = true); |
| 3948 | + }; |
| 3949 | + InnerObserver.prototype.dispose = function() { this.isStopped = true; }; |
| 3950 | + InnerObserver.prototype.fail = function (e) { |
| 3951 | + if (!this.isStopped) { |
| 3952 | + this.isStopped = true; |
| 3953 | + this.o.onError(e); |
| 3954 | + return true; |
| 3955 | + } |
| 3956 | + return false; |
| 3957 | + }; |
| 3958 | + |
| 3959 | + return TakeUntilObservable; |
| 3960 | + }(ObservableBase)); |
| 3961 | + |
| 3962 | + /** |
3963 | 3963 | * Returns the values from the source observable sequence until the other observable sequence produces a value. |
3964 | 3964 | * @param {Observable | Promise} other Observable sequence or Promise that terminates propagation of elements of the source sequence. |
3965 | 3965 | * @returns {Observable} An observable sequence containing the elements of the source sequence up to the point the other sequence interrupted further propagation. |
3966 | 3966 | */ |
3967 | 3967 | observableProto.takeUntil = function (other) { |
3968 | 3968 | return new TakeUntilObservable(this, other); |
3969 | 3969 | }; |
| 3970 | + |
3970 | 3971 | function falseFactory() { return false; } |
3971 | 3972 |
|
3972 | 3973 | /** |
|
4353 | 4354 | return this.ensure(action); |
4354 | 4355 | }; |
4355 | 4356 |
|
4356 | | - var IgnoreElementsObservable = (function(__super__) { |
4357 | | - inherits(IgnoreElementsObservable, __super__); |
4358 | | - |
4359 | | - function IgnoreElementsObservable(source) { |
4360 | | - this.source = source; |
4361 | | - __super__.call(this); |
4362 | | - } |
4363 | | - |
4364 | | - IgnoreElementsObservable.prototype.subscribeCore = function (o) { |
4365 | | - return this.source.subscribe(new InnerObserver(o)); |
4366 | | - }; |
4367 | | - |
4368 | | - function InnerObserver(o) { |
4369 | | - this.o = o; |
4370 | | - this.isStopped = false; |
4371 | | - } |
4372 | | - InnerObserver.prototype.onNext = noop; |
4373 | | - InnerObserver.prototype.onError = function (err) { |
4374 | | - if(!this.isStopped) { |
4375 | | - this.isStopped = true; |
4376 | | - this.o.onError(err); |
4377 | | - } |
4378 | | - }; |
4379 | | - InnerObserver.prototype.onCompleted = function () { |
4380 | | - if(!this.isStopped) { |
4381 | | - this.isStopped = true; |
4382 | | - this.o.onCompleted(); |
4383 | | - } |
4384 | | - }; |
4385 | | - InnerObserver.prototype.dispose = function() { this.isStopped = true; }; |
4386 | | - InnerObserver.prototype.fail = function (e) { |
4387 | | - if (!this.isStopped) { |
4388 | | - this.isStopped = true; |
4389 | | - this.observer.onError(e); |
4390 | | - return true; |
4391 | | - } |
4392 | | - |
4393 | | - return false; |
4394 | | - }; |
4395 | | - |
4396 | | - return IgnoreElementsObservable; |
4397 | | - }(ObservableBase)); |
4398 | | - |
4399 | | - /** |
| 4357 | + var IgnoreElementsObservable = (function(__super__) { |
| 4358 | + inherits(IgnoreElementsObservable, __super__); |
| 4359 | + |
| 4360 | + function IgnoreElementsObservable(source) { |
| 4361 | + this.source = source; |
| 4362 | + __super__.call(this); |
| 4363 | + } |
| 4364 | + |
| 4365 | + IgnoreElementsObservable.prototype.subscribeCore = function (o) { |
| 4366 | + return this.source.subscribe(new InnerObserver(o)); |
| 4367 | + }; |
| 4368 | + |
| 4369 | + function InnerObserver(o) { |
| 4370 | + this.o = o; |
| 4371 | + this.isStopped = false; |
| 4372 | + } |
| 4373 | + InnerObserver.prototype.onNext = noop; |
| 4374 | + InnerObserver.prototype.onError = function (err) { |
| 4375 | + if(!this.isStopped) { |
| 4376 | + this.isStopped = true; |
| 4377 | + this.o.onError(err); |
| 4378 | + } |
| 4379 | + }; |
| 4380 | + InnerObserver.prototype.onCompleted = function () { |
| 4381 | + if(!this.isStopped) { |
| 4382 | + this.isStopped = true; |
| 4383 | + this.o.onCompleted(); |
| 4384 | + } |
| 4385 | + }; |
| 4386 | + InnerObserver.prototype.dispose = function() { this.isStopped = true; }; |
| 4387 | + InnerObserver.prototype.fail = function (e) { |
| 4388 | + if (!this.isStopped) { |
| 4389 | + this.isStopped = true; |
| 4390 | + this.observer.onError(e); |
| 4391 | + return true; |
| 4392 | + } |
| 4393 | + |
| 4394 | + return false; |
| 4395 | + }; |
| 4396 | + |
| 4397 | + return IgnoreElementsObservable; |
| 4398 | + }(ObservableBase)); |
| 4399 | + |
| 4400 | + /** |
4400 | 4401 | * Ignores all elements in an observable sequence leaving only the termination messages. |
4401 | 4402 | * @returns {Observable} An empty observable sequence that signals termination, successful or exceptional, of the source sequence. |
4402 | 4403 | */ |
|
5225 | 5226 | }, source); |
5226 | 5227 | }; |
5227 | 5228 |
|
| 5229 | + var TakeObservable = (function(__super__) { |
| 5230 | + inherits(TakeObservable, __super__); |
| 5231 | + |
| 5232 | + function TakeObservable(source, count) { |
| 5233 | + this.source = source; |
| 5234 | + this.count = count; |
| 5235 | + __super__.call(this); |
| 5236 | + } |
| 5237 | + |
| 5238 | + TakeObservable.prototype.subscribeCore = function (o) { |
| 5239 | + return this.source.subscribe(new InnerObserver(o, this.count)); |
| 5240 | + }; |
| 5241 | + |
| 5242 | + function InnerObserver(o, c) { |
| 5243 | + this.o = o; |
| 5244 | + this.c = c; |
| 5245 | + this.r = c; |
| 5246 | + this.isStopped = false; |
| 5247 | + } |
| 5248 | + InnerObserver.prototype.onNext = function (x) { |
| 5249 | + if (this.isStopped) { return; } |
| 5250 | + if (this.r-- > 0) { |
| 5251 | + this.o.onNext(x); |
| 5252 | + this.r === 0 && this.o.onCompleted(); |
| 5253 | + } |
| 5254 | + }; |
| 5255 | + InnerObserver.prototype.onError = function (err) { |
| 5256 | + if (!this.isStopped) { |
| 5257 | + this.isStopped = true; |
| 5258 | + this.o.onError(err); |
| 5259 | + } |
| 5260 | + }; |
| 5261 | + InnerObserver.prototype.onCompleted = function () { |
| 5262 | + if (!this.isStopped) { |
| 5263 | + this.isStopped = true; |
| 5264 | + this.o.onCompleted(); |
| 5265 | + } |
| 5266 | + }; |
| 5267 | + InnerObserver.prototype.dispose = function () { this.isStopped = true; }; |
| 5268 | + InnerObserver.prototype.fail = function (e) { |
| 5269 | + if (!this.isStopped) { |
| 5270 | + this.isStopped = true; |
| 5271 | + this.o.onError(e); |
| 5272 | + return true; |
| 5273 | + } |
| 5274 | + return false; |
| 5275 | + } |
| 5276 | + |
| 5277 | + return TakeObservable; |
| 5278 | + }(ObservableBase)); |
| 5279 | + |
5228 | 5280 | /** |
5229 | 5281 | * Returns a specified number of contiguous elements from the start of an observable sequence, using the specified scheduler for the edge case of take(0). |
5230 | 5282 | * |
|
5237 | 5289 | observableProto.take = function (count, scheduler) { |
5238 | 5290 | if (count < 0) { throw new ArgumentOutOfRangeError(); } |
5239 | 5291 | if (count === 0) { return observableEmpty(scheduler); } |
5240 | | - var source = this; |
5241 | | - return new AnonymousObservable(function (o) { |
5242 | | - var remaining = count; |
5243 | | - return source.subscribe(function (x) { |
5244 | | - if (remaining-- > 0) { |
5245 | | - o.onNext(x); |
5246 | | - remaining === 0 && o.onCompleted(); |
5247 | | - } |
5248 | | - }, function (e) { o.onError(e); }, function () { o.onCompleted(); }); |
5249 | | - }, source); |
| 5292 | + return new TakeObservable(this, count); |
5250 | 5293 | }; |
5251 | 5294 |
|
5252 | 5295 | /** |
|
0 commit comments