From 9448d78aa87e7b7bc7cdd92c4030d3ff545fa01b Mon Sep 17 00:00:00 2001 From: vsavkin Date: Thu, 6 Nov 2014 10:13:07 -0800 Subject: [PATCH] refactor(ProtoElementInjector): change `instantiate` to take positional args --- .../src/element_injector/instantiate_benchmark.js | 2 +- .../instantiate_benchmark_codegen.js | 2 +- .../instantiate_directive_benchmark.js | 2 +- modules/core/src/compiler/element_injector.js | 11 ++++------- modules/core/src/compiler/view.js | 2 +- .../core/test/compiler/element_injector_spec.js | 14 +++++++------- 6 files changed, 15 insertions(+), 18 deletions(-) diff --git a/modules/benchmarks/src/element_injector/instantiate_benchmark.js b/modules/benchmarks/src/element_injector/instantiate_benchmark.js index b6bb3d6980..ef27f15180 100644 --- a/modules/benchmarks/src/element_injector/instantiate_benchmark.js +++ b/modules/benchmarks/src/element_injector/instantiate_benchmark.js @@ -10,7 +10,7 @@ export function run () { var bindings = [A, B, C]; var proto = new ProtoElementInjector(null, 0, bindings); for (var i = 0; i < ITERATIONS; ++i) { - var ei = proto.instantiate({view:null, parentElementInjector: null}); + var ei = proto.instantiate(null,null); ei.instantiateDirectives(appInjector); } } diff --git a/modules/benchmarks/src/element_injector/instantiate_benchmark_codegen.js b/modules/benchmarks/src/element_injector/instantiate_benchmark_codegen.js index 94d9b39dd1..065ddb8f59 100644 --- a/modules/benchmarks/src/element_injector/instantiate_benchmark_codegen.js +++ b/modules/benchmarks/src/element_injector/instantiate_benchmark_codegen.js @@ -18,7 +18,7 @@ export function run () { var proto = new ProtoElementInjector(null, 0, bindings); for (var i = 0; i < ITERATIONS; ++i) { - var ei = proto.instantiate({view:null, parentElementInjector: null}); + var ei = proto.instantiate(null,null); ei.instantiateDirectives(appInjector); } } diff --git a/modules/benchmarks/src/element_injector/instantiate_directive_benchmark.js b/modules/benchmarks/src/element_injector/instantiate_directive_benchmark.js index 8dc6d4a71f..4a0e814df1 100644 --- a/modules/benchmarks/src/element_injector/instantiate_directive_benchmark.js +++ b/modules/benchmarks/src/element_injector/instantiate_directive_benchmark.js @@ -9,7 +9,7 @@ export function run () { var bindings = [A, B, C]; var proto = new ProtoElementInjector(null, 0, bindings); - var ei = proto.instantiate({view:null, parentElementInjector: null}); + var ei = proto.instantiate(null,null); for (var i = 0; i < ITERATIONS; ++i) { ei.clearDirectives(); diff --git a/modules/core/src/compiler/element_injector.js b/modules/core/src/compiler/element_injector.js index 8169eda863..099210952c 100644 --- a/modules/core/src/compiler/element_injector.js +++ b/modules/core/src/compiler/element_injector.js @@ -3,6 +3,7 @@ import {Math} from 'facade/math'; import {List, ListWrapper} from 'facade/collection'; import {Injector, Key, Dependency, bind, Binding, NoProviderError, ProviderError, CyclicDependencyError} from 'di/di'; import {Parent, Ancestor} from 'core/annotations/visibility'; +import {View} from './view'; import {StaticKeys} from './static_keys'; var _MAX_DIRECTIVE_CONSTRUCTION_COUNTER = 10; @@ -148,12 +149,8 @@ export class ProtoElementInjector { } } - instantiate({view, parentElementInjector}):ElementInjector { - return new ElementInjector({ - proto: this, - parent: parentElementInjector, - view: view - }); + instantiate(parent:ElementInjector, view):ElementInjector { + return new ElementInjector(this, parent, view); } _createBinding(bindingOrType) { @@ -226,7 +223,7 @@ export class ElementInjector extends TreeNode { @FIELD('_obj8:Object') @FIELD('_obj9:Object') @FIELD('_view:View') - constructor({proto, parent, view}) { + constructor(proto:ProtoElementInjector, parent:ElementInjector, view) { super(parent); this._proto = proto; this._view = view; diff --git a/modules/core/src/compiler/view.js b/modules/core/src/compiler/view.js index 7ae5ed6282..d289bc24b4 100644 --- a/modules/core/src/compiler/view.js +++ b/modules/core/src/compiler/view.js @@ -115,7 +115,7 @@ export class ProtoView { static _createElementInjector(element, parent:ElementInjector, proto:ProtoElementInjector) { //TODO: vsavkin: pass element to `proto.instantiate()` once https://github.com/angular/angular/pull/98 is merged - return proto.hasBindings ? proto.instantiate({view:null, parentElementInjector:parent}) : null; + return proto.hasBindings ? proto.instantiate(parent, null) : null; } static _rootElementInjectors(injectors) { diff --git a/modules/core/test/compiler/element_injector_spec.js b/modules/core/test/compiler/element_injector_spec.js index 9f5fada26b..0814e49f7f 100644 --- a/modules/core/test/compiler/element_injector_spec.js +++ b/modules/core/test/compiler/element_injector_spec.js @@ -68,10 +68,10 @@ export function main() { function injector(bindings, appInjector = null, props = null) { if (isBlank(appInjector)) appInjector = new Injector([]); - if (isBlank(props)) props = {}; + if (isBlank(props)) props = {"view" : null}; var proto = new ProtoElementInjector(null, 0, bindings); - var inj = proto.instantiate({view: props["view"], parentElementInjector:null}); + var inj = proto.instantiate(null, props["view"]); inj.instantiateDirectives(appInjector); return inj; } @@ -80,11 +80,11 @@ export function main() { var inj = new Injector([]); var protoParent = new ProtoElementInjector(null, 0, parentBindings); - var parent = protoParent.instantiate({view: null, parentElementInjector: null}); + var parent = protoParent.instantiate(null, null); parent.instantiateDirectives(inj); var protoChild = new ProtoElementInjector(protoParent, 1, childBindings); - var child = protoChild.instantiate({view: null, parentElementInjector: parent}); + var child = protoChild.instantiate(parent, null); child.instantiateDirectives(inj); return child; @@ -97,9 +97,9 @@ export function main() { var protoChild1 = new ProtoElementInjector(protoParent, 1, []); var protoChild2 = new ProtoElementInjector(protoParent, 2, []); - var p = protoParent.instantiate({view: null, parentElementInjector: null}); - var c1 = protoChild1.instantiate({view: null, parentElementInjector: p}); - var c2 = protoChild2.instantiate({view: null, parentElementInjector: p}); + var p = protoParent.instantiate(null, null); + var c1 = protoChild1.instantiate(p, null); + var c2 = protoChild2.instantiate(p, null); expect(humanize(p, [ [p, 'parent'],