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

Node injector should provide both BoundBlockFactory and BlockFactory for transcluding directives. #62

Merged
merged 1 commit into from
Jul 31, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/block.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class Block implements ElementWrapper {
if (directiveRefs == null || directiveRefs.length == 0) return parentInjector;
var nodeModule = new Module();
var blockHoleFactory = () => null;
var blockFactory = () => null;
var boundBlockFactory = () => null;
var nodeAttrs = new NodeAttrs(node);

Expand Down Expand Up @@ -118,11 +119,13 @@ class Block implements ElementWrapper {
}
nodeAttrs[ref.directive.$name] = ref.value;
if (ref.directive.isStructural) {
blockHoleFactory = (Injector injector) => new BlockHole([node]);
blockHoleFactory = () => new BlockHole([node]);
blockFactory = () => ref.blockFactory;
boundBlockFactory = (Injector injector) => ref.blockFactory.bind(injector);
}
});
nodeModule.factory(BlockHole, blockHoleFactory);
nodeModule.factory(BlockFactory, blockFactory);
nodeModule.factory(BoundBlockFactory, boundBlockFactory);
var nodeInjector = parentInjector.createChild([nodeModule]);
directiveRefs.forEach((ref) => nodeInjector.get(ref.directive.type));
Expand Down
10 changes: 9 additions & 1 deletion test/block_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@ import "_specs.dart";

@NgDirective(transclude: true, selector: 'foo')
class LoggerBlockDirective {
LoggerBlockDirective(BlockHole hole, BoundBlockFactory boundBlockFactory, Logger logger) {
LoggerBlockDirective(BlockHole hole, BlockFactory blockFactory,
BoundBlockFactory boundBlockFactory, Logger logger) {
if (hole == null) {
throw new ArgumentError('BlockHole must be injected.');
}
if (boundBlockFactory == null) {
throw new ArgumentError('BoundBlockFactory must be injected.');
}
if (blockFactory == null) {
throw new ArgumentError('BlockFactory must be injected.');
}
logger.add(hole);
logger.add(boundBlockFactory);
logger.add(blockFactory);
}
}

Expand Down