From 389ed2d941a0b9ef950b76576ae54bc18d0ed68a Mon Sep 17 00:00:00 2001 From: Rob Wormald Date: Wed, 28 Oct 2015 21:49:22 -0700 Subject: [PATCH] refactor(async): fix ObservableWrapper.isObservable Makes ObservableWrapper and AsyncPipe work with Observable, Subject, and EventEmitter --- modules/angular2/src/core/facade/async.ts | 7 +++--- .../angular2/test/core/facade/async_spec.ts | 22 ++++++++++++++++++- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/modules/angular2/src/core/facade/async.ts b/modules/angular2/src/core/facade/async.ts index 4c949484a2..a82776094e 100644 --- a/modules/angular2/src/core/facade/async.ts +++ b/modules/angular2/src/core/facade/async.ts @@ -25,13 +25,12 @@ export class TimerWrapper { export class ObservableWrapper { // TODO(vsavkin): when we use rxnext, try inferring the generic type from the first arg - static subscribe(emitter: any, onNext: (value: T) => void, - onError: (exception: any) => void = null, - onComplete: () => void = null): Object { + static subscribe(emitter: any, onNext: (value: T) => void, onError?: (exception: any) => void, + onComplete?: () => void): Object { return emitter.subscribe({next: onNext, error: onError, complete: onComplete}); } - static isObservable(obs: any): boolean { return obs instanceof EventEmitter; } + static isObservable(obs: any): boolean { return obs instanceof RxObservable; } /** * Returns whether `obs` has any subscribers listening to events. diff --git a/modules/angular2/test/core/facade/async_spec.ts b/modules/angular2/test/core/facade/async_spec.ts index b8e3e9c04e..926ec74b96 100644 --- a/modules/angular2/test/core/facade/async_spec.ts +++ b/modules/angular2/test/core/facade/async_spec.ts @@ -12,7 +12,13 @@ import { inject } from 'angular2/testing_internal'; -import {ObservableWrapper, EventEmitter, PromiseWrapper} from 'angular2/src/core/facade/async'; +import { + ObservableWrapper, + Observable, + Subject, + EventEmitter, + PromiseWrapper +} from 'angular2/src/core/facade/async'; export function main() { describe('EventEmitter', () => { @@ -92,6 +98,20 @@ export function main() { // should call dispose on the subscription on return }); + describe("ObservableWrapper", () => { + + it('should correctly check isObservable for EventEmitter', () => { + var e = new EventEmitter(false); + expect(ObservableWrapper.isObservable(e)).toBe(true); + }); + + it('should correctly check isObservable for Subject', () => { + var e = new Subject(); + expect(ObservableWrapper.isObservable(e)).toBe(true); + }); + + }); + // See ECMAScript 6 Spec 25.4.4.1 describe("PromiseWrapper", () => { describe("#all", () => {