Over 10 years of community discussion and knowledge are maintained here as a read-only archive. New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC
|
|
|
Show Posts
|
Pages: [1]
|
4
|
PureMVC Manifold / Bug Report / [UNDER CONSIDERATION] Use Array.slice(0) to copy Observers instead of a loop
|
on: February 19, 2011, 06:07:06
|
Here is the code used in View.notifyObservers() method to copy the Array we will loop over to notify observers :
public function notifyObservers( notification:INotification ) : void { if( observerMap[ notification.getName() ] != null ) { // Get a reference to the observers list for this notification name var observers_ref:Array = observerMap[ notification.getName() ] as Array;
// Copy observers from reference array to working array, // since the reference array may change during the notification loop var observers:Array = new Array(); var observer:IObserver; for (var i:Number = 0; i < observers_ref.length; i++) { observer = observers_ref[ i ] as IObserver; observers.push( observer ); }
// Notify Observers from the working array for (i = 0; i < observers.length; i++) { observer = observers[ i ] as IObserver; observer.notifyObserver( notification ); } } }
This take a lot of CPU steps for nothing and as this method is heavily used, I think we can benefit a lot from changing it to:
public function notifyObservers( notification:INotification ) : void { var observers_ref:Array = observerMap[ notification.getName() ] as Array; if( observers_ref != null ) { // Copy observers from reference array to working array, // since the reference array may change during the notification loop var observers:Array = observers_ref.slice(0);
// Notify Observers from the working array for( var i:uint = 0; i<observers.length; i++) { observer = observers[ i ] as IObserver; observer.notifyObserver( notification ); } } }
|
|
|
12
|
Announcements and General Discussion / General Discussion / [Loadup Utility] Reference to UIComponent
|
on: September 25, 2009, 02:41:33
|
While working with the Loadup Utility I realized that the three classes AssetOfTypeImage, AssetOfTypeSwf, AssetOfTypeText, implementing IAssetForFlex all make direct references to UIComponent. It first add unwanted weight to a pure ActionScript application and probably introduce problems to compile it from Flash IDE.
The reference to this three classes is not a problem in itself as they are intended to provide helpers for Flex components.
The problem is more that even if the utility implements an Asset Factory, the class AssetTypeMap make a reference to this three concrete class instead of letting the user choose the concrete class to build.
Here is the incriminated references in AssetTypeMap
39 protected function defaultMap() :Object { 40 var obj :Object = new Object(); 41 obj[ Loadup.IMAGE_ASSET_TYPE ] = [ AssetOfTypeImage, AssetLoadByLoader ]; 42 obj[ Loadup.TEXT_ASSET_TYPE ] = [ AssetOfTypeText, AssetLoadByURLLoader ]; 43 obj[ Loadup.SWF_ASSET_TYPE ] = [ AssetOfTypeSwf, AssetLoadByLoader ]; 44 return obj; 45 }
To be honest, now, I don't have much time to explore this deeper. For my current needs, I simply modified the AssetTypeMap class to initialize its constructor with my own "defaultMap" which did not contains any UIcomponent reference.
But I'm sure we can do it better with a good implementation of an Abstract Factory where only the user create the client class which will decide to use or not use the UIComponent in the assets it needs.
|
|
|
13
|
Announcements and General Discussion / General Discussion / Non-visual module used as core in multicore
|
on: September 15, 2009, 08:00:13
|
I often have the same problem. I need to use a connection protocol or a specific type of server that requires me to have a group of 3 or 4 proxies to manage each type of connection to do near the same thing. I have to use alternatively one or another type of server in different build of the same app.
I have no problem to implement the same interface in my different proxies type, use the same commands when needed and decide which type of proxies and command to use when registering command/proxies. But I find more elegant not to have to worry about the two different proxies type simultaneously in the same project, even if I separate them into different packages. A native implementation of the IOC in PureMVC here would have probably been the solution to my problem. But I'm afraid that looking into and using Spring ActionScript for PureMVC or another solution take me too long for the project I'm working on.
So I wonder if this might be a good practice to create a core that would have no visual elements at all. Only a mediator for the application class, a group of 3 or 4 proxies and at most one state machine to manage the connection / disconnection when it is persistent one. Pipes literally controlling the module from the shell and other modules, even if I have some basic controller for initialization ?
|
|
|
|
|
|