es6/operator/switchMapTo.js
import { OuterSubscriber } from '../OuterSubscriber';
import { subscribeToResult } from '../util/subscribeToResult';
/* tslint:disable:max-line-length */
export function switchMapTo(innerObservable, resultSelector) {
return this.lift(new SwitchMapToOperator(innerObservable, resultSelector));
}
var SwitchMapToOperator = (function () {
function SwitchMapToOperator(observable, resultSelector) {
this.observable = observable;
this.resultSelector = resultSelector;
}
SwitchMapToOperator.prototype.call = function (subscriber, source) {
return source._subscribe(new SwitchMapToSubscriber(subscriber, this.observable, this.resultSelector));
};
return SwitchMapToOperator;
}());
/**
* We need this JSDoc comment for affecting ESDoc.
* @ignore
* @extends {Ignored}
*/
var SwitchMapToSubscriber = (function (_super) {
__extends(SwitchMapToSubscriber, _super);
function SwitchMapToSubscriber(destination, inner, resultSelector) {
_super.call(this, destination);
this.inner = inner;
this.resultSelector = resultSelector;
this.index = 0;
}
SwitchMapToSubscriber.prototype._next = function (value) {
var innerSubscription = this.innerSubscription;
if (innerSubscription) {
innerSubscription.unsubscribe();
}
this.add(this.innerSubscription = subscribeToResult(this, this.inner, value, this.index++));
};
SwitchMapToSubscriber.prototype._complete = function () {
var innerSubscription = this.innerSubscription;
if (!innerSubscription || innerSubscription.closed) {
_super.prototype._complete.call(this);
}
};
SwitchMapToSubscriber.prototype._unsubscribe = function () {
this.innerSubscription = null;
};
SwitchMapToSubscriber.prototype.notifyComplete = function (innerSub) {
this.remove(innerSub);
this.innerSubscription = null;
if (this.isStopped) {
_super.prototype._complete.call(this);
}
};
SwitchMapToSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
var _a = this, resultSelector = _a.resultSelector, destination = _a.destination;
if (resultSelector) {
this.tryResultSelector(outerValue, innerValue, outerIndex, innerIndex);
}
else {
destination.next(innerValue);
}
};
SwitchMapToSubscriber.prototype.tryResultSelector = function (outerValue, innerValue, outerIndex, innerIndex) {
var _a = this, resultSelector = _a.resultSelector, destination = _a.destination;
var result;
try {
result = resultSelector(outerValue, innerValue, outerIndex, innerIndex);
}
catch (err) {
destination.error(err);
return;
}
destination.next(result);
};
return SwitchMapToSubscriber;
}(OuterSubscriber));
//# sourceMappingURL=switchMapTo.js.map