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

Unified Diff: pkg/template_binding/lib/src/element.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/element.dart
diff --git a/pkg/template_binding/lib/src/element.dart b/pkg/template_binding/lib/src/element.dart
index ccb1a286569cb18c743dbc00bbd2cd335d92f107..c3c4992f39cb95d2dfcb4c06b1faf9db1cb46762 100644
--- a/pkg/template_binding/lib/src/element.dart
+++ b/pkg/template_binding/lib/src/element.dart
@@ -8,11 +8,20 @@ part of template_binding;
class _ElementExtension extends NodeBindExtension {
_ElementExtension(Element node) : super._(node);
- // TODO(jmesserly): should path be optional, and default to empty path?
- // It is used that way in at least one path in JS TemplateElement tests
- // (see "BindImperative" test in original JS code).
- NodeBinding createBinding(String name, model, String path) =>
- new _AttributeBinding(_node, name, model, path);
+ NodeBinding bind(String name, model, [String path]) {
+ _self.unbind(name);
+
+ var binding;
+ if (_node is OptionElement && name == 'value') {
+ // Note: because <option> can be a semantic template, <option> will be
+ // a TemplateBindExtension sometimes. So we need to handle it here.
+ _node.attributes.remove(name);
+ binding = new _OptionValueBinding(_node, model, path);
+ } else {
+ binding = new _AttributeBinding(_node, name, model, path);
+ }
+ return bindings[name] = binding;
+ }
}
class _AttributeBinding extends NodeBinding {
@@ -32,7 +41,7 @@ class _AttributeBinding extends NodeBinding {
Element get node => super.node;
- void boundValueChanged(value) {
+ void valueChanged(value) {
if (conditional) {
if (_toBoolean(value)) {
node.attributes[property] = '';
@@ -46,3 +55,29 @@ class _AttributeBinding extends NodeBinding {
}
}
}
+
+class _OptionValueBinding extends _ValueBinding {
+ _OptionValueBinding(node, model, path) : super(node, model, path);
+
+ OptionElement get node => super.node;
+
+ void valueChanged(newValue) {
+ var oldValue = null;
+ var selectBinding = null;
+ var select = node.parent;
+ if (select is SelectElement) {
+ var valueBinding = nodeBind(select).bindings['value'];
+ if (valueBinding is _SelectBinding) {
+ selectBinding = valueBinding;
+ oldValue = select.value;
+ }
+ }
+
+ super.valueChanged(newValue);
+
+ if (selectBinding != null && !selectBinding.closed &&
+ select.value != oldValue) {
+ selectBinding.nodeValueChanged(null);
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698