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

Unified Diff: third_party/pkg/angular/lib/core/directive.dart

Issue 180843004: Revert revision 33053 (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 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
Index: third_party/pkg/angular/lib/core/directive.dart
===================================================================
--- third_party/pkg/angular/lib/core/directive.dart (revision 33054)
+++ third_party/pkg/angular/lib/core/directive.dart (working copy)
@@ -116,7 +116,7 @@
* that mapping is bi-directional. A change either in field or on
* parent scope will result in change to the other.
*
- * * `&onChange` maps the expression into the controller `onChange`
+ * * `&onChange` maps the expression into tho controllers `onChange`
* field. The result of mapping is a callable function which can be
* invoked at any time by the controller. The invocation of the
* callable function will result in the expression `doSomething()` to
@@ -132,14 +132,22 @@
/**
* Use the list to specify a expressions which are evaluated dynamically
- * (ex. via [Scope.eval]) and are otherwise not statically discoverable.
+ * (ex. via [Scope.$eval]) and are otherwise not statically discoverable.
*/
final List<String> exportExpressions;
+ /**
+ * An expression under which the controller instance will be published into.
+ * This allows the expressions in the template to be referring to controller
+ * instance and its properties.
+ */
+ final String publishAs;
+
const NgAnnotation({
this.selector,
this.children: NgAnnotation.COMPILE_CHILDREN,
this.visibility: NgDirective.LOCAL_VISIBILITY,
+ this.publishAs,
this.publishTypes: const [],
this.map: const {},
this.exportExpressions: const [],
@@ -164,10 +172,10 @@
* ask for any injectable object in their constructor. Components
* can also ask for other components or directives declared on the DOM element.
*
- * Components can implement [NgAttachAware], [NgDetachAware],
- * [NgShadowRootAware] and declare these optional methods:
+ * Components can implement [NgAttachAware], [NgDetachAware], [NgShadowRootAware] and
+ * declare these optional methods:
*
- * * `attach()` - Called on first [Scope.apply()].
+ * * `attach()` - Called on first [Scope.$digest()].
* * `detach()` - Called on when owning scope is destroyed.
* * `onShadowRoot(ShadowRoot shadowRoot)` - Called when [ShadowRoot] is loaded.
*/
@@ -184,11 +192,23 @@
final String templateUrl;
/**
+ * A CSS URL to load into the shadow DOM.
+ */
+ final String cssUrl;
+
+ /**
* A list of CSS URLs to load into the shadow DOM.
*/
- final _cssUrls;
+ final List<String> cssUrls;
- /**
+ List<String> get allCssUrls {
+ if (cssUrls == null && cssUrl == null) return null;
+ if (cssUrls == null && cssUrl != null) return [cssUrl];
+ if (cssUrls != null && cssUrl == null) return cssUrls;
+ if (cssUrls != null && cssUrl != null) return [cssUrl]..addAll(cssUrls);
+ }
+
+/**
* Set the shadow root applyAuthorStyles property. See shadow-DOM
* documentation for further details.
*/
@@ -200,44 +220,35 @@
*/
final bool resetStyleInheritance;
- /**
- * An expression under which the component's controller instance will be
- * published into. This allows the expressions in the template to be referring
- * to controller instance and its properties.
- */
- final String publishAs;
-
const NgComponent({
this.template,
this.templateUrl,
- cssUrl,
+ this.cssUrl,
+ this.cssUrls,
this.applyAuthorStyles,
this.resetStyleInheritance,
- this.publishAs,
+ publishAs,
map,
selector,
visibility,
publishTypes : const <Type>[],
exportExpressions,
- exportExpressionAttrs})
- : _cssUrls = cssUrl,
- super(selector: selector,
+ exportExpressionAttrs
+ }) : super(selector: selector,
children: NgAnnotation.COMPILE_CHILDREN,
visibility: visibility,
publishTypes: publishTypes,
+ publishAs: publishAs,
map: map,
exportExpressions: exportExpressions,
exportExpressionAttrs: exportExpressionAttrs);
- List<String> get cssUrls => _cssUrls == null ?
- const [] :
- _cssUrls is List ? _cssUrls : [_cssUrls];
-
NgAnnotation cloneWithNewMap(newMap) =>
new NgComponent(
template: template,
templateUrl: templateUrl,
- cssUrl: cssUrls,
+ cssUrl: cssUrl,
+ cssUrls: cssUrls,
applyAuthorStyles: applyAuthorStyles,
resetStyleInheritance: resetStyleInheritance,
publishAs: publishAs,
@@ -261,7 +272,7 @@
* Directives can implement [NgAttachAware], [NgDetachAware] and
* declare these optional methods:
*
- * * `attach()` - Called on first [Scope.apply()].
+ * * `attach()` - Called on first [Scope.$digest()].
* * `detach()` - Called on when owning scope is destroyed.
*/
class NgDirective extends NgAnnotation {
@@ -269,20 +280,24 @@
static const String CHILDREN_VISIBILITY = 'children';
static const String DIRECT_CHILDREN_VISIBILITY = 'direct_children';
- const NgDirective({children: NgAnnotation.COMPILE_CHILDREN,
+ const NgDirective({
+ children: NgAnnotation.COMPILE_CHILDREN,
+ publishAs,
map,
selector,
visibility,
publishTypes : const <Type>[],
exportExpressions,
- exportExpressionAttrs}) : super(selector: selector, children: children, visibility: visibility,
- publishTypes: publishTypes, map: map,
+ exportExpressionAttrs
+ }) : super(selector: selector, children: children, visibility: visibility,
+ publishTypes: publishTypes, publishAs: publishAs, map: map,
exportExpressions: exportExpressions,
exportExpressionAttrs: exportExpressionAttrs);
NgAnnotation cloneWithNewMap(newMap) =>
new NgDirective(
children: children,
+ publishAs: publishAs,
map: newMap,
selector: selector,
visibility: visibility,
@@ -304,7 +319,7 @@
* Controllers can implement [NgAttachAware], [NgDetachAware] and
* declare these optional methods:
*
- * * `attach()` - Called on first [Scope.apply()].
+ * * `attach()` - Called on first [Scope.$digest()].
* * `detach()` - Called on when owning scope is destroyed.
*/
class NgController extends NgDirective {
@@ -312,16 +327,9 @@
static const String CHILDREN_VISIBILITY = 'children';
static const String DIRECT_CHILDREN_VISIBILITY = 'direct_children';
- /**
- * An expression under which the controller instance will be published into.
- * This allows the expressions in the template to be referring to controller
- * instance and its properties.
- */
- final String publishAs;
-
const NgController({
children: NgAnnotation.COMPILE_CHILDREN,
- this.publishAs,
+ publishAs,
map,
selector,
visibility,
@@ -329,7 +337,7 @@
exportExpressions,
exportExpressionAttrs
}) : super(selector: selector, children: children, visibility: visibility,
- publishTypes: publishTypes, map: map,
+ publishTypes: publishTypes, publishAs: publishAs, map: map,
exportExpressions: exportExpressions,
exportExpressionAttrs: exportExpressionAttrs);
@@ -424,3 +432,62 @@
void detach();
}
+@NgInjectableService()
+class DirectiveMap extends AnnotationsMap<NgAnnotation> {
+ DirectiveMap(Injector injector, MetadataExtractor metadataExtractor,
+ FieldMetadataExtractor fieldMetadataExtractor)
+ : super(injector, metadataExtractor) {
+ Map<NgAnnotation, List<Type>> directives = {};
+ forEach((NgAnnotation annotation, Type type) {
+ var match;
+ var fieldMetadata = fieldMetadataExtractor(type);
+ if (fieldMetadata.isNotEmpty) {
+ var newMap = annotation.map == null ? {} : new Map.from(annotation.map);
+ fieldMetadata.forEach((String fieldName, AttrFieldAnnotation ann) {
+ var attrName = ann.attrName;
+ if (newMap.containsKey(attrName)) {
+ throw 'Mapping for attribute $attrName is already defined (while '
+ 'processing annottation for field $fieldName of $type)';
+ }
+ newMap[attrName] = '${ann.mappingSpec}$fieldName';
+ });
+ annotation = annotation.cloneWithNewMap(newMap);
+ }
+ directives.putIfAbsent(annotation, () => []).add(type);
+ });
+ _map.clear();
+ _map.addAll(directives);
+ }
+}
+
+@NgInjectableService()
+class FieldMetadataExtractor {
+ List<TypeMirror> _fieldAnnotations = [reflectType(NgAttr),
+ reflectType(NgOneWay), reflectType(NgOneWayOneTime),
+ reflectType(NgTwoWay), reflectType(NgCallback)];
+
+ Map<String, AttrFieldAnnotation> call(Type type) {
+ ClassMirror cm = reflectType(type);
+ Map<String, AttrFieldAnnotation> fields = <String, AttrFieldAnnotation>{};
+ cm.declarations.forEach((Symbol name, DeclarationMirror decl) {
+ if (decl is VariableMirror ||
+ (decl is MethodMirror && (decl.isGetter || decl.isSetter))) {
+ var fieldName = MirrorSystem.getName(name);
+ if (decl is MethodMirror && decl.isSetter) {
+ // Remove = from the end of the setter.
+ fieldName = fieldName.substring(0, fieldName.length - 1);
+ }
+ decl.metadata.forEach((InstanceMirror meta) {
+ if (_fieldAnnotations.contains(meta.type)) {
+ if (fields[fieldName] != null) {
+ throw 'Attribute annotation for $fieldName is defined more '
+ 'than once in $type';
+ }
+ fields[fieldName] = meta.reflectee as AttrFieldAnnotation;
+ }
+ });
+ }
+ });
+ return fields;
+ }
+}
« no previous file with comments | « third_party/pkg/angular/lib/change_detection/watch_group.dart ('k') | third_party/pkg/angular/lib/core/exception_handler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698