Sunday, 3 January 2010

Implementing Lazy Loading of XML with ArrayCollection

I am still gradually working through my implementation of the Picasa public API to load images into Flex. One of the first apps I want to build is a simple signature app for forums that will loop through images in a Picasa album and display them one by one.

A Picasa album can contain 1000 images and the xml is pretty verbose so this would be a very large download. This would download each time the signature appeared on a page and every time the page was refreshed so downloading the whole lot is really bad idea.

I want to mimic the fill method of DataService. I would ask for an ArrayCollection to be filled but only the first 5 or however many records are specified would initially be loaded. The length of the collection would be reported as the number of items in the album and not the number of items downloaded. Additional items would be loaded as they are required.

Looking at ArrayCollection the getItemAt method has a prefetch argument specifying the number of items to fetch if the item is not local. There is also the ItemPendingError that is despatched if the item that is requested is not local but there isn’t much documentation about this and it’s not clear exactly how this is handled.

I had hoped that List and DataGroup for example would listen for ItemPendingError and add responders but they don’t seem to so it might not be as useful to implement the behaviour in this way.

If anyone has any clues as to how all this holds together I’d be very interested to hear them. I am particularly interested in how the DataService class interacts with ListCollectionView. Somehow DataService has to get ListCollectionView to report the length of the remote list and not the local list.
Unfortunately the source for DataService doesn’t seem to be available.

I could possibly implement this with some specific implementation of IList that is passed to a ListCollectionView but I would rather do it a similar way to the framework.

Any help much appreciated.

1 comment:

  1. I too am currently trying to find a good solution to this problem. I've stumbled over some very old partial implementations all based on the idea of creating you own IList implementation. So far, everything I've found lacks sorting or query terms support or both.

    If you get any good answers to this one, please blog them!

    ReplyDelete