Skip to content

Commit

Permalink
Merge pull request #7 from matheusrezende/master
Browse files Browse the repository at this point in the history
Added redux-thunk support
  • Loading branch information
itinance authored Mar 7, 2018
2 parents 5388172 + 2932a21 commit 3672756
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@

export { watchLocationChannel, getCurrentPosition, watchCurrentPosition } from './saga/location';
export { default as locationReducer } from './reducer/location';
export {getCurrentPositionThunk, watchCurrentPositionThunk} from './thunks/location'
27 changes: 27 additions & 0 deletions thunks/location.js
Original file line number Diff line number Diff line change
@@ -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
);
}

0 comments on commit 3672756

Please sign in to comment.