[flexcoders] Design Patters For Loading Data?

2008-08-12 Thread nwebb
Hi, hoping for some help on this...
*
Problem*:
I am making multiple asynchronous calls to the server and I want to ensure I
have the data back from *all* the calls before calling method x.
I don't want to daisy-chain the calls (i.e.having to wait until service#1
reurns data before calling service#2 and so on).

I have a solution which will suffice* but I'm sure there must be a tried and
tested way of handling this kind of scenario - perhaps a design pattern(?).

---
* my current solution is to declare an ArrayCollection and listen to its
CollectionEvent.COLLECTION_CHANGE event.
In each onResult() method I set* itemsLoaded.addItem(true);* and similarly
in each onFault() method I set *itemsLoaded.addItem(false);*

Each time I add the boolean value to the collection, the change-event
handler is called. Inside the change handler I check to see whether the
collection length is equal to the number of results I'm expecting. If it is,
I loop through the collection and check if all the values are true or not.


Re: [flexcoders] Design Patters For Loading Data?

2008-08-12 Thread Simon Bailey
How about defining and array with all the method names and every time  
a method is returned it removes its method name from the array.  The  
method to remove each item from the array would check the array length  
each times its called and when the array.length == 0 then call your  
method x?


Cheers,

Simon

newtriks.com

On 12 Aug 2008, at 12:37, nwebb wrote:


Hi, hoping for some help on this...

Problem:
I am making multiple asynchronous calls to the server and I want to  
ensure I have the data back from all the calls before calling method x.
I don't want to daisy-chain the calls (i.e.having to wait until  
service#1 reurns data before calling service#2 and so on).


I have a solution which will suffice* but I'm sure there must be a  
tried and tested way of handling this kind of scenario - perhaps a  
design pattern(?).


---
* my current solution is to declare an ArrayCollection and listen to  
its CollectionEvent.COLLECTION_CHANGE event.
In each onResult() method I set itemsLoaded.addItem(true); and  
similarly in each onFault() method I set itemsLoaded.addItem(false);


Each time I add the boolean value to the collection, the change-event  
handler is called. Inside the change handler I check to see whether  
the collection length is equal to the number of results I'm expecting.  
If it is, I loop through the collection and check if all the values  
are true or not.







Re: [flexcoders] Design Patters For Loading Data?

2008-08-12 Thread jitendra jain

 Why don't u go for Cairngorm Framework that is perfectly designed for this 
purposeThanks,

with Regards,
Jitendra Jain
Software Engineer




- Original Message 
From: nwebb [EMAIL PROTECTED]
To: flexcoders@yahoogroups.com
Sent: Tuesday, August 12, 2008 5:07:47 PM
Subject: [flexcoders] Design Patters For Loading Data?


Hi, hoping for some help on this...

Problem:
I am making multiple asynchronous calls to the server and I want to ensure I 
have the data back from all the calls before calling method x.
I don't want to daisy-chain the calls (i.e.having to wait until service#1 
reurns data before calling service#2 and so on).

I have a solution which will suffice* but I'm sure there must be a tried and 
tested way of handling this kind of scenario - perhaps a design pattern(?).

 - - -
* my current solution is to declare an ArrayCollection and listen to its 
CollectionEvent. COLLECTION_ CHANGE event. 
In each onResult() method I setitemsLoaded. addItem(true) ; and similarly in 
each onFault() method I set itemsLoaded. addItem(false) ;

Each time I add the boolean value to the collection, the change-event handler 
is called. Inside the change handler I check to see whether the collection 
length is equal to the number of results I'm expecting. If it is, I loop 
through the collection and check if all the values are true or not.

 


  

Re: [flexcoders] Design Patters For Loading Data?

2008-08-12 Thread Johannes Nel
i normally use a hash to manage this kind of thing. when the responder
returns you set the key in the dictionary object's to true, false or error
object, and you loop through all the keys and make your decision from
there.

