Skip to content

Commit ab733bd

Browse files
committed
refactor(change_detection): rename group memento into directive memento
1 parent 1ec796a commit ab733bd

File tree

6 files changed

+55
-59
lines changed

6 files changed

+55
-59
lines changed

modules/angular2/src/change_detection/change_detection_jit_generator.es6

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ function notifyTemplate(index:number):string{
156156
return `
157157
if (${CHANGES_LOCAL} && ${CHANGES_LOCAL}.length > 0) {
158158
if(throwOnChange) ${UTIL}.throwOnChange(${PROTOS_ACCESSOR}[${index}], ${CHANGES_LOCAL}[0]);
159-
${DISPATCHER_ACCESSOR}.onRecordChange(${PROTOS_ACCESSOR}[${index}].groupMemento, ${CHANGES_LOCAL});
159+
${DISPATCHER_ACCESSOR}.onRecordChange(${PROTOS_ACCESSOR}[${index}].directiveMemento, ${CHANGES_LOCAL});
160160
${CHANGES_LOCAL} = null;
161161
}
162162
`;
@@ -388,7 +388,7 @@ export class ChangeDetectorJITGenerator {
388388
}
389389

390390
genNotify(r):string{
391-
return r.lastInGroup ? notifyTemplate(r.selfIndex - 1) : '';
391+
return r.lastInDirective ? notifyTemplate(r.selfIndex - 1) : '';
392392
}
393393

394394
genArgs(r:ProtoRecord):string {

modules/angular2/src/change_detection/coalesce.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ function _selfRecord(r:ProtoRecord, contextIndex:number, selfIndex:number):Proto
4747
contextIndex,
4848
selfIndex,
4949
r.bindingMemento,
50-
r.groupMemento,
50+
r.directiveMemento,
5151
r.expressionAsString,
5252
r.lastInBinding,
53-
r.lastInGroup
53+
r.lastInDirective
5454
);
5555
}
5656

@@ -75,10 +75,10 @@ function _replaceIndices(r:ProtoRecord, selfIndex:number, indexMap:Map) {
7575
contextIndex,
7676
selfIndex,
7777
r.bindingMemento,
78-
r.groupMemento,
78+
r.directiveMemento,
7979
r.expressionAsString,
8080
r.lastInBinding,
81-
r.lastInGroup
81+
r.lastInDirective
8282
);
8383
}
8484

