UNPKG

@chix/flow

Version:
67 lines 2.92 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 debug = _debug('chix:io'); function $Sync(Base) { return (function (_super) { __extends(Sync$, _super); function Sync$() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.syncedTargetMap = new Map(); return _this; } Sync$.prototype.addSyncedTarget = function (link) { if (!this.syncedTargetMap.has(link.target.pid)) { this.syncedTargetMap.set(link.target.pid, {}); } if (!this.syncedTargetMap.get(link.target.pid)[link.target.get('sync')]) { this.syncedTargetMap.get(link.target.pid)[link.target.get('sync')] = []; } this.syncedTargetMap .get(link.target.pid)[link.target.get('sync')].push(link.target.port); debug('%s: syncing source port `%s` with target port %s', link.ioid, link.target.get('sync'), link.target.port); }; Sync$.prototype.removeSyncedTarget = function (link) { var tgt = this.syncedTargetMap.get(link.target.pid); tgt.splice(tgt.indexOf(link.target.port), 1); if (tgt.length === 0) { this.syncedTargetMap.delete(link.target.pid); } }; Sync$.prototype.getSyncedTargetPorts = function (target) { var originId = target.get('sync'); if (!this.syncedTargetMap.has(target.pid)) { throw new Error("Unknown sync: " + target.pid); } if (!this.syncedTargetMap.get(target.pid).hasOwnProperty(originId)) { throw new Error("Unknown sync with: " + originId); } return this.syncedTargetMap.get(target.pid)[originId]; }; Sync$.prototype.sendSynced = function (_targetId, data) { for (var targetPort in data) { if (data.hasOwnProperty(targetPort)) { var synced = data[targetPort]; debug('%s: sendSynced', synced.link.ioid); this.__sendData(synced.link, synced.p); } } }; return Sync$; }(Base)); } exports.$Sync = $Sync; //# sourceMappingURL=sync.js.map