javascript - Firebase transaction does not update actual value in the Firebase DB -
i using angularjs , firebase in app. when user press button want increase price of auctioning item $0.01 , after has been committed firebase db - deduct $1.00 user's balance. use firebase transaction() that, value of item not updated in firebase db:
$scope.auctionpriceref = travelbidsfirebaseref.child('auction/' + $scope.auction.id + '/price'); $scope.auctionpriceref.transaction(function(currentvalue) { console.log("current val + 0.01: " + (currentvalue + 0.01)); return currentvalue + 0.01; }, function(error, committed, snapshot) { if (error) { console.error("error increasing auction price: " + error); } if (committed) { console.log("successfully increased auction price to: " + snapshot.val()); $rootscope.authuser.balance -= 1.0; } });
this code executes without errors , can see following output @ console (the initial price of item 1.00):
current val + 0.01: 1.01 increased auction price to: 1
the collback executed, no error snapshot value wrong. when check in forge can confirm value has not been updated there. strange... there strange thing here: when click button several times fast transactions being committed. did experienced similar behaviour or has explanation that? code seems correct... or not?
the problem not in transaction() in fact have bound parent object of 'price' - auction local scope variable:
angularfire(travelbidsfirebaseref + "/auction/" + $scope.auctionid, $scope, 'auction', {});
right before transaction update 'price' triggered, update property - 'enddate' of bound auction object:
$scope.auction.enddate = new date(millis).toutcstring();
this line of code triggers update of whole auction object, including 'price'. expected 'enddate' property updated.
this king of code creates racing condition 'price' update overriden right after commit , collback returns not expecting.
it's important understand data being syncronized firebase, , don't create multiple references same data - may kick in ... when app becomes more complicated.
Comments
Post a Comment