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

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

Issue 946513006: Specs: pass the current <script> to the module library init() (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/frameworks.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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 append(nodes); 177 append(nodes);
178 } 178 }
179 } 179 }
180 180
181 class Attr { 181 class Attr {
182 const Attr (this.name, [this.value = '']); // O(1) 182 const Attr (this.name, [this.value = '']); // O(1)
183 final String name; // O(1) 183 final String name; // O(1)
184 final String value; // O(1) 184 final String value; // O(1)
185 } 185 }
186 186
187 // @tagname annotation for registering elements
188 // only useful when placed on classes that inherit from Element
189 class tagname extends AutomaticMetadata {
190 const tagname(this.name);
191 final String name;
192 void init(DeclarationMirror target, Module module) {
193 assert(target is ClassMirror);
194 if (!(target as ClassMirror).isSubclassOf(reflectClass(Element)))
195 throw new UnsupportedError('@tagname can only be used on descendants of El ement');
196 module.registerElement(name, (target as ClassMirror).reflectedType);
197 }
198 }
199
200 // @hasShadow annotation for registering elements 187 // @hasShadow annotation for registering elements
201 class _HasShadow { 188 class _HasShadow {
202 const _HasShadow(); 189 const _HasShadow();
203 } 190 }
204 const hasShadow = const _HasShadow(); 191 const hasShadow = const _HasShadow();
205 192
206 abstract class Element extends ParentNode { 193 abstract class Element extends ParentNode {
207 Element({Map<String, String> attributes: null, 194 Element({Map<String, String> attributes: null,
208 List children: null, 195 List children: null,
209 Module hostModule: null}) { // O(M+N), M = number of attributes, N = number of children nodes plus all their descendants 196 Module hostModule: null}) { // O(M+N), M = number of attributes, N = number of children nodes plus all their descendants
210 var shadowClass = reflectClass(hasShadow.runtimeType); 197 var shadowClass = reflectClass(hasShadow.runtimeType);
211 var shadowAnnotations = reflect(this).type.metadata.where((mirror) => mirror .type == shadowClass); 198 var shadowAnnotations = reflect(this).type.metadata.where((mirror) => mirror .type == shadowClass);
212 if (shadowAnnotations.length > 2) 199 if (shadowAnnotations.length > 2)
213 throw new StateError('@hasShadow specified multiple times on ' + currentMi rrorSystem().getName(reflectClass(this.runtimeType).simpleName)); 200 throw new StateError('@hasShadow specified multiple times on ' + currentMi rrorSystem().getName(reflectClass(this.runtimeType).simpleName));
214 bool needsShadow = shadowAnnotations.length == 1; 201 bool needsShadow = shadowAnnotations.length == 1;
215 if (children != null) 202 if (children != null)
216 children = children.map((node) => node is String ? new Text(node) : node). toList(); 203 children = children.map((node) => node is String ? new Text(node) : node). toList();
217 this._initElement(attributes, children, hostModule, needsShadow); 204 this._initElement(attributes, children, hostModule, needsShadow);
218 } 205 }
219 external void _initElement(Map<String, String> attributes, List children, Modu le hostModule, bool needsShadow); 206 external void _initElement(Map<String, String> attributes, List children, Modu le hostModule, bool needsShadow);
220 // initialises the internal attributes table, which is a ordered list 207 // initialises the internal attributes table, which is a ordered list
221 // appends the given children nodes 208 // appends the given children nodes
222 // children must be Text or Element 209 // children must be Text or Element
223 // if needsShadow is true, creates a shadow tree 210 // if needsShadow is true, creates a shadow tree
224 211
225 String get tagName { // O(N) in number of annotations on the class
226 // throws a StateError if the class doesn't have an @tagname annotation
227 var tagnameClass = reflectClass(tagname);
228 return (reflectClass(this.runtimeType).metadata.singleWhere((mirror) => mirr or.type == tagnameClass).reflectee as tagname).name;
229 }
230
231 external bool hasAttribute(String name); // O(N) in number of attributes 212 external bool hasAttribute(String name); // O(N) in number of attributes
232 external String getAttribute(String name); // O(N) in number of attributes 213 external String getAttribute(String name); // O(N) in number of attributes
233 external void setAttribute(String name, [String value = '']); // O(N) in numbe r of attributes 214 external void setAttribute(String name, [String value = '']); // O(N) in numbe r of attributes
234 external void removeAttribute(String name); // O(N) in number of attributes 215 external void removeAttribute(String name); // O(N) in number of attributes
235 // calling setAttribute() with a null value removes the attribute 216 // calling setAttribute() with a null value removes the attribute
236 // (calling it without a value sets it to the empty string) 217 // (calling it without a value sets it to the empty string)
237 218
238 // Returns a new Array and new Attr instances every time. 219 // Returns a new Array and new Attr instances every time.
239 external List<Attr> getAttributes(); // O(N) in number of attributes 220 external List<Attr> getAttributes(); // O(N) in number of attributes
240 221
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 external bool matches(Element element); // O(F()) 386 external bool matches(Element element); // O(F())
406 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 387 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
407 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 388 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
408 // find() and findAll() throw if the root is not one of the following: 389 // find() and findAll() throw if the root is not one of the following:
409 // - Element 390 // - Element
410 // - Fragment 391 // - Fragment
411 // - Root 392 // - Root
412 } 393 }
413 </script> 394 </script>
414 ``` 395 ```
OLDNEW
« no previous file with comments | « no previous file | sky/specs/frameworks.md » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698