Skip to content

Commit

Permalink
- remove onSnapshot onCompletion parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
tylim88 committed Jul 18, 2022
1 parent 06de400 commit 9237764
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 46 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## v1.5.0 19-July-2022

- rename setting `allFieldsPossiblyUndefined` as `allFieldsPossiblyReadAsUndefined`
- remove onSnapshot onCompletion parameter

## v1.3.0 6-May-2022

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"test": "firebase emulators:exec --only firestore \"rm -rf coverage && jest --forceExit\"",
"parcel": "npm un firebase && npm i firebase && rm -rf dist && tsc --emitDeclarationOnly true && parcel build && npm i -D firebase",
"build": "rm -rf dist && tsc",
"link": "npm link && npm link firelordjs",
"link": "npm unlink firelordjs && npm link && npm link firelordjs",
"dev": "---------------------dev------------------------",
"d-link": "npm run build && npm run link",
"d-test": "tsc && npm test",
Expand Down
3 changes: 0 additions & 3 deletions src/onSnapshot/onSnapshot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ describe('test onSnapshot', () => {
unsub()
done()
},
() => {
//
},
() => {
//
}
Expand Down
43 changes: 3 additions & 40 deletions src/onSnapshot/onSnapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,64 +27,27 @@ export const isOptions = (
export const onSnapshot: OnSnapshot = (
reference,
onNext,
onError,
onCompletion?: (() => void) | OriSnapshotListenOptions,
onError?: ((error: FirestoreError) => void) | OriSnapshotListenOptions,
options?: OriSnapshotListenOptions
) => {
const newOnError = isOptions(onError) ? undefined : onError
const newOnCompletion = isOptions(onCompletion) ? undefined : onCompletion
const newOptions =
options ||
(isOptions(onError) ? onError : undefined) ||
(isOptions(onCompletion) ? onCompletion : undefined)
const newOptions = options || (isOptions(onError) ? onError : undefined)

return newOptions
? onSnapshot_(reference as OriQuery, newOptions, {
// @ts-expect-error
next: onNext,
error: newOnError,
complete: newOnCompletion,
})
: onSnapshot_(
reference as OriQuery,
// @ts-expect-error
onNext,
newOnError,
newOnCompletion
newOnError
)
}

type OnSnapshot = {
/**
* Attaches a listener for `DocumentSnapshot` events. You may either pass
* individual `onNext` and `onError` callbacks or pass a single observer
* object with `next` and `error` callbacks.
*
* NOTE: Although an `onCompletion` callback can be provided, it will
* never be called because the snapshot stream is never-ending.
*
* @param reference - A reference to the document to listen to.
* @param onNext - A callback to be called every time a new `DocumentSnapshot`
* is available.
* @param onError - An optional callback to be called if the listen fails or is
* cancelled. No further callbacks will occur.
* @param onCompletion - optional callback, but will not be called since streams are
* never ending.
* @param options - Options controlling the listen behavior.
* @returns An unsubscribe function that can be called to cancel
* the snapshot listener.
*/
<T extends MetaType, Ref extends Query<T> | DocumentReference<T>>(
reference: Ref extends never ? Ref : Query<T> | DocumentReference<T>,
onNext: (
snapshot: Ref extends DocumentReference<T>
? DocumentSnapshot<T>
: QuerySnapshot<T>
) => void,
onError?: (error: FirestoreError) => void,
onCompletion?: () => void,
options?: SnapshotListenOptions
): Unsubscribe
/**
* Attaches a listener for `DocumentSnapshot` events. You may either pass
* individual `onNext` and `onError` callbacks or pass a single observer
Expand Down

0 comments on commit 9237764

Please sign in to comment.