Commands with parameters using signals..

brndn's Avatar

brndn

04 Apr, 2013 10:24 PM

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

  1. Support Staff 1 Posted by Shaun Smith on 04 Apr, 2013 11:56 PM

    Shaun Smith's Avatar

    Hello Brndn,

    I believe that you should be able to [Inject] the Signal parameters into the Command.

    Hope that helps!

  2. 2 Posted by brndn on 05 Apr, 2013 11:39 AM

    brndn's Avatar

    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

  3. Support Staff 3 Posted by creynders on 05 Apr, 2013 02:45 PM

    creynders's Avatar

    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. 4 Posted by brndn on 06 Apr, 2013 07:24 PM

    brndn's Avatar

    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.

  5. Support Staff 5 Posted by creynders on 07 Apr, 2013 11:42 AM

    creynders's Avatar

    I was hoping to send a payload with via the signal.dispatch();

    Yep, that is how it's done.

    signal.dispatch(foo);
    
    //command
    [Inject]
    public var foo:Foo;
    
    [Inject]
    public var service:IAmNotNecessarilyASingletonService
    
    public function execute():void{
        service.send( foo );
    }
    

    Using commands in parsley, you can define the execute method, and using events you can pass requests down the pipe.

    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:

    signalCommandMap.map( FooSignal )
        .toCommand( FooService)
        .withExecuteMethod( 'send')
    

    However, in this case FooService will have to expose a prop/setter which allows injection of the Foo payload.

  6. 6 Posted by brndn on 07 Apr, 2013 07:33 PM

    brndn's Avatar

    Hi Creynders

    Thanks for the further clarification.

    Does that mean I can do as below.

    signal.dispatch(new Foo(x,y,z));
    

    Or is the typed Foo injected into the class where the signal is dispatched also.

  7. 7 Posted by brndn on 07 Apr, 2013 09:33 PM

    brndn's Avatar

    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.

    protected function routeSignalToCommand(signal:ISignal, valueObjects:Array, commandClass:Class, oneshot:Boolean):void
        {
         .....
                unmapSignalValues( signal.valueClasses, valueObjects );
                if (isApproved)
                {
                   command.execute();
                }
          .......
        }
    

    something like this....

    
    if(valueObjects)
        command.execute(valueObjects);
    else
    command.execute();

    any thoughts on this would be much appreciated, or if there could be any forseen repercussions.

  8. 8 Posted by brndn on 07 Apr, 2013 10:18 PM

    brndn's Avatar

    I guess this is where I can pull the RL2 repo and change the ICommandMappingConfig, and CommandMapping for my specific use case.

  9. Support Staff 9 Posted by Shaun Smith on 07 Apr, 2013 10:48 PM

    Shaun Smith's Avatar

    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. 10 Posted by brndn on 09 Apr, 2013 12:45 PM

    brndn's Avatar

    Shaun
    cheers for the update.

  11. Support Staff 11 Posted by creynders on 10 Apr, 2013 04:15 PM

    creynders's Avatar

    Going to close this for now if there's anything else let us know!

  12. creynders closed this discussion on 10 Apr, 2013 04:15 PM.

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