diff --git a/src/operator/single.ts b/src/operator/single.ts index 7ba02dafe1..6e414e8d2e 100644 --- a/src/operator/single.ts +++ b/src/operator/single.ts @@ -2,9 +2,6 @@ import {Observable} from '../Observable'; import {Operator} from '../Operator'; import {Subscriber} from '../Subscriber'; import {Observer} from '../Observer'; - -import {tryCatch} from '../util/tryCatch'; -import {errorObject} from '../util/errorObject'; import {EmptyError} from '../util/EmptyError'; /** @@ -55,20 +52,25 @@ class SingleSubscriber extends Subscriber { protected _next(value: T): void { const predicate = this.predicate; - const currentIndex = this.index++; - + this.index++; if (predicate) { - let result = tryCatch(predicate)(value, currentIndex, this.source); - if (result === errorObject) { - this.destination.error(errorObject.e); - } else if (result) { - this.applySingleValue(value); - } + this.tryNext(value); } else { this.applySingleValue(value); } } + private tryNext(value: T): void { + try { + const result = this.predicate(value, this.index, this.source); + if (result) { + this.applySingleValue(value); + } + } catch (err) { + this.destination.error(err); + } + } + protected _complete(): void { const destination = this.destination;