You will extend these classes to create all your modules.
These classes will be used to set up your application and start it. (they will also automatically initiate framework)
You can name your modules by sending moduleName to super()
constructor. (By default your modules will be named automatically: module1, module2...)
Set up and start your application by overriding onInit() function.
Module can be disposed with disposeModule() function.
Extend this class then you need place to store data and application state.
Create public functions(API) to manipulate your data and
application state, and send messages about changes. Proxy can't
listen for framework messages, only send them.
Proxies are injected in your application with help of meta-tag [Inject].
This tag must be used right in front of public
variable for proxy object.(It is injected using object Type)
It is possible to have more then one proxy with same Type by
using name. [Inject(name='myProxyName')]
Extend this class to create mediators for your view objects.
Mediators should focus only on mediating and not managing view.
Mediators get view object injected with help of meta-tag [Inject].
This tag must be used right in front of public view object variable.
Mediators can injected proxy instances with help of meta-tag [Inject]
to get needed data, but this will create dependencies. If you
want/need your view to stay independent from proxy classes - use messages instead.
Mediators also have functions to handle AS3 events better:
addListener(),
removeListener(),
removeAllListeners().
Event listeners added this way are automatically removed them mediator is removed.
Extend this class to create executable command.
Your command class must have public execute(params:Object) function. (you can change type of params object to have strong type)
Commands should be stateless - do not hold data.
Commands should do one specific job, do it well and die.
Extend this class to create executable command that will be pooled.
Pooled commands save a lot of performance if you plan to execute them a lot. (if command will be rarely used - it is better to us simple
Command.
For asynchronous commands use lock() to prevent them from automatic pooling, and unlock() then they finished there work.
You can set up your application in your module classes with onInit()
function or execute() Command classes to do the job.(Usually it's better to do it in commands, unless you have really small module.)
To set up commands use commandMap:
To use commands you will map your custom commands to message types, for them to be executed automatically then specific
message is send, or execute them directly using CommandMap object.
commandMap can be used from Modules and Commands.
Map a class to be executed then message with type provided is sent:
commandMap.map(type:String, commandClass:Class):void
Or unmap mapped class:
commandMap.unmap(type:String, commandClass:Class):void
Commands also can be executed directly, without need to map to message:
commandMap.execute(commandClass:Class, params:Object = null):void
To set up proxies use
proxylMap:
You will manually create your proxies and map them using
ProxylMap
object, it can be used from Modules and Commands.
Maps proxy object to injectClass and name.
proxyMap.map(proxyObject:
Proxy, injectClass:Class = null, name:String = ""):void
Removes proxy mapped for injection by injectClass and name.
proxyMap.unmap(proxyClass:Class, name:String = ""):void
You can also map proxies lazily:
lazyMap(proxyClass:Class, injectClass:Class = null, name:String, proxyParams:Array = null)
To set up mediators use mediatorMap:
You will map your view classes to mediator classes using
MediatorMap
object, it can be used from Modules and Commands.
Map mediator class to view class.
mediatorMap.map(viewClass:Class, mediatorClass:Class):void
Unmaps any mediator class to given view class.
mediatorMap.unmap(viewClass:Class):void
Automatically instantiate mediator class(if mapped), handles all injections(including viewObject), and calls onRegister function:
mediatorMap.mediate(viewObject:Object):void
If any mediator is mediating viewObject: it calls onRemove, automatically removes all handler functions listening for messages from that mediator and disposes it:
mediatorMap.unmediate(viewObject:Object):void
Proxies can be used in Mediator's,
Command's and other
Proxies by injecting them automatically on creation using [Inject] metadata tag.
It is injected by using object type and optional name:
[Inject(name="optionalName")]
public var myProxy:MyProxy;
Alternatively it can be done dynamically by code:
You can send messages from modules, commands, proxies and mediators framework classes, optionally send parameter object(it will be passed to handle function or commands execute() function):
sendMessage(type:String, params:Object = null):void
You can listen for messages in Mediators by adding handle function:
addHandler(type:String, handler:Function):void
Or in Mediators remove existing handle functions:removeHandler
(type:String, handler:Function):void
(Also you can use commandMap to map command class to be executed then message is sent.)
Both handler function and
execute() function in your commands must contain one
parameter!
Type of that parameter must be the same as params object sent
with sentMessage(), or you can set it to type: Object.
If you don't send any parameters with message - null
will be passed to handling function.
To get framework debug data use :
MvcExpress.debugFunction= trace;
(will work only during debug compile.)
To enable circular dependency support set pendingInjectsTimeOut value. :
MvcExpress.pendingInjectsTimeOut = 1000;
WARNING: If you just starting learning MVC stay away
from modular programming. Trust me - one module is more then
enough to do big great projects.
Even then you get a hang on MVC I would recommend starting with
only couple of modules and minimizing module to module
communication and dependencies, until you learn best practices
with Modular programming.
Before using module communication or data sharing features you need to register scope. This can be done in module class or Command:
registerScope(scopeName:String, messageSending:Boolean = true, messageReceiving:Boolean = true, proxieMap:Boolean = false):void
You can control if current module can send messages, can receive messages or can map proxies to scope with parameters.
You can also unregisterScope scope.
To send a message to another module, you will send a message to Scope. Scope is defined by
scopeName.
sendScopeMessage(scopeName:String, type:String, params:Object = null):void
Then in another module, in mediator you can handle message from Scope.
(Remove it with: removeScopeHandler(scopeName:String, type:String, handler:Function):void)
Or handle it with command:
scommandMap.scopeMap(scopeName:String, type:String, commandClass:Class):void
It is possible to share proxies in beat-wean modules.
(potentially creating module to module dependencies)
You do it by mapping proxy to scope from one module:
proxyMap.scopeMap(scopeName:String, proxyObject:Proxy, injectClass:Class = null, name:String):void
(to unmap: proxyMap.scopeUnmap(scopeName:String, injectClass:Class, name:String):void)
Then in another module you can inject proxy from Scope:
[Inject(scope="myScopeName" name="optionalName")]
public var myProxy:MyProxy;