[database][js] fixed a regression where snapshot.child() would no longer work on array values
This commit is contained in:
parent
0a828aae40
commit
d0b6972e39
|
@ -51,6 +51,7 @@ export default class DataSnapshot {
|
|||
* @returns {Snapshot}
|
||||
*/
|
||||
child(path: string): DataSnapshot {
|
||||
// TODO validate path is a string
|
||||
let value = deepGet(this._value, path);
|
||||
if (value === undefined) value = null;
|
||||
const childRef = this.ref.child(path);
|
||||
|
@ -59,9 +60,9 @@ export default class DataSnapshot {
|
|||
key: childRef.key,
|
||||
exists: value !== null,
|
||||
|
||||
// todo this is wrong - child keys needs to be the ordered keys, from FB
|
||||
// todo potential solution is build up a tree/map of a snapshot and its children
|
||||
// todo natively and send that back to JS to be use in this class.
|
||||
// TODO this is wrong - child keys needs to be the ordered keys, from FB
|
||||
// TODO potential solution is build up a tree/map of a snapshot and its children
|
||||
// TODO natively and send that back to JS to be use in this class.
|
||||
|
||||
// null check to keep flow happy even though isObject already does this
|
||||
childKeys: isObject(value) && value !== null ? Object.keys(value) : [],
|
||||
|
|
|
@ -30,7 +30,7 @@ export function hop(object: Object, property: string): boolean {
|
|||
* @returns {*}
|
||||
*/
|
||||
export function deepGet(object: any, path: string, joiner?: string = '/'): any {
|
||||
if (!isObject(object)) return undefined;
|
||||
if (!isObject(object) && !Array.isArray(object)) return undefined;
|
||||
const keys = path.split(joiner);
|
||||
|
||||
let i = 0;
|
||||
|
|
Loading…
Reference in New Issue