-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
feat(firestore): Added option to include document IDs on valueChanges() #1976
Conversation
An 'idField' string arg can be used with collection.valueChanges() to include the document ID on the emitted data payload.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Maybe we can union the return type T
with [idField]: string
if possible? But that can be follow on work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work!
Just a little comment on the API.
@@ -104,12 +104,18 @@ export class AngularFirestoreCollection<T=DocumentData> { | |||
/** | |||
* Listen to all documents in the collection and its possible query as an Observable. | |||
*/ | |||
valueChanges(): Observable<T[]> { | |||
valueChanges(idField?: string): Observable<T[]> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe something like this for future proofing? Not a huge deal but it could help.
valueChanges(idField?: string): Observable<T[]> { | |
valueChanges({ idField: string }: ValueChangeOptions?): Observable<T[]> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I second using an options object for future proofing. Great PR otherwise.
@codediodeio I just created a new PR to update this PR and make If you accept this change, it will (hopefully) make this PR here able to be merged. |
feat(firestore): changed valueChanges() arg to options object
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the ℹ️ Googlers: Go here for more info. |
1 similar comment
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the ℹ️ Googlers: Go here for more info. |
I am ok with my commits being contributed to this project 👍 ! @davideast per your comment, |
A Googler has manually verified that the CLAs look good. (Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.) ℹ️ Googlers: Go here for more info. |
1 similar comment
A Googler has manually verified that the CLAs look good. (Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.) ℹ️ Googlers: Go here for more info. |
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the ℹ️ Googlers: Go here for more info. |
1 similar comment
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the ℹ️ Googlers: Go here for more info. |
A Googler has manually verified that the CLAs look good. (Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.) ℹ️ Googlers: Go here for more info. |
A Googler has manually verified that the CLAs look good. (Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.) ℹ️ Googlers: Go here for more info. |
Thanks @codediodeio and @thefliik, will ship in the next beta and this will land in the |
const ITEMS = 1; | ||
const { ref, stocks, names } = await collectionHarness(afs, ITEMS); | ||
const idField = 'myCustomID'; | ||
const sub = stocks.valueChanges({idField}).subscribe(data => { |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe they are destructuring the valueChanges object and grabbing just the idField
property.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{idField}
is shorthand for {idField: idField}
https://stackoverflow.com/questions/34414766/ Shorthand property names (ES2015)
thanks... you just ruined all the tutorials out there :) |
When i use valueChanges({ idField: 'id' }) and map i get an error like below. If i directly subscribe to it there is no problem. No problem with snapshotChanges() in both situation.
|
Checklist
yarn install
,yarn test
run successfully? YesDescription
An 'idField' string arg can be used with collection.valueChanges() to include the document ID on the emitted data payload.
Code sample