@connectv/core
Version:
agent-based reactive programming library for typescript/javascript
71 lines • 2.52 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 rxjs_1 = require("rxjs");
var source_1 = require("../pin/source");
var agent_1 = require("./agent");
/**
*
* Represents [proxy](https://connective.dev/docs/proxy) agents.
*
*/
var Proxy = /** @class */ (function (_super) {
__extends(Proxy, _super);
function Proxy() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
*
* Proxies given agent, connecting it to the rest of the flow
* that the proxy itself is connected to.
*
* @param agent
* @returns a [subscription](https://rxjs-dev.firebaseapp.com/guide/subscription) object
* that can be unsubscribed (call `.unsubscribe()`) to unproxy given agent.
*
*/
Proxy.prototype.proxy = function (agent) {
var _this = this;
var subs = new rxjs_1.Subscription(function () {
_this.untrack(subs);
});
this.inputs.entries.forEach(function (entry) { return agent.in(entry[0]).from(entry[1]); });
this.outputs.entries.forEach(function (entry) {
subs.add(agent.out(entry[0]).observable.subscribe(function (emission) {
entry[1].emit(emission);
}));
});
return this.track(subs);
};
Proxy.prototype.createOutput = function (label) {
this.checkOutput(label);
return new source_1.Source();
};
return Proxy;
}(agent_1.Agent));
exports.Proxy = Proxy;
/**
*
* Creates a [proxy](https://connective.dev/docs/proxy) agent.
* [Checkout the docs](https://connective.dev/docs/proxy) for examples and further information.
*
* @param signature the signature of the proxied agent (or a projection of the signature that needs
* to be proxied).
*
*/
function proxy(signature) { return new Proxy(signature); }
exports.proxy = proxy;
exports.default = proxy;
//# sourceMappingURL=proxy.js.map