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

Commit 12b5a2a

Browse files
committed
[docs] - Update Transaction documentation
1 parent 15ea235 commit 12b5a2a

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

docs/DATABASE.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,10 +431,9 @@ firebase.transaction(path, (currentValue => {
431431
if (currentValue === null) {
432432
return 0;
433433
} else {
434-
// console.log('User ada already exists.');
435-
return ++currentValue; // Abort the transaction.
434+
return ++currentValue; // Increment the current value. Do not try to increment currentValue if its NaN!
436435
}
437-
})) // firebase.Datasnapshot follows the web datasnapshot interface
436+
}))
438437
.then((result: { committed: boolean, snapshot: firebase.DataSnapshot }) => {
439438
console.log(result.committed + " snapshotValue: " + result.snapshot.val());
440439
}).catch(err => console.log("Encountered an error " + err));
@@ -460,7 +459,7 @@ firebaseWebApi.database().ref(path).transaction(currentValue => {
460459

461460
firebaseWebApi.database().ref(path).transaction(currentValue => {
462461
if (currentValue === null) {
463-
return null; // Do nothing if this value doesn't exist
462+
return null; // Do nothing if this value doesn't exist or return undefined (null works here because theres nothing at this path)
464463
//return 0 // If you want to put a 0 in if no value exist
465464
} else {
466465
return ++currentValue; // increment the value

0 commit comments

Comments
 (0)