Skip to content

Commit 85b551a

Browse files
committed
Revert "refactor: use isObservable provided by rxjs 6.1+ (angular#27668)"
This reverts commit 92c5478.
1 parent c5006e0 commit 85b551a

File tree

13 files changed

+50
-22
lines changed

13 files changed

+50
-22
lines changed
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
11
import "@angular/core";
2-
3-
import "rxjs";
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
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, ɵisPromise, ɵlooseIdentical} from '@angular/core';
10-
import {Observable, SubscriptionLike, isObservable} from 'rxjs';
9+
import {ChangeDetectorRef, EventEmitter, OnDestroy, Pipe, PipeTransform, WrappedValue, ɵisObservable, ɵisPromise, ɵlooseIdentical} from '@angular/core';
10+
import {Observable, SubscriptionLike} 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 {isPromise as ɵisPromise} from './util/lang';
33+
export {isObservable as ɵisObservable, 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 {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';

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

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

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

packages/core/src/util/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ ts_library(
1515
deps = [
1616
"//packages:types",
1717
"//packages/core/src/interface",
18+
"@npm//rxjs",
1819
],
1920
)

packages/core/src/util/lang.ts

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

9+
import {Observable} from 'rxjs';
10+
911
/**
1012
* Determine if the argument is shaped like a Promise
1113
*/
@@ -14,3 +16,12 @@ export function isPromise(obj: any): obj is Promise<any> {
1416
// It's up to the caller to ensure that obj.then conforms to the spec
1517
return !!obj && typeof obj.then === 'function';
1618
}
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {isObservable} from 'rxjs';
109
import {ChangeDetectorRef, SimpleChange, SimpleChanges, WrappedValue} from '../change_detection/change_detection';
1110
import {INJECTOR, Injector, resolveForwardRef} from '../di';
1211
import {ElementRef} from '../linker/element_ref';
1312
import {TemplateRef} from '../linker/template_ref';
1413
import {ViewContainerRef} from '../linker/view_container_ref';
1514
import {Renderer2} from '../render/api';
15+
import {isObservable} from '../util/lang';
1616
import {stringify} from '../util/stringify';
1717

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

packages/core/test/util/lang_spec.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
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 {isPromise} from '@angular/core/src/util/lang';
8+
import {isObservable, isPromise} from '@angular/core/src/util/lang';
9+
import {of } from 'rxjs';
910

1011
{
1112
describe('isPromise', () => {
@@ -25,4 +26,22 @@ import {isPromise} from '@angular/core/src/util/lang';
2526
expect(isPromise(null)).toEqual(false);
2627
});
2728
});
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+
});
2847
}

packages/core/test/view/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ ts_library(
1717
"//packages/core/testing",
1818
"//packages/platform-browser",
1919
"//packages/private/testing",
20-
"@npm//rxjs",
2120
],
2221
)
2322

0 commit comments

Comments
 (0)