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

Yes, also FirebaseListObservable should have this.

jeffbcross avatar Jun 02 '16 01:06 jeffbcross

@jeffbcross Why do you think that @vicb should do this?

mhevery avatar Jun 03 '16 20:06 mhevery

I thought @vicb said he was going to work on it once the upgrade to firebase sdk v3 was done, but maybe I misunderstood. On Fri, Jun 3, 2016 at 1:44 PM Miško Hevery [email protected] wrote:

@jeffbcross https://github.com/jeffbcross Why do you think that @vicb https://github.com/vicb should do this?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/angular/angularfire2/issues/201#issuecomment-223689720, or mute the thread https://github.com/notifications/unsubscribe/AAcTVzMimV736dYpHzfyAfsz6i_E3oNWks5qIJINgaJpZM4Ir9fB .

jeffbcross avatar Jun 03 '16 20:06 jeffbcross

Yep Jeff, that's what we agrreed on

vicb avatar Jun 04 '16 16:06 vicb

@vicb Are you still up to the task? If not I can handle it 👍

davideast avatar Jun 27 '16 16:06 davideast

I was about to do it but because you insist, please take over ;)

It would be nice that you update periscope once angularfire supports it. Ping me if you need more info.

Thanks !!

vicb avatar Jun 27 '16 16:06 vicb

I'm having trouble coming up with benefits of adding transactions into AngularFire2. All the reasons I might use transactions are already covered by the SDK and I don't see any pain points we can solve here. It feels like a straight wrapper on the methods. Can you guys push out some use cases on why one wouldn't go straight to the SDK for this?

katowulf avatar Aug 24 '16 17:08 katowulf

@katowulf you're right - that actually what we ended up doing - forgot to close the issue, sorry

edit: can not close this myself

vicb avatar Aug 25 '16 01:08 vicb

Can you mention this somewhere in the documentation, please? I'd say it would be useful to have a part in the docs where you clarify your policy about this.

elekzalan avatar Sep 06 '16 09:09 elekzalan

:+1: on mentioning how to do this in the docs

ross-nordstrom avatar Oct 10 '16 17:10 ross-nordstrom

Hi, just wondering if an explanation on how to perform transactions ended up in the docs? Thanks

idoghoo avatar Nov 18 '16 14:11 idoghoo

Hi,

I'm trying to figure this one out too. Is there any documentation / examples?

dprof-johan avatar Dec 15 '16 14:12 dprof-johan

Docs on transactions are here: https://firebase.google.com/docs/database/web/save-data#save_data_as_transactions

katowulf avatar Dec 15 '16 16:12 katowulf

Isn't the argument for adding transaction support to Angularfire that in order to support tree shaking properly, we should refrain from using the firebase import?

larssn avatar May 03 '17 19:05 larssn

@larssn You should avoid importing all of firebase. There is no harm in importing the app/typings if you have already included the AngularFireModule and/or AngularFireDatabaseModule.

// imports only typings and app which should already be imported
import * as firebase from 'firebase/app';

You can also access the App or Database instance off of the AngularFireDatabase service.

constructor(afDb: AngularFireDatabase) {
  const firebaseDb = afDb.database;
  const firebaseApp = adDb.app;
}

davideast avatar May 03 '17 19:05 davideast

@davideast Appreciate the fast response! I'll play around with your suggestions.

larssn avatar May 03 '17 19:05 larssn

@davideast Seems its located on afDb.app.database. (This is on 4.0 Rc0)

larssn avatar May 03 '17 19:05 larssn

@larssn I just had to use .transaction() in my project, so I thought I'd share my code in case you're still working it out.

import { FirebaseApp } from 'angularfire2';
...
constructor(
    private fbApp: FirebaseApp,
) {}

pushStoryToCategories(categories: string[]) {
  categories.forEach(category => {
    const catRef = this.fbApp.database().ref(`/categories/${category}/count`);
    catRef.transaction(count => count + 1);
  }
}

I've stripped out non-essential code, but beyond the imports and injection, it's two lines of code.

markgoho avatar Jun 06 '17 14:06 markgoho

This thread got me most of the way there, but after the recent update, I had to do it this way:

import { AngularFireModule } from 'angularfire2';
import { AngularFireDatabaseModule, AngularFireDatabase } from 'angularfire2/database';

export class User {
  db: AngularFireDatabase;

  constructor(db: AngularFireDatabase) {
    this.db = db;
  }

  addDebt(amount: number) { 
    this.db.object('/users/'.concat(this.currentUserID,'/debts/',this.userID)).$ref.ref.transaction(debt => debt + amount);
  }
}

Hope this helps!

(Edit: Simplified code paste.)

GiselleSerate avatar Jul 21 '17 22:07 GiselleSerate

thank you so much for your response😄 when it was the las update?

RicardoVM64 avatar Jul 21 '17 22:07 RicardoVM64