On Tue, Aug 12, 2008 at 1:46 PM, Simon Bailey [EMAIL PROTECTED]wrote:

   How about defining and array with all the method names and every time a
 method is returned it removes its method name from the array.  The method to
 remove each item from the array would check the array length each times its
 called and when the array.length == 0 then call your method x?

 Cheers,

 Simon
 **
 newtriks.com http://www.newtriks.com/

 On 12 Aug 2008, at 12:37, nwebb wrote:


 Hi, hoping for some help on this...
 *
 Problem*:
 I am making multiple asynchronous calls to the server and I want to ensure
 I have the data back from *all* the calls before calling method x.
 I don't want to daisy-chain the calls (i.e.having to wait until service#1
 reurns data before calling service#2 and so on).

 I have a solution which will suffice* but I'm sure there must be a tried
 and tested way of handling this kind of scenario - perhaps a design
 pattern(?).

 ---
 * my current solution is to declare an ArrayCollection and listen to its
 CollectionEvent.COLLECTION_CHANGE event.
 In each onResult() method I set* itemsLoaded.addItem(true);* and similarly
 in each onFault() method I set *itemsLoaded.addItem(false);*

 Each time I add the boolean value to the collection, the change-event
 handler is called. Inside the change handler I check to see whether the
 collection length is equal to the number of results I'm expecting. If it is,
 I loop through the collection and check if all the values are true or not.



  




-- 
j:pn
\\no comment


Re: [flexcoders] Design Patters For Loading Data?

2008-08-12 Thread Josh McDonald
This is pretty ordinary, and I plan on re-vamping it, but we're planning on
open sourcing most of this stuff soon, so you might as well have a look and
you can use it as a base for something better:
http://www.gfunk007.com/flex/ChainLoader.as

Usage example:

new ChainLoader(Application.application.spinner, begin).then(
Application.application, showLoading).then(
Singletons.services.returnCentreDao,
getReturnCentre).thenOnSuccess(
Singletons.services.vehiclesDao,
getVehiclesPending).thenOnSuccess(
Singletons.services.vehiclesDao,
getVehiclesInStock).thenOnSuccess(
Singletons.services.vehiclesDao,
getVehiclesInRepair).thenOnSuccess(
Singletons.services.tenderDao,
getAllTenders).thenOnSuccess(
this, selectDefaultTender).then(
this, getTenderVehicles).thenOnSuccess(
_pollTimer, start).then(
this, selectReturnCentreCompleted).then(
Application.application, hideLoading).then(
Application.application.spinner, end).go();

Like I said, it's rough don't bother telling me the myriad ways it can be
better, I know :)

-Josh

On Tue, Aug 12, 2008 at 9:46 PM, Simon Bailey [EMAIL PROTECTED]wrote:

  How about defining and array with all the method names and every time a
 method is returned it removes its method name from the array.  The method to
 remove each item from the array would check the array length each times its
 called and when the array.length == 0 then call your method x?
 Cheers,

 Simon
 **
 newtriks.com http://www.newtriks.com/

 On 12 Aug 2008, at 12:37, nwebb wrote:


 Hi, hoping for some help on this...
 *
 Problem*:
 I am making multiple asynchronous calls to the server and I want to ensure
 I have the data back from *all* the calls before calling method x.
 I don't want to daisy-chain the calls (i.e.having to wait until service#1
 reurns data before calling service#2 and so on).

 I have a solution which will suffice* but I'm sure there must be a tried
 and tested way of handling this kind of scenario - perhaps a design
 pattern(?).

 ---
 * my current solution is to declare an ArrayCollection and listen to its
 CollectionEvent.COLLECTION_CHANGE event.
 In each onResult() method I set* itemsLoaded.addItem(true);* and similarly
 in each onFault() method I set *itemsLoaded.addItem(false);*

 Each time I add the boolean value to the collection, the change-event
 handler is called. Inside the change handler I check to see whether the
 collection length is equal to the number of results I'm expecting. If it is,
 I loop through the collection and check if all the values are true or not.



 




