JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q21248F
  • License ISC

Turn your view into a duplex stream

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

install

$ npm intall 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)

// you can have multiple subsribers
var anotherSourceStream = viewStream.listen()  

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

// 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>`
}