refactor(ProtoElementInjector): change `instantiate` to take positional args

This commit is contained in:
vsavkin 2014-11-06 10:13:07 -08:00
parent b5f6417635
commit 9448d78aa8
6 changed files with 15 additions and 18 deletions

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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();

View File

@ -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;

View File

@ -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) {

View File

@ -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'],