UNPKG

@connectv/core

Version:

agent-based reactive programming library for typescript/javascript

48 lines 1.5 kB
import { Subscription } from 'rxjs'; import { Source } from '../pin/source'; import { Agent } from './agent'; /** * * Represents [proxy](https://connective.dev/docs/proxy) agents. * */ export class Proxy extends Agent { /** * * 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(agent) { let subs = new Subscription(() => { this.untrack(subs); }); this.inputs.entries.forEach(entry => agent.in(entry[0]).from(entry[1])); this.outputs.entries.forEach(entry => { subs.add(agent.out(entry[0]).observable.subscribe((emission) => { entry[1].emit(emission); })); }); return this.track(subs); } createOutput(label) { this.checkOutput(label); return new Source(); } } /** * * 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). * */ export function proxy(signature) { return new Proxy(signature); } export default proxy; //# sourceMappingURL=proxy.js.map