@@ -83,59 +83,56 @@ class ElementBinder {
83
83
bool get hasDirectivesOrEvents =>
84
84
_usableDirectiveRefs.isNotEmpty || onEvents.isNotEmpty;
85
85
86
- void _bindTwoWay (tasks, expression , scope, controllerScope,
87
- dstPathFn, controller, formatters, dstExpression ) {
86
+ void _bindTwoWay (tasks, AST ast , scope, controllerScope,
87
+ controller, dstAST ) {
88
88
var taskId = tasks.registerTask ();
89
- Expression expressionFn = _parser (expression);
90
89
91
90
var viewOutbound = false ;
92
91
var viewInbound = false ;
93
- scope.watch (expression , (inboundValue, _) {
92
+ scope.watchAST (ast , (inboundValue, _) {
94
93
if (! viewInbound) {
95
94
viewOutbound = true ;
96
95
scope.rootScope.runAsync (() => viewOutbound = false );
97
- var value = dstPathFn .assign (controller, inboundValue);
96
+ var value = dstAST.exp .assign (controller, inboundValue);
98
97
tasks.completeTask (taskId);
99
98
return value;
100
99
}
101
- }, formatters : formatters );
102
- if (expressionFn .isAssignable) {
103
- controllerScope.watch (dstExpression , (outboundValue, _) {
100
+ });
101
+ if (ast.exp .isAssignable) {
102
+ controllerScope.watchAST (dstAST , (outboundValue, _) {
104
103
if (! viewOutbound) {
105
104
viewInbound = true ;
106
105
scope.rootScope.runAsync (() => viewInbound = false );
107
- expressionFn .assign (scope.context, outboundValue);
106
+ ast.exp .assign (scope.context, outboundValue);
108
107
tasks.completeTask (taskId);
109
108
}
110
- }, formatters : formatters );
109
+ });
111
110
}
112
111
}
113
112
114
- _bindOneWay (tasks, expression , scope, dstPathFn, controller, formatters ) {
113
+ _bindOneWay (tasks, ast , scope, AST dstAST, controller ) {
115
114
var taskId = tasks.registerTask ();
116
115
117
- Expression attrExprFn = _parser (expression);
118
- scope.watch (expression, (v, _) {
119
- dstPathFn.assign (controller, v);
116
+ scope.watchAST (ast, (v, _) {
117
+ dstAST.exp.assign (controller, v);
120
118
tasks.completeTask (taskId);
121
- }, formatters : formatters );
119
+ });
122
120
}
123
121
124
122
void _bindCallback (dstPathFn, controller, expression, scope) {
125
123
dstPathFn.assign (controller, _parser (expression).bind (scope.context, ScopeLocals .wrapper));
126
124
}
127
125
128
126
129
- void _createAttrMappings (directive, scope, List <MappingParts > mappings, nodeAttrs, formatters,
130
- tasks) {
127
+ void _createAttrMappings (directive, scope, List <MappingParts > mappings, nodeAttrs, tasks) {
131
128
Scope controllerScope; // Only created if there is a two-way binding in the element.
132
129
mappings.forEach ((MappingParts p) {
133
130
var attrName = p.attrName;
134
- var dstExpression = p.dstExpression;
131
+ var attrValueAST = p.attrValueAST;
132
+ var dstAST = p.dstAST;
135
133
136
- Expression dstPathFn = _parser (dstExpression);
137
- if (! dstPathFn.isAssignable) {
138
- throw "Expression '$dstExpression ' is not assignable in mapping '${p .originalValue }' "
134
+ if (! dstAST.exp.isAssignable) {
135
+ throw "Expression '${dstAST .expression }' is not assignable in mapping '${p .originalValue }' "
139
136
"for attribute '$attrName '." ;
140
137
}
141
138
@@ -146,12 +143,12 @@ class ElementBinder {
146
143
if (controllerScope == null ) {
147
144
controllerScope = scope.createChild (directive);
148
145
}
149
- _bindTwoWay (tasks, bindAttr, scope, controllerScope, dstPathFn,
150
- directive, formatters, dstExpression );
151
- } else if (p.mode == '&' ) {
152
- _bindCallback (dstPathFn, directive, bindAttr, scope) ;
146
+ _bindTwoWay (tasks, bindAttr, scope, controllerScope,
147
+ directive, dstAST );
148
+ } else if (p.mode == '&' ) {
149
+ throw "Callbacks do not support bind- syntax" ;
153
150
} else {
154
- _bindOneWay (tasks, bindAttr, scope, dstPathFn , directive, formatters );
151
+ _bindOneWay (tasks, bindAttr, scope, dstAST , directive);
155
152
}
156
153
return ;
157
154
}
@@ -160,7 +157,7 @@ class ElementBinder {
160
157
case '@' : // string
161
158
var taskId = tasks.registerTask ();
162
159
nodeAttrs.observe (attrName, (value) {
163
- dstPathFn .assign (directive, value);
160
+ dstAST.exp .assign (directive, value);
164
161
tasks.completeTask (taskId);
165
162
});
166
163
break ;
@@ -170,14 +167,14 @@ class ElementBinder {
170
167
if (controllerScope == null ) {
171
168
controllerScope = scope.createChild (directive);
172
169
}
173
- _bindTwoWay (tasks, nodeAttrs[attrName] , scope, controllerScope, dstPathFn ,
174
- directive, formatters, dstExpression );
170
+ _bindTwoWay (tasks, attrValueAST , scope, controllerScope,
171
+ directive, dstAST );
175
172
break ;
176
173
177
174
case '=>' : // one-way
178
175
if (nodeAttrs[attrName] == null ) return ;
179
- _bindOneWay (tasks, nodeAttrs[attrName] , scope,
180
- dstPathFn , directive, formatters );
176
+ _bindOneWay (tasks, attrValueAST , scope,
177
+ dstAST , directive);
181
178
break ;
182
179
183
180
case '=>!' : // one-way, one-time
@@ -187,7 +184,7 @@ class ElementBinder {
187
184
var watch;
188
185
var lastOneTimeValue;
189
186
watch = scope.watch (nodeAttrs[attrName], (value, _) {
190
- if ((lastOneTimeValue = dstPathFn .assign (directive, value)) != null && watch != null ) {
187
+ if ((lastOneTimeValue = dstAST.exp .assign (directive, value)) != null && watch != null ) {
191
188
var watchToRemove = watch;
192
189
watch = null ;
193
190
scope.rootScope.domWrite (() {
@@ -202,13 +199,13 @@ class ElementBinder {
202
199
break ;
203
200
204
201
case '&' : // callback
205
- _bindCallback (dstPathFn , directive, nodeAttrs[attrName], scope);
202
+ _bindCallback (dstAST.exp , directive, nodeAttrs[attrName], scope);
206
203
break ;
207
204
}
208
205
});
209
206
}
210
207
211
- void _link (nodeInjector, probe, scope, nodeAttrs, formatters ) {
208
+ void _link (nodeInjector, probe, scope, nodeAttrs) {
212
209
_usableDirectiveRefs.forEach ((DirectiveRef ref) {
213
210
var directive = nodeInjector.get (ref.type);
214
211
probe.directives.add (directive);
@@ -223,7 +220,7 @@ class ElementBinder {
223
220
224
221
if (ref.mappings.isNotEmpty) {
225
222
if (nodeAttrs == null ) nodeAttrs = new _AnchorAttrs (ref);
226
- _createAttrMappings (directive, scope, ref.mappings, nodeAttrs, formatters, tasks);
223
+ _createAttrMappings (directive, scope, ref.mappings, nodeAttrs, tasks);
227
224
}
228
225
229
226
if (directive is AttachAware ) {
@@ -286,7 +283,6 @@ class ElementBinder {
286
283
Injector bind (View view, Injector parentInjector, dom.Node node) {
287
284
Injector nodeInjector;
288
285
Scope scope = parentInjector.get (Scope );
289
- FormatterMap formatters = parentInjector.get (FormatterMap );
290
286
var nodeAttrs = node is dom.Element ? new NodeAttrs (node) : null ;
291
287
ElementProbe probe;
292
288
@@ -323,7 +319,7 @@ class ElementBinder {
323
319
probe = _expando[node] = new ElementProbe (
324
320
parentInjector.get (ElementProbe ), node, nodeInjector, scope);
325
321
326
- _link (nodeInjector, probe, scope, nodeAttrs, formatters );
322
+ _link (nodeInjector, probe, scope, nodeAttrs);
327
323
328
324
onEvents.forEach ((event, value) {
329
325
view.registerEvent (EventHandler .attrNameToEventName (event));
0 commit comments