refactor(async): fix ObservableWrapper.isObservable

Makes ObservableWrapper and AsyncPipe work with Observable, Subject, and EventEmitter
This commit is contained in:
Rob Wormald 2015-10-28 21:49:22 -07:00
parent 0378e55fab
commit 389ed2d941
2 changed files with 24 additions and 5 deletions

View File

@ -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<T>(emitter: any, onNext: (value: T) => void,
onError: (exception: any) => void = null,
onComplete: () => void = null): Object {
static subscribe<T>(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.

View File

@ -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", () => {