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

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

Issue 20149004: [mdv] implement Node.createBinding and Node.createBindings (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 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/mdv/lib/src/template.dart
diff --git a/pkg/mdv/lib/src/template.dart b/pkg/mdv/lib/src/template.dart
index 5b8a46726e1678fb6b8840b98af85ec427b39d92..7bdc0bb42b52ad1aeffe594df78365876d5cd2fc 100644
--- a/pkg/mdv/lib/src/template.dart
+++ b/pkg/mdv/lib/src/template.dart
@@ -13,7 +13,9 @@ class _TemplateExtension extends _ElementExtension {
_TemplateExtension(Element node) : super(node);
- void bind(String name, model, String path) {
+ Element get node => super.node;
+
+ NodeBinding createBinding(String name, model, String path) {
switch (name) {
case 'bind':
case 'repeat':
@@ -21,34 +23,14 @@ class _TemplateExtension extends _ElementExtension {
if (_templateIterator == null) {
_templateIterator = new _TemplateIterator(node);
}
- _templateIterator.inputs.bind(name, model, path);
- return;
- default:
- super.bind(name, model, path);
- }
- }
-
- void unbind(String name) {
- switch (name) {
- case 'bind':
- case 'repeat':
- case 'if':
- if (_templateIterator != null) {
- _templateIterator.inputs.unbind(name);
- }
- return;
+ // TODO(jmesserly): why do we do this here and nowhere else?
+ if (path == null) path = '';
+ return new _TemplateBinding(node, name, model, path);
default:
- super.unbind(name);
+ return super.createBinding(name, model, path);
}
}
- void unbindAll() {
- unbind('bind');
- unbind('repeat');
- unbind('if');
- super.unbindAll();
- }
-
/**
* Creates an instance of the template.
*/
@@ -98,3 +80,23 @@ class _TemplateExtension extends _ElementExtension {
_addBindings(node, _model, _bindingDelegate);
}
}
+
+class _TemplateBinding extends NodeBinding {
+ // TODO(jmesserly): MDV uses TemplateIterator as the node, see:
+ // https://github.com/Polymer/mdv/issues/127
+ _TemplateBinding(node, name, model, path)
+ : super(node, name, model, path) {
+ _mdv(node)._templateIterator.inputs.bind(property, model, path);
+ }
+
+ // These are no-ops because we don't use the underlying PathObserver.
+ void _observePath() {}
+ void boundValueChanged(newValue) {}
+
+ void close() {
+ if (closed) return;
+ var templateIterator = _mdv(node)._templateIterator;
+ if (templateIterator != null) templateIterator.inputs.unbind(property);
+ super.close();
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698