Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(527)

Side by Side Diff: sky/specs/elements.md

Issue 923023005: Specs: Make appendChild, prependChild, and setChild return the child; make Dispatcher's unlisten() … (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | sky/specs/events.md » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 void appendChild(Node node) { 142 Node 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;
146 } 147 }
147 void append(List nodes) { 148 void append(List nodes) {
148 nodes.forEach(appendChild); 149 nodes.forEach(appendChild);
149 } 150 }
150 151
151 external void _prependChild(Node node); // O(N) in number of descendants 152 external void _prependChild(Node node); // O(N) in number of descendants
152 // node must be Text or Element 153 // node must be Text or Element
153 void prependChild(Node node) { 154 Node prependChild(Node node) {
154 if (node is String) 155 if (node is String)
155 node = new Text(node); 156 node = new Text(node);
156 _prependChild(node); 157 _prependChild(node);
158 return node;
157 } 159 }
158 void prepend(List nodes) { 160 void prepend(List nodes) {
159 // note: not implemented in terms of _prependChild() 161 // note: not implemented in terms of _prependChild()
160 if (firstChild != null) 162 if (firstChild != null)
161 firstChild.insertBefore(nodes); 163 firstChild.insertBefore(nodes);
162 else 164 else
163 append(nodes); 165 append(nodes);
164 } 166 }
165 167
166 external void removeChildren(); // O(N) in number of descendants 168 external void removeChildren(); // O(N) in number of descendants
167 void setChild(Node node) { 169 Node setChild(Node node) {
168 removeChildren(); 170 removeChildren();
169 appendChild(node); 171 appendChild(node);
172 return node;
170 } 173 }
171 void setChildren(List nodes) { 174 void setChildren(List nodes) {
172 removeChildren(); 175 removeChildren();
173 append(nodes); 176 append(nodes);
174 } 177 }
175 } 178 }
176 179
177 class Attr { 180 class Attr {
178 const Attr (this.name, [this.value = '']); // O(1) 181 const Attr (this.name, [this.value = '']); // O(1)
179 final String name; // O(1) 182 final String name; // O(1)
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 external bool matches(Element element); // O(F()) 384 external bool matches(Element element); // O(F())
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 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
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 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
384 // find() and findAll() throw if the root is not one of the following: 387 // find() and findAll() throw if the root is not one of the following:
385 // - Element 388 // - Element
386 // - Fragment 389 // - Fragment
387 // - Root 390 // - Root
388 } 391 }
389 </script> 392 </script>
390 ``` 393 ```
OLDNEW
« no previous file with comments | « no previous file | sky/specs/events.md » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698