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 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 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
430 // to ensure binding is not left on attribute if property | 430 // to ensure binding is not left on attribute if property |
431 // does not update due to not changing. | 431 // does not update due to not changing. |
432 // Dart note: we include this patch: | 432 // Dart note: we include this patch: |
433 // https://github.com/Polymer/polymer/pull/319 | 433 // https://github.com/Polymer/polymer/pull/319 |
434 reflectPropertyToAttribute(property.simpleName); | 434 reflectPropertyToAttribute(property.simpleName); |
435 return bindings[name] = observer; | 435 return bindings[name] = observer; |
436 } | 436 } |
437 } | 437 } |
438 | 438 |
439 Map<String, NodeBinding> get bindings => nodeBindFallback(this).bindings; | 439 Map<String, NodeBinding> get bindings => nodeBindFallback(this).bindings; |
440 TemplateInstance get templateInstance => | |
441 nodeBindFallback(this).templateInstance; | |
440 | 442 |
441 void unbind(String name) => nodeBindFallback(this).unbind(name); | 443 void unbind(String name) => nodeBindFallback(this).unbind(name); |
442 | 444 |
443 void asyncUnbindAll() { | 445 void asyncUnbindAll() { |
444 if (_unbound == true) return; | 446 if (_unbound == true) return; |
445 _unbindLog.fine('[$localName] asyncUnbindAll'); | 447 _unbindLog.fine('[$localName] asyncUnbindAll'); |
446 _unbindAllJob = _runJob(_unbindAllJob, unbindAll, Duration.ZERO); | 448 _unbindAllJob = _runJob(_unbindAllJob, unbindAll, Duration.ZERO); |
447 } | 449 } |
448 | 450 |
449 void unbindAll() { | 451 void unbindAll() { |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
731 * custom element in which the node exists. Adding a '@' in the path directs | 733 * custom element in which the node exists. Adding a '@' in the path directs |
732 * the event binding to use the model path as the event listener. In both | 734 * the event binding to use the model path as the event listener. In both |
733 * cases, the actual listener is attached to a generic method which evaluates | 735 * cases, the actual listener is attached to a generic method which evaluates |
734 * the bound path at event execution time. | 736 * the bound path at event execution time. |
735 */ | 737 */ |
736 // from src/instance/event.js#prepareBinding | 738 // from src/instance/event.js#prepareBinding |
737 // Dart note: template_binding doesn't have the notion of prepareBinding, so | 739 // Dart note: template_binding doesn't have the notion of prepareBinding, so |
738 // we implement this by wrapping/overriding getBinding instead. | 740 // we implement this by wrapping/overriding getBinding instead. |
739 // TODO(sorvell): we're patching the syntax while evaluating | 741 // TODO(sorvell): we're patching the syntax while evaluating |
740 // event bindings. we'll move this to a better spot when that's done | 742 // event bindings. we'll move this to a better spot when that's done |
741 static getBindingWithEvents( | 743 static PrepareBindingFunction prepareBinding(String path, String name, node, |
742 model, String path, name, node, originalGetBinding) { | 744 originalPrepareBinding) { |
745 | |
743 // if lhs an event prefix, | 746 // if lhs an event prefix, |
744 if (name is! String || !_hasEventPrefix(name)) { | 747 if (!_hasEventPrefix(name)) return originalPrepareBinding(path, name, node); |
745 return originalGetBinding(model, path, name, node); | |
746 } | |
747 | 748 |
748 // provide an event-binding callback. | 749 return (model, node) { |
749 // return (model, name, node) { | 750 // provide an event-binding callback. |
Siggi Cherem (dart-lang)
2013/10/29 21:00:07
move this line above the return (to match polymer.
Jennifer Messerly
2013/10/29 22:35:07
Done.
| |
750 if (_eventsLog.isLoggable(Level.FINE)) { | 751 // return (model, name, node) { |
Siggi Cherem (dart-lang)
2013/10/29 21:00:07
remove this line (it was there just to make it eas
Jennifer Messerly
2013/10/29 22:35:07
Done.
| |
751 _eventsLog.fine('event: [${node.localName}].$name => ' | 752 if (_eventsLog.isLoggable(Level.FINE)) { |
752 '[${model.localName}].$path())'); | 753 _eventsLog.fine('event: [${node}].$name => [${model}].$path())'); |
753 } | |
754 var eventName = _removeEventPrefix(name); | |
755 // TODO(sigmund): polymer.js dropped event translations. reconcile? | |
756 var translated = _eventTranslations[eventName]; | |
757 eventName = translated != null ? translated : eventName; | |
758 return node.on[eventName].listen((event) { | |
759 var ctrlr = _findController(node); | |
760 if (ctrlr is! Polymer) return; | |
761 var obj = ctrlr; | |
762 var method = path; | |
763 if (path[0] == '@') { | |
764 obj = model; | |
765 // Dart note: using getBinding gets us the result of evaluating the | |
766 // original path (without the @) as a normal expression. | |
767 method = originalGetBinding(model, path.substring(1), name, node).value; | |
768 } | 754 } |
769 var detail = event is CustomEvent ? | 755 var eventName = _removeEventPrefix(name); |
770 (event as CustomEvent).detail : null; | 756 // TODO(sigmund): polymer.js dropped event translations. reconcile? |
771 ctrlr.dispatchMethod(obj, method, [event, detail, node]); | 757 var translated = _eventTranslations[eventName]; |
772 }); | 758 eventName = translated != null ? translated : eventName; |
759 | |
760 // TODO(jmesserly): returning a StreamSubscription as the model is quite | |
761 // strange. package:template_binding doesn't have any cleanup logic to | |
762 // handle that. | |
763 return node.on[eventName].listen((event) { | |
764 var ctrlr = _findController(node); | |
765 if (ctrlr is! Polymer) return; | |
766 var obj = ctrlr; | |
767 var method = path; | |
768 if (path[0] == '@') { | |
769 obj = model; | |
770 // Dart note: using getBinding gets us the result of evaluating the | |
771 // original path (without the @) as a normal expression. | |
Siggi Cherem (dart-lang)
2013/10/29 21:00:07
we might also want to add a note here about what w
Jennifer Messerly
2013/10/29 22:35:07
Switched it to use PathObserver. but yeah follow u
| |
772 method = originalPrepareBinding(path.substring(1), name, node) | |
773 (model, node).value; | |
774 } | |
775 var detail = event is CustomEvent ? | |
776 (event as CustomEvent).detail : null; | |
777 ctrlr.dispatchMethod(obj, method, [event, detail, node]); | |
778 }); | |
779 }; | |
773 } | 780 } |
774 | 781 |
775 // TODO(jmesserly): this won't find the correct host unless the ShadowRoot | 782 // TODO(jmesserly): this won't find the correct host unless the ShadowRoot |
776 // was created on a PolymerElement. | 783 // was created on a PolymerElement. |
777 static Polymer _findController(Node node) { | 784 static Polymer _findController(Node node) { |
778 while (node.parentNode != null) { | 785 while (node.parentNode != null) { |
779 node = node.parentNode; | 786 node = node.parentNode; |
780 } | 787 } |
781 return _shadowHost[node]; | 788 return _shadowHost[node]; |
782 } | 789 } |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1067 polymerCreated(); | 1074 polymerCreated(); |
1068 } | 1075 } |
1069 } | 1076 } |
1070 | 1077 |
1071 class _PropertyValue { | 1078 class _PropertyValue { |
1072 Object oldValue, newValue; | 1079 Object oldValue, newValue; |
1073 _PropertyValue(this.oldValue); | 1080 _PropertyValue(this.oldValue); |
1074 } | 1081 } |
1075 | 1082 |
1076 class _PolymerExpressionsWithEventDelegate extends PolymerExpressions { | 1083 class _PolymerExpressionsWithEventDelegate extends PolymerExpressions { |
1077 getBinding(model, String path, name, node) { | 1084 prepareBinding(String path, name, node) { |
Siggi Cherem (dart-lang)
2013/10/29 21:00:07
nit, it was like this before, but consider using =
Jennifer Messerly
2013/10/29 22:35:07
Done.
| |
1078 return Polymer.getBindingWithEvents( | 1085 return Polymer.prepareBinding(path, name, node, super.prepareBinding); |
1079 model, path, name, node, super.getBinding); | |
1080 } | 1086 } |
1081 } | 1087 } |
OLD | NEW |