refactor(ElementInjector): use index instead of the elementInjector field to instantiate element injectors

This commit is contained in:
vsavkin
2014-11-04 17:03:35 -08:00
parent 7908533336
commit b5f6417635
7 changed files with 38 additions and 94 deletions

View File

@ -93,39 +93,7 @@ ElementInjector (ElementModule):
PERF BENCHMARK: http://www.williambrownstreet.net/blog/2014/04/faster-angularjs-rendering-angularjs-and-reactjs/
*/
export class ProtoElementInjector extends TreeNode {
/**
parent:ProtoDirectiveInjector;
next:ProtoDirectiveInjector;
prev:ProtoDirectiveInjector;
head:ProtoDirectiveInjector;
tail:ProtoDirectiveInjector;
DirectiveInjector cloningInstance;
KeyMap keyMap;
/// Because DI tree is sparse, this shows how far away is the Parent DI
parentDistance:int = 1; /// 1 for non-sparse/normal depth.
cKey:int; cFactory:Function; cParams:List<int>;
_keyId0:int; factory0:Function; params0:List<int>;
_keyId1:int; factory1:Function; params1:List<int>;
_keyId2:int; factory2:Function; params2:List<int>;
_keyId3:int; factory3:Function; params3:List<int>;
_keyId4:int; factory4:Function; params4:List<int>;
_keyId5:int; factory5:Function; params5:List<int>;
_keyId6:int; factory6:Function; params6:List<int>;
_keyId7:int; factory7:Function; params7:List<int>;
_keyId8:int; factory8:Function; params8:List<int>;
_keyId9:int; factory9:Function; params9:List<int>;
query_keyId0:int;
query_keyId1:int;
textNodes:List<int>;
events:Map<string, Expression>;
elementInjector:ElementInjector;
*/
@FIELD('_elementInjector:ElementInjector')
export class ProtoElementInjector {
@FIELD('_binding0:Binding')
@FIELD('_binding1:Binding')
@FIELD('_binding2:Binding')
@ -146,10 +114,11 @@ export class ProtoElementInjector extends TreeNode {
@FIELD('_key7:int')
@FIELD('_key8:int')
@FIELD('_key9:int')
constructor(parent:ProtoElementInjector, bindings:List) {
super(parent);
this._elementInjector = null;
@FIELD('final parent:ProtoElementInjector')
@FIELD('final index:int')
constructor(parent:ProtoElementInjector, index:int, bindings:List) {
this.parent = parent;
this.index = index;
this._binding0 = null; this._keyId0 = null;
this._binding1 = null; this._keyId1 = null;
@ -179,15 +148,12 @@ export class ProtoElementInjector extends TreeNode {
}
}
instantiate({view}):ElementInjector {
var p = this._parent;
var parentElementInjector = p === null ? null : p._elementInjector;
this._elementInjector = new ElementInjector({
instantiate({view, parentElementInjector}):ElementInjector {
return new ElementInjector({
proto: this,
parent: parentElementInjector,
view: view
});
return this._elementInjector;
}
_createBinding(bindingOrType) {
@ -198,10 +164,6 @@ export class ProtoElementInjector extends TreeNode {
return new Binding(b.key, b.factory, deps, b.providedAsPromise);
}
clearElementInjector() {
this._elementInjector = null;
}
get hasBindings():boolean {
return isPresent(this._binding0);
}

View File

@ -99,13 +99,9 @@ export class ProtoView {
static _createElementInjectors(elements, binders) {
var injectors = ListWrapper.createFixedSize(binders.length);
for (var i = 0; i < binders.length; ++i) {
injectors[i] = ProtoView._createElementInjector(
elements[i], binders[i].protoElementInjector);
}
// Cannot be rolled into loop above, because parentInjector pointers need
// to be set on the children.
for (var i = 0; i < binders.length; ++i) {
binders[i].protoElementInjector.clearElementInjector();
var proto = binders[i].protoElementInjector;
var parentElementInjector = isPresent(proto.parent) ? injectors[proto.parent.index] : null;
injectors[i] = ProtoView._createElementInjector(elements[i], parentElementInjector, proto);
}
return injectors;
}
@ -117,9 +113,9 @@ export class ProtoView {
}
}
static _createElementInjector(element, proto) {
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}) : null;
return proto.hasBindings ? proto.instantiate({view:null, parentElementInjector:parent}) : null;
}
static _rootElementInjectors(injectors) {