UNPKG

@connectv/core

Version:

agent-based reactive programming library for typescript/javascript

72 lines 2.33 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var operators_1 = require("rxjs/operators"); var pipe_1 = require("./pipe"); /** * * Represents [sink](https://connective.dev/docs/sink) pins. * */ var Sink = /** @class */ (function (_super) { __extends(Sink, _super); function Sink(func) { if (func === void 0) { func = function () { }; } var _this = _super.call(this, [operators_1.tap(function (emission) { return func(emission.value, emission.context); })]) || this; _this.func = func; _this._bound = false; return _this; } Object.defineProperty(Sink.prototype, "bound", { /** * * @returns `true` if this sink is already bound. * */ get: function () { return this._bound; }, enumerable: true, configurable: true }); /** * * 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. * */ Sink.prototype.bind = function () { if (!this._bound) { this._bound = true; this.track(this.subscribe()); } return this; }; return Sink; }(pipe_1.Pipe)); exports.Sink = Sink; /** * * 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 * */ function sink(func) { return new Sink(func); } exports.sink = sink; exports.default = sink; //# sourceMappingURL=sink.js.map