diff --git a/modules/@angular/common/src/pipes/async_pipe.ts b/modules/@angular/common/src/pipes/async_pipe.ts index 68b87b633f..9b6bf6561b 100644 --- a/modules/@angular/common/src/pipes/async_pipe.ts +++ b/modules/@angular/common/src/pipes/async_pipe.ts @@ -6,15 +6,14 @@ import {ObservableWrapper, Observable, EventEmitter} from '../../src/facade/asyn import {InvalidPipeArgumentException} from './invalid_pipe_argument_exception'; interface SubscriptionStrategy { - createSubscription(async: any, updateLatestValue: any, onError?: (v: any) => any): any; + createSubscription(async: any, updateLatestValue: any): any; dispose(subscription: any): void; onDestroy(subscription: any): void; } class ObservableStrategy implements SubscriptionStrategy { - createSubscription(async: any, updateLatestValue: any, - onError: (v: any) => any = e => { throw e; }): any { - return ObservableWrapper.subscribe(async, updateLatestValue, onError); + createSubscription(async: any, updateLatestValue: any): any { + return ObservableWrapper.subscribe(async, updateLatestValue, e => { throw e; } ); } dispose(subscription: any): void { ObservableWrapper.dispose(subscription); } @@ -23,9 +22,8 @@ class ObservableStrategy implements SubscriptionStrategy { } class PromiseStrategy implements SubscriptionStrategy { - createSubscription(async: Promise, updateLatestValue: (v: any) => any, - onError: (v: any) => any = e => { throw e; }): any { - return async.then(updateLatestValue, onError); + createSubscription(async: Promise, updateLatestValue: (v: any) => any): any { + return async.then(updateLatestValue, e => { throw e; }); } dispose(subscription: any): void {} @@ -78,10 +76,10 @@ export class AsyncPipe implements OnDestroy { } } - transform(obj: Observable| Promise| EventEmitter, onError?: (v: any) => any): any { + transform(obj: Observable| Promise| EventEmitter): any { if (isBlank(this._obj)) { if (isPresent(obj)) { - this._subscribe(obj, onError); + this._subscribe(obj); } this._latestReturnedValue = this._latestValue; return this._latestValue; @@ -89,7 +87,7 @@ export class AsyncPipe implements OnDestroy { if (obj !== this._obj) { this._dispose(); - return this.transform(obj, onError); + return this.transform(obj); } if (this._latestValue === this._latestReturnedValue) { @@ -101,11 +99,11 @@ export class AsyncPipe implements OnDestroy { } /** @internal */ - _subscribe(obj: Observable| Promise| EventEmitter, onError?: any): void { + _subscribe(obj: Observable| Promise| EventEmitter): void { this._obj = obj; this._strategy = this._selectStrategy(obj); this._subscription = this._strategy.createSubscription( - obj, (value: Object) => this._updateLatestValue(obj, value), onError); + obj, (value: Object) => this._updateLatestValue(obj, value)); } /** @internal */ diff --git a/modules/@angular/common/test/pipes/async_pipe_spec.ts b/modules/@angular/common/test/pipes/async_pipe_spec.ts index 6196b08de1..726895ee99 100644 --- a/modules/@angular/common/test/pipes/async_pipe_spec.ts +++ b/modules/@angular/common/test/pipes/async_pipe_spec.ts @@ -52,9 +52,10 @@ export function main() { TimerWrapper.setTimeout(() => { expect(pipe.transform(emitter)).toEqual(new WrappedValue(message)); async.done(); - }, 0); + }, 0) })); + it("should return same value when nothing has changed since the last call", inject([AsyncTestCompleter], (async) => { pipe.transform(emitter); @@ -64,23 +65,7 @@ export function main() { pipe.transform(emitter); expect(pipe.transform(emitter)).toBe(message); async.done(); - }, 0); - })); - - it("should invoke onError of when a function is provided", - inject([AsyncTestCompleter], (async) => { - var error = false; - function onError() { error = true; } - expect(() => pipe.transform(emitter, onError)).not.toThrow(); - - expect(error).toBe(false); - // this should not affect the pipe - ObservableWrapper.callError(emitter, message); - - TimerWrapper.setTimeout(() => { - expect(error).toBe(true); - async.done(); - }, 0); + }, 0) })); it("should dispose of the existing subscription when subscribing to a new observable", @@ -96,7 +81,7 @@ export function main() { TimerWrapper.setTimeout(() => { expect(pipe.transform(newEmitter)).toBe(null); async.done(); - }, 0); + }, 0) })); it("should request a change detection check upon receiving a new value", @@ -107,7 +92,7 @@ export function main() { TimerWrapper.setTimeout(() => { expect(ref.spy('markForCheck')).toHaveBeenCalled(); async.done(); - }, 10); + }, 10) })); }); @@ -124,7 +109,7 @@ export function main() { TimerWrapper.setTimeout(() => { expect(pipe.transform(emitter)).toBe(null); async.done(); - }, 0); + }, 0) })); }); }); @@ -155,23 +140,7 @@ export function main() { TimerWrapper.setTimeout(() => { expect(pipe.transform(completer.promise)).toEqual(new WrappedValue(message)); async.done(); - }, timer); - })); - - it("should invoke onError of when a function is provided", - inject([AsyncTestCompleter], (async) => { - var error = false; - function onError() { error = true; } - expect(() => pipe.transform(completer.promise, onError)).not.toThrow(); - - expect(error).toBe(false); - // this should not affect the pipe - completer.reject('rejection'); - - TimerWrapper.setTimeout(() => { - expect(error).toBe(true); - async.done(); - }, 0); + }, timer) })); it("should return unwrapped value when nothing has changed since the last call", @@ -183,7 +152,7 @@ export function main() { pipe.transform(completer.promise); expect(pipe.transform(completer.promise)).toBe(message); async.done(); - }, timer); + }, timer) })); it("should dispose of the existing subscription when subscribing to a new promise", @@ -199,7 +168,7 @@ export function main() { TimerWrapper.setTimeout(() => { expect(pipe.transform(newCompleter.promise)).toBe(null); async.done(); - }, timer); + }, timer) })); it("should request a change detection check upon receiving a new value", @@ -211,7 +180,7 @@ export function main() { TimerWrapper.setTimeout(() => { expect(markForCheck).toHaveBeenCalled(); async.done(); - }, timer); + }, timer) })); describe("ngOnDestroy", () => { @@ -221,15 +190,15 @@ export function main() { it("should dispose of the existing source", inject([AsyncTestCompleter], (async) => { pipe.transform(completer.promise); expect(pipe.transform(completer.promise)).toBe(null); - completer.resolve(message); + completer.resolve(message) - TimerWrapper.setTimeout(() => { - expect(pipe.transform(completer.promise)).toEqual(new WrappedValue(message)); - pipe.ngOnDestroy(); - expect(pipe.transform(completer.promise)).toBe(null); - async.done(); - }, timer); + TimerWrapper.setTimeout(() => { + expect(pipe.transform(completer.promise)).toEqual(new WrappedValue(message)); + pipe.ngOnDestroy(); + expect(pipe.transform(completer.promise)).toBe(null); + async.done(); + }, timer); })); }); }); diff --git a/tools/public_api_guard/public_api_spec.ts b/tools/public_api_guard/public_api_spec.ts index 264caa6b1c..8bbbd31b47 100644 --- a/tools/public_api_guard/public_api_spec.ts +++ b/tools/public_api_guard/public_api_spec.ts @@ -621,7 +621,7 @@ const COMMON = [ 'AsyncPipe', 'AsyncPipe.constructor(_ref:ChangeDetectorRef)', 'AsyncPipe.ngOnDestroy():void', - 'AsyncPipe.transform(obj:Observable|Promise|EventEmitter, onError:(v: any) => any):any', + 'AsyncPipe.transform(obj:Observable|Promise|EventEmitter):any', 'CheckboxControlValueAccessor', 'CheckboxControlValueAccessor.constructor(_renderer:Renderer, _elementRef:ElementRef)', 'CheckboxControlValueAccessor.onChange:any',