-- 
Therefore, send not to know For whom the bell tolls. It tolls for thee.

:: Josh 'G-Funk' McDonald
:: 0437 221 380 :: [EMAIL PROTECTED]


Re: [flexcoders] Design Patters For Loading Data?

2008-08-12 Thread Simon Bailey

Nice touch Josh, like it, props!

On 12 Aug 2008, at 13:07, Josh McDonald wrote:


This is pretty ordinary, and I plan on re-vamping it, but we're  
planning on open sourcing most of this stuff soon, so you might as  
well have a look and you can use it as a base for something better: http://www.gfunk007.com/flex/ChainLoader.as


Usage example:

new ChainLoader(Application.application.spinner,  
begin).then(

Application.application, showLoading).then(
Singletons.services.returnCentreDao,  
getReturnCentre).thenOnSuccess(
Singletons.services.vehiclesDao,  
getVehiclesPending).thenOnSuccess(
Singletons.services.vehiclesDao,  
getVehiclesInStock).thenOnSuccess(
Singletons.services.vehiclesDao,  
getVehiclesInRepair).thenOnSuccess(
Singletons.services.tenderDao,  
getAllTenders).thenOnSuccess(

this, selectDefaultTender).then(
this, getTenderVehicles).thenOnSuccess(
_pollTimer, start).then(
this, selectReturnCentreCompleted).then(
Application.application, hideLoading).then(
Application.application.spinner, end).go();

Like I said, it's rough don't bother telling me the myriad ways it can  
be better, I know :)


-Josh

On Tue, Aug 12, 2008 at 9:46 PM, Simon Bailey  
[EMAIL PROTECTED]wrote:
How about defining and array with all the method names and every time  
a method is returned it removes its method name from the array.  The  
method to remove each item from the array would check the array length  
each times its called and when the array.length == 0 then call your  
method x?


Cheers,

Simon

newtriks.com

On 12 Aug 2008, at 12:37, nwebb wrote:


Hi, hoping for some help on this...

Problem:
I am making multiple asynchronous calls to the server and I want to  
ensure I have the data back from all the calls before calling method x.
I don't want to daisy-chain the calls (i.e.having to wait until  
service#1 reurns data before calling service#2 and so on).


I have a solution which will suffice* but I'm sure there must be a  
tried and tested way of handling this kind of scenario - perhaps a  
design pattern(?).


---
* my current solution is to declare an ArrayCollection and listen to  
its CollectionEvent.COLLECTION_CHANGE event.
In each onResult() method I set itemsLoaded.addItem(true); and  
similarly in each onFault() method I set itemsLoaded.addItem(false);


Each time I add the boolean value to the collection, the change-event  
handler is called. Inside the change handler I check to see whether  
the collection length is equal to the number of results I'm expecting.  
If it is, I loop through the collection and check if all the values  
are true or not.







--
Therefore, send not to know For whom the bell tolls. It tolls for  
thee.


:: Josh 'G-Funk' McDonald
:: 0437 221 380 :: [EMAIL PROTECTED]





Re: [flexcoders] Design Patters For Loading Data?

2008-08-12 Thread DannyT
Very neat, but does this have a variant whereby these calls can be made at
the same time? Looks like this (as the name suggests) daisy chains the calls
firing one after the other rather than calling them all and monitoring all
of the results and notifying when all are successfully called.

Like the impelementation for subsequent result dependent calls though :)

