@@ -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,24 +167,23 @@ 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
184
181
if (nodeAttrs[attrName] == null ) return ;
185
182
186
- Expression attrExprFn = _parser (nodeAttrs[attrName]);
187
183
var watch;
188
184
var lastOneTimeValue;
189
- watch = scope.watch (nodeAttrs[attrName] , (value, _) {
190
- if ((lastOneTimeValue = dstPathFn .assign (directive, value)) != null && watch != null ) {
185
+ watch = scope.watchAST (attrValueAST , (value, _) {
186
+ if ((lastOneTimeValue = dstAST.exp .assign (directive, value)) != null && watch != null ) {
191
187
var watchToRemove = watch;
192
188
watch = null ;
193
189
scope.rootScope.domWrite (() {
@@ -198,17 +194,17 @@ class ElementBinder {
198
194
}
199
195
});
200
196
}
201
- }, formatters : formatters );
197
+ });
202
198
break ;
203
199
204
200
case '&' : // callback
205
- _bindCallback (dstPathFn , directive, nodeAttrs[attrName], scope);
201
+ _bindCallback (dstAST.exp , directive, nodeAttrs[attrName], scope);
206
202
break ;
207
203
}
208
204
});
209
205
}
210
206
211
- void _link (nodeInjector, probe, scope, nodeAttrs, formatters ) {
207
+ void _link (nodeInjector, probe, scope, nodeAttrs) {
212
208
_usableDirectiveRefs.forEach ((DirectiveRef ref) {
213
209
var directive = nodeInjector.getByKey (ref.typeKey);
214
210
probe.directives.add (directive);
@@ -223,7 +219,7 @@ class ElementBinder {
223
219
224
220
if (ref.mappings.isNotEmpty) {
225
221
if (nodeAttrs == null ) nodeAttrs = new _AnchorAttrs (ref);
226
- _createAttrMappings (directive, scope, ref.mappings, nodeAttrs, formatters, tasks);
222
+ _createAttrMappings (directive, scope, ref.mappings, nodeAttrs, tasks);
227
223
}
228
224
229
225
if (directive is AttachAware ) {
@@ -287,7 +283,6 @@ class ElementBinder {
287
283
Injector bind (View view, Injector parentInjector, dom.Node node) {
288
284
Injector nodeInjector;
289
285
Scope scope = parentInjector.getByKey (SCOPE_KEY );
290
- FormatterMap formatters = parentInjector.getByKey (FORMATTER_MAP_KEY );
291
286
var nodeAttrs = node is dom.Element ? new NodeAttrs (node) : null ;
292
287
ElementProbe probe;
293
288
@@ -325,7 +320,7 @@ class ElementBinder {
325
320
parentInjector.getByKey (ELEMENT_PROBE_KEY ), node, nodeInjector, scope);
326
321
scope.on (ScopeEvent .DESTROY ).listen ((_) {_expando[node] = null ;});
327
322
328
- _link (nodeInjector, probe, scope, nodeAttrs, formatters );
323
+ _link (nodeInjector, probe, scope, nodeAttrs);
329
324
330
325
onEvents.forEach ((event, value) {
331
326
view.registerEvent (EventHandler .attrNameToEventName (event));
0 commit comments