UNPKG

autograph

Version:

A visual data routing automation tool.

206 lines (153 loc) 6.14 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Source: components/models/BaseComponent.js</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Source: components/models/BaseComponent.js</h1> <section> <article> <pre class="prettyprint source"><code>/** * Implement the logic of an AutoGraph component * @module BaseComponent */ define(['models/PositionedModel', 'models/OutputTerminalModel', 'models/InputTerminalModel'], function (PositionedModel, OutputTerminalModel, InputTerminalModel) { /** * @constructor */ return PositionedModel.extend({ label:"component", inputs:{ input:{name:"input"} }, outputs:{ output:{name:"output"} }, defaults:{ }, /** * @method */ initialize:function () { this.buildInputs(this.inputs); this.buildOutputs(this.outputs); }, /** * @method */ receiveBang:function () { var inputTerminalValues = this.readInputValues(); var self = this; this.process(inputTerminalValues, function (results) { console.log("process results for "+self.label); console.log(results); self.updateOutputTerminals(results); self.sendBang(); }); }, /** * @method */ readInputValues:function () { var ins = {}; for (var key in this.inputs) { var input = this.inputs[key].model; if (input.get("value")) { ins[key] = input.get("value"); } } return ins; }, /** * @method */ updateOutputTerminals:function (values) { for (var key in values) { var output = this.outputs[key]; if (output) { output.model.set("value", values[key]); } } }, /** * @method */ process:function (args, callback) { callback(args); }, /** * @method */ sendBang:function () { this.trigger("bang"); }, /** * @method */ buildInputs:function (inputs) { var cnt = 0; for (var i in inputs) { var input = inputs[i]; var im = new InputTerminalModel({ autograph:this.get("autograph"), component:this, x:cnt * 20, y:0, name:input.name }); this.listenTo(im, "bang", this.receiveBang); this.listenTo(im, "change:value", function () { console.log("basecomp setting " + input.name + " to " + im.get("value")); this.set(input.name, im.get("value")) }); input.model = im; this.get("autograph").Terminals.add(im); cnt++; } }, /** * @method */ buildOutputs:function (outputs) { var cnt = 0; for (var i in outputs) { var output = outputs[i]; var om = new OutputTerminalModel({ autograph:this.get("autograph"), component:this, x:cnt * 20, y:0, name:output.name }); output.model = om; this.get("autograph").Terminals.add(om); cnt++; } } }); }); </code></pre> </article> </section> </div> <nav> <h2><a href="index.html">Index</a></h2><h3>Modules</h3><ul><li><a href="module-autograph.html">autograph</a></li><li><a href="module-BaseComponent.html">BaseComponent</a></li><li><a href="module-BaseComponentView.html">BaseComponentView</a></li><li><a href="module-ComponentCollection.html">ComponentCollection</a></li><li><a href="module-ComponentLibrary.html">ComponentLibrary</a></li><li><a href="module-CursorModel.html">CursorModel</a></li><li><a href="TerminalModel_.html">models/TerminalModel</a></li><li><a href="module-PositionedModel.html">PositionedModel</a></li><li><a href="module-SelectionTool.html">SelectionTool</a></li><li><a href="module-TerminalModel.html">TerminalModel</a></li><li><a href="module-WebviewComponentView.html">WebviewComponentView</a></li><li><a href="module-WireModel.html">WireModel</a></li></ul><h3>Classes</h3><ul><li><a href="BaseComponentView.html">BaseComponentView</a></li><li><a href="ButtonComponent.html">ButtonComponent</a></li><li><a href="ButtonComponentView.html">ButtonComponentView</a></li><li><a href="ClockComponent.html">ClockComponent</a></li><li><a href="ComponentLibrary.html">ComponentLibrary</a></li><li><a href="DelayComponent.html">DelayComponent</a></li><li><a href="EchoComponentView.html">EchoComponentView</a></li><li><a href="HTTPClientComponentView.html">HTTPClientComponentView</a></li><li><a href="TerminalModel.html">models/TerminalModel</a></li><li><a href="PositionedModel.html">PositionedModel</a></li><li><a href="TerminalModel__.html">TerminalModel</a></li><li><a href="ValueComponentView.html">ValueComponentView</a></li><li><a href="WebviewComponentView.html">WebviewComponentView</a></li><li><a href="WireModel.html">WireModel</a></li></ul><h3>Global</h3><ul><li><a href="global.html#addContent">addContent</a></li><li><a href="global.html#hilight">hilight</a></li><li><a href="global.html#initialize">initialize</a></li><li><a href="global.html#render">render</a></li></ul> </nav> <br clear="both"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a> on Wed May 07 2014 22:03:07 GMT-0500 (CDT) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>