This repository was archived by the owner on Apr 4, 2023. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -416,7 +416,9 @@ same time.
416416You can look at the [ docs] ( https://firebase.google.com/docs/reference/js/firebase.database.Reference#transaction ) for more information.
417417
418418Note that a return value of ` null ` will delete the value at this location whereas returning
419- undefined will abort the transaction. On success a promise is returned containing
419+ undefined will not modify the data at this location. Firebase web aborts the transaction when
420+ given an undefined, but due to technically difficulties we just return transaction success which
421+ results in committed = true. On transaction complete a promise is returned containing
420422{committed: boolean , snapshot: DataSnapshot} and an error will be returned if the transaciton
421423failed.
422424
@@ -463,6 +465,25 @@ firebaseWebApi.database().ref(path).transaction(currentValue => {
463465 return ++ currentValue ; // increment the value
464466 }
465467 })
468+
469+ // Based off Firebase simple blog post. You can also treat the
470+ // data as an object and return an updated version of post
471+ firebaseWebApi .database ().ref (path ).transaction (function (post ) {
472+ if (post ) {
473+ console .log (" Post Object looks like: " + JSON .stringify (post ));
474+ if (post .stars && post .stars [uid ]) {
475+ post .starCount -- ;
476+ post .stars [uid ] = null ;
477+ } else {
478+ post .starCount ++ ;
479+ if (! post .stars ) {
480+ post .stars = {};
481+ }
482+ post .stars [uid ] = true ;
483+ }
484+ }
485+ return post ;
486+ });
466487```
467488</details >
468489
You can’t perform that action at this time.
0 commit comments