Skip to content

Commit

Permalink
added redux-thunk support
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusrezende committed Feb 28, 2018
1 parent 5388172 commit 2932a21
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 2932a21

Please sign in to comment.