From fe7d6df04f39f15c471a3a2f7343866efd94abf2 Mon Sep 17 00:00:00 2001 From: Luis Alvarez Date: Mon, 15 Feb 2021 12:02:31 -0500 Subject: [PATCH] Added a MutationHandler --- framework/commerce/utils/types.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/framework/commerce/utils/types.ts b/framework/commerce/utils/types.ts index 98e4ebbae..a06aa0477 100644 --- a/framework/commerce/utils/types.ts +++ b/framework/commerce/utils/types.ts @@ -76,6 +76,29 @@ export type HookHandler< fetcher?: HookFetcherFn } +export type MutationHandler< + // Data obj returned by the hook and fetch operation + Data, + // Input expected by the hook + Input extends { [k: string]: unknown } = {}, + // Input expected before doing a fetch operation + FetchInput extends HookFetchInput = {}, + // Custom state added to the response object of SWR + State = {} +> = { + useHook?(context: { + input: Input & { swrOptions?: SwrOptions } + useCallback( + fn: (context?: { + input?: HookFetchInput | HookSwrInput + swrOptions?: SwrOptions + }) => Data + ): ResponseState + }): ResponseState & State + fetchOptions: HookFetcherOptions + fetcher?: HookFetcherFn +} + export type SwrOptions = ConfigInterface< Data, CommerceError,