From c5a14464e888c15fe38fbb689de77274f2493c5b Mon Sep 17 00:00:00 2001 From: Nedyalko Nikolov Date: Thu, 5 May 2016 15:10:05 +0300 Subject: [PATCH] Fixed issue with simple object as binding context. --- apps/tests/ui/bindable-tests.ts | 11 +++++++++++ ui/core/bindable.ts | 15 ++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/apps/tests/ui/bindable-tests.ts b/apps/tests/ui/bindable-tests.ts index 8d9b4aef6..c10fa923c 100644 --- a/apps/tests/ui/bindable-tests.ts +++ b/apps/tests/ui/bindable-tests.ts @@ -1220,4 +1220,15 @@ export function test_BindingToRelatedProps() { model.prop2 = "Tralala"; TKUnit.assertEqual(target2.get('targetProp2'), "Tralala"); +} + +export function test_only_Bindable_BindingContext_Null_DoesNotThrow() { + var options: bindable.BindingOptions = { + sourceProperty: "a.b", + targetProperty: "test" + } + var obj = new bindable.Bindable(); + obj.bind(options); + obj.bindingContext = new observable.Observable({ a: "b" }); + obj.bindingContext = null; } \ No newline at end of file diff --git a/ui/core/bindable.ts b/ui/core/bindable.ts index 3c036333e..c41a6dbca 100644 --- a/ui/core/bindable.ts +++ b/ui/core/bindable.ts @@ -192,10 +192,8 @@ export class Binding { this.sourceOptions = undefined; } } - - public bind(source: Object): void { - this.clearSource(); - + + private sourceAsObject(source: any): any { /* tslint:disable */ let objectType = typeof source; if (objectType === "number") { @@ -208,6 +206,13 @@ export class Binding { source = new String(source); } /* tslint:enable */ + return source; + } + + public bind(source: Object): void { + this.clearSource(); + + source = this.sourceAsObject(source); if (!types.isNullOrUndefined(source)) { this.source = new WeakRef(source); @@ -559,7 +564,7 @@ export class Binding { let resolvedObj = objectsAndProperties[objectsAndProperties.length - 1].instance; let prop = objectsAndProperties[objectsAndProperties.length - 1].property; return { - instance: new WeakRef(resolvedObj), + instance: new WeakRef(this.sourceAsObject(resolvedObj)), property: prop } }