"use strict"; /** * @class OutputProperty * * @param args Arguments * @param {Function} args.getter Function that returns the value * @param {Node} args.owner Port owner * @param {string} args.type Output value type * @constructor */ function OutputProperty(args) { if(!args.owner) { throw new Error("Owner must be set"); } this.getter = args.getter; this.connections = []; this.owner = args.owner; this.name = args.name; this.onFirstConnectionAdded = args.onFirstConnectionAdded; this.onLastConnectionRemoved = args.onLastConnectionRemoved; this._id = undefined; } Object.defineProperties(OutputProperty.prototype, { /** * Gets the current value * @name OutputProperty#value * @readonly */ value: { get: function() { return this.getter.call(this.owner); } }, id: { get: function() { if(!this._id) { this._id = this.owner.id + this.name; } return this._id; } }, /** * Registers a connection to propagate dirtiness * Also records which input port it's connected to so nodes like * Animation can set it's implicit start value * @name OutputProperty#registerConnection * @readonly */ registerConnection: { value: function(node, inputPortName) { this.connections.push({ node: node, inputPortName: inputPortName }); if(this.connections.length === 1 && this.onFirstConnectionAdded) { this.onFirstConnectionAdded.call(this.owner); } } }, /** * Deregisters a connection to a specific input port * @name OutputProperty#deregisterConnection * @readonly */ deregisterConnection: { value: function(node, inputPortName) { for(var i=0; i 500) { //this will make the owner send a warning and stop its update this.owner._cyclicLoop = true; } for(var i= 0, len=this.connections.length; i 0; } } }); module.exports = OutputProperty;