import { ActionCreator , AnyAction , Dispatch } from "redux" ; import { ThunkAction } from "redux-thunk" ; import { getProduct as getProductFromAPI , getProducts as getProductsFromAPI } from "./ProductsData" ; import { IProductsGetAllAction , IProductsGetSingleAction , IProductsLoadingAction , IProductsState , ProductsActionTypes } from "./ProductsTypes" ; const loading = ( ) => ( { type : ProductsActionTypes . LOADING } ) ; export const getProducts = ( ) => { return async ( dispatch ) => { dispatch ( loading ( ) ) ; const products = await getProductsFromAPI ( ) ; return dispatch ( { products , type : ProductsActionTypes . GETALL } ) ; } ; } ; export const getProduct = ( id ) => { return async ( dispatch ) => { dispatch ( loading ( ) ) ; const product = await getProductFromAPI ( id ) ; dispatch ( { product , type : ProductsActionTypes . GETSINGLE } ) ; } ; } ;