Skip to content

Commit

Permalink
[database][js] fixed a regression where snapshot.child() would no lon…
Browse files Browse the repository at this point in the history
…ger work on array values
  • Loading branch information
Salakar committed Apr 21, 2018
1 parent 0a828aa commit d0b6972
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions lib/modules/database/DataSnapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) : [],
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d0b6972

Please sign in to comment.