Revert "feat(AsyncPipe): allow onError argument"
This reverts commit 390046d7b3
.
CI fails for IE on win8.
PR #7990
This commit is contained in:
parent
a20639558b
commit
352ee53202
|
@ -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<any>, updateLatestValue: (v: any) => any,
|
||||
onError: (v: any) => any = e => { throw e; }): any {
|
||||
return async.then(updateLatestValue, onError);
|
||||
createSubscription(async: Promise<any>, 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<any>| Promise<any>| EventEmitter<any>, onError?: (v: any) => any): any {
|
||||
transform(obj: Observable<any>| Promise<any>| EventEmitter<any>): 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<any>| Promise<any>| EventEmitter<any>, onError?: any): void {
|
||||
_subscribe(obj: Observable<any>| Promise<any>| EventEmitter<any>): 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 */
|
||||
|
|
|
@ -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,7 +190,7 @@ 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(() => {
|
||||
|
|
|
@ -621,7 +621,7 @@ const COMMON = [
|
|||
'AsyncPipe',
|
||||
'AsyncPipe.constructor(_ref:ChangeDetectorRef)',
|
||||
'AsyncPipe.ngOnDestroy():void',
|
||||
'AsyncPipe.transform(obj:Observable<any>|Promise<any>|EventEmitter<any>, onError:(v: any) => any):any',
|
||||
'AsyncPipe.transform(obj:Observable<any>|Promise<any>|EventEmitter<any>):any',
|
||||
'CheckboxControlValueAccessor',
|
||||
'CheckboxControlValueAccessor.constructor(_renderer:Renderer, _elementRef:ElementRef)',
|
||||
'CheckboxControlValueAccessor.onChange:any',
|
||||
|
|
Loading…
Reference in New Issue