refactor(change_detection): rename group memento into directive memento

This commit is contained in:
vsavkin
2015-02-06 13:35:05 -08:00
parent 1ec796a601
commit ab733bd80e
6 changed files with 55 additions and 59 deletions

View File

@ -156,7 +156,7 @@ function notifyTemplate(index:number):string{
return `
if (${CHANGES_LOCAL} && ${CHANGES_LOCAL}.length > 0) {
if(throwOnChange) ${UTIL}.throwOnChange(${PROTOS_ACCESSOR}[${index}], ${CHANGES_LOCAL}[0]);
${DISPATCHER_ACCESSOR}.onRecordChange(${PROTOS_ACCESSOR}[${index}].groupMemento, ${CHANGES_LOCAL});
${DISPATCHER_ACCESSOR}.onRecordChange(${PROTOS_ACCESSOR}[${index}].directiveMemento, ${CHANGES_LOCAL});
${CHANGES_LOCAL} = null;
}
`;
@ -388,7 +388,7 @@ export class ChangeDetectorJITGenerator {
}
genNotify(r):string{
return r.lastInGroup ? notifyTemplate(r.selfIndex - 1) : '';
return r.lastInDirective ? notifyTemplate(r.selfIndex - 1) : '';
}
genArgs(r:ProtoRecord):string {

View File

@ -47,10 +47,10 @@ function _selfRecord(r:ProtoRecord, contextIndex:number, selfIndex:number):Proto
contextIndex,
selfIndex,
r.bindingMemento,
r.groupMemento,
r.directiveMemento,
r.expressionAsString,
r.lastInBinding,
r.lastInGroup
r.lastInDirective
);
}
@ -75,10 +75,10 @@ function _replaceIndices(r:ProtoRecord, selfIndex:number, indexMap:Map) {
contextIndex,
selfIndex,
r.bindingMemento,
r.groupMemento,
r.directiveMemento,
r.expressionAsString,
r.lastInBinding,
r.lastInGroup
r.lastInDirective
);
}

View File

