diff --git a/lib/modules/database/DataSnapshot.js b/lib/modules/database/DataSnapshot.js index 31597cbf..7717e87d 100644 --- a/lib/modules/database/DataSnapshot.js +++ b/lib/modules/database/DataSnapshot.js @@ -51,7 +51,8 @@ export default class DataSnapshot { * @returns {Snapshot} */ child(path: string): DataSnapshot { - const value = deepGet(this._value, path); + let value = deepGet(this._value, path); + if (value === undefined) value = null; const childRef = this.ref.child(path); return new DataSnapshot(childRef, { value, diff --git a/lib/modules/firestore/DocumentSnapshot.js b/lib/modules/firestore/DocumentSnapshot.js index 23e8ef10..d7317e79 100644 --- a/lib/modules/firestore/DocumentSnapshot.js +++ b/lib/modules/firestore/DocumentSnapshot.js @@ -5,7 +5,7 @@ import DocumentReference from './DocumentReference'; import FieldPath from './FieldPath'; import Path from './Path'; -import { isObject } from '../../utils'; +import { isObject, deepGet } from '../../utils'; import { parseNativeMap } from './utils/serialize'; import type Firestore from './'; @@ -63,6 +63,6 @@ export default class DocumentSnapshot { if (fieldPath instanceof FieldPath) { return extractFieldPathData(this._data, fieldPath._segments); } - return this._data ? this._data[fieldPath] : undefined; + return this._data ? deepGet(this._data, fieldPath, '.') : undefined; } } diff --git a/lib/utils/index.js b/lib/utils/index.js index bbe1031e..ca9f1973 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -33,7 +33,7 @@ export function deepGet( while (i < len) { const key = keys[i++]; - if (!tmp || !hasOwnProperty.call(tmp, key)) return null; + if (!tmp || !hasOwnProperty.call(tmp, key)) return undefined; tmp = tmp[key]; }