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

fix(node): will no longer error mixing RxJS 6.3 and 6.2 #4078

Merged
merged 1 commit into from
Sep 4, 2018
Merged
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
28 changes: 25 additions & 3 deletions spec/Subscriber-spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'chai';
import * as Rx from 'rxjs/Rx';

const Subscriber = Rx.Subscriber;
import { SafeSubscriber } from 'rxjs/internal/Subscriber';
import { Subscriber } from 'rxjs';
import { rxSubscriber } from 'rxjs/internal/symbol/rxSubscriber';

/** @test {Subscriber} */
describe('Subscriber', () => {
Expand All @@ -20,6 +20,28 @@ describe('Subscriber', () => {
expect(times).to.equal(2);
});

it('should accept subscribers as a destination if they meet the proper criteria', () => {
const fakeSubscriber = {
[rxSubscriber](this: any) { return this; },
_addParentTeardownLogic() { /* noop */ }
};

const subscriber = new Subscriber(fakeSubscriber as any);
expect((subscriber as any).destination).to.equal(fakeSubscriber);
});

it('should wrap unsafe observers in a safe subscriber', () => {
const observer = {
next(x: any) { /* noop */ },
error(err: any) { /* noop */ },
complete() { /* noop */ }
};

const subscriber = new Subscriber(observer);
expect((subscriber as any).destination).not.to.equal(observer);
expect((subscriber as any).destination).to.be.an.instanceof(SafeSubscriber);
});

it('should ignore error messages after unsubscription', () => {
let times = 0;
let errorCalled = false;
Expand Down
4 changes: 2 additions & 2 deletions src/internal/Subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export class Subscriber<T> extends Subscription implements Observer<T> {
* @ignore
* @extends {Ignored}
*/
class SafeSubscriber<T> extends Subscriber<T> {
export class SafeSubscriber<T> extends Subscriber<T> {

private _context: any;

Expand Down Expand Up @@ -326,5 +326,5 @@ class SafeSubscriber<T> extends Subscriber<T> {
}

function isTrustedSubscriber(obj: any) {
return obj instanceof Subscriber || ('syncErrorThrowable' in obj && obj[rxSubscriberSymbol]);
return obj instanceof Subscriber || ('_addParentTeardownLogic' in obj && obj[rxSubscriberSymbol]);
}