parent
839edaa15b
commit
416fd085b1
|
@ -21,11 +21,11 @@ export {
|
|||
|
||||
WrappedValue,
|
||||
PipeTransform,
|
||||
PipeOnDestroy,
|
||||
IterableDiffers,
|
||||
IterableDiffer,
|
||||
IterableDifferFactory,
|
||||
KeyValueDiffers,
|
||||
KeyValueDiffer,
|
||||
KeyValueDifferFactory,
|
||||
BasePipeTransform
|
||||
KeyValueDifferFactory
|
||||
} from 'angular2/src/change_detection/change_detection';
|
||||
|
|
|
@ -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';
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,4 +2,4 @@ library angular2.core.compiler.pipe_lifecycle_reflector;
|
|||
|
||||
import 'package:angular2/src/change_detection/pipe_transform.dart';
|
||||
|
||||
bool implementsOnDestroy(Object pipe) => pipe is PipeOnDestroy;
|
||||
bool implementsOnDestroy(Object pipe) => pipe is PipeOnDestroy;
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
export function implementsOnDestroy(pipe: any): boolean {
|
||||
return pipe.constructor.prototype.onDestroy;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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); }
|
||||
}
|
||||
|
|
|
@ -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 {}
|
||||
}
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -73,11 +73,5 @@ export function main() {
|
|||
});
|
||||
|
||||
});
|
||||
|
||||
describe("onDestroy", () => {
|
||||
it("should do nothing when no latest value",
|
||||
() => { expect(() => pipe.onDestroy()).not.toThrow(); });
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue