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

Commit 96d46c5

Browse files
committed
chore(compiler): Move ViewFactory into WalkingViewFactory
1 parent 811b460 commit 96d46c5

File tree

4 files changed

+31
-19
lines changed

4 files changed

+31
-19
lines changed

lib/core_dom/compiler.dart

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
part of angular.core.dom;
22

3+
abstract class Compiler implements Function {
4+
WalkingViewFactory call(List<dom.Node> elements, DirectiveMap directives);
5+
}
6+
37
@NgInjectableService()
4-
class Compiler implements Function {
8+
class WalkingCompiler implements Compiler {
59
final Profiler _perf;
610
final Expando _expando;
711

8-
Compiler(this._perf, this._expando);
12+
WalkingCompiler(this._perf, this._expando);
913

1014
List<ElementBinderTreeRef> _compileView(NodeCursor domCursor, NodeCursor templateCursor,
1115
ElementBinder existingElementBinder,
@@ -22,7 +26,7 @@ class Compiler implements Function {
2226
: existingElementBinder;
2327

2428
if (elementBinder.hasTemplate) {
25-
elementBinder.templateViewFactory = compileTransclusion(
29+
elementBinder.templateViewFactory = _compileTransclusion(
2630
domCursor, templateCursor,
2731
elementBinder.template, elementBinder.templateBinder, directives);
2832
}
@@ -50,7 +54,7 @@ class Compiler implements Function {
5054
return elementBinders;
5155
}
5256

53-
ViewFactory compileTransclusion(
57+
WalkingViewFactory _compileTransclusion(
5458
NodeCursor domCursor, NodeCursor templateCursor,
5559
DirectiveRef directiveRef,
5660
ElementBinder transcludedElementBinder,
@@ -66,7 +70,7 @@ class Compiler implements Function {
6670
_compileView(domCursor, transcludeCursor, transcludedElementBinder, directives);
6771
if (elementBinders == null) elementBinders = [];
6872

69-
viewFactory = new ViewFactory(transcludeCursor.elements, elementBinders, _perf, _expando);
73+
viewFactory = new WalkingViewFactory(transcludeCursor.elements, elementBinders, _perf, _expando);
7074
domCursor.index = domCursorIndex;
7175

7276
if (domCursor.isInstance) {
@@ -84,7 +88,7 @@ class Compiler implements Function {
8488
return viewFactory;
8589
}
8690

87-
ViewFactory call(List<dom.Node> elements, DirectiveMap directives) {
91+
WalkingViewFactory call(List<dom.Node> elements, DirectiveMap directives) {
8892
var timerId;
8993
assert((timerId = _perf.startTimer('ng.compile', _html(elements))) != false);
9094
final List<dom.Node> domElements = elements;
@@ -93,7 +97,7 @@ class Compiler implements Function {
9397
new NodeCursor(domElements), new NodeCursor(templateElements),
9498
null, directives);
9599

96-
var viewFactory = new ViewFactory(templateElements,
100+
var viewFactory = new WalkingViewFactory(templateElements,
97101
elementBinders == null ? [] : elementBinders, _perf, _expando);
98102

99103
assert(_perf.stopTimer(timerId) != false);

lib/core_dom/module.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class NgCoreDomModule extends Module {
3939
type(NgTextMustacheDirective);
4040
type(NgAttrMustacheDirective);
4141

42-
type(Compiler);
42+
type(Compiler, implementedBy: WalkingCompiler);
4343
type(Http);
4444
type(UrlRewriter);
4545
type(HttpBackend);

lib/core_dom/view_factory.dart

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,23 @@ class BoundViewFactory {
1919
viewFactory(injector.createChild([new Module()..value(Scope, scope)]));
2020
}
2121

22+
abstract class ViewFactory implements Function {
23+
BoundViewFactory bind(Injector injector);
24+
25+
View call(Injector injector, [List<dom.Node> elements]);
26+
}
27+
2228
/**
2329
* ViewFactory is used to create new [View]s. ViewFactory is created by the
2430
* [Compiler] as a result of compiling a template.
2531
*/
26-
class ViewFactory implements Function {
32+
class WalkingViewFactory implements ViewFactory {
2733
final List<ElementBinderTreeRef> elementBinders;
2834
final List<dom.Node> templateElements;
2935
final Profiler _perf;
3036
final Expando _expando;
3137

32-
ViewFactory(this.templateElements, this.elementBinders, this._perf, this._expando) {
38+
WalkingViewFactory(this.templateElements, this.elementBinders, this._perf, this._expando) {
3339
assert(elementBinders.forEach((ElementBinderTreeRef eb) { assert(eb is ElementBinderTreeRef); }) != true);
3440
}
3541

@@ -62,6 +68,7 @@ class ViewFactory implements Function {
6268
//List childElementBinders = eb.childElementBinders;
6369
int nodeListIndex = index + preRenderedIndexOffset;
6470
dom.Node node = nodeList[nodeListIndex];
71+
var binder = tree.binder;
6572

6673
var timerId;
6774
try {
@@ -75,16 +82,16 @@ class ViewFactory implements Function {
7582
parentNode.append(node);
7683
}
7784

78-
var childInjector = tree.binder != null ? tree.binder.bind(view, parentInjector, node) : parentInjector;
79-
80-
if (tree.subtrees != null) {
81-
_link(view, node.nodes, tree.subtrees, childInjector);
82-
}
85+
var childInjector = binder != null ? binder.bind(view, parentInjector, node) : parentInjector;
8386

8487
if (fakeParent) {
8588
// extract the node from the parentNode.
8689
nodeList[nodeListIndex] = parentNode.nodes[0];
8790
}
91+
92+
if (tree.subtrees != null) {
93+
_link(view, node.nodes, tree.subtrees, childInjector);
94+
}
8895
} finally {
8996
assert(_perf.stopTimer(timerId) != false);
9097
}

test/core_dom/view_spec.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class BFilter {
6060

6161

6262
main() {
63+
var viewFactoryFactory = (a,b,c,d) => new WalkingViewFactory(a,b,c,d);
6364
describe('View', () {
6465
var anchor;
6566
var $rootElement;
@@ -77,8 +78,8 @@ main() {
7778
$rootElement.html('<!-- anchor -->');
7879
anchor = new ViewPort($rootElement.contents().eq(0)[0],
7980
injector.get(NgAnimate));
80-
a = (new ViewFactory($('<span>A</span>a'), [], perf, expando))(injector);
81-
b = (new ViewFactory($('<span>B</span>b'), [], perf, expando))(injector);
81+
a = (viewFactoryFactory($('<span>A</span>a'), [], perf, expando))(injector);
82+
b = (viewFactoryFactory($('<span>B</span>b'), [], perf, expando))(injector);
8283
}));
8384

8485

@@ -141,10 +142,10 @@ main() {
141142
LoggerViewDirective,
142143
new NgDirective(children: NgAnnotation.TRANSCLUDE_CHILDREN, selector: 'foo'),
143144
'');
144-
directiveRef.viewFactory = new ViewFactory($('<b>text</b>'), [], perf, new Expando());
145+
directiveRef.viewFactory = viewFactoryFactory($('<b>text</b>'), [], perf, new Expando());
145146
var binder = ebf.binder();
146147
binder.setTemplateInfo(0, [ directiveRef ]);
147-
var outerViewType = new ViewFactory(
148+
var outerViewType = viewFactoryFactory(
148149
$('<!--start--><!--end-->'),
149150
[binder],
150151
perf,

0 commit comments

Comments
 (0)