Question

I have a bunch of warning messages like this appear when using Robotlegs/Signals. Everytime this command class executes, which is every 2-3 seconds ..this message displays below

If you have overwritten this mapping intentionally you can use "injector.unmap()" prior to your replacement mapping in order to avoid seeing this message. Warning: Injector already has a rule for type "mx.messaging.messages::IMessage", named "".

The command functions fine otherwise but I think I'm doing something wrong anyhow.

    public class MessageReceivedCommand extends SignalCommand
    {

        [Inject]
        public var message:IMessage;

            ...etc.. do something with message..
    }

the application context doesnt map IMessage to this command, as I only see an option to mapSignalClass , besides the payload is received fine.

Wonder if anyone knows how I might either fix or suppress this message. I've tried calling this as the warning suggests

injector.unmap(IMessage, "")

but I receive an error - no mapping found for ::IMessage named "".

Thanks

Edit: A bit more info about the error

Here is the signal that I dispatch to the command

public class GameMessageSignal extends Signal
{   
    public function GameMessageSignal()
    {
        super(IMessage);
    }
}

which is dispatched from a IPushDataService class

    gameMessage.dispatch(message.message);

and the implementation is wired up in the app context via

injector.mapClass(IPushDataService, PushDataService);

along with the signal

signalCommandMap.mapSignalClass(GameMessageSignal, MessageReceivedCommand);

Edit #2: Probably good to point out also I inject an instance of GameMessageSignal into IPushDataService

public class PushDataService extends BaseDataService implements IPushDataService
{
   [Inject]
   public var gameMessage:GameMessageSignal;

   //then

   private function processMessage(message:MessageEvent):void
   {
          gameMessage.dispatch(message.message);
   }
}

Edit:3

The mappings i set up in the SignalContext:

injector.mapSingleton(IPushDataService);

injector.mapClass(IPushDataService, PushDataService);
Was it helpful?

Solution

Okay, I took a longer look at the Signals extension, and I believe this is in fact a bug. A related issue has been filed on github a year ago, but it has not been fixed yet. The warning has something to do with the way that signals are mapped to commands:

(From SignalCommandMap)

protected function routeSignalToCommand(signal:ISignal, valueObjects:Array, commandClass:Class, oneshot:Boolean):void
{
    mapSignalValues( signal.valueClasses, valueObjects );
    createCommandInstance( commandClass ).execute();
    unmapSignalValues( signal.valueClasses, valueObjects );
    (...)

The mappings are assigned only just before the call to mySignalCommand.execute(), and removed immediately after. This is why you can't manually unmap().

The problem here is due to a chaining of signals, i.e. the same signal fires again during the execution of your command, so that the mapping occurs twice - "nested" signals, so to speak:

Signal.dispatch
    => mapValues 
    => execute() 
        => Signal.dispatch 
            => mapValues 
            => execute() 
            => unmapValues()
    => unmapValues()

I've had a similar problem with event mappings in the RobotLegs2 framework, and commited a bug fix. Therefore, I'm sure this will no longer bother anyone once using RL2, but until then you might just want to apply an equivalent patch to the Signals extension and use it as a workaround.

It should be quite simple: Just decouple instantiation and execution of the Command. In the above-mentioned routeSignalToCommand() method in SignalCommandMap, replace this:

mapSignalValues( signal.valueClasses, valueObjects );
createCommandInstance( commandClass ).execute();
unmapSignalValues( signal.valueClasses, valueObjects );

with this:

mapSignalValues( signal.valueClasses, valueObjects );
var command:* = createCommandInstance( commandClass );
unmapSignalValues( signal.valueClasses, valueObjects );
command.execute();

Now since I have neither RL1 nor Signals in use, I can't test it myself - just give it a try and comment if you have any problems.

OTHER TIPS

These mapping issues are fixed in the SignalCommandMap extension for RL2. You can find it here: https://github.com/pixels4nickels/robotlegs-extensions-SignalCommandMap I have tried to fix issues and keep things updated in a timely manner.(chaining multiple commands works as well)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top