cyclejs-community/cyclejs-utils

Name: cyclejs-utils

Owner: Cycle.js Community

Description: A few helper functions for dealing with sinks

Created: 2017-01-22 14:04:57.0

Updated: 2017-11-15 09:55:33.0

Pushed: 2017-11-14 12:18:49.0

Homepage: null

Size: 189

Language: TypeScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

cyclejs-utils

A few helper functions for dealing with sinks

Links

git repository: https://github.com/cyclejs-community/cyclejs-util

npm package: https://www.npmjs.com/package/cyclejs-utils

typedoc documentation: https://cyclejs-community.github.io/cyclejs-util/index.html

Usage

The most useful functions are mergeSinks and extractSinks.

rt { ChildComponent } from 'XXX'
rt { Sinks, mergeSinks$, filterProp, extractSinks } from 'cyclejs-utils'

t drivers = { /* ... */ };
t driverNames = Object.keys(drivers);

tion main(sources)

const children$ : Stream<Sinks[]> = sources.state
    .map(s => s.childState.map(c => ChildComponent(sources)));

//Create a combined DOM of the children
const vdom$ : Stream<VNode> = children$
    .map(arr => xs.combine(...arr.map(s => s.DOM)))
    .flatten()
    .map(div); //Just display the children in a div

//Merge all children Sinks automaticly
const child$ : Stream<Sinks> = children$.map(arr => mergeSinks(...arr));

const childSink : Sinks = filterProp(
    extractSinks(child$, driverNames), //Transform a Stream of Sinks to a normal Sinks object
    'DOM'
); //give me a driver object without the DOM property

return Object.assign({}, childSink, { DOM: vdom$ });


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.