views:

175

answers:

2

I have a datasource, which I show as a list in a Flex UI.

I refresh the list periodically, One of my UI requirements is to gracefully show when the datasource removes an item from the list, So I'm correlating the current list against the incoming datasource.

The correlation process is this:

  1. Refresh the datasource.

  2. Loop through the existing dataset, Check each ID against the incoming items, if I can't find a match, flag the existing item as closed. (UI handles this flag on item update and does it's visual trick.)

  3. On the next refresh of data, look for flagged items in the current list and remove them.

Here's my question, am I doing this in the most efficient manner? Or is there some simple trick I'm missing?

Update: would a JAXB equivalent for as3 help here?

A: 

I'm not sure I quite follow, but could you just use the new data from the data source as the data provider to the list i.e. bind it to the result of the data source update?

stephen
Well, it's not just binding the data, because I have to display an effect on items that are not included in the last refresh.I'm thinking I need to create a new version of the List (or DataGroup, this is Flex4 BTW) which manages the datachange with a correlation of old data/incomming data. Instead of doing it on the model itself, which seems a bit redundant.
slomojo
+1  A: 

As I understand it, you probably want to have an custom item renderer for each item in the list. Then, when you merge the original list with the updated list, if an item has been deleted, you set a property on the list object(e.g., x[i].deleted=true). Then in your custom item renderer, you just render it differently depending on the state of the "deleted" property.

Simple.

Glenn
That's pretty much what I'm doing already. The model is complex and doesn't really need to know that it has a deleted item. However, If I have the List inspect/correlate the dataprovider, the model doesn't need to care about the delete property.Where I'm going with this is creating a subclass of List to manage the correlation, and Interface the list model Items so that they have an UID of some sort and deleted flag.
slomojo
The question came to mind because of where I was managing the correlation (to begin with on refresh in the model population routine)
slomojo
Yeah. Subclassing the list to handle the merge should be easy as well. Just override the "set dataProvider" function and set the extra properties as needed.
Glenn
Yep, that's the way I think.
slomojo