Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(274)

Side by Side Diff: pkg/polymer_expressions/lib/polymer_expressions.dart

Issue 263833027: Fix two-way binding in polymer expressions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/polymer_expressions/lib/eval.dart ('k') | pkg/polymer_expressions/test/bindings_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /** 5 /**
6 * A binding delegate used with Polymer elements that 6 * A binding delegate used with Polymer elements that
7 * allows for complex binding expressions, including 7 * allows for complex binding expressions, including
8 * property access, function invocation, 8 * property access, function invocation,
9 * list/map indexing, and two-way filtering. 9 * list/map indexing, and two-way filtering.
10 * 10 *
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 try { 116 try {
117 return _convertValue(eval(expr, scope), scope, converter); 117 return _convertValue(eval(expr, scope), scope, converter);
118 } catch (e, s) { 118 } catch (e, s) {
119 new Completer().completeError( 119 new Completer().completeError(
120 "Error evaluating expression '$expr': $e", s); 120 "Error evaluating expression '$expr': $e", s);
121 } 121 }
122 return null; 122 return null;
123 } 123 }
124 124
125 _setValue(v) { 125 _setValue(v) {
126 var oldValue = _value;
126 _value = _convertValue(v, _scope, _converter); 127 _value = _convertValue(v, _scope, _converter);
127 if (_callback != null) _callback(_value); 128 if (_callback != null && oldValue != _value) _callback(_value);
128 } 129 }
129 130
130 static _convertValue(v, scope, converter) { 131 static _convertValue(v, scope, converter) {
131 if (v is Comprehension) { 132 if (v is Comprehension) {
132 // convert the Comprehension into a list of scopes with the loop 133 // convert the Comprehension into a list of scopes with the loop
133 // variable added to the scope 134 // variable added to the scope
134 return v.iterable.map((i) => scope.childScope(v.identifier, i)) 135 return v.iterable.map((i) => scope.childScope(v.identifier, i))
135 .toList(growable: false); 136 .toList(growable: false);
136 } else { 137 } else {
137 return converter == null ? v : converter(v); 138 return converter == null ? v : converter(v);
138 } 139 }
139 } 140 }
140 141
141 get value { 142 get value {
142 if (_callback != null) return _value; 143 if (_callback != null) return _value;
143 return _oneTime(_expr, _scope, _converter); 144 return _oneTime(_expr, _scope, _converter);
144 } 145 }
145 146
146 set value(v) { 147 set value(v) {
147 try { 148 try {
148 assign(_expr, v, _scope); 149 var newValue = assign(_expr, v, _scope);
150 _value = _convertValue(newValue, _scope, _converter);
149 } catch (e, s) { 151 } catch (e, s) {
150 new Completer().completeError( 152 new Completer().completeError(
151 "Error evaluating expression '$_expr': $e", s); 153 "Error evaluating expression '$_expr': $e", s);
152 } 154 }
153 } 155 }
154 156
155 open(callback(value)) { 157 open(callback(value)) {
156 if (_callback != null) throw new StateError('already open'); 158 if (_callback != null) throw new StateError('already open');
157 159
158 _callback = callback; 160 _callback = callback;
(...skipping 15 matching lines...) Expand all
174 176
175 void close() { 177 void close() {
176 if (_callback == null) return; 178 if (_callback == null) return;
177 179
178 _sub.cancel(); 180 _sub.cancel();
179 _sub = null; 181 _sub = null;
180 _expr = (_expr as ExpressionObserver).expression; 182 _expr = (_expr as ExpressionObserver).expression;
181 _callback = null; 183 _callback = null;
182 } 184 }
183 } 185 }
OLDNEW
« no previous file with comments | « pkg/polymer_expressions/lib/eval.dart ('k') | pkg/polymer_expressions/test/bindings_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698