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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 | 83 |
84 getInstanceModel(Element template, model) { | 84 getInstanceModel(Element template, model) { |
85 if (model is! Scope) { | 85 if (model is! Scope) { |
86 var _scope = new Scope(model: model, variables: globals); | 86 var _scope = new Scope(model: model, variables: globals); |
87 return _scope; | 87 return _scope; |
88 } | 88 } |
89 return model; | 89 return model; |
90 } | 90 } |
91 } | 91 } |
92 | 92 |
93 class _Binding extends Object with ChangeNotifierMixin { | 93 class _Binding extends ChangeNotifierBase { |
94 static const _VALUE = const Symbol('value'); | |
95 | 94 |
96 final Scope _scope; | 95 final Scope _scope; |
97 final ExpressionObserver _expr; | 96 final ExpressionObserver _expr; |
98 final _converter; | 97 final _converter; |
99 var _value; | 98 var _value; |
100 | 99 |
101 _Binding(Expression expr, Scope scope, [this._converter]) | 100 _Binding(Expression expr, Scope scope, [this._converter]) |
102 : _expr = observe(expr, scope), | 101 : _expr = observe(expr, scope), |
103 _scope = scope { | 102 _scope = scope { |
104 _expr.onUpdate.listen(_setValue).onError((e) { | 103 _expr.onUpdate.listen(_setValue).onError((e) { |
(...skipping 13 matching lines...) Expand all Loading... |
118 // variable added to the scope | 117 // variable added to the scope |
119 _value = v.iterable.map((i) { | 118 _value = v.iterable.map((i) { |
120 var vars = new Map(); | 119 var vars = new Map(); |
121 vars[v.identifier] = i; | 120 vars[v.identifier] = i; |
122 Scope childScope = new Scope(parent: _scope, variables: vars); | 121 Scope childScope = new Scope(parent: _scope, variables: vars); |
123 return childScope; | 122 return childScope; |
124 }).toList(growable: false); | 123 }).toList(growable: false); |
125 } else { | 124 } else { |
126 _value = (_converter == null) ? v : _converter(v); | 125 _value = (_converter == null) ? v : _converter(v); |
127 } | 126 } |
128 notifyChange(new PropertyChangeRecord(_VALUE)); | 127 notifyChange(new PropertyChangeRecord(#value)); |
129 } | 128 } |
130 | 129 |
131 get value => _value; | 130 get value => _value; |
132 | 131 |
133 set value(v) { | 132 set value(v) { |
134 try { | 133 try { |
135 assign(_expr, v, _scope); | 134 assign(_expr, v, _scope); |
136 notifyChange(new PropertyChangeRecord(_VALUE)); | 135 notifyChange(new PropertyChangeRecord(#value)); |
137 } on EvalException catch (e) { | 136 } on EvalException catch (e) { |
138 // silently swallow binding errors | 137 // silently swallow binding errors |
139 } | 138 } |
140 } | 139 } |
141 | 140 |
142 getValueWorkaround(key) { | 141 getValueWorkaround(key) { |
143 if (key == _VALUE) return value; | 142 if (key == #value) return value; |
144 } | 143 } |
145 | 144 |
146 setValueWorkaround(key, v) { | 145 setValueWorkaround(key, v) { |
147 if (key == _VALUE) value = v; | 146 if (key == #value) value = v; |
148 } | 147 } |
149 } | 148 } |
OLD | NEW |