Skip to content

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

Closed
@codediodeio

Description

@codediodeio

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions