Sink

A sink() acts as a consumer of incoming events/data:
  /*!*/import { source, map, filter, sink } from '@connectv/core';

let a = source();
/*!*/let b = sink(x => console.log(x));

a.to(map(x => x * 2)).to(b);
a.to(filter(x => x % 2 == 0)).to(map(x => x * 10)).to(b);

/*!*/b.bind();
a.send(2);
a.send(3);
sink() has a .bind() method which will lock the sink and cause it to receive events/data from the rest of the flow. .bind() will lock the portion of the flow that the sink is reliant on, much like .subscribe() method.

You can also place a sink in the middle of your reactive flow to do something according to incoming data/events without transforming them:
  /*!*/import { wrap, group, map, filter, sink } from '@connectv/core';
import { fromEvent } from 'rxjs';

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

wrap(fromEvent(a, 'input'))
.to(map(() => a.value))             //--> get the input value
/*!*/.to(sink(x => console.log(x)))      //--> log it
.to(filter(x => x % 2 == 1))        //--> filter for odd ones
.subscribe(v => p.innerHTML = v);   //--> put them on the page

Further reading




Copied to Clipboard!