views:

32

answers:

1

I am making a sequence of Ajax calls using the Ext.Direct module. I want to save some data when I make each call, and then match each return value with the correct call.

In the server call, Ext provide a tid property (presumable "transaction identifier") in the JSON packet which it uses match return values to calls. Problem is, there doesn't seem to be any documented way for my client-side Javascript to capture the tid of the outgoing call.

The following method works, but it makes use of the undocumented Ext.Direct.TID property. Assuming that my.namespace.my_action.my_method is an Ext.Direct API call that has been properly configured:

// Set up a global object in which to store data about pending calls
pendingCalls = {};

.
.
.

// Make a call to the server-side routine, and queue the data
my.namespace.my_action.my_method( call_data );
pendingCalls[ Ext.Direct.TID ] = call_data;

.
.
.
//The handler of the Ext.direct.Provider's "data" event
onData = function( provider, data ) {
    if data.type == "rpc" {
        // Recover the original call_data
        call_data = pendingCalls[ data.tid ];

        // Do something with call_data and data.result
    }
}

I don't like using the private internals of the Ext.Direct class. Is there an official way to do this, using Ext.Direct's public interface?

A: 

The solution I posted in the question works, even though its undocumented. And since nobody's posted another way of doing this, I'll stick with it.

Dan Menes