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

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

Issue 17552019: Reorganize mdv and observe packages (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merged Created 7 years, 6 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
« no previous file with comments | « pkg/mdv/lib/src/bindings.dart ('k') | pkg/mdv/lib/src/input_element.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/mdv/lib/src/element.dart
diff --git a/pkg/mdv/lib/src/element.dart b/pkg/mdv/lib/src/element.dart
new file mode 100644
index 0000000000000000000000000000000000000000..6c0f4055efff038520690db405c034e974a72cf9
--- /dev/null
+++ b/pkg/mdv/lib/src/element.dart
@@ -0,0 +1,65 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+part of mdv;
+
+/** Extensions to the [Element] API. */
+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>();
+ }
+
+ node.xtag.attributes.remove(name);
+
+ var changed;
+ if (name.endsWith('?')) {
+ name = name.substring(0, name.length - 1);
+
+ changed = (value) {
+ if (_Bindings._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);
+ }
+
+ void unbind(String name) {
+ if (_attributeBindings != null) {
+ var binding = _attributeBindings.remove(name);
+ if (binding != null) binding.cancel();
+ }
+ }
+
+ void unbindAll() {
+ if (_attributeBindings != null) {
+ for (var binding in _attributeBindings.values) {
+ binding.cancel();
+ }
+ _attributeBindings = null;
+ }
+ }
+}
« no previous file with comments | « pkg/mdv/lib/src/bindings.dart ('k') | pkg/mdv/lib/src/input_element.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698