From a089699c8915636ba4f158d77dba9b012bc93208 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 4 Mar 2011 19:02:28 +0300 Subject: build custom layer of Dojo to speed up loading of tt-rss (refs #293) --- lib/dojo/rpc/JsonpService.js | 80 +++++++++++++++++++++++++++++++++----------- 1 file changed, 60 insertions(+), 20 deletions(-) (limited to 'lib/dojo/rpc/JsonpService.js') diff --git a/lib/dojo/rpc/JsonpService.js b/lib/dojo/rpc/JsonpService.js index 68c971207..31e95077b 100644 --- a/lib/dojo/rpc/JsonpService.js +++ b/lib/dojo/rpc/JsonpService.js @@ -5,28 +5,68 @@ */ -if(!dojo._hasResource["dojo.rpc.JsonpService"]){ -dojo._hasResource["dojo.rpc.JsonpService"]=true; +if(!dojo._hasResource["dojo.rpc.JsonpService"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dojo.rpc.JsonpService"] = true; dojo.provide("dojo.rpc.JsonpService"); dojo.require("dojo.rpc.RpcService"); dojo.require("dojo.io.script"); -dojo.declare("dojo.rpc.JsonpService",dojo.rpc.RpcService,{constructor:function(_1,_2){ -if(this.required){ -if(_2){ -dojo.mixin(this.required,_2); -} -dojo.forEach(this.required,function(_3){ -if(_3==""||_3==undefined){ -throw new Error("Required Service Argument not found: "+_3); -} + +dojo.declare("dojo.rpc.JsonpService", dojo.rpc.RpcService, { + // summary: + // Generic JSONP service. Minimally extends RpcService to allow + // easy definition of nearly any JSONP style service. Example + // SMD files exist in dojox.data + + constructor: function(args, requiredArgs){ + if(this.required) { + if(requiredArgs){ + dojo.mixin(this.required, requiredArgs); + } + + dojo.forEach(this.required, function(req){ + if(req=="" || req==undefined){ + throw new Error("Required Service Argument not found: "+req); + } + }); + } + }, + + strictArgChecks: false, + + bind: function(method, parameters, deferredRequestHandler, url){ + //summary: + // JSONP bind method. Takes remote method, parameters, + // deferred, and a url, calls createRequest to make a JSON-RPC + // envelope and passes that off with bind. + // method: string + // The name of the method we are calling + // parameters: array + // The parameters we are passing off to the method + // deferredRequestHandler: deferred + // The Deferred object for this particular request + + var def = dojo.io.script.get({ + url: url||this.serviceUrl, + callbackParamName: this.callbackParamName||"callback", + content: this.createRequest(parameters), + timeout: this.timeout, + handleAs: "json", + preventCache: true + }); + def.addCallbacks(this.resultCallback(deferredRequestHandler), this.errorCallback(deferredRequestHandler)); + }, + + createRequest: function(parameters){ + // summary: + // create a JSONP req + // params: array + // The array of parameters for this request; + + var params = (dojo.isArrayLike(parameters) && parameters.length==1) ? + parameters[0] : {}; + dojo.mixin(params,this.required); + return params; + } }); -} -},strictArgChecks:false,bind:function(_4,_5,_6,_7){ -var _8=dojo.io.script.get({url:_7||this.serviceUrl,callbackParamName:this.callbackParamName||"callback",content:this.createRequest(_5),timeout:this.timeout,handleAs:"json",preventCache:true}); -_8.addCallbacks(this.resultCallback(_6),this.errorCallback(_6)); -},createRequest:function(_9){ -var _a=(dojo.isArrayLike(_9)&&_9.length==1)?_9[0]:{}; -dojo.mixin(_a,this.required); -return _a; -}}); + } -- cgit v1.2.3