Enhancing SignalCommandMap to allow dispatching multiple value objects of the same class type

24 views
Skip to first unread message

Zack Pierce

unread,
Sep 26, 2010, 8:02:25 PM9/26/10
to Robotlegs AS3
Hi, I'm looking for feedback on a recent enhancement I've made to Joel
Hooks' excellent SignalCommand extension.

http://github.com/ZackPierce/signals-extensions-CommandSignal

The thought was "how could one dispatch two or more value objects of
the same class type and have these value objects injected into
specific properties of the relevant Command?"

The canonical, and by far preferred solution is "wrap your multiple
values into a custom value object class." However, in some situations
the wrapper approach may be less desirable. Perhaps the signal in
question has a set parameter list with multiple alike class types
fixed in place by requirements beyond an individual programmer's
control. Perhaps there are strong disincentives regarding profligate
custom class introduction.

The solution I've arrived at is to add support for name-based
injection. A signal could optionally implement INameableDispatcher,
which provides an array of Strings to be associated with the dispatch
parameters. These strings are then used in SignalCommandMap to fill
in the optional "named" parameter of the injector.mapValue call
responsible for creating rules for injecting a signal's dispatched
value objects.

An example.

var signal:NameableSignal = new NameableSignal(int, int);
signal.setDispatchParameterNames("firstInt", "secondInt");
signalCommandMap.mapSignal(signal, SampleCommand);
signal.dispatch(42, 314159);

public class SampleCommand {
[Inject(name="firstInt")]
public var firstInt:int;

[Inject(name="secondInt")]
public var secondInt:int;

public function execute():void {
trace(firstInt); // Should be 42 for this example
trace(secondInt); // Should be 314159 for this example
}
}

I know stringy name-based injection is rarely favored, but I figure
that the flexibility it grants could at least be supported in my
favorite robotlegs extension. One less thing to say "robotlegs
+signals can't do that" about.

Michael Cann

unread,
Sep 27, 2010, 5:47:26 AM9/27/10
to robo...@googlegroups.com
I too have given this some thought while I have been using the signal command map.

The solution I conceived of is just to inject the params into the execute() method.

so you have something that looks like:

signal.dispatch("hello","world");

and in the command:

public function execute(str1:String, str2:String) : void
{
}

Would remove the need for extra meta-data.. 


--
You received this message because you are subscribed to the Google
Groups "Robotlegs" group.
To post to this group, send email to robo...@googlegroups.com
To unsubscribe from this group, send email to
robotlegs+...@googlegroups.com
for support visit http://knowledge.robotlegs.org



--
Mike Cann
http://www.mikecann.co.uk/
http://www.artificialgames.co.uk/
Reply all
Reply to author
Forward
0 new messages