From c48433e0350d4b374614eef8a0c9036805535dcb Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 27 Jan 2014 11:29:45 -0800 Subject: [PATCH] fix(Directive): remove publishAs from NgDirective to avoid confusion. Closes# 396 --- lib/core/directive.dart | 35 +++++++++++++++++--------------- lib/core_dom/block_factory.dart | 6 ++++-- test/core_dom/compiler_spec.dart | 2 +- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/lib/core/directive.dart b/lib/core/directive.dart index e88db4aa9..c8f1bb470 100644 --- a/lib/core/directive.dart +++ b/lib/core/directive.dart @@ -136,18 +136,10 @@ abstract class NgAnnotation { */ final List 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 [], @@ -208,7 +200,7 @@ class NgComponent extends NgAnnotation { if (cssUrls != null && cssUrl != null) return [cssUrl]..addAll(cssUrls); } -/** + /** * Set the shadow root applyAuthorStyles property. See shadow-DOM * documentation for further details. */ @@ -220,6 +212,13 @@ class NgComponent extends NgAnnotation { */ 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, @@ -227,7 +226,7 @@ class NgComponent extends NgAnnotation { this.cssUrls, this.applyAuthorStyles, this.resetStyleInheritance, - publishAs, + this.publishAs, map, selector, visibility, @@ -238,7 +237,6 @@ class NgComponent extends NgAnnotation { children: NgAnnotation.COMPILE_CHILDREN, visibility: visibility, publishTypes: publishTypes, - publishAs: publishAs, map: map, exportExpressions: exportExpressions, exportExpressionAttrs: exportExpressionAttrs); @@ -282,7 +280,6 @@ class NgDirective extends NgAnnotation { const NgDirective({ children: NgAnnotation.COMPILE_CHILDREN, - publishAs, map, selector, visibility, @@ -290,14 +287,13 @@ class NgDirective extends NgAnnotation { exportExpressions, exportExpressionAttrs }) : super(selector: selector, children: children, visibility: visibility, - publishTypes: publishTypes, publishAs: publishAs, map: map, + publishTypes: publishTypes, map: map, exportExpressions: exportExpressions, exportExpressionAttrs: exportExpressionAttrs); NgAnnotation cloneWithNewMap(newMap) => new NgDirective( children: children, - publishAs: publishAs, map: newMap, selector: selector, visibility: visibility, @@ -327,9 +323,16 @@ class NgController extends NgDirective { 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, - publishAs, + this.publishAs, map, selector, visibility, @@ -337,7 +340,7 @@ class NgController extends NgDirective { exportExpressions, exportExpressionAttrs }) : super(selector: selector, children: children, visibility: visibility, - publishTypes: publishTypes, publishAs: publishAs, map: map, + publishTypes: publishTypes, map: map, exportExpressions: exportExpressions, exportExpressionAttrs: exportExpressionAttrs); diff --git a/lib/core_dom/block_factory.dart b/lib/core_dom/block_factory.dart index 9491bb64c..ccde9117d 100644 --- a/lib/core_dom/block_factory.dart +++ b/lib/core_dom/block_factory.dart @@ -191,8 +191,10 @@ class BlockFactory { probe.directives.add(controller); assert((linkMapTimer = _perf.startTimer('ng.block.link.map', ref.type)) != false); var shadowScope = (fctrs != null && fctrs.containsKey(ref.type)) ? fctrs[ref.type].shadowScope : null; - if (ref.annotation.publishAs != null) { - (shadowScope == null ? scope : shadowScope)[ref.annotation.publishAs] = controller; + if (ref.annotation is NgController) { + scope[(ref.annotation as NgController).publishAs] = controller; + } else if (ref.annotation is NgComponent) { + shadowScope[(ref.annotation as NgComponent).publishAs] = controller; } if (nodeAttrs == null) nodeAttrs = new _AnchorAttrs(ref); for(var map in ref.mappings) { diff --git a/test/core_dom/compiler_spec.dart b/test/core_dom/compiler_spec.dart index 102f71946..4faf6fe4d 100644 --- a/test/core_dom/compiler_spec.dart +++ b/test/core_dom/compiler_spec.dart @@ -691,7 +691,7 @@ class PublishMeComponent { } -@NgDirective ( +@NgController ( selector: '[publish-me]', publishAs: 'ctrlName' )