🐛 Fix bug with null in ObservableObject

This commit is contained in:
Jan Oberhauser 2020-12-28 19:18:16 +01:00
parent 1d2c286b88
commit 50e16de270
2 changed files with 10 additions and 1 deletions

View file

@ -13,7 +13,7 @@ export function create(target: IDataObject, parent?: IObservableObject, option?:
// Make all the children of target also observeable
for (const key in target) {
if (typeof target[key] === 'object') {
if (typeof target[key] === 'object' && target[key] !== null) {
target[key] = create(target[key] as IDataObject, (parent || target) as IObservableObject, option, depth + 1);
}
}

View file

@ -142,6 +142,15 @@ describe('ObservableObject', () => {
expect(testObject).toEqual({ a: {} });
});
test('should recognize that item on second child level changed with null (init data exists)', () => {
const testObject = ObservableObject.create({ a: { b: { c: null } } });
expect(testObject.__dataChanged).toBeFalsy();
expect((testObject.a! as IDataObject).b).toEqual({ c: null });
expect(((testObject.a! as IDataObject).b! as IDataObject).c).toEqual(null);
((testObject.a! as IDataObject).b! as IDataObject).c = 2;
expect(testObject.__dataChanged).toBeTruthy();
expect((testObject.a! as IDataObject).b).toEqual({ c: 2 });
});