Introduction to Robotlegs 2

20,044 views
18,929 views

Published on

An introduction to the features coming in Robotlegs 2.0 and a discussion of covariance

Published in: Technology
0 Comments
13 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
20,044
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
0
Comments
0
Likes
13
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • uses fluent interface, for readability. think jQuery. each chained method returns context for the next call. \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • for example, a Context View Watcher, which waits for ADDED TO STAGE.\n
  • for example, a Context View Watcher, which waits for ADDED TO STAGE.\n
  • for example, the View Manager, Stage Watcher, Logging mechanism\n
  • for example, the View Manager, Stage Watcher, Logging mechanism\n
  • for example, the Parent Context Finder - the context checks to see if a parent exists during the creation process. \n
  • for example, the Parent Context Finder - the context checks to see if a parent exists during the creation process. \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • show Mediate Classes examples.\n
  • when done, see Mediate Classes > Mediators > console output.\n
  • when done, see Mediate Classes > Mediators > console output.\n
  • when done, see Mediate Classes > Mediators > console output.\n
  • when done, see Mediate Classes > Mediators > console output.\n
  • when done, see Mediate Classes > Mediators > console output.\n
  • when done, see Mediate Classes > Mediators > console output.\n
  • \n
  • \n
  • \n
  • show the Mediate Middle example. Show variant mediator map.\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Introduction to Robotlegs 2

    1. robotlegs
    2. robotlegs 2.0
    3. the goals
    4. configurable because every project is unique
    5. versatile rigidity sucks
    6. conciseuse only what you need
    7. fluentmake(tea).with(milk).butNot(sugar)
    8. govt health warningthese examples are subject to change
    9. the features
    10. .context builder
    11. Contexts in robotlegs circa v1
    12. Contexts in robotlegs circa v1public 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;}
    13. public class Container{ private var youCantSeeMe:SoLetsHopeIKnowWhatImDoing; protected var sureYouCanOverrideMe:ButYouAintGettingRidOfMe;}
    14. public class Container{ private var youCantSeeMe:SoLetsHopeIKnowWhatImDoing; protected var sureYouCanOverrideMe:ButYouAintGettingRidOfMe;}in version one,features were bound to the context.
    15. RL2 contexts are created with what you need not extended with what you don’t
    16. Introducing the context builder
    17. Introducing the context builderpublic 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;}
    18. .withConfig
    19. .withConfigpublic interface IContextConfig{ function configure(context:IContext):void;}setup your configuration to execute once at build.
    20. .withExtension
    21. .withExtensionpublic interface IContextExtension{ function initialize(context:IContext):void; function install(context:IContext):void; function uninstall(context:IContext):void;}extensions add functionality at any time.
    22. .withProcessor
    23. .withProcessorpublic interface IContextProcessor{ function process(context:IContext, callback:Function):void;}processors asynchronously affect the build state.
    24. .pre-configured bundles
    25. four tasty flavours of robotlegs each representing a context builder bundle
    26. Original»when plain old vanilla is just right.
    27. light» when size and performance are paramount.
    28. rapid»when time is of the essence.
    29. » smart viewswhen you simply can’t live without view injection.
    30. .type matching
    31. Definion
    32. Definionpublic class TypeMatcher{ function anyOf(... params):TypeMatcher; function noneOf(... params):TypeMatcher; function allOf(... params):TypeMatcher;}Usagenew TypeMatcher() .allOf(ISpaceShip, IEnemy) .noneOf(DeathStar)flexible and fluent type matching syntax
    33. .view management
    34. viewManager.addContainer(contextView); viewManager.addHandler(mediatorMap); viewManager.addWatcher(stageWatcher); viewManager.addContainer(myPopUp); wire view handlers to view watchers
    35. viewManager.addContainer(contextView); viewManager.addHandler(mediatorMap); viewManager.addWatcher(stageWatcher); viewManager.addContainer(myPopUp); wire view handlers to view watchers viewManager.addContainer(myPopUp); viewManager.addContainer(myAIRWindow); native support for flex popups and air windows.
    36. .mediate anything
    37. mediatorMap.map(UserDetailsMediator).toView(IUserDetailsAware); map mediators to interfaces rather than concrete classes.
    38. mediatorMap.map(UserDetailsMediator).toView(IUserDetailsAware); map mediators to interfaces rather than concrete classes.mediatorMap .map(SomeMenuMediator) .toMatcher() .anyOf(TopLevelMenu, AdminMenu, FootMenu);use type-matching to refine your mapping
    39. .guards and hooks
    40. possible use-cases for a guard:
    41. possible use-cases for a guard:• prevent mediation when ...
    42. possible use-cases for a guard:• prevent mediation when ...• prevent command execution when ...
    43. possible use-cases for a guard:• prevent mediation when ...• prevent command execution when ...mediatorMap .map(UserDetailsMediator) .toView(IUserDetailsAware) .withGuard(UserIsAdminGuard);a guard represents conditional logic for anaction to occur.
    44. scenarios for using a hook:
    45. scenarios for using a hook:• customised logging
    46. scenarios for using a hook:• customised logging• view skinning
    47. scenarios for using a hook:• customised logging• view skinning• view localisation
    48. scenarios for using a hook:• customised logging• view skinning• view localisation• instance configuration prior to command execution
    49. scenarios for using a hook:• customised logging• view skinning• view localisation• instance configuration prior to command executioncommandMap .map(UserLoginCommand) .toEvent(UserLoginEvent.LOGIN, UserLoginEvent) .withHook(ConfigureUserDetails)
    50. scenarios for using a hook:• customised logging• view skinning• view localisation• instance configuration prior to command executioncommandMap .map(UserLoginCommand) .toEvent(UserLoginEvent.LOGIN, UserLoginEvent) .withHook(ConfigureUserDetails)a hook enables pre-processing on an action.
    51. .rule sets and command flow
    52. possible uses of a rule:
    53. possible uses of a rule:• adding or removing mediators
    54. possible uses of a rule:• adding or removing mediators• loading or unloading commands
    55. possible uses of a rule:• adding or removing mediators• loading or unloading commandsa rule can prevent or ensure an action’s occurrence.
    56. command flows:
    57. command flows:create a workflow of commands to represent acomplex sequence
    58. command flows:create a workflow of commands to represent acomplex sequenceflows are pathways between commands
    59. .swift-suspenders integration
    60. //creates a new instance per injectioninjector.map(SomeType); //or injector.map(SomeType, ‘named’);//create new instance per injection and map toinjector.map(IService).toType(SomeService); //or value .toValue(someInstance)//map as singleton instanceinjector.map(SomeService).asSingleton(); //or .toSingleton(SomeService);//allows to easily specify custom providers to use for a mappinginjector.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 existsinjector.map(SomeService).soft(); // .strong() maps regardless//prevents changes to the mapping; returns a unique key objectinjector.map(SomeService).seal(); //can revert with key and .unseal()full integration with swift suspenders 2leverages the entire toolkit.
    61. .module integration
    62. integrated module automation:
    63. integrated module automation:• context wired up by parent once added to stage
    64. integrated module automation:• context wired up by parent once added to stage• view events are collated in the one view manager
    65. 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
    66. 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 bothstandalone and when integrated.
    67. 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 bothstandalone and when integrated.in robotlegs 2, modules just work.
    68. .robotlegs inspector
    69. new inspector gadget tool to help you with your robotlegging.info here.
    70. an example in covariance mediate behaviours not views
    71. for comparison
    72. for comparisonlet’s look at a simple robotlegs v1 application
    73. invariant mediation (via classes)
    74. invariant mediation (via classes) View
    75. invariant mediation (via classes) View Mediator
    76. invariant mediation (via classes) View Mediator
    77. invariant mediation (via classes) events View Mediator
    78. invariant mediation (via classes) events View Mediator one mediator per view.
    79. what’s wrong with this approach?
    80. what’s wrong with this approach?• the mediator is tightly coupled to the view
    81. what’s wrong with this approach?• the mediator is tightly coupled to the view• view is restricted to one mediator
    82. what’s wrong with this approach?• the mediator is tightly coupled to the view• view is restricted to one mediator• no reuse of mediation
    83. how to fix this in v1?
    84. how to fix this in v1?using the variance utility
    85. covariant mediation (via interfaces)
    86. covariant mediation (via interfaces) View
    87. covariant mediation (via interfaces) View IBehaviour A IBehaviour B IBehaviour C
    88. covariant mediation (via interfaces) View Mediator A IBehaviour A IBehaviour B IBehaviour C Mediator B Mediator C
    89. covariant mediation (via interfaces) View Mediator A IBehaviour A IBehaviour B IBehaviour C Mediator B Mediator C
    90. covariant mediation (via interfaces) e v e n t s View Mediator A e v e n t s IBehaviour A IBehaviour B e v e n t s IBehaviour C Mediator B Mediator C
    91. covariant mediation (via interfaces) e v e n t s View Mediator A e v e n t s IBehaviour A IBehaviour B e v e n t s IBehaviour C Mediator B Mediator C n mediators per view.
    92. what is wrong with this contract?
    93. what is wrong with this contract? import flash.events.IEventDispatcher; [Event(name="doAsync", type="...ControlEvent")] public interface IServiceStarter extends IEventDispatcher { function serviceReturned():void; }we have to extend IEventDispatcher and there’s no enforcement of contract.
    94. .enter signals, stage right
    95. with signals, we define the contract
    96. with signals, we define the contract import org.osflash.signals.ISignal; public interface IServiceStarter { function serviceReturned():void; function get start():ISignal; } and force the view to comply 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” />
    97. with covariance and signals
    98. with covariance and signals View IBehaviour A IBehaviour B IBehaviour C
    99. with covariance and signals View Mediator A IBehaviour A IBehaviour B IBehaviour C Mediator B Mediator C
    100. with covariance and signals View Mediator A IBehaviour A IBehaviour B IBehaviour C Mediator B Mediator C
    101. with covariance and signals View Mediator A IBehaviour A IBehaviour B IBehaviour C Mediator B Mediator C each view is mediated bidirectionally.
    102. 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
    103. so when is robotlegs 2 coming?
    104. ...now.
    105. as of this afternoonrobotlegs 2 is in open beta.
    106. Stay updated.
    107. 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.
    108. fin.about.me/justinj@justinjmoses

    ×