Merge pull request #1452 from NativeScript/nnikolov/BindingExpressionToSupportFuncs

Added support for functions with binding expressions.
This commit is contained in:
Nedyalko Nikolov
2016-01-29 09:19:39 +02:00
2 changed files with 26 additions and 1 deletions

View File

@ -938,3 +938,28 @@ export var test_BindingHitsGetterTooManyTimes = function () {
TKUnit.assertEqual(counter, 1, "Property getter should be hit only once!");
}
export function test_SupportFunctionsInExpressions() {
var model = new observable.Observable({
"anyColor": "red",
"isVisible": function () {
return this.get("anyColor") === "red";
}
});
var bindableObj = new bindable.Bindable();
bindableObj.bind({
"sourceProperty": "$value",
"targetProperty": "test",
"expression": "isVisible() ? 'visible' : 'collapsed'"
}, model);
model.set("anyColor", "blue");
TKUnit.assertEqual(bindableObj.get("test"), "collapsed", "When anyColor is blue test property should be collapsed.");
model.set("anyColor", "red");
TKUnit.assertEqual(bindableObj.get("test"), "visible", "When anyColor is red test property should be visible.");
}

View File

@ -379,7 +379,7 @@ export class Binding {
this.prepareContextForExpression(context, expression);
model[contextKey] = context;
return exp.getValue(model, isBackConvert, changedModel);
return exp.getValue(model, isBackConvert, changedModel ? changedModel : model);
}
return new Error(expression + " is not a valid expression.");
}