Skip to content

Commit

Permalink
fix: onCreate, onUpdate and onDelete receive a DocumentQuerySnapshopt
Browse files Browse the repository at this point in the history
The arguments of Firestore triggers `onCreate`, `onUpdate` and `onDelete` cannot have an undefined data by definition, so we changed the arguments of those handlers to reflect that by using DocumentQuerySnapshot.

fixes firebase#659
  • Loading branch information
sk- committed Apr 24, 2020
1 parent 1dde3db commit af19fa1
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/providers/firestore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const service = 'firestore.googleapis.com';
export const defaultDatabase = '(default)';
let firestoreInstance: any;
export type DocumentSnapshot = firebase.firestore.DocumentSnapshot;
export type QueryDocumentSnapshot = firebase.firestore.QueryDocumentSnapshot;

/**
* Select the Firestore document to listen to for events.
Expand Down Expand Up @@ -204,30 +205,30 @@ export class DocumentBuilder {
/** Respond only to document updates. */
onUpdate(
handler: (
change: Change<DocumentSnapshot>,
change: Change<QueryDocumentSnapshot>,
context: EventContext
) => PromiseLike<any> | any
): CloudFunction<Change<DocumentSnapshot>> {
): CloudFunction<Change<QueryDocumentSnapshot>> {
return this.onOperation(handler, 'document.update', changeConstructor);
}

/** Respond only to document creations. */
onCreate(
handler: (
snapshot: DocumentSnapshot,
snapshot: QueryDocumentSnapshot,
context: EventContext
) => PromiseLike<any> | any
): CloudFunction<DocumentSnapshot> {
): CloudFunction<QueryDocumentSnapshot> {
return this.onOperation(handler, 'document.create', snapshotConstructor);
}

/** Respond only to document deletions. */
onDelete(
handler: (
snapshot: DocumentSnapshot,
snapshot: QueryDocumentSnapshot,
context: EventContext
) => PromiseLike<any> | any
): CloudFunction<DocumentSnapshot> {
): CloudFunction<QueryDocumentSnapshot> {
return this.onOperation(
handler,
'document.delete',
Expand Down

0 comments on commit af19fa1

Please sign in to comment.