I guess I'm not really happy with any of them, but I do think my suggestion is the only one staying true to the actual semantics of the language.

Here's what Phil said originally:

The existing app doesn't work as intended because of an initialization issue. The onwidth() event is fired during initialization and this turns the view blue. The intent of the demo is to show an event being fired when the user clicks on a button.

My first thought was to make sure the object was fully initialized before enabling the onwidth event. The problem is that it will make the app look more complicated. I took an easier route and changed the onwidth() method to only turn the view red if the size changes from the initial value. There are lots of ways to solve this issue and the simplest is to hard-wire the initial width into a conditional. I changed

I think the sample code is just poorly conceived. The 'onwidth' handler is going to fire at some indeterminate time after setAttribute ('width',n) is called, at initialization time or later. That's the semantics of our language. It was an accident of the ActionScript language that @width was set (and onwidth triggered) before bgcolor was set to its initial value of red. It is a programming error to rely on that accidental behavior, and adding a check for the initial value is not only brittle, it doesn't teach anything about the defined semantics of LZX.

That's why I recommended using isinited -- it may require learning another concept, but if you are going to write code that is sensitive to initialization time you need to use isinited. Look at the code for baseslider, including the unit tests. To get those unit tests to pass, you pretty much have to engineer it so that all setter- triggered events are deferred until isinited is not longer true. It's not easy to maintain the min<=val<=max constraint otherwise.

jim

On Dec 12, 2006, at 6:50 PM, P T Withington wrote:

I vote for mine!  :P

On 2006-12-12, at 16:30 EST, Philip Romanik wrote:

I haven't checked in my change because there are 3 proposals of how to handle it.

original:
<handler name="onwidth" >
  if (this.getWidth() != 100)
    this.setBGColor(0xFF0000);
</handler>

Jim:
<handler name="onwidth" >
  if (this.isinited == false)
    return;
  this.setBGColor(0xFF0000);
</handler>

Tucker:
<handler name="onwidth">
  this.setAttribute('bgcolor', this.width > 100 ? red : blue);
</handler>

Jim's and Tucker's example is better than my recommendation. I like Tucker's better because it doesn't introduce the concept of isinited. Any objections to me using Tucker's example? In Tucker's example, bgcolor is not initialized in the view, and only in the event handler.

Thanks!

Phil




Reply via email to