expresser
Version:
A ready-to-use platform for Node.js web apps, built on top of Express.
203 lines (123 loc) • 6.26 kB
HTML
<html>
<head>
<title>events.coffee</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="stylesheet" media="all" href="public/stylesheets/normalize.css" />
<link rel="stylesheet" media="all" href="docco.css" />
</head>
<body>
<div class="container">
<div class="page">
<div class="header">
<h1>events.coffee</h1>
<div class="toc">
<h3>Table of Contents</h3>
<ol>
<li>
<a class="source" href="index.html">
index.coffee
</a>
</li>
<li>
<a class="source" href="app.html">
app.coffee
</a>
</li>
<li>
<a class="source" href="cron.html">
cron.coffee
</a>
</li>
<li>
<a class="source" href="database.html">
database.coffee
</a>
</li>
<li>
<a class="source" href="downloader.html">
downloader.coffee
</a>
</li>
<li>
<a class="source" href="events.html">
events.coffee
</a>
</li>
<li>
<a class="source" href="firewall.html">
firewall.coffee
</a>
</li>
<li>
<a class="source" href="imaging.html">
imaging.coffee
</a>
</li>
<li>
<a class="source" href="logger.html">
logger.coffee
</a>
</li>
<li>
<a class="source" href="mailer.html">
mailer.coffee
</a>
</li>
<li>
<a class="source" href="settings.html">
settings.coffee
</a>
</li>
<li>
<a class="source" href="sockets.html">
sockets.coffee
</a>
</li>
<li>
<a class="source" href="utils.html">
utils.coffee
</a>
</li>
</ol>
</div>
</div>
<h2 id="expresser-events">EXPRESSER EVENTS</h2>
<p>Central event manager to dispatch events to all Expresser modules.
This module acts as a wrapper to Node’s EventEmitter class.</p>
<div class='highlight'><pre><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Events</span></span>
evt = <span class="hljs-built_in">require</span> <span class="hljs-string">"events"</span>
emitter = <span class="hljs-keyword">new</span> evt.EventEmitter()</pre></div>
<h2 id="methods">METHODS</h2>
<p>Emit a new event. The first argument is the event ID, all others are
passed to the event emitter.
@param [String] id The event ID.
@param [Arguments] args Arguments to be passed to the emitter.
@return Returns itself so calls can be chained.</p>
<div class='highlight'><pre> <span class="hljs-attribute">emit</span>: <span class="hljs-function"><span class="hljs-params">(id, args)</span> =></span>
emitter.emit.apply emitter, arguments
<span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span></pre></div>
<p>Bind a specific callback to an event ID.
@param [String] id The event ID.
@param [Method] callback The callback to be triggered.
@return Returns itself so calls can be chained.</p>
<div class='highlight'><pre> <span class="hljs-attribute">on</span>: <span class="hljs-function"><span class="hljs-params">(id, callback)</span> =></span>
emitter.addListener id, callback
<span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span></pre></div>
<p>Remove a specific callback from the listeners related to an event ID.
@param [String] id The event ID.
@param [Method] callback The callback to be removed.
@return Returns itself so calls can be chained.</p>
<div class='highlight'><pre> <span class="hljs-attribute">off</span>: <span class="hljs-function"><span class="hljs-params">(id, callback)</span> =></span>
emitter.removeListener id, callback
<span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span></pre></div>
<h2 id="singleton-implementation-">Singleton implementation.</h2>
<div class='highlight'><pre>Events.<span class="hljs-function"><span class="hljs-title">getInstance</span> = -></span>
<span class="hljs-property">@instance</span> = <span class="hljs-keyword">new</span> Events() <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> <span class="hljs-property">@instance</span>?
<span class="hljs-keyword">return</span> <span class="hljs-property">@instance</span>
<span class="hljs-built_in">module</span>.<span class="hljs-built_in">exports</span> = <span class="hljs-built_in">exports</span> = Events.getInstance()</pre></div>
<div class="fleur">h</div>
</div>
</div>
</body>
</html>