2008/8/12 Josh McDonald [EMAIL PROTECTED]

   This is pretty ordinary, and I plan on re-vamping it, but we're planning
 on open sourcing most of this stuff soon, so you might as well have a look
 and you can use it as a base for something better:
 http://www.gfunk007.com/flex/ChainLoader.as

 Usage example:

 new ChainLoader(Application.application.spinner, begin).then(
 Application.application, showLoading).then(
 Singletons.services.returnCentreDao,
 getReturnCentre).thenOnSuccess(
 Singletons.services.vehiclesDao,
 getVehiclesPending).thenOnSuccess(
 Singletons.services.vehiclesDao,
 getVehiclesInStock).thenOnSuccess(
 Singletons.services.vehiclesDao,
 getVehiclesInRepair).thenOnSuccess(
 Singletons.services.tenderDao,
 getAllTenders).thenOnSuccess(
 this, selectDefaultTender).then(
 this, getTenderVehicles).thenOnSuccess(
 _pollTimer, start).then(
 this, selectReturnCentreCompleted).then(
 Application.application, hideLoading).then(
 Application.application.spinner, end).go();

 Like I said, it's rough don't bother telling me the myriad ways it can be
 better, I know :)

 -Josh

 On Tue, Aug 12, 2008 at 9:46 PM, Simon Bailey [EMAIL PROTECTED]wrote:

  How about defining and array with all the method names and every time a
 method is returned it removes its method name from the array.  The method to
 remove each item from the array would check the array length each times its
 called and when the array.length == 0 then call your method x?
 Cheers,

 Simon
 **
 newtriks.com http://www.newtriks.com/

 On 12 Aug 2008, at 12:37, nwebb wrote:


 Hi, hoping for some help on this...
 *
 Problem*:
 I am making multiple asynchronous calls to the server and I want to ensure
 I have the data back from *all* the calls before calling method x.
 I don't want to daisy-chain the calls (i.e.having to wait until service#1
 reurns data before calling service#2 and so on).

 I have a solution which will suffice* but I'm sure there must be a tried
 and tested way of handling this kind of scenario - perhaps a design
 pattern(?).

 ---
 * my current solution is to declare an ArrayCollection and listen to its
 CollectionEvent.COLLECTION_CHANGE event.
 In each onResult() method I set* itemsLoaded.addItem(true);* and
 similarly in each onFault() method I set *itemsLoaded.addItem(false);*

 Each time I add the boolean value to the collection, the change-event
 handler is called. Inside the change handler I check to see whether the
 collection length is equal to the number of results I'm expecting. If it is,
 I loop through the collection and check if all the values are true or not.






 --
 Therefore, send not to know For whom the bell tolls. It tolls for thee.

 :: Josh 'G-Funk' McDonald
 :: 0437 221 380 :: [EMAIL PROTECTED]
  




-- 
http://danny-t.co.uk


Re: [flexcoders] Design Patters For Loading Data?

2008-08-12 Thread Sefi Ninio
I agree, Cairngorm is perfect for this, especially when using the
UniversalMind Cairngorm extension.
UM lets you define an array of remote calls (event-command pairs) which can
be sequence or parallel execution, and once all the remote calls are
finished, you get a notification.
Sounds like exactly what you need.

Lemme know if you need more details, I've spent some time making sense of
how to use it.

HTH
Sefi

On Tue, Aug 12, 2008 at 4:21 PM, DannyT [EMAIL PROTECTED] wrote:

   Very neat, but does this have a variant whereby these calls can be made
 at the same time? Looks like this (as the name suggests) daisy chains the
 calls firing one after the other rather than calling them all and monitoring
 all of the results and notifying when all are successfully called.

 Like the impelementation for subsequent result dependent calls though :)

 2008/8/12 Josh McDonald [EMAIL PROTECTED]

