An open API service indexing awesome lists of open source software.

https://github.com/nichoth/yo-pull-stream

Turn your view into a duplex stream
https://github.com/nichoth/yo-pull-stream

Last synced: 12 months ago
JSON representation

Turn your view into a duplex stream

Awesome Lists containing this project

README

          

# yo pull stream

Turn your view into a duplex stream. This uses [yo-yo](https://github.com/maxogden/yo-yo/) to render your view, and gives you a duplex stream interface for emitting events and subscribing to changes.

## install

$ npm install yo-pull-stream

## example

```js
var S = require('pull-stream')
var scan = require('pull-scan')
var ViewStream = require('../')
var html = require('yo-yo')

var root = document.createElement('div')
document.body.appendChild(root)

// viewStream is a duplex stream
var viewStream = ViewStream(root, myView, function onEnd (err) {
if (err) return console.log('error', err)
console.log("it's over")
})

S(
viewStream,
scan(function (state, ev) {
if (ev === 'plus') return { count: state.count + 1 }
return state
}),
viewStream
)

// push an initial event so our view renders
viewStream.source.push({ count: 0 })

function myView (state, push) {
// call push to publish an event
return html`


${state.count}

plus 1
`
}
```

You can pass in a render function. This should work with any function like `morphdom`:

```js
var ViewStream = require('yo-pull-stream/render-loop')(myRenderFunction)
var viewStream = ViewStream(root, myView, function onEnd (err) {
})
```