The solution is that there is no solution. The simplest thing to do is to ensure that the values are updated by hand whenever they need to be drawn. I’ve included a method called assignDisplayValues
to the arrivals component. It should be called just before the drawBasicFunction
. This feels wasteful and kludgy, but it seems like the most straightforward thing to do. Other solutions (like burying values in arrays) impose overheads of their own, so I figure it would be best to just be honest about what’s happening. In the long run this will be the most clear solution for the programmer.
I’m surprised that I hadn’t really appreciated this aspect of JavaScript until now, but perhaps I shouldn’t be. Every tool comes with a large number of features you simply won’t see until you do that first thing that forces you to. In the meantime I understand why this limitation is part of the language, but I also understand why people probably find it to be annoying (a word I seem to be using a lot recently…).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
//could also create blank and then use this.dataGroup.define externally so initiation not internal like this this.dataGroup = new displayGroup(this.componentName,10,10,100,"#00FFFF","#FF0000","#FFFF00"); this.dataGroup.addValue(this.componentID,"comp. ID","integer"); this.dataGroup.addValue(this.startBlockTime,"Start Time","numdec",5); this.dataGroup.addValue(this.currentBlockTime,"CurrentTime","numdec",5); this.dataGroup.addValue(this.endBlockTime,"End Time","numdec",5); this.dataGroup.addValue(this.entitiesScheduled,"# Entities","integer"); this.dataGroup.addValue(this.entitiesRemaining,"# Remaining","integer"); this.dataGroup.addValue(this.currentEntityID,"Entity ID","integer"); this.dataGroup.addValue(this.activity,"Activity","text"); this.assignDisplayValues = function() { this.dataGroup.valueList[0].value = this.componentID; this.dataGroup.valueList[1].value = this.startBlockTime; this.dataGroup.valueList[2].value = this.currentBlockTime; this.dataGroup.valueList[3].value = this.endBlockTime; this.dataGroup.valueList[4].value = this.entitiesScheduled; this.dataGroup.valueList[5].value = this.entitiesRemaining; this.dataGroup.valueList[6].value = this.currentEntityID; this.dataGroup.valueList[7].value = this.activity; }; ... ... //set values before drawing this.assignDisplayValues(); clearCanvas("#000000"); this.dataGroup.drawBasic(); |