Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Commit

Permalink
fix(Directive): remove publishAs from NgDirective to avoid confusion.
Browse files Browse the repository at this point in the history
Closes# 396
  • Loading branch information
mhevery committed Jan 27, 2014
1 parent 51e167b commit c48433e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
35 changes: 19 additions & 16 deletions lib/core/directive.dart
Expand Up @@ -136,18 +136,10 @@ abstract class NgAnnotation {
*/
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 [],
Expand Down Expand Up @@ -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.
*/
Expand All @@ -220,14 +212,21 @@ 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,
this.cssUrl,
this.cssUrls,
this.applyAuthorStyles,
this.resetStyleInheritance,
publishAs,
this.publishAs,
map,
selector,
visibility,
Expand All @@ -238,7 +237,6 @@ class NgComponent extends NgAnnotation {
children: NgAnnotation.COMPILE_CHILDREN,
visibility: visibility,
publishTypes: publishTypes,
publishAs: publishAs,
map: map,
exportExpressions: exportExpressions,
exportExpressionAttrs: exportExpressionAttrs);
Expand Down Expand Up @@ -282,22 +280,20 @@ class NgDirective extends NgAnnotation {

const NgDirective({
children: NgAnnotation.COMPILE_CHILDREN,
publishAs,
map,
selector,
visibility,
publishTypes : const <Type>[],
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,
Expand Down Expand Up @@ -327,17 +323,24 @@ 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,
publishTypes : const <Type>[],
exportExpressions,
exportExpressionAttrs
}) : super(selector: selector, children: children, visibility: visibility,
publishTypes: publishTypes, publishAs: publishAs, map: map,
publishTypes: publishTypes, map: map,
exportExpressions: exportExpressions,
exportExpressionAttrs: exportExpressionAttrs);

Expand Down
6 changes: 4 additions & 2 deletions lib/core_dom/block_factory.dart
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion test/core_dom/compiler_spec.dart
Expand Up @@ -691,7 +691,7 @@ class PublishMeComponent {
}


@NgDirective (
@NgController (
selector: '[publish-me]',
publishAs: 'ctrlName'
)
Expand Down

3 comments on commit c48433e

@jbdeboer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks a number of apps in-the-wild.

@pavelgj
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be a trivial fix... scope['ctrl'] = this;

@mhevery
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are still not v1.0, so this is the time for breaking changes.

Please sign in to comment.