| OLD | NEW |
| 1 Sky DOM APIs | 1 Sky DOM APIs |
| 2 ============ | 2 ============ |
| 3 | 3 |
| 4 ```dart | 4 ```dart |
| 5 SKY MODULE | 5 SKY MODULE |
| 6 <!-- part of dart:sky --> | 6 <!-- part of dart:sky --> |
| 7 | 7 |
| 8 <script> | 8 <script> |
| 9 // ELEMENT TREE API | 9 // ELEMENT TREE API |
| 10 | 10 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 | 132 |
| 133 // Returns a new List every time. | 133 // Returns a new List every time. |
| 134 external List<Node> getChildren(); // O(N) in number of child nodes | 134 external List<Node> getChildren(); // O(N) in number of child nodes |
| 135 List<Element> getChildElements() { | 135 List<Element> getChildElements() { |
| 136 // that the following works without a cast is absurd | 136 // that the following works without a cast is absurd |
| 137 return getChildren().where((node) => node is Element).toList(); | 137 return getChildren().where((node) => node is Element).toList(); |
| 138 } | 138 } |
| 139 | 139 |
| 140 external void _appendChild(Node node); // O(N) in number of descendants | 140 external void _appendChild(Node node); // O(N) in number of descendants |
| 141 // node must be Text or Element | 141 // node must be Text or Element |
| 142 Node appendChild(Node node) { | 142 void appendChild(Node node) { |
| 143 if (node is String) | 143 if (node is String) |
| 144 node = new Text(node); | 144 node = new Text(node); |
| 145 _appendChild(node); | 145 _appendChild(node); |
| 146 return node; | |
| 147 } | 146 } |
| 148 void append(List nodes) { | 147 void append(List nodes) { |
| 149 nodes.forEach(appendChild); | 148 nodes.forEach(appendChild); |
| 150 } | 149 } |
| 151 | 150 |
| 152 external void _prependChild(Node node); // O(N) in number of descendants | 151 external void _prependChild(Node node); // O(N) in number of descendants |
| 153 // node must be Text or Element | 152 // node must be Text or Element |
| 154 Node prependChild(Node node) { | 153 void prependChild(Node node) { |
| 155 if (node is String) | 154 if (node is String) |
| 156 node = new Text(node); | 155 node = new Text(node); |
| 157 _prependChild(node); | 156 _prependChild(node); |
| 158 return node; | |
| 159 } | 157 } |
| 160 void prepend(List nodes) { | 158 void prepend(List nodes) { |
| 161 // note: not implemented in terms of _prependChild() | 159 // note: not implemented in terms of _prependChild() |
| 162 if (firstChild != null) | 160 if (firstChild != null) |
| 163 firstChild.insertBefore(nodes); | 161 firstChild.insertBefore(nodes); |
| 164 else | 162 else |
| 165 append(nodes); | 163 append(nodes); |
| 166 } | 164 } |
| 167 | 165 |
| 168 external void removeChildren(); // O(N) in number of descendants | 166 external void removeChildren(); // O(N) in number of descendants |
| 169 Node setChild(Node node) { | 167 void setChild(Node node) { |
| 170 removeChildren(); | 168 removeChildren(); |
| 171 appendChild(node); | 169 appendChild(node); |
| 172 return node; | |
| 173 } | 170 } |
| 174 void setChildren(List nodes) { | 171 void setChildren(List nodes) { |
| 175 removeChildren(); | 172 removeChildren(); |
| 176 append(nodes); | 173 append(nodes); |
| 177 } | 174 } |
| 178 } | 175 } |
| 179 | 176 |
| 180 class Attr { | 177 class Attr { |
| 181 const Attr (this.name, [this.value = '']); // O(1) | 178 const Attr (this.name, [this.value = '']); // O(1) |
| 182 final String name; // O(1) | 179 final String name; // O(1) |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 external bool matches(Element element); // O(F()) | 381 external bool matches(Element element); // O(F()) |
| 385 external Element find(node root); // O(N*F())+O(M) where N is the number of de
scendants and M the average depth of the tree | 382 external Element find(node root); // O(N*F())+O(M) where N is the number of de
scendants and M the average depth of the tree |
| 386 external List<Element> findAll(Node root); // O(N*F())+O(N*M) where N is the n
umber of descendants and M the average depth of the tree | 383 external List<Element> findAll(Node root); // O(N*F())+O(N*M) where N is the n
umber of descendants and M the average depth of the tree |
| 387 // find() and findAll() throw if the root is not one of the following: | 384 // find() and findAll() throw if the root is not one of the following: |
| 388 // - Element | 385 // - Element |
| 389 // - Fragment | 386 // - Fragment |
| 390 // - Root | 387 // - Root |
| 391 } | 388 } |
| 392 </script> | 389 </script> |
| 393 ``` | 390 ``` |
| OLD | NEW |