PDA

View Full Version : Action versioning feature



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
};
}
});

evant
16 Jun 2009, 8:55 PM
I'm not so big on this. I mean, I can see where it could possibly be applied, but why not just update the client side code to match the server code?

azbok
17 Jun 2009, 8:56 AM
This feature is more of a "to each his own" which is useful to me but probably less useful to many other people so probably shouldn't be part of Ext itself.

For me, lets say I have a web service with multiple interfaces, maybe web sites and desktop apps and who knows what is using a particular web service function. If I have all sorts of stuff in production, I can't just go and monkey up the web service in a backwards incompatible way. For me, I'd rather have a new function version which can be used in new code and *eventually* all of the other code in production could be upgraded to use the new version, but in the mean time everything is still using the old version.

By using version numbers, the namespace of web service functions doesn't need to be polluted. You still lets say have the "Login" service but it's version 2 instead of either making a new function named Login2 or instead of having a cruftier Login service that supports both the new and old methods.

I agree that if it's just 1 application using the 1 web service, then ya, just update the client side code to match the server side code.

I'm not suggesting really that this be part of Ext... just that other people may find it useful.

Thanks :)

thesilentman
18 Jul 2009, 10:04 AM
Hello azbok,
just read your thread.

I am using some kind of versioning like this in a project, too.
but I just pass the version string as part of the parameters and act upon it at the method on the php side.

Works for me like this...

You can always extend Ext.direct's capabilities though :)

Greets,
Frank