@ -54,22 +54,19 @@ export class DynamicChangeDetector extends AbstractChangeDetector {
var protos:List<ProtoRecord> = this.protos;
var updatedRecords = null;
var currentGroup = null;
for (var i = 0; i < protos.length; ++i) {
var proto:ProtoRecord = protos[i];
var change = this._check(proto);
if (isPresent(change)) {
currentGroup = proto.groupMemento;
var record = ChangeDetectionUtil.changeRecord(proto.bindingMemento, change);
updatedRecords = ChangeDetectionUtil.addRecord(updatedRecords, record);
}
if (proto.lastInGroup && isPresent(updatedRecords)) {
if (proto.lastInDirective && isPresent(updatedRecords)) {
if (throwOnChange) ChangeDetectionUtil.throwOnChange(proto, updatedRecords[0]);
this.dispatcher.onRecordChange(currentGroup, updatedRecords);
this.dispatcher.onRecordChange(proto.directiveMemento, updatedRecords);
updatedRecords = null;
}
}

View File

@ -45,7 +45,7 @@ export const CHECK_ALWAYS="ALWAYS_CHECK";
export const DETACHED="DETACHED";
export class ChangeDispatcher {
onRecordChange(groupMemento, records:List<ChangeRecord>) {}
onRecordChange(directiveMemento, records:List<ChangeRecord>) {}
}
export class ChangeDetector {

View File

@ -53,9 +53,9 @@ export class ProtoRecord {
contextIndex:number;
selfIndex:number;
bindingMemento:any;
groupMemento:any;
directiveMemento:any;
lastInBinding:boolean;
lastInGroup:boolean;
lastInDirective:boolean;
expressionAsString:string;
constructor(mode:number,
@ -66,10 +66,10 @@ export class ProtoRecord {
contextIndex:number,
selfIndex:number,
bindingMemento:any,
groupMemento:any,
directiveMemento:any,
expressionAsString:string,
lastInBinding:boolean,
lastInGroup:boolean) {
lastInDirective:boolean) {
this.mode = mode;
this.name = name;
@ -79,9 +79,9 @@ export class ProtoRecord {
this.contextIndex = contextIndex;
this.selfIndex = selfIndex;
this.bindingMemento = bindingMemento;
this.groupMemento = groupMemento;
this.directiveMemento = directiveMemento;
this.lastInBinding = lastInBinding;
this.lastInGroup = lastInGroup;
this.lastInDirective = lastInDirective;
this.expressionAsString = expressionAsString;
}
@ -93,7 +93,7 @@ export class ProtoRecord {
}
export class ProtoChangeDetector {
addAst(ast:AST, bindingMemento:any, groupMemento:any = null, structural:boolean = false){}
addAst(ast:AST, bindingMemento:any, directiveMemento:any = null, structural:boolean = false){}
instantiate(dispatcher:any, formatters:Map):ChangeDetector{
return null;
}
@ -108,8 +108,8 @@ export class DynamicProtoChangeDetector extends ProtoChangeDetector {
this._recordBuilder = new ProtoRecordBuilder();
}
addAst(ast:AST, bindingMemento:any, groupMemento:any = null, structural:boolean = false) {
this._recordBuilder.addAst(ast, bindingMemento, groupMemento, structural);
addAst(ast:AST, bindingMemento:any, directiveMemento:any = null, structural:boolean = false) {
this._recordBuilder.addAst(ast, bindingMemento, directiveMemento, structural);
}
instantiate(dispatcher:any, formatters:Map) {
@ -135,8 +135,8 @@ export class JitProtoChangeDetector extends ProtoChangeDetector {
this._recordBuilder = new ProtoRecordBuilder();
}
addAst(ast:AST, bindingMemento:any, groupMemento:any = null, structural:boolean = false) {
this._recordBuilder.addAst(ast, bindingMemento, groupMemento, structural);
addAst(ast:AST, bindingMemento:any, directiveMemento:any = null, structural:boolean = false) {
this._recordBuilder.addAst(ast, bindingMemento, directiveMemento, structural);
}
instantiate(dispatcher:any, formatters:Map) {
@ -161,19 +161,19 @@ class ProtoRecordBuilder {
this.records = [];
}
addAst(ast:AST, bindingMemento:any, groupMemento:any = null, structural:boolean = false) {
addAst(ast:AST, bindingMemento:any, directiveMemento:any = null, structural:boolean = false) {
if (structural) ast = new Structural(ast);
var last = ListWrapper.last(this.records);
if (isPresent(last) && last.groupMemento == groupMemento) {
last.lastInGroup = false;
if (isPresent(last) && last.directiveMemento == directiveMemento) {
last.lastInDirective = false;
}
var pr = _ConvertAstIntoProtoRecords.convert(ast, bindingMemento, groupMemento, this.records.length);
var pr = _ConvertAstIntoProtoRecords.convert(ast, bindingMemento, directiveMemento, this.records.length);
if (! ListWrapper.isEmpty(pr)) {
var last = ListWrapper.last(pr);
last.lastInBinding = true;
last.lastInGroup = true;
last.lastInDirective = true;
this.records = ListWrapper.concat(this.records, pr);
}
@ -183,20 +183,20 @@ class ProtoRecordBuilder {
class _ConvertAstIntoProtoRecords {
protoRecords:List;
bindingMemento:any;
groupMemento:any;
directiveMemento:any;
contextIndex:number;
expressionAsString:string;
constructor(bindingMemento:any, groupMemento:any, contextIndex:number, expressionAsString:string) {
constructor(bindingMemento:any, directiveMemento:any, contextIndex:number, expressionAsString:string) {
this.protoRecords = [];
this.bindingMemento = bindingMemento;
this.groupMemento = groupMemento;
this.directiveMemento = directiveMemento;
this.contextIndex = contextIndex;
this.expressionAsString = expressionAsString;
}
static convert(ast:AST, bindingMemento:any, groupMemento:any, contextIndex:number) {
var c = new _ConvertAstIntoProtoRecords(bindingMemento, groupMemento, contextIndex, ast.toString());
static convert(ast:AST, bindingMemento:any, directiveMemento:any, contextIndex:number) {
var c = new _ConvertAstIntoProtoRecords(bindingMemento, directiveMemento, contextIndex, ast.toString());
ast.visit(c);
return c.protoRecords;
}
@ -292,7 +292,7 @@ class _ConvertAstIntoProtoRecords {
var selfIndex = ++ this.contextIndex;
ListWrapper.push(this.protoRecords,
new ProtoRecord(type, name, funcOrValue, args, fixedArgs, context, selfIndex,
this.bindingMemento, this.groupMemento, this.expressionAsString, false, false));
this.bindingMemento, this.directiveMemento, this.expressionAsString, false, false));
return selfIndex;
}
}