Skip to content

Instantly share code, notes, and snippets.

@gjacobrobertson
Created July 17, 2018 14:14
Show Gist options
  • Save gjacobrobertson/74367dde47fd5b0a1fc1f7de0d75a4c3 to your computer and use it in GitHub Desktop.
Save gjacobrobertson/74367dde47fd5b0a1fc1f7de0d75a4c3 to your computer and use it in GitHub Desktop.
function createFetcher<Params, Return>(endpoint: (params: Params) => string, handler: (obj: any) => Return) {
return _debounce((params: Params) => {
fetch(API_BASE_URL + endpoint(params), DEFAULT_GET_OPTIONS)
.then(response => response.json())
.then(handler);
}, 200);
}
export const findMarketingAsset = createFetcher(
({ id = null } = {}) => `/assets/${id}`,
jsonArray => new MarketingAsset(jsonArray[0]),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment