Skip to content

firestore: DocumentChangeAction is not exported #1249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Toxicable opened this issue Oct 11, 2017 · 1 comment
Closed

firestore: DocumentChangeAction is not exported #1249

Toxicable opened this issue Oct 11, 2017 · 1 comment

Comments

@Toxicable
Copy link

DocumentChangeAction dosen't appear to be exported as a public API, along with all the interfaces under interfaces.ts, not sure about the other interfaces but DocumentChangeAction is exposed by .snapshotChanges(), therefore it should also be exported.

Use Case

Transforming the data into data with it's id in a function to avoid code duplication

function addIdsToItems(items: DocumentChangeAction[]) {
  return items.map(a => {
    const data = a.payload.doc.data() as Pizza;
    const id = a.payload.doc.id;
    return { id, ...data };
  });
}

//use
this.itemsRef.snapshotChanges().map(addIdsToItems);

Speaking of which, it would be nice if AngularFire provided this or a similar function since it's super boiler plately and i'm sure everyone needs to use it

code ref: https://github.com/angular/angularfire2/blob/a3c746d6dedbeb8368d5acd4ed76d278494bfd64/src/firestore/interfaces.ts#L4

@davideast
Copy link
Collaborator

@Toxicable Want to send in a PR to export the type?

I hear you on the boilerplate method. However, we can't assume the id key name. A user could easily store id as something else entirely. The official SDK is looking into supporting auto applying __id__ to the doc.data() call and then stripping it on the update. That is the idea solution because it will be like $key except we don't have to do anything in AngularFire land to support it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants