@@ -9,7 +9,7 @@ import * as firebaseMessaging from "./messaging/messaging";
99import * as application from "tns-core-modules/application/application" ;
1010import { ios as iOSUtils } from "tns-core-modules/utils/utils" ;
1111import * as firebaseFunctions from './functions/functions' ;
12- import { firestore , User , OnDisconnect as OnDisconnectBase , transaction , DataSnapshot } from "./firebase" ;
12+ import { firestore , User , OnDisconnect as OnDisconnectBase , DataSnapshot } from "./firebase" ;
1313import { firebaseUtils } from "./utils" ;
1414
1515firebase . _gIDAuthentication = null ;
@@ -1546,9 +1546,23 @@ firebase.transaction = (path: string, transactionUpdate: (currentState) => any,
15461546
15471547 dbRef . runTransactionBlockAndCompletionBlock (
15481548 ( mutableData : FIRMutableData ) : FIRTransactionResult => {
1549- const desiredValue = transactionUpdate ( mutableData . value ) ;
1549+ const desiredValue = transactionUpdate ( firebaseUtils . toJsObject ( mutableData . value ) ) ;
15501550 if ( desiredValue === undefined ) {
1551- return FIRTransactionResult . abort ( ) ;
1551+ // The problem case : user returns undefined when the the value we give them (mutableData) is null.
1552+ // This is a valid case as the user will want to abort if he thinks theres no data, BUT mutualData
1553+ // is usually null when runTransaction is called the first time(which is why its called multiple times).
1554+ // Result: we would abort and the transaction terminates, but the real data didn't have a chance to come in
1555+ // for the function to be called a second time.
1556+ // Even in the ios simple blog example their complete block is called twice with committed first being false
1557+ // followed by a second one saying committed is true... So with this implementation I favored having an "incorrect"
1558+ // committed boolean, but have the correct updated value
1559+
1560+ // TLDR: if user returns undefined then we may never execute his function with the correct input
1561+ // For now the way to resolve this is to call success with the original value (so we don't modify anything)
1562+ // And then the user will get his expected value, but { committed: always true }....
1563+
1564+ // return FIRTransactionResult.abort();
1565+ return FIRTransactionResult . successWithValue ( mutableData ) ;
15521566 } else {
15531567 mutableData . value = desiredValue ;
15541568 return FIRTransactionResult . successWithValue ( mutableData ) ;
0 commit comments