Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


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

Pages: [1]
Print
Author Topic: About code structure  (Read 5276 times)
badoumba
Newbie
*
Posts: 8


View Profile Email
« on: November 09, 2011, 11:24:14 »

Very quick and simple question.

What's the best practice if I have a variable that will be used by many mediators and skins and that I don't want to duplicate (a Matrix value). Should I place it in the facade?

Thanks
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: November 10, 2011, 09:46:03 »

Don't store it on the Facade. That's the sort of thing that leads to Singletons having a bad reputation.

Instead, store it in a "transient Proxy". An instance of the framework Proxy class just used to hold an arbitrary value.

Inside a PrepareViewCommand (or the 'view prep phase' of StartupCommand)

:
// Store the Matrix
var matrix:Matrix = new Matrix();
var matrixProxy:Proxy = new Proxy( AppConstants.MATRIX, matrix );
// Register Mediators...

Inside each Mediator that needs a reference to this matrix :
:
protected var matrixProxy:IProxy;
override public function onRegister():void
{
   matrixProxy = facade.retrieveProxy(AppConstants.MATRIX);
   matrixNeedingComponent = matrixProxy.getData() as Matrix;
}

protected function get matrixNeedingComponent():MatrixNeedingComponent
{
   return viewComponent as MatrixNeedingComponent;
}
If there are a lot of these mediators, you might consider making an AbstractMediator they inherit from and call super.onRegister() from your subclasses to get the matrix proxy.


Inside a Command that needs to reference the Matrix

:
 var matrixProxy:IProxy = facade.retrieveProxy(AppConstants.MATRIX);
  var matrix:Matrix = matrixProxy.getData() as Matrix;

   // do stuff with the matrix
« Last Edit: November 10, 2011, 09:49:17 by puremvc » Logged
Pages: [1]
Print