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
- Host: GitHub
- URL: https://github.com/nichoth/yo-pull-stream
- Owner: nichoth
- Created: 2017-04-16T03:58:01.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-06-02T17:16:39.000Z (about 9 years ago)
- Last Synced: 2025-07-21T01:24:18.599Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 11.7 KB
- Stars: 3
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
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) {
})
```