Nice idea, go work on it ;-)

Seriously, though, it would be nice to see something like this.  I don’t
know that I’d use a Converter, it might be sufficient to use Metadata to
annotate a property with a default class and property list to use if the
value doesn’t coerce cleanly.  So maybe the Component would be defined
like this:

Class Component
{
    [ValueConversion(class=geom.Rectangle,propertylist=left,right)]
    public var padding:Rectangle;
}

It won’t be on my work list right now though, too many other fish to fry.
One other note: in FlexJS, we are allowing HTML style syntax for styles so
padding can be expressed as:

<custom:Component style=“padding:10,10” />

This doesn’t get checked by the compiler, so you can also do:

<custom:Component>
        <custom:style>
                <js:SimpleStyleObject paddingLeft=“10” paddingRight=“10” />

-Alex

On 5/7/15, 10:21 AM, "Héctor A" <neverbi...@gmail.com> wrote:

>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