Skip to content

Commit b65b145

Browse files
committed
refactor(view): refactored DirectiveMemento to expose properties in a consistent way
1 parent 982bb8b commit b65b145

File tree

5 files changed

+23
-26
lines changed

5 files changed

+23
-26
lines changed

modules/angular2/src/change_detection/abstract_change_detector.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ export class AbstractChangeDetector extends ChangeDetector {
5151

5252
this._detectChangesInLightDomChildren(throwOnChange);
5353

54-
this.notifyOnAllChangesDone();
54+
this.callOnAllChangesDone();
5555

5656
this._detectChangesInShadowDomChildren(throwOnChange);
5757

5858
if (this.mode === CHECK_ONCE) this.mode = CHECKED;
5959
}
6060

6161
detectChangesInRecords(throwOnChange:boolean){}
62-
notifyOnAllChangesDone(){}
62+
callOnAllChangesDone(){}
6363

6464
_detectChangesInLightDomChildren(throwOnChange:boolean) {
6565
var c = this.lightDomChildren;

modules/angular2/src/change_detection/change_detection_jit_generator.es6

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ import {
6464
* }
6565
* }
6666
*
67-
* ChangeDetector0.prototype.notifyOnAllChangesDone = function() {}
67+
* ChangeDetector0.prototype.callOnAllChangesDone = function() {}
6868
*
6969
* ChangeDetector0.prototype.hydrate = function(context, locals) {
7070
* this.context = context;
@@ -162,9 +162,9 @@ ${type}.prototype.detectChangesInRecords = function(throwOnChange) {
162162
`;
163163
}
164164

165-
function notifyOnAllChangesDoneTemplate(type:string, body:string):string {
165+
function callOnAllChangesDoneTemplate(type:string, body:string):string {
166166
return `
167-
${type}.prototype.notifyOnAllChangesDone = function() {
167+
${type}.prototype.callOnAllChangesDone = function() {
168168
${body}
169169
}
170170
`;
@@ -304,7 +304,7 @@ export class ChangeDetectorJITGenerator {
304304

305305
generate():Function {
306306
var text = typeTemplate(this.typeName, this.genConstructor(), this.genDetectChanges(),
307-
this.genNotifyOnAllChangesDone(), this.genHydrate());
307+
this.genCallOnAllChangesDone(), this.genHydrate());
308308
return new Function('AbstractChangeDetector', 'ChangeDetectionUtil', 'protos', 'directiveMementos', text)
309309
(AbstractChangeDetector, ChangeDetectionUtil, this.records, this.directiveMementos);
310310
}
@@ -340,18 +340,18 @@ export class ChangeDetectorJITGenerator {
340340
return detectChangesTemplate(this.typeName, body);
341341
}
342342

343-
genNotifyOnAllChangesDone():string {
343+
genCallOnAllChangesDone():string {
344344
var notifications = [];
345345
var mementos = this.directiveMementos;
346346

347347
for (var i = mementos.length - 1; i >= 0; --i) {
348348
var memento = mementos[i];
349-
if (memento.notifyOnAllChangesDone) {
349+
if (memento.callOnAllChangesDone) {
350350
notifications.push(onAllChangesDoneTemplate(i));
351351
}
352352
}
353353

354-
return notifyOnAllChangesDoneTemplate(this.typeName, notifications.join(";\n"));
354+
return callOnAllChangesDoneTemplate(this.typeName, notifications.join(";\n"));
355355
}
356356

357357
genBody():string {

modules/angular2/src/change_detection/dynamic_change_detector.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@ export class DynamicChangeDetector extends AbstractChangeDetector {
104104
}
105105
}
106106

107-
notifyOnAllChangesDone() {
107+
callOnAllChangesDone() {
108108
var mementos = this.directiveMementos;
109109
for (var i = mementos.length - 1; i >= 0; --i) {
110110
var memento = mementos[i];
111-
if (memento.notifyOnAllChangesDone) {
111+
if (memento.callOnAllChangesDone) {
112112
this.dispatcher.onAllChangesDone(memento);
113113
}
114114
}

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

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,7 @@ export class View {
249249

250250
_notifyDirectiveAboutChanges(directiveMemento, records:List) {
251251
var dir = directiveMemento.directive(this.elementInjectors);
252-
var binding = directiveMemento.directiveBinding(this.elementInjectors);
253-
254-
if (binding.callOnChange) {
252+
if (directiveMemento.callOnChange) {
255253
dir.onChange(this._collectChanges(records));
256254
}
257255
}
@@ -663,7 +661,8 @@ export class ProtoView {
663661
if (!MapWrapper.contains(this._directiveMementosMap, id)) {
664662
var binding = protoElementInjector.getDirectiveBindingAtIndex(directiveIndex);
665663
MapWrapper.set(this._directiveMementosMap, id,
666-
new DirectiveMemento(elementInjectorIndex, directiveIndex, binding.callOnAllChangesDone));
664+
new DirectiveMemento(elementInjectorIndex, directiveIndex,
665+
binding.callOnAllChangesDone, binding.callOnChange));
667666
}
668667

669668
return MapWrapper.get(this._directiveMementosMap, id);
@@ -740,23 +739,21 @@ export class DirectiveBindingMemento {
740739
class DirectiveMemento {
741740
_elementInjectorIndex:number;
742741
_directiveIndex:number;
743-
notifyOnAllChangesDone:boolean;
742+
callOnAllChangesDone:boolean;
743+
callOnChange:boolean;
744744

745-
constructor(elementInjectorIndex:number, directiveIndex:number, notifyOnAllChangesDone:boolean) {
745+
constructor(elementInjectorIndex:number, directiveIndex:number, callOnAllChangesDone:boolean,
746+
callOnChange:boolean) {
746747
this._elementInjectorIndex = elementInjectorIndex;
747748
this._directiveIndex = directiveIndex;
748-
this.notifyOnAllChangesDone = notifyOnAllChangesDone;
749+
this.callOnAllChangesDone = callOnAllChangesDone;
750+
this.callOnChange = callOnChange;
749751
}
750752

751753
directive(elementInjectors:List<ElementInjector>) {
752754
var elementInjector:ElementInjector = elementInjectors[this._elementInjectorIndex];
753755
return elementInjector.getDirectiveAtIndex(this._directiveIndex);
754756
}
755-
756-
directiveBinding(elementInjectors:List<ElementInjector>) {
757-
var elementInjector:ElementInjector = elementInjectors[this._elementInjectorIndex];
758-
return elementInjector.getDirectiveBindingAtIndex(this._directiveIndex);
759-
}
760757
}
761758

762759
/**

modules/angular2/test/change_detection/change_detection_spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -780,11 +780,11 @@ class TestData {
780780

781781
class FakeDirectiveMemento {
782782
value:any;
783-
notifyOnAllChangesDone:boolean;
783+
callOnAllChangesDone:boolean;
784784

785-
constructor(value, notifyOnAllChangesDone:boolean = false) {
785+
constructor(value, callOnAllChangesDone:boolean = false) {
786786
this.value = value;
787-
this.notifyOnAllChangesDone = notifyOnAllChangesDone;
787+
this.callOnAllChangesDone = callOnAllChangesDone;
788788
}
789789
}
790790

0 commit comments

Comments
 (0)