| OLD | NEW |
| 1 part of angular.core.dom; | 1 part of angular.core.dom; |
| 2 | 2 |
| 3 /** | 3 /** |
| 4 * Callback function used to notify of attribute changes. | 4 * Callback function used to notify of attribute changes. |
| 5 */ | 5 */ |
| 6 typedef AttributeChanged(String newValue); | 6 typedef AttributeChanged(String newValue); |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * Callback function used to notify of text changes. |
| 10 */ |
| 11 abstract class TextChangeListener{ |
| 12 call(String text); |
| 13 } |
| 14 |
| 15 /** |
| 9 * NodeAttrs is a facade for element attributes. The facade is responsible | 16 * NodeAttrs is a facade for element attributes. The facade is responsible |
| 10 * for normalizing attribute names as well as allowing access to the | 17 * for normalizing attribute names as well as allowing access to the |
| 11 * value of the directive. | 18 * value of the directive. |
| 12 */ | 19 */ |
| 13 class NodeAttrs { | 20 class NodeAttrs { |
| 14 final dom.Element element; | 21 final dom.Element element; |
| 15 | 22 |
| 16 Map<String, List<AttributeChanged>> _observers; | 23 Map<String, List<AttributeChanged>> _observers; |
| 17 | 24 |
| 18 NodeAttrs(this.element); | 25 NodeAttrs(this.element); |
| 19 | 26 |
| 20 operator [](String attributeName) => | 27 operator [](String attributeName) => |
| 21 element.attributes[attributeName]; | 28 element.attributes[snakecase(attributeName, '-')]; |
| 22 | 29 |
| 23 operator []=(String attributeName, String value) { | 30 operator []=(String attributeName, String value) { |
| 31 var snakeName = snakecase(attributeName, '-'); |
| 24 if (value == null) { | 32 if (value == null) { |
| 25 element.attributes.remove(attributeName); | 33 element.attributes.remove(snakeName); |
| 26 } else { | 34 } else { |
| 27 element.attributes[attributeName] = value; | 35 element.attributes[snakeName] = value; |
| 28 } | 36 } |
| 29 if (_observers != null && _observers.containsKey(attributeName)) { | 37 if (_observers != null && _observers.containsKey(attributeName)) { |
| 30 _observers[attributeName].forEach((fn) => fn(value)); | 38 _observers[attributeName].forEach((fn) => fn(value)); |
| 31 } | 39 } |
| 32 } | 40 } |
| 33 | 41 |
| 34 /** | 42 /** |
| 35 * Observe changes to the attribute by invoking the [AttributeChanged] | 43 * Observe changes to the attribute by invoking the [AttributeChanged] |
| 36 * function. On registration the [AttributeChanged] function gets invoked | 44 * function. On registration the [AttributeChanged] function gets invoked |
| 37 * synchronise with the current value. | 45 * synchronise with the current value. |
| 38 */ | 46 */ |
| 39 observe(String attributeName, AttributeChanged notifyFn) { | 47 observe(String attributeName, AttributeChanged notifyFn) { |
| 40 if (_observers == null) { | 48 if (_observers == null) { |
| 41 _observers = new Map<String, List<AttributeChanged>>(); | 49 _observers = new Map<String, List<AttributeChanged>>(); |
| 42 } | 50 } |
| 43 if (!_observers.containsKey(attributeName)) { | 51 if (!_observers.containsKey(attributeName)) { |
| 44 _observers[attributeName] = new List<AttributeChanged>(); | 52 _observers[attributeName] = new List<AttributeChanged>(); |
| 45 } | 53 } |
| 46 _observers[attributeName].add(notifyFn); | 54 _observers[attributeName].add(notifyFn); |
| 47 notifyFn(this[attributeName]); | 55 notifyFn(this[attributeName]); |
| 48 } | 56 } |
| 49 | 57 |
| 50 void forEach(void f(String k, String v)) { | 58 void forEach(void f(String k, String v)) { |
| 51 element.attributes.forEach(f); | 59 element.attributes.forEach((k, v) => f(camelcase(k), v)); |
| 52 } | 60 } |
| 53 | 61 |
| 54 bool containsKey(String attributeName) => | 62 bool containsKey(String attributeName) => |
| 55 element.attributes.containsKey(attributeName); | 63 element.attributes.containsKey(snakecase(attributeName, '-')); |
| 56 | 64 |
| 57 Iterable<String> get keys => | 65 Iterable<String> get keys => |
| 58 element.attributes.keys; | 66 element.attributes.keys.map((name) => camelcase(name)); |
| 59 } | 67 } |
| 60 | 68 |
| 61 /** | 69 /** |
| 62 * TemplateLoader is an asynchronous access to ShadowRoot which is | 70 * TemplateLoader is an asynchronous access to ShadowRoot which is |
| 63 * loaded asynchronously. It allows a Component to be notified when its | 71 * loaded asynchronously. It allows a Component to be notified when its |
| 64 * ShadowRoot is ready. | 72 * ShadowRoot is ready. |
| 65 */ | 73 */ |
| 66 class TemplateLoader { | 74 class TemplateLoader { |
| 67 final async.Future<dom.ShadowRoot> _template; | 75 final async.Future<dom.ShadowRoot> _template; |
| 68 | 76 |
| 69 async.Future<dom.ShadowRoot> get template => _template; | 77 async.Future<dom.ShadowRoot> get template => _template; |
| 70 | 78 |
| 71 TemplateLoader(this._template); | 79 TemplateLoader(this._template); |
| 72 } | 80 } |
| OLD | NEW |