@@ -2216,6 +2216,21 @@ firebase.firestore.collection = (collectionPath: string): firestore.CollectionRe
22162216 }
22172217} ;
22182218
2219+ firebase . firestore . onSnapshot = ( docRef : com . google . firebase . firestore . DocumentReference , callback : ( doc : DocumentSnapshot ) => void ) : void => {
2220+ docRef . addSnapshotListener ( new com . google . firebase . firestore . EventListener ( {
2221+ onEvent : ( ( snapshot : com . google . firebase . firestore . DocumentSnapshot , exception ) => {
2222+ if ( exception !== null ) {
2223+ return ;
2224+ }
2225+ callback ( new DocumentSnapshot (
2226+ snapshot ? snapshot . getId ( ) : null ,
2227+ snapshot . exists ( ) ,
2228+ snapshot ? ( ) => firebase . toJsObject ( snapshot . getData ( ) ) : null ) ) ;
2229+ } )
2230+ } )
2231+ ) ;
2232+ } ;
2233+
22192234firebase . firestore . doc = ( collectionPath : string , documentPath ?: string ) : firestore . DocumentReference => {
22202235 try {
22212236
@@ -2234,7 +2249,8 @@ firebase.firestore.doc = (collectionPath: string, documentPath?: string): firest
22342249 set : ( data : any , options ?: firestore . SetOptions ) => firebase . firestore . set ( collectionPath , docRef . getId ( ) , data , options ) ,
22352250 get : ( ) => firebase . firestore . getDocument ( collectionPath , docRef . getId ( ) ) ,
22362251 update : ( data : any ) => firebase . firestore . update ( collectionPath , docRef . getId ( ) , data ) ,
2237- delete : ( ) => firebase . firestore . delete ( collectionPath , docRef . getId ( ) )
2252+ delete : ( ) => firebase . firestore . delete ( collectionPath , docRef . getId ( ) ) ,
2253+ onSnapshot : ( callback : ( doc : DocumentSnapshot ) => void ) => firebase . firestore . onSnapshot ( docRef , callback )
22382254 } ;
22392255
22402256 } catch ( ex ) {
@@ -2255,14 +2271,15 @@ firebase.firestore.add = (collectionPath: string, document: any): Promise<firest
22552271 const db = com . google . firebase . firestore . FirebaseFirestore . getInstance ( ) ;
22562272
22572273 const onSuccessListener = new com . google . android . gms . tasks . OnSuccessListener ( {
2258- onSuccess : ( documentReference : com . google . firebase . firestore . DocumentReference ) => {
2274+ onSuccess : ( docRef : com . google . firebase . firestore . DocumentReference ) => {
22592275 resolve ( {
2260- id : documentReference . getId ( ) ,
2276+ id : docRef . getId ( ) ,
22612277 collection : cp => firebase . firestore . collection ( cp ) ,
2262- set : ( data : any , options ?: firestore . SetOptions ) => firebase . firestore . set ( collectionPath , documentReference . getId ( ) , data , options ) ,
2263- get : ( ) => firebase . firestore . getDocument ( collectionPath , documentReference . getId ( ) ) ,
2264- update : ( data : any ) => firebase . firestore . update ( collectionPath , documentReference . getId ( ) , data ) ,
2265- delete : ( ) => firebase . firestore . delete ( collectionPath , documentReference . getId ( ) )
2278+ set : ( data : any , options ?: firestore . SetOptions ) => firebase . firestore . set ( collectionPath , docRef . getId ( ) , data , options ) ,
2279+ get : ( ) => firebase . firestore . getDocument ( collectionPath , docRef . getId ( ) ) ,
2280+ update : ( data : any ) => firebase . firestore . update ( collectionPath , docRef . getId ( ) , data ) ,
2281+ delete : ( ) => firebase . firestore . delete ( collectionPath , docRef . getId ( ) ) ,
2282+ onSnapshot : ( callback : ( doc : DocumentSnapshot ) => void ) => firebase . firestore . onSnapshot ( docRef , callback )
22662283 } ) ;
22672284 }
22682285 } ) ;
0 commit comments