Last active
April 11, 2017 11:56
-
-
Save mori-dev/34e882ef0a97759fdd431fc773314897 to your computer and use it in GitHub Desktop.
プロミスでラップ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | |
}, | |
) | |
}); | |
}, | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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