Merge pull request #150 from NativeScript/nnikolov/BindingWithSourceIssue

Fixed issue when UI element is bound to source different from binding…
This commit is contained in:
Nedyalko Nikolov
2015-05-12 17:16:31 +03:00
2 changed files with 24 additions and 1 deletions

View File

@@ -490,4 +490,26 @@ export var test_BindingContext_NavigatingForwardAndBack = function () {
}
helper.navigateToModuleAndRunTest("./tests/ui/bindingContext_testPage1", null, testFunc);
}
export var test_BindingToSource_FailsAfterBindingContextChange = function () {
var createLabel = function () {
var label = new labelModule.Label();
return label;
}
var labelViewModel = new observable.Observable();
var expectedValue = "testValue";
labelViewModel.set("testProperty", expectedValue);
var testFunc = function (views: Array<viewModule.View>) {
var testLabel = <labelModule.Label>(views[0]);
testLabel.bind({ sourceProperty: "testProperty", targetProperty: "text" }, labelViewModel);
var page = <pageModule.Page>(views[1]);
page.bindingContext = new observable.Observable;
TKUnit.assertEqual(testLabel.text, expectedValue);
}
helper.buildUIAndRunTest(createLabel(), testFunc);
}

View File

@@ -102,7 +102,8 @@ export class Bindable extends dependencyObservable.DependencyObservable implemen
for (var p in this._bindings) {
binding = this._bindings[p];
if (binding.updating) {
var sourceIsNotBindingContext = (binding.source && (binding.source.get() !== oldValue));
if (binding.updating || sourceIsNotBindingContext) {
continue;
}