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.