Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dash-os/saga-geolocation-observer
Use saga-observables to provide a simple way to use the HTML5 Geolocation API with redux-saga
https://github.com/dash-os/saga-geolocation-observer
Last synced: 17 days ago
JSON representation
Use saga-observables to provide a simple way to use the HTML5 Geolocation API with redux-saga
- Host: GitHub
- URL: https://github.com/dash-os/saga-geolocation-observer
- Owner: Dash-OS
- Created: 2017-05-30T18:23:02.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-05-30T20:02:56.000Z (over 7 years ago)
- Last Synced: 2024-10-28T08:14:21.797Z (18 days ago)
- Language: JavaScript
- Size: 8.79 KB
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# saga-geolocation-observer
Uses [saga-observable](https://www.npmjs.com/package/saga-observable) to provide a
simple way to user the [watchPosition](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/watchPosition)
API.### Installation
```
yarn add saga-geolocation-observer
```**or**
```
npm install --save saga-geolocation-observer
```### Simple Example
```js
import { put, fork } = 'redux-saga/effects'
import startLocationObserver from 'saga-geolocation-observer'function* mySaga(foo, bar, ctx) {
const task = yield fork(
startLocationObserver,
'watch-position-observer', // uid
{ enableHighAccuracy: true }, // PositionOptions (@ https://developer.mozilla.org/en-US/docs/Web/API/PositionOptions )
{
onEvent: handleEvent,
onError: handleError,
// optionally use [ context, fn ] for binding context.
onCancel: [ ctx, handleCancellation ] ,
// called when finally is reached (catch or cancel)
onFinally: handleComplete,
}, // optional lifecycle events, called as saga if possible.
/* pass through args are sent to the handlers */
foo, bar
)
}function* handleEvent(event, value, uid, ...passThroughArgs) {
yield put({
type: 'LOCATION_EVENT',
event, // 'watchPosition'
value, // Position (@ https://developer.mozilla.org/en-US/docs/Web/API/Position)
uid, // 'watch-position-observer'
passThroughArgs, // [ foo, bar ]
})
}function* handleError(event, error, uid, ...passThroughArgs) {
/* ... handle error ... */
}function* handleCancellation(event, uid, ...passThroughArgs) {
/* ... handle cancellation ... */
}function* handleComplete(event, uid, ...passThroughArgs) {
/* ... handle finished ... */
}
```