Signals startup code
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>
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
Support Staff 1 Posted by creynders on 14 Jun, 2013 12:05 PM
If I remember correctly, no injections in config files. But you don't need them either, since you have access to the injector:
[Inject]
tag aboveinitSignal
context.afterInitializing(init)
writeet voila :)
2 Posted by JeffW. on 14 Jun, 2013 12:07 PM
voila indeed, great!
Support Staff 3 Posted by Ondina D.F. on 14 Jun, 2013 12:14 PM
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.
CommandConfig, where you map your commands, MediatorsConfig, where you map your mediators, and so on.
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.
(in your configure) signalCommandMap.map( InitSignal ).toCommand( InitCommand );
(in your init) var initSignal: InitSignal = injector.getInstance(InitSignal);
initSignal.dispatch();
Support Staff 4 Posted by Ondina D.F. on 14 Jun, 2013 12:14 PM
oops, late to the party;)
Support Staff 5 Posted by creynders on 14 Jun, 2013 12:25 PM
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.
JeffW. closed this discussion on 14 Jun, 2013 12:39 PM.