mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 21:01:34 +08:00
Fixed stack overflow exception in binding.
This commit is contained in:
@ -1124,3 +1124,46 @@ export function test_BindingToPropertiesWithSameNamesSecondCase() {
|
|||||||
TKUnit.assertEqual(target1.get("targetProperty"), model.item.get("seconds"));
|
TKUnit.assertEqual(target1.get("targetProperty"), model.item.get("seconds"));
|
||||||
TKUnit.assertEqual(target2.get("targetProp"), newValue);
|
TKUnit.assertEqual(target2.get("targetProp"), newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class RelatedPropsClass extends observable.Observable {
|
||||||
|
private _prop1: boolean;
|
||||||
|
private _prop2: string;
|
||||||
|
public get prop1(): boolean {
|
||||||
|
return this._prop1;
|
||||||
|
}
|
||||||
|
public set prop1(value: boolean) {
|
||||||
|
if (this._prop1 !== value) {
|
||||||
|
this._prop1 = value;
|
||||||
|
this.notifyPropertyChange("prop1", value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public get prop2(): string {
|
||||||
|
this.prop1 = !this._prop1;
|
||||||
|
this.notifyPropertyChange("prop2", this._prop2);
|
||||||
|
return this._prop2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public set prop2(value: string) {
|
||||||
|
if (this._prop2 !== value) {
|
||||||
|
this._prop2 = value;
|
||||||
|
this.notifyPropertyChange("prop2", value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function test_BindingToRelatedProps() {
|
||||||
|
let model = new RelatedPropsClass();
|
||||||
|
model.prop1 = false;
|
||||||
|
model.prop2 = "Alabala";
|
||||||
|
|
||||||
|
let target1 = new bindable.Bindable();
|
||||||
|
target1.bind({sourceProperty: 'prop1', targetProperty: 'targetProp1'}, model);
|
||||||
|
|
||||||
|
let target2 = new bindable.Bindable();
|
||||||
|
target2.bind({sourceProperty: 'prop2', targetProperty: 'targetProp2'}, model);
|
||||||
|
|
||||||
|
model.prop2 = "Tralala";
|
||||||
|
|
||||||
|
TKUnit.assertEqual(target2.get('targetProp2'), "Tralala");
|
||||||
|
}
|
@ -414,8 +414,9 @@ export class Binding {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changedPropertyIndex > -1) {
|
// we need to do this only if nested objects are used as source and some middle object is changed.
|
||||||
let probablyChangedObject = this.propertyChangeListeners.get(parentProps);
|
if (changedPropertyIndex > -1 && changedPropertyIndex < sourcePropsLength - 1) {
|
||||||
|
var probablyChangedObject = this.propertyChangeListeners.get(parentProps);
|
||||||
if (probablyChangedObject &&
|
if (probablyChangedObject &&
|
||||||
probablyChangedObject !== data.object[sourceProps[changedPropertyIndex]]) {
|
probablyChangedObject !== data.object[sourceProps[changedPropertyIndex]]) {
|
||||||
// remove all weakevent listeners after change, because changed object replaces object that is hooked for
|
// remove all weakevent listeners after change, because changed object replaces object that is hooked for
|
||||||
@ -434,9 +435,9 @@ export class Binding {
|
|||||||
|
|
||||||
let newProps = sourceProps.slice(changedPropertyIndex + 1);
|
let newProps = sourceProps.slice(changedPropertyIndex + 1);
|
||||||
// add new weakevent listeners
|
// add new weakevent listeners
|
||||||
let newObject = data.object[sourceProps[changedPropertyIndex]]
|
var newObject = data.object[sourceProps[changedPropertyIndex]]
|
||||||
if (typeof newObject === 'object') {
|
if (!types.isNullOrUndefined(newObject) && typeof newObject === 'object') {
|
||||||
this.addPropertyChangeListeners(new WeakRef(data.object[sourceProps[changedPropertyIndex]]), newProps, parentProps);
|
this.addPropertyChangeListeners(new WeakRef(newObject), newProps, parentProps);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user