Welcome to mvcExpress documentation! v2.0.rc3


  package Description
  mvcexpress
  mvcexpress.core
  mvcexpress.core.interfaces
  mvcexpress.core.messenger
  mvcexpress.modules
  mvcexpress.mvc
  mvcexpress.utils

Quick summary of framework classes and functions:


Framework classes you will work with:


ModuleCore:

You will use this class to create all your modules.
This class will be used to set up your application and start it. (it will 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.

Proxy:

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')]

Mediator:

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.

Command:

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.

PooledCommand:

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.



Set Up:

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, injectClass:Class = null, ... restClassPairs:Array):void

Unmaps any mediator class to given view class.
mediatorMap.unmap(viewClass:Class, mediatorClass:Class = null):void


Then view and mediator pairs are mapped you can start mediating view object. It can be done from Modules, Commands and Mediators:

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, mediatorClass:Class = null):void


You can also mediate view object without mapping it first to Mediator class. Sometimes it is needed:

mediatorMap.mediateWith(viewObject:Object, mediatorClass:Class, injectClass:Class = null):void


Getting proxies:

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:

getProxy(injectClass:Class, name:String = ""):Proxy


Communication:

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.


MvcExpress:

You can use MvcExpress.as to change global settings of how framework works.

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;