75 lines
1.5 KiB
TypeScript
Raw Normal View History

import {ABSTRACT, BaseException, CONST} from 'angular2/src/facade/lang';
2015-04-10 11:15:01 -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
*
* 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
*/
export class WrappedValue {
constructor(public wrapped: any) {}
static wrap(value: any): WrappedValue {
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-04-10 11:15:01 -07:00
* An interface for extending the list of pipes known to Angular.
*
* If you are writing a custom {@link Pipe}, you must extend this interface.
2015-04-10 11:15:01 -07:00
*
* #Example
*
* ```
* class DoublePipe extends Pipe {
* supports(obj) {
* return true;
* }
*
* transform(value) {
* return `${value}${value}`;
* }
* }
* ```
*
* @exportedAs angular2/pipes
*/
export class Pipe {
supports(obj): boolean { return false; }
onDestroy() {}
transform(value: any): any { return null; }
2015-04-10 11:15:01 -07:00
}
// TODO: vsavkin: make it an interface
@CONST()
export class PipeFactory {
supports(obs): boolean {
_abstract();
return false;
}
create(cdRef): Pipe {
_abstract();
return null;
}
}
function _abstract() {
throw new BaseException('This method is abstract');
}