Injecting different events

d4rklit3's Avatar

d4rklit3

04 Oct, 2011 12:40 AM

Lets say i have several event types that may call a command, is there a way to inject the event into the command as an interface or abstract so that it can accept different events?

  1. 1 Posted by krasimir on 04 Oct, 2011 06:46 AM

    krasimir's Avatar

    Hello, just use:
    [Inject] public var event:YourEventType; in your command. They by using event.type you will be able to catch the different situations.

  2. 2 Posted by d4rklit3 on 04 Oct, 2011 05:01 PM

    d4rklit3's Avatar

    Sorry, I meant event class not event.type. for instance, I want a command to receive a ViewEvent and/or a ModelEvent both those event types have the same abstract class as its parent, but the injector doesn't like it. I suppose this isn't in accordance to best practices anyways.

  3. 3 Posted by Stray on 04 Oct, 2011 10:36 PM

    Stray's Avatar

    Hi there, you can handle this by pushing the actual work done by the command to a helper command that you call within each individual command which is mapped to each specific event.

    Then I pass the injected event to the worker command manually.

    So it's like this:

    [Inject]
    public var event:SomeEvent;

    public override function execute():void
    {
    var workerCommand:SomeWorkCommand = injector.instantiate(SomeWorkerCommand);
    workerCommand.event = event;
    workerCommand.execute();
    }

    This way the workerCommand can have the generic / base event type, but the injector will still be happy.

    Let me know if that doesn't make sense - I'm a bit tired!

    Stray

  4. 4 Posted by d4rklit3 on 04 Oct, 2011 10:58 PM

    d4rklit3's Avatar

    This makes sense. It just seems like a pretty intense workaround. I think I'll just manage my event classes better so I don't have to do this :) Thanks Stray

  5. 5 Posted by Cotton Hou on 07 Oct, 2011 08:19 AM

    Cotton Hou's Avatar

    Hi there, I'd a patch for this kind of scenario, it has been merged into the development branch of RL and should be out soon in the next RL 1.x drop.

    You can review the pull request of this with whole discussion at here.
    The whole diffs of this patch with test case at here.

    And if you're using the latest stable release of RL(v1.4.0) and don't want to wait for the next droping, you can just patch this single file into your current project without touch SWC or Ant etc.

    Let me know that works or not in your case, thanks.

  6. Ondina D.F. closed this discussion on 16 Nov, 2011 09:16 AM.

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