Skip to content

Commit a6ea5f6

Browse files
author
vthinkxie
committed
refactor(core): replace with rxjs isObservable
1 parent 29bc3a7 commit a6ea5f6

File tree

13 files changed

+23
-52
lines changed

13 files changed

+23
-52
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
import "@angular/core";
2+
3+
import "rxjs";
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
import "tslib";
22

33
import "@angular/core";
4+
5+
import "rxjs";

packages/common/src/pipes/async_pipe.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {ChangeDetectorRef, EventEmitter, OnDestroy, Pipe, PipeTransform, WrappedValue, ɵisObservable, ɵisPromise, ɵlooseIdentical} from '@angular/core';
10-
import {Observable, SubscriptionLike} from 'rxjs';
9+
import {ChangeDetectorRef, EventEmitter, OnDestroy, Pipe, PipeTransform, WrappedValue, ɵisPromise, ɵlooseIdentical} from '@angular/core';
10+
import {Observable, SubscriptionLike, isObservable} from 'rxjs';
1111
import {invalidPipeArgumentError} from './invalid_pipe_argument_error';
1212

1313
interface SubscriptionStrategy {
@@ -122,7 +122,7 @@ export class AsyncPipe implements OnDestroy, PipeTransform {
122122
return _promiseStrategy;
123123
}
124124

125-
if (ɵisObservable(obj)) {
125+
if (isObservable(obj)) {
126126
return _observableStrategy;
127127
}
128128

packages/core/src/core_private_export.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export {global as ɵglobal} from './util/global';
3030
export {looseIdentical as ɵlooseIdentical,} from './util/comparison';
3131
export {stringify as ɵstringify} from './util/stringify';
3232
export {makeDecorator as ɵmakeDecorator} from './util/decorators';
33-
export {isObservable as ɵisObservable, isPromise as ɵisPromise} from './util/lang';
33+
export {isPromise as ɵisPromise} from './util/lang';
3434
export {clearOverrides as ɵclearOverrides, initServicesIfNeeded as ɵinitServicesIfNeeded, overrideComponentView as ɵoverrideComponentView, overrideProvider as ɵoverrideProvider} from './view/index';
3535
export {NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR as ɵNOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR} from './view/provider';
3636
export {getLocalePluralCase as ɵgetLocalePluralCase, findLocaleData as ɵfindLocaleData} from './i18n/locale_data_api';

packages/core/src/render3/instructions/listener.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
9+
import {isObservable} from 'rxjs';
1010
import {assertDataInRange} from '../../util/assert';
11-
import {isObservable} from '../../util/lang';
1211
import {EMPTY_OBJ} from '../empty';
1312
import {PropertyAliasValue, TNode, TNodeFlags, TNodeType} from '../interfaces/node';
1413
import {GlobalTargetResolver, RElement, Renderer3, isProceduralRenderer} from '../interfaces/renderer';

packages/core/src/util/lang.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {Observable} from 'rxjs';
10-
119
/**
1210
* Determine if the argument is shaped like a Promise
1311
*/
@@ -16,12 +14,3 @@ export function isPromise(obj: any): obj is Promise<any> {
1614
// It's up to the caller to ensure that obj.then conforms to the spec
1715
return !!obj && typeof obj.then === 'function';
1816
}
19-
20-
/**
21-
* Determine if the argument is an Observable
22-
*/
23-
export function isObservable(obj: any | Observable<any>): obj is Observable<any> {
24-
// TODO: use isObservable once we update pass rxjs 6.1
25-
// https://github.com/ReactiveX/rxjs/blob/master/CHANGELOG.md#610-2018-05-03
26-
return !!obj && typeof obj.subscribe === 'function';
27-
}

packages/core/src/view/provider.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
8+
import {isObservable} from 'rxjs';
99
import {ChangeDetectorRef, SimpleChange, SimpleChanges, WrappedValue} from '../change_detection/change_detection';
1010
import {INJECTOR, Injector, resolveForwardRef} from '../di';
1111
import {ElementRef} from '../linker/element_ref';
1212
import {TemplateRef} from '../linker/template_ref';
1313
import {ViewContainerRef} from '../linker/view_container_ref';
1414
import {Renderer2} from '../render/api';
15-
import {isObservable} from '../util/lang';
1615
import {stringify} from '../util/stringify';
1716

1817
import {createChangeDetectorRef, createInjector} from './refs';

packages/core/test/util/lang_spec.ts

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import {isObservable, isPromise} from '@angular/core/src/util/lang';
9-
import {of } from 'rxjs';
8+
import {isPromise} from '@angular/core/src/util/lang';
109

1110
{
1211
describe('isPromise', () => {
@@ -26,22 +25,4 @@ import {of } from 'rxjs';
2625
expect(isPromise(null)).toEqual(false);
2726
});
2827
});
29-
30-
describe('isObservable', () => {
31-
it('should be true for an Observable', () => expect(isObservable(of (true))).toEqual(true));
32-
33-
it('should be true if the argument is the object with subscribe function',
34-
() => expect(isObservable({subscribe: () => {}})).toEqual(true));
35-
36-
it('should be false if the argument is undefined',
37-
() => expect(isObservable(undefined)).toEqual(false));
38-
39-
it('should be false if the argument is null', () => expect(isObservable(null)).toEqual(false));
40-
41-
it('should be false if the argument is an object',
42-
() => expect(isObservable({})).toEqual(false));
43-
44-
it('should be false if the argument is a function',
45-
() => expect(isObservable(() => {})).toEqual(false));
46-
});
4728
}

packages/core/test/view/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ ts_library(
1717
"//packages/core/testing",
1818
"//packages/platform-browser",
1919
"//packages/private/testing",
20+
"@npm//rxjs",
2021
],
2122
)
2223

packages/core/test/view/provider_spec.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {ArgumentType, DepFlags, NodeFlags, Services, anchorDef, asElementData, d
1212
import {TestBed, withModule} from '@angular/core/testing';
1313
import {ɵgetDOM as getDOM} from '@angular/common';
1414
import {ivyEnabled} from '@angular/private/testing';
15+
import {Observable} from 'rxjs';
1516

1617
import {ARG_TYPE_VALUES, checkNodeInlineOrDynamic, createRootView, createAndGetRootNodes, compViewDef, compViewDefFactory} from './helper';
1718

@@ -339,15 +340,12 @@ import {ARG_TYPE_VALUES, checkNodeInlineOrDynamic, createRootView, createAndGetR
339340
it('should listen to provider events', () => {
340341
let emitter = new EventEmitter<any>();
341342
let unsubscribeSpy: any;
342-
343343
class SomeService {
344-
emitter = {
345-
subscribe: (callback: any) => {
346-
const subscription = emitter.subscribe(callback);
347-
unsubscribeSpy = spyOn(subscription, 'unsubscribe').and.callThrough();
348-
return subscription;
349-
}
350-
};
344+
emitter = new Observable((callback: any) => {
345+
const subscription = emitter.subscribe(callback);
346+
unsubscribeSpy = spyOn(subscription, 'unsubscribe').and.callThrough();
347+
return subscription;
348+
});
351349
}
352350

353351
const handleEvent = jasmine.createSpy('handleEvent');

0 commit comments

Comments
 (0)