@connectv/core
Version:
agent-based reactive programming library for typescript/javascript
153 lines • 5.35 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 __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var tracker_1 = require("../shared/tracker");
var group_1 = __importStar(require("./group"));
//
// TODO: write tests for this.
// TODO: make Agent inherit this, but default throwing error when used like this.
// TODO: make common agent types act as proper partial flows.
//
/**
*
* Represents a partial reactive flow, with some entry pins going into it
* and some exit pins coming out of it.
*
*/
var PartialFlow = /** @class */ (function (_super) {
__extends(PartialFlow, _super);
function PartialFlow() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
*
* Connects all given pins to all of its entry pins
*
* @param pins
* @returns a [group](https://connective.dev/docs/group) of the given pins. If any `PartialFlow`
* was among the given pins, its entry pins will be added to the group.
*
*/
PartialFlow.prototype.from = function () {
var _a;
var pins = [];
for (var _i = 0; _i < arguments.length; _i++) {
pins[_i] = arguments[_i];
}
return (_a = this.entries).from.apply(_a, pins);
};
/**
*
* Connects all of its exit pins to given pins
*
* @param pins
* @returns a [group](https://connective.dev/docs/group) of the given pins. If any `PartialFlow`
* was among the given pins, its exit pins added to the group.
*
*/
PartialFlow.prototype.to = function () {
var _a;
var pins = [];
for (var _i = 0; _i < arguments.length; _i++) {
pins[_i] = arguments[_i];
}
return (_a = this.exits).to.apply(_a, pins);
};
/**
*
* Connects all given pins serially to its entry pins
*
* @param pins
* @returns a [group](https://connective.dev/docs/group) of the given pins. If any `PartialFlow`
* was among the given pins, its entry pins will be added to the group.
*
*/
PartialFlow.prototype.serialFrom = function () {
var _a;
var pins = [];
for (var _i = 0; _i < arguments.length; _i++) {
pins[_i] = arguments[_i];
}
return (_a = this.entries).serialFrom.apply(_a, pins);
};
/**
*
* Connects all of its exit pins to given pins
*
* @param pins
* @returns a [group](https://connective.dev/docs/group) of the given pins. If any `PartialFlow`
* was among the given pins, its exit pins added to the group.
*
*/
PartialFlow.prototype.serialTo = function () {
var _a;
var pins = [];
for (var _i = 0; _i < arguments.length; _i++) {
pins[_i] = arguments[_i];
}
return (_a = this.exits).serialTo.apply(_a, pins);
};
Object.defineProperty(PartialFlow.prototype, "observable", {
get: function () {
return this.exits.observable;
},
enumerable: true,
configurable: true
});
/**
*
* Subscribes to all of its exit pins. Returns a composite subscription of
* all created subscriptions.
*
*/
PartialFlow.prototype.subscribe = function (_, __, ___) {
return this.exits.subscribe(_, __, ___);
};
return PartialFlow;
}(tracker_1.Tracker));
exports.PartialFlow = PartialFlow;
var InlineFlow = /** @class */ (function (_super) {
__extends(InlineFlow, _super);
function InlineFlow(factory) {
var _this = _super.call(this) || this;
_this.factory = factory;
var _a = factory(), entries = _a[0], exits = _a[1];
_this.entries = (entries instanceof group_1.Group) ? entries : group_1.default.apply(void 0, entries);
_this.exits = (exits instanceof group_1.Group) ? exits : group_1.default.apply(void 0, exits);
return _this;
}
return InlineFlow;
}(PartialFlow));
/**
*
* Creates a partial flow, using the given factory function. The factory function
* should return either a [`group`](https://connective.dev/docs/group) or an array
* of [pins](https://connective.dev/docs/pin) for inputs, and a group or an array of pins
* for outputs, in array format itself (first object being the inputs, second the outputs).
*
* @param factory
*
*/
function partialFlow(factory) { return new InlineFlow(factory); }
exports.partialFlow = partialFlow;
exports.default = partialFlow;
//# sourceMappingURL=partial-flow.js.map