-
Notifications
You must be signed in to change notification settings - Fork 401
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
add useCallableFunctionResponse #449
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { httpsCallable as rxHttpsCallable } from 'rxfire/functions'; | ||
import { ReactFireOptions, useObservable, ObservableStatus } from './'; | ||
import { useFunctions } from '.'; | ||
|
||
import type { HttpsCallableOptions } from 'firebase/functions'; | ||
|
||
/** | ||
* Calls a callable function. | ||
* | ||
* @param functionName - The name of the function to call | ||
* @param options | ||
*/ | ||
export function useCallableFunctionResponse<RequestData, ResponseData>( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ☝️ this is where it is implemented |
||
functionName: string, | ||
options?: ReactFireOptions<ResponseData> & { | ||
httpsCallableOptions?: HttpsCallableOptions; | ||
data?: RequestData; | ||
} | ||
): ObservableStatus<ResponseData> { | ||
const functions = useFunctions(); | ||
const observableId = `functions:callableResponse:${functionName}:${JSON.stringify(options?.data)}:${JSON.stringify(options?.httpsCallableOptions)}`; | ||
const obsFactory = rxHttpsCallable<RequestData, ResponseData>(functions, functionName, options?.httpsCallableOptions); | ||
|
||
//@ts-expect-error because RxFire doesn't make data optional. Remove when https://github.com/FirebaseExtended/rxfire/pull/34 is released. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
const observable$ = obsFactory(options?.data); | ||
|
||
return useObservable(observableId, observable$, options); | ||
} |
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.
What do you think about the name
useCallableFunctionResponse
? It's a little wordy because I wanted to emphasize that this would call the callable function and update with the response. Any suggestions to make it shorter/better?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.
Wordy but I like that it's very explicit. SGTM