Pot.js


Pot.js / PotLite.js :
Pot.js is an implemental utility library that can execute JavaScript without burdening the CPU.
Pot.js / PotLite.js :
Pot.js / PotLite.js implements practical tendency as a substitution utility library.
That includes asynchronous methods as "Deferred" for solution to heavy process.
That is fully ECMAScript compliant.
Pot.js is a JavaScript library that can be performed without causing stress to the UI and
the CPU load by using easy loop iteration functions.
With respect to load, you can implement a particular application without requiring the programmer to be aware of.
Pot.js is built around the asynchronous processing and iterator with Deferred.
Pot.Deferred is a Deferred object like MochiKit (or JSDeferred like).
That makes it possible to various iterations (forEach, filter, map, reduce, zip, repeat, some etc.).
Moreover, Pot.js is an utility library that handles string processes with various algorithms,
and it has the Signal object that can write like aspect-oriented (AOP),
and it has the Event object for DOM listener,
and treats it the File API for HTML5. etc.
And, Pot.js never pollute the prototype of the global objects.
We only define the 'Pot' object in the global scope basically.
You can use Pot.js with other available libraries without fear of conflict.
Pot.js is a cross-browser library that works on a Web browser,
Node.js, userscript (Greasemonkey, Scriptish) XUL, or (Firefox Add-ons) etc.
PotLite.js is a light version that extracts only the part of
asynchronous processing (Deferred etc.) has been implemented in Pot.js.
Install
Will work with common ways.
<script type="text/javascript" src="pot.min.js"></script>
<script type="text/javascript" src="potlite.min.js"></script>
For Node.js
npm install pot.js
var pot = require('pot.js');
As for jQuery plugin.
Pot.deferrizejQueryAjax();
$.getJSON('/hoge.json').then(function(data) {
alert(data.results[0].text);
}).rescue(function(err) {
alert('Error! ' + err);
}).ensure(function() {
return someNextProcess();
});
$('div#hoge').deferred('hide', 'slow').then(function() {
});
Compatibility
Pot.js / PotLite.js works with the following web browsers.
- Mozilla Firefox *
- Internet Explorer 6+
- Safari *
- Opera *
- Google Chrome *
And, it also designed for operate in following environments.
- Greasemonkey (userscript)
- Mozilla Firefox Add-On (on XUL)
- Node.js
- Other non-browser environment
Test Run
License
Dual licensed under the MIT and GPL v2 licenses.
Copyright © 2012-2014 polygon planet
Documentation And Reference
Blog
Example
Pot.begin(function() {
Pot.debug('BEGIN example');
}).then(function() {
return Pot.request('pot.js.example.json', {
mimeType : 'application/json'
}).ensure(function(res) {
if (Pot.isError(res)) {
return {
foo : 'fooError',
bar : 'barError',
baz : 'bazError'
};
} else {
Pot.debug(res.responseText);
return Pot.parseFromJSON(res.responseText);
}
}).forEach(function(val, key) {
Pot.debug(key + ' : ' + val);
return Pot.wait(1);
}).wait(0.5).speed('slow').then(function(res) {
var s = '', keys = [];
Pot.forEach(res, function(val, key) {
s += key;
keys.push(key);
});
keys.push(s);
return keys;
}).then(function(foo, bar, baz, all) {
Pot.debug('foo = ' + foo);
Pot.debug('bar = ' + bar);
Pot.debug('baz = ' + baz);
Pot.debug('all = ' + all);
return [foo, bar, baz];
}).map.doze(function(val) {
Pot.debug('in map.doze(val) : ' + val);
return val + '!';
}).then(function(res) {
Pot.debug(res);
var d = new Pot.Deferred();
return d.then(function() {
throw new Error('TestError');
}).then(function() {
Pot.debug('Help me!!');
}).rescue(function(err) {
Pot.debug(err);
}).then(function() {
return Pot.Deferred.reduce(res, function(a, b) {
return a + b;
}).then(function(result) {
return result;
});
}).begin();
}).wait(2).then(function(res) {
Pot.debug(res);
return Pot.filter(res.split('!'), function(val) {
return val && val.length;
});
});
}).then(function(result) {
Pot.debug(result);
Pot.debug('END example');
}).end();
Refer document if you want to need more example and usage.
Pot.js + PotLite.js - Document and Reference