From ab733bd80e77b9d0ef9b59df47e7cde9696ee6b3 Mon Sep 17 00:00:00 2001 From: vsavkin Date: Fri, 6 Feb 2015 13:35:05 -0800 Subject: [PATCH] refactor(change_detection): rename group memento into directive memento --- .../change_detection_jit_generator.es6 | 4 +- .../angular2/src/change_detection/coalesce.js | 8 +-- .../dynamic_change_detector.js | 7 +-- .../src/change_detection/interfaces.js | 2 +- .../change_detection/proto_change_detector.js | 44 ++++++++--------- modules/angular2/src/core/compiler/view.js | 49 +++++++++---------- 6 files changed, 55 insertions(+), 59 deletions(-) diff --git a/modules/angular2/src/change_detection/change_detection_jit_generator.es6 b/modules/angular2/src/change_detection/change_detection_jit_generator.es6 index 22cb1ce93c..1bee7bdd74 100644 --- a/modules/angular2/src/change_detection/change_detection_jit_generator.es6 +++ b/modules/angular2/src/change_detection/change_detection_jit_generator.es6 @@ -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 { diff --git a/modules/angular2/src/change_detection/coalesce.js b/modules/angular2/src/change_detection/coalesce.js index cb1bf4d5df..9f227bedec 100644 --- a/modules/angular2/src/change_detection/coalesce.js +++ b/modules/angular2/src/change_detection/coalesce.js @@ -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 ); } diff --git a/modules/angular2/src/change_detection/dynamic_change_detector.js b/modules/angular2/src/change_detection/dynamic_change_detector.js index bc1d4ecb6d..9acd2eb316 100644 --- a/modules/angular2/src/change_detection/dynamic_change_detector.js +++ b/modules/angular2/src/change_detection/dynamic_change_detector.js @@ -54,22 +54,19 @@ export class DynamicChangeDetector extends AbstractChangeDetector { var protos:List = 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; } } diff --git a/modules/angular2/src/change_detection/interfaces.js b/modules/angular2/src/change_detection/interfaces.js index 6f6bc42009..ce8888d0b6 100644 --- a/modules/angular2/src/change_detection/interfaces.js +++ b/modules/angular2/src/change_detection/interfaces.js @@ -45,7 +45,7 @@ export const CHECK_ALWAYS="ALWAYS_CHECK"; export const DETACHED="DETACHED"; export class ChangeDispatcher { - onRecordChange(groupMemento, records:List) {} + onRecordChange(directiveMemento, records:List) {} } export class ChangeDetector { diff --git a/modules/angular2/src/change_detection/proto_change_detector.js b/modules/angular2/src/change_detection/proto_change_detector.js index 9a2ce224a7..e9b81d3400 100644 --- a/modules/angular2/src/change_detection/proto_change_detector.js +++ b/modules/angular2/src/change_detection/proto_change_detector.js @@ -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; } } diff --git a/modules/angular2/src/core/compiler/view.js b/modules/angular2/src/core/compiler/view.js index 923818b7a4..6eac60136f 100644 --- a/modules/angular2/src/core/compiler/view.js +++ b/modules/angular2/src/core/compiler/view.js @@ -195,10 +195,10 @@ export class View { this._dehydrateContext(); } - onRecordChange(groupMemento, records:List) { + onRecordChange(directiveMemento, records:List) { this._invokeMementos(records); - if (groupMemento instanceof DirectivePropertyGroupMemento) { - this._notifyDirectiveAboutChanges(groupMemento, records); + if (directiveMemento instanceof DirectiveMemento) { + this._notifyDirectiveAboutChanges(directiveMemento, records); } } @@ -208,9 +208,9 @@ export class View { } } - _notifyDirectiveAboutChanges(groupMemento, records:List) { - var dir = groupMemento.directive(this.elementInjectors); - var binding = groupMemento.directiveBinding(this.elementInjectors); + _notifyDirectiveAboutChanges(directiveMemento, records:List) { + var dir = directiveMemento.directive(this.elementInjectors); + var binding = directiveMemento.directiveBinding(this.elementInjectors); if (binding.callOnChange) { dir.onChange(this._collectChanges(records)); @@ -220,13 +220,12 @@ export class View { // dispatch to element injector or text nodes based on context _invokeMementoFor(record:ChangeRecord) { var memento = record.bindingMemento; - if (memento instanceof DirectivePropertyMemento) { - // we know that it is DirectivePropertyMemento - var directiveMemento:DirectivePropertyMemento = memento; + if (memento instanceof DirectiveBindingMemento) { + var directiveMemento:DirectiveBindingMemento = memento; directiveMemento.invoke(record, this.elementInjectors); - } else if (memento instanceof ElementPropertyMemento) { - var elementMemento:ElementPropertyMemento = memento; + } else if (memento instanceof ElementBindingMemento) { + var elementMemento:ElementBindingMemento = memento; elementMemento.invoke(record, this.bindElements); } else { @@ -451,7 +450,7 @@ export class ProtoView { } ListWrapper.push(elBinder.textNodeIndices, indexInParent); var memento = this.textNodesWithBindingCount++; - this.protoChangeDetector.addAst(expression, memento, memento); + this.protoChangeDetector.addAst(expression, memento); } /** @@ -463,8 +462,8 @@ export class ProtoView { elBinder.hasElementPropertyBindings = true; this.elementsWithBindingCount++; } - var memento = new ElementPropertyMemento(this.elementsWithBindingCount-1, setterName, setter); - this.protoChangeDetector.addAst(expression, memento, memento); + var memento = new ElementBindingMemento(this.elementsWithBindingCount-1, setterName, setter); + this.protoChangeDetector.addAst(expression, memento); } /** @@ -488,14 +487,14 @@ export class ProtoView { setter:SetterFn, isContentWatch: boolean) { - var expMemento = new DirectivePropertyMemento( + var bindingMemento = new DirectiveBindingMemento( this.elementBinders.length-1, directiveIndex, setterName, setter ); - var groupMemento = DirectivePropertyGroupMemento.get(expMemento); - this.protoChangeDetector.addAst(expression, expMemento, groupMemento, isContentWatch); + var directiveMemento = DirectiveMemento.get(bindingMemento); + this.protoChangeDetector.addAst(expression, bindingMemento, directiveMemento, isContentWatch); } // Create a rootView as if the compiler encountered , @@ -519,7 +518,7 @@ export class ProtoView { } } -export class ElementPropertyMemento { +export class ElementBindingMemento { _elementIndex:int; _setterName:string; _setter:SetterFn; @@ -535,7 +534,7 @@ export class ElementPropertyMemento { } } -export class DirectivePropertyMemento { +export class DirectiveBindingMemento { _elementInjectorIndex:int; _directiveIndex:int; _setterName:string; @@ -558,9 +557,9 @@ export class DirectivePropertyMemento { } } -var _groups = MapWrapper.create(); +var _directiveMementos = MapWrapper.create(); -class DirectivePropertyGroupMemento { +class DirectiveMemento { _elementInjectorIndex:number; _directiveIndex:number; @@ -569,15 +568,15 @@ class DirectivePropertyGroupMemento { this._directiveIndex = directiveIndex; } - static get(memento:DirectivePropertyMemento) { + static get(memento:DirectiveBindingMemento) { var elementInjectorIndex = memento._elementInjectorIndex; var directiveIndex = memento._directiveIndex; var id = elementInjectorIndex * 100 + directiveIndex; - if (!MapWrapper.contains(_groups, id)) { - MapWrapper.set(_groups, id, new DirectivePropertyGroupMemento(elementInjectorIndex, directiveIndex)); + if (!MapWrapper.contains(_directiveMementos, id)) { + MapWrapper.set(_directiveMementos, id, new DirectiveMemento(elementInjectorIndex, directiveIndex)); } - return MapWrapper.get(_groups, id); + return MapWrapper.get(_directiveMementos, id); } directive(elementInjectors:List) {