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

Commit 50ebc99

Browse files
committed
[database][android] - Return mutable data as a js object
By returning as an object we can easily update an entire node in the database and return back the updated object.
1 parent 0493235 commit 50ebc99

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

src/firebase.android.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,14 +1807,22 @@ firebase.transaction = (path: string, transactionUpdate: (currentState) => any,
18071807
const dbRef: com.google.firebase.database.DatabaseReference = firebase.instance.child(path);
18081808
const handler: com.google.firebase.database.Transaction.Handler = new com.google.firebase.database.Transaction.Handler({
18091809
doTransaction: (mutableData: com.google.firebase.database.MutableData) => {
1810-
const desiredValue = transactionUpdate(mutableData.getValue());
1810+
const desiredValue = transactionUpdate(firebase.toJsObject(mutableData.getValue()));
18111811
// Java does not have undefined, but web transactions use undefined to detect if an abort() is desired.
18121812
if (desiredValue === undefined) {
1813-
return com.google.firebase.database.Transaction.abort();
1814-
} else {
1815-
mutableData.setValue(firebase.toValue(desiredValue));
1813+
// Same problem as iOS. The very first call to runTransaction will see that we get undefined
1814+
// and immediately abort the transaction which results in us failing to update the value. Subsequent
1815+
// calls are working fine unlike in iOS which always fail.
1816+
1817+
// TLDR: Abort would be ideal, but atm it can result in a failed update (when it shouln't)
1818+
// Returning success fixes this but makes our { committed: always true }...
1819+
1820+
// return com.google.firebase.database.Transaction.abort();
18161821
return com.google.firebase.database.Transaction.success(mutableData);
18171822
}
1823+
mutableData.setValue(firebase.toValue(desiredValue));
1824+
return com.google.firebase.database.Transaction.success(mutableData);
1825+
18181826
},
18191827
onComplete: (databaseError: com.google.firebase.database.DatabaseError, commited: boolean, snapshot: com.google.firebase.database.DataSnapshot) => {
18201828
databaseError !== null ? reject(databaseError.getMessage()) :

0 commit comments

Comments
 (0)