I plan to gradually work on a comprehensive set of unit-ish tests for
Bindings (it's less easy than other things, but I believe I have an
approach to do it which will work as unit style tests), from the ground up.

I started looking at this today, just with simple bindings and first up
comparing between swf and js for a binding into Label text, basically
nothing more than:

in mxml code block:
 [Bindable]
  public var labelText:String;

in mxml tags:
 <js:Label localId="testLabel" text="{labelText}" />

the first test was to compare startup values without having set labelText
to anything. (initBindings only)

On swf it is empty string and in javascript it is null.

The reason for that is here :
https://github.com/apache/royale-asjs/blob/093c01e15d04d01cd155a24c5873de32ff273148/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/Label.as#L114

At first glance, it looks like the following could be changed (see code
snippet below):
a) the 'if (textNode)' conditional wrapper should be able to be removed.
(textNode is created during construction, so should always exist I think?)
b) we could probably remove the local _text private var because (as per [a]
above) storage could be in the  textNode.nodeValue directly.
textNode.nodeValue = value; converts null to empty string so if the private
_text var was completely removed, then the getter could simply return
textNode.nodeValue instead of _text. This change would then match swf
behaviour for set null, get empty string from Label text.

inside set text(value:String):void {....

if (textNode)
      {
          _text = value;
         textNode.nodeValue = value;
         this.dispatchEvent('textChange');
       }

Does anyone see any issues with that?

Thanks,
Greg

Reply via email to