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(core): use presence of .subscribe to detect observables rather than Symbol.observable #15171

Merged
merged 1 commit into from Mar 16, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/core/rollup.config.js
Expand Up @@ -16,7 +16,6 @@ export default {
'rxjs/Subject': 'Rx',
'rxjs/Observer': 'Rx',
'rxjs/Subscription': 'Rx',
'rxjs/symbol/observable': 'Rx.Symbol.observable',
'rxjs/observable/merge': 'Rx.Observable',
'rxjs/operator/share': 'Rx.Observable.prototype'
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/util/lang.ts
Expand Up @@ -7,7 +7,6 @@
*/

import {Observable} from 'rxjs/Observable';
import {$$observable as symbolObservable} from 'rxjs/symbol/observable';

/**
* Determine if the argument is shaped like a Promise
Expand All @@ -22,7 +21,8 @@ export function isPromise(obj: any): obj is Promise<any> {
* Determine if the argument is an Observable
*/
export function isObservable(obj: any | Observable<any>): obj is Observable<any> {
return !!(obj && obj[symbolObservable]);
// TODO use Symbol.observable when https://github.com/ReactiveX/rxjs/issues/2415 will be resolved
return !!obj && typeof obj.subscribe === 'function';
}

// TODO(misko): replace with Object.assign once we require ES6.
Expand Down
6 changes: 3 additions & 3 deletions packages/core/test/util/lang_spec.ts
Expand Up @@ -30,6 +30,9 @@ export function main() {
describe('isObservable', () => {
it('should be true for an Observable', () => expect(isObservable(of (true))).toEqual(true));

it('should be true if the argument is the object with subscribe function',
() => expect(isObservable({subscribe: () => {}})).toEqual(true));

it('should be false if the argument is undefined',
() => expect(isObservable(undefined)).toEqual(false));

Expand All @@ -40,8 +43,5 @@ export function main() {

it('should be false if the argument is a function',
() => expect(isObservable(() => {})).toEqual(false));

it('should be false if the argument is the object with subscribe function',
() => expect(isObservable({subscribe: () => {}})).toEqual(false));
});
}