@@ -3,8 +3,10 @@ import {SetterFn} from 'angular2/src/reflection/types';
3
3
import { AST } from './parser/ast' ;
4
4
import { DirectiveIndex , DirectiveRecord } from './directive_record' ;
5
5
6
- const DIRECTIVE = "directive" ;
7
6
const DIRECTIVE_LIFECYCLE = "directiveLifecycle" ;
7
+ const BINDING = "native" ;
8
+
9
+ const DIRECTIVE = "directive" ;
8
10
const ELEMENT_PROPERTY = "elementProperty" ;
9
11
const ELEMENT_ATTRIBUTE = "elementAttribute" ;
10
12
const ELEMENT_CLASS = "elementClass" ;
@@ -13,24 +15,12 @@ const TEXT_NODE = "textNode";
13
15
const EVENT = "event" ;
14
16
const HOST_EVENT = "hostEvent" ;
15
17
16
- export class BindingRecord {
17
- constructor ( public mode : string , public implicitReceiver : any , public ast : AST ,
18
- public elementIndex : number , public propertyName : string , public propertyUnit : string ,
19
- public eventName : string , public setter : SetterFn , public lifecycleEvent : string ,
20
- public directiveRecord : DirectiveRecord ) { }
21
-
22
- callOnChange ( ) : boolean {
23
- return isPresent ( this . directiveRecord ) && this . directiveRecord . callOnChange ;
24
- }
25
-
26
- isDefaultChangeDetection ( ) : boolean {
27
- return isBlank ( this . directiveRecord ) || this . directiveRecord . isDefaultChangeDetection ( ) ;
28
- }
18
+ export class BindingTarget {
19
+ constructor ( public mode : string , public elementIndex : number , public name : string ,
20
+ public unit : string , public debug : string ) { }
29
21
30
22
isDirective ( ) : boolean { return this . mode === DIRECTIVE ; }
31
23
32
- isDirectiveLifecycle ( ) : boolean { return this . mode === DIRECTIVE_LIFECYCLE ; }
33
-
34
24
isElementProperty ( ) : boolean { return this . mode === ELEMENT_PROPERTY ; }
35
25
36
26
isElementAttribute ( ) : boolean { return this . mode === ELEMENT_ATTRIBUTE ; }
@@ -40,87 +30,118 @@ export class BindingRecord {
40
30
isElementStyle ( ) : boolean { return this . mode === ELEMENT_STYLE ; }
41
31
42
32
isTextNode ( ) : boolean { return this . mode === TEXT_NODE ; }
33
+ }
43
34
44
- static createForDirective ( ast : AST , propertyName : string , setter : SetterFn ,
45
- directiveRecord : DirectiveRecord ) : BindingRecord {
46
- return new BindingRecord ( DIRECTIVE , 0 , ast , 0 , propertyName , null , null , setter , null ,
47
- directiveRecord ) ;
35
+ export class BindingRecord {
36
+ constructor ( public mode : string , public target : BindingTarget , public implicitReceiver : any ,
37
+ public ast : AST , public setter : SetterFn , public lifecycleEvent : string ,
38
+ public directiveRecord : DirectiveRecord ) { }
39
+
40
+ isDirectiveLifecycle ( ) : boolean { return this . mode === DIRECTIVE_LIFECYCLE ; }
41
+
42
+ callOnChange ( ) : boolean {
43
+ return isPresent ( this . directiveRecord ) && this . directiveRecord . callOnChange ;
48
44
}
49
45
46
+ isDefaultChangeDetection ( ) : boolean {
47
+ return isBlank ( this . directiveRecord ) || this . directiveRecord . isDefaultChangeDetection ( ) ;
48
+ }
49
+
50
+
50
51
static createDirectiveOnCheck ( directiveRecord : DirectiveRecord ) : BindingRecord {
51
- return new BindingRecord ( DIRECTIVE_LIFECYCLE , 0 , null , 0 , null , null , null , null , "onCheck" ,
52
- directiveRecord ) ;
52
+ return new BindingRecord ( DIRECTIVE_LIFECYCLE , null , 0 , null , null , "onCheck" , directiveRecord ) ;
53
53
}
54
54
55
55
static createDirectiveOnInit ( directiveRecord : DirectiveRecord ) : BindingRecord {
56
- return new BindingRecord ( DIRECTIVE_LIFECYCLE , 0 , null , 0 , null , null , null , null , "onInit" ,
57
- directiveRecord ) ;
56
+ return new BindingRecord ( DIRECTIVE_LIFECYCLE , null , 0 , null , null , "onInit" , directiveRecord ) ;
58
57
}
59
58
60
59
static createDirectiveOnChange ( directiveRecord : DirectiveRecord ) : BindingRecord {
61
- return new BindingRecord ( DIRECTIVE_LIFECYCLE , 0 , null , 0 , null , null , null , null , "onChange" ,
62
- directiveRecord ) ;
60
+ return new BindingRecord ( DIRECTIVE_LIFECYCLE , null , 0 , null , null , "onChange" , directiveRecord ) ;
61
+ }
62
+
63
+
64
+
65
+ static createForDirective ( ast : AST , propertyName : string , setter : SetterFn ,
66
+ directiveRecord : DirectiveRecord ) : BindingRecord {
67
+ var t = new BindingTarget ( DIRECTIVE , null , propertyName , null , ast . toString ( ) ) ;
68
+ return new BindingRecord ( DIRECTIVE , t , 0 , ast , setter , null , directiveRecord ) ;
63
69
}
64
70
71
+
72
+
65
73
static createForElementProperty ( ast : AST , elementIndex : number ,
66
74
propertyName : string ) : BindingRecord {
67
- return new BindingRecord ( ELEMENT_PROPERTY , 0 , ast , elementIndex , propertyName , null , null , null ,
68
- null , null ) ;
75
+ var t = new BindingTarget ( ELEMENT_PROPERTY , elementIndex , propertyName , null , ast . toString ( ) ) ;
76
+ return new BindingRecord ( BINDING , t , 0 , ast , null , null , null ) ;
69
77
}
70
78
71
79
static createForElementAttribute ( ast : AST , elementIndex : number ,
72
80
attributeName : string ) : BindingRecord {
73
- return new BindingRecord ( ELEMENT_ATTRIBUTE , 0 , ast , elementIndex , attributeName , null , null ,
74
- null , null , null ) ;
81
+ var t = new BindingTarget ( ELEMENT_ATTRIBUTE , elementIndex , attributeName , null , ast . toString ( ) ) ;
82
+ return new BindingRecord ( BINDING , t , 0 , ast , null , null , null ) ;
75
83
}
76
84
77
85
static createForElementClass ( ast : AST , elementIndex : number , className : string ) : BindingRecord {
78
- return new BindingRecord ( ELEMENT_CLASS , 0 , ast , elementIndex , className , null , null , null , null ,
79
- null ) ;
86
+ var t = new BindingTarget ( ELEMENT_CLASS , elementIndex , className , null , ast . toString ( ) ) ;
87
+ return new BindingRecord ( BINDING , t , 0 , ast , null , null , null ) ;
80
88
}
81
89
82
90
static createForElementStyle ( ast : AST , elementIndex : number , styleName : string ,
83
91
unit : string ) : BindingRecord {
84
- return new BindingRecord ( ELEMENT_STYLE , 0 , ast , elementIndex , styleName , unit , null , null , null ,
85
- null ) ;
92
+ var t = new BindingTarget ( ELEMENT_STYLE , elementIndex , styleName , unit , ast . toString ( ) ) ;
93
+ return new BindingRecord ( BINDING , t , 0 , ast , null , null , null ) ;
86
94
}
87
95
96
+
97
+
88
98
static createForHostProperty ( directiveIndex : DirectiveIndex , ast : AST ,
89
99
propertyName : string ) : BindingRecord {
90
- return new BindingRecord ( ELEMENT_PROPERTY , directiveIndex , ast , directiveIndex . elementIndex ,
91
- propertyName , null , null , null , null , null ) ;
100
+ var t = new BindingTarget ( ELEMENT_PROPERTY , directiveIndex . elementIndex , propertyName , null ,
101
+ ast . toString ( ) ) ;
102
+ return new BindingRecord ( BINDING , t , directiveIndex , ast , null , null , null ) ;
92
103
}
93
104
94
105
static createForHostAttribute ( directiveIndex : DirectiveIndex , ast : AST ,
95
106
attributeName : string ) : BindingRecord {
96
- return new BindingRecord ( ELEMENT_ATTRIBUTE , directiveIndex , ast , directiveIndex . elementIndex ,
97
- attributeName , null , null , null , null , null ) ;
107
+ var t = new BindingTarget ( ELEMENT_ATTRIBUTE , directiveIndex . elementIndex , attributeName , null ,
108
+ ast . toString ( ) ) ;
109
+ return new BindingRecord ( BINDING , t , directiveIndex , ast , null , null , null ) ;
98
110
}
99
111
100
112
static createForHostClass ( directiveIndex : DirectiveIndex , ast : AST ,
101
113
className : string ) : BindingRecord {
102
- return new BindingRecord ( ELEMENT_CLASS , directiveIndex , ast , directiveIndex . elementIndex ,
103
- className , null , null , null , null , null ) ;
114
+ var t = new BindingTarget ( ELEMENT_CLASS , directiveIndex . elementIndex , className , null ,
115
+ ast . toString ( ) ) ;
116
+ return new BindingRecord ( BINDING , t , directiveIndex , ast , null , null , null ) ;
104
117
}
105
118
106
119
static createForHostStyle ( directiveIndex : DirectiveIndex , ast : AST , styleName : string ,
107
120
unit : string ) : BindingRecord {
108
- return new BindingRecord ( ELEMENT_STYLE , directiveIndex , ast , directiveIndex . elementIndex ,
109
- styleName , unit , null , null , null , null ) ;
121
+ var t = new BindingTarget ( ELEMENT_STYLE , directiveIndex . elementIndex , styleName , unit ,
122
+ ast . toString ( ) ) ;
123
+ return new BindingRecord ( BINDING , t , directiveIndex , ast , null , null , null ) ;
110
124
}
111
125
126
+
127
+
112
128
static createForTextNode ( ast : AST , elementIndex : number ) : BindingRecord {
113
- return new BindingRecord ( TEXT_NODE , 0 , ast , elementIndex , null , null , null , null , null , null ) ;
129
+ var t = new BindingTarget ( TEXT_NODE , elementIndex , null , null , ast . toString ( ) ) ;
130
+ return new BindingRecord ( BINDING , t , 0 , ast , null , null , null ) ;
114
131
}
115
132
133
+
134
+
116
135
static createForEvent ( ast : AST , eventName : string , elementIndex : number ) : BindingRecord {
117
- return new BindingRecord ( EVENT , 0 , ast , elementIndex , null , null , eventName , null , null , null ) ;
136
+ var t = new BindingTarget ( EVENT , elementIndex , eventName , null , ast . toString ( ) ) ;
137
+ return new BindingRecord ( EVENT , t , 0 , ast , null , null , null ) ;
118
138
}
119
139
120
140
static createForHostEvent ( ast : AST , eventName : string ,
121
141
directiveRecord : DirectiveRecord ) : BindingRecord {
122
142
var directiveIndex = directiveRecord . directiveIndex ;
123
- return new BindingRecord ( EVENT , directiveIndex , ast , directiveIndex . elementIndex , null , null ,
124
- eventName , null , null , directiveRecord ) ;
143
+ var t =
144
+ new BindingTarget ( HOST_EVENT , directiveIndex . elementIndex , eventName , null , ast . toString ( ) ) ;
145
+ return new BindingRecord ( HOST_EVENT , t , directiveIndex , ast , null , null , directiveRecord ) ;
125
146
}
126
147
}
0 commit comments