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 part of template_binding; | 5 part of template_binding; |
6 | 6 |
7 // This code is a port of what was formerly known as Model-Driven-Views, now | 7 // This code is a port of what was formerly known as Model-Driven-Views, now |
8 // located at: | 8 // located at: |
9 // https://github.com/polymer/TemplateBinding | 9 // https://github.com/polymer/TemplateBinding |
10 // https://github.com/polymer/NodeBind | 10 // https://github.com/polymer/NodeBind |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 } | 250 } |
251 | 251 |
252 void _updateDependencies(_TemplateBindingMap directives, model) { | 252 void _updateDependencies(_TemplateBindingMap directives, model) { |
253 _closeDependencies(); | 253 _closeDependencies(); |
254 | 254 |
255 final template = _templateElement; | 255 final template = _templateElement; |
256 | 256 |
257 _hasIf = directives._if != null; | 257 _hasIf = directives._if != null; |
258 _hasRepeat = directives._repeat != null; | 258 _hasRepeat = directives._repeat != null; |
259 | 259 |
260 var ifValue = true; | |
260 if (_hasIf) { | 261 if (_hasIf) { |
261 _ifOneTime = directives._if.onlyOneTime; | 262 _ifOneTime = directives._if.onlyOneTime; |
262 _ifValue = _processBinding('if', directives._if, template, model); | 263 _ifValue = _processBinding('if', directives._if, template, model); |
264 ifValue = _ifValue; | |
263 | 265 |
264 // oneTime if & predicate is false. nothing else to do. | 266 // oneTime if & predicate is false. nothing else to do. |
265 if (_ifOneTime) { | 267 if (_ifOneTime && !_toBoolean(ifValue)) { |
266 if (!_toBoolean(_ifValue)) { | 268 _valueChanged(null); |
267 _updateIteratedValue(null); | 269 return; |
268 return; | 270 } |
269 } | 271 |
270 } else { | 272 if (!_ifOneTime) { |
271 (_ifValue as Bindable).open(_updateIteratedValue); | 273 ifValue = (ifValue as Bindable).open(_updateIfValue); |
272 } | 274 } |
273 } | 275 } |
274 | 276 |
275 if (_hasRepeat) { | 277 if (_hasRepeat) { |
276 _oneTime = directives._repeat.onlyOneTime; | 278 _oneTime = directives._repeat.onlyOneTime; |
277 _value = _processBinding('repeat', directives._repeat, template, model); | 279 _value = _processBinding('repeat', directives._repeat, template, model); |
278 } else { | 280 } else { |
279 _oneTime = directives._bind.onlyOneTime; | 281 _oneTime = directives._bind.onlyOneTime; |
280 _value = _processBinding('bind', directives._bind, template, model); | 282 _value = _processBinding('bind', directives._bind, template, model); |
281 } | 283 } |
282 | 284 |
283 if (!_oneTime) _value.open(_updateIteratedValue); | 285 var value = _value; |
286 if (!_oneTime) { | |
287 value = _value.open(_updateIteratedValue); | |
288 } | |
284 | 289 |
285 _updateIteratedValue(null); | 290 if (!_toBoolean(ifValue)) { |
291 _valueChanged(null); | |
292 return; | |
293 } | |
294 | |
295 _updateValue(value); | |
286 } | 296 } |
287 | 297 |
288 void _updateIteratedValue(_) { | 298 /** |
Siggi Cherem (dart-lang)
2014/08/13 23:00:26
nit: use /// instead of /** */
jakemac
2014/08/14 18:00:49
Done.
| |
299 * Gets the updated value of the bind/repeat. This can potentially call | |
300 * user code (if a bindingDelegate is set up) so we try to avoid it if we | |
301 * already have the value in hand (from Observer.open). | |
302 */ | |
303 Object getUpdatedValue() { | |
Siggi Cherem (dart-lang)
2014/08/13 23:00:26
I wonder if this could be private too, since it's
jakemac
2014/08/14 18:00:49
Done.
| |
304 var value = _value; | |
305 // Dart Note: Changed value.discardChanges() to value.value since | |
306 // discardChanges is a private function in the dart version. The value | |
307 // getter just calls this private function so it has the same effect. | |
Siggi Cherem (dart-lang)
2014/08/13 23:00:26
yes - note that this is a Dart note in observe (we
jakemac
2014/08/14 18:00:49
Done.
| |
308 if (!_toBoolean(_oneTime)) value = value.value; | |
309 return value; | |
310 } | |
311 | |
312 void _updateIfValue(ifValue) { | |
313 if (!_toBoolean(ifValue)) { | |
314 _valueChanged(null); | |
315 return; | |
316 } | |
317 _updateValue(getUpdatedValue()); | |
318 } | |
319 | |
320 void _updateIteratedValue(value) { | |
289 if (_hasIf) { | 321 if (_hasIf) { |
290 var ifValue = _ifValue; | 322 var ifValue = _ifValue; |
291 if (!_ifOneTime) ifValue = (ifValue as Bindable).value; | 323 if (!_ifOneTime) ifValue = (ifValue as Bindable).value; |
292 if (!_toBoolean(ifValue)) { | 324 if (!_toBoolean(ifValue)) { |
293 _valueChanged([]); | 325 _valueChanged([]); |
294 return; | 326 return; |
295 } | 327 } |
296 } | 328 } |
297 | 329 |
298 var value = _value; | 330 _updateValue(value); |
299 if (!_oneTime) value = (value as Bindable).value; | 331 } |
332 | |
333 void _updateValue(Object value) { | |
300 if (!_hasRepeat) value = [value]; | 334 if (!_hasRepeat) value = [value]; |
301 _valueChanged(value); | 335 _valueChanged(value); |
302 } | 336 } |
303 | 337 |
304 void _valueChanged(Object value) { | 338 void _valueChanged(Object value) { |
305 if (value is! List) { | 339 if (value is! List) { |
306 if (value is Iterable) { | 340 if (value is Iterable) { |
307 // Dart note: we support Iterable by calling toList. | 341 // Dart note: we support Iterable by calling toList. |
308 // But we need to be careful to observe the original iterator if it | 342 // But we need to be careful to observe the original iterator if it |
309 // supports that. | 343 // supports that. |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
517 _closed = true; | 551 _closed = true; |
518 } | 552 } |
519 } | 553 } |
520 | 554 |
521 // Dart note: the JavaScript version just puts an expando on the array. | 555 // Dart note: the JavaScript version just puts an expando on the array. |
522 class _BoundNodes { | 556 class _BoundNodes { |
523 final List<Node> nodes; | 557 final List<Node> nodes; |
524 final List<Bindable> instanceBindings; | 558 final List<Bindable> instanceBindings; |
525 _BoundNodes(this.nodes, this.instanceBindings); | 559 _BoundNodes(this.nodes, this.instanceBindings); |
526 } | 560 } |
OLD | NEW |