Possible bug when mapping two commands to the same event with diffrent guards

jakub.gondek's Avatar

jakub.gondek

31 Jan, 2013 10:24 AM

Hi,

I'm not an experienced Robotlegs user, so code below may not follow best practices, but it certainly acts a bit weird.

/**
 * Author: Jakub Gondek
 */
package
{
import flash.events.Event;
import flash.events.IEventDispatcher;
import flash.utils.setTimeout;

import robotlegs.bender.extensions.eventCommandMap.api.IEventCommandMap;
import robotlegs.bender.framework.api.IConfig;
import robotlegs.bender.framework.api.IContext;
import robotlegs.bender.framework.api.LogLevel;

public class ApplicationConfig implements IConfig
{
    [Inject]
    public var context : IContext;

    [Inject]
    public var eventCommandMap : IEventCommandMap;

    [Inject]
    public var eventDispatcher : IEventDispatcher;

    public static const TEST : String = "test";

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

        eventCommandMap
                .map(TEST, Event)
                .toCommand(Command1)
                .withGuards(
                        OnlyIfCondition1
                );

        eventCommandMap
                .map(TEST, Event)
                .toCommand(Command2)
                .withGuards(
                        OnlyIfCondition2
                );
        context.afterInitializing(function () : void
        {
            eventDispatcher.dispatchEvent(new Event(TEST));
            setTimeout(function () : void
            {
                TEST_RobotlegsBug.condition = !TEST_RobotlegsBug.condition;
                eventDispatcher.dispatchEvent(new Event(TEST));
            }, 5000);
        });
    }
}
}

internal class Command1
{
    public function execute() : void
    {
        trace("Command 1 executed");
    }
}

internal class Command2
{
    public function execute() : void
    {
        trace("Command 2 executed");
    }
}

internal class OnlyIfCondition1
{
    public function approve() : Boolean
    {
        trace("OnlyIfCondition1: " + TEST_RobotlegsBug.condition);
        return TEST_RobotlegsBug.condition;
    }
}

internal class OnlyIfCondition2
{
    public function approve() : Boolean
    {
        trace("OnlyIfCondition2: " + (!TEST_RobotlegsBug.condition));
        return !TEST_RobotlegsBug.condition;
    }
}

Here is the trace that I get:

OnlyIfCondition1: false
OnlyIfCondition2: true
Command 2 executed
OnlyIfCondition1: true
Command 1 executed
OnlyIfCondition2: false
Command 1 executed

and here is what I would expect:

OnlyIfCondition1: false
OnlyIfCondition2: true
Command 2 executed
OnlyIfCondition1: true
OnlyIfCondition2: false
Command 1 executed

I'm using Robotlegs 2.0.0b4

Best regards
Jakub Gondek

  1. Support Staff 1 Posted by Ondina D.F. on 31 Jan, 2013 05:13 PM

    Ondina D.F.'s Avatar

    Hi Jakub,

    I commented on github:
    https://github.com/robotlegs/robotlegs-framework/issues/110

    Ondina

  2. Support Staff 2 Posted by Shaun Smith on 31 Jan, 2013 10:20 PM

    Shaun Smith's Avatar

    Thanks, fixed!

  3. Shaun Smith closed this discussion on 31 Jan, 2013 10:20 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