UNPKG

@chix/flow

Version:
100 lines 3.89 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 forOf = require("object-forof"); var common_1 = require("../common"); var events_1 = require("../events"); var packet_1 = require("../packet"); var util_1 = require("../util"); var ports_1 = require("./ports"); var debug = _debug('chix:node'); function $Context(Base) { return (function (_super) { __extends(Context$, _super); function Context$() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.setContext = _this.setContextProperty; return _this; } Context$.prototype.$setContextProperty = function (port, data, trigger) { debug('%s:%s set context', this.identifier, port); if (data === undefined) { throw Error('Refused to $setContextProperty to undefined'); } var packet; if (packet_1.Packet.isPacket(data)) { packet = data; } else { packet = packet_1.Packet.create(data, this.getPortType('input', port)).setOwner(this); } this.getInputPort(port).setContext(packet, trigger); }; Object.defineProperty(Context$.prototype, "context", { get: function () { var context = {}; forOf(function (name, port) { context[name] = port.context; }, this.ports.input); return context; }, enumerable: true, configurable: true }); Context$.prototype.clearContextProperty = function (port) { debug('%s:%s clear context', this.identifier, port); var inputPort = this.getInputPort(port); var context = inputPort.context.read(inputPort); inputPort.clearContext(); this.event(events_1.NodeEvents.CONTEXT_CLEAR, { node: this, port: port, context: context, }); }; Context$.prototype.addContext = function (context) { var _this = this; forOf(function (port, val) { _this.setContextProperty(port, val); }, context); }; Context$.prototype.setContextProperty = function (port, data, trigger) { if (port === ':start') { this._initStartPort(); } if (this.portExists('input', port)) { this.$setContextProperty(port, data, trigger); this.event(events_1.NodeEvents.CONTEXT_UPDATE, { data: data, node: this, port: port, }); } else { throw Error("No such input port " + port + " for " + this.identifier); } }; return Context$; }(Base)); } exports.$Context = $Context; (function ($Context) { function create(Base) { return util_1.mixin($Context, common_1.$Event.create, common_1.$Identity.create, ports_1.$Ports.create)(Base); } $Context.create = create; })($Context = exports.$Context || (exports.$Context = {})); //# sourceMappingURL=context.js.map