tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/687-injecting-different-eventsRobotlegs: Discussion 2018-10-18T16:35:32Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/103902912011-10-04T06:46:08Z2011-10-04T06:46:50ZInjecting different events<div><p>Hello, just use:<br>
[Inject] public var event:YourEventType; in your command. They by
using event.type you will be able to catch the different
situations.</p></div>krasimirtag:robotlegs.tenderapp.com,2009-10-18:Comment/103902912011-10-04T17:01:59Z2011-10-04T17:01:59ZInjecting different events<div><p>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.</p></div>d4rklit3tag:robotlegs.tenderapp.com,2009-10-18:Comment/103902912011-10-04T22:36:00Z2011-10-04T22:36:00ZInjecting different events<div><p>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.</p>
<p>Then I pass the injected event to the worker command
manually.</p>
<p>So it's like this:</p>
<p>[Inject] public var event:SomeEvent;</p>
<p>public override function execute():void<br>
{</p>
<pre>
<code>var workerCommand:SomeWorkCommand = injector.instantiate(SomeWorkerCommand);
workerCommand.event = event;
workerCommand.execute();</code>
</pre>
<p>}</p>
<p>This way the workerCommand can have the generic / base event
type, but the injector will still be happy.</p>
<p>Let me know if that doesn't make sense - I'm a bit tired!</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/103902912011-10-04T22:58:25Z2011-10-04T22:58:25ZInjecting different events<div><p>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</p></div>d4rklit3tag:robotlegs.tenderapp.com,2009-10-18:Comment/103902912011-10-07T08:19:19Z2011-10-07T08:52:27ZInjecting different events<div><p>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.</p>
<p>You can review the pull request of this with whole discussion at
<a href=
"https://github.com/robotlegs/robotlegs-framework/pull/16">here</a>.<br>
The whole diffs of this patch with test case at <a href=
"https://github.com/robotlegs/robotlegs-framework/commit/ef00083485306cff6f87bc1d826c5d6c5982797b">
here</a>.</p>
<p>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
<a href="https://github.com/robotlegs/robotlegs-framework/blob/development/src/org/robotlegs/base/CommandMap.as">
this</a> single file into your current project without touch SWC or
Ant etc.</p>
<p>Let me know that works or not in your case, thanks.</p></div>Cotton Hou