Skip to content

Commit cbbee3b

Browse files
author
Hristo Hristov
authored
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 …
1 parent 585e74e commit cbbee3b

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

tests/app/data/observable-tests.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,3 +539,23 @@ export function test_NestedObservableWithNullShouldNotCrash() {
539539
});
540540
TKUnit.assert(testObservable !== undefined);
541541
}
542+
543+
export function test_get_set_on_observables_fromObject_without_property_in_json() {
544+
const array = new ObservableArray<any>();
545+
const vm = fromObject({});
546+
vm.set("p", array);
547+
const value1 = vm.get("p");
548+
const value2 = (<any>vm).p;
549+
TKUnit.assertEqual(value1, array);
550+
TKUnit.assertNull(value2);
551+
}
552+
553+
export function test_get_set_on_observables_fromObject_with_property_in_json() {
554+
const array = new ObservableArray<any>();
555+
const vm = fromObject({ p: null});
556+
vm.set("p", array);
557+
const value1 = vm.get("p");
558+
const value2 = (<any>vm).p;
559+
TKUnit.assertEqual(value1, array);
560+
TKUnit.assertEqual(value2, array);
561+
}

tns-core-modules/data/observable/observable.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ export class Observable implements ObservableDefinition {
185185
class ObservableFromObject extends Observable {
186186
public _map = {};
187187

188+
public get(name: string): any {
189+
return this._map[name];
190+
}
191+
188192
public set(name: string, value: any) {
189193
const currentValue = this._map[name];
190194
if (currentValue === value) {

0 commit comments

Comments
 (0)