This is pretty ordinary, and I plan on re-vamping it, but we're
 planning on open sourcing most of this stuff soon, so you might as well have
 a look and you can use it as a base for something better:
 http://www.gfunk007.com/flex/ChainLoader.as

 Usage example:

 new ChainLoader(Application.application.spinner,
 begin).then(
 Application.application, showLoading).then(
 Singletons.services.returnCentreDao,
 getReturnCentre).thenOnSuccess(
 Singletons.services.vehiclesDao,
 getVehiclesPending).thenOnSuccess(
 Singletons.services.vehiclesDao,
 getVehiclesInStock).thenOnSuccess(
 Singletons.services.vehiclesDao,
 getVehiclesInRepair).thenOnSuccess(
 Singletons.services.tenderDao,
 getAllTenders).thenOnSuccess(
 this, selectDefaultTender).then(
 this, getTenderVehicles).thenOnSuccess(
 _pollTimer, start).then(
 this, selectReturnCentreCompleted).then(
 Application.application, hideLoading).then(
 Application.application.spinner, end).go();

 Like I said, it's rough don't bother telling me the myriad ways it can be
 better, I know :)

 -Josh

 On Tue, Aug 12, 2008 at 9:46 PM, Simon Bailey [EMAIL PROTECTED]wrote:

  How about defining and array with all the method names and every time a
 method is returned it removes its method name from the array.  The method to
 remove each item from the array would check the array length each times its
 called and when the array.length == 0 then call your method x?
 Cheers,

 Simon
 **
 newtriks.com http://www.newtriks.com/

 On 12 Aug 2008, at 12:37, nwebb wrote:


 Hi, hoping for some help on this...
 *
 Problem*:
 I am making multiple asynchronous calls to the server and I want to
 ensure I have the data back from *all* the calls before calling method
 x.
 I don't want to daisy-chain the calls (i.e.having to wait until service#1
 reurns data before calling service#2 and so on).

 I have a solution which will suffice* but I'm sure there must be a tried
 and tested way of handling this kind of scenario - perhaps a design
 pattern(?).

 ---
 * my current solution is to declare an ArrayCollection and listen to its
 CollectionEvent.COLLECTION_CHANGE event.
 In each onResult() method I set* itemsLoaded.addItem(true);* and
 similarly in each onFault() method I set *itemsLoaded.addItem(false);*

 Each time I add the boolean value to the collection, the change-event
 handler is called. Inside the change handler I check to see whether the
 collection length is equal to the number of results I'm expecting. If it is,
 I loop through the collection and check if all the values are true or not.






 --
 Therefore, send not to know For whom the bell tolls. It tolls for thee.

 :: Josh 'G-Funk' McDonald
 :: 0437 221 380 :: [EMAIL PROTECTED]




 --
 http://danny-t.co.uk
  



Re: [flexcoders] Design Patters For Loading Data?

2008-08-12 Thread nwebb
Thanks all.

I normally use Cairngorm but it's overkill for an application of this size.
I will check out the UniversalMind extension though - sounds good.

@Josh - looks cool. Not looking for a sequential loader, but still ... :)

@Johannes - yes, an improvement, thanks



Thanks for all the feedback.






On Tue, Aug 12, 2008 at 4:55 PM, Sefi Ninio [EMAIL PROTECTED] wrote:

   I agree, Cairngorm is perfect for this, especially when using the
 UniversalMind Cairngorm extension.
 UM lets you define an array of remote calls (event-command pairs) which can
 be sequence or parallel execution, and once all the remote calls are
 finished, you get a notification.
 Sounds like exactly what you need.

 Lemme know if you need more details, I've spent some time making sense of
 how to use it.

 HTH
 Sefi


 On Tue, Aug 12, 2008 at 4:21 PM, DannyT [EMAIL PROTECTED] wrote:

   Very neat, but does this have a variant whereby these calls can be made
 at the same time? Looks like this (as the name suggests) daisy chains the
 calls firing one after the other rather than calling them all and monitoring
 all of the results and notifying when all are successfully called.

 Like the impelementation for subsequent result dependent calls though :)

 2008/8/12 Josh McDonald [EMAIL PROTECTED]

