refactor(pipes): removed BasePipeTrasnform

Closes #3608
This commit is contained in:
vsavkin 2015-08-12 12:04:54 -07:00 committed by Victor Savkin
parent 839edaa15b
commit 416fd085b1
13 changed files with 21 additions and 52 deletions

View File

@ -21,11 +21,11 @@ export {
WrappedValue,
PipeTransform,
PipeOnDestroy,
IterableDiffers,
IterableDiffer,
IterableDifferFactory,
KeyValueDiffers,
KeyValueDiffer,
KeyValueDifferFactory,
BasePipeTransform
KeyValueDifferFactory
} from 'angular2/src/change_detection/change_detection';

View File

@ -44,7 +44,7 @@ export {DynamicChangeDetector} from './dynamic_change_detector';
export {ChangeDetectorRef} from './change_detector_ref';
export {IterableDiffers, IterableDiffer, IterableDifferFactory} from './differs/iterable_differs';
export {KeyValueDiffers, KeyValueDiffer, KeyValueDifferFactory} from './differs/keyvalue_differs';
export {PipeTransform, PipeOnDestroy, BasePipeTransform} from './pipe_transform';
export {PipeTransform, PipeOnDestroy} from './pipe_transform';
export {WrappedValue} from './change_detection_util';
/**

View File

@ -37,26 +37,3 @@ export interface PipeTransform { transform(value: any, args: List<any>): any; }
* ```
*/
export interface PipeOnDestroy { onDestroy(): void; }
/**
* Provides default implementation of the `onDestroy` method.
*
* #Example
*
* ```
* class DoublePipe extends BasePipe {
* transform(value) {
* return `${value}${value}`;
* }
* }
* ```
*/
@CONST()
export class BasePipeTransform implements PipeTransform, PipeOnDestroy {
onDestroy(): void {}
transform(value: any, args: List<any>): any { return _abstract(); }
}
function _abstract() {
throw new BaseException('This method is abstract');
}

View File

