Packagecom.soma.core.mediator
Classpublic class Mediator
InheritanceMediator Inheritance Wire Inheritance Object
Implements IMediator

Author: Romuald Quantin - www.soundstep.com

Resources: http://www.soundstep.com/downloads/somacore

Actionscript version: 3.0

Copyright: Mozilla Public License 1.1 (MPL 1.1) http://www.opensource.org/licenses/mozilla1.1.php

A Mediator is a class that extends a wire and has a relation one-to-one with a view. A mediator can be created with the injection enabled or disabled.

The first step is to map a view class to a mediator class, and everytime a view is added to a display list, a mediator for this view is automatically instantiated by the framework.

The mediator instance will automatically be destroyed by the framework when the view it represents will be removed from the display list.

View the examples

See also

com.soma.core.mediator.SomaMediators
com.soma.core.interfaces.IMediator
com.soma.core.wire.Wire
com.soma.core.wire.SomaWires


Public Properties
 PropertyDefined By
 Inheritedinjector : ISomaInjector
[read-only]
Wire
 Inheritedinstance : ISoma
Retrieves the instance of the framework.
Wire
 Inheritedmediators : SomaMediators
[read-only]
Wire
 Inheritedstage : Stage
[read-only] Get the stage that has been registered to the framework.
Wire
  viewComponent : Object
View that has been mapped to the mediator instance.
Mediator
Protected Properties
 PropertyDefined By
 Inherited_name : String
Name of the wire.
Wire
  _viewComponent : Object
View that has been mapped to the mediator instance.
Mediator
Public Methods
 MethodDefined By
  
Mediator(name:String = null)
Create an instance of a Mediator class.
Mediator
 Inherited
addCommand(commandName:String, command:Class):void
Registers a command to the framework.
Wire
 Inherited
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
Registers an event listener object with an EventDispatcher object so that the listener receives notification of an event.
Wire
 Inherited
addModel(modelName:String, model:IModel):IModel
Registers a model to the framework.
Wire
 Inherited
addView(viewName:String, view:Object):Object
Registers a view to the framework.
Wire
 Inherited
addWire(wireName:String, wire:IWire):IWire
Registers a wire to the framework.
Wire
  
Method that can you can override, called when if the view is part of the Flex Framework (not used for a pure AS3 view).
Mediator
 Inherited
dispatchEvent(event:Event):Boolean
Dispatches an event into the event flow.
Wire
 Inherited
dispose():void
Method that can you can override, called when the wire has been removed from the framework.
Wire
 Inherited
getCommand(commandName:String):Class
Retrieves the command class that has been registered with a command name.
Wire
 Inherited
getCommands():Array
Retrieves all the command names (event type) that have been registered to the framework.
Wire
 Inherited
Retrieves the last sequence command that has been instantiated in the framework.
Wire
 Inherited
getModel(modelName:String):IModel
Retrieves the model instance that has been registered using its name.
Wire
 Inherited
getModels():Dictionary
Retrieves all the model instances that have been registered to the framework.
Wire
 Inherited
getName():String
Retrieves the name of the wire.
Wire
 Inherited
Retrieves all the sequence command instances that are running.
Wire
 Inherited
Retrieves the sequence command instance using an event instance that has been created from this sequence command.
Wire
 Inherited
getView(viewName:String):Object
Retrieves the view instance that has been registered using its name.
Wire
 Inherited
getViews():Dictionary
Retrieves all the view instances that have been registered to the framework.
Wire
 Inherited
getWire(wireName:String):IWire
Retrieves the wire instance that has been registered using its name.
Wire
 Inherited
getWires():Dictionary
Retrieves all the wire instances that have been registered to the framework.
Wire
 Inherited
hasCommand(commandName:String):Boolean
Indicates wether a command has been registered to the framework.
Wire
 Inherited
hasEventListener(type:String):Boolean
Checks whether the EventDispatcher object has any listeners registered for a specific type of event.
Wire
 Inherited
hasModel(modelName:String):Boolean
Indicates wether a model has been registered to the framework.
Wire
 Inherited
hasView(viewName:String):Boolean
Indicates wether a view has been registered to the framework.
Wire
 Inherited
hasWire(wireName:String):Boolean
Indicates wether a wire has been registered to the framework.
Wire
 Inherited
initialize():void
Method that can you can override, called when the wire has been registered to the framework.
Wire
 Inherited
isPartOfASequence(event:Event):Boolean
Indicates wether an event has been instantiated from a ISequenceCommand class.
Wire
 Inherited
Wire
 Inherited
removeCommand(commandName:String):void
Removes a command from the framework.
Wire
 Inherited
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
Removes a listener from the EventDispatcher object.
Wire
 Inherited
removeModel(modelName:String):void
Removes a model from the framework and call the dispose method of this model.
Wire
 Inherited
removeView(viewName:String):void
Removes a view from the framework and call the (optional) dispose method of this view.
Wire
 Inherited
removeWire(wireName:String):void
Removes a wire from the framework and call the dispose method of this wire.
Wire
 Inherited
setName(name:String):void
Sets the name of the wire.
Wire
 Inherited
Stops all the sequence command instances that are running.
Wire
 Inherited
stopSequencer(sequencer:ISequenceCommand):Boolean
Stops a sequence command using the sequence command instance itself.
Wire
 Inherited
stopSequencerWithEvent(event:Event):Boolean
Stops a sequence command using an event instance that has been created from this sequence command.
Wire
 Inherited
willTrigger(type:String):Boolean
Checks whether an event listener is registered with this EventDispatcher object or any of its ancestors for the specified event type.
Wire
Property Detail
_viewComponentproperty
protected var _viewComponent:Object

View that has been mapped to the mediator instance.

viewComponentproperty 
viewComponent:Object

View that has been mapped to the mediator instance.


Implementation
    public function get viewComponent():Object
    public function set viewComponent(value:Object):void
Constructor Detail
Mediator()Constructor
public function Mediator(name:String = null)

Create an instance of a Mediator class. The Mediator class should be extended and is usually automatically created (and removed) by the framework.

Parameters
name:String (default = null) — Name of the wire.
Method Detail
creationComplete()method
public function creationComplete():void

Method that can you can override, called when if the view is part of the Flex Framework (not used for a pure AS3 view).

Examples
Map a view class to a mediator class
package {
    import com.soma.core.interfaces.IMediator;
    import com.soma.core.mediator.Mediator;
    public class MyViewMediator extends Mediator implements IMediator {
        
        [Inject]
        public var myView:MyView;
        
        override public function initialize():void {
            // called when the mediator has been created and registered to the framework
            trace(myView == viewComponent);
        }
        
        override public function dispose():void {
            // called when the mediator has been destroyed by the framework
        }
        
    }
}
     
Map a mediator class to a view class.
mediators.mapView(MyView, MyViewMediator);
     
Remove mapping.
mediators.removeMapping(MyView);
     
Retrieve a mediator.
var mediator:MyViewMediator = mediators.getMediatorByView(view) as MyViewMediator;
     
Trigger the creation of a mediator by adding a view to the display list.
mediators.mapView(MyView, MyViewMediator);
var view:MyView = new MyView();
myDisplayObjectContainer.addChild(view);
// mediator instance created
var mediator:MyViewMediator = mediators.getMediatorByView(view) as MyViewMediator;
trace(mediators.hasMediator(view));