Skip to content

Commit

Permalink
fix(node): will no longer error mixing RxJS 6.3 and 6.2 (#4078)
Browse files Browse the repository at this point in the history
- updates `isTrustedSubscriber` to check for `_addParentTeardownLogic`

resolves #4077
  • Loading branch information
benlesh committed Sep 4, 2018
1 parent 4dde71b commit 69d9ccf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
28 changes: 25 additions & 3 deletions spec/Subscriber-spec.ts
@@ -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
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]);
}

0 comments on commit 69d9ccf

Please sign in to comment.