Singleton Signals?
Hi,
Im just playing around on one of my project I have come across a need to invoke a signal from a Class.
To explain what I mean take the following snippet from a SignalContext:
public class InputtieContext extends SignalContext
{
override public function startup():void
{
// Map a signal to command fine
signalCommandMap.mapSignalClass( MySignal, MyCommand );
// Now get the signal back again.
var signal : Signal = injector.instantiate(MySignal);
// And invoke MyCommand?
signal.dispatch();
}
}
This code however doesnt work as I would have thought it might.
I would have expected that calling signalCommandMap.mapSignalClass( ) would mean that the signal used for the mapping is now in effect a singleton so calling "injector.instantiate(MySignal);" should return back the singleton instance, which when called would invoke MyCommand?
If this isnt the intention, could you explain how could I invoke a mapped signal in the signalCommandMap? Something like "signalCommandMap.getMappedSignal(signalClazz:Class) : Signal" perhaps?
Cheers,
Mike
Comments are currently closed for this discussion. You can start a new one.
Support Staff 2 Posted by Shaun Smith on 14 Mar, 2010 02:57 PM
Unfortunately, the "instantiate" method always creates a new instance - a little confusing, I know. The next version of SwiftSuspenders (and RL) will have a "getInstance" method that will function as you expect.
I haven't used the signalCommandMap yet, so I can't answer the rest of your question. Perhaps Joel can provide some insight here?
Support Staff 3 Posted by Joel Hooks on 14 Mar, 2010 03:22 PM
This is a limitation with the current API (it is being fixed in Robotlegs 1.1) with instantiate.
http://github.com/joelhooks/robotlegs-examples-ImageGalleryPM/blob/...
You can see how I worked around it here. Not very pretty, but it will be better soon ^^
4 Posted by Mike Cann on 14 Mar, 2010 03:27 PM
Hi Shaun / Joel,
Cheers for the replies. Yes I had seen that Joel and wondered about it. Although it works in that simple context, its not so hot when you have lots of classes about the place wanting to get at the signals.
Okay, I shall await with baited breath for RL 1.1 ;)
Mike
Support Staff 5 Posted by Joel Hooks on 14 Mar, 2010 03:29 PM
The classes waiting for the Signals can simply [Inject] them. They are mapped when you mapSignalClass. The problem is when you want to trigger a command in the same method scope.
Stray closed this discussion on 16 Feb, 2011 04:55 PM.