Pot.js Overview

This document is crazy english that is the one that most of sentences was translated literally and automatically into English from Japanese. Therefore, please acknowledge it though there is a possibility with improper sentences. You can refer the original Japanese document.

Overview

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.

Download

Latest and Stable

Pot.js

PotLite.js (lite)

Repository

$ git clone git://github.com/polygonplanet/Pot.js

GitHub : polygonplanet/Pot.js

Install

Will work with common ways.

Example:

<script type="text/javascript" src="pot.min.js"></script>

<!--
  Or you can use the API hosting server for the Pot.js available.
  That referenced followings.
-->
<script type="text/javascript" src="http://api.polygonpla.net/js/pot/1.13/pot.min.js"></script>

Example for after loading of Pot.js:

<script type="text/javascript">
// You can use short method name in any by
//   Pot.globalize method. (see below).
Pot.globalize();

begin(function() {
    return request('./hoge.json', {
        mimeType : 'text/javascript'
    }).then(function(res) {
        return parseFromJSON(res.responseText);
    });
}).then(function(res) {
    return Deferred.forEach(res.items, function(value, key) {
        // ...
    });
});
// ...
</script>

For Node.js:

// Example to define Pot object on Node.js.
var Pot = require('./pot.min.js');
Pot.debug(Pot.VERSION);

Pot.Deferred.begin(function() {
    Pot.debug('Hello World!');
}).then(function() {...})
// ...

Example of Greasemonkey (userscript).

// ==UserScript==
// ...
// @require  https://github.com/polygonplanet/Pot.js/raw/master/pot.min.js
// ...
// ==/UserScript==

Pot.Deferred.begin(function() {
    return Pot.request('http://www.example.com/data.json', {
        mimeType : 'application/json'
    }).then(function(res) {
        return Pot.parseFromJSON(res.responseText);
    });
}).then(function(res) {
    Pot.debug(res);
    // do something...
});
//...

Pot.js API hosting server is available if you import directly from the Web with a limited version of the Pot.js.
On GitHub link above defects may occur due to differences in implementation because it is always up to date.

Example for use the Pot.js version 1.13:

This can be changed to fit the part of the released version 1.13.
When tagged version (e.g. 1.xx), we will put a new package to the API server together with the repository.

For example, if you use 1.13 with Greasemonkey (userscript):

// ==UserScript==
// ...
// @require  http://api.polygonpla.net/js/pot/1.13/pot.min.js
// ...
// ==/UserScript==

Note: This example uses the version numbers of 1.13, it is not always up to date.
Please select the version with more stable.

Examples of using PotLite.js:

You can use the API hosting server by change the link URL for PotLite.js like Pot.js's URL.

You can check the latest version number on GitHub repository (All tags)


As for jQuery plugin:

// Execute after loading with jQuery.
Pot.deferrizejQueryAjax();

// Ajax-based functions will return with Pot.Deferred object instance.
$.getJSON('/hoge.json').then(function(data) {
    alert(data.results[0].text);
}).rescue(function(err) {
    alert('Error! ' + err);
}).ensure(function() {
    return someNextProcess();
});

// Will added 'deferred' method for effects etc
//  that convert to Deferred functions.
$('div#hoge').deferred('hide', 'slow').then(function() {
    // (...Do something after hide() method completed.)
});

Pot.deferrizejQueryAjax() does not execute in library now. So, if you use as plugin, must call first.

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

You can verify by running the operation test in the following page.

License

Dual licensed under the MIT and GPL v2 licenses.

Copyright © 2012 polygon planet

Contact

Author: polygon planet

polygon.planet[at]gmail.com

Thanks

Logo design:
yinyang302mg

Thanks for which became chance to make Pot.js / PotLite.js library:
JSDeferred, MochiKit (Mochi Media, Inc.), Tombloo developers.

JSDoc Document

The auto-generated documentation from the Pot.js / PotLite.js source code by Closure Compiler.

Refer more detailed implementation from the source code directly if needed.

Introduction

Pot.js / PotLite.js will define a "Pot" object in global scope for does non-conflict with other libraries.
If the environment is enabled the module (Node.js etc.), Pot.js / PotLite.js will use "exports" for "require". That case will not define an "Pot" object in global scope.

If you want to use short method name:

Pot.globalize();

Execute this code in the first. For example, you can be called only "begin", As method name of the "Pot.Deferred.begin".

And, "Pot.globalize" can be useful when define any object into the global scope.

var obj = {
    foo: function() { return 'foo' },
    bar: function() { return 'bar' }
};
Pot.globalize(obj);

alert(foo() + bar()); // 'foobar'

By providing such an argument on any object can be useful when you want to place any object in global scope.

Blog Archives

Pot.js / PotLite.js - Blog Archives (Japanese).