@connectv/core
Version:
agent-based reactive programming library for typescript/javascript
103 lines • 3.86 kB
JavaScript
;
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 __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var control_1 = require("../pin/control");
var map_1 = __importDefault(require("../pin/map"));
var filter_1 = __importDefault(require("../pin/filter"));
var group_1 = __importDefault(require("../pin/group"));
var agent_1 = require("./agent");
/**
*
* Represents [gate](https://connective.dev/docs/gate) agents.
*
*/
var Gate = /** @class */ (function (_super) {
__extends(Gate, _super);
function Gate() {
var _this = _super.call(this, { inputs: ['value'], outputs: ['value'] }) || this;
_this._control = new control_1.Control();
return _this;
}
Object.defineProperty(Gate.prototype, "input", {
/**
*
* Shortcut for `.in('value')`, the input pin receiving values.
* [Read this](https://connective.dev/docs/gate#signature) for more details.
*
*/
get: function () { return this.in('value'); },
enumerable: true,
configurable: true
});
Object.defineProperty(Gate.prototype, "output", {
/**
*
* Shortcut for `.out('value')`, the output emitting allowed values.
* [Read this](https://connective.dev/docs/gate#signature) for more details.
*
*/
get: function () { return this.out('value'); },
enumerable: true,
configurable: true
});
Object.defineProperty(Gate.prototype, "control", {
/**
*
* Each pin connected to this pin should emit a boolean value for each
* value sent to `.input`, and if all are true, the value is emitted via `.output`.
* [Read this](https://connective.dev/docs/gate) for more details.
*
*/
get: function () { return this._control; },
enumerable: true,
configurable: true
});
Gate.prototype.createOutput = function (label) {
this.checkOutput(label);
return group_1.default(this.control, this.input)
.to(new control_1.Control())
.to(filter_1.default(function (_a) {
var ctrl = _a[0], _ = _a[1];
return ctrl.every(function (signal) { return !!signal; });
}))
.to(map_1.default(function (_a) {
var _ = _a[0], input = _a[1];
return input;
}));
};
Gate.prototype.createEntries = function () { return [this.input]; };
Gate.prototype.createExits = function () { return [this.output]; };
Gate.prototype.clear = function () {
this.control.clear();
return _super.prototype.clear.call(this);
};
return Gate;
}(agent_1.Agent));
exports.Gate = Gate;
/**
*
* Creates a [gate](https://connective.dev/docs/gate) agent.
* Gate agents await a control signal for each incoming value and either pass it along
* or drop it based on the boolean value of the control signal.
* [Checkout the docs](https://connective.dev/docs/gate) for examples and further information.
*
*/
function gate() { return new Gate(); }
exports.gate = gate;
exports.default = gate;
//# sourceMappingURL=gate.js.map