Skip to content

Instantly share code, notes, and snippets.

@steida
Created November 4, 2016 17:04
Show Gist options
  • Select an option

  • Save steida/344d994f992fdb27940ce55094bbbfdc to your computer and use it in GitHub Desktop.

Select an option

Save steida/344d994f992fdb27940ce55094bbbfdc to your computer and use it in GitHub Desktop.
// TODO: Run epic on app start if geolocation was already explicitly requested.
const watchAppPositionEpic = (action$, { geolocation }) => {
const geolocation$ = Observable.create(observer => {
const onNext = (position: Position) => {
const action = watchAppPositionNext(geopositionToObject(position));
observer.next(action);
};
const onError = ({ code, message }: PositionError) => {
const action = watchAppPositionFail({ code, message });
observer.next(action);
};
const watchID = geolocation.watchPosition(onNext, onError);
return () => {
geolocation.clearWatch(watchID);
};
});
return action$.ofType(WATCH_APP_POSITION)
.switchMap(() =>
geolocation$.takeUntil(action$.ofType(APP_STOP))
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment