You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by he...@apache.org on 2014/07/02 13:42:23 UTC

svn commit: r1607326 - /thrift/cms-site/trunk/content/tutorial/js.md

Author: henrique
Date: Wed Jul  2 11:42:23 2014
New Revision: 1607326

URL: http://svn.apache.org/r1607326
Log:
typos and formatting

Modified:
    thrift/cms-site/trunk/content/tutorial/js.md

Modified: thrift/cms-site/trunk/content/tutorial/js.md
URL: http://svn.apache.org/viewvc/thrift/cms-site/trunk/content/tutorial/js.md?rev=1607326&r1=1607325&r2=1607326&view=diff
==============================================================================
--- thrift/cms-site/trunk/content/tutorial/js.md (original)
+++ thrift/cms-site/trunk/content/tutorial/js.md Wed Jul  2 11:42:23 2014
@@ -42,62 +42,63 @@ Use either the [Java tutorial](/tutorial
 ### Inspecting the generated Javascript code and HTML code
 
 Inside the html file is the entry point of using the Thrift.js and compiled Javascript files. The main section code from the tutorial.html fileis the Thrift client as shown above.
-	
+
 The first thing for using the Thrift files is setting up your Transport protocol. At this time, it only supports AJAX and is as follows:
-	
+
 		var transport = new Thrift.Transport("/thrift/service/tutorial/");
-	
+
 After that the protocol needs setup using the transport object, which for Javascript is JSON:
-	
+
 		var protocol  = new Thrift.Protocol(transport);
-	
+
 Now we are setup for the full Thrift communications, so we can start instantiating the Thrift objects, which define our Services and Objects.
-	
+
 		var client    = new CalculatorClient(protocol);
 
 Now that we have a functional Service Interface object created, we can can setup the JSON object, which gets is needed by the service routine and gets passed to it:
-		
+
 		var work = new Work()
 		work.num1 = $("#num1").val();
 		work.num2 = $("#num2").val();
 		work.op = $("#op").val();
-	
-	Once the object is created, we can now pass 
-	
+
+Once the object is created, we can now pass 
+
 		try {
 			result = client.calculate(1, work);
 			//etc......
-	
+
 Now, when the calculate button on the html page is clicked, the calc() function as defined above is called and we get an AJAX call, which blocks and waits for the response. This then updates the result from the calculation.
 	
 ### Inspecting the generated tutorial_types.js file
 
 Each Thrift struct will have properties associated with it.  For our tutorial object, Work, this is as shown above. For example:
-	
+
 		var work = new Work();
 		work.num1 = 1;
 		work.num2 = 2;
 		work.op = ADD;
-	
+
 In addition, there is a read(input) and write(output) function created on the object as well. For the end user, these are not functions to be used as they are mainly just used by the Thrift.js file for accessing objects.
 
 ### Inspecting the generated Calculator.js file
 The Calculator.js file is the services created and defined in the .thrift file. The two services defined are:
-	
+
 		i32 add(1:i32 num1, 2:i32 num2),
 		i32 calculate(1:i32 logid, 2:Work w) throws (1:InvalidOperation ouch),
 
 To start using this, the Calculator object has to be created and accessed as shown above. The Javascript Object, whichi is your interface to the services created looks like this:
-		
+
 		CalculatorClient = function(input, output){}
 
 Then, to access your defined services, the functions created look like this:
-	
+
 		CalculatorClient.prototype.add = function(num1, num2) {}
+
 and
-		
+
 		CalculatorClient.prototype.calculate = function(logid, w) {}
-		
+
 Unfortunately, the Javascript object isn't just called Calculator and there are a lot of other functions defined as well, but how those are used are out of the scope of this tutorial.  
 
 ### Inspecting the Thrift.js file
@@ -114,11 +115,11 @@ jQuery aware JS source files can generat
 
     thrift --gen js:jquery tutorial.thrift
 
-This does not change the default behavior of the library, i.e. service calls will be done synchronously. However, services will start using jQuery.ajax when a callback function is provided as showed below.
+This does not change the default behavior of the library, i.e. service calls will be done synchronously. However, services will use jQuery.ajax if a callback function is provided as showed below.
 
     client.calculate(1, work, function(result) { alert(result); });
 
-This method call will return immediately but the callback function (and its *alert*) will be called as soon as a response is received from the server. The service call also returns a jqXHR object, which has more callback options:
+This method call will immediately return but the callback function (and its *alert* message) will be called as soon as a response is received from the server. The service call also returns a jqXHR object, which has more callback options:
 
     client.calculate(1, work, function(){} )
     .fail( function(jqXHR, status, error) {  alert(error.message); } )