| Package | com.soma.core |
| Class | public class Soma |
| Inheritance | Soma flash.events.EventDispatcher |
| Implements | ISoma, flash.events.IEventDispatcher |
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
SomaCore is a lightweight event-based MVC framework written in AS3 that provides a structure, models, views management and commands. Somacore can be used for Flash, Flex and AIR projects. SomaCore is completely event-based and use a concept of wires to code in a efficient decoupled way. SomaCore can be used with or without dependency injection, and provide an injector adapter for the included DI library: SwiftSuspenders. You can use SomaCore in anything, except to include/distribute it in another framework, application, template, component or structure that is meant to build, scaffold or generate source files.
Few things to know:
| Property | Defined By | ||
|---|---|---|---|
| controller : SomaController [read-only]
Gets the commands manager instance. | Soma | ||
| injector : ISomaInjector [read-only]
Retrieves the injector instance that has been created by the framework from the injector Class registered. | Soma | ||
| injectorClass : Class [read-only]
Retrieves the injector Class registered to the framework. | Soma | ||
| mediators : SomaMediators [read-only]
Gets the mediator manager instance that has been created by the framework from the injector Class registered. | Soma | ||
| models : SomaModels [read-only]
Gets the model manager instance. | Soma | ||
| reflector : ISomaReflector [read-only]
Retrieves the refletor instance. | Soma | ||
| stage : Stage [read-only]
Get the stage that has been registered to the framework. | Soma | ||
| views : SomaViews [read-only]
Gets the view manager class. | Soma | ||
| wires : SomaWires [read-only]
Gets the wires manager instance. | Soma | ||
| Method | Defined By | ||
|---|---|---|---|
Soma(stage:Stage = null, injectorClass:Class = null)
Create an instance of the SomaCore class. | Soma | ||
addCommand(commandName:String, command:Class):void
Registers a command to the framework. | Soma | ||
Registers a model to the framework. | Soma | ||
addView(viewName:String, view:Object):Object
Registers a view to the framework. | Soma | ||
Registers a wire to the framework. | Soma | ||
Creates a plugin instance. | Soma | ||
Creates a plugin instance using the class name and the getDefinitionByName method. | Soma | ||
dispose():void
Destroys the SomaCore core classes and elements registered to the framework. | Soma | ||
getCommand(commandName:String):Class
Retrieves the command class that has been registered with a command name. | Soma | ||
getCommands():Array
Retrieves all the command names (event type) that have been registered to the framework. | Soma | ||
Retrieves the last sequence command that has been instantiated in the framework. | Soma | ||
Retrieves the model instance that has been registered using its name. | Soma | ||
getModels():Dictionary
Retrieves all the model instances that have been registered to the framework. | Soma | ||
getRunningSequencers():Array
Retrieves all the sequence command instances that are running. | Soma | ||
getSequencer(event:Event):ISequenceCommand
Retrieves the sequence command instance using an event instance that has been created from this sequence command. | Soma | ||
getView(viewName:String):Object
Retrieves the view instance that has been registered using its name. | Soma | ||
getViews():Dictionary
Retrieves all the view instances that have been registered to the framework. | Soma | ||
Retrieves the wire instance that has been registered using its name. | Soma | ||
getWires():Dictionary
Retrieves all the wire instances that have been registered to the framework. | Soma | ||
hasCommand(commandName:String):Boolean
Indicates wether a command has been registered to the framework. | Soma | ||
hasModel(modelName:String):Boolean
Indicates wether a model has been registered to the framework. | Soma | ||
hasView(viewName:String):Boolean
Indicates wether a view has been registered to the framework. | Soma | ||
hasWire(wireName:String):Boolean
Indicates wether a wire has been registered to the framework. | Soma | ||
isPartOfASequence(event:Event):Boolean
Indicates wether an event has been instantiated from a ISequenceCommand class. | Soma | ||
removeCommand(commandName:String):void
Removes a command from the framework. | Soma | ||
removeModel(modelName:String):void
Removes a model from the framework and call the dispose method of this model. | Soma | ||
removeView(viewName:String):void
Removes a view from the framework and call the (optional) dispose method of this view. | Soma | ||
removeWire(wireName:String):void
Removes a wire from the framework and call the dispose method of this wire. | Soma | ||
setup(stage:Stage = null, injectorClass:Class = null):void
Register elements that the frameworks needs to be ready, such as the stage and the optional injector class (default is SomaInjector). | Soma | ||
stopAllSequencers():void
Stops all the sequence command instances that are running. | Soma | ||
stopSequencer(sequencer:ISequenceCommand):Boolean
Stops a sequence command using the sequence command instance itself. | Soma | ||
stopSequencerWithEvent(event:Event):Boolean
Stops a sequence command using an event instance that has been created from this sequence command. | Soma | ||
| Method | Defined By | ||
|---|---|---|---|
initialize():void
Method that you can optionally overwrite to initialize elements before anything else. | Soma | ||
registerCommands():void
Method that you can optionally overwrite to register commands (mapping events to command classes) to the framework. | Soma | ||
registerModels():void
Method that you can optionally overwrite to register models to the framework. | Soma | ||
registerPlugins():void
Method that you can optionally overwrite to register plugins to the framework. | Soma | ||
registerViews():void
Method that you can optionally overwrite to register views to the framework. | Soma | ||
registerWires():void
Method that you can optionally overwrite to register wires to the framework. | Soma | ||
start():void
Method that you can optionally overwrite to start your own after that the framework has registered all the elements (models, views, commands, wires, plugins). | Soma | ||
| controller | property |
controller:SomaController [read-only] Gets the commands manager instance.
public function get controller():SomaController| injector | property |
injector:ISomaInjector [read-only] Retrieves the injector instance that has been created by the framework from the injector Class registered.
public function get injector():ISomaInjector| injectorClass | property |
injectorClass:Class [read-only] Retrieves the injector Class registered to the framework.
public function get injectorClass():Class| mediators | property |
mediators:SomaMediators [read-only] Gets the mediator manager instance that has been created by the framework from the injector Class registered.
public function get mediators():SomaMediators| models | property |
models:SomaModels [read-only] Gets the model manager instance.
public function get models():SomaModels| reflector | property |
reflector:ISomaReflector [read-only] Retrieves the refletor instance.
public function get reflector():ISomaReflector| stage | property |
stage:Stage [read-only] Get the stage that has been registered to the framework.
public function get stage():Stage| views | property |
views:SomaViews [read-only] Gets the view manager class.
public function get views():SomaViews| wires | property |
wires:SomaWires [read-only] Gets the wires manager instance.
public function get wires():SomaWires| Soma | () | Constructor |
public function Soma(stage:Stage = null, injectorClass:Class = null)Create an instance of the SomaCore class.
Parametersstage:Stage (default = null) — The stage is used as a global EventDispatcher (as well as the Soma class), and is required to instantiate the framework.
| |
injectorClass:Class (default = null) — Class that must extend ISomaInjector.
|
| addCommand | () | method |
public final function addCommand(commandName:String, command:Class):voidRegisters a command to the framework.
Parameters
commandName:String — Event type that is used as a command name.
| |
command:Class — Class that will be executed when a command has been dispatched.
|
See also
addCommand(MyEvent.DOSOMETHING, MyCommand);
| addModel | () | method |
public final function addModel(modelName:String, model:IModel):IModelRegisters a model to the framework.
Parameters
modelName:String — Name of the model.
| |
model:IModel — Instance of the model.
|
IModel — The model instance.
|
See also
addModel(MyModel.NAME, new MyModel());
| addView | () | method |
public final function addView(viewName:String, view:Object):ObjectRegisters a view to the framework.
Parameters
viewName:String — Name of the view.
| |
view:Object — Instance of the view.
|
Object — The view instance.
|
See also
addView(MySprite.NAME, new MySprite());
| addWire | () | method |
public final function addWire(wireName:String, wire:IWire):IWireRegisters a wire to the framework.
Parameters
wireName:String — Name of the wire.
| |
wire:IWire — Instance of the wire.
|
IWire — The wire instance.
|
See also
addWire(MyWire.NAME, new MyWire());
| createPlugin | () | method |
public final function createPlugin(plugin:Class, pluginVO:ISomaPluginVO):ISomaPluginCreates a plugin instance.
Parameters
plugin:Class — Class of the plugin that will be instantiated.
| |
pluginVO:ISomaPluginVO — Value Object class of the plugin.
|
ISomaPlugin — An instance of the plugin.
|
var pluginVO:SomaDebuggerVO = new SomaDebuggerVO(this, SomaDebugger.NAME_DEFAULT, getCommands(), true, false);
var debugger:SomaDebugger = createPlugin(SomaDebugger, pluginVO) as SomaDebugger;
| createPluginFromClassName | () | method |
public final function createPluginFromClassName(pluginClassName:String, pluginVO:ISomaPluginVO):ISomaPluginCreates a plugin instance using the class name and the getDefinitionByName method.
Parameters
pluginClassName:String — Class name of the plugin that will be instantiated.
| |
pluginVO:ISomaPluginVO — Value Object class of the plugin.
|
ISomaPlugin — An instance of the plugin.
|
var pluginVO:SomaDebuggerVO = new SomaDebuggerVO(this, SomaDebugger.NAME_DEFAULT, getCommands(), true, false);
var debugger:SomaDebugger = createPluginFromClassName("com.soma.core.debugger.SomaDebugger", pluginVO) as SomaDebugger;
| dispose | () | method |
public function dispose():voidDestroys the SomaCore core classes and elements registered to the framework.
| getCommand | () | method |
public final function getCommand(commandName:String):ClassRetrieves the command class that has been registered with a command name.
Parameters
commandName:String — Event type that is used as a command name.
|
Class — A class.
|
See also
var commandClass:ICommand = getCommand(MyEvent.DOSOMETHING) as ICommand;
| getCommands | () | method |
public final function getCommands():ArrayRetrieves all the command names (event type) that have been registered to the framework.
ReturnsArray — An Array of String (command name).
|
See also
var commands:Array = getCommands();
| getLastSequencer | () | method |
public final function getLastSequencer():ISequenceCommandRetrieves the last sequence command that has been instantiated in the framework.
ReturnsISequenceCommand — An ISequenceCommand instance.
|
See also
var lastSequencer:ISequenceCommand = getLastSequencer();
| getModel | () | method |
public final function getModel(modelName:String):IModelRetrieves the model instance that has been registered using its name.
Parameters
modelName:String — Name of the model.
|
IModel — A IModel instance.
|
See also
var myModel:MyModel = getModel(MyModel.NAME) as MyModel;
| getModels | () | method |
public final function getModels():DictionaryRetrieves all the model instances that have been registered to the framework.
ReturnsDictionary — A Dictionary (the key of the Dictionary is the name used for the registration).
|
See also
var models:Dictionary = getModels();
| getRunningSequencers | () | method |
public final function getRunningSequencers():ArrayRetrieves all the sequence command instances that are running.
ReturnsArray — An Array of ISequenceCommand instances.
|
See also
var sequencers:Array = getRunningSequencers();
| getSequencer | () | method |
public final function getSequencer(event:Event):ISequenceCommandRetrieves the sequence command instance using an event instance that has been created from this sequence command.
Parameters
event:Event — Event instance.
|
ISequenceCommand — A sequencer (ISequenceCommand).
|
See also
var sequencer:ISequenceCommand = getSequencer(myEvent);
| getView | () | method |
public final function getView(viewName:String):ObjectRetrieves the view instance that has been registered using its name.
Parameters
viewName:String — Name of the view.
|
Object — An Object instance.
|
See also
var mySprite:MySprite = getView(MySprite.NAME) as MySprite;
| getViews | () | method |
public final function getViews():DictionaryRetrieves all the view instances that have been registered to the framework.
ReturnsDictionary — A Dictionary (the key of the Dictionary is the name used for the registration).
|
See also
var sprites:Dictionary = getViews();
| getWire | () | method |
public final function getWire(wireName:String):IWireRetrieves the wire instance that has been registered using its name.
Parameters
wireName:String — Name of the wire.
|
IWire — A wire instance.
|
See also
var myWire:MyWire = getWire(MyWire.NAME) as MyWire;
| getWires | () | method |
public final function getWires():DictionaryRetrieves all the wire instances that have been registered to the framework.
ReturnsDictionary — A Dictionary (the key of the Dictionary is the name used for the registration).
|
See also
var wires:Dictionary = getWires();
| hasCommand | () | method |
public final function hasCommand(commandName:String):BooleanIndicates wether a command has been registered to the framework.
Parameters
commandName:String — Event type that is used as a command name.
|
Boolean — A Boolean.
|
See also
hasCommand(MyEvent.DOSOMETHING);
| hasModel | () | method |
public final function hasModel(modelName:String):BooleanIndicates wether a model has been registered to the framework.
Parameters
modelName:String — Name of the model.
|
Boolean — A Boolean.
|
See also
hasModel(MyModel.NAME);
| hasView | () | method |
public final function hasView(viewName:String):BooleanIndicates wether a view has been registered to the framework.
Parameters
viewName:String — Name of the view.
|
Boolean — A Boolean.
|
See also
hasView(MySprite.NAME);
| hasWire | () | method |
public final function hasWire(wireName:String):BooleanIndicates wether a wire has been registered to the framework.
Parameters
wireName:String — Name of the wire.
|
Boolean — A Boolean.
|
See also
hasWire(MyWire.NAME);
| initialize | () | method |
protected function initialize():voidMethod that you can optionally overwrite to initialize elements before anything else.
See also
addModel(MyModel.NAME, new MyModel());
| isPartOfASequence | () | method |
public final function isPartOfASequence(event:Event):BooleanIndicates wether an event has been instantiated from a ISequenceCommand class.
Parameters
event:Event |
Boolean — A Boolean.
|
See also
var inSequence:Boolean = isPartOfASequence(myEvent);
| registerCommands | () | method |
protected function registerCommands():voidMethod that you can optionally overwrite to register commands (mapping events to command classes) to the framework.
See also
addCommand(MyEvent.DOSOMETING, MyCommandClass);
| registerModels | () | method |
protected function registerModels():voidMethod that you can optionally overwrite to register models to the framework.
See also
addModel(MyModel.NAME, new MyModel());
| registerPlugins | () | method |
protected function registerPlugins():voidMethod that you can optionally overwrite to register plugins to the framework.
var pluginVO:SomaDebuggerVO = new SomaDebuggerVO(this, SomaDebugger.NAME_DEFAULT, getCommands(), true, false);
var debugger:SomaDebugger = createPlugin(SomaDebugger, pluginVO) as SomaDebugger;
| registerViews | () | method |
protected function registerViews():voidMethod that you can optionally overwrite to register views to the framework.
See also
addView(MySprite.NAME, new MySprite());
| registerWires | () | method |
protected function registerWires():voidMethod that you can optionally overwrite to register wires to the framework.
See also
addWire(MyWire.NAME, new MyWire());
| removeCommand | () | method |
public final function removeCommand(commandName:String):voidRemoves a command from the framework.
Parameters
commandName:String — Event type that is used as a command name.
|
See also
removeCommand(MyEvent.DOSOMETHING);
| removeModel | () | method |
public final function removeModel(modelName:String):voidRemoves a model from the framework and call the dispose method of this model.
Parameters
modelName:String — Name of the model.
|
See also
removeModel(MyModel.NAME);
| removeView | () | method |
public final function removeView(viewName:String):voidRemoves a view from the framework and call the (optional) dispose method of this view.
Parameters
viewName:String — Name of the view.
|
See also
removeView(MySprite.NAME);
| removeWire | () | method |
public final function removeWire(wireName:String):voidRemoves a wire from the framework and call the dispose method of this wire.
Parameters
wireName:String — Name of the wire.
|
See also
removeWire(MyWire.NAME);
| setup | () | method |
public function setup(stage:Stage = null, injectorClass:Class = null):voidRegister elements that the frameworks needs to be ready, such as the stage and the optional injector class (default is SomaInjector).
Parameters
stage:Stage (default = null) — The stage is used as a global EventDispatcher (as well as the Soma class), and is required to instantiate the framework.
| |
injectorClass:Class (default = null) — Class that must extend ISomaInjector.
|
| start | () | method |
protected function start():voidMethod that you can optionally overwrite to start your own after that the framework has registered all the elements (models, views, commands, wires, plugins).
See also
addWire(MyWire.NAME, new MyWire());
| stopAllSequencers | () | method |
public final function stopAllSequencers():voidStops all the sequence command instances that are running.
See also
stopAllSequencers();
| stopSequencer | () | method |
public final function stopSequencer(sequencer:ISequenceCommand):BooleanStops a sequence command using the sequence command instance itself.
Parameters
sequencer:ISequenceCommand — The sequence command instance.
|
Boolean — A Boolean (true if the sequence command has been stopped).
|
See also
var success:Boolean = stopSequencer(mySequenceCommand);
| stopSequencerWithEvent | () | method |
public final function stopSequencerWithEvent(event:Event):BooleanStops a sequence command using an event instance that has been created from this sequence command.
Parameters
event:Event — Event instance.
|
Boolean — A Boolean (true if a sequence command has been stopped).
|
See also
var success:Boolean = stopSequencerWithEvent(myEvent);
package {
import com.soma.core.interfaces.ISoma;
import com.soma.core.di.SomaInjector;
import flash.display.Sprite;
public class Main extends Sprite {
private var _app:ISoma;
public function Main() {
// injection disabled
_app = new SomaApplication(stage);
// injection enabled
_app = new SomaApplication(stage, SomaInjector);
}
}
}
package {
import com.soma.core.Soma;
import com.soma.core.interfaces.ISoma;
import flash.display.Stage;
public class SomaApplication extends Soma implements ISoma {
public function SomaApplication(stage:Stage, injectorClass:Class) {
super(stage, injector);
}
override protected function initialize():void {
}
override protected function registerCommands():void {
}
override protected function registerModels():void {
}
override protected function registerPlugins():void {
}
override protected function registerViews():void {
}
override protected function registerWires():void {
}
override protected function start():void {
}
}
}