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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/specs/elements.md ('k') | sky/specs/modules.md » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/specs/frameworks.md
diff --git a/sky/specs/frameworks.md b/sky/specs/frameworks.md
new file mode 100644
index 0000000000000000000000000000000000000000..f7d91a517f6f7347e3687548a8bd79b832b43853
--- /dev/null
+++ b/sky/specs/frameworks.md
@@ -0,0 +1,31 @@
+Frameworks
+----------
+
+Sky is intended to support multiple frameworks. Here is one way you
+could register a custom element using Dart annotations:
+
+```dart
+// @tagname annotation for registering elements
+// only useful when placed on classes that inherit from Element
+class tagname extends AutomaticMetadata {
+ const tagname(this.name);
+ final String name;
+ void init(DeclarationMirror target, Module module, ScriptElement script) {
+ assert(target is ClassMirror);
+ if (!(target as ClassMirror).isSubclassOf(reflectClass(Element)))
+ throw new UnsupportedError('@tagname can only be used on descendants of Element');
+ module.registerElement(name, (target as ClassMirror).reflectedType);
+ }
+}
+```
+
+A framework that used the above code could use the following code to
+get the tag name of an element:
+
+```dart
+String getTagName(Element element) { // O(N) in number of annotations on the class
+ // throws a StateError if the class doesn't have an @tagname annotation
+ var tagnameClass = reflectClass(tagname);
+ return (reflectClass(element.runtimeType).metadata.singleWhere((mirror) => mirror.type == tagnameClass).reflectee as tagname).name;
+}
+```
« 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