Fixed issue with simple object as binding context.

This commit is contained in:
Nedyalko Nikolov
2016-05-05 15:10:05 +03:00
parent 5ca72cb465
commit c5a14464e8
2 changed files with 21 additions and 5 deletions

View File

@ -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;
}

View File

@ -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
}
}