Updated version: https://gist.github.com/1148887
qx.Class.define("tradingactive.UtilXhr", { extend : qx.core.Object, construct: function(url,data,cb,caller) { var req = new qx.io.request.Xhr(url,'POST'); if (data) req.setRequestData(data); req.addListener("success",function(e) { e=e.getTarget(); if (!e.getResponse()) { dialog.Dialog.error("Server error"); } else { var cb2=qx.lang.Function.bind(cb,caller); cb2(e.getResponse()); } },this); req.send(); } }); On Tue, Aug 16, 2011 at 2:34 PM, franck34 <franck....@gmail.com> wrote: > > > On Tue, Aug 16, 2011 at 2:06 PM, thron7 <thomas.herchenroe...@1und1.de>wrote: > >> >> >> On 08/16/2011 01:36 PM, franck34 wrote: >> > Here is the "good" one : >> > >> > https://gist.github.com/1148887 >> > >> > ------------------------------ >> > >> > qx.Class.define("tradingactive.UtilXhr", { >> > extend : qx.application.Standalone, /* BUG: not the good class to >> > extend, which one ?? */ >> >> qx.core.Object >> > > Fixed > > > construct : function() { >> > >> > this.base(arguments); >> > >> > /* is it the good way to fecth args ? */ >> > var url=arguments[0]; >> > var data=arguments[1]; >> > var callback=arguments[2]; >> >> No, use explicit arguments: function (url, data, callback) >> > > Fixed > > >> >> > var req = new qx.io.request.Xhr(url,'POST'); >> >> To do everything in the constructor is ok if you intend to throw each >> UtilXhr instance away after its instantiation. >> > > Notice i'm noob in OO too so ... what do you mean ? need i have to add > something in my main code ? > > var myRequest = new tradingactive.xhr(.....); > myRequest.destroy() > > or something like that ? > > >> >> > if (data) req.setRequestData(data); >> > req.addListener("success",function(e) { >> >> You might want to add listeners for other request events as well, e.g. >> 'statusError'. >> > > I'll, later, thanks > >> >> > e=e.getTarget(); >> > if (!e.getResponse()) { >> > dialog.Dialog.error("Bad answer from the server"); >> > } else { >> > /* this code below doesn't work, because the >> callback is >> > searched in the class, not in the caller class */ >> > var >> myCallback=qx.lang.Function.bind(callback,this); >> >> Indeed, so the caller should probably do the bind. Or you pass the >> caller's "this" to the constructor. >> > > I choosed to pass "this" to the constructor > > >> > myCallback(e.getResponse()); >> > } >> >> From the API side it might also be a good idea to save the request >> result, request status etc. in instance properties so you can query them >> from the code that uses the API. >> > > Not a bad idea ! I'll improve > > >> >> > },this); >> > req.send(); >> > >> > } >> > }); >> >> In general, I personally prefer constructors to be "declarative", just >> configuring the new instance and not doing any serious actions. But >> that's just my personal taste. >> >> > Please learn me to make a clean code ! can you show me a sample ? > > Thanks a lot ! > >
------------------------------------------------------------------------------ uberSVN's rich system and user administration capabilities and model configuration take the hassle out of deploying and managing Subversion and the tools developers use with it. Learn more about uberSVN and get a free download at: http://p.sf.net/sfu/wandisco-dev2dev
_______________________________________________ qooxdoo-devel mailing list qooxdoo-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel