UNPKG

angoose

Version:

Angoose is a Remote Method Invocation module that comes with built-in mongoose/angular support. Now you can call server side module in browser just like you're in the server side!

233 lines (170 loc) 9.53 kB
<!DOCTYPE html> <html> <head> <title>Remotable.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <ul id="jump_to"> <li> <a class="large" href="javascript:void(0);">Jump To &hellip;</a> <a class="small" href="javascript:void(0);">+</a> <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="Context.html"> Context.js </a> <a class="source" href="Model.html"> Model.js </a> <a class="source" href="Principal.html"> Principal.js </a> <a class="source" href="Remotable.html"> Remotable.js </a> <a class="source" href="Schema.html"> Schema.js </a> <a class="source" href="Service.html"> Service.js </a> <a class="source" href="angoose.html"> angoose.js </a> </div> </li> </ul> <ul class="sections"> <li id="title"> <div class="annotation"> <h1>Remotable.js</h1> </div> </li> <li id="section-1"> <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>This is the base class for Angoose model classes and service classes. This is used internally and it&#39;s here only for listing the APIs common to all Model and Service classes. </p> </div> <div class="content"><div class='highlight'><pre><span class="keyword">var</span> logger = require(<span class="string">"log4js"</span>).getLogger(<span class="string">"angoose"</span>); <span class="keyword">var</span> _ = require(<span class="string">"underscore"</span>); <span class="keyword">var</span> Class = require(<span class="string">"./util/classy"</span>); <span class="keyword">var</span> schemaUtil = require(<span class="string">"./Schema"</span>);</pre></div></div> </li> <li id="section-2"> <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-2">&#182;</a> </div> <h3 id="api-rereferences">API Rereferences</h3> <p><strong>getContext()</strong></p> <p>This method allows you obtain the execution context. See <a href="Context.html">Context</a> for more. </p> <p>Note this method is also available on the class(function) as well. i.e.,</p> <pre><code> /** MyModel is subclass of Remotable */ var instance = new MyModel(); /** Following yields true */ MyModel.getContext() === instance.getContext(); </code></pre> </div> <div class="content"><div class='highlight'><pre><span class="keyword">var</span> getContext = <span class="function"><span class="keyword">function</span><span class="params">()</span>{</span> <span class="keyword">return</span> require(<span class="string">"./angoose"</span>).getContext() } <span class="keyword">var</span> Remotable = Class.$extend({}); Remotable.prototype = { getContext: getContext } Remotable._angoosemeta ={ baseClass: <span class="string">'Remotable'</span> } Remotable.extend = extend; Remotable.getContext = getContext;</pre></div></div> </li> <li id="section-3"> <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p><strong> extend </strong></p> <p>This static method is used to create Angoose model or service classes. All classes created using this method is a subclass of <code>Remotable</code></p> </div> <div class="content"><div class='highlight'><pre><span class="function"><span class="keyword">function</span> <span class="title">extend</span><span class="params">(target, options)</span>{</span> options = options||{}; <span class="keyword">var</span> parentClass = <span class="keyword">this</span>; logger.trace(<span class="string">"Extending from "</span>, parentClass._angoosemeta.name, options); <span class="keyword">var</span> rv = <span class="literal">null</span>; <span class="keyword">if</span>(<span class="keyword">typeof</span> (target) == <span class="string">'function'</span>){ rv = target; mixinInstance(parentClass, rv, options); } <span class="keyword">else</span>{ <span class="comment">/** schema object */</span> rv = parentClass.$extend( target ); } <span class="comment">/** mixin Angoose class level functions */</span> rv = mixinStatic(parentClass, rv, options); <span class="keyword">if</span>(rv._angoosemeta.name){ <span class="comment">/** register it with Angoose */</span> require(<span class="string">"./angoose"</span>).registerClass(rv._angoosemeta.name, rv); } <span class="keyword">return</span> rv; } <span class="function"><span class="keyword">function</span> <span class="title">mixinInstance</span><span class="params">(parentClass, subClass, options)</span>{</span> subClass.prototype.getContext = getContext; <span class="comment">/** look for static classes*/</span> } <span class="function"><span class="keyword">function</span> <span class="title">mixinStatic</span><span class="params">(parentClass, subClass, options)</span>{</span> <span class="comment">/** mixin Angoose functions to the new class */</span> <span class="comment">/** if(subClass.extend || subClass.getContext ) throw "Class already has 'extend' or 'getContext' property/method" */</span> <span class="comment">/** mixing static properties from parentClass to subClass */</span> <span class="keyword">for</span>(<span class="keyword">var</span> prop <span class="keyword">in</span> parentClass){ <span class="keyword">var</span> val = parentClass[prop]; <span class="keyword">if</span>(!parentClass.hasOwnProperty(prop) || <span class="keyword">typeof</span>(val) != <span class="string">'function'</span>) <span class="keyword">continue</span>; <span class="keyword">if</span>(isRemotableReserved(prop)) <span class="keyword">continue</span>; <span class="keyword">if</span>(subClass[prop]) { logger.warn(<span class="string">"Cannot mixin subclass: property '"</span>+ prop+<span class="string">"' already exists on subclass"</span>); <span class="keyword">throw</span> <span class="string">"Subclass already has property '"</span>+ prop+<span class="string">"' defined."</span>; } logger.trace(<span class="string">"Mixing: "</span>, prop) subClass[prop] = val; }</pre></div></div> </li> <li id="section-4"> <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p>subClass.extend = extend; subClass.getContext = getContext;</p> </div> <div class="content"><div class='highlight'><pre> subClass._angoosemeta = _.extend({}, parentClass._angoosemeta); subClass._angoosemeta = _.extend(subClass._angoosemeta, options) <span class="keyword">return</span> subClass; } <span class="function"><span class="keyword">function</span> <span class="title">isRemotableReserved</span><span class="params">(methodName)</span>{</span> <span class="comment">/** check if method is reserved by the Remotable interface */</span> <span class="keyword">return</span> methodName.indexOf(<span class="string">"_"</span>) == <span class="number">0</span> || methodName.indexOf(<span class="string">"$"</span>) == <span class="number">0</span> || [<span class="string">'constructor'</span>, <span class="string">'isRemotableReserved'</span>].indexOf(methodName)&gt;=<span class="number">0</span>; } <span class="comment">/** a$ is Angoose's internal property*/</span></pre></div></div> </li> <li id="section-5"> <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-5">&#182;</a> </div> <p>Remotable.prototype._angoosemeta = {};</p> </div> <div class="content"><div class='highlight'><pre>Remotable.getContext = getContext; Remotable.isRemotableReserved=isRemotableReserved; module.exports = Remotable</pre></div></div> </li> </ul> </div> </body> </html>