11export class DocumentSnapshot {
22 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
66 }
77
88 data ( ) {
@@ -41,10 +41,11 @@ class DocumentReference {
4141 onSnapshot ( cb , onError ) {
4242 this . cb = cb
4343 this . onError = onError
44- return ( ) => this . cb = this . onError = noop
44+ return ( ) => {
45+ this . cb = this . onError = noop
46+ }
4547 }
4648
47-
4849 async delete ( ) {
4950 return this . collection . _remove ( this . id )
5051 }
@@ -65,7 +66,9 @@ class CollectionReference {
6566 onSnapshot ( cb , onError ) {
6667 this . cb = cb
6768 this . onError = onError
68- return ( ) => this . cb = this . onError = noop
69+ return ( ) => {
70+ this . cb = this . onError = noop
71+ }
6972 }
7073
7174 async add ( data ) {
@@ -81,7 +84,7 @@ class CollectionReference {
8184 type : 'added' ,
8285 doc : new DocumentSnapshot ( null , id , data ) ,
8386 newIndex : Object . keys ( this . data ) . length ,
84- oldIndex : - 1 ,
87+ oldIndex : - 1
8588 } ]
8689 } )
8790 return this . data [ id ]
@@ -92,12 +95,12 @@ class CollectionReference {
9295
9396 doc ( id ) {
9497 id = id || new Key ( )
95- return this . data [ id ] = this . data [ id ] || new DocumentReference ( {
98+ return ( this . data [ id ] = this . data [ id ] || new DocumentReference ( {
9699 collection : this ,
97100 id,
98101 data : { } ,
99102 index : Object . keys ( this . data ) . length
100- } )
103+ } ) )
101104 }
102105
103106 async _remove ( id ) {
@@ -106,7 +109,7 @@ class CollectionReference {
106109 this . cb ( {
107110 docChanges : [ {
108111 doc : new DocumentSnapshot ( null , id , ref . data ) ,
109- type : 'removed' ,
112+ type : 'removed'
110113 } ]
111114 } )
112115 ref . collection = null
@@ -119,10 +122,9 @@ class CollectionReference {
119122 type : 'modified' ,
120123 doc : new DocumentSnapshot ( null , id , data ) ,
121124 oldIndex : this . data [ id ] . index ,
122- newIndex : this . data [ id ] . index ,
125+ newIndex : this . data [ id ] . index
123126 } ]
124127 } )
125-
126128 }
127129}
128130
@@ -133,6 +135,6 @@ export const db = {
133135 collection ( name ) {
134136 // create a collection if no name provided
135137 name = name || `random__${ this . n ++ } `
136- return db [ name ] = db [ name ] || new CollectionReference ( )
138+ return ( db [ name ] = db [ name ] || new CollectionReference ( ) )
137139 }
138140}
0 commit comments