parent
839edaa15b
commit
416fd085b1
|
@ -21,11 +21,11 @@ export {
|
||||||
|
|
||||||
WrappedValue,
|
WrappedValue,
|
||||||
PipeTransform,
|
PipeTransform,
|
||||||
|
PipeOnDestroy,
|
||||||
IterableDiffers,
|
IterableDiffers,
|
||||||
IterableDiffer,
|
IterableDiffer,
|
||||||
IterableDifferFactory,
|
IterableDifferFactory,
|
||||||
KeyValueDiffers,
|
KeyValueDiffers,
|
||||||
KeyValueDiffer,
|
KeyValueDiffer,
|
||||||
KeyValueDifferFactory,
|
KeyValueDifferFactory
|
||||||
BasePipeTransform
|
|
||||||
} from 'angular2/src/change_detection/change_detection';
|
} from 'angular2/src/change_detection/change_detection';
|
||||||
|
|
|
@ -44,7 +44,7 @@ export {DynamicChangeDetector} from './dynamic_change_detector';
|
||||||
export {ChangeDetectorRef} from './change_detector_ref';
|
export {ChangeDetectorRef} from './change_detector_ref';
|
||||||
export {IterableDiffers, IterableDiffer, IterableDifferFactory} from './differs/iterable_differs';
|
export {IterableDiffers, IterableDiffer, IterableDifferFactory} from './differs/iterable_differs';
|
||||||
export {KeyValueDiffers, KeyValueDiffer, KeyValueDifferFactory} from './differs/keyvalue_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';
|
export {WrappedValue} from './change_detection_util';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -37,26 +37,3 @@ export interface PipeTransform { transform(value: any, args: List<any>): any; }
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export interface PipeOnDestroy { onDestroy(): void; }
|
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 {Observable, Promise, ObservableWrapper} from 'angular2/src/facade/async';
|
||||||
import {Injectable} from 'angular2/di';
|
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 {InvalidPipeArgumentException} from './invalid_pipe_argument_exception';
|
||||||
import {ChangeDetectorRef} from 'angular2/change_detection';
|
import {ChangeDetectorRef} from 'angular2/change_detection';
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ var _observableStrategy = new ObservableStrategy();
|
||||||
*/
|
*/
|
||||||
@Pipe({name: 'async'})
|
@Pipe({name: 'async'})
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AsyncPipe implements PipeTransform {
|
export class AsyncPipe implements PipeTransform, PipeOnDestroy {
|
||||||
_latestValue: Object = null;
|
_latestValue: Object = null;
|
||||||
_latestReturnedValue: Object = null;
|
_latestReturnedValue: Object = null;
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ import {DateFormatter} from 'angular2/src/facade/intl';
|
||||||
import {Injectable} from 'angular2/di';
|
import {Injectable} from 'angular2/di';
|
||||||
import {StringMapWrapper, ListWrapper} from 'angular2/src/facade/collection';
|
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 {InvalidPipeArgumentException} from './invalid_pipe_argument_exception';
|
||||||
|
|
||||||
import {Pipe} from 'angular2/src/core/annotations/decorators';
|
import {Pipe} from 'angular2/src/core/annotations/decorators';
|
||||||
|
@ -77,7 +77,7 @@ var defaultLocale: string = 'en-US';
|
||||||
@CONST()
|
@CONST()
|
||||||
@Pipe({name: 'date'})
|
@Pipe({name: 'date'})
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class DatePipe extends BasePipeTransform {
|
export class DatePipe implements PipeTransform {
|
||||||
static _ALIASES = {
|
static _ALIASES = {
|
||||||
'medium': 'yMMMdjms',
|
'medium': 'yMMMdjms',
|
||||||
'short': 'yMdjm',
|
'short': 'yMdjm',
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import {isBlank, isPresent, Json, CONST} from 'angular2/src/facade/lang';
|
import {isBlank, isPresent, Json, CONST} from 'angular2/src/facade/lang';
|
||||||
import {Injectable} from 'angular2/di';
|
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';
|
import {Pipe} from 'angular2/src/core/annotations/decorators';
|
||||||
|
|
||||||
|
@ -31,6 +31,6 @@ import {Pipe} from 'angular2/src/core/annotations/decorators';
|
||||||
@CONST()
|
@CONST()
|
||||||
@Pipe({name: 'json'})
|
@Pipe({name: 'json'})
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class JsonPipe extends BasePipeTransform {
|
export class JsonPipe implements PipeTransform {
|
||||||
transform(value: any, args: List<any> = null): string { return Json.stringify(value); }
|
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 {Math} from 'angular2/src/facade/math';
|
||||||
import {Injectable} from 'angular2/di';
|
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 {InvalidPipeArgumentException} from './invalid_pipe_argument_exception';
|
||||||
|
|
||||||
import {Pipe} from 'angular2/src/core/annotations/decorators';
|
import {Pipe} from 'angular2/src/core/annotations/decorators';
|
||||||
|
@ -78,6 +78,4 @@ export class LimitToPipe implements PipeTransform {
|
||||||
}
|
}
|
||||||
return ListWrapper.slice(value, left, right);
|
return ListWrapper.slice(value, left, right);
|
||||||
}
|
}
|
||||||
|
|
||||||
onDestroy(): void {}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import {isString, StringWrapper, CONST, isBlank} from 'angular2/src/facade/lang';
|
import {isString, StringWrapper, CONST, isBlank} from 'angular2/src/facade/lang';
|
||||||
import {Injectable} from 'angular2/di';
|
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 {InvalidPipeArgumentException} from './invalid_pipe_argument_exception';
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ import {Pipe} from 'angular2/src/core/annotations/decorators';
|
||||||
@CONST()
|
@CONST()
|
||||||
@Pipe({name: 'lowercase'})
|
@Pipe({name: 'lowercase'})
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class LowerCasePipe extends BasePipeTransform {
|
export class LowerCasePipe implements PipeTransform {
|
||||||
transform(value: string, args: List<any> = null): string {
|
transform(value: string, args: List<any> = null): string {
|
||||||
if (isBlank(value)) return value;
|
if (isBlank(value)) return value;
|
||||||
if (!isString(value)) {
|
if (!isString(value)) {
|
||||||
|
|
|
@ -13,7 +13,7 @@ import {NumberFormatter, NumberFormatStyle} from 'angular2/src/facade/intl';
|
||||||
import {Injectable} from 'angular2/di';
|
import {Injectable} from 'angular2/di';
|
||||||
import {ListWrapper} from 'angular2/src/facade/collection';
|
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 {InvalidPipeArgumentException} from './invalid_pipe_argument_exception';
|
||||||
|
|
||||||
import {Pipe} from 'angular2/src/core/annotations/decorators';
|
import {Pipe} from 'angular2/src/core/annotations/decorators';
|
||||||
|
@ -23,7 +23,7 @@ var _re = RegExpWrapper.create('^(\\d+)?\\.((\\d+)(\\-(\\d+))?)?$');
|
||||||
|
|
||||||
@CONST()
|
@CONST()
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class NumberPipe extends BasePipeTransform {
|
export class NumberPipe {
|
||||||
static _format(value: number, style: NumberFormatStyle, digits: string, currency: string = null,
|
static _format(value: number, style: NumberFormatStyle, digits: string, currency: string = null,
|
||||||
currencyAsSymbol: boolean = false): string {
|
currencyAsSymbol: boolean = false): string {
|
||||||
if (isBlank(value)) return null;
|
if (isBlank(value)) return null;
|
||||||
|
@ -84,7 +84,7 @@ export class NumberPipe extends BasePipeTransform {
|
||||||
@CONST()
|
@CONST()
|
||||||
@Pipe({name: 'number'})
|
@Pipe({name: 'number'})
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class DecimalPipe extends NumberPipe {
|
export class DecimalPipe extends NumberPipe implements PipeTransform {
|
||||||
transform(value: any, args: any[]): string {
|
transform(value: any, args: any[]): string {
|
||||||
var digits: string = ListWrapper.first(args);
|
var digits: string = ListWrapper.first(args);
|
||||||
return NumberPipe._format(value, NumberFormatStyle.DECIMAL, digits);
|
return NumberPipe._format(value, NumberFormatStyle.DECIMAL, digits);
|
||||||
|
@ -103,7 +103,7 @@ export class DecimalPipe extends NumberPipe {
|
||||||
@CONST()
|
@CONST()
|
||||||
@Pipe({name: 'percent'})
|
@Pipe({name: 'percent'})
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class PercentPipe extends NumberPipe {
|
export class PercentPipe extends NumberPipe implements PipeTransform {
|
||||||
transform(value: any, args: any[]): string {
|
transform(value: any, args: any[]): string {
|
||||||
var digits: string = ListWrapper.first(args);
|
var digits: string = ListWrapper.first(args);
|
||||||
return NumberPipe._format(value, NumberFormatStyle.PERCENT, digits);
|
return NumberPipe._format(value, NumberFormatStyle.PERCENT, digits);
|
||||||
|
@ -126,7 +126,7 @@ export class PercentPipe extends NumberPipe {
|
||||||
@CONST()
|
@CONST()
|
||||||
@Pipe({name: 'currency'})
|
@Pipe({name: 'currency'})
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CurrencyPipe extends NumberPipe {
|
export class CurrencyPipe extends NumberPipe implements PipeTransform {
|
||||||
transform(value: any, args: any[]): string {
|
transform(value: any, args: any[]): string {
|
||||||
var currencyCode: string = isPresent(args) && args.length > 0 ? args[0] : 'USD';
|
var currencyCode: string = isPresent(args) && args.length > 0 ? args[0] : 'USD';
|
||||||
var symbolDisplay: boolean = isPresent(args) && args.length > 1 ? args[1] : false;
|
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 {isString, StringWrapper, CONST, isBlank} from 'angular2/src/facade/lang';
|
||||||
import {Injectable} from 'angular2/di';
|
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 {InvalidPipeArgumentException} from './invalid_pipe_argument_exception';
|
||||||
|
|
||||||
import {Pipe} from 'angular2/src/core/annotations/decorators';
|
import {Pipe} from 'angular2/src/core/annotations/decorators';
|
||||||
|
@ -29,7 +29,7 @@ import {Pipe} from 'angular2/src/core/annotations/decorators';
|
||||||
@CONST()
|
@CONST()
|
||||||
@Pipe({name: 'uppercase'})
|
@Pipe({name: 'uppercase'})
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UpperCasePipe extends BasePipeTransform {
|
export class UpperCasePipe implements PipeTransform {
|
||||||
transform(value: string, args: List<any> = null): string {
|
transform(value: string, args: List<any> = null): string {
|
||||||
if (isBlank(value)) return value;
|
if (isBlank(value)) return value;
|
||||||
if (!isString(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