mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Fixed getting object properties too many times.
This commit is contained in:
@@ -909,3 +909,32 @@ export var test_BindingContextOfAChildElementIsNotOverwrittenBySettingTheBinding
|
||||
helper.goBack();
|
||||
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!");
|
||||
}
|
||||
|
||||
@@ -255,7 +255,8 @@ export class Binding {
|
||||
currentObjectChanged = true;
|
||||
}
|
||||
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;
|
||||
}
|
||||
currentObjectChanged = false;
|
||||
|
||||
Reference in New Issue
Block a user