azbok
16 Jun 2009, 4:07 PM
In my server side setup, I use action versions. The server side of course needs to call the proper internal function depending on the version number.
Situation:
Suppose your code is in production. Now suppose you realized there is a mistake and the server side action needs to be upgraded but it won't be compatible! On the server side, you can create a new version of the action function. On the Ext side, only the new code will specify the new version. It makes for a very nice upgrade path.
Example:
Ext.Direct.addProvider({
"url":"remoting.php",
"type":"remoting",
"actions":{
"AlbumList":[{
"name":"getAll",
"version":"1.0"
},{
"name":"add",
"version":"1.0"
}]
}
});
Then you can adjust your Ext code to be:
Ext.override(Ext.direct.RemotingProvider, {
doCall : function( c, m, args ) {
var data = null, hs = args[m.len], scope = args[m.len+1];
if(m.len !== 0){
data = args.slice(0, m.len);
}
var t = new Ext.Direct.Transaction({
provider: this,
args: args,
action: c,
method: m.name,
version: m.version, // New version feature
data: data,
cb: scope && typeof hs == 'function' ? hs.createDelegate(scope) : hs
});
if( this.fireEvent('beforecall', this, t) !== false ) {
Ext.Direct.addTransaction(t);
this.queueTransaction(t);
this.fireEvent('call', this, t);
}
},
getCallData: function( t ) {
return {
action : t.action,
method : t.method,
version : t.version, // New version feature
data : t.data,
type : 'rpc',
tid : t.tid
};
}
});
Situation:
Suppose your code is in production. Now suppose you realized there is a mistake and the server side action needs to be upgraded but it won't be compatible! On the server side, you can create a new version of the action function. On the Ext side, only the new code will specify the new version. It makes for a very nice upgrade path.
Example:
Ext.Direct.addProvider({
"url":"remoting.php",
"type":"remoting",
"actions":{
"AlbumList":[{
"name":"getAll",
"version":"1.0"
},{
"name":"add",
"version":"1.0"
}]
}
});
Then you can adjust your Ext code to be:
Ext.override(Ext.direct.RemotingProvider, {
doCall : function( c, m, args ) {
var data = null, hs = args[m.len], scope = args[m.len+1];
if(m.len !== 0){
data = args.slice(0, m.len);
}
var t = new Ext.Direct.Transaction({
provider: this,
args: args,
action: c,
method: m.name,
version: m.version, // New version feature
data: data,
cb: scope && typeof hs == 'function' ? hs.createDelegate(scope) : hs
});
if( this.fireEvent('beforecall', this, t) !== false ) {
Ext.Direct.addTransaction(t);
this.queueTransaction(t);
this.fireEvent('call', this, t);
}
},
getCallData: function( t ) {
return {
action : t.action,
method : t.method,
version : t.version, // New version feature
data : t.data,
type : 'rpc',
tid : t.tid
};
}
});