From 29c73c45fc776c545d920557f97cc1f4a03135e4 Mon Sep 17 00:00:00 2001 From: Dennis Snell Date: Mon, 26 Nov 2018 15:51:40 -0700 Subject: [PATCH] Data Layer: Add helper to GET data from generic URL See #28304 In this patch we're adding a small helper to be used to get raw information from a given URL though a `GET` request. The way we'd use this is inside of the `waitForData()` function. This is meant to obscure the global http-data ID so that the user doesn't need to worry about it. ```js waitForData( { planets: getAtURL( 'https://swapi.co/api/planets/' ), } ).then( ( { planets } ) => { console.log( planets.data ); } ); ``` --- client/state/data-getters/index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/client/state/data-getters/index.js b/client/state/data-getters/index.js index 9b283afac00eb..acf1f350578ab 100644 --- a/client/state/data-getters/index.js +++ b/client/state/data-getters/index.js @@ -23,6 +23,11 @@ import { import { convertToSnakeCase } from 'state/data-layer/utils'; import { dummyTaxRate } from 'lib/tax'; // #tax-on-checkout-placeholder +export const getAtURL = url => + requestHttpData( `get-at-url-${ url }`, rawHttp( { method: 'GET', url } ), { + fromApi: () => data => [ `get-at-url-${ url }`, data ], + } ); + export const requestActivityActionTypeCounts = ( siteId, filter,