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

Side by Side Diff: lib/src/info.dart

Issue 11416259: fix #136, support watch exprs and two way bindings for component fields (Closed) Base URL: https://github.com/dart-lang/dart-web-components.git@master
Patch Set: Created 8 years 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
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 /** 5 /**
6 * Datatypes holding information extracted by the analyzer and used by later 6 * Datatypes holding information extracted by the analyzer and used by later
7 * phases of the compiler. 7 * phases of the compiler.
8 */ 8 */
9 library info; 9 library info;
10 10
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 } 287 }
288 288
289 /** 289 /**
290 * True if [tagName] was defined by more than one component. If this happened 290 * True if [tagName] was defined by more than one component. If this happened
291 * we will skip over the component. 291 * we will skip over the component.
292 */ 292 */
293 bool hasConflict = false; 293 bool hasConflict = false;
294 294
295 ComponentInfo(this.element, this.declaringFile, this.tagName, this.extendsTag, 295 ComponentInfo(this.element, this.declaringFile, this.tagName, this.extendsTag,
296 this.constructor, this.template); 296 this.constructor, this.template);
297
298 /**
299 * Gets the HTML tag extended by the base of the component hierarchy.
300 * Equivalent to [extendsTag] if this inherits directly from an HTML element,
301 * in other words, if [extendsComponent] is null.
302 */
303 String get baseExtendsTag {
304 var comp = this;
305 while (true) {
306 var e = comp.extendsComponent;
307 if (e == null) {
308 return comp.extendsTag;
309 }
310 comp = e;
311 }
Siggi Cherem (dart-lang) 2012/11/29 18:06:57 how about doing this recursively? String get base
Jennifer Messerly 2012/11/30 03:21:41 Done.
312 }
297 } 313 }
298 314
299 /** Base tree visitor for the Analyzer infos. */ 315 /** Base tree visitor for the Analyzer infos. */
300 class InfoVisitor { 316 class InfoVisitor {
301 visit(info) { 317 visit(info) {
302 if (info == null) return; 318 if (info == null) return;
303 if (info is TemplateInfo) { 319 if (info is TemplateInfo) {
304 return visitTemplateInfo(info); 320 return visitTemplateInfo(info);
305 } else if (info is ElementInfo) { 321 } else if (info is ElementInfo) {
306 return visitElementInfo(info); 322 return visitElementInfo(info);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 // preserve the order of the input, but we'd need to be careful about our tree 412 // preserve the order of the input, but we'd need to be careful about our tree
397 // traversal order. 413 // traversal order.
398 /** Collected information for attributes, if any. */ 414 /** Collected information for attributes, if any. */
399 final Map<String, AttributeInfo> attributes = 415 final Map<String, AttributeInfo> attributes =
400 new SplayTreeMap<String, AttributeInfo>(); 416 new SplayTreeMap<String, AttributeInfo>();
401 417
402 /** Collected information for UI events on the corresponding element. */ 418 /** Collected information for UI events on the corresponding element. */
403 final Map<String, List<EventInfo>> events = 419 final Map<String, List<EventInfo>> events =
404 new SplayTreeMap<String, List<EventInfo>>(); 420 new SplayTreeMap<String, List<EventInfo>>();
405 421
406 /** Collected information about `data-value="name:value"` expressions. */ 422 /**
423 * Collected information about `data-value="name:value"` expressions.
424 * Note: this feature is deprecated and should be removed after grace period.
425 */
407 final Map<String, String> values = new SplayTreeMap<String, String>(); 426 final Map<String, String> values = new SplayTreeMap<String, String>();
408 427
409 // TODO(jmesserly): we could keep this local to the analyzer. 428 // TODO(jmesserly): we could keep this local to the analyzer.
410 /** Attribute names to remove in cleanup phase. */ 429 /** Attribute names to remove in cleanup phase. */
411 final Set<String> removeAttributes = new Set<String>(); 430 final Set<String> removeAttributes = new Set<String>();
412 431
413 /** Whether the template element has `iterate="... in ...". */ 432 /** Whether the template element has `iterate="... in ...". */
414 bool get hasIterate => false; 433 bool get hasIterate => false;
415 434
416 /** Whether the template element has an `if="..."` conditional. */ 435 /** Whether the template element has an `if="..."` conditional. */
417 bool get hasIfCondition => false; 436 bool get hasIfCondition => false;
418 437
419 bool get isTemplateElement => false; 438 bool get isTemplateElement => false;
420 439
440 /**
441 * For a builtin HTML element this returns the [node.tagName], otherwise it
442 * returns [component.baseExtendsTag]. This is useful when looking up which
443 * DOM property this element supports.
444 *
445 * **Note:** this returns node.tagName right now, until we fix issue #82.
446 */
447 String get baseTagName {
448 return node.tagName;
449 // TODO(jmesserly): turn this on when issue #82 is fixed.
Jennifer Messerly 2012/11/29 05:34:35 I realized if we have "input" two way bindings but
450 //return component != null ? component.baseExtendsTag : node.tagName;
451 }
452
421 ElementInfo(Element node, ElementInfo parent) : super(node, parent); 453 ElementInfo(Element node, ElementInfo parent) : super(node, parent);
422 454
423 String toString() => '#<ElementInfo ' 455 String toString() => '#<ElementInfo '
424 'identifier: $identifier, ' 456 'identifier: $identifier, '
425 'childrenCreatedInCode: $childrenCreatedInCode, ' 457 'childrenCreatedInCode: $childrenCreatedInCode, '
426 'component: $component, ' 458 'component: $component, '
427 'hasIterate: $hasIterate, ' 459 'hasIterate: $hasIterate, '
428 'hasIfCondition: $hasIfCondition, ' 460 'hasIfCondition: $hasIfCondition, '
429 'hasDataBinding: $hasDataBinding, ' 461 'hasDataBinding: $hasDataBinding, '
430 'hasQuery: $hasQuery, ' 462 'hasQuery: $hasQuery, '
(...skipping 27 matching lines...) Expand all
458 490
459 /** 491 /**
460 * Whether this is a 'data-style' attribute. 492 * Whether this is a 'data-style' attribute.
461 */ 493 */
462 final bool isStyle; 494 final bool isStyle;
463 495
464 /** All bound values that would be monitored for changes. */ 496 /** All bound values that would be monitored for changes. */
465 final List<String> bindings; 497 final List<String> bindings;
466 498
467 /** 499 /**
500 * A two-way binding that needs a watcher. This is used in cases where we
501 * don't have an event.
502 */
503 final bool customTwoWayBinding;
504
505 /**
468 * For a text attribute this contains the text content. This is used by most 506 * For a text attribute this contains the text content. This is used by most
469 * attributes and represents the value that will be assigned to them. If this 507 * attributes and represents the value that will be assigned to them. If this
470 * has been assigned then [isText] will be true. 508 * has been assigned then [isText] will be true.
471 * 509 *
472 * The entries in this list correspond to the entries in [bindings], and this 510 * The entries in this list correspond to the entries in [bindings], and this
473 * will always have one more item than bindings. For example: 511 * will always have one more item than bindings. For example:
474 * 512 *
475 * href="t0 {{b1}} t1 {{b2}} t2" 513 * href="t0 {{b1}} t1 {{b2}} t2"
476 * 514 *
477 * Here textContent would be `["t0 ", " t1 ", " t2"]` and bindings would be 515 * Here textContent would be `["t0 ", " t1 ", " t2"]` and bindings would be
478 * `["b1", "b2"]`. 516 * `["b1", "b2"]`.
479 */ 517 */
480 final List<String> textContent; 518 final List<String> textContent;
481 519
482 AttributeInfo(this.bindings, {this.isStyle: false, this.isClass: false, 520 AttributeInfo(this.bindings, {this.isStyle: false, this.isClass: false,
483 this.textContent}) { 521 this.textContent, this.customTwoWayBinding: false}) {
484 522
485 assert(isText || isClass || bindings.length == 1); 523 assert(isText || isClass || bindings.length == 1);
486 assert(bindings.length > 0); 524 assert(bindings.length > 0);
487 assert(!isText || textContent.length == bindings.length + 1); 525 assert(!isText || textContent.length == bindings.length + 1);
488 assert((isText ? 1 : 0) + (isClass ? 1 : 0) + (isStyle ? 1 : 0) <= 1); 526 assert((isText ? 1 : 0) + (isClass ? 1 : 0) + (isStyle ? 1 : 0) <= 1);
489 } 527 }
490 528
491 /** 529 /**
492 * A value that will be monitored for changes. All attributes have a single 530 * A value that will be monitored for changes. All attributes have a single
493 * bound value unless [isClass] or [isText] is true. 531 * bound value unless [isClass] or [isText] is true.
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 } 669 }
632 670
633 visitChildren(ElementInfo info) { 671 visitChildren(ElementInfo info) {
634 for (var child in info.children) { 672 for (var child in info.children) {
635 var result = visit(child); 673 var result = visit(child);
636 if (result != null) return result; 674 if (result != null) return result;
637 } 675 }
638 return null; 676 return null;
639 } 677 }
640 } 678 }
OLDNEW
« lib/src/emitters.dart ('K') | « lib/src/emitters.dart ('k') | lib/web_components.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698