From adc135e6c87238f8b71875e772388705fd100072 Mon Sep 17 00:00:00 2001 From: Tom Schoener Date: Sat, 12 Mar 2016 14:22:31 +0100 Subject: [PATCH] refactor(async_pipe): use subscription strategy interface The strategies for Promise and Observable based subscriptions have (nearly) the same method signatures. They should implement a common interface. Closes #7573 --- modules/@angular/common/src/pipes/async_pipe.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/@angular/common/src/pipes/async_pipe.ts b/modules/@angular/common/src/pipes/async_pipe.ts index 6d5febac53..68b87b633f 100644 --- a/modules/@angular/common/src/pipes/async_pipe.ts +++ b/modules/@angular/common/src/pipes/async_pipe.ts @@ -5,7 +5,13 @@ import {ObservableWrapper, Observable, EventEmitter} from '../../src/facade/asyn import {InvalidPipeArgumentException} from './invalid_pipe_argument_exception'; -class ObservableStrategy { +interface SubscriptionStrategy { + createSubscription(async: any, updateLatestValue: any, onError?: (v: any) => 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); @@ -16,7 +22,7 @@ class ObservableStrategy { onDestroy(subscription: any): void { ObservableWrapper.dispose(subscription); } } -class PromiseStrategy { +class PromiseStrategy implements SubscriptionStrategy { createSubscription(async: Promise, updateLatestValue: (v: any) => any, onError: (v: any) => any = e => { throw e; }): any { return async.then(updateLatestValue, onError); @@ -61,7 +67,7 @@ export class AsyncPipe implements OnDestroy { _subscription: Object = null; /** @internal */ _obj: Observable| Promise| EventEmitter = null; - private _strategy: any = null; + private _strategy: SubscriptionStrategy = null; /** @internal */ public _ref: ChangeDetectorRef; constructor(_ref: ChangeDetectorRef) { this._ref = _ref; }