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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 | 60 |
61 /** | 61 /** |
62 * Creates a new binding delegate for Polymer expressions, with the provided | 62 * Creates a new binding delegate for Polymer expressions, with the provided |
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 _Binding getBinding(model, 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 if (model is! Scope) { | 73 return (model, node) { |
74 model = new Scope(model: model, variables: globals); | 74 if (model is! Scope) { |
75 } | 75 model = new Scope(model: model, variables: globals); |
76 if (node is Element && name == "class") { | 76 } |
77 return new _Binding(expr, model, _classAttributeConverter); | 77 if (node is Element && name == "class") { |
78 } | 78 return new _Binding(expr, model, _classAttributeConverter); |
79 if (node is Element && name == "style") { | 79 } |
80 return new _Binding(expr, model, _styleAttributeConverter); | 80 if (node is Element && name == "style") { |
81 } | 81 return new _Binding(expr, model, _styleAttributeConverter); |
82 return new _Binding(expr, model); | 82 } |
83 return new _Binding(expr, model); | |
84 }; | |
83 } | 85 } |
84 | 86 |
85 getInstanceModel(Element template, model) { | 87 prepareInstanceModel(Element template) => (model) { |
86 if (model is! Scope) { | 88 if (model is! Scope) { |
87 var _scope = new Scope(model: model, variables: globals); | 89 return new Scope(model: model, variables: globals); |
Siggi Cherem (dart-lang)
2013/10/29 21:00:07
now it might fit with the prev line or even a tern
Jennifer Messerly
2013/10/29 23:07:19
haha. nice. done!
| |
88 return _scope; | |
89 } | 90 } |
90 return model; | 91 return model; |
91 } | 92 }; |
92 } | 93 } |
93 | 94 |
94 class _Binding extends ChangeNotifier { | 95 class _Binding extends ChangeNotifier { |
95 final Scope _scope; | 96 final Scope _scope; |
96 final ExpressionObserver _expr; | 97 final ExpressionObserver _expr; |
97 final _converter; | 98 final _converter; |
98 var _value; | 99 var _value; |
99 | 100 |
100 _Binding(Expression expr, Scope scope, [this._converter]) | 101 _Binding(Expression expr, Scope scope, [this._converter]) |
101 : _expr = observe(expr, scope), | 102 : _expr = observe(expr, scope), |
(...skipping 29 matching lines...) Expand all Loading... | |
131 @reflectable get value => _value; | 132 @reflectable get value => _value; |
132 | 133 |
133 @reflectable set value(v) { | 134 @reflectable set value(v) { |
134 try { | 135 try { |
135 assign(_expr, v, _scope); | 136 assign(_expr, v, _scope); |
136 } on EvalException catch (e) { | 137 } on EvalException catch (e) { |
137 _logger.warning("Error evaluating expression '$_expr': ${e.message}"); | 138 _logger.warning("Error evaluating expression '$_expr': ${e.message}"); |
138 } | 139 } |
139 } | 140 } |
140 } | 141 } |
OLD | NEW |