-
Notifications
You must be signed in to change notification settings - Fork 2
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
1 parent
445d448
commit d5c447d
Showing
8 changed files
with
1,296 additions
and
429 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,367 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>API Documentation for lib/oath.js - Oath | ||
</title> | ||
<script type="text/javascript">var ghuser = 'logicalparadox' | ||
, ghproject = 'oath'; | ||
|
||
</script> | ||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script> | ||
<script src="/oath/public/js/prettify.js"></script> | ||
<script src="/oath/public/js/main.js"></script> | ||
<link rel="stylesheet" href="/oath/public/css/main.css" type="text/css" media="all"> | ||
<link href="http://fonts.googleapis.com/css?family=Lato:100,300" rel="stylesheet" type="text/css"> | ||
<script type="text/javascript">var mpq = []; | ||
mpq.push(["init", "268c122423c94bf806c254a27a491302"]); | ||
(function(){var b,a,e,d,c;b=document.createElement("script");b.type="text/javascript"; | ||
b.async=true;b.src=(document.location.protocol==="https:"?"https:":"http:")+ | ||
"//api.mixpanel.com/site_media/js/api/mixpanel.js";a=document.getElementsByTagName("script")[0]; | ||
a.parentNode.insertBefore(b,a);e=function(f){return function(){mpq.push( | ||
[f].concat(Array.prototype.slice.call(arguments,0)))}};d=["init","track","track_links", | ||
"track_forms","register","register_once","identify","name_tag","set_config"];for(c=0;c< | ||
d.length;c++){mpq[d[c]]=e(d[c])}})(); | ||
</script> | ||
<script type="text/javascript">var _gaq = _gaq || []; | ||
_gaq.push(['_setAccount', 'UA-26183904-4']); | ||
_gaq.push(['_trackPageview']); | ||
(function() { | ||
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; | ||
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; | ||
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); | ||
})(); | ||
</script> | ||
</head> | ||
<body> | ||
<nav> | ||
<ul class="sections"> | ||
<li class="keepcase"><a href="#constructor" class="scroll">constructor</a> | ||
</li> | ||
<li class="keepcase"><a href="#Oath.resolve" class="scroll">Oath.resolve</a> | ||
</li> | ||
<li class="keepcase"><a href="#Oath.reject" class="scroll">Oath.reject</a> | ||
</li> | ||
<li class="keepcase"><a href="#then" class="scroll">then</a> | ||
</li> | ||
<li class="keepcase"><a href="#get" class="scroll">get</a> | ||
</li> | ||
<li class="keepcase"><a href="#pop" class="scroll">pop</a> | ||
</li> | ||
<li class="keepcase"><a href="#call" class="scroll">call</a> | ||
</li> | ||
</ul> | ||
<ul class="pages"> | ||
<li><a href="/oath">Home</a> | ||
</li> | ||
</ul> | ||
<ul class="code"> | ||
<li><a href="/oath/code/index.html">lib/oath.js</a> | ||
</li> | ||
</ul> | ||
</nav> | ||
<header> | ||
<h1><a href="/oath">Oath</a> | ||
</h1> | ||
<div class="description"><p>Oath is a tiny javascript library for <a href="http://nodejs.org">node</a> and the browser that makes it easy to build and interact with promise/future based APIs.</p> | ||
</div> | ||
<div class="gh"> | ||
<h4>Latest Update to Github | ||
</h4> | ||
<div id="commit"><span id="latestCommitTime">Loading...</span><a id="latestCommitURL"></a> | ||
</div> | ||
<div id="latestCommitMessage">Loading... | ||
</div> | ||
<div id="clone"><a href="https://github.com/logicalparadox/oath" class="button fork">Fork me on GitHub</a> | ||
<div class="clone">git clone https://github.com/logicalparadox/oath.git | ||
</div> | ||
</div> | ||
<div id="links"><a id="repoIssues" href="https://github.com/logicalparadox/oath/issues">GitHub Issues</a><a id="repoDownload" href="https://github.com/downloads/logicalparadox/oath/oath-0.1.0.zip">Download v0.1.0 | ||
</a> | ||
</div> | ||
</div> | ||
</header> | ||
<section id="content"> | ||
<div id="code"> | ||
<article id="constructor-section" class="codeblock"> | ||
<div class="header"><h1>Oath constructor</h1> | ||
</div> | ||
<div class="ctx"> | ||
<h3>Oath() | ||
</h3> | ||
</div> | ||
<div class="tags"> | ||
<!-- ignroing this--> | ||
<div class="tag"><span class="type">@param</span><span class="types">{ Object }</span><span class="name">options</span><span class="desc"></span> | ||
</div> | ||
<div class="tag"><span class="type">@api</span><span class="visibility">public</span> | ||
</div> | ||
</div> | ||
<div class="description"><p>Create a new promise.</p> | ||
|
||
<h4>Options</h4> | ||
|
||
<ul> | ||
<li>parent - used internally for chaining</li> | ||
<li>context - object to set as <code>this</code> in callbacks</li> | ||
</ul> | ||
|
||
<p>You can use <code>Oath</code> within single functions</p> | ||
|
||
<pre><code> // assignment style | ||
var promise = new oath(); | ||
promise.then(successFn, errorFn); | ||
myAsycFunction(function(err, result) { | ||
if (err) promise.reject(err); | ||
promise.resolve(result); | ||
}); | ||
</code></pre> | ||
|
||
<p>Or return them to ease chaining of callbacks</p> | ||
|
||
<pre><code> // return style | ||
function doSomething(data) { | ||
var promise = new oath(); | ||
// async stuff here | ||
// promise should be returned immediately | ||
return promise; | ||
} | ||
|
||
doSomething(data).then(successFn, errorFn); | ||
</code></pre> | ||
</div> | ||
<div class="view-source">View Source | ||
</div> | ||
<div class="code-wrap"> | ||
<pre class="source prettyprint"><code>function Oath (options) { | ||
var self = this; | ||
options = options || {}; | ||
|
||
this.pending = []; | ||
this._options = { | ||
parent: options.parent || null, | ||
context: options.context || this | ||
};</code> | ||
</pre> | ||
</div> | ||
</article> | ||
<article id="Oath.resolve-section" class="codeblock"> | ||
<div class="header"><h2>Oath.resolve(result)</h2> | ||
</div> | ||
<div class="ctx"> | ||
<h3>this.resolve() | ||
</h3> | ||
</div> | ||
<div class="tags"> | ||
<!-- ignroing this--> | ||
<div class="tag"><span class="type">@param</span><span class="types">{ Object }</span><span class="name">result</span><span class="desc"></span> | ||
</div> | ||
<div class="tag"><span class="type">@api</span><span class="visibility">public</span> | ||
</div> | ||
</div> | ||
<div class="description"><p>Emits completion event to execute <code>success</code> chain of functions.</p> | ||
|
||
<pre><code> // When async work is complete | ||
promise.resolve(my_data_obj); | ||
</code></pre> | ||
</div> | ||
<div class="view-source">View Source | ||
</div> | ||
<div class="code-wrap"> | ||
<pre class="source prettyprint"><code>this.resolve = function (result) { | ||
self._complete('resolve', result); | ||
};</code> | ||
</pre> | ||
</div> | ||
</article> | ||
<article id="Oath.reject-section" class="codeblock"> | ||
<div class="header"><h2>Oath.reject(result)</h2> | ||
</div> | ||
<div class="ctx"> | ||
<h3>this.reject() | ||
</h3> | ||
</div> | ||
<div class="tags"> | ||
<!-- ignroing this--> | ||
<div class="tag"><span class="type">@param</span><span class="types">{ Object }</span><span class="name">result</span><span class="desc"></span> | ||
</div> | ||
<div class="tag"><span class="type">@api</span><span class="visibility">public</span> | ||
</div> | ||
</div> | ||
<div class="description"><p>Emit completion event to execute <code>failure</code> chain of functions.</p> | ||
|
||
<pre><code> // When async work errors | ||
promise.reject(my_error_obj); | ||
</code></pre> | ||
</div> | ||
<div class="view-source">View Source | ||
</div> | ||
<div class="code-wrap"> | ||
<pre class="source prettyprint"><code>this.reject = function (result) { | ||
self._complete('reject', result); | ||
}; | ||
}</code> | ||
</pre> | ||
</div> | ||
</article> | ||
<article id="then-section" class="codeblock"> | ||
<div class="header"><h1>.then([success], [failure])</h1> | ||
</div> | ||
<div class="ctx"> | ||
<h3>Oath.prototype.then() | ||
</h3> | ||
</div> | ||
<div class="tags"> | ||
<!-- ignroing this--> | ||
<div class="tag"><span class="type">@param</span><span class="types">{ Function }</span><span class="name">success</span><span class="desc">will execute on `resolve`</span> | ||
</div> | ||
<div class="tag"><span class="type">@param</span><span class="types">{ Function }</span><span class="name">failure</span><span class="desc">will execute on `reject` (optional)</span> | ||
</div> | ||
<div class="tag"><span class="type">@api</span><span class="visibility">public</span> | ||
</div> | ||
</div> | ||
<div class="description"><p>Chainable function for promise observers to queue result functions.</p> | ||
|
||
<pre><code> doSomething(my_data) | ||
.then(successFn1, failureFn1) | ||
.then(successFn2, failureFn2) | ||
</code></pre> | ||
</div> | ||
<div class="view-source">View Source | ||
</div> | ||
<div class="code-wrap"> | ||
<pre class="source prettyprint"><code>Oath.prototype.then = function (success, failure) { | ||
var context = this._options.context, | ||
pending = { resolve: null, reject: null }; | ||
|
||
if (success) | ||
pending.resolve = function () { success.apply(context, arguments); }; | ||
|
||
if (failure) | ||
pending.reject = function () { failure.apply(context, arguments); }; | ||
|
||
this.pending.push(pending); | ||
|
||
return this; | ||
};</code> | ||
</pre> | ||
</div> | ||
</article> | ||
<article id="get-section" class="codeblock"> | ||
<div class="header"><h1>.get(property)</h1> | ||
</div> | ||
<div class="ctx"> | ||
<h3>Oath.prototype.get() | ||
</h3> | ||
</div> | ||
<div class="tags"> | ||
<!-- ignroing this--> | ||
<div class="tag"><span class="type">@param</span><span class="types">{ String }</span><span class="name">property</span><span class="desc"></span> | ||
</div> | ||
<div class="tag"><span class="type">@api</span><span class="visibility">public</span> | ||
</div> | ||
</div> | ||
<div class="description"><p>On <code>resolve</code>, will return <code>property</code> value from data<br />passed by oath. Subsequent <code>then</code> calls will have the<br />value of the <code>get</code> passed to them.</p> | ||
|
||
<pre><code> doSomething(my_data) | ||
.get('doctor') | ||
.then(function(doctor) { ... }) | ||
.then(function(doctor) { ... }); | ||
</code></pre> | ||
</div> | ||
<div class="view-source">View Source | ||
</div> | ||
<div class="code-wrap"> | ||
<pre class="source prettyprint"><code>Oath.prototype.get = function (property) { | ||
var o = new Oath({ parent: this }); | ||
this.then( | ||
function(value) { o.resolve(value[property]); }, | ||
function(value) { o.reject(value); } | ||
); | ||
return o; | ||
};</code> | ||
</pre> | ||
</div> | ||
</article> | ||
<article id="pop-section" class="codeblock"> | ||
<div class="header"><h1>.pop()</h1> | ||
</div> | ||
<div class="ctx"> | ||
<h3>Oath.prototype.pop() | ||
</h3> | ||
</div> | ||
<div class="tags"> | ||
<!-- ignroing this--> | ||
<div class="tag"><span class="type">@api</span><span class="visibility">public</span> | ||
</div> | ||
</div> | ||
<div class="description"><p>Return you to a parent oath if you have chained down.</p> | ||
|
||
<pre><code> doSomething(my_data) | ||
.get('doctor') | ||
.then(function(doctor) { ... }) | ||
.pop() | ||
.then(function(my_data) { ... }); | ||
</code></pre> | ||
</div> | ||
<div class="view-source">View Source | ||
</div> | ||
<div class="code-wrap"> | ||
<pre class="source prettyprint"><code>Oath.prototype.pop = function () { | ||
if (this._options.parent) { | ||
return this._options.parent; | ||
} else { | ||
return this; | ||
} | ||
};</code> | ||
</pre> | ||
</div> | ||
</article> | ||
<article id="call-section" class="codeblock"> | ||
<div class="header"><h1>.call(functionName)</h1> | ||
</div> | ||
<div class="ctx"> | ||
<h3>Oath.prototype.call() | ||
</h3> | ||
</div> | ||
<div class="tags"> | ||
<!-- ignroing this--> | ||
<div class="tag"><span class="type">@param</span><span class="types">{ String }</span><span class="name">function</span><span class="desc">name</span> | ||
</div> | ||
<div class="tag"><span class="type">@api</span><span class="visibility">public</span> | ||
</div> | ||
</div> | ||
<div class="description"><p>On <code>resolve</code>, will execute a function of <code>name</code> in the<br />result object. The function that is called will be passed<br />all subseqents parameters of <code>oath.call</code>. The context of<br /><code>this</code> in the function that is called will be equal to the<br /><code>result</code> object passed on <code>oath.resolve</code>.</p> | ||
|
||
<pre><code> // queue up call on complete | ||
oath.call('validate', '1234'); | ||
|
||
oath.resolve({ some: 'data' | ||
, validate: function (apiKey) { | ||
this.some == 'data'; | ||
apiKey == '1234'; | ||
... | ||
} | ||
}); | ||
</code></pre> | ||
</div> | ||
<div class="view-source">View Source | ||
</div> | ||
<div class="code-wrap"> | ||
<pre class="source prettyprint"><code>Oath.prototype.call = function (fn) { | ||
var args = arguments; | ||
return this.then(function(value) { | ||
return value[fn].apply(value, Array.prototype.slice.call(args, 1)); | ||
}); | ||
};</code> | ||
</pre> | ||
</div> | ||
</article> | ||
</div> | ||
</section> | ||
<footer> | ||
<div class="branding">Oath is <a href="http://alogicalparadox.com">a logical paradox</a>. site generated by | ||
<a href="http://codexjs.com">codex.</a> | ||
</div> | ||
</footer> | ||
</body> | ||
</html> |
Oops, something went wrong.