From b65b1451228e650e1b47e2a5c20da99bfca962b7 Mon Sep 17 00:00:00 2001 From: vsavkin Date: Tue, 31 Mar 2015 07:47:26 -0700 Subject: [PATCH] refactor(view): refactored DirectiveMemento to expose properties in a consistent way --- .../abstract_change_detector.js | 4 ++-- .../change_detection_jit_generator.es6 | 14 ++++++------- .../dynamic_change_detector.js | 4 ++-- modules/angular2/src/core/compiler/view.js | 21 ++++++++----------- .../change_detection/change_detection_spec.js | 6 +++--- 5 files changed, 23 insertions(+), 26 deletions(-) diff --git a/modules/angular2/src/change_detection/abstract_change_detector.js b/modules/angular2/src/change_detection/abstract_change_detector.js index 3f17f2fbef..849040083f 100644 --- a/modules/angular2/src/change_detection/abstract_change_detector.js +++ b/modules/angular2/src/change_detection/abstract_change_detector.js @@ -51,7 +51,7 @@ export class AbstractChangeDetector extends ChangeDetector { this._detectChangesInLightDomChildren(throwOnChange); - this.notifyOnAllChangesDone(); + this.callOnAllChangesDone(); this._detectChangesInShadowDomChildren(throwOnChange); @@ -59,7 +59,7 @@ export class AbstractChangeDetector extends ChangeDetector { } detectChangesInRecords(throwOnChange:boolean){} - notifyOnAllChangesDone(){} + callOnAllChangesDone(){} _detectChangesInLightDomChildren(throwOnChange:boolean) { var c = this.lightDomChildren; 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 64076cc5c5..891eb17169 100644 --- a/modules/angular2/src/change_detection/change_detection_jit_generator.es6 +++ b/modules/angular2/src/change_detection/change_detection_jit_generator.es6 @@ -64,7 +64,7 @@ import { * } * } * - * ChangeDetector0.prototype.notifyOnAllChangesDone = function() {} + * ChangeDetector0.prototype.callOnAllChangesDone = function() {} * * ChangeDetector0.prototype.hydrate = function(context, locals) { * this.context = context; @@ -162,9 +162,9 @@ ${type}.prototype.detectChangesInRecords = function(throwOnChange) { `; } -function notifyOnAllChangesDoneTemplate(type:string, body:string):string { +function callOnAllChangesDoneTemplate(type:string, body:string):string { return ` -${type}.prototype.notifyOnAllChangesDone = function() { +${type}.prototype.callOnAllChangesDone = function() { ${body} } `; @@ -304,7 +304,7 @@ export class ChangeDetectorJITGenerator { generate():Function { var text = typeTemplate(this.typeName, this.genConstructor(), this.genDetectChanges(), - this.genNotifyOnAllChangesDone(), this.genHydrate()); + this.genCallOnAllChangesDone(), this.genHydrate()); return new Function('AbstractChangeDetector', 'ChangeDetectionUtil', 'protos', 'directiveMementos', text) (AbstractChangeDetector, ChangeDetectionUtil, this.records, this.directiveMementos); } @@ -340,18 +340,18 @@ export class ChangeDetectorJITGenerator { return detectChangesTemplate(this.typeName, body); } - genNotifyOnAllChangesDone():string { + genCallOnAllChangesDone():string { var notifications = []; var mementos = this.directiveMementos; for (var i = mementos.length - 1; i >= 0; --i) { var memento = mementos[i]; - if (memento.notifyOnAllChangesDone) { + if (memento.callOnAllChangesDone) { notifications.push(onAllChangesDoneTemplate(i)); } } - return notifyOnAllChangesDoneTemplate(this.typeName, notifications.join(";\n")); + return callOnAllChangesDoneTemplate(this.typeName, notifications.join(";\n")); } genBody():string { diff --git a/modules/angular2/src/change_detection/dynamic_change_detector.js b/modules/angular2/src/change_detection/dynamic_change_detector.js index 0adcf8c78b..f380d21294 100644 --- a/modules/angular2/src/change_detection/dynamic_change_detector.js +++ b/modules/angular2/src/change_detection/dynamic_change_detector.js @@ -104,11 +104,11 @@ export class DynamicChangeDetector extends AbstractChangeDetector { } } - notifyOnAllChangesDone() { + callOnAllChangesDone() { var mementos = this.directiveMementos; for (var i = mementos.length - 1; i >= 0; --i) { var memento = mementos[i]; - if (memento.notifyOnAllChangesDone) { + if (memento.callOnAllChangesDone) { this.dispatcher.onAllChangesDone(memento); } } diff --git a/modules/angular2/src/core/compiler/view.js b/modules/angular2/src/core/compiler/view.js index bea832b7f7..c4384af952 100644 --- a/modules/angular2/src/core/compiler/view.js +++ b/modules/angular2/src/core/compiler/view.js @@ -249,9 +249,7 @@ export class View { _notifyDirectiveAboutChanges(directiveMemento, records:List) { var dir = directiveMemento.directive(this.elementInjectors); - var binding = directiveMemento.directiveBinding(this.elementInjectors); - - if (binding.callOnChange) { + if (directiveMemento.callOnChange) { dir.onChange(this._collectChanges(records)); } } @@ -663,7 +661,8 @@ export class ProtoView { if (!MapWrapper.contains(this._directiveMementosMap, id)) { var binding = protoElementInjector.getDirectiveBindingAtIndex(directiveIndex); MapWrapper.set(this._directiveMementosMap, id, - new DirectiveMemento(elementInjectorIndex, directiveIndex, binding.callOnAllChangesDone)); + new DirectiveMemento(elementInjectorIndex, directiveIndex, + binding.callOnAllChangesDone, binding.callOnChange)); } return MapWrapper.get(this._directiveMementosMap, id); @@ -740,23 +739,21 @@ export class DirectiveBindingMemento { class DirectiveMemento { _elementInjectorIndex:number; _directiveIndex:number; - notifyOnAllChangesDone:boolean; + callOnAllChangesDone:boolean; + callOnChange:boolean; - constructor(elementInjectorIndex:number, directiveIndex:number, notifyOnAllChangesDone:boolean) { + constructor(elementInjectorIndex:number, directiveIndex:number, callOnAllChangesDone:boolean, + callOnChange:boolean) { this._elementInjectorIndex = elementInjectorIndex; this._directiveIndex = directiveIndex; - this.notifyOnAllChangesDone = notifyOnAllChangesDone; + this.callOnAllChangesDone = callOnAllChangesDone; + this.callOnChange = callOnChange; } directive(elementInjectors:List) { var elementInjector:ElementInjector = elementInjectors[this._elementInjectorIndex]; return elementInjector.getDirectiveAtIndex(this._directiveIndex); } - - directiveBinding(elementInjectors:List) { - var elementInjector:ElementInjector = elementInjectors[this._elementInjectorIndex]; - return elementInjector.getDirectiveBindingAtIndex(this._directiveIndex); - } } /** diff --git a/modules/angular2/test/change_detection/change_detection_spec.js b/modules/angular2/test/change_detection/change_detection_spec.js index 946d396451..7f57285d2f 100644 --- a/modules/angular2/test/change_detection/change_detection_spec.js +++ b/modules/angular2/test/change_detection/change_detection_spec.js @@ -780,11 +780,11 @@ class TestData { class FakeDirectiveMemento { value:any; - notifyOnAllChangesDone:boolean; + callOnAllChangesDone:boolean; - constructor(value, notifyOnAllChangesDone:boolean = false) { + constructor(value, callOnAllChangesDone:boolean = false) { this.value = value; - this.notifyOnAllChangesDone = notifyOnAllChangesDone; + this.callOnAllChangesDone = callOnAllChangesDone; } }