Share
Embed
Robotlegs 2.0
Detailed information on the upcoming release of Robotlegs, the lightweight micro-architecture for Flash (AS3) applications with modular IOC, contractual mediation and a fluent interface.
justin j. moses
November 16, 2011
Transcript
56 slides
-
govt health warning robotlegs 2 is still in alpha these
examples are subject to change Thursday, 27 October 11 -
public class Context { protected var _injector:IInjector; protected var _reflector:IReflector;
protected var _contextView:DisplayObjectContainer; protected var _commandMap:ICommandMap; protected var _mediatorMap:IMediatorMap; protected var _viewMap:IViewMap; } Contexts in robotlegs circa v1 Thursday, 27 October 11 -
in version one, features were bound to the context. public
class Container { private var youCantSeeMe:SoLetsHopeIKnowWhatImDoing; protected var sureYouCanOverrideMe:ButYouAintGettingRidOfMe; } Thursday, 27 October 11 -
not extended with what you don’t RL2 contexts are created
with what you need Thursday, 27 October 11 -
public interface IContextBuilder { build():IContext; withBundle(bundle:IContextBuilderBundle):IContextBuilder; withConfig(config:IContextConfig):IContextBuilder; withContextView(value:DisplayObjectContainer):IContextBuilder; withDispatcher(value:IEventDispatcher):IContextBuilder; withExtension(extension:IContextExtension):IContextBuilder;
withInjector(value:Injector):IContextBuilder; withParent(value:IContext):IContextBuilder; withProcessor(processor:IContextProcessor):IContextBuilder; } Introducing the context builder Thursday, 27 October 11 -
setup your configuration to execute once at build. public interface
IContextConfig { function configure(context:IContext):void; } .withConfig Thursday, 27 October 11 -
public interface IContextExtension { function initialize(context:IContext):void; function install(context:IContext):void; function uninstall(context:IContext):void;
} .withExtension extensions add functionality at any time. Thursday, 27 October 11 -
.withProcessor public interface IContextProcessor { function process(context:IContext, callback:Function):void; } processors
asynchronously affect the build state. Thursday, 27 October 11 -
each representing a context builder bundle four tasty flavours of
robotlegs Thursday, 27 October 11 -
l i g h t »when size and performance are
paramount. Thursday, 27 October 11 -
smart views » when you simply can’t live without view
injection. Thursday, 27 October 11 -
flexible and fluent type matching syntax public class TypeMatcher {
function anyOf(... params):TypeMatcher; function noneOf(... params):TypeMatcher; function allOf(... params):TypeMatcher; } new TypeMatcher() .allOf(ISpaceShip, IEnemy) .noneOf(DeathStar) Usage Definion Thursday, 27 October 11 -
wire view handlers to view watchers viewManager.addContainer(contextView); viewManager.addHandler(mediatorMap); viewManager.addWatcher(stageWatcher); viewManager.addContainer(myPopUp);
viewManager.addContainer(myPopUp); native support for flex popups and air windows. Thursday, 27 October 11 -
map mediators to interfaces rather than concrete classes. mediatorMap.map(UserDetailsMediator).toView(IUserDetailsAware); use
type-matching to refine your mapping mediatorMap .map(SomeMenuMediator) .toMatcher() .anyOf(TopLevelMenu, AdminMenu, FootMenu); Thursday, 27 October 11 -
a guard exposes conditional logic for an action to occur
possible use-cases for a guard: • prevent mediation when ... • prevent command execution when ... mediatorMap .map(UserDetailsMediator) .withGuard(UserIsAdminGuard) .toView(IUserDetailsAware); Thursday, 27 October 11 -
a hook enables pre-processing on an action. scenarios for using
a hook: • customised logging • view skinning • view localisation • instance configuration prior to command execution commandMap .map(UserLoginCommand) .toEvent(UserLoginEvent.LOGIN, UserLoginEvent) .withHook(ConfigureUserDetails) Thursday, 27 October 11 -
a rule can prevent or ensure an action occurring possible
uses of a rule: • adding or removing mediators • loading or unloading commands Thursday, 27 October 11 -
flows are pathways between commands command flows: create a workflow
of commands to represent a complex sequence Thursday, 27 October 11 -
full integration with swift suspenders 2 leverages the entire toolkit.
//creates a new instance per injection injector.map(SomeType); //or injector.map(SomeType, ‘named’); //create new instance per injection and map to injector.map(IService).toType(SomeService); //or value .toValue(someInstance) //map as singleton instance injector.map(SomeService).asSingleton(); //or .toSingleton(SomeService); //allows to easily specify custom providers to use for a mapping injector.map(IService).toProvider(new CustomProvider()); //prevents sharing the mapping with child injectors; injector.map(SomeService).local(); // .shared() reverts it //allow child injector to map if none exists injector.map(SomeService).soft(); // .strong() maps regardless //prevents changes to the mapping; returns a unique key object injector.map(SomeService).seal(); //can revert with key and .unseal() Thursday, 27 October 11 -
in robotlegs 2, modules just work. integrated module automation: •
context wired up by parent once added to stage • view events are collated in the one view manager • child injectors created and wired to the parent • default injections to ensure modules work both standalone and when integrated. Thursday, 27 October 11 -
info here. new inspector gadget tool to help you with
you robotlegging. Thursday, 27 October 11 -
let’s look at a simple robotlegs v1 application for comparison
Thursday, 27 October 11 -
one mediator per view. invariant mediation (via classes) View Mediator
e v e n t s Thursday, 27 October 11 -
what’s wrong with this approach? • the mediator is tightly
coupled to the view • view is restricted to one mediator • no reuse of mediation Thursday, 27 October 11 -
using the variance utility how to fix this in v1?
Thursday, 27 October 11 -
Mediator C n mediators per view. covariant mediation (via interfaces)
View Mediator A IBehaviour A IBehaviour B IBehaviour C Mediator B e v e n t s Thursday, 27 October 11 -
what is wrong with this contract? we have to extend
IEventDispatcher and there’s no enforcement of contract. import flash.events.IEventDispatcher; [Event(name="doAsync", type="...ControlEvent")] public interface IServiceStarter extends IEventDispatcher { function serviceReturned():void; } Thursday, 27 October 11 -
import org.osflash.signals.ISignal; public interface IServiceStarter { function serviceReturned():void; function get
start():ISignal; } with signals, we define the contract import org.osflash.signals.ISignal; private var startSignal:ISignal = new Signal(); public function serviceReturned():void { Alert.show("The service returned.","Guess what?"); } public function get start():ISignal { return startSignal; } ... <s:Button label=”Start” click=”start.dispatch” /> and force the view to comply Thursday, 27 October 11 -
Mediator C each view is mediated bidirectionally. with covariance and
signals View Mediator A IBehaviour A IBehaviour B IBehaviour C Mediator B Thursday, 27 October 11 -
to view this sample online go to j.mp/covariance Libraries used:
• robotlegs 1.5.2 • robotlegs variance utility 1.1 • as3-signals 0.9-beta Thursday, 27 October 11 -
as of this afternoon robotlegs 2 is in open beta.
Thursday, 27 October 11 -
Stay updated. Add you name to the RL2 beta list
by commenting on: j.mp/robotlegs2 Join the robotlegs google group Follow @robotlegs_as3 on Twitter. Thursday, 27 October 11