Spread

spread() will spread an incoming array into multiple emissions:
  /*!*/import { wrap, control, group, spread, gate, pipe, map, filter } from '@connectv/core';
import { fromEvent } from 'rxjs';
import { delay, debounceTime } from 'rxjs/operators';

let i = document.getElementById('i') as HTMLInputElement;
let p = document.getElementById('p');

let g = gate();

wrap(fromEvent(i, 'input'))
.to(pipe(debounceTime(1000)))        //--> wait for typing to finish
.to(map(() => i.value.split(',')))   //--> split the string
/*!*/.to(spread())                        //--> spread the comma separated list
.to(map(x => x.trim()))              //--> trim each word
.to(filter(x => x.length > 3))       //--> ignore super short ones
.to(g.input);

group(control(), g.output)           //--> the control() is not connected
.to(pipe(delay(1000)))               //... to anything, so it will emit initially
.to(g.control);

g.output.subscribe(v => p.innerHTML = v);
spread() will just relay incoming values that are not arrays:
  /*!*/import { source, spread } from '@connectv/core';

let a = source();
/*!*/a.to(spread()).subscribe(console.log);

a.send([1, 2, 3]); //--> spread the values
a.send(4);         //--> just relay 4
a.send([5, 6]);    //--> spread again
a.send(7);         //--> relay again

Further reading




Copied to Clipboard!