| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 } |
| OLD | NEW |