Baby Steps, simple Robolegs 2 setup

Mike F.'s Avatar

Mike F.

06 Sep, 2013 08:47 AM

I'm new to Robotlegs, and somewhat struggling with the first steps.
To learn the ropes I followed the first part of [Joel Hooks' introduction][1] and am now trying to create the same in RL2.
 
My current questions/problems (I'm sure there will be many more) are:
 - Which method has replaced the startup() in the Context
- In the Context I can no longer just use "mediatorMap"; Do I need to create a MediatorMap Instance for this?
- In the few RL2 example out there, many devs use the IConfig to configure their main Context; is this required, a good convention or optional.
- ..and in which way, is the Context 'configured' through this?

I spent the best part of the day looking for solutions. I apologize if I missed the obvious.
Thanks in advance for any incite.

* source is attached
[1]: http://www.adobe.com/devnet/actionscript/articles/intro-robotlegs-pt1.html

  1. Support Staff 1 Posted by Ondina D.F. on 06 Sep, 2013 11:47 AM

    Ondina D.F.'s Avatar

    Hi Jake,

    I've modified your mini-project, see attachment.

    1.option, using the fx declaration tag:

    <rl:ContextBuilder>
        <mvcs:MVCSBundle/>
        <config:HelloWorldConfig/>
    </rl:ContextBuilder>
    

    2.option - actionscript:

    Main
    private var _helloWorldContext:HelloWorldContext;
    protected function preinitializeHandler(event:FlexEvent):void
    {
        _helloWorldContext = new HelloWorldContext(this);
    }
    
    public class HelloWorldContext
    {
        private var _context:IContext;
    
        public function HelloWorldContext(view:DisplayObjectContainer)
        {
            _context = new Context()
            .install(MVCSBundle)
            .configure(HelloWorldConfig, new ContextView(view));
    
    1. option - the magic happens here:
      https://github.com/robotlegs/robotlegs-framework/blob/master/src/ro...

    2. option
      I don't have enough time right now to get into many details, so please see a short explanation here:
      http://knowledge.robotlegs.org/discussions/robotlegs-2/4493-dispatc...

    Let me know if there is still something you don't understand and I'll try to answer your question later on or tomorrow.

    Ondina

  2. 2 Posted by Mike F. on 06 Sep, 2013 01:57 PM

    Mike F.'s Avatar

    The first option worked like a charm (after I replaced "WindowedApplication" with "Application")! Got so exited, I spilled cereal all over myself.
    I'll look into the other options, to further demystify the framework.
    Thanks so much for your time!

  3. 3 Posted by Paul Robertson on 06 Sep, 2013 08:09 PM

    Paul Robertson's Avatar

    (Caveat: I last updated these examples over a year ago, so they probably
    need some changes to work with the final version of RL2...)

    Here are three examples that were originally built to teach RL1. (I wrote
    two and Joel wrote one.) I later migrated all three of them to RL2
    step-by-step to use as examples for a workshop session I taught at a
    conference. These links point to the commit history, since that shows the
    migration process and hopefully helps communicate the changes.

    The first two are very simple apps that show a single user
    interaction->service->update view lifecycle. The last is a more "real" app
    that Joel used in articles and workshops.

    https://github.com/probertson/robotlegs-examples-Simple/commits/Robotlegs2
    https://github.com/probertson/robotlegs-examples-Simple_NoFlex/commits/Robotlegs2
    https://github.com/probertson/robotlegs-example-ImageGalleryRL2/commits/master

    Hopefully this is helpful, and not just overwhelming :/

    Paul

  4. Support Staff 4 Posted by Ondina D.F. on 07 Sep, 2013 07:35 AM

    Ondina D.F.'s Avatar

    Got so exited, I spilled cereal all over myself.

    Hehe, better cereals than coffee or other liquids, for the sake of your keyboard ;)

    @Paul Thanks for sharing your examples with us! They are perfect for beginners.

    The few changes needed to make them work with the latest rl2:

    robotlegs-examples-Simple_NoFlex-Robotlegs2

    RobotlegsSimple.as

    [1] use install instead of extend - .install(MVCSBundle)

    [2] The Context needs a ContextView. (The "contextView" should always be provided as the final configuration as it may trigger context initialization.) - .configure(new ContextView(this));

    Instead of this:

    private function _initialize():void
    {
        stage.align = StageAlign.TOP_LEFT;
        stage.scaleMode = StageScaleMode.NO_SCALE;
        _context = new Context()
            .extend(MVCSBundle)
            .configure(SimpleConfig, this);
                
        addEventListener(Event.ADDED_TO_STAGE, _onApplication_AddedToStageHandler);
    }
    

    use this:

    private function _initialize():void
    {
        stage.align = StageAlign.TOP_LEFT;
        stage.scaleMode = StageScaleMode.NO_SCALE;
        _context = new Context()
            .install(MVCSBundle)
            .configure(SimpleConfig, new ContextView(this));
                
                addEventListener(Event.ADDED_TO_STAGE, _onApplication_AddedToStageHandler);
    }
    

    SimpleConfig.as

    [3] SimpleConfig should implement IConfig. (If a config implements the IConfig interface configure() will be invoked after construction/injection. ) That means you have access to the Injector and the installed extensions.

    [4] The Injector has to be provided as an interface

    [5] mediatorMap.map instead of mediatorMap.mapView

    [6] implement IConfig.configure() method instead of a postconstruct method

    So, instead of this:

    public class SimpleConfig
    {
        [Inject]
        public var injector:Injector
            
            
        [Inject]
        public var mediatorMap:IMediatorMap;
            
        [Inject]
        public var commandMap:IEventCommandMap;
            
        [PostConstruct]
        public function startup():void
        {
            commandMap.map(SimpleAppEvent.CHOOSE_FILE, SimpleAppEvent).toCommand(ChooseFileCommand);
            commandMap.map(FileResultEvent.FILE_RESULT, FileResultEvent).toCommand(SetSelectedFileCommand);
                
            injector.map(IFileService).toSingleton(FileService);
                
            injector.map(SimpleModel).asSingleton();
                mediatorMap.mapView(ButtonContainer).toMediator(ButtonContainerMediator);
                mediatorMap.mapView(TextContainer).toMediator(TextContainerMediator);
    }
    

    Use this:

    public class SimpleConfig implements IConfig
    {
        [Inject]
        public var injector:IInjector;
            
        [Inject]
        public var mediatorMap:IMediatorMap;
            
        [Inject]
        public var commandMap:IEventCommandMap;
            
        public function configure():void
        {
                commandMap.map(SimpleAppEvent.CHOOSE_FILE, SimpleAppEvent).toCommand(ChooseFileCommand);
                commandMap.map(FileResultEvent.FILE_RESULT, FileResultEvent).toCommand(SetSelectedFileCommand);
                
                injector.map(IFileService).toSingleton(FileService);
                
                injector.map(SimpleModel).asSingleton();
                
                mediatorMap.map(ButtonContainer).toMediator(ButtonContainerMediator);
                mediatorMap.map(TextContainer).toMediator(TextContainerMediator);
    }
    
  5. Support Staff 5 Posted by Ondina D.F. on 07 Sep, 2013 08:31 AM

    Ondina D.F.'s Avatar
  6. 6 Posted by Mike F. on 07 Sep, 2013 11:34 AM

    Mike F.'s Avatar

    @ Paul: Thanks a lot for the examples. The first ones are a perfect starting point (seeing as I'm also only just beginning with mxml). And I'm sure the gallery will great to get a better understanding of services.

    I'm going to focus on the latest version for now though.. I'm a little paranoid that looking into the previous versions of RL will just confuse me (more).

    @ Ondina: Thanks again for taking the time to update the files, and everything!
    You two have made my day!

  7. 7 Posted by Paul Robertson on 09 Sep, 2013 04:32 PM

    Paul Robertson's Avatar

    Yes thanks very much Ondina for doing the updates for me! If you haven't
    already, feel free to submit pull requests and I'll integrate them.

    Paul

    On Saturday, September 7, 2013, Jake wrote:

  8. Support Staff 8 Posted by Ondina D.F. on 09 Sep, 2013 04:52 PM

    Ondina D.F.'s Avatar

    If you haven't already, feel free to submit pull requests and I'll integrate them.

    @Paul - Done:)

    @Jake - Glad we could help!

    I'm going to close this thread, but feel free to re-open it, if need be, and, of course, you can open new ones for other issues/questions.

    Ondina

  9. Ondina D.F. closed this discussion on 09 Sep, 2013 04:52 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac