diff --git a/index.js b/index.js index 23d0790..882904d 100644 --- a/index.js +++ b/index.js @@ -7,3 +7,4 @@ export { watchLocationChannel, getCurrentPosition, watchCurrentPosition } from './saga/location'; export { default as locationReducer } from './reducer/location'; +export {getCurrentPositionThunk, watchCurrentPositionThunk} from './thunks/location' \ No newline at end of file diff --git a/thunks/location.js b/thunks/location.js new file mode 100644 index 0000000..e924dca --- /dev/null +++ b/thunks/location.js @@ -0,0 +1,27 @@ +import { + REDUX_SAGA_LOCATION_ACTION_REQUEST, + REDUX_SAGA_LOCATION_ACTION_SET_POSITION, + REDUX_SAGA_LOCATION_ACTION_SET_ERROR, +} from '../actions'; + +export const getCurrentPositionThunk = (options) => dispatch => { + dispatch({type: REDUX_SAGA_LOCATION_ACTION_REQUEST}) + navigator.geolocation.getCurrentPosition( + position => { + dispatch({type: REDUX_SAGA_LOCATION_ACTION_SET_POSITION, position}) + }, + (error) => dispatch({type: REDUX_SAGA_LOCATION_ACTION_SET_ERROR, error}), + options + ); +} + +export const watchCurrentPositionThunk = (options) => (dispatch) =>{ + dispatch({type: REDUX_SAGA_LOCATION_ACTION_REQUEST}) + navigator.geolocation.watchPosition( + position => { + dispatch({type: REDUX_SAGA_LOCATION_ACTION_SET_POSITION, position}) + }, + (error) => dispatch({type: REDUX_SAGA_LOCATION_ACTION_SET_ERROR, error}), + options + ); +}