@@ -1924,53 +1924,75 @@ firebase.firestore.collection = (collectionPath: string): firestore.CollectionRe
19241924 }
19251925} ;
19261926
1927- firebase . firestore . onDocumentSnapshot = ( docRef : FIRDocumentReference , optionsOrCallback : firestore . SnapshotListenOptions | ( ( snapshot : DocumentSnapshot ) => void ) , callback ? : ( doc : DocumentSnapshot ) => void ) : ( ) => void => {
1927+ firebase . firestore . onDocumentSnapshot = ( docRef : FIRDocumentReference , optionsOrCallback : firestore . SnapshotListenOptions | ( ( snapshot : DocumentSnapshot ) => void ) , callbackOrOnError : ( docOrError : DocumentSnapshot | Error ) => void , onError : ( error : Error ) => void ) : ( ) => void => {
19281928 let includeMetadataChanges = false ;
1929+ let onNextCallback : ( snapshot : DocumentSnapshot ) => void ;
1930+ let onErrorCallback : ( error : Error ) => void ;
1931+
19291932 if ( ( typeof optionsOrCallback ) === "function" ) {
1930- callback = < ( snapshot : DocumentSnapshot ) => void > optionsOrCallback ;
1931- } else if ( ( < firestore . SnapshotListenOptions > optionsOrCallback ) . includeMetadataChanges === true ) {
1933+ onNextCallback = < ( snapshot : DocumentSnapshot ) => void > optionsOrCallback ;
1934+ onErrorCallback = callbackOrOnError ;
1935+ } else {
1936+ onNextCallback = callbackOrOnError ;
1937+ onErrorCallback = onError ;
1938+ }
1939+
1940+ if ( ( < firestore . SnapshotListenOptions > optionsOrCallback ) . includeMetadataChanges === true ) {
19321941 includeMetadataChanges = true ;
19331942 }
19341943
19351944 const listener = docRef . addSnapshotListenerWithIncludeMetadataChangesListener ( includeMetadataChanges , ( snapshot : FIRDocumentSnapshot , error : NSError ) => {
1936- if ( ! error && snapshot ) {
1937- callback ( new DocumentSnapshot ( snapshot ) ) ;
1945+ if ( error || ! snapshot ) {
1946+ error && onErrorCallback && onErrorCallback ( new Error ( error . localizedDescription ) ) ;
1947+ return ;
19381948 }
1949+ onNextCallback && onNextCallback ( new DocumentSnapshot ( snapshot ) ) ;
19391950 } ) ;
19401951
19411952 // There's a bug resulting this function to be undefined..
19421953 if ( listener . remove === undefined ) {
19431954 return ( ) => {
19441955 // .. so we're just ignoring anything received from the server (until the callback is set again when 'onSnapshot' is invoked).
1945- callback = ( ) => {
1956+ onNextCallback = ( ) => {
19461957 } ;
19471958 } ;
19481959 } else {
19491960 return ( ) => listener . remove ( ) ;
19501961 }
19511962} ;
19521963
1953- firebase . firestore . onCollectionSnapshot = ( colRef : FIRCollectionReference , optionsOrCallback : any , callback : ( snapshot : QuerySnapshot ) => void ) : ( ) => void => {
1964+ firebase . firestore . onCollectionSnapshot = ( colRef : FIRCollectionReference , optionsOrCallback : firestore . SnapshotListenOptions | ( ( snapshot : QuerySnapshot ) => void ) , callbackOrOnError : ( snapshotOrError : QuerySnapshot | Error ) => void , onError ?: ( error : Error ) => void ) : ( ) => void => {
19541965 let includeMetadataChanges = false ;
1966+ let onNextCallback : ( snapshot : QuerySnapshot ) => void ;
1967+ let onErrorCallback : ( error : Error ) => void ;
1968+
1969+ // If we passed in an onNext for the first parameter, the next parameter would be onError if provided
1970+ // If options was the first parameter then the next parameter would be onNext if provided
19551971 if ( ( typeof optionsOrCallback ) === "function" ) {
1956- callback = < ( snapshot : QuerySnapshot ) => void > optionsOrCallback ;
1957- } else if ( ( < firestore . SnapshotListenOptions > optionsOrCallback ) . includeMetadataChanges === true ) {
1972+ onNextCallback = < ( snapshot : QuerySnapshot ) => void > optionsOrCallback ;
1973+ onErrorCallback = callbackOrOnError ;
1974+ } else {
1975+ onNextCallback = callbackOrOnError ; // Can be undefined if callback was not provided
1976+ onErrorCallback = onError ; // Can be undefined if onError was not provided
1977+ }
1978+
1979+ if ( ( < firestore . SnapshotListenOptions > optionsOrCallback ) . includeMetadataChanges === true ) {
19581980 includeMetadataChanges = true ;
19591981 }
19601982
19611983 const listener = colRef . addSnapshotListenerWithIncludeMetadataChangesListener ( includeMetadataChanges , ( snapshot : FIRQuerySnapshot , error : NSError ) => {
19621984 if ( error || ! snapshot ) {
1985+ error && onErrorCallback && onErrorCallback ( new Error ( error . localizedDescription ) ) ;
19631986 return ;
19641987 }
1965-
1966- callback ( new QuerySnapshot ( snapshot ) ) ;
1988+ onNextCallback && onNextCallback ( new QuerySnapshot ( snapshot ) ) ;
19671989 } ) ;
19681990
19691991 // There's a bug resulting in this function to be undefined..
19701992 if ( listener . remove === undefined ) {
19711993 return ( ) => {
19721994 // .. so we're just ignoring anything received from the server (until the callback is set again when 'onSnapshot' is invoked).
1973- callback = ( ) => {
1995+ onNextCallback = ( ) => {
19741996 } ;
19751997 } ;
19761998 } else {
@@ -1987,14 +2009,15 @@ firebase.firestore._getCollectionReference = (colRef?: FIRCollectionReference):
19872009
19882010 return {
19892011 id : colRef . collectionID ,
1990- parent : firebase . firestore . _getDocumentReference ( colRef . parent ) ,
2012+ parent : firebase . firestore .
2013+ mentReference ( colRef . parent ) ,
19912014 doc : ( documentPath ?: string ) => firebase . firestore . doc ( collectionPath , documentPath ) ,
19922015 add : document => firebase . firestore . add ( collectionPath , document ) ,
19932016 get : ( ) => firebase . firestore . get ( collectionPath ) ,
19942017 where : ( fieldPath : string , opStr : firestore . WhereFilterOp , value : any ) => firebase . firestore . where ( collectionPath , fieldPath , opStr , value ) ,
19952018 orderBy : ( fieldPath : string , directionStr : firestore . OrderByDirection ) : firestore . Query => firebase . firestore . orderBy ( collectionPath , fieldPath , directionStr , colRef ) ,
19962019 limit : ( limit : number ) : firestore . Query => firebase . firestore . limit ( collectionPath , limit , colRef ) ,
1997- onSnapshot : ( optionsOrCallback : firestore . SnapshotListenOptions | ( ( snapshot : QuerySnapshot ) => void ) , callback ?: ( snapshot : QuerySnapshot ) => void ) => firebase . firestore . onCollectionSnapshot ( colRef , optionsOrCallback , callback ) ,
2020+ onSnapshot : ( optionsOrCallback : firestore . SnapshotListenOptions | ( ( snapshot : QuerySnapshot ) => void ) , callbackOrOnError ?: ( snapshotOrError : QuerySnapshot | Error ) => void , onError ?: ( error : Error ) => void ) => firebase . firestore . onCollectionSnapshot ( colRef , optionsOrCallback , callbackOrOnError , onError ) ,
19982021 startAfter : ( document : DocumentSnapshot ) => firebase . firestore . startAfter ( collectionPath , document , colRef ) ,
19992022 startAt : ( document : DocumentSnapshot ) => firebase . firestore . startAt ( collectionPath , document , colRef ) ,
20002023 endAt : ( document : DocumentSnapshot ) => firebase . firestore . endAt ( collectionPath , document , colRef ) ,
@@ -2019,7 +2042,7 @@ firebase.firestore._getDocumentReference = (docRef?: FIRDocumentReference): fire
20192042 get : ( ) => firebase . firestore . getDocument ( collectionPath , docRef . documentID ) ,
20202043 update : ( data : any ) => firebase . firestore . update ( collectionPath , docRef . documentID , data ) ,
20212044 delete : ( ) => firebase . firestore . delete ( collectionPath , docRef . documentID ) ,
2022- onSnapshot : ( optionsOrCallback : firestore . SnapshotListenOptions | ( ( snapshot : DocumentSnapshot ) => void ) , callback ?: ( snapshot : DocumentSnapshot ) => void ) => firebase . firestore . onDocumentSnapshot ( docRef , optionsOrCallback , callback ) ,
2045+ onSnapshot : ( optionsOrCallback : firestore . SnapshotListenOptions | ( ( snapshot : DocumentSnapshot ) => void ) , callbackOrOnError ?: ( docOrError : DocumentSnapshot | Error ) => void , onError ?: ( error : Error ) => void ) => firebase . firestore . onDocumentSnapshot ( docRef , optionsOrCallback , callbackOrOnError , onError ) ,
20232046 ios : docRef
20242047 } ;
20252048} ;
@@ -2286,7 +2309,7 @@ firebase.firestore._getQuery = (collectionPath: string, query: FIRQuery): firest
22862309 where : ( fp : string , os : firestore . WhereFilterOp , v : any ) : firestore . Query => firebase . firestore . where ( collectionPath , fp , os , v , query ) ,
22872310 orderBy : ( fp : string , directionStr : firestore . OrderByDirection ) : firestore . Query => firebase . firestore . orderBy ( collectionPath , fp , directionStr , query ) ,
22882311 limit : ( limit : number ) : firestore . Query => firebase . firestore . limit ( collectionPath , limit , query ) ,
2289- onSnapshot : ( optionsOrCallback : firestore . SnapshotListenOptions | ( ( snapshot : QuerySnapshot ) => void ) , callback ?: ( snapshot : QuerySnapshot ) => void ) => firebase . firestore . onCollectionSnapshot ( query , optionsOrCallback , callback ) ,
2312+ onSnapshot : ( optionsOrCallback : firestore . SnapshotListenOptions | ( ( snapshot : QuerySnapshot ) => void ) , callbackOrOnError ?: ( snapshotOrError : QuerySnapshot | Error ) => void , onError ?: ( error : Error ) => void ) => firebase . firestore . onCollectionSnapshot ( query , optionsOrCallback , callbackOrOnError , onError ) ,
22902313 startAfter : ( document : DocumentSnapshot ) => firebase . firestore . startAfter ( collectionPath , document , query ) ,
22912314 startAt : ( document : DocumentSnapshot ) => firebase . firestore . startAt ( collectionPath , document , query ) ,
22922315 endAt : ( document : DocumentSnapshot ) => firebase . firestore . endAt ( collectionPath , document , query ) ,
0 commit comments