Skip navigation
Currently Being Moderated

Lazy Loading Modules

Jul 15, 2010 8:31 AM

Hello,

 

I have a project that uses Cairngorm 3 and am trying to implement a solution that loads modules on demand based on navigation events.  I am using version 0.8 of the Module library with Flex 3.5.

 

In my case however the list of modules to eventually be loaded is determined at runtime.  After a login event fires a list of modules is determined.  For each module a ParsleyModuleInfo object is created and initialized and added to a collection.  This collection is then used as a data provider to a repeater which is a child of a view stack.  The repeater has one child which is a subclass of ViewLoader.  When the repeater repeats the automationName and info properties are populated from the data provider.

 

Using this approach however for dynamically adding modules causes all modules to be downloaded and initialized.  I'd much rather prefer to have modules loaded only when an appropriate navigation event is fired.  I've read that the Navigation and Module libraries support lazy loading but am just unsure how to make use of it since my case is unique.

 
Replies
  • Currently Being Moderated
    Jul 15, 2010 9:24 AM   in reply to Anthony.R

    Hi,

     

    First of all I would really encourage you to migrate to the latest version of the Module Library which is version 0.11 as since version 0.10 we fixed a major issue in how styling get inherited in the modules.

     

    Now concerning the ability to lazy load the module you can have a look at the ModuleTest project available here http://opensource.adobe.com/svn/opensource/cairngorm3/trunk/libraries/ ModuleTest/

     

    In there you will see that we dispatch a message called "PingMessage" thru the parsley dispatcher which contains a [ModuleId] Metadata. The moduleId defines a unique instance of a module. If you set the moduleId to the ViewLoader and specify the same moduleId in the message, you basically redirect the message to that specific ViewLoader.

     

    Using the ModuleId is not mandatory, if not specified, you will have to use the moduleRef property of the ModuleMessageInterceptor and therefore the message is going to be dispatched into every modules instances of that type. (eg. If you have 10 instances of ModuleA, the message is going to be dispatched to all 10)

     

    Here a little example of what need to be setup using the LazyModuleLoadPolicy :

     

    In your View:

     

    [Bindable]
    public var moduleManager:IModuleManager;
     
    [Bindable]
    [Inject(id="lazyLoadPolicy")]
    public var lazyLoadPolicy:ILoadPolicy;
     
    

    ...

    <cairngorm:ViewLoader id="moduleLoader"
         moduleId="myModuleId123"
         moduleManager="{ moduleManager }"
         loadPolicy="{ lazyLoadPolicy }"/>
    
    

     

    In your Parsley Context:

     

    To link the PingMessage to the LazyModuleLoadPolicy that is injected to your ViewLoader:

    <cg:LazyModuleLoadPolicyTag objectId="lazyLoadPolicy" type="{ PingMessage }" />
    
    

     

    To register the PingMessage as an inter-communcation message that need to travel to a module:

    <cg:ModuleMessageInterceptor
         type="{ PingMessage }" />
    
    

     

    The message (PingMessage):

    public class PingMessage
    {
         private var _moduleId:String;
     
         public function PingMessage(moduleId:String)
         {
              this._moduleId = moduleId;
         }
     
         [ModuleId]
         public function get moduleId():String
         {
              return _moduleId;
         }
    }
     
    

     

    You dispatch the message as follow:

    [MessageDispatcher]
    public var dispatcher:Function;
     
    ...
     
    dispatcher( new PingMessage("myModuleId123") );
     
    

     

    Hope It helps

     

    /yaniv

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 15, 2010 12:03 PM   in reply to Anthony.R

    Hello guys,

     

    I just added the missing flex3 releases.

    ...so now you'll have for Module for instance :

     

    Module for flex4(.1) :  http://opensource.adobe.com/svn/opensource/cairngorm3/maven-repository /com/adobe/cairngorm/module/0.11/

    Module for flex3(.5) : http://opensource.adobe.com/svn/opensource/cairngorm3/maven-repository /com/adobe/cairngorm/module-flex3/0.11/

     

    Cheers,

    François

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 28, 2010 12:15 AM   in reply to Anthony.R

    Hi Anthony,

     

    When we migrated the Module library to Flex SDK 4.x,  we took the opportunity to re-write the ViewLoader as a Spark component which is now named "ModuleViewLoader". This new component use the spark architecture which means that the look&feel is now separated into a Skin using states. The default skin for the ModuleViewLoader is ModuleViewLoaderSkin which can be found in the same package. If you want to change the look&feel you can create your own Skin based on the ModuleViewLoaderSkin.

     

    Now, concerning the SDK 3 ViewLoader, we decided that the ViewLoader would become a lightweight version compatible with Flex SDK 3 (and 4) that doesn't have any skinning either views such as errorView and progressView. However you can easily extends the ViewLoader to add such features if you need them or if your project is using SDK 4, I would recommend you to use ModuleViewLoader instead.

     

    I hope it clarify the difference between the ViewLoader and ModuleViewLoader ...

     

    Cheers,

    /yaniv 

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points