Robotlegs Extensions

Download Robotlegs Extensions

Post on 09-May-2015

121 views

Category:

Technology

3 download

Embed Size (px)

DESCRIPTION

Robotlegs is a popular framework to build Flex applications. This presentation will walk you through some handy extensions which can be used with Robotlegs.

TRANSCRIPT

<ul><li>1.Extensions &amp; Utilities </li></ul> <p>2. Who am I Yennick Trevels Rich Application Consultant @ iDA MediaFoundry Adobe Flex 4 Certified Expert 3. Robotlegs 3rd generation MVC(S) Micro architecture Lightweight Dependency Injection 4. Signals extension Use signals to trigger commands Automatic injection of signal parameters into the commands 5. AS3-Signals: example var contactsLoaded:Signal = new Signal(ArrayCollection); contactsLoaded.add(contactsLoadedHandler); contactsLoaded.dispatch(contacts); private function contactsLoadedHandler(contacts:ArrayCollection):void { // handler code } 6. Signals extension: Usage Context public class MyContext extends SignalContext { override public function startup():void { //other injection mappings injector.mapSingleton(SaveContactSignal); signalCommandMap.mapSignalClass( SaveContactSignal, SaveContactCommand); } } 7. Signals extension: Usage Mediator public class ContactFormMediator extends Mediator{ [Inject] public var saveContact:SaveContactSignal; ... private function saveButton_click(event:MouseEvent):void { saveContact.dispatch(contact); } } 8. Signals extension: Usage Command public class SaveContactCommand extends SignalCommand { [Inject] public var contact:Contact; ... override public function execute():void { contactService.saveContact(contact); } } 9. ModuleContext Modular extension Without the extension: One Context per module Each module works independently No communication between modules Facilitates communication between modules Shell IModuleEventDispatcher ModuleContext Module ModuleContext Module 10. Modular extension: Usage Module Context public class MyModuleContext extends ModuleContext { ... } Module general Mediator public class MyModuleMediator extends ModuleMediator { ... private function exitModuleHandler():void { var exitModuleEvent:ModuleEvent = new ModuleEvent(ModuleEvent.EXIT_MODULE); dispatchToModules(exitModuleEvent); } } 11. Modular extension: Usage Shell/Module Mediator public class ShellMediator extends ModuleMediator { override public function onRegister():void { eventMap.mapListener(moduleDispatcher, ModuleEvent.EXIT_MODULE, moduleExitHandler, ModuleEvent); } ... } 12. Signals &amp; Modular extension? Not possible by default Solution 1. Take the SignalContext code and copy it into a new ModuleSignalContext class 2. Take the ModularContext code and merge it into the new class 3. Done &amp; works like a charm 13. OptionCommandMap utility Run different command based on selected option Use case: 1. User has the choice between several options 2. Based on the chosen option a different command will run Automatic removal of mappings after one option has been processed Removes the need for an custom event per option 14. OptionCommandMap utility Streamlines the following: Setup commandMap.mapEvent(SelectCharacterEvent.MAGE, SelectMageCommand, SelectCharacterEvent); commandMap.mapEvent(SelectCharacterEvent.WARRIOR, SelectWarriorCommand, SelectCharacterEvent); Once a command has been processed commandMap.unmapEvent(SelectCharacterEvent.MAGE, SelectMageCommand, SelectCharacterEvent); commandMap.unmapEvent(SelectCharacterEvent.WARRIOR, SelectWarriorCommand, SelectCharacterEvent); 15. OptionCommandMap: Usage Context override protected function mapInjections():void { super.mapInjections(); injector.mapValue(IOptionCommandMap, new OptionCommandMap(eventDispatcher, injector, reflector)); } Inside Mediator or Command //map the options optionCommandMap.mapOption(1, SelectMageCommand); optionCommandMap.mapOption(2, SelectWarriorCommand); 16. OptionCommandMap: Usage Trigger an option var event:OptionEvent = new OptionEvent(OptionEvent[OPTION_1]); dispatch(event); 17. Macrobot utility execute commands in: Sequence: SequenceCommand Parallel: ParallelCommand 18. Macrobot: Usage Parallel var command:ParallelCommand = new ParallelCommand(); command.addCommand(FirstCommand); command.addCommand(SecondCommand); Command.addCompletionListener(command_completeHandler); command.execute(); private function command_completeHandler(success:boolean):void { //perform completion code here } 19. Macrobot: Usage Sequence var command:SequenceCommand = new SequenceCommand(); command.addCommand(FirstCommand); command.addCommand(SecondCommand); Command.addCompletionListener(command_completeHandler); command.execute(); private function command_completeHandler(success:boolean):void { //perform completion code here } 20. Resources Robotlegs http://www.robotlegs.org/ Signals extension https://github.com/joelhooks/signals-extensions-CommandSignal Modular extension https://github.com/joelhooks/robotlegs-utilities-Modular OptionCommandMap utility https://github.com/Stray/robotlegs-utilities-OptionCommandMap Macrobot utility https://github.com/Aaronius/robotlegs-utilities-Macrobot </p>