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