From 55dd4cc38a88d429d845e3094e8a008abc5fd949 Mon Sep 17 00:00:00 2001 From: "Kiryukhin, Vadim" Date: Mon, 22 Aug 2016 01:16:42 -0700 Subject: [PATCH] AJAX documentation and examples --- README.md | 2 +- html/doc.html | 29 +++++++++++++- html/function.html | 2 +- html/http.html | 84 ++++++++++++++++++++++++++++++++++++++++ html/overview.html | 2 +- index.html | 2 +- main.js | 18 ++++++--- vkthread/vkthread.js | 8 ++-- vkthread/vkthread.min.js | 6 +-- 9 files changed, 136 insertions(+), 17 deletions(-) create mode 100644 html/http.html diff --git a/README.md b/README.md index 5f86c3b..9d1e281 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Function can be defined directly in the main thread or called from an external j Plugin is built on HTML5 "Web Worker" technology. (old version of the plugin can be found under tag 0.5.7) -- file size: 1.8k minified / 3.6k development +- file size: 3.5k minified / 5.5k development - Doesn't have any dependecies. **Basic usage:** diff --git a/html/doc.html b/html/doc.html index e57adb9..f4d17f6 100644 --- a/html/doc.html +++ b/html/doc.html @@ -22,4 +22,31 @@

vkThread.execAll ( [param1, param2, ... ] )

param -- object (see above ) -

\ No newline at end of file +

+ + +

$http( url, args )

+

Run XMLHttpRequest in a threads.

+

+	@return -- string
+
+	@url             - string; URL
+	@args (optional) - object; data you send to server with POST or PUT methods
+
+
+

$http Usage:

+

+	$http(url).get().then(...);
+
+	$http(url, args).post().then(...);
+
+	$http(url, args).put().then(...);
+
+	$http(url).delete().then(...);
+
+
+ +

+ + +

\ No newline at end of file diff --git a/html/function.html b/html/function.html index c3147da..89c71a0 100644 --- a/html/function.html +++ b/html/function.html @@ -14,7 +14,7 @@ return ret; } - + diff --git a/html/http.html b/html/http.html new file mode 100644 index 0000000..ab26212 --- /dev/null +++ b/html/http.html @@ -0,0 +1,84 @@ + +
+
Ajax in Thread
+

+To download and process data in a thread vkthread provides promise-style $http() function. +

+ + + +

+Example GET: +
+In this example function requests data from a github server (see URL below), sorts result based on
+star counter and returns name and number of stars for the most popular project in my github repo. +

+ +
function foo(url){
+	return $http(url).get().then(function(data){
+
+        var obj = JSON.parse(data)
+                      .sort( (a,b) => b.stargazers_count - a.stargazers_count )[0];
+
+		return obj.name + ' : ' + obj.stargazers_count + ' stars';
+	});
+}
+
+
+ + + + + +

+
+var param = {
+	fn: foo,
+	args:['https://api.github.com/users/vkiryukhin/repos']
+};
+
+vkthread.exec(param).then(
+	function(data){
+		console.log(data);
+	}
+);
+
+ + +

+Example POST: +
+In this example function requests file LICENSE from the origin server and returns the first line of the text. +

+
function foo(url){
+	return $http(url, args).post().then(function(data){
+		return data.split('\n')[0];
+	});
+}
+
+
+ + + + + +

+
+var param = {
+	fn: foo,
+	args:[ '../LICENSE', {id:123, name:'John'} ]
+};
+
+vkthread.exec(param).then(
+	function(data){
+		console.log(data);
+	}
+);
+
+ + + +

+ + +
diff --git a/html/overview.html b/html/overview.html index d58e492..1aa221a 100644 --- a/html/overview.html +++ b/html/overview.html @@ -40,7 +40,7 @@ -

execute this function in a thread:

+

execute this function in a thread:

var param = {
diff --git a/index.html b/index.html
index c72b295..2334301 100644
--- a/index.html
+++ b/index.html
@@ -66,7 +66,7 @@ 

vkThread

  • Anonymous Function
  • Lambda Function
  • Remote Function
  • - +
  • AJAX