tag:robotlegs.tenderapp.com,2009-10-18:/discussions/robotlegs-2/1337-commands-with-parameters-using-signalsRobotlegs: Discussion 2013-04-12T09:04:14Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/262334342013-04-04T22:24:47Z2013-04-04T22:24:49ZCommands with parameters using signals..<div><p>Hi there<br>
I have a question around using commands, with signals.<br>
Basically I am wanting to pass parameters along with a signal to a
command and onto a service layer..</p>
<p>I have installed the signalsCommandMap, found here<br>
<a href=
"https://github.com/pixels4nickels/robotlegs-extensions-SignalCommandMap">
https://github.com/pixels4nickels/robotlegs-extensions-SignalComman...</a></p>
<p>and as3Signals v0.9-beta, also found in the test bin in the
above link.</p>
<p>commandMap.map( GetServiceSignal ).toCommand( GetServicesCommand
);</p>
<p>via a mediator<br>
'getServieSignal.dispatch(requestData);'</p>
<p>'GetServicesCommand.as [Inject] public var services:Service; //
is singleton</p>
<p>override public function execute():void {
services.getData(...rest); }'</p>
<p>I can see how I can use signals to trigger the notifications,
returning back to the originator..</p>
<p>but passing data or objects, through to the command seems a bit
obscure to me.</p>
<p>any help would be much appreciated.</p>
<p>Brndn</p></div>brndntag:robotlegs.tenderapp.com,2009-10-18:Comment/262334342013-04-04T23:56:31Z2013-04-04T23:56:31ZCommands with parameters using signals..<div><p>Hello Brndn,</p>
<p>I believe that you should be able to [Inject] the Signal
parameters into the Command.</p>
<p>Hope that helps!</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/262334342013-04-05T11:39:03Z2013-04-05T14:39:18ZCommands with parameters using signals..<div><p>Hi Shaun<br>
thanks for the response.<br>
Yes I thought that may be the case.<br>
I guess I was hoping for solution similar to the Parsley Command
pattern.</p>
<p>Cheers</p></div>brndntag:robotlegs.tenderapp.com,2009-10-18:Comment/262334342013-04-05T14:45:01Z2013-04-05T14:45:01ZCommands with parameters using signals..<div><p>What exactly do you mean? I know it's possible to inject
parameters into the execute method of commands in Parsley (Could be
I'm mistaken, it's a REALLY long time since I've last looked at
Parsley) Is that what you were hoping for here too?</p></div>creynderstag:robotlegs.tenderapp.com,2009-10-18:Comment/262334342013-04-06T19:24:46Z2013-04-07T07:50:34ZCommands with parameters using signals..<div><p>Hi there</p>
<p>I was hoping to send a payload with via the
signal.dispatch();</p>
<p>But I am not sure.</p>
<p>Using commands in parsley, you can define the execute method,
and using events you can pass requests down the pipe. So to
speak.</p>
<p>This approach lends itself to be more asynchronous.</p>
<p>As opposed to setting properties, in an injected singleton.
unless I have kinda missed the general flow of objects in the RL
lifecycle and echo system.</p>
<p>Anyway this is simple parsley dynamic command example..</p>
<p>Context Builder config:<br>
<code><spicefactory:DynamicCommand type="{ServiceTokenCommand}"
selector="{ServiceTokenEvent.SERVICE_TOKEN}"
execute="execute"/></code></p>
<p>ServiceTokenCommand:<br>
<code>public function execute(event:ServiceTokenEvent):AsyncToken {
var token:AsyncToken = event.token; token.addResponder(new
AsyncResponder(responseResult, responseFault, event.token));
asyncRequestManager.addRequest(token); return token; }</code></p>
<p>if i remember correctly there is a default result and fault
method.</p></div>brndntag:robotlegs.tenderapp.com,2009-10-18:Comment/262334342013-04-07T11:42:48Z2013-04-07T11:42:48ZCommands with parameters using signals..<div><blockquote>
<p>I was hoping to send a payload with via the
signal.dispatch();</p>
</blockquote>
<p>Yep, that <em>is</em> how it's done.</p>
<pre>
<code>signal.dispatch(foo);
//command
[Inject]
public var foo:Foo;
[Inject]
public var service:IAmNotNecessarilyASingletonService
public function execute():void{
service.send( foo );
}</code>
</pre>
<blockquote>
<p>Using commands in parsley, you can define the execute method,
and using events you can pass requests down the pipe.</p>
</blockquote>
<p>That's the case with RL2 too, we're rewriting the command maps
and the possibility to use a method other than <code>execute</code>
will be added.</p>
<p>So you can take shortcuts if you want:</p>
<pre>
<code>signalCommandMap.map( FooSignal )
.toCommand( FooService)
.withExecuteMethod( 'send')</code>
</pre>
<p>However, in this case FooService will have to expose a
prop/setter which allows injection of the Foo payload.</p></div>creynderstag:robotlegs.tenderapp.com,2009-10-18:Comment/262334342013-04-07T19:33:49Z2013-04-07T19:33:50ZCommands with parameters using signals..<div><p>Hi Creynders</p>
<p>Thanks for the further clarification.</p>
<p>Does that mean I can do as below.</p>
<pre>
<code>signal.dispatch(new Foo(x,y,z));</code>
</pre>
<p>Or is the typed Foo injected into the class where the signal is
dispatched also.</p></div>brndntag:robotlegs.tenderapp.com,2009-10-18:Comment/262334342013-04-07T21:33:34Z2013-04-07T21:33:35ZCommands with parameters using signals..<div><p>Hi I am just looking at this method<br>
And pondering if I could pass the value objects into the command
execution.</p>
<p>I guess by doing this I have less injections between
controllers, models and commands.</p>
<p>I guess this would allow the same functionality as the
signal.add() handler which feels intuitive.</p>
<pre>
<code>protected function routeSignalToCommand(signal:ISignal, valueObjects:Array, commandClass:Class, oneshot:Boolean):void
{
.....
unmapSignalValues( signal.valueClasses, valueObjects );
if (isApproved)
{
command.execute();
}
.......
}</code>
</pre>
<p>something like this....<br></p>
<pre>
<code>
if(valueObjects)
command.execute(valueObjects);
else<br>
command.execute();</code>
</pre>
<p>any thoughts on this would be much appreciated, or if there
could be any forseen repercussions.</p></div>brndntag:robotlegs.tenderapp.com,2009-10-18:Comment/262334342013-04-07T22:18:36Z2013-04-07T22:18:38ZCommands with parameters using signals..<div><p>I guess this is where I can pull the RL2 repo and change the
ICommandMappingConfig, and CommandMapping for my specific use
case.</p></div>brndntag:robotlegs.tenderapp.com,2009-10-18:Comment/262334342013-04-07T22:48:14Z2013-04-07T22:48:14ZCommands with parameters using signals..<div><p>BTW, we're busy working on this side of things at the moment.
See the bottom of this thread:</p>
<p><a href=
"https://github.com/robotlegs/robotlegs-framework/issues/114">https://github.com/robotlegs/robotlegs-framework/issues/114</a></p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/262334342013-04-09T12:45:22Z2013-04-09T12:45:22ZCommands with parameters using signals..<div><p>Shaun<br>
cheers for the update.</p></div>brndntag:robotlegs.tenderapp.com,2009-10-18:Comment/262334342013-04-10T16:15:56Z2013-04-10T16:15:56ZCommands with parameters using signals..<div><p>Going to close this for now if there's anything else let us
know!</p></div>creynders