Skip to content

Commit 69d9ccf

Browse files
authoredSep 4, 2018
fix(node): will no longer error mixing RxJS 6.3 and 6.2 (#4078)
- updates `isTrustedSubscriber` to check for `_addParentTeardownLogic` resolves #4077
1 parent 4dde71b commit 69d9ccf

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed
 

‎spec/Subscriber-spec.ts

+25-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect } from 'chai';
2-
import * as Rx from 'rxjs/Rx';
3-
4-
const Subscriber = Rx.Subscriber;
2+
import { SafeSubscriber } from 'rxjs/internal/Subscriber';
3+
import { Subscriber } from 'rxjs';
4+
import { rxSubscriber } from 'rxjs/internal/symbol/rxSubscriber';
55

66
/** @test {Subscriber} */
77
describe('Subscriber', () => {
@@ -20,6 +20,28 @@ describe('Subscriber', () => {
2020
expect(times).to.equal(2);
2121
});
2222

23+
it('should accept subscribers as a destination if they meet the proper criteria', () => {
24+
const fakeSubscriber = {
25+
[rxSubscriber](this: any) { return this; },
26+
_addParentTeardownLogic() { /* noop */ }
27+
};
28+
29+
const subscriber = new Subscriber(fakeSubscriber as any);
30+
expect((subscriber as any).destination).to.equal(fakeSubscriber);
31+
});
32+
33+
it('should wrap unsafe observers in a safe subscriber', () => {
34+
const observer = {
35+
next(x: any) { /* noop */ },
36+
error(err: any) { /* noop */ },
37+
complete() { /* noop */ }
38+
};
39+
40+
const subscriber = new Subscriber(observer);
41+
expect((subscriber as any).destination).not.to.equal(observer);
42+
expect((subscriber as any).destination).to.be.an.instanceof(SafeSubscriber);
43+
});
44+
2345
it('should ignore error messages after unsubscription', () => {
2446
let times = 0;
2547
let errorCalled = false;

‎src/internal/Subscriber.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ export class Subscriber<T> extends Subscription implements Observer<T> {
190190
* @ignore
191191
* @extends {Ignored}
192192
*/
193-
class SafeSubscriber<T> extends Subscriber<T> {
193+
export class SafeSubscriber<T> extends Subscriber<T> {
194194

195195
private _context: any;
196196

@@ -326,5 +326,5 @@ class SafeSubscriber<T> extends Subscriber<T> {
326326
}
327327

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

0 commit comments

Comments
 (0)
Please sign in to comment.