refactor(view): refactored DirectiveMemento to expose properties in a consistent way
This commit is contained in:
parent
982bb8b01d
commit
b65b145122
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<ElementInjector>) {
|
||||
var elementInjector:ElementInjector = elementInjectors[this._elementInjectorIndex];
|
||||
return elementInjector.getDirectiveAtIndex(this._directiveIndex);
|
||||
}
|
||||
|
||||
directiveBinding(elementInjectors:List<ElementInjector>) {
|
||||
var elementInjector:ElementInjector = elementInjectors[this._elementInjectorIndex];
|
||||
return elementInjector.getDirectiveBindingAtIndex(this._directiveIndex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue