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

Side by Side Diff: pkg/polymer/lib/src/instance.dart

Issue 25740006: port polymer data binding tests (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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 | Annotate | Revision Log
OLDNEW
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 polymer; 5 part of polymer;
6 6
7 /** 7 /**
8 * Use this annotation to publish a field as an attribute. For example: 8 * Use this annotation to publish a field as an attribute. For example:
9 * 9 *
10 * class MyPlaybackElement extends PolymerElement { 10 * class MyPlaybackElement extends PolymerElement {
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 _elementObservers = new Map<String, StreamSubscription>(); 502 _elementObservers = new Map<String, StreamSubscription>();
503 } 503 }
504 _elementObservers[name] = sub; 504 _elementObservers[name] = sub;
505 } 505 }
506 506
507 void observeAttributeProperty(String name) { 507 void observeAttributeProperty(String name) {
508 _observe(name, (value, old) => reflectPropertyToAttribute(name)); 508 _observe(name, (value, old) => reflectPropertyToAttribute(name));
509 } 509 }
510 510
511 void observeProperty(String name, Symbol method) { 511 void observeProperty(String name, Symbol method) {
512 final self = reflect(this); 512 _observe(name, (value, old) => _invoke(method, [old]));
513 _observe(name, (value, old) => self.invoke(method, [old]));
514 } 513 }
515 514
516 void observeBoth(String name, Symbol methodName) { 515 void observeBoth(String name, Symbol methodName) {
517 final self = reflect(this);
518 _observe(name, (value, old) { 516 _observe(name, (value, old) {
519 reflectPropertyToAttribute(name); 517 reflectPropertyToAttribute(name);
520 self.invoke(methodName, [old]); 518 _invoke(methodName, [old]);
521 }); 519 });
522 } 520 }
523 521
524 void unbindProperty(String name) { 522 void unbindProperty(String name) {
525 if (_elementObservers == null) return; 523 if (_elementObservers == null) return;
526 var sub = _elementObservers.remove(name); 524 var sub = _elementObservers.remove(name);
527 if (sub != null) sub.cancel(); 525 if (sub != null) sub.cancel();
528 } 526 }
529 527
530 void unbindAllProperties() { 528 void unbindAllProperties() {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 637
640 String findEventDelegate(Event event) => 638 String findEventDelegate(Event event) =>
641 _declaration._eventDelegates[_eventNameFromType(event.type)]; 639 _declaration._eventDelegates[_eventNameFromType(event.type)];
642 640
643 /** Call [methodName] method on [this] with [args], if the method exists. */ 641 /** Call [methodName] method on [this] with [args], if the method exists. */
644 // TODO(jmesserly): I removed the [node] argument as it was unused. Reconcile. 642 // TODO(jmesserly): I removed the [node] argument as it was unused. Reconcile.
645 void dispatchMethod(Symbol methodName, List args) { 643 void dispatchMethod(Symbol methodName, List args) {
646 bool log = _eventsLog.isLoggable(Level.INFO); 644 bool log = _eventsLog.isLoggable(Level.INFO);
647 if (log) _eventsLog.info('>>> [$localName]: dispatch $methodName'); 645 if (log) _eventsLog.info('>>> [$localName]: dispatch $methodName');
648 646
649 // TODO(sigmund): consider making event listeners list all arguments 647 _invoke(methodName, args);
650 // explicitly. Unless VM mirrors are optimized first, this reflectClass call 648
651 // will be expensive once custom elements extend directly from Element (see 649 if (log) _eventsLog.info('<<< [$localName]: dispatch $methodName');
652 // dartbug.com/11108). 650
651 // TODO(jmesserly): workaround for HTML events not supporting zones.
652 performMicrotaskCheckpoint();
653 }
654
655 InstanceMirror _invoke(Symbol methodName, List args) {
656 // TODO(sigmund): consider making callbacks list all arguments
657 // explicitly. Unless VM mirrors are optimized first, this will be expensive
658 // once custom elements extend directly from Element (see issue 11108).
653 var self = reflect(this); 659 var self = reflect(this);
654 var method = self.type.methods[methodName]; 660 var method = self.type.methods[methodName];
655 if (method != null) { 661 if (method != null) {
656 // This will either truncate the argument list or extend it with extra 662 // This will either truncate the argument list or extend it with extra
657 // null arguments, so it will match the signature. 663 // null arguments, so it will match the signature.
658 // TODO(sigmund): consider accepting optional arguments when we can tell 664 // TODO(sigmund): consider accepting optional arguments when we can tell
659 // them appart from named arguments (see http://dartbug.com/11334) 665 // them appart from named arguments (see http://dartbug.com/11334)
660 args.length = method.parameters.where((p) => !p.isOptional).length; 666 args.length = method.parameters.where((p) => !p.isOptional).length;
661 } 667 }
662 self.invoke(methodName, args); 668 return self.invoke(methodName, args);
663
664 if (log) _eventsLog.info('<<< [$localName]: dispatch $methodName');
665
666 // TODO(jmesserly): workaround for HTML events not supporting zones.
667 performMicrotaskCheckpoint();
668 } 669 }
669 670
670 void instanceEventListener(Event event) { 671 void instanceEventListener(Event event) {
671 _listenLocal(host, event); 672 _listenLocal(host, event);
672 } 673 }
673 674
674 // TODO(sjmiles): much of the below privatized only because of the vague 675 // TODO(sjmiles): much of the below privatized only because of the vague
675 // notion this code is too fiddly and we need to revisit the core feature 676 // notion this code is too fiddly and we need to revisit the core feature
676 void _listenLocal(Element host, Event event) { 677 void _listenLocal(Element host, Event event) {
677 // TODO(jmesserly): do we need this check? It was using cancelBubble, see: 678 // TODO(jmesserly): do we need this check? It was using cancelBubble, see:
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 } 922 }
922 923
923 final Logger _observeLog = new Logger('polymer.observe'); 924 final Logger _observeLog = new Logger('polymer.observe');
924 final Logger _eventsLog = new Logger('polymer.events'); 925 final Logger _eventsLog = new Logger('polymer.events');
925 final Logger _unbindLog = new Logger('polymer.unbind'); 926 final Logger _unbindLog = new Logger('polymer.unbind');
926 final Logger _bindLog = new Logger('polymer.bind'); 927 final Logger _bindLog = new Logger('polymer.bind');
927 928
928 final Expando _shadowHost = new Expando<Element>(); 929 final Expando _shadowHost = new Expando<Element>();
929 930
930 final Expando _eventHandledTable = new Expando<Set<Node>>(); 931 final Expando _eventHandledTable = new Expando<Set<Node>>();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698