refactor: use isObservable provided by rxjs 6.1+ (#27668)
Refactor common, core, forms, router to use the isObservable method from rxjs 6.1+. Remove the isObservable method from core. PR Close #27668
This commit is contained in:
parent
c291c8e2cb
commit
92c547830a
|
@ -1 +1,3 @@
|
||||||
import "@angular/core";
|
import "@angular/core";
|
||||||
|
|
||||||
|
import "rxjs";
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
import "tslib";
|
import "tslib";
|
||||||
|
|
||||||
import "@angular/core";
|
import "@angular/core";
|
||||||
|
|
||||||
|
import "rxjs";
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {ChangeDetectorRef, EventEmitter, OnDestroy, Pipe, PipeTransform, WrappedValue, ɵisObservable, ɵisPromise, ɵlooseIdentical} from '@angular/core';
|
import {ChangeDetectorRef, EventEmitter, OnDestroy, Pipe, PipeTransform, WrappedValue, ɵisPromise, ɵlooseIdentical} from '@angular/core';
|
||||||
import {Observable, SubscriptionLike} from 'rxjs';
|
import {Observable, SubscriptionLike, isObservable} from 'rxjs';
|
||||||
import {invalidPipeArgumentError} from './invalid_pipe_argument_error';
|
import {invalidPipeArgumentError} from './invalid_pipe_argument_error';
|
||||||
|
|
||||||
interface SubscriptionStrategy {
|
interface SubscriptionStrategy {
|
||||||
|
@ -122,7 +122,7 @@ export class AsyncPipe implements OnDestroy, PipeTransform {
|
||||||
return _promiseStrategy;
|
return _promiseStrategy;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ɵisObservable(obj)) {
|
if (isObservable(obj)) {
|
||||||
return _observableStrategy;
|
return _observableStrategy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ export {global as ɵglobal} from './util/global';
|
||||||
export {looseIdentical as ɵlooseIdentical,} from './util/comparison';
|
export {looseIdentical as ɵlooseIdentical,} from './util/comparison';
|
||||||
export {stringify as ɵstringify} from './util/stringify';
|
export {stringify as ɵstringify} from './util/stringify';
|
||||||
export {makeDecorator as ɵmakeDecorator} from './util/decorators';
|
export {makeDecorator as ɵmakeDecorator} from './util/decorators';
|
||||||
export {isObservable as ɵisObservable, isPromise as ɵisPromise} from './util/lang';
|
export {isPromise as ɵisPromise} from './util/lang';
|
||||||
export {clearOverrides as ɵclearOverrides, initServicesIfNeeded as ɵinitServicesIfNeeded, overrideComponentView as ɵoverrideComponentView, overrideProvider as ɵoverrideProvider} from './view/index';
|
export {clearOverrides as ɵclearOverrides, initServicesIfNeeded as ɵinitServicesIfNeeded, overrideComponentView as ɵoverrideComponentView, overrideProvider as ɵoverrideProvider} from './view/index';
|
||||||
export {NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR as ɵNOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR} from './view/provider';
|
export {NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR as ɵNOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR} from './view/provider';
|
||||||
export {LocaleDataIndex as ɵLocaleDataIndex, CurrencyIndex as ɵCurrencyIndex, ExtraLocaleDataIndex as ɵExtraLocaleDataIndex, getLocalePluralCase as ɵgetLocalePluralCase, findLocaleData as ɵfindLocaleData, registerLocaleData as ɵregisterLocaleData, unregisterAllLocaleData as ɵunregisterLocaleData} from './i18n/locale_data_api';
|
export {LocaleDataIndex as ɵLocaleDataIndex, CurrencyIndex as ɵCurrencyIndex, ExtraLocaleDataIndex as ɵExtraLocaleDataIndex, getLocalePluralCase as ɵgetLocalePluralCase, findLocaleData as ɵfindLocaleData, registerLocaleData as ɵregisterLocaleData, unregisterAllLocaleData as ɵunregisterLocaleData} from './i18n/locale_data_api';
|
||||||
|
|
|
@ -6,9 +6,8 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import {isObservable} from 'rxjs';
|
||||||
import {assertDataInRange} from '../../util/assert';
|
import {assertDataInRange} from '../../util/assert';
|
||||||
import {isObservable} from '../../util/lang';
|
|
||||||
import {EMPTY_OBJ} from '../empty';
|
import {EMPTY_OBJ} from '../empty';
|
||||||
import {PropertyAliasValue, TNode, TNodeFlags, TNodeType} from '../interfaces/node';
|
import {PropertyAliasValue, TNode, TNodeFlags, TNodeType} from '../interfaces/node';
|
||||||
import {GlobalTargetResolver, RElement, Renderer3, isProceduralRenderer} from '../interfaces/renderer';
|
import {GlobalTargetResolver, RElement, Renderer3, isProceduralRenderer} from '../interfaces/renderer';
|
||||||
|
|
|
@ -15,6 +15,5 @@ ts_library(
|
||||||
deps = [
|
deps = [
|
||||||
"//packages:types",
|
"//packages:types",
|
||||||
"//packages/core/src/interface",
|
"//packages/core/src/interface",
|
||||||
"@npm//rxjs",
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
|
@ -6,8 +6,6 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {Observable} from 'rxjs';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if the argument is shaped like a Promise
|
* Determine if the argument is shaped like a Promise
|
||||||
*/
|
*/
|
||||||
|
@ -16,12 +14,3 @@ export function isPromise(obj: any): obj is Promise<any> {
|
||||||
// It's up to the caller to ensure that obj.then conforms to the spec
|
// It's up to the caller to ensure that obj.then conforms to the spec
|
||||||
return !!obj && typeof obj.then === 'function';
|
return !!obj && typeof obj.then === 'function';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Determine if the argument is an Observable
|
|
||||||
*/
|
|
||||||
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';
|
|
||||||
}
|
|
||||||
|
|
|
@ -6,13 +6,13 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import {isObservable} from 'rxjs';
|
||||||
import {ChangeDetectorRef, SimpleChange, SimpleChanges, WrappedValue} from '../change_detection/change_detection';
|
import {ChangeDetectorRef, SimpleChange, SimpleChanges, WrappedValue} from '../change_detection/change_detection';
|
||||||
import {INJECTOR, Injector, resolveForwardRef} from '../di';
|
import {INJECTOR, Injector, resolveForwardRef} from '../di';
|
||||||
import {ElementRef} from '../linker/element_ref';
|
import {ElementRef} from '../linker/element_ref';
|
||||||
import {TemplateRef} from '../linker/template_ref';
|
import {TemplateRef} from '../linker/template_ref';
|
||||||
import {ViewContainerRef} from '../linker/view_container_ref';
|
import {ViewContainerRef} from '../linker/view_container_ref';
|
||||||
import {Renderer2} from '../render/api';
|
import {Renderer2} from '../render/api';
|
||||||
import {isObservable} from '../util/lang';
|
|
||||||
import {stringify} from '../util/stringify';
|
import {stringify} from '../util/stringify';
|
||||||
|
|
||||||
import {createChangeDetectorRef, createInjector} from './refs';
|
import {createChangeDetectorRef, createInjector} from './refs';
|
||||||
|
|
|
@ -5,8 +5,7 @@
|
||||||
* Use of this source code is governed by an MIT-style license that can be
|
* Use of this source code is governed by an MIT-style license that can be
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
import {isObservable, isPromise} from '@angular/core/src/util/lang';
|
import {isPromise} from '@angular/core/src/util/lang';
|
||||||
import {of } from 'rxjs';
|
|
||||||
|
|
||||||
{
|
{
|
||||||
describe('isPromise', () => {
|
describe('isPromise', () => {
|
||||||
|
@ -26,22 +25,4 @@ import {of } from 'rxjs';
|
||||||
expect(isPromise(null)).toEqual(false);
|
expect(isPromise(null)).toEqual(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
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));
|
|
||||||
|
|
||||||
it('should be false if the argument is null', () => expect(isObservable(null)).toEqual(false));
|
|
||||||
|
|
||||||
it('should be false if the argument is an object',
|
|
||||||
() => expect(isObservable({})).toEqual(false));
|
|
||||||
|
|
||||||
it('should be false if the argument is a function',
|
|
||||||
() => expect(isObservable(() => {})).toEqual(false));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ ts_library(
|
||||||
"//packages/core/testing",
|
"//packages/core/testing",
|
||||||
"//packages/platform-browser",
|
"//packages/platform-browser",
|
||||||
"//packages/private/testing",
|
"//packages/private/testing",
|
||||||
|
"@npm//rxjs",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import {Observable} from 'rxjs';
|
||||||
import {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, ChangeDetectorRef, DoCheck, ElementRef, ErrorHandler, EventEmitter, Injector, OnChanges, OnDestroy, OnInit, Renderer2, SimpleChange, TemplateRef, ViewContainerRef,} from '@angular/core';
|
import {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, ChangeDetectorRef, DoCheck, ElementRef, ErrorHandler, EventEmitter, Injector, OnChanges, OnDestroy, OnInit, Renderer2, SimpleChange, TemplateRef, ViewContainerRef,} from '@angular/core';
|
||||||
import {getDebugContext} from '@angular/core/src/errors';
|
import {getDebugContext} from '@angular/core/src/errors';
|
||||||
import {ArgumentType, DepFlags, NodeFlags, Services, anchorDef, asElementData, directiveDef, elementDef, providerDef, textDef} from '@angular/core/src/view/index';
|
import {ArgumentType, DepFlags, NodeFlags, Services, anchorDef, asElementData, directiveDef, elementDef, providerDef, textDef} from '@angular/core/src/view/index';
|
||||||
|
@ -341,13 +342,11 @@ import {ARG_TYPE_VALUES, checkNodeInlineOrDynamic, createRootView, createAndGetR
|
||||||
let unsubscribeSpy: any;
|
let unsubscribeSpy: any;
|
||||||
|
|
||||||
class SomeService {
|
class SomeService {
|
||||||
emitter = {
|
emitter = new Observable((callback: any) => {
|
||||||
subscribe: (callback: any) => {
|
|
||||||
const subscription = emitter.subscribe(callback);
|
const subscription = emitter.subscribe(callback);
|
||||||
unsubscribeSpy = spyOn(subscription, 'unsubscribe').and.callThrough();
|
unsubscribeSpy = spyOn(subscription, 'unsubscribe').and.callThrough();
|
||||||
return subscription;
|
return subscription;
|
||||||
}
|
});
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleEvent = jasmine.createSpy('handleEvent');
|
const handleEvent = jasmine.createSpy('handleEvent');
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {InjectionToken, ɵisObservable as isObservable, ɵisPromise as isPromise} from '@angular/core';
|
import {InjectionToken, ɵisPromise as isPromise} from '@angular/core';
|
||||||
import {Observable, forkJoin, from} from 'rxjs';
|
import {Observable, forkJoin, from, isObservable} from 'rxjs';
|
||||||
import {map} from 'rxjs/operators';
|
import {map} from 'rxjs/operators';
|
||||||
import {AsyncValidatorFn, ValidationErrors, Validator, ValidatorFn} from './directives/validators';
|
import {AsyncValidatorFn, ValidationErrors, Validator, ValidatorFn} from './directives/validators';
|
||||||
import {AbstractControl, FormControl} from './model';
|
import {AbstractControl, FormControl} from './model';
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {NgModuleFactory, ɵisObservable as isObservable, ɵisPromise as isPromise} from '@angular/core';
|
import {NgModuleFactory, ɵisPromise as isPromise} from '@angular/core';
|
||||||
import {Observable, from, of } from 'rxjs';
|
import {Observable, from, isObservable, of } from 'rxjs';
|
||||||
import {concatAll, last as lastValue, map} from 'rxjs/operators';
|
import {concatAll, last as lastValue, map} from 'rxjs/operators';
|
||||||
|
|
||||||
import {PRIMARY_OUTLET, Params} from '../shared';
|
import {PRIMARY_OUTLET, Params} from '../shared';
|
||||||
|
|
Loading…
Reference in New Issue