-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
State: Use getHttpData() for geolocation data
In #22549 we added the `getHttpData()` abstraction for simple network data needs. In this patch we're moving the `geo` state subtree over to this new abstraction and removing the old code it previously required. This approach is build on the data-layer ideas and extends it to store data outside of Redux.
- Loading branch information
Showing
16 changed files
with
50 additions
and
581 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** @format */ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import makeJsonSchemaParser from 'lib/make-json-schema-parser'; | ||
import { http as rawHttp } from 'state/http/actions'; | ||
import { requestHttpData } from 'state/data-layer/http-data/common'; | ||
|
||
export const requestGeoLocation = () => | ||
requestHttpData( | ||
'geo', | ||
rawHttp( { | ||
method: 'GET', | ||
url: 'https://public-api.wordpress.com/geo/', | ||
} ), | ||
{ | ||
fromApi: makeJsonSchemaParser( | ||
{ | ||
type: 'object', | ||
properties: { | ||
body: { | ||
type: [ 'object', 'null' ], | ||
properties: { | ||
latitude: { type: 'string' }, | ||
longitude: { type: 'string' }, | ||
country_short: { type: 'string' }, | ||
country_long: { type: 'string' }, | ||
region: { type: 'string' }, | ||
city: { type: 'string' }, | ||
}, | ||
}, | ||
}, | ||
}, | ||
// we only use the short code currently | ||
( { body: { country_short } } ) => [ [ 'geo', country_short ] ] | ||
), | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.