this solution is very easy but has disadvantages. while trying the
listener-method i tried also your method ( and it works, no doubt ). but i
would like to solve this problem "cleanly", like "var result =
rpc.getResult()" ...

the disadvantage is that you must process data inside that callbackfunction.
its much better than processing data inside the handler, thats for sure. but
i want it to be more simple. :)

this is what i got:

var rpc = new qxgui.utils.Rpc;
            
rpc.callAsync( "doLogin", [ username, userpw ], function( result )
{
   alert( result );
});

but i want it this way:

var rpc = new qxgui.utils.Rpc;
            
rpc.callAsync( "doLogin", [ username, userpw ] );

var result = rpc.getResult();

is there something like pointers or refrences ( for primitive vars ) in js?
i dont know this language very well, i did not even read a book. :)


Noggin182 wrote:
> 
> this.__rpc.addListener( "completed", function(e)
> {
>      this.__result = e.getData();
> }, this );
> 
> alert( this.__result );
> 
> Here, you pass the callback function to addListener which then returns 
> immediately. Your alert is called before the result is ready.
> 
> It is a bit strange to get use to at first, and you will no doubt fight 
> the change, but you have to write your code so it works asyncrounously.
> 
> Something like this (changed marked ***like this***):
> 
> callAsync: function( method, args, ***fHandler***)
> {
>    var handler = function( result, exc, id )
>    {
>      if ( exc == null )
>      {
>        *** fHandler(result); ***
>      }
>      else {
>        alert( "RPC-Exception: " + exc + " ( ID: " + id + ")" );
>      }
>    };
> 
>    this.__rpcRunning = this.__rpc.callAsync( handler, method, args);
> }
> 
> 
> Then later in your code:
> var rpc = new qxgui.utils.Rpc;
> rpc.callAsync( "doLogin", [ username, userpw ], function(result)
> {
>    alert(result);
> });
> 
> 
> 
> sNIk wrote:
>> hello!
>> 
>> i would prefer the first option. ;)
>> 
>> i changed my code to this:
>> 
>>         callAsync: function( method, args )
>>         {
>>             var handler = function( result, exc, id )
>>             {
>>                 if ( exc == null )
>>                 {
>>                     //alert( result );
>>                 }
>>                 else {
>>                     alert( "RPC-Exception: " + exc + " ( ID: " + id + ")"
>> );
>>                 }
>>             };
>>             
>>             this.__rpcRunning = this.__rpc.callAsync( handler, method,
>> args
>> );
>>             
>>             this.__rpc.addListener( "completed", function(e)
>>             {
>>                 this.__result = e.getData();
>>             }, this );
>>             
>>             alert( this.__result );
>>         }
>> 
>> but i get "null" as value .. whats wrong? :)
>> 
>> 
>> Noggin182 wrote:
>>> Hi Again,
>>> The call to the backend is asyncrounous, your 
>>> qxgui.utils.Rpc.callAsync() function will return immediately.
>>>
>>> There are two ways forward, you can either change your class so it fires 
>>> an "complete" event, or change the function so it accepts a callback.
>>>
>>>  From the callAsync() function it looks like you are expierenced enough 
>>> to do either without help.
>>>
>>> The two choices would make your calling code look like this:
>>>
>>> Option 1.)
>>>
>>> var rpc = new qxgui.utils.Rpc;
>>> rpc.callAsync( "doLogin", [ username, userpw ] );
>>> rpc.addListener("complete", function(e)
>>> {
>>>    var result = e.getData();
>>> });
>>>
>>> Option 2.)
>>>
>>> var rpc = new qxgui.utils.Rpc;
>>> rpc.callAsync( "doLogin", [ username, userpw ], function(result)
>>> {
>>>    alert(result);
>>> });
>>>
>>>
>>> If you need more help, just decide first which one best meets your 
>>> requirements and let us know :)
>>>
>>> HTH,
>>> Matt
>>>
>>>
>>> sNIk wrote:
>>>> hello there. i want to simplify the usage of rpc and ran into a problem
>>>> with
>>>> the handler. example:
>>>>
>>>> usage:
>>>> -------------------------------------------------------------------------------------
>>>>
>>>> var rpc = new qxgui.utils.Rpc;
>>>> rpc.callAsync( "doLogin", [ username, userpw ] );
>>>> var result = rpc.getResult();
>>>>
>>>>
>>>> class:
>>>> -------------------------------------------------------------------------------------
>>>>
>>>> qx.Class.define("qxgui.utils.Rpc",
>>>> {
>>>>     extend: qx.core.Object,
>>>>     
>>>>     construct: function( url, service )
>>>>     {
>>>>         // standard-paramenter
>>>>        some statements ...
>>>>         
>>>>         // konfigurieren
>>>>         rpc = new qx.io.remote.Rpc( url, service );
>>>>         
>>>>         rpc.setTimeout( this.__timeout );
>>>>         rpc.setCrossDomain( this.__crossDomain );
>>>>         
>>>>         this.__rpc = rpc;
>>>>     },
>>>>     
>>>>     members:
>>>>     {
>>>>         // eigenschaften
>>>>        
>>>> ////////////////////////////////////////////////////////////////////////
>>>>         
>>>>         __url: "xxx",
>>>>         __service: "xxx",
>>>>         __timeout: 5000,
>>>>         __crossDomain: true,
>>>>         
>>>>         __rpc: null,
>>>>         __id: null,
>>>>         __exc: null,
>>>>         __result: null,
>>>>         __rpcRunning: null,
>>>>         
>>>>         
>>>>         // methoden
>>>>        
>>>> ////////////////////////////////////////////////////////////////////////
>>>>         
>>>>         callAsync: function( method, args )
>>>>         {
>>>>             var handler = function( result, exc, id )
>>>>             {
>>>>                 if ( exc == null )
>>>>                 {
>>>>                     this.__result = result;
>>>>                 }
>>>>                 else {
>>>>                     alert( "RPC-Exception: " + exc );
>>>>                 }
>>>>             };
>>>>             
>>>>             this.__rpcRunning = this.__rpc.callAsync( handler, method,
>>>> args
>>>> );
>>>>         },
>>>>         
>>>>         isRpcRunning: function()
>>>>         {
>>>>             return this.__rpcRunning;
>>>>         },
>>>>         
>>>>         getResult: function()
>>>>         {
>>>>             return this.__result;
>>>>         }
>>>>     }
>>>> });
>>>>
>>>>
>>>> how do i get the result into the right scope?
>>>
>>> ------------------------------------------------------------------------------
>>> The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
>>> production scanning environment may not be a perfect world - but thanks
>>> to
>>> Kodak, there's a perfect scanner to get the job done! With the NEW KODAK
>>> i700
>>> Series Scanner you'll get full speed at 300 dpi even with all image 
>>> processing features enabled. http://p.sf.net/sfu/kodak-com
>>> _______________________________________________
>>> qooxdoo-devel mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
>>>
>>>
>> 
> 
> 
> ------------------------------------------------------------------------------
> The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
> production scanning environment may not be a perfect world - but thanks to
> Kodak, there's a perfect scanner to get the job done! With the NEW KODAK
> i700
> Series Scanner you'll get full speed at 300 dpi even with all image 
> processing features enabled. http://p.sf.net/sfu/kodak-com
> _______________________________________________
> qooxdoo-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
> 
> 

-- 
View this message in context: 
http://n2.nabble.com/problems-with-rpc-abstraction-%28-using-this-in-callback-function-%29-tp2792185p2794927.html
Sent from the qooxdoo mailing list archive at Nabble.com.


------------------------------------------------------------------------------
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you'll get full speed at 300 dpi even with all image 
processing features enabled. http://p.sf.net/sfu/kodak-com
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to