xs-combine-obj

A convenient flavor of xs.combine

Usage no npm install needed!

<script type="module">
  import xsCombineObj from 'https://cdn.skypack.dev/xs-combine-obj';
</script>

README

combineObj for xstream

npm install xs-combine-obj

A port of combineLatestObj to xstream.

Usage

Given these observables:

const a$ = xs.periodic(50).take(3);
const b$ = xs.of('Boston');
const c$ = xs.of('Colorado');

Make an observable which is the combination of them, bundled as an object.

import combineObj from 'xs-combine-obj';

const state$ = combineObj({a$, b$, c$});
// or const state$ = combineObj({a: a$, b: b$, c: c$});

state$.addListener({
  next: x => console.dir(x),
  error: () => {},
  complete: () => {}
});
// {a: 0, b: 'Boston', c: 'Colorado'}
// {a: 1, b: 'Boston', c: 'Colorado'}
// {a: 2, b: 'Boston', c: 'Colorado'}

It takes Cycle.js' hungarian notation $ into consideration, returning an object whose keys don't have the $.

The above is more convenient than writing:

var stateAlt$ = xs.combine(a$, b$, c$).map(([a, b, c]) => ({a, b, c}));

Credit: Code and README example pulled from combineLatestObj