Chromium Code Reviews| Index: pkg/polymer/lib/src/instance.dart |
| diff --git a/pkg/polymer/lib/src/instance.dart b/pkg/polymer/lib/src/instance.dart |
| index e46fda35ad9cd190f17827c30a3700f0d807f800..ae93cc657a4893c3deee1d48fbee1f680c13924b 100644 |
| --- a/pkg/polymer/lib/src/instance.dart |
| +++ b/pkg/polymer/lib/src/instance.dart |
| @@ -437,6 +437,8 @@ abstract class Polymer implements Element, Observable, NodeBindExtension { |
| } |
| Map<String, NodeBinding> get bindings => nodeBindFallback(this).bindings; |
| + TemplateInstance get templateInstance => |
| + nodeBindFallback(this).templateInstance; |
| void unbind(String name) => nodeBindFallback(this).unbind(name); |
| @@ -738,38 +740,43 @@ abstract class Polymer implements Element, Observable, NodeBindExtension { |
| // we implement this by wrapping/overriding getBinding instead. |
| // TODO(sorvell): we're patching the syntax while evaluating |
| // event bindings. we'll move this to a better spot when that's done |
| - static getBindingWithEvents( |
| - model, String path, name, node, originalGetBinding) { |
| + static PrepareBindingFunction prepareBinding(String path, String name, node, |
| + originalPrepareBinding) { |
| + |
| // if lhs an event prefix, |
| - if (name is! String || !_hasEventPrefix(name)) { |
| - return originalGetBinding(model, path, name, node); |
| - } |
| + if (!_hasEventPrefix(name)) return originalPrepareBinding(path, name, node); |
| - // provide an event-binding callback. |
| - // return (model, name, node) { |
| - if (_eventsLog.isLoggable(Level.FINE)) { |
| - _eventsLog.fine('event: [${node.localName}].$name => ' |
| - '[${model.localName}].$path())'); |
| - } |
| - var eventName = _removeEventPrefix(name); |
| - // TODO(sigmund): polymer.js dropped event translations. reconcile? |
| - var translated = _eventTranslations[eventName]; |
| - eventName = translated != null ? translated : eventName; |
| - return node.on[eventName].listen((event) { |
| - var ctrlr = _findController(node); |
| - if (ctrlr is! Polymer) return; |
| - var obj = ctrlr; |
| - var method = path; |
| - if (path[0] == '@') { |
| - obj = model; |
| - // Dart note: using getBinding gets us the result of evaluating the |
| - // original path (without the @) as a normal expression. |
| - method = originalGetBinding(model, path.substring(1), name, node).value; |
| + return (model, node) { |
| + // 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.
|
| + // 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.
|
| + if (_eventsLog.isLoggable(Level.FINE)) { |
| + _eventsLog.fine('event: [${node}].$name => [${model}].$path())'); |
| } |
| - var detail = event is CustomEvent ? |
| - (event as CustomEvent).detail : null; |
| - ctrlr.dispatchMethod(obj, method, [event, detail, node]); |
| - }); |
| + var eventName = _removeEventPrefix(name); |
| + // TODO(sigmund): polymer.js dropped event translations. reconcile? |
| + var translated = _eventTranslations[eventName]; |
| + eventName = translated != null ? translated : eventName; |
| + |
| + // TODO(jmesserly): returning a StreamSubscription as the model is quite |
| + // strange. package:template_binding doesn't have any cleanup logic to |
| + // handle that. |
| + return node.on[eventName].listen((event) { |
| + var ctrlr = _findController(node); |
| + if (ctrlr is! Polymer) return; |
| + var obj = ctrlr; |
| + var method = path; |
| + if (path[0] == '@') { |
| + obj = model; |
| + // Dart note: using getBinding gets us the result of evaluating the |
| + // 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
|
| + method = originalPrepareBinding(path.substring(1), name, node) |
| + (model, node).value; |
| + } |
| + var detail = event is CustomEvent ? |
| + (event as CustomEvent).detail : null; |
| + ctrlr.dispatchMethod(obj, method, [event, detail, node]); |
| + }); |
| + }; |
| } |
| // TODO(jmesserly): this won't find the correct host unless the ShadowRoot |
| @@ -1074,8 +1081,7 @@ class _PropertyValue { |
| } |
| class _PolymerExpressionsWithEventDelegate extends PolymerExpressions { |
| - getBinding(model, String path, name, node) { |
| - return Polymer.getBindingWithEvents( |
| - model, path, name, node, super.getBinding); |
| + 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.
|
| + return Polymer.prepareBinding(path, name, node, super.prepareBinding); |
| } |
| } |