| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of mdv; | 5 part of mdv; |
| 6 | 6 |
| 7 /** Extensions to the [Element] API. */ | 7 /** Extensions to the [Element] API. */ |
| 8 class _ElementExtension extends _NodeExtension { | 8 class _ElementExtension extends _NodeExtension { |
| 9 _ElementExtension(Element node) : super(node); | 9 _ElementExtension(Element node) : super(node); |
| 10 | 10 |
| 11 Element get node => super.node; | 11 Element get node => super.node; |
| 12 | 12 |
| 13 Map<String, StreamSubscription> _attributeBindings; | 13 Map<String, StreamSubscription> _attributeBindings; |
| 14 | 14 |
| 15 // TODO(jmesserly): should path be optional, and default to empty path? | 15 // TODO(jmesserly): should path be optional, and default to empty path? |
| 16 // It is used that way in at least one path in JS TemplateElement tests | 16 // It is used that way in at least one path in JS TemplateElement tests |
| 17 // (see "BindImperative" test in original JS code). | 17 // (see "BindImperative" test in original JS code). |
| 18 void bind(String name, model, String path) { | 18 void bind(String name, model, String path) { |
| 19 if (_attributeBindings == null) { | 19 if (_attributeBindings == null) { |
| 20 _attributeBindings = new Map<String, StreamSubscription>(); | 20 _attributeBindings = new Map<String, StreamSubscription>(); |
| 21 } | 21 } |
| 22 | 22 |
| 23 node.xtag.attributes.remove(name); | |
| 24 | |
| 25 var changed; | 23 var changed; |
| 26 if (name.endsWith('?')) { | 24 if (name.endsWith('?')) { |
| 25 node.xtag.attributes.remove(name); |
| 27 name = name.substring(0, name.length - 1); | 26 name = name.substring(0, name.length - 1); |
| 28 | 27 |
| 29 changed = (value) { | 28 changed = (value) { |
| 30 if (_toBoolean(value)) { | 29 if (_toBoolean(value)) { |
| 31 node.xtag.attributes[name] = ''; | 30 node.xtag.attributes[name] = ''; |
| 32 } else { | 31 } else { |
| 33 node.xtag.attributes.remove(name); | 32 node.xtag.attributes.remove(name); |
| 34 } | 33 } |
| 35 }; | 34 }; |
| 36 } else { | 35 } else { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 55 | 54 |
| 56 void unbindAll() { | 55 void unbindAll() { |
| 57 if (_attributeBindings != null) { | 56 if (_attributeBindings != null) { |
| 58 for (var binding in _attributeBindings.values) { | 57 for (var binding in _attributeBindings.values) { |
| 59 binding.cancel(); | 58 binding.cancel(); |
| 60 } | 59 } |
| 61 _attributeBindings = null; | 60 _attributeBindings = null; |
| 62 } | 61 } |
| 63 } | 62 } |
| 64 } | 63 } |
| OLD | NEW |