@connectv/core
Version:
agent-based reactive programming library for typescript/javascript
47 lines • 1.24 kB
JavaScript
import { tap } from 'rxjs/operators';
import { Pipe } from './pipe';
/**
*
* Represents [sink](https://connective.dev/docs/sink) pins.
*
*/
export class Sink extends Pipe {
constructor(func = () => { }) {
super([tap((emission) => func(emission.value, emission.context))]);
this.func = func;
this._bound = false;
}
/**
*
* @returns `true` if this sink is already bound.
*
*/
get bound() { return this._bound; }
/**
*
* Binds this sink if it is not already bound. Binding
* Basically ensures that the pin is subscribed to and that its side-effect
* will be enacted.
*
*/
bind() {
if (!this._bound) {
this._bound = true;
this.track(this.subscribe());
}
return this;
}
}
/**
*
* Creates a [sink](https://connective.dev/docs/sink) pin.
* Sink pins can be used to do something with the data of a flow, outside the scope of the flow
* (like logging them, etc).
* [Checkout the docs](https://connective.dev/docs/sink) for examples and further information.
*
* @param func
*
*/
export function sink(func) { return new Sink(func); }
export default sink;
//# sourceMappingURL=sink.js.map