Angularfire: Proposal: Optionally return a document ID on valueChanges()

Created on 15 Dec 2018  路  4Comments  路  Source: angular/angularfire

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')

Most helpful comment

That would be great.

All 4 comments

Oh please yes!

Yes please.

That would be great.

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

goekaypamuk picture goekaypamuk  路  3Comments

StephenFluin picture StephenFluin  路  3Comments

Maistho picture Maistho  路  3Comments

Leanvitale picture Leanvitale  路  3Comments

fisherds picture fisherds  路  3Comments