Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: lib/templating.dart

Issue 13592003: add support for template repeat (Closed) Base URL: https://github.com/dart-lang/web-ui.git@master
Patch Set: feedback Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/src/info.dart ('k') | test/analyzer_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 /** Bind [exp] to [setter] while this template is visible. */ 448 /** Bind [exp] to [setter] while this template is visible. */
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 /**
459 void loop(Node template, exp, iterSetup, {isTemplateElement: true}) { 459 * Watch [exp] and render a loop while this template is visible.
460 children.add( 460 * This is used by all "iterate" and "repeat" attributes, except those that
461 isTemplateElement ? new LoopTemplate(template, exp, iterSetup) 461 * require [loopIterateAttr].
462 : new LoopTemplateInAttribute(template, exp, iterSetup)); 462 */
463 void loop(Node template, exp, iterSetup) {
464 children.add(new LoopTemplate(template, exp, iterSetup));
465 }
466
467 /**
468 * Watch [exp] and render a loop while this template is visible.
469 * This is used by:
470 * <td template iterate="x in list">
471 */
472 void loopIterateAttr(Node template, exp, iterSetup) {
473 children.add(new LoopTemplateInAttribute(template, exp, iterSetup));
463 } 474 }
464 475
465 /** Bind the lifecycle of the component with this template's lifecycle. */ 476 /** Bind the lifecycle of the component with this template's lifecycle. */
466 void component(WebComponent component) { 477 void component(WebComponent component) {
467 children.add(new ComponentItem(component)); 478 children.add(new ComponentItem(component));
468 } 479 }
469 480
470 // TODO(sigmund): consider changing emitter to accept compact arguments here 481 // TODO(sigmund): consider changing emitter to accept compact arguments here
471 // for instance: 482 // for instance:
472 // __t.add(string) => add(new Text(string)) 483 // __t.add(string) => add(new Text(string))
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 void remove() { 605 void remove() {
595 super.remove(); 606 super.remove();
596 stopper(); 607 stopper();
597 stopper = null; 608 stopper = null;
598 } 609 }
599 } 610 }
600 611
601 /** Function to set up the contents of a loop template. */ 612 /** Function to set up the contents of a loop template. */
602 typedef void LoopIterationSetup(loopVariable, Template template); 613 typedef void LoopIterationSetup(loopVariable, Template template);
603 614
604 /** A template loop of the form `<template iterate="x in list ">`. */ 615 /**
616 * A template loop of the form `<template iterate="x in list ">` or
617 * `<td template repeat="x in list">`.
618 */
605 class LoopTemplate extends PlaceholderTemplate { 619 class LoopTemplate extends PlaceholderTemplate {
606 final LoopIterationSetup iterSetup; 620 final LoopIterationSetup iterSetup;
607 621
608 LoopTemplate(Node reference, exp, this.iterSetup) : super(reference, exp); 622 LoopTemplate(Node reference, exp, this.iterSetup) : super(reference, exp);
609 623
610 void insert() { 624 void insert() {
611 stopper = watchAndInvoke(exp, (e) { 625 stopper = watchAndInvoke(exp, (e) {
612 super.remove(); 626 super.remove();
613 for (var x in e.newValue) { 627 for (var x in e.newValue) {
614 iterSetup(x, this); 628 iterSetup(x, this);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 node.nodes.clear(); 670 node.nodes.clear();
657 nodes.clear(); 671 nodes.clear();
658 } 672 }
659 673
660 void remove() { 674 void remove() {
661 _removeInternal(); 675 _removeInternal();
662 stopper(); 676 stopper();
663 stopper = null; 677 stopper = null;
664 } 678 }
665 } 679 }
OLDNEW
« no previous file with comments | « lib/src/info.dart ('k') | test/analyzer_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698