Skip to content
Closed
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
8 changes: 6 additions & 2 deletions packages/core/src/util/lang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ export function isPromise<T = any>(obj: any): obj is Promise<T> {

/**
* Determine if the argument is an Observable
*
* Strictly this tests that the `obj` is `Subscribable`, since `Observable`
* types need additional methods, such as `lift()`. But it is adequate for our
* needs since within the Angular framework code we only ever need to use the
* `subscribe()` method, and RxJS has mechanisms to wrap `Subscribable` objects
* into `Observable` as needed.
*/
export function isObservable(obj: any|Observable<any>): obj is Observable<any> {
// TODO: use isObservable once we update pass rxjs 6.1
// https://github.com/ReactiveX/rxjs/blob/master/CHANGELOG.md#610-2018-05-03
return !!obj && typeof obj.subscribe === 'function';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be fair, shouldn't this method be renamed to isSubscribable? It literally checks whether the given object can be subscribed to.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but to be consistent that is a bigger change, which would involve us changing our use of Observable to Subscribable across the framework.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, agreed. This is also somewhat addressed in #39627 where it actually is renamed to isSubscribable and isObservable is still exported as a type assertion on that function.

}