Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. import update from "react-addons-update";
  2. import constants from "./actionConstants";
  3.  
  4.  
  5. //----------------------
  6. //Constants
  7. //----------------------
  8.  
  9. const { GET_CURRENT_LOCATION } = constants;
  10.  
  11. //----------------------
  12. // Actions
  13. //----------------------
  14.  
  15. export function getCurrentLocation(){
  16. return(dispatch)=>{
  17. navigator.geolocation.getCurrentPosition(
  18. (position)=>{
  19. dispatch({
  20. type:GET_CURRENT_LOCATION,
  21. payload:position
  22. });
  23. },
  24. (error)=> console.log(error.message),
  25. {enableHighAccuracy: true, timeout: 20000, maximumAge:1000}
  26. );
  27. }
  28. }
  29.  
  30. //----------------------
  31. // Action Handlers
  32. //----------------------
  33.  
  34. function handleGetCurrentLocation(state, action){
  35. return update(state,{
  36. region:{
  37. $set:action.payload
  38. }
  39. })
  40. }
  41.  
  42. const ACTION_HANDLERS = {
  43. GET_CURRENT_LOCATION:handleGetCurrentLocation
  44. }
  45. const initialState = {
  46. region: {}
  47. };
  48.  
  49. export function HomeReducer(state = initialState, action){
  50. const handler = ACTION_HANDLERS[action.type];
  51. return handler ? handler(state, action) : state;
  52. }
  53.  
  54. export default {
  55. GET_CURRENT_LOCATION:"GET_CURRENT_LOCATION"
  56. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement