eidiot Loving ActionScript 3

24Mar/10

SignalExecutorMap – Another way to map AS3-Signal to Command in Robotlegs

I love both Robotlegs and AS3-Signals so much, and many thanks to Joel Hooks's SignalCommandMap, they work together great now. When I saw [Execute] tag in dawn I thought if I can do its way for SignalCommand. So, Here is my SignalExecutorMap. I used it in a simple slide player for my Robotlegs slides.

To use it, put the same count and type of params in the execute() method of the Command as its trigger Signal.

// The signal in SignalBus:
public const turnToPageRequested:Signal = new Signal(int);
// Execute method in Command:
public function execute(index:int):void
// Dispatch the signal
signalBus.turnToPageRequested.dispatch(0);

It's not a common solution, because it eliminates the possibility of using other Command impls already in existence. So I created it as SignalExecutorMap instead of expanding SignalCommandMap, and just leave it a single class for personal use. I shared it just in case somebody want it like me because:

  • 1, By now (until Robotlegs 1.1) SignalCommandMap will unmap the value passed by Signal.
  • 2, Don't want to inject base type like
    [Inject]
    public var index:int;
  • 3, Don't want to create VO class just for being passed by Signal to avoid 1 and 2.

I'm sure SignalCommandMap will get better with Robotlegs 1.1 and better later. Robotlegs and as3-signals, they were born to work together :)

  • http://kevincao.com kyoji

    great job, eidiot. i’ve recently digged into robotlegs+signals too.

    have u try to use SignalCommandMap to map a signal with XML as its payload?

    like: new Signal(XML)

    when i map this kind of signal to a command, i got an error.

  • eidiot

    @kyoji Several places in Robotlegs use someObject.constructor as someObject’s Class type. But there seems be a bug that someXML.constructor is XMLList instead of Class. That’s the problem. Before it’s fully fixed (maybe Robotlegs 1.1 I think) suggest you not use DI for XML type. Or you can use my SignalExecutorMap for passing XML value to Command ;)

  • http://kevincao.com kyoji

    thanks, i am using custom vo to bypass this issue, definitely give SignalExecutorMap a try!

  • http://eidiot.net/en/ eidiot

    VO is a good way to pass values :)

  • BrainstormWilly

    Excellent! I liked the SignalCommandMap way of doing value class injections, but I kept running into injection warnings. I looked at using http://blog.sjhewitt.co.uk/2010/02/robotlegs-and-as3signals-injecting-interfaces-and-named-arguments/, but that meant mangling base classes I would want to update later. The only thing I’m a little leery about with this technique is passing the args via the execute() function. Can cause issues with interfaces and unit testing. But I’m using it for now.