-
Notifications
You must be signed in to change notification settings - Fork 127
Expand file tree
/
Copy pathsnapshot.js
More file actions
52 lines (45 loc) · 1.12 KB
/
snapshot.js
File metadata and controls
52 lines (45 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* @flow
*/
import Reference from './reference.js';
export default class Snapshot {
static key: String;
static value: Object;
static exists: boolean;
static hasChildren: boolean;
static childrenCount: Number;
static childKeys: String[];
ref: Object;
key: string;
value: any;
exists: boolean;
priority: any;
hasChildren: boolean;
childrenCount: number;
childKeys: Array<string>;
constructor(ref: Reference, snapshot: Object) {
this.ref = ref;
this.key = snapshot.key;
this.value = snapshot.value;
this.exists = snapshot.exists || true;
this.priority = snapshot.priority;
this.hasChildren = snapshot.hasChildren || false;
this.childrenCount = snapshot.childrenCount || 0;
this.childKeys = snapshot.childKeys || [];
}
val() {
return this.value;
}
forEach(fn: (key: any) => any) {
(this.childKeys || [])
.forEach(key => fn(this.value[key]));
}
map(fn: (key: string) => mixed) {
const arr = [];
this.forEach(item => arr.push(fn(item)));
return arr;
}
reverseMap(fn: (key: string) => mixed) {
return this.map(fn).reverse();
}
}