Browse files

Added docs

  • Loading branch information...
1 parent b521ef3 commit 8273533fc4483acdaf4184674eec6031207d1df0 @krisk krisk committed Jan 2, 2013
Showing with 374 additions and 1 deletion.
  1. +0 −1 .gitignore
  2. +186 −0 docs/docco.css
  3. +188 −0 docs/fiber.html
View
1 .gitignore
@@ -1,4 +1,3 @@
-docs
node_modules
npm-debug.log
makefile
View
186 docs/docco.css
@@ -0,0 +1,186 @@
+/*--------------------- Layout and Typography ----------------------------*/
+body {
+ font-family: 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif;
+ font-size: 15px;
+ line-height: 22px;
+ color: #252519;
+ margin: 0; padding: 0;
+}
+a {
+ color: #261a3b;
+}
+ a:visited {
+ color: #261a3b;
+ }
+p {
+ margin: 0 0 15px 0;
+}
+h1, h2, h3, h4, h5, h6 {
+ margin: 0px 0 15px 0;
+}
+ h1 {
+ margin-top: 40px;
+ }
+#container {
+ position: relative;
+}
+#background {
+ position: fixed;
+ top: 0; left: 525px; right: 0; bottom: 0;
+ background: #f5f5ff;
+ border-left: 1px solid #e5e5ee;
+ z-index: -1;
+}
+#jump_to, #jump_page {
+ background: white;
+ -webkit-box-shadow: 0 0 25px #777; -moz-box-shadow: 0 0 25px #777;
+ -webkit-border-bottom-left-radius: 5px; -moz-border-radius-bottomleft: 5px;
+ font: 10px Arial;
+ text-transform: uppercase;
+ cursor: pointer;
+ text-align: right;
+}
+#jump_to, #jump_wrapper {
+ position: fixed;
+ right: 0; top: 0;
+ padding: 5px 10px;
+}
+ #jump_wrapper {
+ padding: 0;
+ display: none;
+ }
+ #jump_to:hover #jump_wrapper {
+ display: block;
+ }
+ #jump_page {
+ padding: 5px 0 3px;
+ margin: 0 0 25px 25px;
+ }
+ #jump_page .source {
+ display: block;
+ padding: 5px 10px;
+ text-decoration: none;
+ border-top: 1px solid #eee;
+ }
+ #jump_page .source:hover {
+ background: #f5f5ff;
+ }
+ #jump_page .source:first-child {
+ }
+table td {
+ border: 0;
+ outline: 0;
+}
+ td.docs, th.docs {
+ max-width: 450px;
+ min-width: 450px;
+ min-height: 5px;
+ padding: 10px 25px 1px 50px;
+ overflow-x: hidden;
+ vertical-align: top;
+ text-align: left;
+ }
+ .docs pre {
+ margin: 15px 0 15px;
+ padding-left: 15px;
+ }
+ .docs p tt, .docs p code {
+ background: #f8f8ff;
+ border: 1px solid #dedede;
+ font-size: 12px;
+ padding: 0 0.2em;
+ }
+ .pilwrap {
+ position: relative;
+ }
+ .pilcrow {
+ font: 12px Arial;
+ text-decoration: none;
+ color: #454545;
+ position: absolute;
+ top: 3px; left: -20px;
+ padding: 1px 2px;
+ opacity: 0;
+ -webkit-transition: opacity 0.2s linear;
+ }
+ td.docs:hover .pilcrow {
+ opacity: 1;
+ }
+ td.code, th.code {
+ padding: 14px 15px 16px 25px;
+ width: 100%;
+ vertical-align: top;
+ background: #f5f5ff;
+ border-left: 1px solid #e5e5ee;
+ }
+ pre, tt, code {
+ font-size: 12px; line-height: 18px;
+ font-family: Monaco, Consolas, "Lucida Console", monospace;
+ margin: 0; padding: 0;
+ }
+
+
+/*---------------------- Syntax Highlighting -----------------------------*/
+td.linenos { background-color: #f0f0f0; padding-right: 10px; }
+span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
+body .hll { background-color: #ffffcc }
+body .c { color: #408080; font-style: italic } /* Comment */
+body .err { border: 1px solid #FF0000 } /* Error */
+body .k { color: #954121 } /* Keyword */
+body .o { color: #666666 } /* Operator */
+body .cm { color: #408080; font-style: italic } /* Comment.Multiline */
+body .cp { color: #BC7A00 } /* Comment.Preproc */
+body .c1 { color: #408080; font-style: italic } /* Comment.Single */
+body .cs { color: #408080; font-style: italic } /* Comment.Special */
+body .gd { color: #A00000 } /* Generic.Deleted */
+body .ge { font-style: italic } /* Generic.Emph */
+body .gr { color: #FF0000 } /* Generic.Error */
+body .gh { color: #000080; font-weight: bold } /* Generic.Heading */
+body .gi { color: #00A000 } /* Generic.Inserted */
+body .go { color: #808080 } /* Generic.Output */
+body .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
+body .gs { font-weight: bold } /* Generic.Strong */
+body .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
+body .gt { color: #0040D0 } /* Generic.Traceback */
+body .kc { color: #954121 } /* Keyword.Constant */
+body .kd { color: #954121; font-weight: bold } /* Keyword.Declaration */
+body .kn { color: #954121; font-weight: bold } /* Keyword.Namespace */
+body .kp { color: #954121 } /* Keyword.Pseudo */
+body .kr { color: #954121; font-weight: bold } /* Keyword.Reserved */
+body .kt { color: #B00040 } /* Keyword.Type */
+body .m { color: #666666 } /* Literal.Number */
+body .s { color: #219161 } /* Literal.String */
+body .na { color: #7D9029 } /* Name.Attribute */
+body .nb { color: #954121 } /* Name.Builtin */
+body .nc { color: #0000FF; font-weight: bold } /* Name.Class */
+body .no { color: #880000 } /* Name.Constant */
+body .nd { color: #AA22FF } /* Name.Decorator */
+body .ni { color: #999999; font-weight: bold } /* Name.Entity */
+body .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
+body .nf { color: #0000FF } /* Name.Function */
+body .nl { color: #A0A000 } /* Name.Label */
+body .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
+body .nt { color: #954121; font-weight: bold } /* Name.Tag */
+body .nv { color: #19469D } /* Name.Variable */
+body .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
+body .w { color: #bbbbbb } /* Text.Whitespace */
+body .mf { color: #666666 } /* Literal.Number.Float */
+body .mh { color: #666666 } /* Literal.Number.Hex */
+body .mi { color: #666666 } /* Literal.Number.Integer */
+body .mo { color: #666666 } /* Literal.Number.Oct */
+body .sb { color: #219161 } /* Literal.String.Backtick */
+body .sc { color: #219161 } /* Literal.String.Char */
+body .sd { color: #219161; font-style: italic } /* Literal.String.Doc */
+body .s2 { color: #219161 } /* Literal.String.Double */
+body .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
+body .sh { color: #219161 } /* Literal.String.Heredoc */
+body .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
+body .sx { color: #954121 } /* Literal.String.Other */
+body .sr { color: #BB6688 } /* Literal.String.Regex */
+body .s1 { color: #219161 } /* Literal.String.Single */
+body .ss { color: #19469D } /* Literal.String.Symbol */
+body .bp { color: #954121 } /* Name.Builtin.Pseudo */
+body .vc { color: #19469D } /* Name.Variable.Class */
+body .vg { color: #19469D } /* Name.Variable.Global */
+body .vi { color: #19469D } /* Name.Variable.Instance */
+body .il { color: #666666 } /* Literal.Number.Integer.Long */
View
188 docs/fiber.html
@@ -0,0 +1,188 @@
+<!DOCTYPE html> <html> <head> <title>fiber.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> fiber.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <pre><code>Fiber.js 1.0.5
+@author: Kirollos Risk
+
+Copyright (c) 2012 LinkedIn.
+All Rights Reserved. Apache Software License 2.0
+http://www.apache.org/licenses/LICENSE-2.0
+</code></pre> </td> <td class="code"> <div class="highlight"><pre><span class="p">(</span><span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
+ <span class="cm">/*jshint bitwise: true, camelcase: false, curly: true, eqeqeq: true,</span>
+<span class="cm"> forin: false, immed: true, indent: 2, latedef: true, newcap: false,</span>
+<span class="cm"> noarg: true, noempty: false, nonew: true, plusplus: false,</span>
+<span class="cm"> quotmark: single, regexp: false, undef: true, unused: true, strict: false,</span>
+<span class="cm"> trailing: true, asi: false, boss: false, debug: false, eqnull: true,</span>
+<span class="cm"> es5: false, esnext: false, evil: true, expr: false, funcscope: false,</span>
+<span class="cm"> iterator: false, lastsemic: false, laxbreak: false, laxcomma: false,</span>
+<span class="cm"> loopfunc: false, multistr: true, onecase: false, proto: false,</span>
+<span class="cm"> regexdash: false, scripturl: false, smarttabs: false, shadow: true,</span>
+<span class="cm"> sub: true, supernew: true, validthis: false */</span>
+
+ <span class="cm">/*global exports, global, define, module */</span>
+
+ <span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">root</span><span class="p">,</span> <span class="nx">factory</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="k">typeof</span> <span class="nx">exports</span> <span class="o">===</span> <span class="s1">&#39;object&#39;</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>Node. Does not work with strict CommonJS, but
+only CommonJS-like environments that support module.exports,
+like Node.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">module</span><span class="p">.</span><span class="nx">exports</span> <span class="o">=</span> <span class="nx">factory</span><span class="p">(</span><span class="k">this</span><span class="p">);</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="k">typeof</span> <span class="nx">define</span> <span class="o">===</span> <span class="s1">&#39;function&#39;</span> <span class="o">&amp;&amp;</span> <span class="nx">define</span><span class="p">.</span><span class="nx">amd</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>AMD. Register as an anonymous module.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">define</span><span class="p">(</span><span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="nx">factory</span><span class="p">(</span><span class="nx">root</span><span class="p">);</span>
+ <span class="p">});</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p>Browser globals (root is window)</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">root</span><span class="p">.</span><span class="nx">Fiber</span> <span class="o">=</span> <span class="nx">factory</span><span class="p">(</span><span class="nx">root</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="p">}(</span><span class="k">this</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">global</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <h2>Baseline setup</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <p>Stores whether the object is being initialized. i.e., whether
+to run the <code>init</code> function, or not.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">initializing</span> <span class="o">=</span> <span class="kc">false</span><span class="p">,</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <p>Keep a few prototype references around - for speed access,
+and saving bytes in the minified version.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">ArrayProto</span> <span class="o">=</span> <span class="nb">Array</span><span class="p">.</span><span class="nx">prototype</span><span class="p">,</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <p>Save the previous value of <code>Fiber</code>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">previousFiber</span> <span class="o">=</span> <span class="nx">global</span><span class="p">.</span><span class="nx">Fiber</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">&#182;</a> </div> <p>Helper function to copy properties from one object to the other.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">copy</span><span class="p">(</span><span class="nx">from</span><span class="p">,</span> <span class="nx">to</span><span class="p">)</span> <span class="p">{</span>
+ <span class="kd">var</span> <span class="nx">name</span><span class="p">;</span>
+ <span class="k">for</span> <span class="p">(</span><span class="nx">name</span> <span class="k">in</span> <span class="nx">from</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">from</span><span class="p">.</span><span class="nx">hasOwnProperty</span><span class="p">(</span><span class="nx">name</span><span class="p">))</span> <span class="p">{</span>
+ <span class="nx">to</span><span class="p">[</span><span class="nx">name</span><span class="p">]</span> <span class="o">=</span> <span class="nx">from</span><span class="p">[</span><span class="nx">name</span><span class="p">];</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">&#182;</a> </div> <p>The base <code>Fiber</code> implementation.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">Fiber</span><span class="p">()</span> <span class="p">{}</span></pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-11">&#182;</a> </div> <h3>Extend</h3>
+
+<p>Returns a subclass.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">Fiber</span><span class="p">.</span><span class="nx">extend</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">fn</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-12"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-12">&#182;</a> </div> <p>Keep a reference to the current prototye.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">parent</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">prototype</span><span class="p">,</span></pre></div> </td> </tr> <tr id="section-13"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-13">&#182;</a> </div> <p>Invoke the function which will return an object literal used to
+define the prototype. Additionally, pass in the parent prototype,
+which will allow instances to use it.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">properties</span> <span class="o">=</span> <span class="nx">fn</span><span class="p">(</span><span class="nx">parent</span><span class="p">),</span></pre></div> </td> </tr> <tr id="section-14"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-14">&#182;</a> </div> <p>Stores the constructor's prototype.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">proto</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-15"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-15">&#182;</a> </div> <p>The constructor function for a subclass.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">child</span><span class="p">()</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">initializing</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-16"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-16">&#182;</a> </div> <p>Custom initialization is done in the <code>init</code> method.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">init</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="nx">arguments</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-17"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-17">&#182;</a> </div> <p>Prevent subsequent calls to <code>init</code>. Note: although a <code>delete
+this.init</code> would remove the <code>init</code> function from the instance, it
+would still exist in its super class' prototype. Therefore,
+explicitly set <code>init</code> to <code>void 0</code> to obtain the <code>undefined</code>
+primitive value (in case the global's <code>undefined</code> property has
+been re-assigned).</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">init</span> <span class="o">=</span> <span class="k">void</span> <span class="mi">0</span><span class="p">;</span>
+ <span class="p">}</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-18"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-18">&#182;</a> </div> <p>Instantiate a base class (but only create the instance, without
+running <code>init</code>). And, make every <code>constructor</code> instance an instance
+of <code>this</code> and of <code>constructor</code>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">initializing</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
+ <span class="nx">proto</span> <span class="o">=</span> <span class="nx">child</span><span class="p">.</span><span class="nx">prototype</span> <span class="o">=</span> <span class="k">new</span> <span class="k">this</span><span class="p">;</span>
+ <span class="nx">initializing</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-19"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-19">&#182;</a> </div> <p>Add default <code>init</code> function, which a class may override; it should
+call the super class' <code>init</code> function (if it exists);</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">proto</span><span class="p">.</span><span class="nx">init</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="k">typeof</span> <span class="nx">parent</span><span class="p">.</span><span class="nx">init</span> <span class="o">===</span> <span class="s1">&#39;function&#39;</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">parent</span><span class="p">.</span><span class="nx">init</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="nx">arguments</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="p">};</span></pre></div> </td> </tr> <tr id="section-20"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-20">&#182;</a> </div> <p>Copy the properties over onto the new prototype.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">copy</span><span class="p">(</span><span class="nx">properties</span><span class="p">,</span> <span class="nx">proto</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-21"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-21">&#182;</a> </div> <p>Enforce the constructor to be what we expect.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">proto</span><span class="p">.</span><span class="nx">constructor</span> <span class="o">=</span> <span class="nx">child</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-22"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-22">&#182;</a> </div> <p>Keep a reference to the parent prototype.
+(Note: currently used by decorators and mixins, so that the parent
+can be inferred).</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">child</span><span class="p">.</span><span class="nx">__base__</span> <span class="o">=</span> <span class="nx">parent</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-23"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-23">&#182;</a> </div> <p>Make this class extendable, this can be overridden by providing a
+custom extend method on the proto.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">child</span><span class="p">.</span><span class="nx">extend</span> <span class="o">=</span> <span class="nx">child</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">extend</span> <span class="o">||</span> <span class="nx">Fiber</span><span class="p">.</span><span class="nx">extend</span><span class="p">;</span>
+
+
+ <span class="k">return</span> <span class="nx">child</span><span class="p">;</span>
+ <span class="p">};</span></pre></div> </td> </tr> <tr id="section-24"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-24">&#182;</a> </div> <h2>Utilities</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-25"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-25">&#182;</a> </div> <h3>Proxy</h3>
+
+<p>Returns a proxy object for accessing base methods with a given context.</p>
+
+<ul>
+<li><code>base</code>: the instance' parent class prototype.</li>
+<li><code>instance</code>: a Fiber class instance.</li>
+</ul>
+
+<p>Overloads:</p>
+
+<ul>
+<li><code>Fiber.proxy( instance )</code></li>
+<li><code>Fiber.proxy( base, instance )</code></li>
+</ul> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">Fiber</span><span class="p">.</span><span class="nx">proxy</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">base</span><span class="p">,</span> <span class="nx">instance</span><span class="p">)</span> <span class="p">{</span>
+ <span class="kd">var</span> <span class="nx">name</span><span class="p">,</span>
+ <span class="nx">iface</span> <span class="o">=</span> <span class="p">{},</span>
+ <span class="nx">wrap</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-26"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-26">&#182;</a> </div> <p>If there's only 1 argument specified, then it is the instance,
+thus infer <code>base</code> from its constructor.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="nx">arguments</span><span class="p">.</span><span class="nx">length</span> <span class="o">===</span> <span class="mi">1</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">instance</span> <span class="o">=</span> <span class="nx">base</span><span class="p">;</span>
+ <span class="nx">base</span> <span class="o">=</span> <span class="nx">instance</span><span class="p">.</span><span class="nx">constructor</span><span class="p">.</span><span class="nx">__base__</span><span class="p">;</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-27"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-27">&#182;</a> </div> <p>Returns a function which calls another function with <code>instance</code> as
+the context.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">wrap</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">fn</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="nx">base</span><span class="p">[</span><span class="nx">fn</span><span class="p">].</span><span class="nx">apply</span><span class="p">(</span><span class="nx">instance</span><span class="p">,</span> <span class="nx">arguments</span><span class="p">);</span>
+ <span class="p">};</span>
+ <span class="p">};</span></pre></div> </td> </tr> <tr id="section-28"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-28">&#182;</a> </div> <p>For each function in <code>base</code>, create a wrapped version.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">for</span> <span class="p">(</span><span class="nx">name</span> <span class="k">in</span> <span class="nx">base</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">base</span><span class="p">.</span><span class="nx">hasOwnProperty</span><span class="p">(</span><span class="nx">name</span><span class="p">)</span> <span class="o">&amp;&amp;</span> <span class="k">typeof</span> <span class="nx">base</span><span class="p">[</span><span class="nx">name</span><span class="p">]</span> <span class="o">===</span> <span class="s1">&#39;function&#39;</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">iface</span><span class="p">[</span><span class="nx">name</span><span class="p">]</span> <span class="o">=</span> <span class="nx">wrap</span><span class="p">(</span><span class="nx">name</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+ <span class="k">return</span> <span class="nx">iface</span><span class="p">;</span>
+ <span class="p">};</span></pre></div> </td> </tr> <tr id="section-29"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-29">&#182;</a> </div> <h3>Decorate</h3>
+
+<p>Decorate an instance with given decorator(s).</p>
+
+<ul>
+<li><code>instance</code>: a Fiber class instance.</li>
+<li><code>decorator[s]</code>: the argument list of decorator functions.</li>
+</ul>
+
+<p>Note: when a decorator is executed, the argument passed in is the super
+class' prototype, and the context (i.e. the <code>this</code> binding) is the
+instance.</p>
+
+<p><em>Example usage:</em></p>
+
+<pre><code>function Decorator( base ) {
+ // this === obj
+ return {
+ greet: function() {
+ console.log('hi!');
+ }
+ };
+}
+
+var obj = new Bar(); // Some instance of a Fiber class
+Fiber.decorate(obj, Decorator);
+obj.greet(); // hi!
+</code></pre> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">Fiber</span><span class="p">.</span><span class="nx">decorate</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">instance</span> <span class="cm">/*, decorator[s] */</span><span class="p">)</span> <span class="p">{</span>
+ <span class="kd">var</span> <span class="nx">i</span><span class="p">,</span></pre></div> </td> </tr> <tr id="section-30"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-30">&#182;</a> </div> <p>Get the base prototype.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">base</span> <span class="o">=</span> <span class="nx">instance</span><span class="p">.</span><span class="nx">constructor</span><span class="p">.</span><span class="nx">__base__</span><span class="p">,</span></pre></div> </td> </tr> <tr id="section-31"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-31">&#182;</a> </div> <p>Get all the decorators in the arguments.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">decorators</span> <span class="o">=</span> <span class="nx">ArrayProto</span><span class="p">.</span><span class="nx">slice</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">arguments</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span>
+ <span class="nx">len</span> <span class="o">=</span> <span class="nx">decorators</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span>
+
+ <span class="k">for</span> <span class="p">(</span><span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="nx">len</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">copy</span><span class="p">(</span><span class="nx">decorators</span><span class="p">[</span><span class="nx">i</span><span class="p">].</span><span class="nx">call</span><span class="p">(</span><span class="nx">instance</span><span class="p">,</span> <span class="nx">base</span><span class="p">),</span> <span class="nx">instance</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="p">};</span></pre></div> </td> </tr> <tr id="section-32"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-32">&#182;</a> </div> <h3>Mixin</h3>
+
+<p>Add functionality to a Fiber definition</p>
+
+<ul>
+<li><code>definition</code>: a Fiber class definition.</li>
+<li><code>mixin[s]</code>: the argument list of mixins.</li>
+</ul>
+
+<p>Note: when a mixing is executed, the argument passed in is the super
+class' prototype (i.e., the base)</p>
+
+<p>Overloads:</p>
+
+<ul>
+<li><code>Fiber.mixin( definition, mix_1 )</code></li>
+<li><code>Fiber.mixin( definition, mix_1, ..., mix_n )</code></li>
+</ul>
+
+<p><em>Example usage:</em></p>
+
+<pre><code>var Definition = Fiber.extend(function(base) {
+ return {
+ method1: function(){}
+ }
+});
+
+function Mixin(base) {
+ return {
+ method2: function(){}
+ }
+}
+
+Fiber.mixin(Definition, Mixin);
+var obj = new Definition();
+obj.method2();
+</code></pre> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">Fiber</span><span class="p">.</span><span class="nx">mixin</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">definition</span> <span class="cm">/*, mixin[s] */</span><span class="p">)</span> <span class="p">{</span>
+ <span class="kd">var</span> <span class="nx">i</span><span class="p">,</span></pre></div> </td> </tr> <tr id="section-33"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-33">&#182;</a> </div> <p>Get the base prototype.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">base</span> <span class="o">=</span> <span class="nx">definition</span><span class="p">.</span><span class="nx">__base__</span><span class="p">,</span></pre></div> </td> </tr> <tr id="section-34"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-34">&#182;</a> </div> <p>Get all the mixins in the arguments.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">mixins</span> <span class="o">=</span> <span class="nx">ArrayProto</span><span class="p">.</span><span class="nx">slice</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">arguments</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span>
+ <span class="nx">len</span> <span class="o">=</span> <span class="nx">mixins</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span>
+
+ <span class="k">for</span> <span class="p">(</span><span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="nx">len</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">copy</span><span class="p">(</span><span class="nx">mixins</span><span class="p">[</span><span class="nx">i</span><span class="p">](</span><span class="nx">base</span><span class="p">),</span> <span class="nx">definition</span><span class="p">.</span><span class="nx">prototype</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="p">};</span></pre></div> </td> </tr> <tr id="section-35"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-35">&#182;</a> </div> <h3>noConflict</h3>
+
+<p>Run Fiber.js in <em>noConflict</em> mode, returning the <code>fiber</code> variable to
+its previous owner. Returns a reference to the Fiber object.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">Fiber</span><span class="p">.</span><span class="nx">noConflict</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
+ <span class="nx">global</span><span class="p">.</span><span class="nx">Fiber</span> <span class="o">=</span> <span class="nx">previousFiber</span><span class="p">;</span>
+ <span class="k">return</span> <span class="nx">Fiber</span><span class="p">;</span>
+ <span class="p">};</span>
+
+ <span class="k">return</span> <span class="nx">Fiber</span><span class="p">;</span>
+ <span class="p">}));</span>
+<span class="p">}</span> <span class="p">());</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>

0 comments on commit 8273533

Please sign in to comment.