| OLD | NEW |
| 1 Sky DOM APIs | 1 Sky DOM APIs |
| 2 ============ | 2 ============ |
| 3 | 3 |
| 4 ```dart | 4 ```dart |
| 5 // ELEMENT TREE API | 5 // ELEMENT TREE API |
| 6 | 6 |
| 7 abstract class ChildNode { | 7 abstract class ChildNode { |
| 8 @nonnull external TreeScope get ownerScope; // O(1) | 8 @nonnull external TreeScope get ownerScope; // O(1) |
| 9 | 9 |
| 10 external ParentNode get parentNode; // O(1) | 10 external ParentNode get parentNode; // O(1) |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 } | 72 } |
| 73 | 73 |
| 74 class Attr { | 74 class Attr { |
| 75 const Attr (this.name, [this.value = '']); // O(1) | 75 const Attr (this.name, [this.value = '']); // O(1) |
| 76 final String name; // O(1) | 76 final String name; // O(1) |
| 77 final String value; // O(1) | 77 final String value; // O(1) |
| 78 } | 78 } |
| 79 | 79 |
| 80 // @tagname annotation for registering elements | 80 // @tagname annotation for registering elements |
| 81 // only useful when placed on classes that inherit from Element | 81 // only useful when placed on classes that inherit from Element |
| 82 class tagname { | 82 class tagname extends AutomaticMetadata { |
| 83 const tagname(this.value); | 83 const tagname(this.name); |
| 84 @nonnull final String value; | 84 @nonnull final String name; |
| 85 void init(DeclarationMirror target, Module module) { |
| 86 assert(target is ClassMirror); |
| 87 if (!target.isSubclassOf(reflectClass(Element))) |
| 88 throw Error('@tagname can only be used on descendants of Element'); |
| 89 module.registerElement(name, (target as ClassMirror).reflectedType); |
| 90 } |
| 85 } | 91 } |
| 86 | 92 |
| 87 abstract class FindRoot { } | 93 abstract class FindRoot { } |
| 88 | 94 |
| 89 abstract class Element extends ParentNode with ChildNode implements FindRoot { | 95 abstract class Element extends ParentNode with ChildNode implements FindRoot { |
| 90 Element({Map</*@nonnull*/ String, /*@nonnull*/ String> attributes: null, | 96 external Element({Map</*@nonnull*/ String, /*@nonnull*/ String> attributes: nu
ll, |
| 91 List</*nonnull*/ ChildNode> nodes: null}); // O(M+N), M = number of a
ttributes, N = number of nodes plus all their descendants | 97 List</*nonnull*/ ChildNode> nodes: null, |
| 98 Module hostModule: null}); // O(M+N), M = number of attribute
s, N = number of nodes plus all their descendants |
| 99 // initialises the internal attributes table |
| 100 // appends the given child nodes |
| 101 // if this.needsShadow, creates a shadow tree |
| 92 | 102 |
| 93 @nonnull String get tagName { // O(N) in number of annotations on the class | 103 @nonnull String get tagName { // O(N) in number of annotations on the class |
| 94 // throws a StateError if the class doesn't have an @tagname annotation | 104 // throws a StateError if the class doesn't have an @tagname annotation |
| 95 var tagnameClass = reflectClass(tagname); | 105 var tagnameClass = reflectClass(tagname); |
| 96 return (reflectClass(this.runtimeType).metadata.singleWhere((mirror) => mirr
or.type == tagnameClass).reflectee as tagname).value; | 106 return (reflectClass(this.runtimeType).metadata.singleWhere((mirror) => mirr
or.type == tagnameClass).reflectee as tagname).value; |
| 97 } | 107 } |
| 98 | 108 |
| 99 @nonnull external bool hasAttribute(@nonnull String name); // O(N) in number o
f attributes | 109 @nonnull external bool hasAttribute(@nonnull String name); // O(N) in number o
f attributes |
| 100 @nonnull external String getAttribute(@nonnull String name); // O(N) in number
of attributes | 110 @nonnull external String getAttribute(@nonnull String name); // O(N) in number
of attributes |
| 101 external void setAttribute(@nonnull String name, [@nonnull String value = ''])
; // O(N) in number of attributes | 111 external void setAttribute(@nonnull String name, [@nonnull String value = ''])
; // O(N) in number of attributes |
| 102 external void removeAttribute(@nonnull String name); // O(N) in number of attr
ibutes | 112 external void removeAttribute(@nonnull String name); // O(N) in number of attr
ibutes |
| 103 | 113 |
| 104 // Returns a new Array and new Attr instances every time. | 114 // Returns a new Array and new Attr instances every time. |
| 105 @nonnull external List<Attr> getAttributes(); // O(N) in number of attributes | 115 @nonnull external List<Attr> getAttributes(); // O(N) in number of attributes |
| 106 | 116 |
| 117 get bool needsShadow => false; // O(1) |
| 107 external ShadowRoot get shadowRoot; // O(1) | 118 external ShadowRoot get shadowRoot; // O(1) |
| 108 // returns the shadow root | 119 // returns the shadow root |
| 109 // TODO(ianh): Should this be mutable? It would help explain how it gets set..
. | 120 // TODO(ianh): Should this be mutable? It would help explain how it gets set..
. |
| 110 | 121 |
| 111 void endTagParsedCallback() { } | 122 void endTagParsedCallback() { } |
| 112 void attributeChangeCallback(String name, String oldValue, String newValue) {
} | 123 void attributeChangeCallback(String name, String oldValue, String newValue) {
} |
| 113 // name will never be null when this is called by sky | 124 // name will never be null when this is called by sky |
| 114 | 125 |
| 115 // TODO(ianh): does a node ever need to know when it's been redistributed? | 126 // TODO(ianh): does a node ever need to know when it's been redistributed? |
| 116 | 127 |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 } | 281 } |
| 271 | 282 |
| 272 class SelectorQuery { | 283 class SelectorQuery { |
| 273 external SelectorQuery(@nonnull String selector); // O(F()) where F() is the c
omplexity of the selector | 284 external SelectorQuery(@nonnull String selector); // O(F()) where F() is the c
omplexity of the selector |
| 274 | 285 |
| 275 @nonnull external bool matches(@nonnull Element element); // O(F()) | 286 @nonnull external bool matches(@nonnull Element element); // O(F()) |
| 276 external Element find(@nonnull FindRoot root); // O(N*F())+O(M) where N is the
number of descendants and M the average depth of the tree | 287 external Element find(@nonnull FindRoot root); // O(N*F())+O(M) where N is the
number of descendants and M the average depth of the tree |
| 277 @nonnull external List</*@nonnull*/ Element> findAll(FindRoot root); // O(N*F(
))+O(N*M) where N is the number of descendants and M the average depth of the tr
ee | 288 @nonnull external List</*@nonnull*/ Element> findAll(FindRoot root); // O(N*F(
))+O(N*M) where N is the number of descendants and M the average depth of the tr
ee |
| 278 } | 289 } |
| 279 ``` | 290 ``` |
| OLD | NEW |