Robotlegs 2 is under active development. Developers are encouraged to download the stable Robotlegs 1 release from: http://www.robotlegs.org/
The source for Robotlegs 1 can be found in the master branch:
https://github.com/robotlegs/robotlegs-framework/tree/master
Robotlegs is an ActionScript application framework for Flash and Flex. It offers:
- Dependency management
- Module management
- Command management
- View management
To create a Robotlegs application or module you need to instantiate a Context. A context won't do much without some configuration.
Plain ActionScript:
_context = new Context()
.extend(MVCSBundle)
.configure(MyAppConfig, this);
Note: We pass the instance "this" through to the context. It will be used as the "contextView" which is required by many of the view related extensions. It must be installed after the bundle or it won't be processed. Also, you must hold on to the context instance or it will be garbage collected.
Flex:
<fx:Declarations>
<rl2:ContextBuilder>
<mvcs:MVCSBundle/>
<config:MyAppConfig/>
</rl2:ContextBuilder>
</fx:Declarations>
Note: In Flex we don't need to manually provide a "contextView" as the builder can determine this automatically.
A simple configuration might look something like this:
public class MyAppConfig
{
public function MyAppConfig(mediatorMap:IMediatorMap)
{
mediatorMap.mapType(SomeView).toMediator(SomeMediator);
}
}
The configuration file above is a plain class. An instance of this class will be created automatically when the context initializes. Notice that we are using constructor injection to gain access to the mediator map inside our constructor.
WARNING: The config above will not work when using declarative configuration in Flex. For Flex configs that you intend to add directly to the ContextBuilder you have to use setter injection.. Read on.
If you want to use setter injection you must use a [PostConstruct] tag in your config to ensure that all your dependencies have been injected before you start interacting with them:
public class MyAppConfig
{
[Inject]
public var mediatorMap:IMediatorMap;
[PostConstruct]
public function init():void
{
// OK, ready to rock
mediatorMap.mapView(SomeView).toMediator(SomeMediator);
}
}
Dependencies supplied via setter injection are not available until after construction, and attempting to access them will result in Null Pointer exceptions. This is wrong:
public class MyErroneousAppConfig
{
[Inject]
public var mediatorMap:IMediatorMap;
public function MyErroneousAppConfig()
{
// ERROR: the mediatorMap property will not have been set yet!
mediatorMap.mapView(SomeView).toMediator(SomeMediator);
}
}
Start here:
- src/robotlegs/readme
Robotlegs 2 is a complete rewrite of the Robotlegs framework. It features:
- Better configuration
- Better extension
- Better module support
- Flexible type matching
- Small
- Fast
- Flexible
- Small
- Fast
Whilst Robotlegs can be used for Flex 3 & 4 and plain ActionScript projects, the library must be built with the Flex 4.6 SDK or above.
ant package
-
Install XCode 3 or 4
-
check RubyGems version
$ gem -v 1.8.1
-
update RubyGems if version is less than 1.3.6
$ sudo gem update --system
-
install Bundler
$ sudo gem install bundler
-
run Bundler to install dependencies
$ bundle install
-
run Buildr to build RobotLegs & run Tests
$ bundle exec buildr test
-
open test report
$ open reports/flexunit4/html/index.html