Chapter 11. Power-ups

Used as described so far, Robotlegs is a pareto solution: the 20% of the solutions that can fix 80% of your problems. In a complex application you’ll probably run into some of the problems that the most basic implementation of Robotlegs doesn’t tackle. Some of these problems can be fixed using the less well-used parts of the Robotlegs framework itself, others are better solved by pulling in extra libraries.

Still, we regularly find that problems brought to the Robotlegs forum can be solved using conventional OO techniques—so, while the power-ups we’re covering here are useful, don’t forget that most of your OO understanding still applies: Just Code Normal.

Bootstraps can break up fat contexts

Even a small application can require a large number of injection, command and mediator mappings—so your startup() function can quickly grow to dozens of lines, with your context importing scores of classes. An antidote to this is to use ‘BootstrapCommands’—commands which run just once during your application’s startup, with the relevant wiring for your app spread across several focused commands.

// in your Context startup function
commandMap.mapEvent(ContextEvent.STARTUP_COMPLETE, MapServicesCommand);

public class MapServicesCommand extends Command
{
    override public function execute():void
    {
        injector.mapSingletonOf(IMosaicConfigLoadingService,
                                         MosaicConfigSolLoadingService);
        injector.mapSingletonOf(IMosaicConfigSavingService, 
                                        MosaicConfigSolSavingService);
    }
}

You’ll want to ...

Get ActionScript Developer's Guide to Robotlegs now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.