forked from crowetic/commerce
Added a default fetcher
This commit is contained in:
parent
d8de84bed1
commit
883fbcbcb9
@ -5,6 +5,7 @@ import type {
|
|||||||
UseHookInput,
|
UseHookInput,
|
||||||
UseHookResponse,
|
UseHookResponse,
|
||||||
} from '../utils/types'
|
} from '../utils/types'
|
||||||
|
import defaultFetcher from '../utils/default-fetcher'
|
||||||
import useData from '../utils/use-data-2'
|
import useData from '../utils/use-data-2'
|
||||||
import { Provider, useCommerce } from '..'
|
import { Provider, useCommerce } from '..'
|
||||||
|
|
||||||
@ -27,14 +28,7 @@ export type UseCustomer<P extends Provider> = Partial<
|
|||||||
? (input?: UseCustomerInput<P>) => CustomerResponse<P>
|
? (input?: UseCustomerInput<P>) => CustomerResponse<P>
|
||||||
: (input: UseCustomerInput<P>) => CustomerResponse<P>
|
: (input: UseCustomerInput<P>) => CustomerResponse<P>
|
||||||
|
|
||||||
export const fetcher: HookFetcherFn<Customer | null> = async ({
|
export const fetcher = defaultFetcher as HookFetcherFn<Customer | null>
|
||||||
options,
|
|
||||||
fetch,
|
|
||||||
normalize,
|
|
||||||
}) => {
|
|
||||||
const data = await fetch({ ...options })
|
|
||||||
return data && normalize ? normalize(data) : data
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function useCustomer<P extends Provider>(
|
export default function useCustomer<P extends Provider>(
|
||||||
input: UseCustomerInput<P> = {}
|
input: UseCustomerInput<P> = {}
|
||||||
|
12
framework/commerce/utils/default-fetcher.ts
Normal file
12
framework/commerce/utils/default-fetcher.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import { HookFetcherFn } from './types'
|
||||||
|
|
||||||
|
const defaultFetcher: HookFetcherFn<any> = async ({
|
||||||
|
options,
|
||||||
|
fetch,
|
||||||
|
normalize,
|
||||||
|
}) => {
|
||||||
|
const data = await fetch({ ...options })
|
||||||
|
return data && normalize ? normalize(data) : data
|
||||||
|
}
|
||||||
|
|
||||||
|
export default defaultFetcher
|
@ -5,6 +5,7 @@ import type {
|
|||||||
UseHookInput,
|
UseHookInput,
|
||||||
UseHookResponse,
|
UseHookResponse,
|
||||||
} from '../utils/types'
|
} from '../utils/types'
|
||||||
|
import defaultFetcher from '../utils/default-fetcher'
|
||||||
import useData from '../utils/use-data-2'
|
import useData from '../utils/use-data-2'
|
||||||
import { Provider, useCommerce } from '..'
|
import { Provider, useCommerce } from '..'
|
||||||
|
|
||||||
@ -27,14 +28,7 @@ export type UseWishlist<P extends Provider> = Partial<
|
|||||||
? (input?: UseWishlistInput<P>) => WishlistResponse<P>
|
? (input?: UseWishlistInput<P>) => WishlistResponse<P>
|
||||||
: (input: UseWishlistInput<P>) => WishlistResponse<P>
|
: (input: UseWishlistInput<P>) => WishlistResponse<P>
|
||||||
|
|
||||||
export const fetcher: HookFetcherFn<Wishlist | null> = async ({
|
export const fetcher = defaultFetcher as HookFetcherFn<Wishlist | null>
|
||||||
options,
|
|
||||||
fetch,
|
|
||||||
normalize,
|
|
||||||
}) => {
|
|
||||||
const data = await fetch({ ...options })
|
|
||||||
return data && normalize ? normalize(data) : data
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function useWishlist<P extends Provider>(
|
export default function useWishlist<P extends Provider>(
|
||||||
input: UseWishlistInput<P> = {}
|
input: UseWishlistInput<P> = {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user