puremvc
|
 |
« 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
|