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

Side by Side Diff: sky/specs/frameworks.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 | « sky/specs/elements.md ('k') | sky/specs/modules.md » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 Frameworks
2 ----------
3
4 Sky is intended to support multiple frameworks. Here is one way you
5 could register a custom element using Dart annotations:
6
7 ```dart
8 // @tagname annotation for registering elements
9 // only useful when placed on classes that inherit from Element
10 class tagname extends AutomaticMetadata {
11 const tagname(this.name);
12 final String name;
13 void init(DeclarationMirror target, Module module, ScriptElement script) {
14 assert(target is ClassMirror);
15 if (!(target as ClassMirror).isSubclassOf(reflectClass(Element)))
16 throw new UnsupportedError('@tagname can only be used on descendants of El ement');
17 module.registerElement(name, (target as ClassMirror).reflectedType);
18 }
19 }
20 ```
21
22 A framework that used the above code could use the following code to
23 get the tag name of an element:
24
25 ```dart
26 String getTagName(Element element) { // O(N) in number of annotations on the cla ss
27 // throws a StateError if the class doesn't have an @tagname annotation
28 var tagnameClass = reflectClass(tagname);
29 return (reflectClass(element.runtimeType).metadata.singleWhere((mirror) => mir ror.type == tagnameClass).reflectee as tagname).name;
30 }
31 ```
OLDNEW
« no previous file with comments | « sky/specs/elements.md ('k') | sky/specs/modules.md » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698