modules/angular2/src/change_detection/dynamic_change_detector.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,19 @@ export class DynamicChangeDetector extends AbstractChangeDetector {
5454
var protos:List<ProtoRecord> = this.protos;
5555

5656
var updatedRecords = null;
57-
var currentGroup = null;
58-
5957
for (var i = 0; i < protos.length; ++i) {
6058
var proto:ProtoRecord = protos[i];
6159
var change = this._check(proto);
6260

6361
if (isPresent(change)) {
64-
currentGroup = proto.groupMemento;
6562
var record = ChangeDetectionUtil.changeRecord(proto.bindingMemento, change);
6663
updatedRecords = ChangeDetectionUtil.addRecord(updatedRecords, record);
6764
}
6865

69-
if (proto.lastInGroup && isPresent(updatedRecords)) {
66+
if (proto.lastInDirective && isPresent(updatedRecords)) {
7067
if (throwOnChange) ChangeDetectionUtil.throwOnChange(proto, updatedRecords[0]);
7168

72-
this.dispatcher.onRecordChange(currentGroup, updatedRecords);
69+
this.dispatcher.onRecordChange(proto.directiveMemento, updatedRecords);
7370
updatedRecords = null;
7471
}
7572
}

modules/angular2/src/change_detection/interfaces.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const CHECK_ALWAYS="ALWAYS_CHECK";
4545
export const DETACHED="DETACHED";
4646

4747
export class ChangeDispatcher {
48-
onRecordChange(groupMemento, records:List<ChangeRecord>) {}
48+
onRecordChange(directiveMemento, records:List<ChangeRecord>) {}
4949
}
5050

5151
export class ChangeDetector {

modules/angular2/src/change_detection/proto_change_detector.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ export class ProtoRecord {
5353
contextIndex:number;
5454
selfIndex:number;
5555
bindingMemento:any;
56-
groupMemento:any;
56+
directiveMemento:any;
5757
lastInBinding:boolean;
58-
lastInGroup:boolean;
58+
lastInDirective:boolean;
5959
expressionAsString:string;
6060

6161
constructor(mode:number,
@@ -66,10 +66,10 @@ export class ProtoRecord {
6666
contextIndex:number,
6767
selfIndex:number,
6868
bindingMemento:any,
69-
groupMemento:any,
69+
directiveMemento:any,
7070
expressionAsString:string,
7171
lastInBinding:boolean,
72-
lastInGroup:boolean) {
72+
lastInDirective:boolean) {
7373

7474
this.mode = mode;
7575
this.name = name;
@@ -79,9 +79,9 @@ export class ProtoRecord {
7979
this.contextIndex = contextIndex;
8080
this.selfIndex = selfIndex;
8181
this.bindingMemento = bindingMemento;
82-
this.groupMemento = groupMemento;
82+
this.directiveMemento = directiveMemento;
8383
this.lastInBinding = lastInBinding;
84-
this.lastInGroup = lastInGroup;
84+
this.lastInDirective = lastInDirective;
8585
this.expressionAsString = expressionAsString;
8686
}
8787

@@ -93,7 +93,7 @@ export class ProtoRecord {
9393
}
9494

9595
export class ProtoChangeDetector {
96-
addAst(ast:AST, bindingMemento:any, groupMemento:any = null, structural:boolean = false){}
96+
addAst(ast:AST, bindingMemento:any, directiveMemento:any = null, structural:boolean = false){}
9797
instantiate(dispatcher:any, formatters:Map):ChangeDetector{
9898
return null;
9999
}
@@ -108,8 +108,8 @@ export class DynamicProtoChangeDetector extends ProtoChangeDetector {
108108
this._recordBuilder = new ProtoRecordBuilder();
109109
}
110110

111-
addAst(ast:AST, bindingMemento:any, groupMemento:any = null, structural:boolean = false) {
112-
this._recordBuilder.addAst(ast, bindingMemento, groupMemento, structural);
111+
addAst(ast:AST, bindingMemento:any, directiveMemento:any = null, structural:boolean = false) {
112+
this._recordBuilder.addAst(ast, bindingMemento, directiveMemento, structural);
113113
}
114114

115115
instantiate(dispatcher:any, formatters:Map) {
@@ -135,8 +135,8 @@ export class JitProtoChangeDetector extends ProtoChangeDetector {
135135
this._recordBuilder = new ProtoRecordBuilder();
136136
}
137137

138-
addAst(ast:AST, bindingMemento:any, groupMemento:any = null, structural:boolean = false) {
139-
this._recordBuilder.addAst(ast, bindingMemento, groupMemento, structural);
138+
addAst(ast:AST, bindingMemento:any, directiveMemento:any = null, structural:boolean = false) {
139+
this._recordBuilder.addAst(ast, bindingMemento, directiveMemento, structural);
140140
}
141141

142142
instantiate(dispatcher:any, formatters:Map) {
@@ -161,19 +161,19 @@ class ProtoRecordBuilder {
161161
this.records = [];
162162
}
163163

164-
addAst(ast:AST, bindingMemento:any, groupMemento:any = null, structural:boolean = false) {
164+
addAst(ast:AST, bindingMemento:any, directiveMemento:any = null, structural:boolean = false) {
165165
if (structural) ast = new Structural(ast);
166166

167167
var last = ListWrapper.last(this.records);
168-
if (isPresent(last) && last.groupMemento == groupMemento) {
169-
last.lastInGroup = false;
168+
if (isPresent(last) && last.directiveMemento == directiveMemento) {
169+
last.lastInDirective = false;
170170
}
171171

172-
var pr = _ConvertAstIntoProtoRecords.convert(ast, bindingMemento, groupMemento, this.records.length);
172+
var pr = _ConvertAstIntoProtoRecords.convert(ast, bindingMemento, directiveMemento, this.records.length);
173173
if (! ListWrapper.isEmpty(pr)) {
174174
var last = ListWrapper.last(pr);
175175
last.lastInBinding = true;
176-
last.lastInGroup = true;
176+
last.lastInDirective = true;
177177

178178
this.records = ListWrapper.concat(this.records, pr);
179179
}
@@ -183,20 +183,20 @@ class ProtoRecordBuilder {
183183
class _ConvertAstIntoProtoRecords {
184184
protoRecords:List;
185185
bindingMemento:any;
186-
groupMemento:any;
186+
directiveMemento:any;
187187
contextIndex:number;
188188
expressionAsString:string;
189189

190-
constructor(bindingMemento:any, groupMemento:any, contextIndex:number, expressionAsString:string) {
190+
constructor(bindingMemento:any, directiveMemento:any, contextIndex:number, expressionAsString:string) {
191191
this.protoRecords = [];
192192
this.bindingMemento = bindingMemento;
193-
this.groupMemento = groupMemento;
193+
this.directiveMemento = directiveMemento;
194194
this.contextIndex = contextIndex;
195195
this.expressionAsString = expressionAsString;
196196
}
197197

198-
static convert(ast:AST, bindingMemento:any, groupMemento:any, contextIndex:number) {
199-
var c = new _ConvertAstIntoProtoRecords(bindingMemento, groupMemento, contextIndex, ast.toString());
198+
static convert(ast:AST, bindingMemento:any, directiveMemento:any, contextIndex:number) {
199+
var c = new _ConvertAstIntoProtoRecords(bindingMemento, directiveMemento, contextIndex, ast.toString());
200200
ast.visit(c);
201201
return c.protoRecords;
202202
}
@@ -292,7 +292,7 @@ class _ConvertAstIntoProtoRecords {
292292
var selfIndex = ++ this.contextIndex;
293293
ListWrapper.push(this.protoRecords,
294294
new ProtoRecord(type, name, funcOrValue, args, fixedArgs, context, selfIndex,
295-
this.bindingMemento, this.groupMemento, this.expressionAsString, false, false));
295+
this.bindingMemento, this.directiveMemento, this.expressionAsString, false, false));
296296
return selfIndex;
297297
}
298298
}

modules/angular2/src/core/compiler/view.js

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,10 @@ export class View {
195195
this._dehydrateContext();
196196
}
197197

198-
onRecordChange(groupMemento, records:List) {
198+
onRecordChange(directiveMemento, records:List) {
199199
this._invokeMementos(records);
200-
if (groupMemento instanceof DirectivePropertyGroupMemento) {
201-
this._notifyDirectiveAboutChanges(groupMemento, records);
200+
if (directiveMemento instanceof DirectiveMemento) {
201+
this._notifyDirectiveAboutChanges(directiveMemento, records);
202202
}
203203
}
204204

@@ -208,9 +208,9 @@ export class View {
208208
}
209209
}
210210

211-
_notifyDirectiveAboutChanges(groupMemento, records:List) {
212-
var dir = groupMemento.directive(this.elementInjectors);
213-
var binding = groupMemento.directiveBinding(this.elementInjectors);
211+
_notifyDirectiveAboutChanges(directiveMemento, records:List) {
212+
var dir = directiveMemento.directive(this.elementInjectors);
213+
var binding = directiveMemento.directiveBinding(this.elementInjectors);
214214

215215
if (binding.callOnChange) {
216216
dir.onChange(this._collectChanges(records));
@@ -220,13 +220,12 @@ export class View {
220220
// dispatch to element injector or text nodes based on context
221221
_invokeMementoFor(record:ChangeRecord) {
222222
var memento = record.bindingMemento;
223-
if (memento instanceof DirectivePropertyMemento) {
224-
// we know that it is DirectivePropertyMemento
225-
var directiveMemento:DirectivePropertyMemento = memento;
223+
if (memento instanceof DirectiveBindingMemento) {
224+
var directiveMemento:DirectiveBindingMemento = memento;
226225
directiveMemento.invoke(record, this.elementInjectors);
227226

228-
} else if (memento instanceof ElementPropertyMemento) {
229-
var elementMemento:ElementPropertyMemento = memento;
227+
} else if (memento instanceof ElementBindingMemento) {
228+
var elementMemento:ElementBindingMemento = memento;
230229
elementMemento.invoke(record, this.bindElements);
231230

232231
} else {
@@ -451,7 +450,7 @@ export class ProtoView {
451450
}
452451
ListWrapper.push(elBinder.textNodeIndices, indexInParent);
453452
var memento = this.textNodesWithBindingCount++;
454-
this.protoChangeDetector.addAst(expression, memento, memento);
453+
this.protoChangeDetector.addAst(expression, memento);
455454
}
456455

457456
/**
@@ -463,8 +462,8 @@ export class ProtoView {
463462
elBinder.hasElementPropertyBindings = true;
464463
this.elementsWithBindingCount++;
465464
}
466-
var memento = new ElementPropertyMemento(this.elementsWithBindingCount-1, setterName, setter);
467-
this.protoChangeDetector.addAst(expression, memento, memento);
465+
var memento = new ElementBindingMemento(this.elementsWithBindingCount-1, setterName, setter);
466+
this.protoChangeDetector.addAst(expression, memento);
468467
}
469468

470469
/**
@@ -488,14 +487,14 @@ export class ProtoView {
488487
setter:SetterFn,
489488
isContentWatch: boolean) {
490489

491-
var expMemento = new DirectivePropertyMemento(
490+
var bindingMemento = new DirectiveBindingMemento(
492491
this.elementBinders.length-1,
493492
directiveIndex,
494493
setterName,
495494
setter
496495
);
497-
var groupMemento = DirectivePropertyGroupMemento.get(expMemento);
498-
this.protoChangeDetector.addAst(expression, expMemento, groupMemento, isContentWatch);
496+
var directiveMemento = DirectiveMemento.get(bindingMemento);
497+
this.protoChangeDetector.addAst(expression, bindingMemento, directiveMemento, isContentWatch);
499498
}
500499

501500
// Create a rootView as if the compiler encountered <rootcmp></rootcmp>,
@@ -519,7 +518,7 @@ export class ProtoView {
519518
}
520519
}
521520

522-
export class ElementPropertyMemento {
521+
export class ElementBindingMemento {
523522
_elementIndex:int;
524523
_setterName:string;
525524
_setter:SetterFn;
@@ -535,7 +534,7 @@ export class ElementPropertyMemento {
535534
}
536535
}
537536

538-
export class DirectivePropertyMemento {
537+
export class DirectiveBindingMemento {
539538
_elementInjectorIndex:int;
540539
_directiveIndex:int;
541540
_setterName:string;
@@ -558,9 +557,9 @@ export class DirectivePropertyMemento {
558557
}
559558
}
560559

561-
var _groups = MapWrapper.create();
560+
var _directiveMementos = MapWrapper.create();
562561

563-
class DirectivePropertyGroupMemento {
562+
class DirectiveMemento {
564563
_elementInjectorIndex:number;
565564
_directiveIndex:number;
566565

@@ -569,15 +568,15 @@ class DirectivePropertyGroupMemento {
569568
this._directiveIndex = directiveIndex;
570569
}
571570

572-
static get(memento:DirectivePropertyMemento) {
571+
static get(memento:DirectiveBindingMemento) {
573572
var elementInjectorIndex = memento._elementInjectorIndex;
574573
var directiveIndex = memento._directiveIndex;
575574
var id = elementInjectorIndex * 100 + directiveIndex;
576575

577-
if (!MapWrapper.contains(_groups, id)) {
578-
MapWrapper.set(_groups, id, new DirectivePropertyGroupMemento(elementInjectorIndex, directiveIndex));
576+
if (!MapWrapper.contains(_directiveMementos, id)) {
577+
MapWrapper.set(_directiveMementos, id, new DirectiveMemento(elementInjectorIndex, directiveIndex));
579578
}
580-
return MapWrapper.get(_groups, id);
579+
return MapWrapper.get(_directiveMementos, id);
581580
}
582581

583582
directive(elementInjectors:List<ElementInjector>) {

0 commit comments

Comments
 (0)