fix(common): introduce isObservable method (#14067)

Closes #8848

PR Close #14067
This commit is contained in:
Dzmitry Shylovich
2017-01-23 20:48:04 +03:00
committed by Miško Hevery
parent fe441186e7
commit ff290af38c
7 changed files with 51 additions and 6 deletions

View File

@ -41,7 +41,7 @@ import * as reflector_reader from './reflection/reflector_reader';
import * as reflection_types from './reflection/types';
import * as api from './render/api';
import * as decorators from './util/decorators';
import {isPromise} from './util/lang';
import {isObservable, isPromise} from './util/lang';
export const __core_private__: {
isDefaultChangeDetectionStrategy: typeof constants.isDefaultChangeDetectionStrategy,
@ -107,6 +107,7 @@ export const __core_private__: {
_ComponentStillLoadingError?: ComponentStillLoadingError,
ComponentStillLoadingError: typeof ComponentStillLoadingError,
isPromise: typeof isPromise,
isObservable: typeof isObservable,
AnimationTransition: typeof AnimationTransition
view_utils: typeof view_utils,
} = {
@ -157,5 +158,6 @@ export const __core_private__: {
FILL_STYLE_FLAG: FILL_STYLE_FLAG_,
ComponentStillLoadingError: ComponentStillLoadingError,
isPromise: isPromise,
isObservable: isObservable,
AnimationTransition: AnimationTransition
};

View File

@ -6,6 +6,9 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Observable} from 'rxjs/Observable';
import {$$observable as symbolObservable} from 'rxjs/symbol/observable';
/**
* Determine if the argument is shaped like a Promise
*/
@ -14,3 +17,10 @@ export function isPromise(obj: any): obj is Promise<any> {
// It's up to the caller to ensure that obj.then conforms to the spec
return !!obj && typeof obj.then === 'function';
}
/**
* Determine if the argument is an Observable
*/
export function isObservable(obj: any | Observable<any>): obj is Observable<any> {
return !!(obj && obj[symbolObservable]);
}