@connectv/core
Version:
agent-based reactive programming library for typescript/javascript
77 lines • 3.42 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 __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var composition_1 = require("./composition");
var InlineComposition = /** @class */ (function (_super) {
__extends(InlineComposition, _super);
function InlineComposition(factory, signature) {
var _a;
var _this = _super.call(this, signature) || this;
_this.factory = factory;
_a = _this.factory(function () {
var children = [];
for (var _i = 0; _i < arguments.length; _i++) {
children[_i] = arguments[_i];
}
return children.forEach(function (child) { return _this.add(child); });
}), _this.inpins = _a[0], _this.outpins = _a[1];
return _this;
}
InlineComposition.prototype.init = function () { };
InlineComposition.prototype.wire = function () { };
InlineComposition.prototype.build = function () { };
InlineComposition.prototype.createInput = function (label) { return this.inpins[label]; };
InlineComposition.prototype.createOutput = function (label) { return this.outpins[label]; };
InlineComposition.prototype.createEntries = function () { return Object.values(this.inpins); };
InlineComposition.prototype.createExits = function () { return Object.values(this.outpins); };
return InlineComposition;
}(composition_1.Composition));
/**
*
* Creates a [composition](https://connective.dev/docs/composition) using given factory function.
* [Checkout the docs](https://connective.dev/docs/composition) for examples and further information.
*
* @param factoryOrSignature either the [signature](https://connective.dev/docs/agent#signature) of
* the composition or the factory function creating it. If signature is not provided, the factory function
* will be invoked once to deduce the signature.
* @param factory the factory function for creating the composition. If provided, the first parameter must
* be a signature.
*
*/
function composition(factoryOrSignature, factory) {
var signature;
if (!factory) {
factory = factoryOrSignature;
var tracked_1 = [];
var s = factory(function () {
var children = [];
for (var _i = 0; _i < arguments.length; _i++) {
children[_i] = arguments[_i];
}
tracked_1 = tracked_1.concat(children);
});
signature = { inputs: Object.keys(s[0]), outputs: Object.keys(s[1]) };
tracked_1.forEach(function (thing) { return thing.clear(); });
}
else {
signature = factoryOrSignature;
}
var func = function () { return new InlineComposition(factory, signature); };
func.signature = signature;
return func;
}
exports.composition = composition;
exports.default = composition;
//# sourceMappingURL=inline-composition.js.map