From 5e440ab924041fddaba4e226d96f33c0f8465da7 Mon Sep 17 00:00:00 2001 From: Nedyalko Nikolov Date: Wed, 16 Dec 2015 11:14:16 +0200 Subject: [PATCH] Fixed getting object properties too many times. --- apps/tests/ui/bindable-tests.ts | 31 ++++++++++++++++++++++++++++++- ui/core/bindable.ts | 3 ++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/apps/tests/ui/bindable-tests.ts b/apps/tests/ui/bindable-tests.ts index 99ce71abe..95075db06 100644 --- a/apps/tests/ui/bindable-tests.ts +++ b/apps/tests/ui/bindable-tests.ts @@ -908,4 +908,33 @@ export var test_BindingContextOfAChildElementIsNotOverwrittenBySettingTheBinding TKUnit.waitUntilReady(() => { return testFinished }); helper.goBack(); done(null); -} \ No newline at end of file +} + +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!"); +} diff --git a/ui/core/bindable.ts b/ui/core/bindable.ts index 7d742ef89..0a27ff69f 100644 --- a/ui/core/bindable.ts +++ b/ui/core/bindable.ts @@ -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;