This is pretty ordinary, and I plan on re-vamping it, but we're
 planning on open sourcing most of this stuff soon, so you might as well have
 a look and you can use it as a base for something better:
 http://www.gfunk007.com/flex/ChainLoader.as

 Usage example:

 new ChainLoader(Application.application.spinner,
 begin).then(
 Application.application, showLoading).then(
 Singletons.services.returnCentreDao,
 getReturnCentre).thenOnSuccess(
 Singletons.services.vehiclesDao,
 getVehiclesPending).thenOnSuccess(
 Singletons.services.vehiclesDao,
 getVehiclesInStock).thenOnSuccess(
 Singletons.services.vehiclesDao,
 getVehiclesInRepair).thenOnSuccess(
 Singletons.services.tenderDao,
 getAllTenders).thenOnSuccess(
 this, selectDefaultTender).then(
 this, getTenderVehicles).thenOnSuccess(
 _pollTimer, start).then(
 this, selectReturnCentreCompleted).then(
 Application.application, hideLoading).then(
 Application.application.spinner, end).go();

 Like I said, it's rough don't bother telling me the myriad ways it can be
 better, I know :)

 -Josh

 On Tue, Aug 12, 2008 at 9:46 PM, Simon Bailey [EMAIL PROTECTED]wrote:

  How about defining and array with all the method names and every time a
 method is returned it removes its method name from the array.  The method 
 to
 remove each item from the array would check the array length each times its
 called and when the array.length == 0 then call your method x?
 Cheers,

 Simon
 **
 newtriks.com http://www.newtriks.com/

 On 12 Aug 2008, at 12:37, nwebb wrote:


 Hi, hoping for some help on this...
 *
 Problem*:
 I am making multiple asynchronous calls to the server and I want to
 ensure I have the data back from *all* the calls before calling method
 x.
 I don't want to daisy-chain the calls (i.e.having to wait until
 service#1 reurns data before calling service#2 and so on).

 I have a solution which will suffice* but I'm sure there must be a tried
 and tested way of handling this kind of scenario - perhaps a design
 pattern(?).

 ---
 * my current solution is to declare an ArrayCollection and listen to its
 CollectionEvent.COLLECTION_CHANGE event.
 In each onResult() method I set* itemsLoaded.addItem(true);* and
 similarly in each onFault() method I set *itemsLoaded.addItem(false);*

 Each time I add the boolean value to the collection, the change-event
 handler is called. Inside the change handler I check to see whether the
 collection length is equal to the number of results I'm expecting. If it 
 is,
 I loop through the collection and check if all the values are true or not.






 --
 Therefore, send not to know For whom the bell tolls. It tolls for thee.

 :: Josh 'G-Funk' McDonald
 :: 0437 221 380 :: [EMAIL PROTECTED]




 --
 http://danny-t.co.uk


  



Re: [flexcoders] Design Patters For Loading Data?

2008-08-12 Thread Troy Gilbert
Check out BulkLoader: http://code.google.com/p/bulk-loader/

It's designed for doing exactly this, as well as handling a lot of
other common cases (like loading SWF, images, etc. and automatically
returning the DisplayObject, etc.). It includes accumulated progress
information, etc. Pretty complete solution for what you're looking for
(and active discussion group).

Troy.


Re: [flexcoders] Design Patters For Loading Data?

2008-08-12 Thread Johannes Nel
nice

On Tue, Aug 12, 2008 at 8:20 PM, Troy Gilbert [EMAIL PROTECTED]wrote:

   Check out BulkLoader: http://code.google.com/p/bulk-loader/

 It's designed for doing exactly this, as well as handling a lot of
 other common cases (like loading SWF, images, etc. and automatically
 returning the DisplayObject, etc.). It includes accumulated progress
 information, etc. Pretty complete solution for what you're looking for
 (and active discussion group).

 Troy.
  




-- 
j:pn
\\no comment


Re: [flexcoders] Design Patters For Loading Data?

2008-08-12 Thread neilwebb

Fantasic. Thanks.


On 12 Aug 2008, at 19:20, Troy Gilbert [EMAIL PROTECTED] wrote:


Check out BulkLoader: http://code.google.com/p/bulk-loader/

It's designed for doing exactly this, as well as handling a lot of
other common cases (like loading SWF, images, etc. and automatically
returning the DisplayObject, etc.). It includes accumulated progress
information, etc. Pretty complete solution for what you're looking for
(and active discussion group).

Troy.