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

Unified Diff: pkg/template_binding/lib/src/template.dart

Issue 42433002: port Node.bind to bd0a0591920da9091b326627a46a104a92c7efe7 (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 side-by-side diff with in-line comments
Download patch
Index: pkg/template_binding/lib/src/template.dart
diff --git a/pkg/template_binding/lib/src/template.dart b/pkg/template_binding/lib/src/template.dart
index ee344f4af7e1f398618cad26edcdb44b7bfd8179..be6a6fd436db754ffb1dbc772cd520ef5cad0e66 100644
--- a/pkg/template_binding/lib/src/template.dart
+++ b/pkg/template_binding/lib/src/template.dart
@@ -21,19 +21,18 @@ class TemplateBindExtension extends _ElementExtension {
Element get _node => super._node;
- NodeBinding createBinding(String name, model, String path) {
+ NodeBinding bind(String name, model, [String path]) {
switch (name) {
case 'bind':
case 'repeat':
case 'if':
+ _self.unbind(name);
if (_templateIterator == null) {
_templateIterator = new _TemplateIterator(_node);
}
- // TODO(jmesserly): why do we do this here and nowhere else?
- if (path == null) path = '';
- return new _TemplateBinding(this, name, model, path);
+ return bindings[name] = new _TemplateBinding(this, name, model, path);
default:
- return super.createBinding(name, model, path);
+ return super.bind(name, model, path);
}
}
@@ -88,17 +87,8 @@ class TemplateBindExtension extends _ElementExtension {
Element result = null;
var refId = _node.attributes['ref'];
if (refId != null) {
- var treeScope = _node;
- while (treeScope.parentNode != null) {
- treeScope = treeScope.parentNode;
- }
-
- // Note: JS code tests that getElementById is present. We can't do that
- // easily, so instead check for the types known to implement it.
- if (treeScope is Document ||
- treeScope is ShadowRoot ||
- treeScope is SvgSvgElement) {
-
+ var treeScope = _getTreeScope(_node);
+ if (treeScope != null) {
result = treeScope.getElementById(refId);
}
}
@@ -309,12 +299,12 @@ class _TemplateBinding extends NodeBinding {
// https://github.com/Polymer/mdv/issues/127
_TemplateBinding(ext, name, model, path)
: _ext = ext, super(ext._node, name, model, path) {
- _ext._templateIterator.inputs.bind(property, model, path);
+ _ext._templateIterator.inputs.bind(property, model, this.path);
}
// These are no-ops because we don't use the underlying PathObserver.
void _observePath() {}
- void boundValueChanged(newValue) {}
+ void valueChanged(newValue) {}
void close() {
if (closed) return;
@@ -323,3 +313,16 @@ class _TemplateBinding extends NodeBinding {
super.close();
}
}
+
+_getTreeScope(Node node) {
+ while (node.parentNode != null) {
+ node = node.parentNode;
+ }
+
+ // Note: JS code tests that getElementById is present. We can't do that
+ // easily, so instead check for the types known to implement it.
+ if (node is Document || node is ShadowRoot || node is SvgSvgElement) {
+ return node;
+ }
+ return null;
+}

Powered by Google App Engine
This is Rietveld 408576698