@@ -1703,10 +1703,14 @@ firebase.push = (path, val) => {
17031703 }
17041704
17051705 const pushInstance = firebase . instance . child ( path ) . push ( ) ;
1706- pushInstance . setValue ( firebase . toValue ( val ) ) ;
1707- resolve ( {
1708- key : pushInstance . getKey ( )
1706+
1707+ const onCompletionListener = new com . google . firebase . database . DatabaseReference . CompletionListener ( {
1708+ onComplete : ( error : any /* com.google.firebase.database.DatabaseError */ , dbRef : any /* com.google.firebase.database.DatabaseReference */ ) => {
1709+ error ? reject ( error . getMessage ( ) ) : resolve ( { key : pushInstance . getKey ( ) } ) ;
1710+ }
17091711 } ) ;
1712+
1713+ pushInstance . setValue ( firebase . toValue ( val ) , onCompletionListener ) ;
17101714 } catch ( ex ) {
17111715 console . log ( "Error in firebase.push: " + ex ) ;
17121716 reject ( ex ) ;
@@ -1722,8 +1726,13 @@ firebase.setValue = (path, val) => {
17221726 return ;
17231727 }
17241728
1725- firebase . instance . child ( path ) . setValue ( firebase . toValue ( val ) ) ;
1726- resolve ( ) ;
1729+ const onCompletionListener = new com . google . firebase . database . DatabaseReference . CompletionListener ( {
1730+ onComplete : ( error : any /* com.google.firebase.database.DatabaseError */ , dbRef : any /* com.google.firebase.database.DatabaseReference */ ) => {
1731+ error ? reject ( error . getMessage ( ) ) : resolve ( ) ;
1732+ }
1733+ } ) ;
1734+
1735+ firebase . instance . child ( path ) . setValue ( firebase . toValue ( val ) , onCompletionListener ) ;
17271736 } catch ( ex ) {
17281737 console . log ( "Error in firebase.setValue: " + ex ) ;
17291738 reject ( ex ) ;
@@ -1739,16 +1748,21 @@ firebase.update = (path, val) => {
17391748 return ;
17401749 }
17411750
1751+ const onCompletionListener = new com . google . firebase . database . DatabaseReference . CompletionListener ( {
1752+ onComplete : ( error : any /* com.google.firebase.database.DatabaseError */ , dbRef : any /* com.google.firebase.database.DatabaseReference */ ) => {
1753+ error ? reject ( error . getMessage ( ) ) : resolve ( ) ;
1754+ }
1755+ } ) ;
1756+
17421757 if ( typeof val === "object" ) {
1743- firebase . instance . child ( path ) . updateChildren ( firebase . toHashMap ( val ) ) ;
1758+ firebase . instance . child ( path ) . updateChildren ( firebase . toHashMap ( val ) , onCompletionListener ) ;
17441759 } else {
17451760 const lastPartOfPath = path . lastIndexOf ( "/" ) ;
17461761 const pathPrefix = path . substring ( 0 , lastPartOfPath ) ;
17471762 const pathSuffix = path . substring ( lastPartOfPath + 1 ) ;
17481763 const updateObject = '{"' + pathSuffix + '" : "' + val + '"}' ;
1749- firebase . instance . child ( pathPrefix ) . updateChildren ( firebase . toHashMap ( JSON . parse ( updateObject ) ) ) ;
1764+ firebase . instance . child ( pathPrefix ) . updateChildren ( firebase . toHashMap ( JSON . parse ( updateObject ) ) , onCompletionListener ) ;
17501765 }
1751- resolve ( ) ;
17521766 } catch ( ex ) {
17531767 console . log ( "Error in firebase.update: " + ex ) ;
17541768 reject ( ex ) ;
@@ -1879,8 +1893,14 @@ firebase.remove = path => {
18791893 reject ( "Run init() first!" ) ;
18801894 return ;
18811895 }
1882- firebase . instance . child ( path ) . setValue ( null ) ;
1883- resolve ( ) ;
1896+
1897+ const onCompletionListener = new com . google . firebase . database . DatabaseReference . CompletionListener ( {
1898+ onComplete : ( error : any /* com.google.firebase.database.DatabaseError */ , dbRef : any /* com.google.firebase.database.DatabaseReference */ ) => {
1899+ error ? reject ( error . getMessage ( ) ) : resolve ( ) ;
1900+ }
1901+ } ) ;
1902+
1903+ firebase . instance . child ( path ) . setValue ( null , onCompletionListener ) ;
18841904 } catch ( ex ) {
18851905 console . log ( "Error in firebase.remove: " + ex ) ;
18861906 reject ( ex ) ;
0 commit comments