| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 * variables used as [globals]. If no globals are supplied, a copy of the | 63 * variables used as [globals]. If no globals are supplied, a copy of the |
| 64 * [DEFAULT_GLOBALS] will be used. | 64 * [DEFAULT_GLOBALS] will be used. |
| 65 */ | 65 */ |
| 66 PolymerExpressions({Map<String, Object> globals}) | 66 PolymerExpressions({Map<String, Object> globals}) |
| 67 : globals = (globals == null) ? | 67 : globals = (globals == null) ? |
| 68 new Map<String, Object>.from(DEFAULT_GLOBALS) : globals; | 68 new Map<String, Object>.from(DEFAULT_GLOBALS) : globals; |
| 69 | 69 |
| 70 prepareBinding(String path, name, node) { | 70 prepareBinding(String path, name, node) { |
| 71 if (path == null) return null; | 71 if (path == null) return null; |
| 72 var expr = new Parser(path).parse(); | 72 var expr = new Parser(path).parse(); |
| 73 | |
| 74 // For template bind/repeat to an empty path, just pass through the model. | |
| 75 // We don't want to unwrap the Scope. | |
| 76 // TODO(jmesserly): a custom element extending <template> could notice this | |
| 77 // behavior. An alternative is to associate the Scope with the node via an | |
| 78 // Expando, which is what the JavaScript PolymerExpressions does. | |
| 79 if (isSemanticTemplate(node) && (name == 'bind' || name == 'repeat') && | |
| 80 expr is EmptyExpression) { | |
| 81 return null; | |
| 82 } | |
| 83 | |
| 84 return (model, node) { | 73 return (model, node) { |
| 85 if (model is! Scope) { | 74 if (model is! Scope) { |
| 86 model = new Scope(model: model, variables: globals); | 75 model = new Scope(model: model, variables: globals); |
| 87 } | 76 } |
| 88 if (node is Element && name == "class") { | 77 if (node is Element && name == "class") { |
| 89 return new _Binding(expr, model, _classAttributeConverter); | 78 return new _Binding(expr, model, _classAttributeConverter); |
| 90 } | 79 } |
| 91 if (node is Element && name == "style") { | 80 if (node is Element && name == "style") { |
| 92 return new _Binding(expr, model, _styleAttributeConverter); | 81 return new _Binding(expr, model, _styleAttributeConverter); |
| 93 } | 82 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 @reflectable get value => _value; | 128 @reflectable get value => _value; |
| 140 | 129 |
| 141 @reflectable set value(v) { | 130 @reflectable set value(v) { |
| 142 try { | 131 try { |
| 143 assign(_expr, v, _scope); | 132 assign(_expr, v, _scope); |
| 144 } on EvalException catch (e) { | 133 } on EvalException catch (e) { |
| 145 _logger.warning("Error evaluating expression '$_expr': ${e.message}"); | 134 _logger.warning("Error evaluating expression '$_expr': ${e.message}"); |
| 146 } | 135 } |
| 147 } | 136 } |
| 148 } | 137 } |
| OLD | NEW |