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

Unified Diff: pkg/mdv/lib/src/element.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/element.dart
diff --git a/pkg/mdv/lib/src/element.dart b/pkg/mdv/lib/src/element.dart
index 3e6e1b06ae5a27921670e8026bb6b12f45ea9a80..a126161a71ca51b2ee4da7de005220001292a5cb 100644
--- a/pkg/mdv/lib/src/element.dart
+++ b/pkg/mdv/lib/src/element.dart
@@ -8,56 +8,41 @@ part of mdv;
class _ElementExtension extends _NodeExtension {
_ElementExtension(Element node) : super(node);
- Element get node => super.node;
-
- Map<String, StreamSubscription> _attributeBindings;
-
// 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).
- void bind(String name, model, String path) {
- if (_attributeBindings == null) {
- _attributeBindings = new Map<String, StreamSubscription>();
- }
+ NodeBinding createBinding(String name, model, String path) =>
+ new _AttributeBinding(node, name, model, path);
+}
+
+class _AttributeBinding extends NodeBinding {
+ final bool conditional;
- var changed;
- if (name.endsWith('?')) {
+ _AttributeBinding._(node, name, model, path, this.conditional)
+ : super(node, name, model, path);
+
+ factory _AttributeBinding(Element node, name, model, path) {
+ bool conditional = name.endsWith('?');
+ if (conditional) {
node.xtag.attributes.remove(name);
name = name.substring(0, name.length - 1);
-
- changed = (value) {
- if (_toBoolean(value)) {
- node.xtag.attributes[name] = '';
- } else {
- node.xtag.attributes.remove(name);
- }
- };
- } else {
- changed = (value) {
- // TODO(jmesserly): escape value if needed to protect against XSS.
- // See https://github.com/polymer-project/mdv/issues/58
- node.xtag.attributes[name] = value == null ? '' : '$value';
- };
}
-
- unbind(name);
-
- _attributeBindings[name] = new PathObserver(model, path).bindSync(changed);
+ return new _AttributeBinding._(node, name, model, path, conditional);
}
- void unbind(String name) {
- if (_attributeBindings != null) {
- var binding = _attributeBindings.remove(name);
- if (binding != null) binding.cancel();
- }
- }
+ Element get node => super.node;
- void unbindAll() {
- if (_attributeBindings != null) {
- for (var binding in _attributeBindings.values) {
- binding.cancel();
+ void boundValueChanged(value) {
+ if (conditional) {
+ if (_toBoolean(value)) {
+ node.xtag.attributes[property] = '';
+ } else {
+ node.xtag.attributes.remove(property);
}
- _attributeBindings = null;
+ } else {
+ // TODO(jmesserly): escape value if needed to protect against XSS.
+ // See https://github.com/polymer-project/mdv/issues/58
+ node.xtag.attributes[property] = sanitizeBoundValue(value);
Siggi Cherem (dart-lang) 2013/07/25 16:24:12 should that escaping be defined in sanitizeBoundVa
}
}
}

Powered by Google App Engine
This is Rietveld 408576698