Migrating a simple Robotlegs application (form 1.5 to 2)

308 views Asked by At

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 and am now trying to create the same in RL2.

My current questions/problems 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.

part of the main class (mxml)

xmlns:context="contexts.*"
    <fx:Declarations>
        <rl:ContextBuilder>
            <context:HelloWorldContext/>
        </rl:ContextBuilder>
</fx:Declarations>  

and the (non-compling) context .as

public class HelloWorldContext extends Context
{       
    public function HelloWorldContext()
    {
        this.install(MVCSBundle);
        this.configure(HelloWorldConfig);

        mediatorMap.map(ButtonView).toMediator(ButtonMediator); // Error: mediatorMap not defined
    }
}
1

There are 1 answers

0
ThanksBro On BEST ANSWER

Which method has replaced the startup() in the Context In the Context

use context.install to install extension that you want to use. most common one is MVCSBundle. use context.configure with (new ContextView) argument will start your context initialization.

I can no longer just use "mediatorMap"; Do I need to create a MediatorMap Instance for this? you can inject IMediatorMap anywhere you need it, like in config [Inject] public var injector:IInjector;

[Inject]
public var mediatorMap:IMediatorMap;

[Inject]
public var commandMap:ISignalCommandMap;

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? you can create your own config. Usually, in there you will map your commands, mediators and injections. You create one [PostConstruct] method which will call all theese stuff:

If you implement IConfig inside config, you dont need [PostConstruct] tag, because robotlegs will call configure function automatically once the dependencies have been injected.

    [PostConstruct]
    public function init():void {

        context.logLevel = LogLevel.DEBUG;
//        injector.fallbackProvider = new DefaultFallbackProvider();

        mapSignalCommands();
        mapMediators();
        mapInjection();

        context.afterInitializing(afterInit);

    }

in your case you will have

_context:IContext;
public function MainApp()
{
    _context = new Context();
    _context.install(MVCSBundle);
    _context.configure(HelloWorldConfig,new ContextView(this));

        }

mediator thing goes to config on mapMediators();