|
2386 | 2386 | __super__.call(this, subscribe); |
2387 | 2387 | } |
2388 | 2388 |
|
| 2389 | + ObservableBase.prototype.subscribeCore = function(observer) { |
| 2390 | + throw new Error('Not implemeneted'); |
| 2391 | + } |
| 2392 | + |
2389 | 2393 | return ObservableBase; |
2390 | 2394 |
|
2391 | 2395 | }(Observable)); |
|
4431 | 4435 |
|
4432 | 4436 | }(ObservableBase)); |
4433 | 4437 |
|
4434 | | - var MapObserver = (function (__super__) { |
4435 | | - inherits(MapObserver, __super__); |
| 4438 | + function MapObserver(observer, selector, source) { |
| 4439 | + this.observer = observer; |
| 4440 | + this.selector = selector; |
| 4441 | + this.source = source; |
| 4442 | + this.index = 0; |
| 4443 | + this.isStopped = false; |
| 4444 | + } |
4436 | 4445 |
|
4437 | | - function MapObserver(observer, selector, source) { |
4438 | | - this.observer = observer; |
4439 | | - this.selector = selector; |
4440 | | - this.source = source; |
4441 | | - this.index = 0; |
4442 | | - __super__.call(this); |
| 4446 | + MapObserver.prototype.onNext = function(x) { |
| 4447 | + if (this.isStopped) { return; } |
| 4448 | + try { |
| 4449 | + var result = this.selector(x, this.index++, this.source); |
| 4450 | + } catch(e) { |
| 4451 | + return this.observer.onError(e); |
4443 | 4452 | } |
4444 | | - |
4445 | | - MapObserver.prototype.next = function(x) { |
4446 | | - try { |
4447 | | - var result = this.selector(x, this.index++, this.source); |
4448 | | - } catch(e) { |
4449 | | - return this.observer.onError(e); |
4450 | | - } |
4451 | | - this.observer.onNext(result); |
4452 | | - }; |
4453 | | - |
4454 | | - MapObserver.prototype.error = function (e) { |
| 4453 | + this.observer.onNext(result); |
| 4454 | + }; |
| 4455 | + MapObserver.prototype.onError = function (e) { |
| 4456 | + if(!this.isStopped) { this.isStopped = true; this.observer.onError(e); } |
| 4457 | + }; |
| 4458 | + MapObserver.prototype.onCompleted = function () { |
| 4459 | + if(!this.isStopped) { this.isStopped = true; this.observer.onCompleted(); } |
| 4460 | + }; |
| 4461 | + MapObserver.prototype.dispose = function() { this.isStopped = true; }; |
| 4462 | + MapObserver.prototype.fail = function (e) { |
| 4463 | + if (!this.isStopped) { |
| 4464 | + this.isStopped = true; |
4455 | 4465 | this.observer.onError(e); |
4456 | | - }; |
4457 | | - |
4458 | | - MapObserver.prototype.completed = function () { |
4459 | | - this.observer.onCompleted(); |
4460 | | - }; |
| 4466 | + return true; |
| 4467 | + } |
4461 | 4468 |
|
4462 | | - return MapObserver; |
4463 | | - }(AbstractObserver)); |
| 4469 | + return false; |
| 4470 | + }; |
4464 | 4471 |
|
4465 | 4472 | /** |
4466 | 4473 | * Projects each element of an observable sequence into a new form by incorporating the element's index. |
|
4476 | 4483 | }; |
4477 | 4484 |
|
4478 | 4485 | /** |
4479 | | - * Retrieves the value of a specified property from all elements in the Observable sequence. |
4480 | | - * @param {String} prop The property to pluck. |
| 4486 | + * Retrieves the value of a specified nested property from all elements in |
| 4487 | + * the Observable sequence. |
| 4488 | + * @param {Arguments} arguments The nested properties to pluck. |
4481 | 4489 | * @returns {Observable} Returns a new Observable sequence of property values. |
4482 | 4490 | */ |
4483 | | - observableProto.pluck = function (prop) { |
4484 | | - return this.map(function (x) { return x[prop]; }); |
| 4491 | + observableProto.pluck = function () { |
| 4492 | + var args = arguments, len = arguments.length; |
| 4493 | + if (len === 0) { throw new Error('List of properties cannot be empty.'); } |
| 4494 | + return this.map(function (x) { |
| 4495 | + var currentProp = x; |
| 4496 | + for (var i = 0; i < len; i++) { |
| 4497 | + var p = currentProp[args[i]]; |
| 4498 | + if (typeof p !== 'undefined') { |
| 4499 | + currentProp = p; |
| 4500 | + } else { |
| 4501 | + return undefined; |
| 4502 | + } |
| 4503 | + } |
| 4504 | + return currentProp; |
| 4505 | + }); |
4485 | 4506 | }; |
4486 | 4507 |
|
4487 | 4508 | function flatMap(source, selector, thisArg) { |
|
4719 | 4740 |
|
4720 | 4741 | }(ObservableBase)); |
4721 | 4742 |
|
4722 | | - var FilterObserver = (function (__super__) { |
4723 | | - inherits(FilterObserver, __super__); |
| 4743 | + function FilterObserver(observer, predicate, source) { |
| 4744 | + this.observer = observer; |
| 4745 | + this.predicate = predicate; |
| 4746 | + this.source = source; |
| 4747 | + this.index = 0; |
| 4748 | + this.isStopped = false; |
| 4749 | + } |
4724 | 4750 |
|
4725 | | - function FilterObserver(observer, predicate, source) { |
4726 | | - this.observer = observer; |
4727 | | - this.predicate = predicate; |
4728 | | - this.source = source; |
4729 | | - this.index = 0; |
4730 | | - __super__.call(this); |
| 4751 | + FilterObserver.prototype.onNext = function(x) { |
| 4752 | + try { |
| 4753 | + var shouldYield = this.predicate(x, this.index++, this.source); |
| 4754 | + } catch(e) { |
| 4755 | + return this.observer.onError(e); |
4731 | 4756 | } |
| 4757 | + shouldYield && this.observer.onNext(x); |
| 4758 | + }; |
4732 | 4759 |
|
4733 | | - FilterObserver.prototype.next = function(x) { |
4734 | | - try { |
4735 | | - var shouldYield = this.predicate(x, this.index++, this.source); |
4736 | | - } catch(e) { |
4737 | | - return this.observer.onError(e); |
4738 | | - } |
4739 | | - shouldYield && this.observer.onNext(x); |
4740 | | - }; |
4741 | | - |
4742 | | - FilterObserver.prototype.error = function (e) { |
| 4760 | + FilterObserver.prototype.onError = function (e) { |
| 4761 | + if(!this.isStopped) { this.isStopped = true; this.observer.onError(e); } |
| 4762 | + }; |
| 4763 | + FilterObserver.prototype.onCompleted = function () { |
| 4764 | + if(!this.isStopped) { this.isStopped = true; this.observer.onCompleted(); } |
| 4765 | + }; |
| 4766 | + FilterObserver.prototype.dispose = function() { this.isStopped = true; }; |
| 4767 | + FilterObserver.prototype.fail = function (e) { |
| 4768 | + if (!this.isStopped) { |
| 4769 | + this.isStopped = true; |
4743 | 4770 | this.observer.onError(e); |
4744 | | - }; |
| 4771 | + return true; |
| 4772 | + } |
| 4773 | + |
| 4774 | + return false; |
| 4775 | + }; |
4745 | 4776 |
|
4746 | | - FilterObserver.prototype.completed = function () { |
4747 | | - this.observer.onCompleted(); |
4748 | | - }; |
4749 | 4777 |
|
4750 | | - return FilterObserver; |
4751 | | - }(AbstractObserver)); |
4752 | 4778 |
|
4753 | 4779 | /** |
4754 | 4780 | * Filters the elements of an observable sequence based on a predicate by incorporating the element's index. |
|
0 commit comments