Commands with parameters using signals..
Hi there
I have a question around using commands, with signals.
Basically I am wanting to pass parameters along with a signal to a
command and onto a service layer..
I have installed the signalsCommandMap, found here
https://github.com/pixels4nickels/robotlegs-extensions-SignalComman...
and as3Signals v0.9-beta, also found in the test bin in the above link.
commandMap.map( GetServiceSignal ).toCommand( GetServicesCommand );
via a mediator
'getServieSignal.dispatch(requestData);'
'GetServicesCommand.as [Inject] public var services:Service; // is singleton
override public function execute():void { services.getData(...rest); }'
I can see how I can use signals to trigger the notifications, returning back to the originator..
but passing data or objects, through to the command seems a bit obscure to me.
any help would be much appreciated.
Brndn
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
Support Staff 1 Posted by Shaun Smith on 04 Apr, 2013 11:56 PM
Hello Brndn,
I believe that you should be able to [Inject] the Signal parameters into the Command.
Hope that helps!
2 Posted by brndn on 05 Apr, 2013 11:39 AM
Hi Shaun
thanks for the response.
Yes I thought that may be the case.
I guess I was hoping for solution similar to the Parsley Command pattern.
Cheers
Support Staff 3 Posted by creynders on 05 Apr, 2013 02:45 PM
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?
4 Posted by brndn on 06 Apr, 2013 07:24 PM
Hi there
I was hoping to send a payload with via the signal.dispatch();
But I am not sure.
Using commands in parsley, you can define the execute method, and using events you can pass requests down the pipe. So to speak.
This approach lends itself to be more asynchronous.
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.
Anyway this is simple parsley dynamic command example..
Context Builder config:
<spicefactory:DynamicCommand type="{ServiceTokenCommand}" selector="{ServiceTokenEvent.SERVICE_TOKEN}" execute="execute"/>
ServiceTokenCommand:
public function execute(event:ServiceTokenEvent):AsyncToken { var token:AsyncToken = event.token; token.addResponder(new AsyncResponder(responseResult, responseFault, event.token)); asyncRequestManager.addRequest(token); return token; }
if i remember correctly there is a default result and fault method.
Support Staff 5 Posted by creynders on 07 Apr, 2013 11:42 AM
Yep, that is how it's done.
That's the case with RL2 too, we're rewriting the command maps and the possibility to use a method other than
execute
will be added.So you can take shortcuts if you want:
However, in this case FooService will have to expose a prop/setter which allows injection of the Foo payload.
6 Posted by brndn on 07 Apr, 2013 07:33 PM
Hi Creynders
Thanks for the further clarification.
Does that mean I can do as below.
Or is the typed Foo injected into the class where the signal is dispatched also.
7 Posted by brndn on 07 Apr, 2013 09:33 PM
Hi I am just looking at this method
And pondering if I could pass the value objects into the command execution.
I guess by doing this I have less injections between controllers, models and commands.
I guess this would allow the same functionality as the signal.add() handler which feels intuitive.
something like this....
any thoughts on this would be much appreciated, or if there could be any forseen repercussions.
8 Posted by brndn on 07 Apr, 2013 10:18 PM
I guess this is where I can pull the RL2 repo and change the ICommandMappingConfig, and CommandMapping for my specific use case.
Support Staff 9 Posted by Shaun Smith on 07 Apr, 2013 10:48 PM
BTW, we're busy working on this side of things at the moment. See the bottom of this thread:
https://github.com/robotlegs/robotlegs-framework/issues/114
10 Posted by brndn on 09 Apr, 2013 12:45 PM
Shaun
cheers for the update.
Support Staff 11 Posted by creynders on 10 Apr, 2013 04:15 PM
Going to close this for now if there's anything else let us know!
creynders closed this discussion on 10 Apr, 2013 04:15 PM.