Do you let the commands response to services

Nikos Katsikanis's Avatar

Nikos Katsikanis

08 Oct, 2010 03:54 PM via web

From my understanding people prefer to let the commands response to services and update the application rather than handling that stuff in services. What is your prefered method of handing the different responses from methods in your services in the command. My services typically use remote objects. Should the methods in the service return asnctokens or responers?

  1. Support Staff 2 Posted by Ondina D.F. on 09 Oct, 2010 10:48 AM

    Ondina D.F.'s Avatar

    Hi Nikos,

    2 approaches in one of my applications:

    • 1 SomeService
    public function someRequest():void
    {
    responder=new Responder(onSomeResult, onServerFault);
    service.source="SomeRemoteClass";
    service.getOperation("someRemoteMethod ").arguments=remoteModel.argumentsList;
    var asyncToken:AsyncToken=service.getOperation("someRemoteMethod").send();
    asyncToken.addResponder(responder);
    }
    
    protected function onSomeResult(event:ResultEvent):void{
    
        someModel.resultsArray=ArrayUtil.toArray(event.result);
    }
    

    SomeModel dispatches an event with SomeVO as a payload

    SomeMediator listens for that event and passes the data to the SomeView

    • 2 SomeService onSomeResult dispatches an event with the result as the payload, SomeMediator listens for it, and it does something because of the payload or with it...
      Sometimes I just need to dispatch an event from the Service without a payload, for example after saving data on server the Mediator just needs a confirmation that everything worked fine

    Ondina

  2. Support Staff 3 Posted by Joel Hooks on 09 Oct, 2010 03:15 PM

    Joel Hooks's Avatar

    I like the Promise approach that Shaun has here:

    http://gist.github.com/470851

  3. 4 Posted by Nikos Katsikanis on 13 Oct, 2010 12:03 PM

    Nikos Katsikanis's Avatar

    Is the Promise approach still valid when we have the asyncCommand?

  4. 5 Posted by Nikos Katsikanis on 15 Oct, 2010 10:25 AM

    Nikos Katsikanis's Avatar

    After thinking about this more it feels more natural to do all the after amfService method completion stuff in the actual service(using callbacks ) rather than passing it back to the command via callbacks in the command as I feel all this does is make it harder to figure out what it going on in your app.

    Opinions?

  5. Nikos Katsikanis closed this discussion on 06 Nov, 2010 12:36 PM.

Comments are currently closed for this discussion. You can start a new one.