Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /** Common utility functions used by code generated by the dwc compiler. */ | 5 /** Common utility functions used by code generated by the dwc compiler. */ |
| 6 library templating; | 6 library templating; |
| 7 | 7 |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:collection'; | 9 import 'dart:collection'; |
| 10 import 'dart:html'; | 10 import 'dart:html'; |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 449 void oneWayBind(exp, setter, isFinal, [isUrl = false]) { | 449 void oneWayBind(exp, setter, isFinal, [isUrl = false]) { |
| 450 children.add(new DomPropertyBinding(exp, setter, isUrl, isFinal)); | 450 children.add(new DomPropertyBinding(exp, setter, isUrl, isFinal)); |
| 451 } | 451 } |
| 452 | 452 |
| 453 /** Watch [exp] and render a conditional while this template is visible. */ | 453 /** Watch [exp] and render a conditional while this template is visible. */ |
| 454 void conditional(Node template, exp, bodySetup) { | 454 void conditional(Node template, exp, bodySetup) { |
| 455 children.add(new ConditionalTemplate(template, exp, bodySetup)); | 455 children.add(new ConditionalTemplate(template, exp, bodySetup)); |
| 456 } | 456 } |
| 457 | 457 |
| 458 /** Watch [exp] and render a loop while this template is visible. */ | 458 /** Watch [exp] and render a loop while this template is visible. */ |
| 459 void loop(Node template, exp, iterSetup, {isTemplateElement: true}) { | 459 void loop(Node template, exp, iterSetup) { |
| 460 children.add( | 460 children.add(new LoopTemplate(template, exp, iterSetup)); |
| 461 isTemplateElement ? new LoopTemplate(template, exp, iterSetup) | 461 } |
| 462 : new LoopTemplateInAttribute(template, exp, iterSetup)); | 462 |
| 463 /** | |
| 464 * Watch [exp] and render a loop while this template is visible. | |
| 465 * NOTE: this form is deprecated. Please use [loop] instead. | |
| 466 */ | |
| 467 void loopIterateAttr(Node template, exp, iterSetup) { | |
|
Siggi Cherem (dart-lang)
2013/04/05 20:09:24
should we add @deprecated?
Jennifer Messerly
2013/04/05 20:34:36
:) yeah I had the same thought. My fear was that o
| |
| 468 children.add(new LoopTemplateInAttribute(template, exp, iterSetup)); | |
| 463 } | 469 } |
| 464 | 470 |
| 465 /** Bind the lifecycle of the component with this template's lifecycle. */ | 471 /** Bind the lifecycle of the component with this template's lifecycle. */ |
| 466 void component(WebComponent component) { | 472 void component(WebComponent component) { |
| 467 children.add(new ComponentItem(component)); | 473 children.add(new ComponentItem(component)); |
| 468 } | 474 } |
| 469 | 475 |
| 470 // TODO(sigmund): consider changing emitter to accept compact arguments here | 476 // TODO(sigmund): consider changing emitter to accept compact arguments here |
| 471 // for instance: | 477 // for instance: |
| 472 // __t.add(string) => add(new Text(string)) | 478 // __t.add(string) => add(new Text(string)) |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 594 void remove() { | 600 void remove() { |
| 595 super.remove(); | 601 super.remove(); |
| 596 stopper(); | 602 stopper(); |
| 597 stopper = null; | 603 stopper = null; |
| 598 } | 604 } |
| 599 } | 605 } |
| 600 | 606 |
| 601 /** Function to set up the contents of a loop template. */ | 607 /** Function to set up the contents of a loop template. */ |
| 602 typedef void LoopIterationSetup(loopVariable, Template template); | 608 typedef void LoopIterationSetup(loopVariable, Template template); |
| 603 | 609 |
| 604 /** A template loop of the form `<template iterate="x in list ">`. */ | 610 /** |
| 611 * A template loop of the form `<template iterate="x in list ">` or | |
| 612 * `<td template repeat="x in list">`. | |
| 613 */ | |
| 605 class LoopTemplate extends PlaceholderTemplate { | 614 class LoopTemplate extends PlaceholderTemplate { |
| 606 final LoopIterationSetup iterSetup; | 615 final LoopIterationSetup iterSetup; |
| 607 | 616 |
| 608 LoopTemplate(Node reference, exp, this.iterSetup) : super(reference, exp); | 617 LoopTemplate(Node reference, exp, this.iterSetup) : super(reference, exp); |
| 609 | 618 |
| 610 void insert() { | 619 void insert() { |
| 611 stopper = watchAndInvoke(exp, (e) { | 620 stopper = watchAndInvoke(exp, (e) { |
| 612 super.remove(); | 621 super.remove(); |
| 613 for (var x in e.newValue) { | 622 for (var x in e.newValue) { |
| 614 iterSetup(x, this); | 623 iterSetup(x, this); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 656 node.nodes.clear(); | 665 node.nodes.clear(); |
| 657 nodes.clear(); | 666 nodes.clear(); |
| 658 } | 667 } |
| 659 | 668 |
| 660 void remove() { | 669 void remove() { |
| 661 _removeInternal(); | 670 _removeInternal(); |
| 662 stopper(); | 671 stopper(); |
| 663 stopper = null; | 672 stopper = null; |
| 664 } | 673 } |
| 665 } | 674 } |
| OLD | NEW |