Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 17b48f5

Browse files
committed
[database][ios] - Returns js object during transaction
1 parent 50ebc99 commit 17b48f5

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

src/firebase.ios.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)