Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(Observable): Subjects no longer wrapped in Subscriber #863

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion spec/observable-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ describe('Observable', function () {
expect(unsubscribeCalled).toBe(true);
});

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)
})

describe('when called with an anonymous observer', function () {
it('should accept an anonymous observer with just a next function', function () {
Observable.of(1).subscribe({
Expand Down Expand Up @@ -161,4 +168,4 @@ describe('Observable.create', function () {
result.subscribe(function () { });
expect(called).toBe(true);
});
});
});
2 changes: 1 addition & 1 deletion src/Observable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class Observable<T> implements CoreOperators<T> {
let subscriber: Subscriber<T>;

if (observerOrNext && typeof observerOrNext === 'object') {
if (observerOrNext instanceof Subscriber) {
if (observerOrNext instanceof Subscriber || observerOrNext instanceof Subject) {
subscriber = (<Subscriber<T>> observerOrNext);
} else {
subscriber = new Subscriber(<Observer<T>> observerOrNext);
Expand Down
4 changes: 3 additions & 1 deletion src/Rx.KitchenSink.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* tslint:disable:no-unused-variable */
import {Subject} from './Subject';
/* tslint:enable:no-unused-variable */
import {Observable} from './Observable';
import {CoreOperators} from './CoreOperators';
import {Scheduler as IScheduler} from './Scheduler';
Expand Down Expand Up @@ -125,7 +128,6 @@ import './operator/zip';
import './operator/zipAll';

/* tslint:disable:no-unused-variable */
import {Subject} from './Subject';
import {Subscription} from './Subscription';
import {Subscriber} from './Subscriber';
import {AsyncSubject} from './subject/AsyncSubject';
Expand Down
7 changes: 6 additions & 1 deletion src/Rx.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/* tslint:disable:no-unused-variable */
// Subject imported before Observable to bypass circular dependency issue since
// Subject extends Observable and Observable references Subject in it's
// definition
import {Subject} from './Subject';
/* tslint:enable:no-unused-variable */
import {Observable} from './Observable';

// statics
Expand Down Expand Up @@ -101,7 +107,6 @@ import './operator/zip';
import './operator/zipAll';

/* tslint:disable:no-unused-variable */
import {Subject} from './Subject';
import {Subscription} from './Subscription';
import {Subscriber} from './Subscriber';
import {AsyncSubject} from './subject/AsyncSubject';
Expand Down