Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions actions/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
export const REDUX_SAGA_LOCATION_ACTION_SET_POSITION = 'REDUX_SAGA_LOCATION_SET_POSITION';
export const REDUX_SAGA_LOCATION_ACTION_SET_ERROR = 'REDUX_SAGA_LOCATION_SET_ERROR';
export const REDUX_SAGA_LOCATION_ACTION_REQUEST = 'REDUX_SAGA_LOCATION_ACTION_REQUEST';
export const REDUX_SAGA_LOCATION_CLEAR_REQUEST = 'REDUX_SAGA_LOCATION_CLEAR_REQUEST';
export const REDUX_SAGA_LOCATION_STOP_REQUEST = 'REDUX_SAGA_LOCATION_STOP_REQUEST';
export const REDUX_SAGA_LOCATION_ACTION_SET_POSITION = "REDUX_SAGA_LOCATION_SET_POSITION";
export const REDUX_SAGA_LOCATION_ACTION_SET_ERROR = "REDUX_SAGA_LOCATION_SET_ERROR";
export const REDUX_SAGA_LOCATION_ACTION_REQUEST = "REDUX_SAGA_LOCATION_ACTION_REQUEST";
export const REDUX_SAGA_LOCATION_CLEAR_REQUEST = "REDUX_SAGA_LOCATION_CLEAR_REQUEST";
export const REDUX_SAGA_LOCATION_STOP_REQUEST = "REDUX_SAGA_LOCATION_STOP_REQUEST";
// REDUX_SAGA_LOCATION_STOP_REQUEST deprecated because
// stop observing is deprecated in react-native-community/geolocation
// switch to clearWatch as soon as possible
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "redux-saga-location",
"version": "1.6.0",
"version": "1.7.0",
"description": "Location-support for redux-saga",
"main": "index.js",
"scripts": {
Expand All @@ -21,7 +21,7 @@
"author": "Hagen Huebel <[email protected]> ([email protected])",
"license": "MIT",
"peerDependencies": {
"@react-native-community/geolocation": "2.0.2"
"@react-native-community/geolocation": "3.4.0"
},
"devDependencies": {
"flow-bin": "0.28.0",
Expand Down
43 changes: 23 additions & 20 deletions reducer/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,59 +3,62 @@ import {
REDUX_SAGA_LOCATION_ACTION_SET_ERROR,
REDUX_SAGA_LOCATION_ACTION_SET_POSITION,
REDUX_SAGA_LOCATION_CLEAR_REQUEST,
REDUX_SAGA_LOCATION_STOP_REQUEST
} from '../actions';
REDUX_SAGA_LOCATION_STOP_REQUEST,
} from "../actions";

export default function locationReducer(state = {
export default function locationReducer(
state = {
position: null,
error: null,
fetching: false
}, action) {
switch(action.type) {

fetching: false,
},
action
) {
switch (action.type) {
case REDUX_SAGA_LOCATION_ACTION_REQUEST: {
return {
...state,
fetching: true
}
fetching: true,
};
}

case REDUX_SAGA_LOCATION_ACTION_SET_POSITION: {
const {position} = action;
const { position } = action;

return {
...state,
position,
error: null,
fetching: false
}
fetching: false,
};
}

case REDUX_SAGA_LOCATION_ACTION_SET_ERROR: {
const {error} = action;
const { error } = action;

return {
...state,
error: error,
fetching: false
}
fetching: false,
};
}

case REDUX_SAGA_LOCATION_CLEAR_REQUEST: {
return {
...state,
fetching: false
}
fetching: false,
};
}

case REDUX_SAGA_LOCATION_STOP_REQUEST: {
// Stop observing is deprecated in react-native-community/geolocation
// switch to clearWatch as soon as possible
return {
...state,
fetching: false
}
fetching: false,
};
}


