|
|
Show Posts
|
Pages: 1 ... 8 9 [10]
|
138
|
Announcements and General Discussion / General Discussion / Re: first project with pureMVC
|
on: January 30, 2008, 03:43:18
|
Cliff /Daniele /others
Following on Cliff's comments, I have been thinking about this utility/demo suggestion and whether I should offer to contribute. So, if you like, I would be willing to go ahead and... 1. package the relevant classes into a separate utility, with class level comments to explain usage 2. create a simple demo app to use this utility and show off the dependency feature.
Utility... I could package this using my own company naming e.g. com.xyz.utils...., but I presume we want a generic naming so that more utilities can be added, code can be modified etc. What about org.puremvc.forums as the base package? Then we could have <base>.utils and <base>.demos as the next levels. I'm new to this, so maybe I'm missing the point, or maybe I've missed some posts regarding this.
Anyway, for this case, say we have <base>.utils.startupWithDependencies. The relevant classes (3 I believe) could then sit directly in that package, or do we prefer sub-folders for controller and model?
Is startupMonitor a better name for the utility? - I am avoiding this because I don't want to present this as the only startup solution.
Demo... This would be packaged as <base>.demos.startupWithDependencies, with sub-folders for model/view/controller. A demo app does not have to have the same name as a utility, of course, though I propose it in this case.
Finally I would zip all this to Cliff, with a .swf for the app, and presumably a .swc for the utility. This code could then be enhanced (or ignored!), by others.
I am very aware that all I've done is adapt code originally created by daniele and meekgeek, and use daniele's ApplicationSkeleton demo as a reference. So, if anyone else would like to take the lead on one or both of these items, that is fine by me.
Regards Philip
|
|
|
139
|
Announcements and General Discussion / General Discussion / Re: first project with pureMVC
|
on: January 28, 2008, 09:23:47
|
Thanks to Cliff for Puremvc and for these forums etc., and to danieleUg and to meekgeek for the StartupMonitorProxy solution, as implemented in the ApplicationSkeleton code.
My application requires a more powerful method of sequencing the loading of data resources at startup. Specifically, I want to be able to specify that a resource cannot be loaded until specific other resources have been loaded. The dependencies are such that use of the blockChain boolean on the resource would result in sub-optimal loading, in that loading of some resources would be unnecessarily delayed.
I am presenting the basics of my code here, in case it is of interest to others.
My resource is called StartupResource, as follows.
package com...model { /* * From original code of Daniele Ugoletti and Meekgeek * on the puremvc forums, modified to use 'requires' instead * of blocking boolean. Also have a multi-valued status instead * of a 'loaded' boolean. * * @author Philip Sexton * @since 11.01.2008 */ public class StartupResource { private static const EMPTY :int = 1; private static const LOADING :int = 2; private static const LOADED :int = 3;
public var proxyName:String;
private var status :int;
// StartupResources, pre-requisites for this resource, if any. // These pre-requisites must be loaded before this resource can be loaded. private var _requires :Array; public function StartupResource( proxyName:String ) { this.proxyName = proxyName; this.status = EMPTY; this.requires = new Array(); } public function setStatusToLoading() :void { status = LOADING; } public function setStatusToLoaded() :void { status = LOADED; } public function isLoaded() :Boolean { return status == LOADED; } public function set requires( resources :Array ) :void { _requires = resources; } public function get requires() :Array { return _requires; } public function isOkToLoad() :Boolean { if ( status != EMPTY ) return false; for( var i:int =0; i < requires.length; i++) { if ( ! (requires[i] as StartupResource).isLoaded() ) return false; } return true; } }
}
StartupMonitorProxy is as follows. Note that method addResource() is not called from the individual resource proxies; it is called from the startup command. In fact, the individual resource proxies contain no code specific to the startup monitor.
package com...model { import org.puremvc.interfaces.*; import org.puremvc.patterns.proxy.Proxy; import com...model.StartupResource;
/* * A proxy for the startup loading process. * From original code of Daniele Ugoletti and Meekgeek * on the puremvc forums, modified to use a StartupResource * designed to cater for more complex constraints. * * @author Philip Sexton * @since 11.01.2008 */ public class StartupMonitorProxy extends Proxy implements IProxy { public static const NAME:String = "StartupMonitorProxy"; // array listing all the resources to be loaded private var resourceList:Array; //---- total resource to read //-----private var totalResources:int = 0; // number of loaded resources private var loadedResources:int = 0; public function StartupMonitorProxy ( data:Object = null ) { super ( NAME, data ); this.resourceList = new Array(); } /** * Add a resource to be loaded */ public function addResource( r :StartupResource ):void { this.resourceList.push( r ); } /** * Start/Continue to load all resources */ public function loadResources():void { for( var i:int = 0; i < this.resourceList.length; i++) { var r:StartupResource = this.resourceList[i] as StartupResource; if ( r.isOkToLoad() ) { var proxy:* = facade.retrieveProxy( r.proxyName ) as Proxy; r.setStatusToLoading(); proxy.load(); } } } /** * The resource is loaded, update the state and check if the loading process is completed * * @param name proxy name */ public function resourceLoaded( proxyName :String ):void { for( var i:int = 0; i < this.resourceList.length; i++) { var r:StartupResource = this.resourceList[i] as StartupResource; if ( r.proxyName == proxyName ) { r.setStatusToLoaded(); this.loadedResources++;
// send the notification for update the progress bar //this.sendNotification( ApplicationFacade.LOADING_STEP, this.resourceList.length / this.loadedReources * 100 );
// if not all loaded, continue load. if ( !allResourcesLoaded() ) { this.loadResources(); } break; } }
} /** * Check if the loading process is completed * * @return boolean process is completed */ private function allResourcesLoaded():Boolean { for( var i:int = 0; i < this.resourceList.length; i++) { var r:StartupResource = this.resourceList[i] as StartupResource; if ( !r.isLoaded() ) { return false; } } //this.sendNotification( ApplicationFacade.LOADING_COMPLETE ); return true; } } }
The StartupCommand has code as follows, here presented in pseudo-code.
public class StartupCommand extends SimpleCommand implements ICommand {
private var monitor :StartupMonitorProxy;
override public function execute( note:INotification ) : void {
facade.registerProxy( new StartupMonitorProxy() ); this.monitor = facade.retrieveProxy( StartupMonitorProxy.NAME ) as StartupMonitorProxy; ... register other proxies ...
var rA :StartupResource = makeAndRegisterStartupResource( ProxyA.NAME ); var rB :StartupResource = makeAndRegisterStartupResource( ProxyB.NAME ); var rC :StartupResource = makeAndRegisterStartupResource( ProxyC.NAME ); var rD :StartupResource = makeAndRegisterStartupResource( ProxyD.NAME ); var rE :StartupResource = makeAndRegisterStartupResource( ProxyE.NAME ); var rF :StartupResource = makeAndRegisterStartupResource( ProxyF.NAME ); var rG :StartupResource = makeAndRegisterStartupResource( ProxyG.NAME ); var rH :StartupResource = makeAndRegisterStartupResource( ProxyH.NAME );
rC.requires = [ rA, rB ]; rD.requires = [ rC ]; rE.requires = [ rD ]; rH.requires = [ rE, rF, rG ]; monitor.loadResources();
... register mediator(s) ... } private function makeAndRegisterStartupResource( proxyName :String ) :StartupResource { var r :StartupResource = new StartupResource( proxyName ); monitor.addResource( r ); return r; } }
With the completion of each resource load, in the proxy/responder objects, a 'loaded' notification specific to the resource is sent. All such notifications are handled by a StartupResourceLoadedCommand. The application facade has registered this command against each of the notifications. The command code is as follows.
public class StartupResourceLoadedCommand extends SimpleCommand {
/** * Inform the startup monitor that a resource is now loaded. * The notification body identifies the particular resource. */ override public function execute( note:INotification ) : void { ( facade.retrieveProxy( StartupMonitorProxy.NAME ) as StartupMonitorProxy). resourceLoaded( note.getBody() as String ); } }
I hope the above makes sense. Some people may think it unnecessary. Any comments are welcome.
Thank you Philip
|
|
|
|
|