mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
get method on Observable created with fromObject wan’t returning the value that was put from set if that property was not specified in the object passed to fromObject. (#4213)
get method on Observable created with fromObject wasn’t returning the …
This commit is contained in:
@ -539,3 +539,23 @@ export function test_NestedObservableWithNullShouldNotCrash() {
|
||||
});
|
||||
TKUnit.assert(testObservable !== undefined);
|
||||
}
|
||||
|
||||
export function test_get_set_on_observables_fromObject_without_property_in_json() {
|
||||
const array = new ObservableArray<any>();
|
||||
const vm = fromObject({});
|
||||
vm.set("p", array);
|
||||
const value1 = vm.get("p");
|
||||
const value2 = (<any>vm).p;
|
||||
TKUnit.assertEqual(value1, array);
|
||||
TKUnit.assertNull(value2);
|
||||
}
|
||||
|
||||
export function test_get_set_on_observables_fromObject_with_property_in_json() {
|
||||
const array = new ObservableArray<any>();
|
||||
const vm = fromObject({ p: null});
|
||||
vm.set("p", array);
|
||||
const value1 = vm.get("p");
|
||||
const value2 = (<any>vm).p;
|
||||
TKUnit.assertEqual(value1, array);
|
||||
TKUnit.assertEqual(value2, array);
|
||||
}
|
@ -185,6 +185,10 @@ export class Observable implements ObservableDefinition {
|
||||
class ObservableFromObject extends Observable {
|
||||
public _map = {};
|
||||
|
||||
public get(name: string): any {
|
||||
return this._map[name];
|
||||
}
|
||||
|
||||
public set(name: string, value: any) {
|
||||
const currentValue = this._map[name];
|
||||
if (currentValue === value) {
|
||||
|
Reference in New Issue
Block a user