[Dojo-checkins] bill - r26961 - dojo/trunk/rpc

dojo-checkins-admin at dojotoolkit.org dojo-checkins-admin at dojotoolkit.org
Thu Nov 3 18:10:52 EDT 2011


Author: bill
Date: Thu Nov  3 15:10:52 2011
New Revision: 26961

Modified:
   dojo/trunk/rpc/JsonService.js
   dojo/trunk/rpc/JsonpService.js
   dojo/trunk/rpc/RpcService.js
Log:
Convert dojo/rpc code to have granular dependencies and to be baseless.  Fixes #14203 !strict.


Modified: dojo/trunk/rpc/JsonService.js
==============================================================================
--- dojo/trunk/rpc/JsonService.js	(original)
+++ dojo/trunk/rpc/JsonService.js	Thu Nov  3 15:10:52 2011
@@ -1,11 +1,18 @@
-define(["../main", "./RpcService"], function(dojo) {
-	// module:
-	//		dojo/rpc/JsonService
-	// summary:
-	//		TODOC
+define([
+	"../_base/declare", "../_base/Deferred", "../_base/json", "../_base/lang", "../_base/xhr",
+	"./RpcService"
+], function(declare, Deferred, json, lang, xhr, RpcService) {
+
+// module:
+//		dojo/rpc/JsonService
+// summary:
+//		TODOC
+
+/*=====
+RpcService = dojo.rpc.RpcService;
+=====*/
 
-
-dojo.declare("dojo.rpc.JsonService", dojo.rpc.RpcService, {
+return declare("dojo.rpc.JsonService", RpcService, {
 		bustCache: false,
 		contentType: "application/json-rpc",
 		lastSubmissionId: 0,
@@ -14,29 +21,29 @@
 			// summary:
 			// 		call an arbitrary remote method without requiring it to be
 			// 		predefined with SMD
-			//	method: string
+			// method: string
 			//		the name of the remote method you want to call.
-			//	params: array
+			// params: array
 			//		array of parameters to pass to method
 
-			var deferred = new dojo.Deferred();
+			var deferred = new Deferred();
 			this.bind(method, params, deferred);
 			return deferred;
 		},
 
 		bind: function(method, parameters, deferredRequestHandler, url){
-			//summary:
+			// summary:
 			//		JSON-RPC 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
+			// method: string
 			//		The name of the method we are calling
-			//	parameters: array
+			// parameters: array
 			//		The parameters we are passing off to the method
-			//	deferredRequestHandler: deferred
+			// deferredRequestHandler: deferred
 			//		The Deferred object for this particular request
 
-			var def = dojo.rawXhrPost({
+			var def = xhr.post({
 				url: url||this.serviceUrl,
 				postData: this.createRequest(method, parameters),
 				contentType: this.contentType,
@@ -48,24 +55,24 @@
 
 		createRequest: function(method, params){
 			// summary:
-			//	create a JSON-RPC envelope for the request
-			//	method: string
-			//		The name of the method we are creating the requst for
-			//	params: array
-			//		The array of parameters for this request;
+			//		create a JSON-RPC envelope for the request
+			// method: string
+			//		The name of the method we are creating the request for
+			// params: array
+			//		The array of parameters for this request
 
 			var req = { "params": params, "method": method, "id": ++this.lastSubmissionId };
-			return dojo.toJson(req);
+			return json.toJson(req);
 		},
 
 		parseResults: function(/*anything*/obj){
-			//summary:
+			// summary:
 			//		parse the result envelope and pass the results back to
 			//		the callback function
-			//	obj: Object
-			//		Object containing envelope of data we recieve from the server
+			// obj: Object
+			//		Object containing envelope of data we receive from the server
 
-			if(dojo.isObject(obj)){
+			if(lang.isObject(obj)){
 				if("result" in obj){
 					return obj.result;
 				}
@@ -81,5 +88,4 @@
 	}
 );
 
-return dojo.rpc.JsonService;
 });

Modified: dojo/trunk/rpc/JsonpService.js
==============================================================================
--- dojo/trunk/rpc/JsonpService.js	(original)
+++ dojo/trunk/rpc/JsonpService.js	Thu Nov  3 15:10:52 2011
@@ -1,23 +1,29 @@
-define(["../main", "./RpcService", "../io/script"], function(dojo) {
-	// module:
-	//		dojo/rpc/JsonpService
-	// summary:
-	//		TODOC
-
+define([
+	"../_base/array", "../_base/declare", "../_base/lang", "./RpcService", "../io/script"],
+	function(array, declare, lang, RpcService, script) {
+
+// module:
+//		dojo/rpc/JsonpService
+// summary:
+//		TODOC
+
+/*=====
+RpcService = dojo.rpc.RpcService;
+=====*/
 
-dojo.declare("dojo.rpc.JsonpService", dojo.rpc.RpcService, {
+return declare("dojo.rpc.JsonpService", 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
+	//		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);
+				lang.mixin(this.required, requiredArgs);
 			}
 
-			dojo.forEach(this.required, function(req){
+			array.forEach(this.required, function(req){
 				if(req=="" || req==undefined){
 					throw new Error("Required Service Argument not found: "+req);
 				}
@@ -29,17 +35,17 @@
 
 	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
+		//		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({
+		var def = script.get({
 			url: url||this.serviceUrl,
 			callbackParamName: this.callbackParamName||"callback",
 			content: this.createRequest(parameters),
@@ -53,15 +59,14 @@
 	createRequest: function(parameters){
 		// summary:
 		//      create a JSONP req
-		//      params: array
-		//              The array of parameters for this request;
+		// params: array
+		//		The array of parameters for this request;
 
-		var params = (dojo.isArrayLike(parameters) && parameters.length==1) ?
+		var params = (lang.isArrayLike(parameters) && parameters.length==1) ?
 				parameters[0] : {};
-		dojo.mixin(params,this.required);
+		lang.mixin(params,this.required);
 		return params;
 	}
 });
 
-return dojo.rpc.JsonpService;
 });

Modified: dojo/trunk/rpc/RpcService.js
==============================================================================
--- dojo/trunk/rpc/RpcService.js	(original)
+++ dojo/trunk/rpc/RpcService.js	Thu Nov  3 15:10:52 2011
@@ -1,17 +1,20 @@
-define(["../main", "../_base/url"], function(dojo) {
-	// module:
-	//		dojo/rpc/RpcService
-	// summary:
-	//		TODOC
+define([
+	"../_base/array", "../_base/declare", "../_base/Deferred", "../_base/kernel","../_base/lang",
+	"../_base/url", "../_base/xhr"
+], function(array, declare, Deferred, kernel, lang, _Url, xhr) {
+
+// module:
+//		dojo/rpc/RpcService
+// summary:
+//		TODOC
 
-
-dojo.declare("dojo.rpc.RpcService", null, {
+return declare("dojo.rpc.RpcService", null, {
 	constructor: function(args){
-		//summary:
-		//Take a string as a url to retrieve an smd or an object that is an smd or partial smd to use
-		//as a definition for the service
+		// summary:
+		//		Take a string as a url to retrieve an smd or an object that is an smd or partial smd to use
+		//		as a definition for the service
 		//
-		//	args: object
+		// args: object
 		//		Takes a number of properties as kwArgs for defining the service.  It also
 		//		accepts a string.  When passed a string, it is treated as a url from
 		//		which it should synchronously retrieve an smd file.  Otherwise it is a kwArgs
@@ -24,13 +27,13 @@
 		//
 		if(args){
 			//if the arg is a string, we assume it is a url to retrieve an smd definition from
-			if( (dojo.isString(args)) || (args instanceof dojo._Url)){
-				if (args instanceof dojo._Url){
+			if( (lang.isString(args)) || (args instanceof _Url)){
+				if (args instanceof _Url){
 					var url = args + "";
 				}else{
 					url = args;
 				}
-				var def = dojo.xhrGet({
+				var def = xhr.get({
 					url: url,
 					handleAs: "json-comment-optional",
 					sync: true
@@ -42,7 +45,7 @@
 				});
 
 			}else if(args.smdStr){
-				this.processSmd(dojo.eval("("+args.smdStr+")"));
+				this.processSmd(kernel.eval("("+args.smdStr+")"));
 			}else{
 				// otherwise we assume it's an arguments object with the following
 				// (optional) properties:
@@ -74,15 +77,15 @@
 		//		parse the results coming back from an rpc request.  this
 		//		base implementation, just returns the full object
 		//		subclasses should parse and only return the actual results
-		//	obj: Object
+		// obj: Object
 		//		Object that is the return results from an rpc request
 		return obj;
 	},
 
 	errorCallback: function(/* dojo.Deferred */ deferredRequestHandler){
 		// summary:
-		//		create callback that calls the Deferres errback method
-		//	deferredRequestHandler: Deferred
+		//		create callback that calls the Deferred errback method
+		// deferredRequestHandler: Deferred
 		//		The deferred object handling a request.
 		return function(data){
 			deferredRequestHandler.errback(data.message);
@@ -92,10 +95,10 @@
 	resultCallback: function(/* dojo.Deferred */ deferredRequestHandler){
 		// summary:
 		//		create callback that calls the Deferred's callback method
-		//	deferredRequestHandler: Deferred
+		// deferredRequestHandler: Deferred
 		//		The deferred object handling a request.
 
-		return dojo.hitch(this,
+		return lang.hitch(this,
 			function(obj){
 				if(obj.error!=null){
 					var err;
@@ -119,15 +122,15 @@
 	generateMethod: function(/*string*/ method, /*array*/ parameters, /*string*/ url){
 		// summary:
 		//		generate the local bind methods for the remote object
-		//	method: string
+		// method: string
 		//		The name of the method we are generating
-		//	parameters: array
+		// parameters: array
 		//		the array of parameters for this call.
-		//	url: string
+		// url: string
 		//		the service url for this call
 
-		return dojo.hitch(this, function(){
-			var deferredRequestHandler = new dojo.Deferred();
+		return lang.hitch(this, function(){
+			var deferredRequestHandler = new Deferred();
 
 			// if params weren't specified, then we can assume it's varargs
 			if( (this.strictArgChecks) &&
@@ -137,7 +140,7 @@
 				// put error stuff here, no enough params
 				throw new Error("Invalid number of parameters for remote method.");
 			}else{
-				this.bind(method, dojo._toArray(arguments), deferredRequestHandler, url);
+				this.bind(method, lang._toArray(arguments), deferredRequestHandler, url);
 			}
 
 			return deferredRequestHandler;
@@ -146,18 +149,18 @@
 
 	processSmd: function(object){
 		// summary:
-		//		callback method for reciept of a smd object.  Parse the smd
+		//		callback method for receipt of a smd object.  Parse the smd
 		//		and generate functions based on the description
-		//	object:
+		// object:
 		//		smd object defining this service.
 
 		if(object.methods){
-			dojo.forEach(object.methods, function(m){
+			array.forEach(object.methods, function(m){
 				if(m && m.name){
 					this[m.name] = this.generateMethod(	m.name,
 										m.parameters,
 										m.url||m.serviceUrl||m.serviceURL);
-					if(!dojo.isFunction(this[m.name])){
+					if(!lang.isFunction(this[m.name])){
 						throw new Error("RpcService: Failed to create" + m.name + "()");
 						/*console.log("RpcService: Failed to create", m.name, "()");*/
 					}
@@ -171,5 +174,4 @@
 	}
 });
 
-return dojo.rpc.RpcService;
 });


More information about the Dojo-checkins mailing list