sort Bulkloader.items array

6 views
Skip to first unread message

JeffWinder

unread,
Jun 10, 2010, 7:39:38 AM6/10/10
to BulkLoader users
hi,

when I load a number of images and one of them is for example an
invalid url,
then I listen for the error in the error handler for that item
I then remove the item by remove( item.id )
and add another url, of a default, alternative pic.
And then I start BulkLoader again.

This is how I understood one can do this,
but it results in two problems:
- the complete handler for all items gets called twice,
once for the items that are loaded correctly the first time
and once for when they are loaded including the alternative image.

- the alternative image ends up at the end of the array,
messing up my way of handling the loaded images.

I can deal with the first problem by checking whether
the number of loaded items is equal to the items I requested to ooad.

About the second issue: Is there a way to sort the array
on item id's, for instance by using the Array.sort or Array.sortOn
method,
and how would that look?
My id's are uints, that have the right order so
items[0].id = 3304
items[1].id = 3305
items[2].id = 3308
items[3[.id = 3312

When the alternative image ends up at the end of the array,
then naturally its position is not correct, also regarding the id's,
so the id's would give me a chance to sort the array, but I'm not sure
how.

Maybe more of an actionscript question but anyway,

thanks!
Jeff.

Jeff

unread,
Jun 10, 2010, 9:16:06 AM6/10/10
to BulkLoader users
well, it's simple,just
forgot to pass id between quotes:

images.sortOn('id');

But if there is a better way of dealing with loading errors,
I'd still be interested :)

Blake Goulette

unread,
Jun 10, 2010, 9:42:10 AM6/10/10
to bulkload...@googlegroups.com
Real quick, but wouldn't the following work:

items.sortOn("id") do just what you want? Not sure if you have to reassign items -- items=items.sortOn("id"); -- or not...


--
You received this message because you are subscribed to the Google Groups "BulkLoader users" group.
To post to this group, send email to bulkload...@googlegroups.com.
To unsubscribe from this group, send email to bulkloader-use...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/bulkloader-users?hl=en.


Arthur Debert

unread,
Jun 10, 2010, 11:01:21 AM6/10/10
to bulkload...@googlegroups.com
Hi Jeff.

> - the complete handler for all items gets called twice,
> once for the items that are loaded correctly the first time
> and once for  when they are loaded including the alternative image.

If this is happening its a bug. Period. If so, it usually is good
practice to remove listeners inside it's handlers (to avoid either
memory leaks or multiple dispatches). If you can provide a minimal
test case showing that, I'd appreciate it.

> About the second issue: Is there a way to sort the array
> on item id's, for instance by using the Array.sort or Array.sortOn
> method,
> and how would that look?

Items are just a regular array. You can sort it any way you like:
sortOn, a regular loop and custom logic. You name it.
The thing is, this one example of BulkLoaders permissive design.

It's usually not a good thing to allow users to mock directly with the
'items' collection. They might remove stuff that should be there, add
odd things, etc. The way I've deal with it is this:
- bulkLoader.items -> Returns a **copy** of the all items in that
bulkloader. For most users. It's safer.
- bulkLoader._items -> Returns the original thing. Just don't do weird
stuff with it. Nothing is private in BulkLoader. If you know what you
are doing, go ahead.

If you go through the code, there are updates to properties every time
an item is added or removed (look inside the implementation of 'add'
and 'remove' for an idea of what it looks like). This means that
adding or removing items should be done through those methods. Direct
manipulation will get you weird behavior.

The way to deal with is correct, with the caveat that 2 onCompletes
would definitely a bug.

Two ideas to explore as well:
- On the item fail: change it to the new URL. And ask to reload it .
(beware: kludge)
- If removing and adding it, you can always use the priority property
or 'loadNow' to assure loading as quickly as possible.

Best Regards
--
Arthur Debert
www.stimuli.com.br

Reply all
Reply to author
Forward
0 new messages