Skip to content

Instantly share code, notes, and snippets.

@mori-dev
Last active Apr 11, 2017
Embed
What would you like to do?
プロミスでラップ
function* sendPlace(action: Action): Generator<any, any, any> {
try {
const response: any = yield call(Geo.sendPlace, action.payload, action.meta);
yield put(someSendPlaceOk(response));
} catch (error) {
yield put(someSendPlaceNg(error));
}
}
export function* watchGeoSendPlace(): Generator<any, any, any> {
while (true) {
const action = yield take(ActionTypes.SOME_SEND_PLACE_WSSTART);
yield fork(sendPlace, action);
}
}
const Geo = {
sendPlace: (payload: geoSendPlaceStartPayload, meta: any = {}): Promise<*> => {
return new Promise((resolve, reject) => {
navigator.geolocation.getCurrentPosition(
(position) => {
const lat = position.coords.latitude;
const lng = position.coords.longitude;
const newPayload = { lat, lng };
resolve(newPayload, meta)
},
(error) => {
const errorInfo = JSON.stringify(error);
reject(new Error(errorInfo));
},
)
});
},
};
sendCurrentPlace(): void {
const lat = null;
const lng = null;
const payload = {lat, lng};
this.props.geoActions.geoSendPlace(payload);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment