import type { ComponentClass } from 'react'; import type CommerceDataSource from './CommerceDataSource'; import type { ProductQuery } from './types/ProductQuery'; /** * Additional props that are used both by the high order component and passed to the wrapped * component. * * @template Source The type of datasource. Defaults to `CommerceDataSource`. */ export interface WithCommerceSharedProps { /** * Instance of the provided or constructed Data Source which is provided as a property * to the wrapped component. */ commerceDataSource: Source; } /** * Additional props that are consumed by the high order component. * * @template Data The type of data provided to the wrapped component. * @template Source The type of datasource. Defaults to `CommerceDataSource`. */ export interface WithCommerceProviderProps extends WithCommerceSharedProps { /** * Called when new data has been loaded. */ onDataLoaded?: (data: Data) => void; /** * Called when an error occurs while attempting to load new data. */ onDataError?: (error: Error) => void; } /** * Props to provide the commerce data. * * @template Data The type of data provided to the wrapped component. */ export interface WithCommerceDataProps { /** * Loaded commerce data. */ commerceData?: Readonly; isLoading?: boolean; } /** * Additional props that will be provided to the wrapped component. * * @template Data The type of data provided to the wrapped component. * @template Source The type of datasource. Defaults to `CommerceDataSource`. */ export interface WithCommerceProps extends WithCommerceSharedProps, WithCommerceDataProps { /** * A function that loads and updates commerceData. Arbitrary data to load can be provided as * an optional argument. */ commerceLoadData: (data?: Data) => void; /** * A function that loads and appends new products to the existing list of products in * commerceData. */ commerceProviderLoadMore: (productQuery: ProductQuery) => Promise; } /** * The state of the CommerceProvider component which is passed to the wrapped component as a prop. * * @template Data The type of data provided to the wrapped component. */ export declare type WithCommerceState = WithCommerceDataProps; /** * A function that fetches data using the given datasource for a given query. * * @template P The original props of the wrapped component. * @template Data The type of data provided to the wrapped component. * @template Source The type of datasource. Defaults to `CommerceDataSource`. * @param datasource The datasource with which to fetch the data. * @param props The props passed to the wrapped component. * @param query Deprecated. Additional query parameters to restrict the data further. */ export declare type FetchDataFunction = (datasource: Readonly, props: Readonly

, query?: ProductQuery) => Promise; /** * A function that fetches data using the given datasource for a given query. * * @template P The original props of the wrapped component. * @template Data The type of data provided to the wrapped component. * @param props The props passed to the wrapped component. */ export declare type InitialDataFunction = (props: Readonly

) => Data | undefined; /** * A function that wraps a a component and returns a new high order component. The wrapped * component will be given commerce data as props. * * @template P The original props of the wrapped component. * @template Data The type of product data that will be provided. * @template Source The type of datasource providing the data. Defaults to `CommerceDataSource`. * @param WrappedComponent A component to wrap * and provide commerce data to as props. * @return A high order component. */ export declare type CommerceWrapper = (WrappedComponent: ComponentClass

>) => ComponentClass

>; /** * Function that wraps a specified component with additional properties and state allowing * it to interact with a Commerce Data Source. * * @template P The original props of the wrapped component. * @template Data The type of product data that will be provided. * @template Source The type of datasource providing the data. Defaults to `CommerceDataSource`. * @param fetchData Function to retrieve commerce data * @param initialData Function to determine initial data to be * loaded into the provider * @return A function that wraps a a component and returns a new * high order component. The wrapped component will be given commerce data as props. */ declare function withCommerceData(fetchData: FetchDataFunction, initialData?: InitialDataFunction): CommerceWrapper; export default withCommerceData;