UNPKG

@chix/flow

Version:
85 lines 3.47 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 context_1 = require("../context"); var events_1 = require("../events"); var util_1 = require("../util"); var node_1 = require("./node"); var ports_1 = require("./ports"); var debug = _debug('chix:flow'); function $Context(Base) { return (function (_super) { __extends(Context$, _super); function Context$() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.contextProvider = new context_1.DefaultContextProvider(); return _this; } 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.addContext = function (context) { var _this = this; debug('%s: addContext', this.identifier); forOf(function (port, val) { var portDef = _this.getPortDefinition(port, 'input'); _this.getNode(portDef.nodeId).setContextProperty(portDef.name, val); }, context); }; Context$.prototype.setContextProperty = function (port, data, trigger) { var portDef = this.getPortDefinition(port, 'input'); this.getNode(portDef.nodeId).setContextProperty(portDef.name, data, trigger); this.event(events_1.NodeEvents.CONTEXT_UPDATE, { data: data, node: this, port: port, }); }; Context$.prototype.clearContextProperty = function (port) { var portDef = this.getPortDefinition(port, 'input'); var inputPort = this.getNode(portDef.nodeId).getInputPort(portDef.name); var context = inputPort.context.read(inputPort); inputPort.clearContext(); this.event(events_1.NodeEvents.CONTEXT_CLEAR, { node: this, port: port, context: context, }); }; Context$.prototype.setContextProvider = function (provider) { this.contextProvider = provider; }; return Context$; }(Base)); } exports.$Context = $Context; (function ($Context) { function create(Base) { return util_1.mixin($Context, common_1.$Event.create, common_1.$Identity.create, node_1.$Node.create, ports_1.$Ports.create)(Base); } $Context.create = create; })($Context = exports.$Context || (exports.$Context = {})); //# sourceMappingURL=context.js.map