Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kiryukhin, Vadim
committed
Apr 20, 2016
0 parents
commit 40efb58
Showing
39 changed files
with
33,485 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2013 Vadim Kiryukhin | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<div class="container-fluid docContainer"> | ||
<div class="row"> | ||
<div class="col-md-2"></div> | ||
<div class="col-md-8"> | ||
|
||
<p></p> | ||
<h4>vkThread.exec ( param )</h4> | ||
<p>Run function in a thread.</p> | ||
<pre><code data-language="javascript"> | ||
@return -- promise object | ||
|
||
param -- object which has following attributes: | ||
|
||
@fn - function to execute | ||
@args (optional) - array of arguments for @fn | ||
@context (optional) - object which will be 'this' for @fn | ||
@importFiles (optional) - array of strings; each string is URL | ||
to a file, which @fn depends on. | ||
|
||
</code></pre> | ||
<p></p> | ||
<h4>vkThread.execAll ( [param1, param2, ... ] )</h4> | ||
<p>Run multiple functions in multiple threads.</p> | ||
<pre><code data-language="javascript"> | ||
@return -- promise object when all threads done. | ||
|
||
param -- object (see above ) | ||
</code></pre> | ||
|
||
<p></p> | ||
<h4>vkThread.getVersion();</h4> | ||
<pre><code data-language="javascript"> | ||
@return current version as a String; | ||
</code></pre> | ||
<p></p><p></p> | ||
</div> | ||
<div class="col-md-2"></div> | ||
</div> <!-- row --> | ||
</div> <!-- container-fluid --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
|
||
<p>Function <b>twoArgs()</b> takes 2 arguments: array and object, filters out members which are below 50 stars, and set comment based on star's value.</p> | ||
|
||
<pre><code data-language="javascript"> | ||
function twoArgs(arr, msgs){ | ||
function isGreateFifty(value){ | ||
return value.stargazers_count > 50; | ||
} | ||
function msg(obj){ | ||
obj.language = obj.stargazers_count > 70 ? msgs.excellent : msgs.good; | ||
return obj; | ||
} | ||
return arr.filter(isGreateFifty).map(msg); | ||
} | ||
</code></pre> | ||
|
||
<p>run it in thred <input type="button" ng-click="runWithArgs()" value="Run"/></p> | ||
<pre><code data-language="javascript"> | ||
var param = { | ||
fn: twoArgs, | ||
args: [$scope.repos, | ||
{ good:'Good Job!', | ||
excellent:'Excellent Job!' | ||
} | ||
] | ||
}; | ||
|
||
vkThread.exec(param).then( | ||
function (data) { | ||
$scope.repos = data; | ||
}, | ||
function(err) { | ||
alert(err); | ||
} | ||
); | ||
</code></pre> | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
<p>Function <b>Foo</b> is constructor, and getFirst() is a member function, which sorts array and returns 3 elements. Pay attention that we don't pass array as an argument. It passed as a context with foo object. </p> | ||
|
||
<pre><code data-language="javascript"> | ||
function Foo(arr){ | ||
this.myArr = arr; | ||
this.getFirst = function(){ | ||
function compare(a,b){ | ||
return b.stargazers_count - a.stargazers_count | ||
} | ||
return this.myArr.sort(compare).slice(1,4); | ||
} | ||
} | ||
|
||
var foo = new Foo($scope.repos); | ||
</code></pre> | ||
|
||
<p>run it in thred <input type="button" ng-click="runWithContext()" value="Run with Context"/> </p> | ||
<pre><code data-language="javascript"> | ||
var param = { | ||
fn:foo.getFirst, | ||
context:foo | ||
}; | ||
|
||
vkThread.exec(param).then( | ||
function (data) { | ||
$scope.repos = data; | ||
}, | ||
function(err) { | ||
alert(err); | ||
} | ||
); | ||
</code></pre> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
<p>Function <b>withDependency()</b> gets array as an argument, sorts it and uses "underscore" library to return the first and the last elements of the array. We must provide url to the library as "importFiles" value. You can pass dependencies as many as you need. </p> | ||
|
||
<pre><code data-language="javascript"> | ||
function withDependency(arr){ | ||
var ret = []; | ||
|
||
function compare(a,b){ | ||
return b.stargazers_count - a.stargazers_count | ||
} | ||
|
||
arr.sort(compare) | ||
ret.push(_.first(arr)); | ||
ret.push(_.last(arr)); | ||
return ret; | ||
} | ||
|
||
</code></pre> | ||
|
||
<p>run it in thred <input type="button" ng-click="runWithDependency()" value="Run with Dependency"/> </p> | ||
<pre><code data-language="javascript"> | ||
var param = { | ||
fn:examples.withDependency, | ||
args: [ $scope.repos], | ||
importFiles:['https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js'] | ||
}; | ||
|
||
vkThread.exec(param).then( | ||
function (data) { | ||
$scope.repos = data; | ||
}, | ||
function(err) { | ||
alert(err); | ||
} | ||
); | ||
</code></pre> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
|
||
<div class="container-fluid" ng-controller="ExampleController"> | ||
<div class="row"> | ||
|
||
<div class="col-md-4"> | ||
<form ng-submit="search(username)"> | ||
|
||
<input type="searchUser" required placeholder="find something" ng-model="username"/> | ||
<input type="submit" value="Search Github"/> | ||
<div><sub>(enter any repo: angular, jquery, your own)</sub></div> | ||
</form> | ||
<br/><br/> | ||
|
||
<div> | ||
<img style="width:50px; height:50px;" ng-src="{{user.avatar_url}}" title="{{user.name}}" /> | ||
{{user.name}} | ||
</div> | ||
|
||
<div> | ||
|
||
</div> | ||
|
||
<div ng-include="'html/userdetails.html'" ng-show="user"></div> | ||
|
||
</div> | ||
|
||
<div class="col-md-8"> | ||
|
||
<div id="subMenu"> | ||
<span ng-click="onClickTab('arguments')" | ||
style="cursor:pointer" | ||
ng-class="{activeTabName: activeTabName=='arguments'}"> | ||
arguments | ||
</span> | ||
| | ||
<span ng-click="onClickTab('context')" | ||
style="cursor:pointer" | ||
ng-class="{activeTabName: activeTabName=='context'}"> | ||
context | ||
</span> | ||
| | ||
<span ng-click="onClickTab('dependency')" | ||
style="cursor:pointer" | ||
ng-class="{activeTabName: activeTabName=='dependency'}"> | ||
dependency | ||
</span> | ||
| | ||
<span ng-click="onClickTab('multithreading')" | ||
style="cursor:pointer" | ||
ng-class="{activeTabName: activeTabName=='multithreading'}"> | ||
multithreading | ||
</span> | ||
</div> | ||
<p></p> | ||
<div id="content" class="docContainer"> | ||
|
||
<div id="docContentWrapper" > | ||
<div class="pageContent"> | ||
<ng-include src="activeTab" onload="colorIt()"></ng-include> | ||
</div> | ||
</div> | ||
|
||
</div> | ||
|
||
|
||
</div> | ||
|
||
|
||
</div> <!-- row --> | ||
|
||
|
||
</div> <!-- container-fluid --> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
|
||
<p>Function <b>basicAjax()</b> gets data with AJAX in a thread, sorts it and returns the first 5 elements of the array. | ||
We run this function in 2 different threads providing different URLs, and then join responses from these 2 threads. </p> | ||
|
||
<pre><code data-language="javascript"> | ||
function basicAjax(url) { | ||
|
||
var httpRequest = new XMLHttpRequest(), | ||
result; | ||
|
||
httpRequest.onreadystatechange = function(){ | ||
if (httpRequest.readyState === 4) { | ||
if (httpRequest.status === 200) { | ||
result = JSON.parse(httpRequest.responseText); | ||
} else { | ||
result = 'There was a problem with the request.'; | ||
} | ||
} | ||
}; | ||
|
||
// IMPORTANT: ajax must perform the operation synchronously | ||
// (the 3-rd arg is false); as ajax is executed in a thread, it's OK. | ||
httpRequest.open('GET', url, false); | ||
httpRequest.send(); | ||
|
||
function compare(a,b){ | ||
return b.stargazers_count - a.stargazers_count | ||
} | ||
|
||
return result.sort(compare).slice(0,5); | ||
} | ||
</code></pre> | ||
|
||
<p>run it in thred <input type="button" ng-click="runMultiThread()" value="Run" /> </p> | ||
|
||
<pre><code data-language="javascript"> | ||
var param1 = { | ||
fn: basicAjax, | ||
args: ['https://api.github.com/users/angular/repos'] | ||
}; | ||
var param2 = { | ||
fn: basicAjax, | ||
args: ['https://api.github.com/users/vkiryukhin/repos'] | ||
} | ||
|
||
vkThread.execAll([param1,param2]).then( | ||
function (data) { | ||
$scope.repos = data[0].concat(data[1]); | ||
}, | ||
function(err) { | ||
alert(err); | ||
} | ||
); | ||
</code></pre> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<div class="container-fluid docContainer"> | ||
<div class="row"> | ||
<div class="col-md-2"></div> | ||
<div class="col-md-8"> | ||
<p> | ||
<b>ng-vkThread</b> is an Angular plugin, which allows you to execute a function in a thread. | ||
</p> | ||
<p> | ||
Function can be: | ||
<ul> | ||
<li>Regular function</li> | ||
<li>Object's method</li> | ||
<li>Function with dependencies</li> | ||
<li>Function with context</li> | ||
<li>Anonymous function</li> | ||
</ul> | ||
</p> | ||
|
||
<p> | ||
<div>Plugin is built on HTML5 "Web Workers" technology. </div> | ||
|
||
<ul> | ||
<li>It is very compact: 1.8k minified / 4.0k development</li> | ||
<li>Doesn't have any dependecies. </li> | ||
</ul> | ||
</p> | ||
<p> | ||
Basic usage: | ||
</p> | ||
<pre><code data-language="javascript"> | ||
var app = angular.module('myApp',['ng-vkThread']); | ||
|
||
app.controller('ExampleController', ['$scope', 'vkThread', | ||
function($scope, vkThread){ | ||
|
||
var vkThread = vkThread(); | ||
|
||
. . . | ||
} | ||
</code></pre> | ||
|
||
|
||
<pre><code data-language="javascript"> | ||
/* function to execute in a thread */ | ||
function foo(n, m){ | ||
return n + m; | ||
} | ||
|
||
/* create an object, which you pass to vkThread as an argument*/ | ||
var param = { | ||
fn: foo // <-- function to execute | ||
args: [1, 2] // <-- arguments for this function | ||
}; | ||
|
||
/* run thread */ | ||
vkThread.exec(param).then( | ||
function (data) { | ||
console.log(data); // <-- thread returns 3 | ||
}, | ||
function(err) { | ||
alert(err); // <-- thread returns error message | ||
} | ||
|
||
); | ||
</code></pre> | ||
|
||
</div> | ||
<div class="col-md-2"></div> | ||
</div> <!-- row --> | ||
</div> <!-- container-fluid --> | ||
|
Oops, something went wrong.