UNPKG

@connectv/core

Version:

agent-based reactive programming library for typescript/javascript

68 lines 2.62 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 __()); }; })(); var __spreadArrays = (this && this.__spreadArrays) || function () { for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j]; return r; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var filter_1 = __importDefault(require("../pin/filter")); var agent_1 = require("./agent"); var Switch = /** @class */ (function (_super) { __extends(Switch, _super); function Switch() { var cases = []; for (var _i = 0; _i < arguments.length; _i++) { cases[_i] = arguments[_i]; } var _this = _super.call(this, { inputs: ['target'], outputs: cases.map(function (_, index) { return index.toString(); }), }) || this; _this.cases = cases; return _this; } Object.defineProperty(Switch.prototype, "target", { get: function () { return this.in('target'); }, enumerable: true, configurable: true }); Switch.prototype.case = function (index) { return this.out(index); }; Switch.prototype.createOutput = function (label) { this.checkOutput(label); var _case = this.cases[label]; return this.target .to((typeof _case === 'function') ? filter_1.default(_case) : filter_1.default(function (value) { return _case === value; })); }; return Switch; }(agent_1.Agent)); exports.Switch = Switch; function _switch() { var cases = []; for (var _i = 0; _i < arguments.length; _i++) { cases[_i] = arguments[_i]; } return new (Switch.bind.apply(Switch, __spreadArrays([void 0], cases)))(); } exports._switch = _switch; exports.default = _switch; //# sourceMappingURL=switch.js.map