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';
|
import {InvalidPipeArgumentException} from './invalid_pipe_argument_exception';
|
||||||
|
|
||||||
interface SubscriptionStrategy {
|
interface SubscriptionStrategy {
|
||||||
createSubscription(async: any, updateLatestValue: any, onError?: (v: any) => any): any;
|
createSubscription(async: any, updateLatestValue: any): any;
|
||||||
dispose(subscription: any): void;
|
dispose(subscription: any): void;
|
||||||
onDestroy(subscription: any): void;
|
onDestroy(subscription: any): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ObservableStrategy implements SubscriptionStrategy {
|
class ObservableStrategy implements SubscriptionStrategy {
|
||||||
createSubscription(async: any, updateLatestValue: any,
|
createSubscription(async: any, updateLatestValue: any): any {
|
||||||
onError: (v: any) => any = e => { throw e; }): any {
|
return ObservableWrapper.subscribe(async, updateLatestValue, e => { throw e; } );
|
||||||
return ObservableWrapper.subscribe(async, updateLatestValue, onError);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dispose(subscription: any): void { ObservableWrapper.dispose(subscription); }
|
dispose(subscription: any): void { ObservableWrapper.dispose(subscription); }
|
||||||
|
@ -23,9 +22,8 @@ class ObservableStrategy implements SubscriptionStrategy {
|
||||||
}
|
}
|
||||||
|
|
||||||
class PromiseStrategy implements SubscriptionStrategy {
|
class PromiseStrategy implements SubscriptionStrategy {
|
||||||
createSubscription(async: Promise<any>, updateLatestValue: (v: any) => any,
|
createSubscription(async: Promise<any>, updateLatestValue: (v: any) => any): any {
|
||||||
onError: (v: any) => any = e => { throw e; }): any {
|
return async.then(updateLatestValue, e => { throw e; });
|
||||||
return async.then(updateLatestValue, onError);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dispose(subscription: any): void {}
|
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 (isBlank(this._obj)) {
|
||||||
if (isPresent(obj)) {
|
if (isPresent(obj)) {
|
||||||
this._subscribe(obj, onError);
|
this._subscribe(obj);
|
||||||
}
|
}
|
||||||
this._latestReturnedValue = this._latestValue;
|
this._latestReturnedValue = this._latestValue;
|
||||||
return this._latestValue;
|
return this._latestValue;
|
||||||
|
@ -89,7 +87,7 @@ export class AsyncPipe implements OnDestroy {
|
||||||
|
|
||||||
if (obj !== this._obj) {
|
if (obj !== this._obj) {
|
||||||
this._dispose();
|
this._dispose();
|
||||||
return this.transform(obj, onError);
|
return this.transform(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._latestValue === this._latestReturnedValue) {
|
if (this._latestValue === this._latestReturnedValue) {
|
||||||
|
@ -101,11 +99,11 @@ export class AsyncPipe implements OnDestroy {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @internal */
|
/** @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._obj = obj;
|
||||||
this._strategy = this._selectStrategy(obj);
|
this._strategy = this._selectStrategy(obj);
|
||||||
this._subscription = this._strategy.createSubscription(
|
this._subscription = this._strategy.createSubscription(
|
||||||
obj, (value: Object) => this._updateLatestValue(obj, value), onError);
|
obj, (value: Object) => this._updateLatestValue(obj, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
|
|
|
@ -52,9 +52,10 @@ export function main() {
|
||||||
TimerWrapper.setTimeout(() => {
|
TimerWrapper.setTimeout(() => {
|
||||||
expect(pipe.transform(emitter)).toEqual(new WrappedValue(message));
|
expect(pipe.transform(emitter)).toEqual(new WrappedValue(message));
|
||||||
async.done();
|
async.done();
|
||||||
}, 0);
|
}, 0)
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
it("should return same value when nothing has changed since the last call",
|
it("should return same value when nothing has changed since the last call",
|
||||||
inject([AsyncTestCompleter], (async) => {
|
inject([AsyncTestCompleter], (async) => {
|
||||||
pipe.transform(emitter);
|
pipe.transform(emitter);
|
||||||
|
@ -64,23 +65,7 @@ export function main() {
|
||||||
pipe.transform(emitter);
|
pipe.transform(emitter);
|
||||||
expect(pipe.transform(emitter)).toBe(message);
|
expect(pipe.transform(emitter)).toBe(message);
|
||||||
async.done();
|
async.done();
|
||||||
}, 0);
|
}, 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);
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it("should dispose of the existing subscription when subscribing to a new observable",
|
it("should dispose of the existing subscription when subscribing to a new observable",
|
||||||
|
@ -96,7 +81,7 @@ export function main() {
|
||||||
TimerWrapper.setTimeout(() => {
|
TimerWrapper.setTimeout(() => {
|
||||||
expect(pipe.transform(newEmitter)).toBe(null);
|
expect(pipe.transform(newEmitter)).toBe(null);
|
||||||
async.done();
|
async.done();
|
||||||
}, 0);
|
}, 0)
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it("should request a change detection check upon receiving a new value",
|
it("should request a change detection check upon receiving a new value",
|
||||||
|
@ -107,7 +92,7 @@ export function main() {
|
||||||
TimerWrapper.setTimeout(() => {
|
TimerWrapper.setTimeout(() => {
|
||||||
expect(ref.spy('markForCheck')).toHaveBeenCalled();
|
expect(ref.spy('markForCheck')).toHaveBeenCalled();
|
||||||
async.done();
|
async.done();
|
||||||
}, 10);
|
}, 10)
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -124,7 +109,7 @@ export function main() {
|
||||||
TimerWrapper.setTimeout(() => {
|
TimerWrapper.setTimeout(() => {
|
||||||
expect(pipe.transform(emitter)).toBe(null);
|
expect(pipe.transform(emitter)).toBe(null);
|
||||||
async.done();
|
async.done();
|
||||||
}, 0);
|
}, 0)
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -155,23 +140,7 @@ export function main() {
|
||||||
TimerWrapper.setTimeout(() => {
|
TimerWrapper.setTimeout(() => {
|
||||||
expect(pipe.transform(completer.promise)).toEqual(new WrappedValue(message));
|
expect(pipe.transform(completer.promise)).toEqual(new WrappedValue(message));
|
||||||
async.done();
|
async.done();
|
||||||
}, timer);
|
}, 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);
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it("should return unwrapped value when nothing has changed since the last call",
|
it("should return unwrapped value when nothing has changed since the last call",
|
||||||
|
@ -183,7 +152,7 @@ export function main() {
|
||||||
pipe.transform(completer.promise);
|
pipe.transform(completer.promise);
|
||||||
expect(pipe.transform(completer.promise)).toBe(message);
|
expect(pipe.transform(completer.promise)).toBe(message);
|
||||||
async.done();
|
async.done();
|
||||||
}, timer);
|
}, timer)
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it("should dispose of the existing subscription when subscribing to a new promise",
|
it("should dispose of the existing subscription when subscribing to a new promise",
|
||||||
|
@ -199,7 +168,7 @@ export function main() {
|
||||||
TimerWrapper.setTimeout(() => {
|
TimerWrapper.setTimeout(() => {
|
||||||
expect(pipe.transform(newCompleter.promise)).toBe(null);
|
expect(pipe.transform(newCompleter.promise)).toBe(null);
|
||||||
async.done();
|
async.done();
|
||||||
}, timer);
|
}, timer)
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it("should request a change detection check upon receiving a new value",
|
it("should request a change detection check upon receiving a new value",
|
||||||
|
@ -211,7 +180,7 @@ export function main() {
|
||||||
TimerWrapper.setTimeout(() => {
|
TimerWrapper.setTimeout(() => {
|
||||||
expect(markForCheck).toHaveBeenCalled();
|
expect(markForCheck).toHaveBeenCalled();
|
||||||
async.done();
|
async.done();
|
||||||
}, timer);
|
}, timer)
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe("ngOnDestroy", () => {
|
describe("ngOnDestroy", () => {
|
||||||
|
@ -221,15 +190,15 @@ export function main() {
|
||||||
it("should dispose of the existing source", inject([AsyncTestCompleter], (async) => {
|
it("should dispose of the existing source", inject([AsyncTestCompleter], (async) => {
|
||||||
pipe.transform(completer.promise);
|
pipe.transform(completer.promise);
|
||||||
expect(pipe.transform(completer.promise)).toBe(null);
|
expect(pipe.transform(completer.promise)).toBe(null);
|
||||||
completer.resolve(message);
|
completer.resolve(message)
|
||||||
|
|
||||||
|
|
||||||
TimerWrapper.setTimeout(() => {
|
TimerWrapper.setTimeout(() => {
|
||||||
expect(pipe.transform(completer.promise)).toEqual(new WrappedValue(message));
|
expect(pipe.transform(completer.promise)).toEqual(new WrappedValue(message));
|
||||||
pipe.ngOnDestroy();
|
pipe.ngOnDestroy();
|
||||||
expect(pipe.transform(completer.promise)).toBe(null);
|
expect(pipe.transform(completer.promise)).toBe(null);
|
||||||
async.done();
|
async.done();
|
||||||
}, timer);
|
}, timer);
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -621,7 +621,7 @@ const COMMON = [
|
||||||
'AsyncPipe',
|
'AsyncPipe',
|
||||||
'AsyncPipe.constructor(_ref:ChangeDetectorRef)',
|
'AsyncPipe.constructor(_ref:ChangeDetectorRef)',
|
||||||
'AsyncPipe.ngOnDestroy():void',
|
'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',
|
||||||
'CheckboxControlValueAccessor.constructor(_renderer:Renderer, _elementRef:ElementRef)',
|
'CheckboxControlValueAccessor.constructor(_renderer:Renderer, _elementRef:ElementRef)',
|
||||||
'CheckboxControlValueAccessor.onChange:any',
|
'CheckboxControlValueAccessor.onChange:any',
|
||||||
|
|
Loading…
Reference in New Issue