angularfire icon indicating copy to clipboard operation
angularfire copied to clipboard

Please support transaction API

Open mhevery opened this issue 10 years ago • 27 comments

https://www.firebase.com/docs/web/api/firebase/transaction.html

My guess is that it should be on FirebaseObjectObservable.transaction

mhevery avatar Jun 01 '16 20:06 mhevery

For Firestore Transactions, the process is similar:

import { FirebaseApp } from 'angularfire2';
...
export class QuestionComponent implements OnInit {
  questionRef;

  constructor(private fb: FirebaseApp) {}
  ngOnInit() {
    this.questionRef = this.fb.firestore().collection('questions').doc(this.id);
  }

  voteYes() {
    this.fb.firestore().runTransaction(transaction => {
      return transaction.get(this.questionRef).then(question => {
        const newVotes = question.data().yesVotes + 1;
        transaction.update(this.questionRef, { yesVotes: newVotes });
      });
    });
  }

markgoho avatar Dec 07 '17 01:12 markgoho

@markgoho I was just wondering about this, and you commented less than an hour ago. Very cool fo you and coincidental.

aaronfrost avatar Dec 07 '17 03:12 aaronfrost

@markgoho @aaronfrost Would you two be interested in an observable form of this API?

davideast avatar Dec 07 '17 03:12 davideast

vs Promise based... why not. Not a huge pain to deal with a promise here.

aaronfrost avatar Dec 07 '17 03:12 aaronfrost

@davideast I would love to see something observable based!

markgoho avatar Dec 07 '17 03:12 markgoho

I should PR this to the documentation. It's sad that it's buried all the way over here in this 18 month old closed issue.

aaronfrost avatar Dec 07 '17 03:12 aaronfrost

Can anyone take a look at https://stackoverflow.com/questions/50215622/firebase-database-transaction-with-angularfire2 ? I can't get this to work.

cengiz-dev avatar May 07 '18 16:05 cengiz-dev