First, I'm not demanding anything, this is just an idea. I know that even
so when ideas are proposed in open source projects some people feel
"offended" and ask for the OP to work on them, but I hope this is taken
kindly by everyone.

I'm lately feeling that MXML could be less verbose if attributes could be
decorated with a custom converter. For greater reusability the converter
could point to some interface implementation, or if the performance may be
a critical concern because of mobile devices, maybe some global function,
or if the latter suppose some problem, maybe a local function.

The idea would be reducing boilerplate code like:

<custom:Component>
  <custom:padding>
    <geom:Rectangle left="10" right="10" />
  </custom:padding>
</custom:Component>

Or

<s:Rect>
  <s:fill>
   <s:SolidColor="#ff0000"/>
  </s:fill>
</s:Rect>

To more compact code like:

<custom:Component padding="10;10"/>

And

<s:Rect fill="#ff0000"/>

The code behind would be something like:

[Converter("org.apache.MxmlConverters.convertToRectangle")]
public function set padding(value:Rectangle):void { .. }

[Converter("org.apache.MxmlConverters.convertToSolidColor")]
public function set padding(value:IFill):void { .. }

Using a function as the converter also enables to check the returned value
type is the one needed, as AS3 doesn't support generics an interface
wouldn't allow to validate the type.

This is somewhat similar to XAML. I don't know if allowing to inject some
converter in binding expressions like XAML does would be meaningful (since
I'd say we could just use it directly in the binding expression):

<s:Rect fill="{'#ff0000;#000000',
Converter='org.apache.MxmlConverters.convertToGradientColor'}"/>

Or maybe:

<s:Rect fill="@Converter(value='#ff0000;#000000',
converter='org.apacheMxmlConverters.convertToGradientColor')"/>

What do you think? would this change make MXML a bit more pleasant to work
with? I sometimes think so.

Reply via email to