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 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 | 423 |
424 var model = _iteratedValue[addIndex]; | 424 var model = _iteratedValue[addIndex]; |
425 var fragment = null; | 425 var fragment = null; |
426 var instance = instanceCache.remove(model); | 426 var instance = instanceCache.remove(model); |
427 List instanceBindings; | 427 List instanceBindings; |
428 List instanceNodes = null; | 428 List instanceNodes = null; |
429 if (instance != null && instance.nodes.isNotEmpty) { | 429 if (instance != null && instance.nodes.isNotEmpty) { |
430 instanceBindings = instance.instanceBindings; | 430 instanceBindings = instance.instanceBindings; |
431 instanceNodes = instance.nodes; | 431 instanceNodes = instance.nodes; |
432 } else { | 432 } else { |
433 instanceBindings = []; | 433 try { |
434 if (_instanceModelFn != null) { | 434 instanceBindings = []; |
435 model = _instanceModelFn(model); | 435 if (_instanceModelFn != null) { |
436 } | 436 model = _instanceModelFn(model); |
437 if (model != null) { | 437 } |
438 fragment = _templateExt.createInstance(model, delegate, | 438 if (model != null) { |
439 instanceBindings); | 439 fragment = _templateExt.createInstance(model, delegate, |
| 440 instanceBindings); |
| 441 } |
| 442 } catch (e, s) { |
| 443 // Dart note: we propagate errors asynchronously here to avoid |
| 444 // disrupting the rendering flow. This is different than in the JS |
| 445 // implementation but it should probably be fixed there too. Dart |
| 446 // hits this case more because non-existing properties in |
| 447 // [PropertyPath] are treated as errors, while JS treats them as |
| 448 // null/undefined. |
| 449 new Completer().completeError(e, s); |
440 } | 450 } |
441 } | 451 } |
442 | 452 |
443 _insertInstanceAt(addIndex, fragment, instanceNodes, instanceBindings); | 453 _insertInstanceAt(addIndex, fragment, instanceNodes, instanceBindings); |
444 } | 454 } |
445 } | 455 } |
446 | 456 |
447 for (var instance in instanceCache.values) { | 457 for (var instance in instanceCache.values) { |
448 _closeInstanceBindings(instance.instanceBindings); | 458 _closeInstanceBindings(instance.instanceBindings); |
449 } | 459 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 _closed = true; | 530 _closed = true; |
521 } | 531 } |
522 } | 532 } |
523 | 533 |
524 // Dart note: the JavaScript version just puts an expando on the array. | 534 // Dart note: the JavaScript version just puts an expando on the array. |
525 class _BoundNodes { | 535 class _BoundNodes { |
526 final List<Node> nodes; | 536 final List<Node> nodes; |
527 final List<Bindable> instanceBindings; | 537 final List<Bindable> instanceBindings; |
528 _BoundNodes(this.nodes, this.instanceBindings); | 538 _BoundNodes(this.nodes, this.instanceBindings); |
529 } | 539 } |
OLD | NEW |