Chromium Code Reviews| 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 html; | 5 part of html; |
| 6 | 6 |
| 7 // This code is a port of Model-Driven-Views: | 7 // This code is a port of Model-Driven-Views: |
| 8 // https://github.com/toolkitchen/mdv | 8 // https://github.com/toolkitchen/mdv |
| 9 // The code mostly comes from src/template_element.js | 9 // The code mostly comes from src/template_element.js |
| 10 | 10 |
| (...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 516 var value = values[i]; | 516 var value = values[i]; |
| 517 if (value != null) { | 517 if (value != null) { |
| 518 newValue.write(value); | 518 newValue.write(value); |
| 519 } | 519 } |
| 520 } | 520 } |
| 521 } | 521 } |
| 522 | 522 |
| 523 return newValue.toString(); | 523 return newValue.toString(); |
| 524 }; | 524 }; |
| 525 | 525 |
| 526 node.bind(name, replacementBinding, 'value'); | 526 _nodeOrCustom(node).bind(name, replacementBinding, 'value'); |
| 527 } | 527 } |
| 528 | 528 |
| 529 void _bindOrDelegate(node, name, model, String path, | 529 void _bindOrDelegate(node, name, model, String path, |
| 530 CustomBindingSyntax syntax) { | 530 CustomBindingSyntax syntax) { |
| 531 | 531 |
| 532 if (syntax != null) { | 532 if (syntax != null) { |
| 533 var delegateBinding = syntax.getBinding(model, path, name, node); | 533 var delegateBinding = syntax.getBinding(model, path, name, node); |
| 534 if (delegateBinding != null) { | 534 if (delegateBinding != null) { |
| 535 model = delegateBinding; | 535 model = delegateBinding; |
| 536 path = 'value'; | 536 path = 'value'; |
| 537 } | 537 } |
| 538 } | 538 } |
| 539 | 539 |
| 540 node.bind(name, model, path); | 540 _nodeOrCustom(node).bind(name, model, path); |
| 541 } | 541 } |
| 542 | 542 |
| 543 /** | |
| 544 * Gets the [node]'s custom [Element.xtag] if present, otherwise returns | |
| 545 * the node. This is used so nodes can override [Node.bind], [Node.unbind], | |
| 546 * and [Node.unbindAll] like | |
| 547 */ | |
| 548 // TODO(jmesserly): remove this when we can extend Element for real. | |
| 549 _nodeOrCustom(node) => node is Element ? node.xtag : node; | |
|
Siggi Cherem (dart-lang)
2013/05/13 16:42:13
interesting, what about a custom element that exte
Jennifer Messerly
2013/05/13 19:42:41
Not sure I understand...
What this does is try an
Jennifer Messerly
2013/05/13 19:43:45
oops, "skill the custom impl" should be "skip the
| |
| 550 | |
| 543 class _BindingToken { | 551 class _BindingToken { |
| 544 final String value; | 552 final String value; |
| 545 final bool isBinding; | 553 final bool isBinding; |
| 546 | 554 |
| 547 _BindingToken(this.value, {this.isBinding: false}); | 555 _BindingToken(this.value, {this.isBinding: false}); |
| 548 | 556 |
| 549 bool get isText => !isBinding; | 557 bool get isText => !isBinding; |
| 550 } | 558 } |
| 551 | 559 |
| 552 List<_BindingToken> _parseMustacheTokens(String s) { | 560 List<_BindingToken> _parseMustacheTokens(String s) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 592 fragment.$dom_firstChild, fragment.$dom_lastChild, model); | 600 fragment.$dom_firstChild, fragment.$dom_lastChild, model); |
| 593 | 601 |
| 594 var node = instanceRecord.firstNode; | 602 var node = instanceRecord.firstNode; |
| 595 while (node != null) { | 603 while (node != null) { |
| 596 node._templateInstance = instanceRecord; | 604 node._templateInstance = instanceRecord; |
| 597 node = node.nextNode; | 605 node = node.nextNode; |
| 598 } | 606 } |
| 599 } | 607 } |
| 600 | 608 |
| 601 void _removeAllBindingsRecursively(Node node) { | 609 void _removeAllBindingsRecursively(Node node) { |
| 602 node.unbindAll(); | 610 _nodeOrCustom(node).unbindAll(); |
| 603 for (var c = node.$dom_firstChild; c != null; c = c.nextNode) { | 611 for (var c = node.$dom_firstChild; c != null; c = c.nextNode) { |
| 604 _removeAllBindingsRecursively(c); | 612 _removeAllBindingsRecursively(c); |
| 605 } | 613 } |
| 606 } | 614 } |
| 607 | 615 |
| 608 void _removeTemplateChild(Node parent, Node child) { | 616 void _removeTemplateChild(Node parent, Node child) { |
| 609 child._templateInstance = null; | 617 child._templateInstance = null; |
| 610 if (child is Element && child.isTemplate) { | 618 if (child is Element && child.isTemplate) { |
| 611 // Make sure we stop observing when we remove an element. | 619 // Make sure we stop observing when we remove an element. |
| 612 var templateIterator = child._templateIterator; | 620 var templateIterator = child._templateIterator; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 767 _sub.cancel(); | 775 _sub.cancel(); |
| 768 _sub = null; | 776 _sub = null; |
| 769 } | 777 } |
| 770 | 778 |
| 771 void abandon() { | 779 void abandon() { |
| 772 unobserve(); | 780 unobserve(); |
| 773 _valueBinding.cancel(); | 781 _valueBinding.cancel(); |
| 774 inputs.dispose(); | 782 inputs.dispose(); |
| 775 } | 783 } |
| 776 } | 784 } |
| OLD | NEW |