Skip to content

Commit 5d81ea0

Browse files
committed
snapshot.hasChild(path) now supports deep checks i.e snapshot.hasChild('foo/bar/baz')
1 parent 7b9c2d4 commit 5d81ea0

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Diff for: lib/modules/database/snapshot.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @flow
33
*/
44
import Reference from './reference.js';
5-
import { isObject, deepGet } from './../../utils';
5+
import { isObject, deepGet, deepExists } from './../../utils';
66

77
export default class Snapshot {
88
static key: String;
@@ -26,6 +26,7 @@ export default class Snapshot {
2626
this.priority = snapshot.priority === undefined ? null : snapshot.priority;
2727
this.childKeys = snapshot.childKeys || [];
2828
}
29+
2930
/*
3031
* DEFAULT API METHODS
3132
*/
@@ -50,15 +51,15 @@ export default class Snapshot {
5051
}
5152

5253
forEach(fn: (key: any) => any) {
53-
(this.childKeys || []).forEach((key, i) => fn(this.value[key], i));
54+
return this.childKeys.forEach((key, i) => fn(this.value[key], i));
5455
}
5556

5657
getPriority() {
5758
return this.priority;
5859
}
5960

60-
hasChild(key: string) {
61-
return this.childKeys.includes(key);
61+
hasChild(path: string) {
62+
return deepExists(this.value, path);
6263
}
6364

6465
hasChildren() {

0 commit comments

Comments
 (0)