| 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 |
| 73 return (model, node) { | 84 return (model, node) { |
| 74 if (model is! Scope) { | 85 if (model is! Scope) { |
| 75 model = new Scope(model: model, variables: globals); | 86 model = new Scope(model: model, variables: globals); |
| 76 } | 87 } |
| 77 if (node is Element && name == "class") { | 88 if (node is Element && name == "class") { |
| 78 return new _Binding(expr, model, _classAttributeConverter); | 89 return new _Binding(expr, model, _classAttributeConverter); |
| 79 } | 90 } |
| 80 if (node is Element && name == "style") { | 91 if (node is Element && name == "style") { |
| 81 return new _Binding(expr, model, _styleAttributeConverter); | 92 return new _Binding(expr, model, _styleAttributeConverter); |
| 82 } | 93 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 @reflectable get value => _value; | 139 @reflectable get value => _value; |
| 129 | 140 |
| 130 @reflectable set value(v) { | 141 @reflectable set value(v) { |
| 131 try { | 142 try { |
| 132 assign(_expr, v, _scope); | 143 assign(_expr, v, _scope); |
| 133 } on EvalException catch (e) { | 144 } on EvalException catch (e) { |
| 134 _logger.warning("Error evaluating expression '$_expr': ${e.message}"); | 145 _logger.warning("Error evaluating expression '$_expr': ${e.message}"); |
| 135 } | 146 } |
| 136 } | 147 } |
| 137 } | 148 } |
| OLD | NEW |