angular / angularfire

Angular + Firebase = ❤️
https://firebaseopensource.com/projects/angular/angularfire2
MIT License
7.64k stars 2.2k forks source link

Proposal: Optionally return a document ID on valueChanges() #1973

Closed codediodeio closed 3 years ago

codediodeio commented 5 years ago

A major pain point with angularfire continues to be mapping a document ID to a collection query. I propose we add an optional withId argument to collection.valueChanges(). This can be a simple non-breaking change and I can PR it.

collection.valueChanges(withId?: string)

// emits [ { myIdKey: 'MrfFpRBfWLTd7LqiTt9u', ...data }, ... ]

This will greatly simplify the code below

// current requirement
ref.snapshotChanges()
      .pipe(
        map(actions => {
          return actions.map(a => {
            const data = a.payload.doc.data();
            const id = a.payload.doc.id;
            return { myIdKey: id, ...data };
          });
})

// after change 

ref.valueChanges('myIDKey')
codercatdev commented 5 years ago

Oh please yes!

AJHanekom commented 5 years ago

Yes please.

balajkhan07 commented 5 years ago

That would be great.

rtpHarry commented 4 years ago

This can be closed it was merged with #1976 (and thanks)