@ -2,7 +2,7 @@ import {isBlank, isPresent, isPromise, CONST, BaseException} from 'angular2/src/
import {Observable, Promise, ObservableWrapper} from 'angular2/src/facade/async';
import {Injectable} from 'angular2/di';
import {PipeTransform, WrappedValue} from 'angular2/change_detection';
import {PipeTransform, PipeOnDestroy, WrappedValue} from 'angular2/change_detection';
import {InvalidPipeArgumentException} from './invalid_pipe_argument_exception';
import {ChangeDetectorRef} from 'angular2/change_detection';
@ -59,7 +59,7 @@ var _observableStrategy = new ObservableStrategy();
*/
@Pipe({name: 'async'})
@Injectable()
export class AsyncPipe implements PipeTransform {
export class AsyncPipe implements PipeTransform, PipeOnDestroy {
_latestValue: Object = null;
_latestReturnedValue: Object = null;

View File

@ -12,7 +12,7 @@ import {DateFormatter} from 'angular2/src/facade/intl';
import {Injectable} from 'angular2/di';
import {StringMapWrapper, ListWrapper} from 'angular2/src/facade/collection';
import {PipeTransform, WrappedValue, BasePipeTransform} from 'angular2/change_detection';
import {PipeTransform, WrappedValue} from 'angular2/change_detection';
import {InvalidPipeArgumentException} from './invalid_pipe_argument_exception';
import {Pipe} from 'angular2/src/core/annotations/decorators';
@ -77,7 +77,7 @@ var defaultLocale: string = 'en-US';
@CONST()
@Pipe({name: 'date'})
@Injectable()
export class DatePipe extends BasePipeTransform {
export class DatePipe implements PipeTransform {
static _ALIASES = {
'medium': 'yMMMdjms',
'short': 'yMdjm',

View File

@ -1,7 +1,7 @@
import {isBlank, isPresent, Json, CONST} from 'angular2/src/facade/lang';
import {Injectable} from 'angular2/di';
import {PipeTransform, WrappedValue, BasePipeTransform} from 'angular2/change_detection';
import {PipeTransform, WrappedValue} from 'angular2/change_detection';
import {Pipe} from 'angular2/src/core/annotations/decorators';
@ -31,6 +31,6 @@ import {Pipe} from 'angular2/src/core/annotations/decorators';
@CONST()
@Pipe({name: 'json'})
@Injectable()
export class JsonPipe extends BasePipeTransform {
export class JsonPipe implements PipeTransform {
transform(value: any, args: List<any> = null): string { return Json.stringify(value); }
}

View File

@ -10,7 +10,7 @@ import {ListWrapper} from 'angular2/src/facade/collection';
import {Math} from 'angular2/src/facade/math';
import {Injectable} from 'angular2/di';
import {PipeTransform, WrappedValue, BasePipeTransform} from 'angular2/change_detection';
import {PipeTransform, WrappedValue} from 'angular2/change_detection';
import {InvalidPipeArgumentException} from './invalid_pipe_argument_exception';
import {Pipe} from 'angular2/src/core/annotations/decorators';
@ -78,6 +78,4 @@ export class LimitToPipe implements PipeTransform {
}
return ListWrapper.slice(value, left, right);
}
onDestroy(): void {}
}

View File

@ -1,7 +1,7 @@
import {isString, StringWrapper, CONST, isBlank} from 'angular2/src/facade/lang';
import {Injectable} from 'angular2/di';
import {PipeTransform, WrappedValue, BasePipeTransform} from 'angular2/change_detection';
import {PipeTransform, WrappedValue} from 'angular2/change_detection';
import {InvalidPipeArgumentException} from './invalid_pipe_argument_exception';
@ -30,7 +30,7 @@ import {Pipe} from 'angular2/src/core/annotations/decorators';
@CONST()
@Pipe({name: 'lowercase'})
@Injectable()
export class LowerCasePipe extends BasePipeTransform {
export class LowerCasePipe implements PipeTransform {
transform(value: string, args: List<any> = null): string {
if (isBlank(value)) return value;
if (!isString(value)) {

View File

@ -13,7 +13,7 @@ import {NumberFormatter, NumberFormatStyle} from 'angular2/src/facade/intl';
import {Injectable} from 'angular2/di';
import {ListWrapper} from 'angular2/src/facade/collection';
import {PipeTransform, WrappedValue, BasePipeTransform} from 'angular2/change_detection';
import {PipeTransform, WrappedValue} from 'angular2/change_detection';
import {InvalidPipeArgumentException} from './invalid_pipe_argument_exception';
import {Pipe} from 'angular2/src/core/annotations/decorators';
@ -23,7 +23,7 @@ var _re = RegExpWrapper.create('^(\\d+)?\\.((\\d+)(\\-(\\d+))?)?$');
@CONST()
@Injectable()
export class NumberPipe extends BasePipeTransform {
export class NumberPipe {
static _format(value: number, style: NumberFormatStyle, digits: string, currency: string = null,
currencyAsSymbol: boolean = false): string {
if (isBlank(value)) return null;
@ -84,7 +84,7 @@ export class NumberPipe extends BasePipeTransform {
@CONST()
@Pipe({name: 'number'})
@Injectable()
export class DecimalPipe extends NumberPipe {
export class DecimalPipe extends NumberPipe implements PipeTransform {
transform(value: any, args: any[]): string {
var digits: string = ListWrapper.first(args);
return NumberPipe._format(value, NumberFormatStyle.DECIMAL, digits);
@ -103,7 +103,7 @@ export class DecimalPipe extends NumberPipe {
@CONST()
@Pipe({name: 'percent'})
@Injectable()
export class PercentPipe extends NumberPipe {
export class PercentPipe extends NumberPipe implements PipeTransform {
transform(value: any, args: any[]): string {
var digits: string = ListWrapper.first(args);
return NumberPipe._format(value, NumberFormatStyle.PERCENT, digits);
@ -126,7 +126,7 @@ export class PercentPipe extends NumberPipe {
@CONST()
@Pipe({name: 'currency'})
@Injectable()
export class CurrencyPipe extends NumberPipe {
export class CurrencyPipe extends NumberPipe implements PipeTransform {
transform(value: any, args: any[]): string {
var currencyCode: string = isPresent(args) && args.length > 0 ? args[0] : 'USD';
var symbolDisplay: boolean = isPresent(args) && args.length > 1 ? args[1] : false;

View File

@ -1,7 +1,7 @@
import {isString, StringWrapper, CONST, isBlank} from 'angular2/src/facade/lang';
import {Injectable} from 'angular2/di';
import {PipeTransform, WrappedValue, BasePipeTransform} from 'angular2/change_detection';
import {PipeTransform, WrappedValue} from 'angular2/change_detection';
import {InvalidPipeArgumentException} from './invalid_pipe_argument_exception';
import {Pipe} from 'angular2/src/core/annotations/decorators';
@ -29,7 +29,7 @@ import {Pipe} from 'angular2/src/core/annotations/decorators';
@CONST()
@Pipe({name: 'uppercase'})
@Injectable()
export class UpperCasePipe extends BasePipeTransform {
export class UpperCasePipe implements PipeTransform {
transform(value: string, args: List<any> = null): string {
if (isBlank(value)) return value;
if (!isString(value)) {

View File

@ -73,11 +73,5 @@ export function main() {
});
});
describe("onDestroy", () => {
it("should do nothing when no latest value",
() => { expect(() => pipe.onDestroy()).not.toThrow(); });
});
});
}