| 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 [Node] API. */ | 7 /** Extensions to the [Node] API. */ |
| 8 class _NodeExtension { | 8 class _NodeExtension { |
| 9 final Node node; | 9 final Node node; |
| 10 Map<String, NodeBinding> _bindings; | 10 Map<String, NodeBinding> _bindings; |
| 11 | 11 |
| 12 _NodeExtension(this.node); | 12 _NodeExtension(this.node); |
| 13 | 13 |
| 14 NodeBinding createBinding(String name, model, String path) => null; | 14 NodeBinding createBinding(String name, model, String path) => null; |
| 15 | 15 |
| 16 /** | 16 /** |
| 17 * Binds the attribute [name] to the [path] of the [model]. | 17 * Binds the attribute [name] to the [path] of the [model]. |
| 18 * Path is a String of accessors such as `foo.bar.baz`. | 18 * Path is a String of accessors such as `foo.bar.baz`. |
| 19 */ | 19 */ |
| 20 NodeBinding bind(String name, model, String path) { | 20 NodeBinding bind(String name, model, String path) { |
| 21 var binding = bindings[name]; | 21 var binding = bindings[name]; |
| 22 if (binding != null) binding.close(); | 22 if (binding != null) binding.close(); |
| 23 | 23 |
| 24 binding = createBinding(name, model, path); | 24 // Note: dispatch through the xtag so a custom element can override it. |
| 25 binding = (node is Element ? node.xtag : node) |
| 26 .createBinding(name, model, path); |
| 27 |
| 25 bindings[name] = binding; | 28 bindings[name] = binding; |
| 26 if (binding == null) { | 29 if (binding == null) { |
| 27 window.console.error('Unhandled binding to Node: ' | 30 window.console.error('Unhandled binding to Node: ' |
| 28 '$this $name $model $path'); | 31 '$this $name $model $path'); |
| 29 } | 32 } |
| 30 return binding; | 33 return binding; |
| 31 } | 34 } |
| 32 | 35 |
| 33 /** Unbinds the attribute [name]. */ | 36 /** Unbinds the attribute [name]. */ |
| 34 void unbind(String name) { | 37 void unbind(String name) { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 void close() { | 123 void close() { |
| 121 if (closed) return; | 124 if (closed) return; |
| 122 | 125 |
| 123 if (_pathSub != null) _pathSub.cancel(); | 126 if (_pathSub != null) _pathSub.cancel(); |
| 124 _pathSub = null; | 127 _pathSub = null; |
| 125 _observer = null; | 128 _observer = null; |
| 126 _node = null; | 129 _node = null; |
| 127 _model = null; | 130 _model = null; |
| 128 } | 131 } |
| 129 } | 132 } |
| OLD | NEW |