default: {
return state;
}
Expand Down
22 changes: 12 additions & 10 deletions saga/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
REDUX_SAGA_LOCATION_ACTION_SET_ERROR,
REDUX_SAGA_LOCATION_ACTION_SET_POSITION,
REDUX_SAGA_LOCATION_CLEAR_REQUEST,
REDUX_SAGA_LOCATION_STOP_REQUEST
REDUX_SAGA_LOCATION_STOP_REQUEST,
} from "../actions";

export function* clearWatch(watchId) {
Expand All @@ -20,39 +20,41 @@ export function* clearWatch(watchId) {
export function* getCurrentPosition(options) {
locationChannel.put({ type: REDUX_SAGA_LOCATION_ACTION_REQUEST });
Geolocation.getCurrentPosition(
position => {
(position) => {
locationChannel.put({
type: REDUX_SAGA_LOCATION_ACTION_SET_POSITION,
position
position,
});
},
error =>
(error) =>
locationChannel.put({
type: REDUX_SAGA_LOCATION_ACTION_SET_ERROR,
error
error,
}),
options
);
}

export function* stopObserving() {
// Stop observing is deprecated in react-native-community/geolocation
// switch to clearWatch as soon as possible
locationChannel.put({ type: REDUX_SAGA_LOCATION_STOP_REQUEST });
Geolocation.stopObserving();
}

export function* watchCurrentPosition(options) {
locationChannel.put({ type: REDUX_SAGA_LOCATION_ACTION_REQUEST });
Geolocation.watchPosition(
position => {
return Geolocation.watchPosition(
(position) => {
locationChannel.put({
type: REDUX_SAGA_LOCATION_ACTION_SET_POSITION,
position
position,
});
},
error =>
(error) =>
locationChannel.put({
type: REDUX_SAGA_LOCATION_ACTION_SET_ERROR,
error
error,
}),
options
);
Expand Down
28 changes: 15 additions & 13 deletions thunks/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,39 @@ import {
REDUX_SAGA_LOCATION_ACTION_SET_ERROR,
REDUX_SAGA_LOCATION_ACTION_SET_POSITION,
REDUX_SAGA_LOCATION_CLEAR_REQUEST,
REDUX_SAGA_LOCATION_STOP_REQUEST
REDUX_SAGA_LOCATION_STOP_REQUEST,
} from "../actions";

export const clearWatchThunk = watchId => dispatch => {
export const clearWatchThunk = (watchId) => (dispatch) => {
dispatch({ type: REDUX_SAGA_LOCATION_CLEAR_REQUEST });
Geolocation.clearWatch(watchId)
}
Geolocation.clearWatch(watchId);
};

export const getCurrentPositionThunk = options => dispatch => {
export const getCurrentPositionThunk = (options) => (dispatch) => {
dispatch({ type: REDUX_SAGA_LOCATION_ACTION_REQUEST });
Geolocation.getCurrentPosition(
position => {
(position) => {
dispatch({ type: REDUX_SAGA_LOCATION_ACTION_SET_POSITION, position });
},
error => dispatch({ type: REDUX_SAGA_LOCATION_ACTION_SET_ERROR, error }),
(error) => dispatch({ type: REDUX_SAGA_LOCATION_ACTION_SET_ERROR, error }),
options
);
};

export const stopObservingThunk = () => dispatch => {
export const stopObservingThunk = () => (dispatch) => {
// Stop observing is deprecated in react-native-community/geolocation
// switch to clearWatch as soon as possible
dispatch({ type: REDUX_SAGA_LOCATION_STOP_REQUEST });
Geolocation.stopObserving();
}
};

export const watchCurrentPositionThunk = options => dispatch => {
export const watchCurrentPositionThunk = (options) => (dispatch) => {
dispatch({ type: REDUX_SAGA_LOCATION_ACTION_REQUEST });
Geolocation.watchPosition(
position => {
return Geolocation.watchPosition(
(position) => {
dispatch({ type: REDUX_SAGA_LOCATION_ACTION_SET_POSITION, position });
},
error => dispatch({ type: REDUX_SAGA_LOCATION_ACTION_SET_ERROR, error }),
(error) => dispatch({ type: REDUX_SAGA_LOCATION_ACTION_SET_ERROR, error }),
options
);
};