Signals startup code

JeffW.'s Avatar

JeffW.

14 Jun, 2013 11:03 AM

hi,

I'm trying to use Signals with RL2, which works fine, except that I don't see how I can startup my app. I cannot inject the signal in my AppConfig class as below because it gives me the good old 'Injector is missing a mapping' error.

 [Inject]
    public var initSignal:InitSignal;

public function configure():void
{
        context.logLevel = LogLevel.INFO;

        signalCommandMap.map( InitSignal ).toCommand( InitCommand );
        signalCommandMap.map( RequestTestSignal ).toCommand( RequestTestCommand );

        mediatorMap.map(MessageWriterView).toMediator(MessageWriterMediator);

        context.afterInitializing(init);
}

private function init():void
{
        // add the view that has the mediator mapped to it
        contextView.view.addChild(new MessageWriterView());

        // dispatch the signal that is bound to the command
        initSignal.dispatch();
}</code>



  1. Support Staff 1 Posted by creynders on 14 Jun, 2013 12:05 PM

    creynders's Avatar

    If I remember correctly, no injections in config files. But you don't need them either, since you have access to the injector:

    1. Drop the [Inject] tag above initSignal
    2. right before context.afterInitializing(init) write
      initSignal = context.injector.getInstance(InitSignal);
      

    et voila :)

  2. 2 Posted by JeffW. on 14 Jun, 2013 12:07 PM

    JeffW.'s Avatar

    voila indeed, great!

  3. Support Staff 3 Posted by Ondina D.F. on 14 Jun, 2013 12:14 PM

    Ondina D.F.'s Avatar

    That’s right; the Injector can’t inject the signal into your config class:
    no mapping == no injection

    So, you have to find a way to map the signal before injecting it.
    Maybe there are other solutions as well, but right now there are 2 ways of solving this that I can think of.

    • You can have several config classes.

    CommandConfig, where you map your commands, MediatorsConfig, where you map your mediators, and so on.

    context = new Context()
        .install(MVCSBundle, SignalCommandMapExtension)
        .configure(CommandsConfig)
        .configure(ModelsConfig)
        .configure(ServicesConfig)
        .configure(MediatorsConfig)
    
        .configure(AppConfig)
        .configure(new ContextView(this));
    

    In your CommandConfig:

    signalCommandMap.map( InitSignal ).toCommand( InitCommand );
    signalCommandMap.map( RequestTestSignal ).toCommand( RequestTestCommand );

    In your AppConfig (find a better name for it) you can now inject the initSignal and dispatch it within your init method.

    Note the order of your config classes: the config that maps the signal has to run prior to the one you want to inject the signal into.

    • Instead of injecting it, you let the injector retrieve an instance of your signal:

    (in your configure) signalCommandMap.map( InitSignal ).toCommand( InitCommand );

    (in your init) var initSignal: InitSignal = injector.getInstance(InitSignal);
    initSignal.dispatch();

  4. Support Staff 4 Posted by Ondina D.F. on 14 Jun, 2013 12:14 PM

    Ondina D.F.'s Avatar

    oops, late to the party;)

  5. Support Staff 5 Posted by creynders on 14 Jun, 2013 12:25 PM

    creynders's Avatar

    Late to the party, but more correct :)

    I looked it up and Ondina's right, config instances are injected with dependencies.
    But as she said, obviously you need to map a dependency first, before it can be injected.

  6. JeffW. closed this discussion on 14 Jun, 2013 12:39 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