Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Robotlegs 2.0

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
Tweet

More Decks by justin j. moses

Other Decks in Technology

Transcript

  1. govt health warning robotlegs 2 is still in alpha these

    examples are subject to change Thursday, 27 October 11
  2. 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
  3. in version one, features were bound to the context. public

    class Container { private var youCantSeeMe:SoLetsHopeIKnowWhatImDoing; protected var sureYouCanOverrideMe:ButYouAintGettingRidOfMe; } Thursday, 27 October 11
  4. not extended with what you don’t RL2 contexts are created

    with what you need Thursday, 27 October 11
  5. setup your configuration to execute once at build. public interface

    IContextConfig { function configure(context:IContext):void; } .withConfig Thursday, 27 October 11
  6. l i g h t »when size and performance are

    paramount. Thursday, 27 October 11
  7. 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
  8. 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
  9. 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
  10. 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
  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
  12. flows are pathways between commands command flows: create a workflow

    of commands to represent a complex sequence Thursday, 27 October 11
  13. 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
  14. 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
  15. info here. new inspector gadget tool to help you with

    you robotlegging. Thursday, 27 October 11
  16. 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
  17. 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
  18. 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
  19. 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
  20. 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
  21. 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
  22. 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