From d0b6972e395f5e7f9cd59e961689b4b3a22e3c7e Mon Sep 17 00:00:00 2001 From: Salakar Date: Sun, 22 Apr 2018 00:29:33 +0100 Subject: [PATCH] [database][js] fixed a regression where snapshot.child() would no longer work on array values --- lib/modules/database/DataSnapshot.js | 7 ++++--- lib/utils/index.js | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/modules/database/DataSnapshot.js b/lib/modules/database/DataSnapshot.js index c3500434..6537f7cf 100644 --- a/lib/modules/database/DataSnapshot.js +++ b/lib/modules/database/DataSnapshot.js @@ -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) : [], diff --git a/lib/utils/index.js b/lib/utils/index.js index c82735f5..421ba44e 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -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;