Package Exports
- yo-pull-stream
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (yo-pull-stream) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
yo pull stream
Turn your view into a duplex stream. This uses 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
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`<div>
<div>${state.count}</div>
<button onclick=${push.bind(null, 'plus')}>plus 1</button>
</div>`
}
You can pass in a render function. This should work with any function like morphdom
:
var ViewStream = require('yo-pull-stream/render-loop')(myRenderFunction)
var viewStream = ViewStream(root, myView, function onEnd (err) {
})