2015-05-04 12:18:06 -07:00
|
|
|
import {ABSTRACT, BaseException, CONST} from 'angular2/src/facade/lang';
|
|
|
|
|
2015-04-10 11:15:01 -07:00
|
|
|
/**
|
2015-05-01 14:05:19 -07:00
|
|
|
* Indicates that the result of a {@link Pipe} transformation has changed even though the reference
|
|
|
|
*has not changed.
|
2015-04-10 11:15:01 -07:00
|
|
|
*
|
2015-04-23 17:19:29 -07:00
|
|
|
* The wrapped value will be unwrapped by change detection, and the unwrapped value will be stored.
|
2015-04-10 11:15:01 -07:00
|
|
|
*
|
|
|
|
* @exportedAs angular2/pipes
|
|
|
|
*/
|
2015-04-23 17:19:29 -07:00
|
|
|
export class WrappedValue {
|
2015-05-01 14:05:19 -07:00
|
|
|
constructor(public wrapped: any) {}
|
2015-04-23 17:19:29 -07:00
|
|
|
|
2015-05-01 14:05:19 -07:00
|
|
|
static wrap(value: any): WrappedValue {
|
2015-04-23 17:19:29 -07:00
|
|
|
var w = _wrappedValues[_wrappedIndex++ % 5];
|
|
|
|
w.wrapped = value;
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var _wrappedValues = [
|
|
|
|
new WrappedValue(null),
|
|
|
|
new WrappedValue(null),
|
|
|
|
new WrappedValue(null),
|
|
|
|
new WrappedValue(null),
|
|
|
|
new WrappedValue(null)
|
|
|
|
];
|
|
|
|
|
|
|
|
var _wrappedIndex = 0;
|
2015-02-12 14:56:41 -08:00
|
|
|
|
2015-03-31 22:47:11 +00:00
|
|
|
/**
|
2015-04-10 11:15:01 -07:00
|
|
|
* An interface for extending the list of pipes known to Angular.
|
|
|
|
*
|
2015-04-17 13:01:07 -07:00
|
|
|
* If you are writing a custom {@link Pipe}, you must extend this interface.
|
2015-04-10 11:15:01 -07:00
|
|
|
*
|
|
|
|
* #Example
|
|
|
|
*
|
|
|
|
* ```
|
2015-06-18 15:40:12 -07:00
|
|
|
* class DoublePipe implements Pipe {
|
2015-04-10 11:15:01 -07:00
|
|
|
* supports(obj) {
|
|
|
|
* return true;
|
|
|
|
* }
|
|
|
|
*
|
2015-06-18 15:40:12 -07:00
|
|
|
* onDestroy() {}
|
|
|
|
*
|
2015-04-10 11:15:01 -07:00
|
|
|
* transform(value) {
|
|
|
|
* return `${value}${value}`;
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* @exportedAs angular2/pipes
|
2015-03-31 22:47:11 +00:00
|
|
|
*/
|
2015-06-18 15:40:12 -07:00
|
|
|
export interface Pipe {
|
|
|
|
supports(obj): boolean;
|
|
|
|
onDestroy(): void;
|
|
|
|
transform(value: any): any;
|
2015-04-10 11:15:01 -07:00
|
|
|
}
|
2015-05-04 12:18:06 -07:00
|
|
|
|
2015-06-18 15:40:12 -07:00
|
|
|
/**
|
|
|
|
* Provides default implementation of supports and onDestroy.
|
|
|
|
*
|
|
|
|
* #Example
|
|
|
|
*
|
|
|
|
* ```
|
|
|
|
* class DoublePipe extends BasePipe {*
|
|
|
|
* transform(value) {
|
|
|
|
* return `${value}${value}`;
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* ```
|
|
|
|
*/
|
|
|
|
export class BasePipe implements Pipe {
|
|
|
|
supports(obj): boolean { return true; }
|
|
|
|
onDestroy(): void {}
|
|
|
|
transform(value: any): any { return _abstract(); }
|
|
|
|
}
|
2015-05-04 12:18:06 -07:00
|
|
|
|
2015-06-18 15:40:12 -07:00
|
|
|
export interface PipeFactory {
|
|
|
|
supports(obs): boolean;
|
|
|
|
create(cdRef): Pipe;
|
2015-05-04 12:18:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function _abstract() {
|
2015-05-01 14:05:19 -07:00
|
|
|
throw new BaseException('This method is abstract');
|
2015-05-04 12:18:06 -07:00
|
|
|
}
|