1
1
export class DocumentSnapshot {
2
2
constructor ( firestore , key , document ) {
3
- this . _firestore = firestore ;
4
- this . _key = key ;
5
- this . _document = document ;
3
+ this . _firestore = firestore
4
+ this . _key = key
5
+ this . _document = document
6
6
}
7
7
8
8
data ( ) {
@@ -41,10 +41,11 @@ class DocumentReference {
41
41
onSnapshot ( cb , onError ) {
42
42
this . cb = cb
43
43
this . onError = onError
44
- return ( ) => this . cb = this . onError = noop
44
+ return ( ) => {
45
+ this . cb = this . onError = noop
46
+ }
45
47
}
46
48
47
-
48
49
async delete ( ) {
49
50
return this . collection . _remove ( this . id )
50
51
}
@@ -65,7 +66,9 @@ class CollectionReference {
65
66
onSnapshot ( cb , onError ) {
66
67
this . cb = cb
67
68
this . onError = onError
68
- return ( ) => this . cb = this . onError = noop
69
+ return ( ) => {
70
+ this . cb = this . onError = noop
71
+ }
69
72
}
70
73
71
74
async add ( data ) {
@@ -81,7 +84,7 @@ class CollectionReference {
81
84
type : 'added' ,
82
85
doc : new DocumentSnapshot ( null , id , data ) ,
83
86
newIndex : Object . keys ( this . data ) . length ,
84
- oldIndex : - 1 ,
87
+ oldIndex : - 1
85
88
} ]
86
89
} )
87
90
return this . data [ id ]
@@ -92,12 +95,12 @@ class CollectionReference {
92
95
93
96
doc ( id ) {
94
97
id = id || new Key ( )
95
- return this . data [ id ] = this . data [ id ] || new DocumentReference ( {
98
+ return ( this . data [ id ] = this . data [ id ] || new DocumentReference ( {
96
99
collection : this ,
97
100
id,
98
101
data : { } ,
99
102
index : Object . keys ( this . data ) . length
100
- } )
103
+ } ) )
101
104
}
102
105
103
106
async _remove ( id ) {
@@ -106,7 +109,7 @@ class CollectionReference {
106
109
this . cb ( {
107
110
docChanges : [ {
108
111
doc : new DocumentSnapshot ( null , id , ref . data ) ,
109
- type : 'removed' ,
112
+ type : 'removed'
110
113
} ]
111
114
} )
112
115
ref . collection = null
@@ -119,10 +122,9 @@ class CollectionReference {
119
122
type : 'modified' ,
120
123
doc : new DocumentSnapshot ( null , id , data ) ,
121
124
oldIndex : this . data [ id ] . index ,
122
- newIndex : this . data [ id ] . index ,
125
+ newIndex : this . data [ id ] . index
123
126
} ]
124
127
} )
125
-
126
128
}
127
129
}
128
130
@@ -133,6 +135,6 @@ export const db = {
133
135
collection ( name ) {
134
136
// create a collection if no name provided
135
137
name = name || `random__${ this . n ++ } `
136
- return db [ name ] = db [ name ] || new CollectionReference ( )
138
+ return ( db [ name ] = db [ name ] || new CollectionReference ( ) )
137
139
}
138
140
}
0 commit comments