# choo-streamdata.io

> small wrapper around streamdata.io-events and choo

Latest version **1.0.0** (published 2017-10-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install choo-streamdata.io
pnpm add choo-streamdata.io
yarn add choo-streamdata.io
bun add choo-streamdata.io
```

## 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 | 1.0.0 |
| Published | 2017-10-24 |
| First published | 2017-10-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jake Burden |
| Maintainers | jekrb |

## Links

- npm: https://www.npmjs.com/package/choo-streamdata.io
- npm.io page: https://npm.io/package/choo-streamdata.io

## Dependencies (2)

- [nanoassert](https://npm.io/package/nanoassert.md) ^1.1.0
- [streamdata.io-events](https://npm.io/package/streamdata.io-events.md) ^1.0.1

## Recent versions

- 1.0.0 (latest) — 2017-10-24

## README

# choo-streamdata.io

> small glue code around the [streamdata.io-events](https://github.com/jekrb/streamdata.io-events) browser API and [choo](https://github.com/choojs/choo)

Adds streamdata.io events to the choo event emitter.

## Usage

```js
var choo = require('choo')
var html = require('choo/html')
var devtools = require('choo-devtools')
var streamdata = require('choo-streamdata.io')

var url = 'https://www.reddit.com/r/random.json?obey_over18=true'
var key = 'ODRlZDNmYmUtMDAxZC00NWJmLTgwMzQtNTkzMWJiYjFhYjVj'

var app = choo()
app.use(devtools())
app.use(streamdata(url, key))
app.use(SSE)

app.route('/', mainView)
app.mount('body')

function mainView (state, emit) {
  return html`
    <body>
      <strong>random subreddit</strong>
      <p>${state.subreddit}</p>
    </body>
  `
}

function SSE (state, emitter) {
  emitter.on('DOMContentLoaded', function () {
    emitter.on('SSE:data', function (data) {
      console.log(data)
      state.subreddit = data.data.children[0].data.subreddit_name_prefixed
      emitter.emit('render')
    })
  })

  emitter.on('SSE:opened', function () {
    console.log('SSE opened')
  })

  emitter.on('SSE:error', function (err) {
    console.error(err)
  })

  emitter.on('SSE:patch', function () {})

  window.onunload = function () {
    emitter.emit('SSE:close')
  }
}
```

## Example
![](./example/choo-streamdata.gif)

## API

### `SSE:opened`
Occurs when the SSE is opened

### `SSE:data`
Occurs when the SSE emits a new data event (full data update with patch applied)

### `SSE:patch`
Occurs when the SSE emits a new patch event (patch is just whats changed since the last patch or data event)

### `SSE:error`
Occurs when the SSE throws a new error

### `SSE:open`
Emitting this event will open the SSE connection if its been closed.

### `SSE:close`
Emitting this event will close the SSE connection. 

## Install

With [npm](https://npmjs.org/) installed, run

```
$ npm install choo-streamdata.io
```

## Acknowledgments

choo-streamdata.io was inspired by..

- [`YerkoPalma/choo-websocket`](https://github.com/YerkoPalma/choo-websocket)

## See Also

- [`choo`](https://github.com/choojs/choo)

## License

[MIT](https://tldrlegal.com/license/mit-license)

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