Fixed getting object properties too many times.

This commit is contained in:
Nedyalko Nikolov
2015-12-16 11:14:16 +02:00
parent 04b13beb04
commit 5e440ab924
2 changed files with 32 additions and 2 deletions

View File

@@ -908,4 +908,33 @@ export var test_BindingContextOfAChildElementIsNotOverwrittenBySettingTheBinding
TKUnit.waitUntilReady(() => { return testFinished }); TKUnit.waitUntilReady(() => { return testFinished });
helper.goBack(); helper.goBack();
done(null); done(null);
} }
export var test_BindingHitsGetterTooManyTimes = function () {
var counter = 0;
class Dummy extends observable.Observable {
private _dummyProperty: string;
public get dummyProperty(): string {
counter++;
return this._dummyProperty;
}
public set dummyProperty(value: string) {
if (this._dummyProperty !== value) {
this._dummyProperty = value;
this.notifyPropertyChange("dummyProperty", value);
}
}
}
var model = new Dummy();
model.dummyProperty = "OPA";
var bindableObj = new bindable.Bindable();
bindableObj.bind({ sourceProperty: "dummyProperty", targetProperty: "dummyTarget" }, model);
TKUnit.assertEqual(counter, 1, "Property getter should be hit only once!");
}

View File

@@ -255,7 +255,8 @@ export class Binding {
currentObjectChanged = true; currentObjectChanged = true;
} }
result.push({ instance: currentObject, property: objProp }); result.push({ instance: currentObject, property: objProp });
if (!currentObjectChanged) { // do not need to dive into last object property getter on binding stage will handle it
if (!currentObjectChanged && (i < propsArrayLength - 1)) {
currentObject = currentObject ? currentObject[propsArray[i]] : null; currentObject = currentObject ? currentObject[propsArray[i]] : null;
} }
currentObjectChanged = false; currentObjectChanged = false;