UNPKG

@chix/flow

Version:
65 lines 2.49 kB
"use strict"; 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 _debug = require("debug"); var uuid_1 = require("uuid"); var events_1 = require("../events"); var debug = _debug('chix:io'); function $Connect(Base) { return (function (_super) { __extends(Connect$, _super); function Connect$() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.connections = new Map(); return _this; } Connect$.prototype.connect = function (link) { if (!link.source || !link.source.id || !link.source.port) { throw Error('Link requires a source'); } if (!link.source.pid) { link.source.pid = link.source.id; } if (!link.ioid) { link.ioid = uuid_1.v4(); } if (!link.target || !link.target.id || !link.target.port) { throw Error('Link requires a target'); } if (!link.target.pid) { link.target.pid = link.target.id; } this.connections.set(link.ioid, link); if (link.target.has('sync')) { this.addSyncedTarget(link); } if (link.source.get('pointer')) { this.addPointerPort(link); } debug('%s: link connected', link.ioid); link.source.on(events_1.ConnectorEvents.DATA, this.onDataHandler); this.emit(events_1.IOEvents.CONNECT, link); }; Connect$.prototype.get = function (link) { if (this.connections.has(link.ioid)) { return this.connections.get(link.ioid); } throw Error('Unable to get link.'); }; return Connect$; }(Base)); } exports.$Connect = $Connect; //# sourceMappingURL=connect.js.map