-
Notifications
You must be signed in to change notification settings - Fork 24.7k
/
pipe.ts
87 lines (79 loc) 路 1.72 KB
/
pipe.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import {ABSTRACT, BaseException, CONST} from 'angular2/src/facade/lang';
/**
* Indicates that the result of a {@link Pipe} transformation has changed even though the reference
*has not changed.
*
* The wrapped value will be unwrapped by change detection, and the unwrapped value will be stored.
*
* @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;
/**
* An interface for extending the list of pipes known to Angular.
*
* If you are writing a custom {@link Pipe}, you must extend this interface.
*
* #Example
*
* ```
* class DoublePipe implements Pipe {
* supports(obj) {
* return true;
* }
*
* onDestroy() {}
*
* transform(value) {
* return `${value}${value}`;
* }
* }
* ```
*
* @exportedAs angular2/pipes
*/
export interface Pipe {
supports(obj): boolean;
onDestroy(): void;
transform(value: any): any;
}
/**
* Provides default implementation of supports and onDestroy.
*
* #Example
*
* ```
* class DoublePipe extends BasePipe {*
* transform(value) {
* return `${value}${value}`;
* }
* }
* ```
*/
@CONST()
export class BasePipe implements Pipe {
supports(obj): boolean { return true; }
onDestroy(): void {}
transform(value: any): any { return _abstract(); }
}
export interface PipeFactory {
supports(obs): boolean;
create(cdRef): Pipe;
}
function _abstract() {
throw new BaseException('This method is abstract');
}