diff --git a/src/Observable.ts b/src/Observable.ts index 7d803addc5..79e6a904b1 100644 --- a/src/Observable.ts +++ b/src/Observable.ts @@ -11,14 +11,14 @@ import $$observable from './util/Symbol_observable'; /** * A representation of any set of values over any amount of time. This the most basic building block * of RxJS. - * + * * @class Observable */ export default class Observable implements CoreOperators { source: Observable; operator: Operator; _isScalar: boolean = false; - + /** * @constructor * @param {Function} subscribe the function that is @@ -31,25 +31,25 @@ export default class Observable implements CoreOperators { this._subscribe = subscribe; } } - - // HACK: Since TypeScript inherits static properties too, we have to + + // HACK: Since TypeScript inherits static properties too, we have to // fight against TypeScript here so Subject can have a different static create signature /** * @static * @method create * @param {Function} subscribe? the subscriber function to be passed to the Observable constructor * @returns {Observable} a new cold observable - * @description creates a new cold Observable by calling the Observable constructor + * @description creates a new cold Observable by calling the Observable constructor */ static create: Function = (subscribe?: (subscriber: Subscriber) => Subscription|Function|void) => { return new Observable(subscribe); }; - + /** * @method lift * @param {Operator} operator the operator defining the operation to take on the observable * @returns {Observable} a new observable with the Operator applied - * @description creates a new Observable, with this Observable as the source, and the passed + * @description creates a new Observable, with this Observable as the source, and the passed * operator defined as the new observable's operator. */ lift(operator: Operator): Observable { @@ -70,7 +70,7 @@ export default class Observable implements CoreOperators { /** * @method subscribe - * @param {Observer|Function} observerOrNext (optional) either an observer defining all functions to be called, + * @param {Observer|Function} observerOrNext (optional) either an observer defining all functions to be called, * or the first of three possible handlers, which is the handler for each value emitted from the observable. * @param {Function} error (optional) a handler for a terminal event resulting from an error. If no error handler is provided, * the error will be thrown as unhandled @@ -116,11 +116,11 @@ export default class Observable implements CoreOperators { PromiseCtor = root.Promise; } } - + if(!PromiseCtor) { throw new Error('no Promise impl found'); } - + return new PromiseCtor((resolve, reject) => { this.subscribe(next, reject, resolve); }); diff --git a/src/Subject.ts b/src/Subject.ts index 6377a7589d..8c628e7bb4 100644 --- a/src/Subject.ts +++ b/src/Subject.ts @@ -16,12 +16,11 @@ const _subscriberNext = Subscriber.prototype._next; const _subscriberError = Subscriber.prototype._error; const _subscriberComplete = Subscriber.prototype._complete; -const _observableSubscribe = Observable.prototype._subscribe; export default class Subject extends Observable implements Observer, Subscription { _subscriptions: Subscription[]; _unsubscribe: () => void; - + static create(source: Observable, destination: Observer): Subject { return new BidirectionalSubject(source, destination); } @@ -177,7 +176,8 @@ class BidirectionalSubject extends Subject { } _subscribe(subscriber: Subscriber) { - return _observableSubscribe.call(this, subscriber); + const operator = this.operator; + return this.source._subscribe.call(this.source, operator ? operator.call(subscriber) : subscriber); } next(x) {