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

Unified Diff: sky/specs/elements.md

Issue 938183002: Specs: move needsShadow to an annotation (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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/specs/elements.md
diff --git a/sky/specs/elements.md b/sky/specs/elements.md
index d11c76d37b3573ff39bef3951ebc98479a0a5f3e..9b570e28f6b1d0cfd5d3d8786bcfc4ee17e42aae 100644
--- a/sky/specs/elements.md
+++ b/sky/specs/elements.md
@@ -197,14 +197,27 @@ class tagname extends AutomaticMetadata {
}
}
+// @hasShadow annotation for registering elements
+class _HasShadow {
+ const HasShadow();
+}
+const hasShadow = const _HasShadow();
+
abstract class Element extends ParentNode {
- external Element({Map<String, String> attributes: null,
- List children: null,
- Module hostModule: null}); // O(M+N), M = number of attributes, N = number of children nodes plus all their descendants
+ Element({Map<String, String> attributes: null,
+ List children: null,
+ Module hostModule: null}) { // O(M+N), M = number of attributes, N = number of children nodes plus all their descendants
+ var shadowClass = reflectClass(hasShadow);
+ bool needsShadow = reflect(this).type.metadata.singleWhere((mirror) => mirror.type == hasShadowClass);
+ if (children != null)
+ children = children.map((node) => node is String ? new Text(node) : node).toList();
+ this._initElement(attributes, children, hostModule, needsShadow);
+ }
+ external void _initElement(Map<String, String> attributes, List children, Module hostModule, bool needsShadow);
// initialises the internal attributes table, which is a ordered list
// appends the given children nodes
- // children must be String, Text, or Element
- // if this.needsShadow, creates a shadow tree
+ // children must be Text or Element
+ // if needsShadow is true, creates a shadow tree
String get tagName { // O(N) in number of annotations on the class
// throws a StateError if the class doesn't have an @tagname annotation
@@ -222,7 +235,6 @@ abstract class Element extends ParentNode {
// Returns a new Array and new Attr instances every time.
external List<Attr> getAttributes(); // O(N) in number of attributes
- get bool needsShadow => false; // O(1)
external final Root shadowRoot; // O(1)
// returns the shadow root
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698