Skip to content

Commit

Permalink
feat(Observable): subscribe accepts objects with rxSubscriber symbol
Browse files Browse the repository at this point in the history
removes instanceof Subject check
adds check for rxSubscriber symbol on whatever is passed

related #899
  • Loading branch information
benlesh committed Dec 8, 2015
1 parent 7bda360 commit b7672f4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
10 changes: 5 additions & 5 deletions spec/observable-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ describe('Observable', function () {
});

it('should return the given subject when called with a Subject', function () {
var source = Observable.of(42)
var subject = new Rx.Subject()
var subscriber = source.subscribe(subject)
expect(subscriber).toBe(subject)
})
var source = Observable.of(42);
var subject = new Rx.Subject();
var subscriber = source.subscribe(subject);
expect(subscriber).toBe(subject);
});

describe('when called with an anonymous observer', function () {
it('should accept an anonymous observer with just a next function', function () {
Expand Down
5 changes: 4 additions & 1 deletion src/Observable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {GroupedObservable} from './operator/groupBy-support';
import {ConnectableObservable} from './observable/ConnectableObservable';
import {Subject} from './Subject';
import {Notification} from './Notification';
import {rxSubscriber} from'./symbol/rxSubscriber';

/**
* A representation of any set of values over any amount of time. This the most basic building block
Expand Down Expand Up @@ -89,8 +90,10 @@ export class Observable<T> implements CoreOperators<T> {
let subscriber: Subscriber<T>;

if (observerOrNext && typeof observerOrNext === 'object') {
if (observerOrNext instanceof Subscriber || observerOrNext instanceof Subject) {
if (observerOrNext instanceof Subscriber) {
subscriber = (<Subscriber<T>> observerOrNext);
} else if (observerOrNext[rxSubscriber]) {
subscriber = observerOrNext[rxSubscriber]();
} else {
subscriber = new Subscriber(<Observer<T>> observerOrNext);
}
Expand Down

0 comments on commit b7672f4

Please sign in to comment.