saga-observable
v1.0.9
Published
Build Observables that allow redux-saga to promise future actions
Downloads
8
Readme
SagaObservable
Abstracts PromiseQueue to add the redux-saga cancellation logic on top. This allows us to easily wait for future actions / events in our sagas.
If you are not using redux-saga then you probably should be looking at the PromiseQueue package above.
Simple Example
import { fork } from 'redux-saga/effects'
import SagaObservable from 'saga-observable'
export function* watchUserPositionSaga(options = { enableHighAccuracy: true }) {
if ( ! navigator.geolocation ) {
console.warn('User Position can not be used, check permissions or update browser.')
return
}
const observer = new SagaObservable({ /* ... config ... */ })
let id
try {
id = navigator.geolocation.watchPosition(
observer.publish, observer.publish, options
)
while(true) {
const location = yield apply(observer, observer.next)
// handle new data via [yield fork]
}
} catch (e) {
// handle errors
} finally {
if ( observer.cancelled() ) {
// handle cancellation
}
navigator.geolocation.clearWatch(id)
}
}