1.0.9 • Published 7 years ago

saga-observable v1.0.9

Weekly downloads
5
License
MIT
Repository
github
Last release
7 years ago

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)
  }
}
1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago