# rethinkdb-observable

> Convert a rethinkdb cursor into an observable

Latest version **2.0.0** (published 2016-07-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install rethinkdb-observable
pnpm add rethinkdb-observable
yarn add rethinkdb-observable
bun add rethinkdb-observable
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2016-07-22 |
| First published | 2016-07-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | Tejesh Mehta |
| Maintainers | tjmehta |
| Keywords | rethinkdb, rethink, cursor, observable, observe, subscribe, reactive |

## Links

- npm: https://www.npmjs.com/package/rethinkdb-observable
- Repository: https://github.com/tjmehta/rethinkdb-observable
- Issues: https://github.com/tjmehta/rethinkdb-observable/issues
- npm.io page: https://npm.io/package/rethinkdb-observable

## Recent versions

- 2.0.0 (latest) — 2016-07-22
- 1.0.0 — 2016-07-12

## README

# rethinkdb-observable [![Build Status](https://travis-ci.org/tjmehta/rethinkdb-observable.svg?branch=master)](https://travis-ci.org/tjmehta/rethinkdb-observable) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/)
Convert a rethinkdb cursor into an observable

# Installation
```js
npm i --save rethinkdb-observable
npm i --save rxjs # peer dependency
```

# Usage
#### Example: observable w/ single subscribe/unsubscribe
```js
var createObservable = require('rethinkdb-observable')
var r = require('rethinkdb')

rethinkdb.table('test').run(conn).then(function (cursor) {
  // Note: this is a basic observable and only allows ONE subscription. for multiple, see example below.
  var observable = createObservable(cursor)
  // subscribe usage
  var subscription = observable.subscribe(
    function onNext (next) {
      // onNext will be passed each item as they are recieved from the cursor
    },
    function onError (err) {
      // onError will trigger for any cursor errors
    },
    function onCompleted () {
      // on complete will trigger after last "next" has been pushed
      // and cursor has closed successfully
    }
  )
  // unsubscribe usage
  subscription.unsubscribe()
  // unsubscribe will detach the subscription callbacks and close the cursor
})
```

#### Example: observable w/ multiple subscriptions
Uses [rxjs](https://github.com/ReactiveX/rxjs) ConnectableObservable by using `publish`.
To learn more about ReactiveX observables checkout: [reactivex.io](http://reactivex.io) or [intro to rx](https://gist.github.com/staltz/868e7e9bc2a7b8c1f754)
```js
var createObservable = require('rethinkdb-observable')
var r = require('rethinkdb')
// required to use publish
require('rxjs/add/operator/publish')

rethinkdb.table('test').run(conn).then(function (cursor) {
  // Note: this is a basic observable and only allows ONE subscription. for multiple, see example below.
  var observable = rethinkdbObservable(cursor).publish().refCount()
  // subscribe usage
  var subscription = observable.subscribe(
    function onNext (next) {
      // onNext will be passed each item as they are recieved from the cursor
    },
    function onError (err) {
      // onError will trigger for any cursor errors
    },
    function onCompleted () {
      // on complete will trigger after last "next" has been pushed
      // and cursor has closed successfully
    }
  )
  // unsubscribe usage
  subscription.unsubscribe()
  // unsubscribe will detach the subscription callbacks and close the cursor
})
```


# License
MIT

---
_Source: https://npm.io/package/rethinkdb-observable · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
