-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat(firestore): Add support for SnapshotListenOptions #1813
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
Conversation
Will it be better if we can directly specify {source : 'server'} instead of reading metadata? That way, the subscribe to valuechanges / snapshot will only fire once. Today, subscribe fires two times, one for cached data and another for server data. Even today, I can look at 'fromCache' property and identify whether it's cached data or loaded from server. Not sure how including metadata will be different. |
@TyagiAnkit40 You can do something like Try something like this: afs.collection('items').snapshotChanges({ includeMetadataChanges: true }).pipe(
filter(actions => actions.filter(a => a.payload.meta.fromCache === false)),
map(actions => actions.map(a => a.payload.data())
).subscribe(console.log)); |
} | ||
|
||
/** | ||
* Create a stream of synchronized changes. This method keeps the local array in sorted | ||
* query order. | ||
* @param events | ||
*/ | ||
snapshotChanges(events?: DocumentChangeType[]): Observable<DocumentChangeAction<T>[]> { | ||
snapshotChanges(eventsOrOptions?: DocumentChangeType[] | firestore.SnapshotListenOptions, options?: firestore.SnapshotListenOptions): Observable<DocumentChangeAction<T>[]> { | ||
let events: DocumentChangeType[] = []; |
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.
Use validateEventsOrOptions
here?
let events: DocumentChangeType[] = []; | ||
let listenerOptions: firestore.SnapshotListenOptions | undefined = options; | ||
if(Array.isArray(eventsOrOptions)) { | ||
events = eventsOrOptions; |
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.
would it make sense to pass into validateEventsArray
here?
.pipe( | ||
map(payload => ({ payload, type: 'value' })) | ||
); | ||
export function fromDocRef<T>(ref: DocumentReference): Observable<DocumentSnapshot<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.
Do we want to drop the payload
/type
in this commit? If so let's make sure to address the docs.
After a lengthy discussion with @jamesdaniels we decided it was best to include these changes into the new #1819 proposal and keep these methods stable. We don't provide access to the |
Addressing #1747.
Add support for metadata changes via the SnapshotListenOptions
In some cases you need to listen to metadata updates to know if you want to surface an event. If you only want to display server data or know when something offline has been modified.