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:
Hristo Hristov
2017-05-17 13:30:46 +03:00
committed by GitHub
parent 585e74e752
commit cbbee3bbe7
2 changed files with 24 additions and 0 deletions

View File

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

View File

@ -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) {