You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@royale.apache.org by Greg Dove <gr...@gmail.com> on 2019/10/02 09:44:38 UTC

RoyaleArrayLike - quick summary

Just a quick overview of something I added that I was meaning to do for a
long time. It makes a huge difference when porting from things like
ArrayCollection to Royale ArrayList. It saved me hours of menial stuff on
something I had to do recently, and that was also a time-consuming task
that both Carlos and I experienced when working on his app.

The latest updates include support for IArrayList and BinaryData to be used
in for each loops and also to use indexed array access. This works the same
(and uses the same code) to make it work between swf and js - it is
metadata driven.  This only works with strong typing - it is compile-time
only, and follows normal inheritance rules (so AMFBinaryData should also
work the same because it inherits from BinaryData, for example).


So you can do (assuming myArrayList and myOtherArrayList are either
IArrayList typed or some implementing type or subclass such as ArrayList or
ArrayListView):
myArrayList[0] = myOtherArrayList[100]

and it will generate:
myArrayList.setItemAt(myOtherArrayList.getItemAt(100),0)

or:
myBinaryData[0] = 255;

and things like:
for each(var byte:uint in myBinaryData) ....

for-each loops (and for-in loops) are supported without special methods or
properties needed on the classes that are supported. There is a single
support function in Language that provides backing support and is included
in the build only if it is needed. At the moment it is a one-size-fits-all
support function.
The loops behave like normal as3 for loops, and handle null target values
and also loop target mutation inside the loop (e.g removeAll() on an
ArrayList loop target instance inside the loop will stop the loop early).
This could also be a safer option for things like XMLList and
ArrayCollection as well, I did not consider that yet, but I will test those
in the coming days.

Re: RoyaleArrayLike - quick summary

Posted by Carlos Rovira <ca...@apache.org>.
Hi Greg,

I know about this change, but missed this email. Thanks for working on this
improvement.
I think this was very needed, and we know about it since we suffer lots of
for each loops for collections
that we need to migrate to some more basic loop, what made the task very
cumbersome.

This change will make migration more close to change less code, so this is
a very cool change, thanks! :)

In fact with this improvement, I think coding in Royale now is very very
close to coding in Flex. Right now I don't remember
other issues of this kind...maybe others can think in something we already
can't be done in Royale, exposing it would be good
to take it into account :)



El mié., 2 oct. 2019 a las 11:44, Greg Dove (<gr...@gmail.com>)
escribió:

> Just a quick overview of something I added that I was meaning to do for a
> long time. It makes a huge difference when porting from things like
> ArrayCollection to Royale ArrayList. It saved me hours of menial stuff on
> something I had to do recently, and that was also a time-consuming task
> that both Carlos and I experienced when working on his app.
>
> The latest updates include support for IArrayList and BinaryData to be used
> in for each loops and also to use indexed array access. This works the same
> (and uses the same code) to make it work between swf and js - it is
> metadata driven.  This only works with strong typing - it is compile-time
> only, and follows normal inheritance rules (so AMFBinaryData should also
> work the same because it inherits from BinaryData, for example).
>
>
> So you can do (assuming myArrayList and myOtherArrayList are either
> IArrayList typed or some implementing type or subclass such as ArrayList or
> ArrayListView):
> myArrayList[0] = myOtherArrayList[100]
>
> and it will generate:
> myArrayList.setItemAt(myOtherArrayList.getItemAt(100),0)
>
> or:
> myBinaryData[0] = 255;
>
> and things like:
> for each(var byte:uint in myBinaryData) ....
>
> for-each loops (and for-in loops) are supported without special methods or
> properties needed on the classes that are supported. There is a single
> support function in Language that provides backing support and is included
> in the build only if it is needed. At the moment it is a one-size-fits-all
> support function.
> The loops behave like normal as3 for loops, and handle null target values
> and also loop target mutation inside the loop (e.g removeAll() on an
> ArrayList loop target instance inside the loop will stop the loop early).
> This could also be a safer option for things like XMLList and
> ArrayCollection as well, I did not consider that yet, but I will test those
> in the coming days.
>


-- 
Carlos Rovira
http://about.me/carlosrovira