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

Commit

Permalink
fix(compiler): change compiler to support attribute mapping for templ…
Browse files Browse the repository at this point in the history
…ate decorators

Closes #1581
  • Loading branch information
vsavkin authored and rkirov committed Dec 16, 2014
1 parent c1dd60f commit d658909
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
12 changes: 9 additions & 3 deletions lib/core_dom/view_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,18 @@ class ViewFactoryCache {
class _AnchorAttrs extends NodeAttrs {
DirectiveRef _directiveRef;

_AnchorAttrs(DirectiveRef this._directiveRef): super(null);
_AnchorAttrs(DirectiveRef directiveRef)
: super(directiveRef.element),
_directiveRef = directiveRef;

String operator [](name) => name == '.' ? _directiveRef.value : null;
String operator [](name) => name == '.' ? _directiveRef.value : super[name];

void observe(String attributeName, _AttributeChanged notifyFn) {
notifyFn(attributeName == '.' ? _directiveRef.value : null);
if (attributeName == '.') {
notifyFn(_directiveRef.value);
} else {
super.observe(attributeName, notifyFn);
}
}
}

Expand Down
25 changes: 24 additions & 1 deletion test/core_dom/compiler_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ void main() {
..bind(Parent, toValue: null)
..bind(Child)
..bind(ChildTemplateComponent)
..bind(InjectorDependentComponent);
..bind(InjectorDependentComponent)
..bind(TranscludeChildrenWithAttributeDirective);
});

beforeEach((TestBed tb) => _ = tb);
Expand Down Expand Up @@ -1149,6 +1150,14 @@ void main() {
expect(logger).toContain('LazyPane-0');
}));
});

it('should set attributes on a directive transcluding its children', () {
_.compile('<div><transclude-children-with-attr attr="value"/></div>');
_.rootScope.apply();

var dir = _.rootScope.context['transclude-children-with-attr'];
expect(dir.attr).toEqual('value');
});
}));
}

Expand Down Expand Up @@ -1234,6 +1243,20 @@ class SimpleTranscludeInAttachAttrDirective {
}
}

@Decorator(
children: Directive.TRANSCLUDE_CHILDREN,
selector:'transclude-children-with-attr',
map: const {
'attr': '@attr'
})
class TranscludeChildrenWithAttributeDirective {
var attr;

TranscludeChildrenWithAttributeDirective(RootScope scope) {
scope.context['transclude-children-with-attr'] = this;
}
}

@Decorator(selector: '[include-transclude]')
class IncludeTranscludeAttrDirective {
IncludeTranscludeAttrDirective(SimpleTranscludeInAttachAttrDirective simple, Logger log) {
Expand Down

0 comments on commit d658909

Please sign in to comment.