Functions for working with Flyd stream in objects.
- Convert object values from plain values into streams with streamProps
- Convert object values from streams into plain values with extractProps
- Convert a plain object with stream values into a single stream of plain objects with stream
These functions perform these conversions recursively in nested objects.
Given an object of normal values, turn every value into a stream. It will stream nested properties recursively.
Signature
Object a -> Object (Stream a)
Usage
const flydObj = require('flyd/module/object')
const obj = {x: 1, y: {z: 2}}
const objOfStreams = flydObj.streamProps(obj)
objOfStreams.x() // 1
objOfStreams.y.z() // 2
Given an object that contains streams for values, extract everything into an object of regular values. It will extract nested properties recursively.
Signature
Object (Stream a) -> Object a
Usage
const objOfStreams = {x: flyd.stream(1), y: {z: flyd.stream(2)}}
const obj = flydObj.extractProps(objOfStreams)
//obj is {x: 1, y: {z: 2}}
Given an object containing streams, combine all the streams into a single stream of plain objects.
Signature
Object (Stream a) -> Stream (Object a)
Usage
const click = flyd.stream()
const message = flyd.map(() => 'Hello world!', state.click)
const state = {click, message}
const stateStream = flydObj.stream(state)
stateStream() // {click: undefined, message: undefined}
click(true)
stateStream() // {click: true, message: 'Hello World!'}