Repository URL to install this package:
|
Version:
1.0.0-722a1f9 ▾
|
@doodle/geolocation
/
README.md
|
|---|
Connects Doodle's geolocation service (https://github.com/DoodleScheduling/service-geoip) to redux.
| @doodle/geolocation | |
|---|---|
| NPM package | @doodle/geolocation |
| JIRA project | PLAT |
The object returned by the geolocation service has the following shape:
{ "ip": "84.74.100.162", "country_code": "CH", "country_name": "Switzerland", "region_code": "ZH", "region_name": "Zurich", "city": "Zurich", "zip_code": "8047", "time_zone": "Europe/Zurich", "latitude": 47.3667, "longitude" :8.55, "metro_code": 0 }
!!! For now only country_code and country_name are available. !!!
To use geolocation state in one of your projects you need to follow these steps:
@doodle/geolocation to your project's dependencies in package.json.add @doodle/geolocation
rootSaga:import { loadGeolocationSaga } from '@doodle/geolocation'; export default function* rootSaga(options = {}) { yield all([ call(loadGeolocationSaga, options.geolocation), // ... add other sagas here ]); }
initialState.js:import { createState as createGeolocationInitialState } from '@doodle/geolocation'; export default { ...createGeolocationInitialState(), // ... add other initial states here };
import { combineReducers } from 'redux'; import { routerReducer } from 'react-router-redux'; import { createReducer as createGeolocationReducer } from '@doodle/geolocation'; export default function createReducer(injectedReducers = {}) { return combineReducers({ router: routerReducer, ...createGeolocationReducer(), // ... add other reducers here ...injectedReducers, }); }
client.js:store.runRootSaga({ geolocation: { geoipServiceUrl: 'https://doodle-test.com/api/geoip/v1.0', }, });
import { ActionTypes as GeolocationActionTypes, fetchGeolocation } from '@doodle/geolocation'; function* onFetchGeolocationSuccess() { const geolocation = yield select(state => state.geolocation.geolocation); } function* watchFetchGeolocationSuccess(options) { yield takeLatest(GeolocationActionTypes.FETCH_GEOLOCATION_SUCCESS, onFetchGeolocationSuccess, options); } export default function* exampleSaga(options = {}) { yield all([ call(watchFetchGeolocationSuccess, options), put(fetchGeolocation()), ]); }
git clone https://github.com/DoodleScheduling/web-geolocation.git cd web-geolocation
$ yarn $ yarn start
git fetch git checkout -b my-branch origin/master # ... commit changes git push origin my-branch
@doodle/geolocationIn order to check how your changes to geolocation will work with other project, link the geolocation package into another project:
dist folder of the package you want to linkyarn link
yarn link "@doodle/geolocation"
resolve: { alias: { 'react-redux': path.resolve('./node_modules/react-redux'), 'react-dom': path.resolve('./node_modules/react-dom'), }, },
yarn unlink
and:
yarn unlink "@doodle/geolocation" yarn
to unlink a geolocation package that was symlinked during development in your project,
After bumping version in package.json, publish new version:
gulp publish