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

Unified Diff: lib/src/common/polymer_descriptor.dart

Issue 1290643006: First cut at behaviors. This just implements the lifecycle methodsportion. We may get the rest for … (Closed) Base URL: git@github.com:dart-lang/polymer-dart.git@master
Patch Set: Created 5 years, 4 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
Index: lib/src/common/polymer_descriptor.dart
diff --git a/lib/src/common/polymer_descriptor.dart b/lib/src/common/polymer_descriptor.dart
index f4457caeb8275be5c79b115b2f376c15e55a6d99..ba5ab24f197b5320ce22c27695c1b7a71e86e283 100644
--- a/lib/src/common/polymer_descriptor.dart
+++ b/lib/src/common/polymer_descriptor.dart
@@ -5,6 +5,7 @@ library polymer.src.micro.properties;
import 'dart:js';
import 'package:reflectable/reflectable.dart';
+import 'behavior.dart';
import 'declarations.dart';
import 'js_proxy.dart';
import 'property.dart';
@@ -20,9 +21,10 @@ JsObject createPolymerDescriptor(Type type, PolymerRegister annotation) {
'is': annotation.tagName,
'extends': annotation.extendsTag,
'hostAttributes': annotation.hostAttributes,
- 'properties': buildPropertiesObject(type),
+ 'properties': _buildPropertiesObject(type),
'observers': _buildObserversObject(type),
'listeners': _buildListenersObject(type),
+ 'behaviors': _buildBehaviorsList(type),
'__isPolymerDart__': true,
};
_setupLifecycleMethods(type, object);
@@ -44,7 +46,7 @@ Map<String, DeclarationMirror> propertyDeclarationsFor(Type type) {
}
// Set up the `properties` descriptor object.
-Map buildPropertiesObject(Type type) {
+Map _buildPropertiesObject(Type type) {
var declarations = propertyDeclarationsFor(type);
var properties = {};
declarations.forEach((String name, DeclarationMirror declaration) {
@@ -187,6 +189,23 @@ Map _getPropertyInfoForType(Type type, DeclarationMirror declaration) {
return property;
}
+/// List of [JsObjects]s representing the behaviors for an element.
+List<JsObject> _buildBehaviorsList(Type type) {
+ var behaviors = <JsObject>[];
+
+ isBehavior(instance) => instance is BehaviorInterface;
+
+ var interfaces = mixinsFor(type, jsProxyReflectable,
Siggi Cherem (dart-lang) 2015/08/12 22:43:15 Seems like we are visiting each behavior annotatio
jakemac 2015/08/13 17:50:45 I didn't add mixinForEach, but I did modify it to
+ where: (ClassMirror mixin) => mixin.metadata.any(isBehavior));
+ for (var interface in interfaces) {
+ behaviors.add(
+ (interface.metadata.firstWhere(isBehavior) as BehaviorInterface)
+ .getBehavior(interface.reflectedType));
+ }
+
+ return behaviors.isEmpty ? null : behaviors;
+}
+
/// Given a [Type] return the [JsObject] representation of that type.
/// TODO(jakemac): Make this more robust, specifically around Lists.
dynamic jsType(Type type) {

Powered by Google App Engine
This is Rietveld 408576698