<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
<channel>
	<title>Los Techies</title>
    
	<link>http://lostechies.com</link>
	<description>LosTechies.com was originally discussed a few years ago, over a couple of adult beverages whose name sounds very similar to l(D)os t(E)quies. Anyway the thought was to create a public forum where technical ideas and thoughts can be shared in the same way we all get together around a good meal and drinks. Ideas and thoughts are cultivated in discussion, and brought to fruition through professional debate and laughter. Sounds good in theory, well read our thoughts and ideas, take part in our debates and rejoice in our laughter.</description>
	<lastBuildDate>Wed, 23 May 2012 20:21:27 +0000</lastBuildDate>
		<language>en</language>
        <image>
		<url>http://lostechies.com/favicon.ico</url>
		<title>LosTechies Master Site Feed Posts &amp; Pages</title>
		<link>http://lostechies.com</link>
	</image>
    
<generator>http://wordpress.org/?v=3.1.1</generator>
	<feedburner:info uri="lostechies" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/BigNellie" /><feedburner:info uri="bignellie" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Would you like to be employee #1 at a Software Company</title>
		<link>http://feedproxy.google.com/~r/LosTechies/~3/KdffPslziGM/</link>
		<comments>http://lostechies.com/johnteague/2012/05/23/would-you-like-to-be-employee-1-at-a-software-company/#comments</comments>
		<pubDate>Wed, 23 May 2012 20:21:27 +0000</pubDate>
		<dc:creator>John Teague</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://lostechies.com/johnteague/?p=109]]></guid>
		<description><![CDATA[Update: this position is located in Austin.  However if you don&#8217;t live in the area and are interested in working with us, please contact me.  I&#8217;m always interested in working with talented developers no matter where they live! I&#8217;m expanding&#160;&#8230; <a href="http://lostechies.com/johnteague/2012/05/23/would-you-like-to-be-employee-1-at-a-software-company/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p><strong>Update: </strong>this position is located in Austin.  However if you don&#8217;t live in the area and are interested in working with us, please contact me.  I&#8217;m always interested in working with talented developers no matter where they live!</p>
<p>I&#8217;m expanding my company.  I&#8217;m looking to hire a polyglot programmer that is comfortable in C#, JavaScript, Ruby, the best tool for the job.</p>
<p>We&#8217;re a mix of consulting and software products (just starting our first) and you&#8217;ll work with a good group of guys offshore as well.  You&#8217;ll be setting the architecture for ours and our clients applications, defining user stories and acceptance criteria and making sure quality stays at an extremely high level.  TDD and Agile are required.</p>
<p>Compensation will be salary+equity.  Chances are, if you&#8217;re sr. .Net developer, salary will be lower than what you&#8217;re making now.  But you&#8217;ll have a lot responsibility, and a life (40 hour work weeks).  You&#8217;ll need to be more excited about owning part of the company and making it into something exceptional.</p>
<p>You can contact me through the website, on twitter at @john_teague, or at john at avenidasoftware.com if you are interested.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/LosTechies?a=KdffPslziGM:tpsfqd504ak:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/LosTechies?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=KdffPslziGM:tpsfqd504ak:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/LosTechies?i=KdffPslziGM:tpsfqd504ak:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=KdffPslziGM:tpsfqd504ak:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/LosTechies?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=KdffPslziGM:tpsfqd504ak:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/LosTechies?i=KdffPslziGM:tpsfqd504ak:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/LosTechies/~4/KdffPslziGM" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://lostechies.com/johnteague/2012/05/23/would-you-like-to-be-employee-1-at-a-software-company/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
            <media:content url="http://www.gravatar.com/avatar/4ec3c07d6f4527238a3f5c6ec5fefd63?s=96&amp;d=http%3A%2F%2Fwww.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
            <media:title type="html">John Teague</media:title>
        </media:content>
    		<feedburner:origLink>http://lostechies.com/johnteague/2012/05/23/would-you-like-to-be-employee-1-at-a-software-company/</feedburner:origLink></item>
	<item>
		<title>$(function(){…}) vs (function($){…})($) or DOMReady vs The Module Pattern</title>
		<link>http://feedproxy.google.com/~r/LosTechies/~3/O-g3VMzEGvQ/</link>
		<comments>http://lostechies.com/derickbailey/2012/05/22/function%e2%80%a6-vs-function%e2%80%a6-or-domready-vs-the-module-pattern/#comments</comments>
		<pubDate>Tue, 22 May 2012 13:06:33 +0000</pubDate>
		<dc:creator>Derick Bailey</dc:creator>
				<category><![CDATA[Backbone]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Principles and Patterns]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://lostechies.com/derickbailey/?p=940]]></guid>
		<description><![CDATA[This was originally a StackOverflow question. I&#8217;m re-posting here because I think the question is fairly common, and I like the answer that I provided.  Why define anonymous function and pass it jQuery as the argument? This is the original&#160;&#8230; <a href="http://lostechies.com/derickbailey/2012/05/22/function%e2%80%a6-vs-function%e2%80%a6-or-domready-vs-the-module-pattern/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p>This was originally <a href="http://stackoverflow.com/questions/10371539/why-define-anonymous-function-and-pass-it-jquery-as-the-argument/10372429#10372429">a StackOverflow question</a>. I&#8217;m re-posting here because I think the question is fairly common, and I like the answer that I provided. </p>
<h2>Why define anonymous function and pass it jQuery as the argument?</h2>
<p>This is the original question title, but it doesn&#8217;t really show the nuances of the question&#8217;s content. The StackOverflow user really wants to know the difference between an <a href="http://benalman.com/news/2010/11/immediately-invoked-function-expression/">immediately-invoked function expression</a>, and the jQuery DOMReady event:</p>
<div id="gist-2762389" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">$</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC2'>&nbsp;&nbsp;<span class="c1">// Backbone code in here</span></div><div class='line' id='LC3'><span class="p">})(</span><span class="nx">jQuery</span><span class="p">);</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2762389/cc870d7947fb6e22ecd8db3618e315765479b4df/1.js" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2762389#file_1.js" style="float:right;margin-right:10px;color:#666">1.js</a>
            <a href="https://gist.github.com/2762389">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>vs</p>
<div id="gist-2762389" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="nx">$</span><span class="p">(</span><span class="kd">function</span><span class="p">(){</span></div><div class='line' id='LC2'>&nbsp;&nbsp;<span class="c1">// Backbone code in here</span></div><div class='line' id='LC3'><span class="p">});</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2762389/bc10775430e2af25e1ef17e3ca26d775dc47d162/2.js" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2762389#file_2.js" style="float:right;margin-right:10px;color:#666">2.js</a>
            <a href="https://gist.github.com/2762389">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>At a high level, the two blocks of code shown are dramatically different in when and why they execute. They do not serve the same purpose. But they are not exclusive of each other. In fact, you can nest them in to each other if you want &#8211; although this can have some odd effects if you&#8217;re not careful.</p>
<h2>jQuery&#8217;s &#8220;DOMReady&#8221; function</h2>
<div id="gist-2762389" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="nx">$</span><span class="p">(</span><span class="kd">function</span><span class="p">(){</span></div><div class='line' id='LC2'>&nbsp;&nbsp;<span class="c1">// Backbone code in here</span></div><div class='line' id='LC3'><span class="p">});</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2762389/bc10775430e2af25e1ef17e3ca26d775dc47d162/2.js" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2762389#file_2.js" style="float:right;margin-right:10px;color:#666">2.js</a>
            <a href="https://gist.github.com/2762389">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>This is an alias to <a href="http://api.jquery.com/ready/">jQuery&#8217;s &#8220;DOMReady&#8221; function</a> which executes when the DOM is ready to be manipulated by your JavaScript code. This allows you to write code that needs the DOM, knowing that the DOM is available and ready to be read, written to, and otherwise modified by your application. </p>
<p>This is not a module, though. This is only a callback function passed in to the DOMReady alias. The major difference between a module and a callback, in this case, is that jQuery waits for the DOM to be ready and then calls the callback function at the appropriate time &#8211; all from the context of jQuery &#8211; while a module pattern or immediately invoking function executes immediately after it&#8217;s defined. In the above examples, the module is receiving jQuery as a parameter, but this is not the same as using jQuery&#8217;s DOMReady event because the module function is called, passing in jQuery as a parameter, immediately. It does not wait for the DOM to be ready. It executes as soon as the function has been parsed.</p>
<h2>JavaScript Modules</h2>
<div id="gist-2762389" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">$</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC2'>&nbsp;&nbsp;<span class="c1">// Backbone code in here</span></div><div class='line' id='LC3'><span class="p">})(</span><span class="nx">jQuery</span><span class="p">);</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2762389/cc870d7947fb6e22ecd8db3618e315765479b4df/1.js" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2762389#file_1.js" style="float:right;margin-right:10px;color:#666">1.js</a>
            <a href="https://gist.github.com/2762389">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>This is an immediately-invoking function expression (FKA &#8220;anonymous function&#8221;, &#8220;self-invoking function&#8221;, etc).</p>
<p>The implementation of this is a function that is immediately invoked by the calling (jQuery) parenthesis. The purpose of passing jQuery in to the parenthesis is to provide local scoping to the global variable. This helps reduce the amount of overhead of looking up the $ variable, and allows better compression / optimization for minifiers in some cases.</p>
<p>In this case, the function is being used as the JavaScript &#8220;module&#8221; pattern. Modules in the currently implemented version of JavaScript in most browsers, are not specific constructs like functions. Rather, they are a pattern of implementation that use an immediately invoking function to provide scope and privacy around a &#8220;module&#8221; of related functionality. It&#8217;s common for modules to expose a public API &#8211; the &#8220;revealing module&#8221; pattern &#8211; by returning an object from the module&#8217;s function. But at times, modules are entirely self-contained and don&#8217;t provide any external methods to call. </p>
<p>For more information on modules, see the following resources:</p>
<ul>
<li><a href="http://www.watchmecode.net/javascript-scope">WatchMeCode Episode 2: Variable Scope</a> (covering modules, which provide scope)</li>
<li>Ben Alman&#8217;s <a href="http://benalman.com/news/2010/11/immediately-invoked-function-expression/">Immediately Invoking Function Expressions Post</a></li>
<li>Addy Osmani&#8217;s <a href="http://addyosmani.com/resources/essentialjsdesignpatterns/book/#modulepatternjavascript">Essential Design Patterns in JavaScript book &#8211; the module pattern</a>. </li>
<li>Adequately Good: <a href="http://www.adequatelygood.com/2010/3/JavaScript-Module-Pattern-In-Depth">JavaScript Module Pattern In-Depth</a></li>
<li>Stoyan Stefanov&#8217;s <a href="http://www.amazon.com/JavaScript-Patterns-Stoyan-Stefanov/dp/0596806752">JavaScript Patterns book</a></li>
</ul>
<h2>Modules vs DOMReady In Backbone Apps</h2>
<p>It&#8217;s bad form to define your Backbone code inside of jQuery&#8217;s DOMReady function, and <a href="http://encosia.com/dont-let-jquerys-document-ready-slow-you-down/">potentially damaging to your application performance</a>. This function does not get called until the DOM has loaded and is ready to be manipulated. That means you&#8217;re waiting until the browser has parsed the DOM at least once before you are defining your objects.</p>
<p>It&#8217;s a better idea to define your Backbone objects outside of a DOMReady function. I, among many others, prefer to do this inside of a JavaScript Module pattern so that I can provide encapsulation and privacy for my code. I tend to use the &#8220;Revealing Module&#8221; pattern (see the links above) to provide access to the bits that I need outside of my module.</p>
<p><span>Modules And DOMReady In Backbone Apps</span></p>
<p>You&#8217;re likely going to use a DOMReady function even if you define your Backbone objects somewhere else. The reason is that many Backbone apps need to manipulate the DOM in some manner. To do this, you need to wait until the DOM is ready, therefore you need to use the DOMReady function to start your application after it has been defined.</p>
<p>Here&#8217;s a very basic example that uses both a Module and the DOMReady function in a Backbone application.</p>
<div id="gist-2762389" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="c1">// Define &quot;MyApp&quot; as a revealing module</span></div><div class='line' id='LC2'><br/></div><div class='line' id='LC3'><span class="nx">MyApp</span> <span class="o">=</span> <span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">Backbone</span><span class="p">,</span> <span class="nx">$</span><span class="p">){</span></div><div class='line' id='LC4'><br/></div><div class='line' id='LC5'>&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">View</span> <span class="o">=</span> <span class="nx">Backbone</span><span class="p">.</span><span class="nx">View</span><span class="p">.</span><span class="nx">extend</span><span class="p">({</span></div><div class='line' id='LC6'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="c1">// do stuff here  </span></div><div class='line' id='LC7'>&nbsp;&nbsp;<span class="p">});</span></div><div class='line' id='LC8'><br/></div><div class='line' id='LC9'>&nbsp;&nbsp;<span class="k">return</span> <span class="p">{</span></div><div class='line' id='LC10'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">init</span><span class="o">:</span> <span class="kd">function</span><span class="p">(){</span></div><div class='line' id='LC11'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">view</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">View</span><span class="p">();</span></div><div class='line' id='LC12'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">$</span><span class="p">(</span><span class="s2">&quot;#some-div&quot;</span><span class="p">).</span><span class="nx">html</span><span class="p">(</span><span class="nx">view</span><span class="p">.</span><span class="nx">render</span><span class="p">().</span><span class="nx">el</span><span class="p">);</span></div><div class='line' id='LC13'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC14'>&nbsp;&nbsp;<span class="p">};</span></div><div class='line' id='LC15'><br/></div><div class='line' id='LC16'><span class="p">})(</span><span class="nx">Backbone</span><span class="p">,</span> <span class="nx">jQuery</span><span class="p">);</span></div><div class='line' id='LC17'><br/></div><div class='line' id='LC18'><br/></div><div class='line' id='LC19'><br/></div><div class='line' id='LC20'><span class="c1">// Run &quot;MyApp&quot; in DOMReady</span></div><div class='line' id='LC21'><br/></div><div class='line' id='LC22'><span class="nx">$</span><span class="p">(</span><span class="kd">function</span><span class="p">(){</span></div><div class='line' id='LC23'>&nbsp;&nbsp;<span class="nx">MyApp</span><span class="p">.</span><span class="nx">init</span><span class="p">();</span></div><div class='line' id='LC24'><span class="p">});</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2762389/0cfb79f7896988935aace323fc317d28455952de/3.js" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2762389#file_3.js" style="float:right;margin-right:10px;color:#666">3.js</a>
            <a href="https://gist.github.com/2762389">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>Note that we&#8217;re defining the module well before the jQuery DOMReady function is called. We&#8217;re also calling the API that our module defined and returned from the module definition, within the DOMReady callback. This is an important point to understand, too. We&#8217;re not defining our objects and our application flow inside of the DOMReady callback. We&#8217;re defining it elsewhere. We&#8217;re letting the application definition live on it&#8217;s own. Then after the application has been defined, and when the DOM is ready, the application is started.</p>
<p>By defining your objects outside of the DOMReady function, and providing some way to reference them, you are allowing the browser to get a head start on processing your JavaScript, potentially speeding up the user experience. It also makes the code more flexible as you can move things around without having to worry about creating more DOMREady functions when you do move things.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/LosTechies?a=O-g3VMzEGvQ:ZSYNaRfw6yo:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/LosTechies?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=O-g3VMzEGvQ:ZSYNaRfw6yo:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/LosTechies?i=O-g3VMzEGvQ:ZSYNaRfw6yo:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=O-g3VMzEGvQ:ZSYNaRfw6yo:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/LosTechies?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=O-g3VMzEGvQ:ZSYNaRfw6yo:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/LosTechies?i=O-g3VMzEGvQ:ZSYNaRfw6yo:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/LosTechies/~4/O-g3VMzEGvQ" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://lostechies.com/derickbailey/2012/05/22/function%e2%80%a6-vs-function%e2%80%a6-or-domready-vs-the-module-pattern/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
            <media:content url="http://www.gravatar.com/avatar/e592bd1326b1e80188ed4c0bf26b9f75?s=96&amp;d=http%3A%2F%2Fwww.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
            <media:title type="html">Derick Bailey</media:title>
        </media:content>
    		<feedburner:origLink>http://lostechies.com/derickbailey/2012/05/22/function%e2%80%a6-vs-function%e2%80%a6-or-domready-vs-the-module-pattern/</feedburner:origLink></item>
	<item>
		<title>RabbitMQ for Windows: Topic Exchanges</title>
		<link>http://feedproxy.google.com/~r/LosTechies/~3/lx63Dhs6P_c/</link>
		<comments>http://lostechies.com/derekgreer/2012/05/18/rabbitmq-for-windows-topic-exchanges/#comments</comments>
		<pubDate>Fri, 18 May 2012 15:31:06 +0000</pubDate>
		<dc:creator>Derek Greer</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[RabbitMQ]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://lostechies.com/derekgreer/?p=781]]></guid>
		<description><![CDATA[This is the seventh installment to the series: RabbitMQ for Windows.&#160; In the last installment, we walked through creating a fanout exchange example.&#160; In this installment, we’ll be walking through a topic exchange example. Topic exchanges are similar to direct&#160;&#8230; <a href="http://lostechies.com/derekgreer/2012/05/18/rabbitmq-for-windows-topic-exchanges/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p>This is the seventh installment to the series: RabbitMQ for Windows.&nbsp; In the <a href="http://lostechies.com/derekgreer/2012/05/16/rabbitmq-for-windows-fanout-exchanges/">last installment</a>, we walked through creating a fanout exchange example.&nbsp; In this installment, we’ll be walking through a topic exchange example.</p>
<p>Topic exchanges are similar to direct exchanges in that they use a routing key to determine which queue a message should be delivered to, but they differ in that they provide the ability to match on portions of a routing key.&nbsp; When publishing to a topic exchange, a routing key consisting of multiple words separated by periods (e.g. “word1.word2.word3”) will be matched against a pattern supplied by the binding queue.&nbsp; Patterns may contain an asterisk (“*”) to match a word in a specific segment or a hash (“#”) to match zero or more words.&nbsp; As discussed earlier in the series, the topic exchange type can be useful for directing messages based on multiple categories or for routing messages originating from multiple sources.</p>
<p>To demonstrate topic exchanges, we’ll return to our logging example, but this time we’ll subscribe to a subset of the messages being published to demonstrate the flexibility of how routing keys are used by topic exchanges.&nbsp; For this example, we’ll be modeling a scenario where a company may have multiple client installations, each of which may be used to service different sectors of a company’s business model (e.g. Business or Personal sectors).&nbsp; We’ll use a routing key that specifies the sector and subscribe to messages published for the Personal sector only.</p>
<p>As with our previous examples, we’ll keep things simple by creating console applications for a Producer and a Consumer.&nbsp; Let’s start by creating the Producer app and establishing a connection using the default settings:</p>
<pre class="prettyprint">using RabbitMQ.Client;

namespace Producer
{
  class Program
  {
    const long ClientId = 10843;

    static void Main(string[] args)
    {
      var connectionFactory = new ConnectionFactory();
      IConnection connection = connectionFactory.CreateConnection();
    }
  }
}
</pre>
<p>&nbsp;</p>
<p>Rather than just publishing messages directly from the Main() method as with our first logging example, let’s create a separate logger object this time.&nbsp; Here the logger interface and implementation we’ll be using:</p>
<pre class="prettyprint">  interface ILogger
  {
    void Write(Sector sector, string entry, TraceEventType traceEventType);
  }

  class RabbitLogger : ILogger, IDisposable
  {
    readonly long _clientId;
    readonly IModel _channel;
    bool _disposed;

    public RabbitLogger(IConnection connection, long clientId)
    {
      _clientId = clientId;
      _channel = connection.CreateModel();
      _channel.ExchangeDeclare("direct-exchange-example", ExchangeType.Topic, false, true, null);
    }

    public void Dispose()
    {
      if (!_disposed)
      {
        if (_channel != null &amp;&amp; _channel.IsOpen)
        {
          _channel.Close();
        }
      }
      GC.SuppressFinalize(this);
    }

    public void Write(Sector sector, string entry, TraceEventType traceEventType)
    {
      byte[] message = Encoding.UTF8.GetBytes(entry);
      string routingKey = string.Format("{0}.{1}.{2}", _clientId, sector.ToString(), traceEventType.ToString());
      _channel.BasicPublish("topic-exchange-example", routingKey, null, message);
    }

    ~RabbitLogger()
    {
      Dispose();
    }
  }
</pre>
<p>In addition to an open IConnection, our RabbitLogger class is instantiated with a client Id.&nbsp; We use this as part of the routing key.&nbsp; Since each log can vary by sector, we pass a Sector enum as part of the Write() method.&nbsp; Here’s our Sector enum:</p>
<pre class="prettyprint">  public enum Sector
  {
    Personal,
    Business
  }
</pre>
<p>Returning to our Main() method, we now need to instantiate our RabbitLogger and log messages with differing sectors.&nbsp; As as way to ensure our client has an opportunity to subscribe to our messages and to help emulate a continual stream of log messages being published, let’s use the logger to publish a series of log messages every second for 10 seconds:</p>
<pre class="prettyprint">      TimeSpan time = TimeSpan.FromSeconds(10);
      var stopwatch = new Stopwatch();
      Console.WriteLine("Running for {0} seconds", time.ToString("ss"));
      stopwatch.Start();

      while (stopwatch.Elapsed &lt; time)
      {
        using (var logger = new RabbitLogger(connection, ClientId))
        {
          Console.Write("Time to complete: {0} seconds\r", (time - stopwatch.Elapsed).ToString("ss"));
          logger.Write(Sector.Personal, "This is an information message", TraceEventType.Information);
          logger.Write(Sector.Business, "This is an warning message", TraceEventType.Warning);
          logger.Write(Sector.Business, "This is an error message", TraceEventType.Error);
          Thread.Sleep(1000);
        }
      }
</pre>
<p>This code prints out the time remaining just to give us a little feedback on the publishing progress.&nbsp; Finally, we’ll close our our connection and prompt the user to exit the console application:</p>
<pre class="prettyprint">      connection.Close();
      Console.Write("                             \r");
      Console.WriteLine("Press any key to exit");
      Console.ReadKey();
</pre>
<p>&nbsp;</p>
<p>Here’s the full Producer listing:</p>
<pre class="prettyprint">using System;
using System.Diagnostics;
using System.Text;
using System.Threading;
using RabbitMQ.Client;

namespace Producer
{
  public enum Sector
  {
    Personal,
    Business
  }

  interface ILogger
  {
    void Write(Sector sector, string entry, TraceEventType traceEventType);
  }

  class RabbitLogger : ILogger, IDisposable
  {
    readonly long _clientId;
    readonly IModel _channel;
    bool _disposed;

    public RabbitLogger(IConnection connection, long clientId)
    {
      _clientId = clientId;
      _channel = connection.CreateModel();
      _channel.ExchangeDeclare("direct-exchange-example", ExchangeType.Topic, false, true, null);
    }

    public void Dispose()
    {
      if (!_disposed)
      {
        if (_channel != null &amp;&amp; _channel.IsOpen)
        {
          _channel.Close();
        }
      }
      GC.SuppressFinalize(this);
    }

    public void Write(Sector sector, string entry, TraceEventType traceEventType)
    {
      byte[] message = Encoding.UTF8.GetBytes(entry);
      string routingKey = string.Format("{0}.{1}.{2}", _clientId, sector.ToString(), traceEventType.ToString());
      _channel.BasicPublish("topic-exchange-example", routingKey, null, message);
    }

    ~RabbitLogger()
    {
      Dispose();
    }
  }

  class Program
  {
    const long ClientId = 10843;

    static void Main(string[] args)
    {
      var connectionFactory = new ConnectionFactory();
      IConnection connection = connectionFactory.CreateConnection();

      TimeSpan time = TimeSpan.FromSeconds(10);
      var stopwatch = new Stopwatch();
      Console.WriteLine("Running for {0} seconds", time.ToString("ss"));
      stopwatch.Start();

      while (stopwatch.Elapsed &lt; time)
      {
        using (var logger = new RabbitLogger(connection, ClientId))
        {
          Console.Write("Time to complete: {0} seconds\r", (time - stopwatch.Elapsed).ToString("ss"));
          logger.Write(Sector.Personal, "This is an information message", TraceEventType.Information);
          logger.Write(Sector.Business, "This is an warning message", TraceEventType.Warning);
          logger.Write(Sector.Business, "This is an error message", TraceEventType.Error);
          Thread.Sleep(1000);
        }
      }

      connection.Close();
      Console.Write("                             \r");
      Console.WriteLine("Press any key to exit");
      Console.ReadKey();
    }
  }
}
</pre>
<p>&nbsp;</p>
<p>For our Consumer app, we’ll pretty much be using the same code as with our fanout exchange example, but we’ll need to change the exchange type along with the exchange and queue names.&nbsp; Additionally, we also need to provide a routing key that registers for logs in the Personal sector only.&nbsp; The messages published by the Producer will be in the form: [client Id].[sector].[log severity], so we can use a routing key of “*.Personal.*” (or alternately “*.Personal.#”).&nbsp; Here’s the full Consumer listing:</p>
<pre class="prettyprint">using System;
using System.IO;
using System.Text;
using RabbitMQ.Client;
using RabbitMQ.Client.Events;

namespace Consumer
{
  class Program
  {
    static void Main(string[] args)
    {
      var connectionFactory = new ConnectionFactory();
      IConnection connection = connectionFactory.CreateConnection();
      IModel channel = connection.CreateModel();

      channel.ExchangeDeclare("topic-exchange-example", ExchangeType.Topic, false, true, null);
      channel.QueueDeclare("log", false, false, true, null);
      channel.QueueBind("log", "topic-exchange-example", "*.Personal.*");

      var consumer = new QueueingBasicConsumer(channel);
      channel.BasicConsume("log", true, consumer);

      while (true)
      {
        try
        {
          var eventArgs = (BasicDeliverEventArgs) consumer.Queue.Dequeue();
          string message = Encoding.UTF8.GetString(eventArgs.Body);
          Console.WriteLine(string.Format("{0} - {1}", eventArgs.RoutingKey, message));
        }
        catch (EndOfStreamException)
        {
          // The consumer was cancelled, the model closed, or the connection went away.
          break;
        }
      }

      channel.Close();
      connection.Close();
    }
  }
}
</pre>
<p>&nbsp;</p>
<p>Setting the solution to run both the Producer and Consumer on startup, we should see similar output to the following listings:</p>
<p>&nbsp;</p>
<p><strong>Producer</strong></p>
<pre class="prettyprint">Running for 10 seconds
Time to complete: 06 seconds
</pre>
<p>&nbsp;</p>
<p><strong>Consumer</strong></p>
<pre class="prettyprint">10843.Personal.Information - This is an information message
10843.Personal.Information - This is an information message
10843.Personal.Information - This is an information message
10843.Personal.Information - This is an information message
10843.Personal.Information - This is an information message
10843.Personal.Information - This is an information message
10843.Personal.Information - This is an information message
</pre>
<p>&nbsp;</p>
<p>This concludes our topic exchange example.&nbsp; Next time, we’ll walk through an example using the final exchange type: Header Exchanges.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/LosTechies?a=lx63Dhs6P_c:VajMhyzF6s4:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/LosTechies?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=lx63Dhs6P_c:VajMhyzF6s4:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/LosTechies?i=lx63Dhs6P_c:VajMhyzF6s4:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=lx63Dhs6P_c:VajMhyzF6s4:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/LosTechies?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=lx63Dhs6P_c:VajMhyzF6s4:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/LosTechies?i=lx63Dhs6P_c:VajMhyzF6s4:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/LosTechies/~4/lx63Dhs6P_c" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://lostechies.com/derekgreer/2012/05/18/rabbitmq-for-windows-topic-exchanges/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
            <media:content url="http://www.gravatar.com/avatar/9e02fc4b81dce4323e7d2652935e870d?s=96&amp;d=http%3A%2F%2Fwww.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
            <media:title type="html">Derek Greer</media:title>
        </media:content>
    		<feedburner:origLink>http://lostechies.com/derekgreer/2012/05/18/rabbitmq-for-windows-topic-exchanges/</feedburner:origLink></item>
	<item>
		<title>Backbone.Syphon: Serialize Form Inputs To JavaScript Objects</title>
		<link>http://feedproxy.google.com/~r/LosTechies/~3/rQaXw5vBoYo/</link>
		<comments>http://lostechies.com/derickbailey/2012/05/17/backbone-syphon-serialize-form-inputs-to-javascript-objects/#comments</comments>
		<pubDate>Thu, 17 May 2012 12:57:13 +0000</pubDate>
		<dc:creator>Derick Bailey</dc:creator>
				<category><![CDATA[Backbone]]></category>
		<category><![CDATA[Backbone.Syphon]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[JSON]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://lostechies.com/derickbailey/?p=934]]></guid>
		<description><![CDATA[Working with form elements in a Backbone view can become very tedious very quickly. You will either end up writing a lot of repetitive code to read values from the form, or end up using a key-value-observer or data-binding solution&#160;&#8230; <a href="http://lostechies.com/derickbailey/2012/05/17/backbone-syphon-serialize-form-inputs-to-javascript-objects/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p>Working with form elements in a Backbone view can become very tedious very quickly. You will either end up writing a lot of repetitive code to read values from the form, or end up using a key-value-observer or data-binding solution that automatically populates your model for you. While these are valid options and I highly recommend understanding how they work, there are times when these options are not the best choice for your application.</p>
<h2>jQuery</h2>
<p>The most basic option in serializing a form&#8217;s elements in to use jQuery&#8217;s <a href="http://api.jquery.com/serialize/">serialize</a> or <a href="http://api.jquery.com/serializeArray/">serializeArray</a> methods. These methods work well and make it easy to get data out of your form. But they have limitations that I don&#8217;t like:</p>
<p>The serialize method encodes the values in to a URL encoding. This works well if you plan on using the data as URL parameters in an HTTP GET or other similar manner. But if you want to use the data in your JavaScript code, it&#8217;s a bit of a pain to work with.</p>
<p>The serializeArray method return a JavaScript array that contains objects each with a name and value key. So, a text input with a &#8220;name&#8221; of &#8220;foo&#8221; would return [{name: "foo", value: "bar"}]. This works much better for dealing with the data in your JavaScript code, but is still severely constrained. You don&#8217;t have direct access to the key/value pairs based on the name of the input element. Instead, you have to search through the array of objects and find the one you want. </p>
<p>What I want, instead, is a way to serialize a form into a plain JavaScript object where the object&#8217;s attributes (or keys) are the input element ids, with the key&#8217;s value set to the value of the input element.</p>
<h2>Backbone.Syphon</h2>
<p><a href="https://github.com/derickbailey/backbone.syphon">Backbone.Syphon</a> aims to make it easy to serialize the form inputs of a Backbone.View in to a simple JSON object that contains all of the values from the form. All you need to do is call `Backbone.Syphon.serialize(view)` and it will return a JavaScript object to you with key / value pairs that match the input element ids and values.</p>
<p>For example, with this underscore template:</p>
<div id="gist-2710848" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="nt">&lt;script </span><span class="na">id=</span><span class="s">&quot;my-form-template&quot;</span> <span class="na">type=</span><span class="s">&quot;text/html&quot;</span><span class="nt">&gt;</span></div><div class='line' id='LC2'>&nbsp;&nbsp;<span class="o">&lt;</span><span class="nx">form</span><span class="o">&gt;</span></div><div class='line' id='LC3'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="o">&lt;</span><span class="nx">input</span> <span class="nx">type</span><span class="o">=</span><span class="s2">&quot;text&quot;</span> <span class="nx">id</span><span class="o">=</span><span class="s2">&quot;foo&quot;</span> <span class="nx">value</span><span class="o">=</span><span class="s2">&quot;bar&quot;</span><span class="o">&gt;</span></div><div class='line' id='LC4'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="o">&lt;</span><span class="nx">input</span> <span class="nx">type</span><span class="o">=</span><span class="s2">&quot;checkbox&quot;</span> <span class="nx">id</span><span class="o">=</span><span class="s2">&quot;chk&quot;</span> <span class="nx">checked</span><span class="o">&gt;</span></div><div class='line' id='LC5'>&nbsp;&nbsp;<span class="o">&lt;</span><span class="err">/form&gt;</span></div><div class='line' id='LC6'><span class="nt">&lt;/script&gt;</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2710848/c80c5422081a73a58b90584249f3b1607cfe9799/1.html" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2710848#file_1.html" style="float:right;margin-right:10px;color:#666">1.html</a>
            <a href="https://gist.github.com/2710848">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>And this Backbone.View setup:</p>
<div id="gist-2710848" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="nx">Backbone</span><span class="p">.</span><span class="nx">View</span><span class="p">.</span><span class="nx">extend</span><span class="p">({</span></div><div class='line' id='LC2'>&nbsp;&nbsp;<span class="nx">events</span><span class="o">:</span> <span class="p">{</span></div><div class='line' id='LC3'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="s2">&quot;submit form&quot;</span><span class="o">:</span> <span class="s2">&quot;formSubmitted&quot;</span></div><div class='line' id='LC4'>&nbsp;&nbsp;<span class="p">},</span></div><div class='line' id='LC5'><br/></div><div class='line' id='LC6'>&nbsp;&nbsp;<span class="nx">formSubmitted</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">e</span><span class="p">){</span></div><div class='line' id='LC7'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">e</span><span class="p">.</span><span class="nx">preventDefault</span><span class="p">();</span></div><div class='line' id='LC8'><br/></div><div class='line' id='LC9'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">data</span> <span class="o">=</span> <span class="nx">Backbone</span><span class="p">.</span><span class="nx">Syphon</span><span class="p">.</span><span class="nx">serialize</span><span class="p">(</span><span class="k">this</span><span class="p">);</span></div><div class='line' id='LC10'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">model</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="nx">data</span><span class="p">);</span></div><div class='line' id='LC11'><br/></div><div class='line' id='LC12'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">model</span><span class="p">.</span><span class="nx">save</span><span class="p">();</span></div><div class='line' id='LC13'>&nbsp;&nbsp;<span class="p">},</span></div><div class='line' id='LC14'><br/></div><div class='line' id='LC15'>&nbsp;&nbsp;<span class="nx">render</span><span class="o">:</span> <span class="kd">function</span><span class="p">(){</span></div><div class='line' id='LC16'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="c1">// build the view&#39;s form, here</span></div><div class='line' id='LC17'>&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC18'><span class="p">});</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2710848/619c5696ee741d1640d668740ff6202e5bc74dc9/2.js" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2710848#file_2.js" style="float:right;margin-right:10px;color:#666">2.js</a>
            <a href="https://gist.github.com/2710848">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>When you click the &#8220;save&#8221; button, the handler for the click calls `Backbone.Syphon.serialize(this)`. This returns an object that looks like this:</p>
<div id="gist-2710848" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="p">{</span></div><div class='line' id='LC2'>&nbsp;&nbsp;<span class="nx">foo</span><span class="o">:</span> <span class="s2">&quot;bar&quot;</span><span class="p">,</span></div><div class='line' id='LC3'>&nbsp;&nbsp;<span class="nx">chk</span><span class="o">:</span> <span class="kc">true</span></div><div class='line' id='LC4'><span class="p">}</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2710848/93cda89340165c36472fa4cf05aed0b5c085f7a8/3.js" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2710848#file_3.js" style="float:right;margin-right:10px;color:#666">3.js</a>
            <a href="https://gist.github.com/2710848">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>The large benefit of this output is that you can immediately pass it to a Backbone.Model instance via the `set` method. There&#8217;s no need to sift through it and pull out the bits you need, like the jQuery serialize methods. Of course you can use it for more than just Backbone models, too. Anywhere that you need the data from your form, you can get it with Syphon and use it right away.</p>
<p>I use this plugin in several of my projects already &#8211; well, precursors that were poorly written and not tested thoroughly, at least. But I plan on continuing to use this plugin in scenarios where I need to get data out of my forms. Data-binding plugins just don&#8217;t interest me anymore, as I&#8217;ve gone down that path and abandoned it. </p>
<h2>Serializes By Element Id</h2>
<p>There are a handful of limitations in this first release. One of the largest is that all of the input elements will be serialized by the `id` attribute of the element. Look at the example above again, and you&#8217;ll notice that the text input with an id of &#8220;foo&#8221; was serialized in to a `{foo: &#8220;bar&#8221;}` attribute on the resulting object. I&#8217;m sure this will change over time, and become something more configurable. But for now, this was all I needed as I tend to use the id of a field as the key for my object&#8217;s data.</p>
<p>For more information on the current limitations, <a href="https://github.com/derickbailey/backbone.syphon#current-limitation">see the documentation</a>.</p>
<h2>Some-what Pluggable Serialization</h2>
<p>I&#8217;ve built this plugin more than a few times at this point, starting with direct client needs and eventually turning in to the plugin that it is now. One of the lessons that I learned in rebuilding it a few times is that the process of serializing the input elements needs to be pluggable. I can&#8217;t limit how it reads the data from the input elements, because there are different needs for different situations. </p>
<p>With that in mind, I built in the idea of &#8220;<a href="https://github.com/derickbailey/backbone.syphon#register-your-own-input-readers">Input Readers</a>&#8220;. An Input Reader is a callback function that is registered against a particular input type, and is used to read the data from that type of input. </p>
<p>At the moment, there are only two built in input readers: the default, which handles nearly everything, and the checkbox reader. The default reader uses jQuery&#8217;s `val()` function to get the value out of the input. This works for nearly every type of input. But there are some cases where this isn&#8217;t what you want to do. For example, I generally use checkboxes as boolean values instead of an actual text value. To handle this, then, I created the built in checkbox input reader. It uses jQuery&#8217;s `prop()` function to read the state of the checkbox and tell me whether or not the checkbox is checked. If you look at the previous example again, you&#8217;ll see that the &#8220;chk&#8221; checkbox is returning a boolean value.</p>
<h2>Initial Build And Release As A Screencast</h2>
<p>There are several reasons that this initial release is so small and limited in scope and functionality. The largest of which is that it covers the majority of my needs, and like all of my plugins and add-ons, I figure out what I need and the common things that I do across projects first. Then when I have the majority of my cases covered, I start looking at what others need in order to get their projects up and running.</p>
<p>Another reason that this release is limited, is because I decided to record the creation of the plugin as a live screencast &#8211; a &#8220;prequel&#8221; of sorts, to the first &#8220;<a href="http://www.watchmecode.net/refactoring-javascript">Refactoring JavaScript</a>&#8221; screencast that I released last year. In this case, the end product of the Backbone.Syphon plugin is more of a side effect than the purpose of the screencast. The real focus of the screencast is the tools and processes that I use to get a plugin like this off the ground, built and delivered. </p>
<p>If you&#8217;re an audio/video learner and you want to see my process for creating something from nothing more than the ideas in my head, then you should check out Episode 7 of WatchMeCode: <a href="http://www.watchmecode.net/backbone-plugin">Building A Backbone Plugin (Live)</a>. And if you&#8217;re looking for a way to get up to speed with test-driven JavaScript, including a basic introduction to Jasmine and refactoring an existing application that is covered by Jasmine tests, then you might be interested in the <a href="http://www.watchmecode.net/jasmine-live">Jasmine Live! multi-pack</a> of screencasts.</p>
<h2>Documentation, Downloads, And Moving Forward</h2>
<p>If you&#8217;d like to get your hands on Syphon, head over to <a href="https://github.com/derickbailey/backbone.syphon">the Github repository</a>. There are links to the the downloads and a little bit of documentation to show how to use it (the same as what I showed here), as well as some discussion on the current limitations of the plugin.</p>
<p>I&#8217;m hoping to get some input and assistance from others that could use a plugin like this, moving forward. I&#8217;d like to see this project fleshed out so that it can be used in a broader set of scenarios, with more options for how the data is serialized from the input elements. At the same time, though, I&#8217;m going to be rather picky about how the implementation moves forward. I don&#8217;t want to end up with another 1,000 line blob of unmaintainable garbage, like my ModelBinding plugin. As it stands now, though, Syphon&#8217;s code is starting out on the right foot. I just need to keep it heading down a clean path as it moves forward.</p>
<p> </p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/LosTechies?a=rQaXw5vBoYo:xz8wBxTxNKA:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/LosTechies?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=rQaXw5vBoYo:xz8wBxTxNKA:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/LosTechies?i=rQaXw5vBoYo:xz8wBxTxNKA:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=rQaXw5vBoYo:xz8wBxTxNKA:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/LosTechies?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=rQaXw5vBoYo:xz8wBxTxNKA:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/LosTechies?i=rQaXw5vBoYo:xz8wBxTxNKA:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/LosTechies/~4/rQaXw5vBoYo" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://lostechies.com/derickbailey/2012/05/17/backbone-syphon-serialize-form-inputs-to-javascript-objects/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
            <media:content url="http://www.gravatar.com/avatar/e592bd1326b1e80188ed4c0bf26b9f75?s=96&amp;d=http%3A%2F%2Fwww.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
            <media:title type="html">Derick Bailey</media:title>
        </media:content>
    		<feedburner:origLink>http://lostechies.com/derickbailey/2012/05/17/backbone-syphon-serialize-form-inputs-to-javascript-objects/</feedburner:origLink></item>
	<item>
		<title>RabbitMQ for Windows: Fanout Exchanges</title>
		<link>http://feedproxy.google.com/~r/LosTechies/~3/Q6L3t_9tnaQ/</link>
		<comments>http://lostechies.com/derekgreer/2012/05/16/rabbitmq-for-windows-fanout-exchanges/#comments</comments>
		<pubDate>Wed, 16 May 2012 13:24:24 +0000</pubDate>
		<dc:creator>Derek Greer</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[RabbitMQ]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://lostechies.com/derekgreer/?p=767]]></guid>
		<description><![CDATA[This is the sixth installment to the series: RabbitMQ for Windows. In the last installment, we walked through creating a direct exchange example and introduced the push API. In this installment, we’ll walk through a fanout exchange example. As discussed&#160;&#8230; <a href="http://lostechies.com/derekgreer/2012/05/16/rabbitmq-for-windows-fanout-exchanges/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p>This is the sixth installment to the series: RabbitMQ for Windows.  In the <a href="http://lostechies.com/derekgreer/2012/04/02/rabbitmq-for-windows-direct-exchanges/">last installment</a>, we walked through creating a direct exchange example and introduced the push API.  In this installment, we’ll walk through a fanout exchange example.</p>
<p>As discussed earlier in the series, the fanout exchange type is useful for facilitating the <a href="http://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern">publish-subscribe</a> pattern.  When we publish a message to a fanout exchange, the message is delivered indiscriminately to all bound queues.  With the Direct, Topic, and Headers exchange types, a criteria is used by a routing algorithm taking the form of a routing key or a collection of message headers depending on the exchange type in question.  A routing key or a collection of message headers may also be specified with the fanout exchange which will be delivered as part of the message’s metadata, but they will not be used as a filter in determining which queue receives a published message.</p>
<p>To demonstrate the fanout exchange, we’ll use a stock ticker example.  In the previous example, logs were routed to queues based upon a matching routing key (an empty string in the logging example’s case).  In this example, we’d like our messages to be delivered to all bound queues regardless of qualification.</p>
<p>Similar to the previous example, we’ll create a Producer console application which periodically publishes stock quote messages and a Consumer console application which displays the message to the console.</p>
<p>We’ll start our Producer app as before by establishing a connection using the default settings, creating the connection, and creating a channel:</p>
<pre class="prettyprint">
namespace Producer
{
  class Program
  {
    static volatile bool _cancelling;

    static void Main(string[] args)
    {
      var connectionFactory = new ConnectionFactory();
      IConnection connection = connectionFactory.CreateConnection();
      IModel channel = connection.CreateModel();
    }
  }
}
</pre>
<p>Next, we need to declare an exchange of type “fanout”.  We’ll name our new exchange “fanout-exchange-example”:</p>
<pre class="prettyprint">
channel.ExchangeDeclare("direct-exchange-example", ExchangeType.Fanout, false, true, null);
</pre>
<p>To publish the stock messages periodically, we’ll call a PublishQuotes() method with the provided channel and run it on a background thread:</p>
<pre class="prettyprint">
var thread = new Thread(() => PublishQuotes(channel));
thread.Start();
</pre>
<p>Next, we’ll provide a way to exit the application by prompting the user to enter ‘x’ and use a simple Boolean to signal the background thread when to exit:</p>
<pre class="prettyprint">
Console.WriteLine("Press 'x' to exit");
var input = (char) Console.Read();
_cancelling = true;
</pre>
<p>Lastly, we need to close the channel and connection:</p>
<pre class="prettyprint">
channel.Close();
connection.Close();
</pre>
<p>For our PublishQuotes() method, well iterate over a set of stock symbols, retrieve the stock information for each symbol, and publish a simple string-based message in the form [symbol]:[price]:</p>
<pre class="prettyprint">
static void PublishQuotes(IModel channel)
{
  while (true)
  {
    if (_cancelling) return;
    IEnumerable<string> quotes = FetchStockQuotes(new[] {"GOOG", "HD", "MCD"});
    foreach (string quote in quotes)
    {
      byte[] message = Encoding.UTF8.GetBytes(quote);
      channel.BasicPublish("direct-exchange-example", "", null, message);
    }
    Thread.Sleep(5000);
  }
}
</pre>
<p>To implement the FetchStockQuotes() method, we’ll use the Yahoo Finance API which entails retrieving an XML-based list of stock quotes and parsing out the bit of information we’re interested in for our example:</p>
<pre class="prettyprint">
static IEnumerable&lt;string> FetchStockQuotes(string[] symbols)
{
  var quotes = new List&lt;string>();

  string url = string.Format("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20({0})&#038;env=store://datatables.org/alltableswithkeys",
      String.Join("%2C", symbols.Select(s => "%22" + s + "%22")));
  var wc = new WebClient {Proxy = WebRequest.DefaultWebProxy};
  var ms = new MemoryStream(wc.DownloadData(url));
  var reader = new XmlTextReader(ms);
  XDocument doc = XDocument.Load(reader);
  XElement results = doc.Root.Element("results");

  foreach (string symbol in symbols)
  {
    XElement q = results.Elements("quote").First(w => w.Attribute("symbol").Value == symbol);
    quotes.Add(symbol + ":" + q.Element("AskRealtime").Value);
  }

  return quotes;
}
</pre>
<p>Here is the complete Producer listing:</p>
<pre class="prettyprint">
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Xml;
using System.Xml.Linq;
using RabbitMQ.Client;

namespace Producer
{
  class Program
  {
    static volatile bool _cancelling;

    static void Main(string[] args)
    {
      var connectionFactory = new ConnectionFactory();
      IConnection connection = connectionFactory.CreateConnection();
      IModel channel = connection.CreateModel();
      channel.ExchangeDeclare("direct-exchange-example", ExchangeType.Fanout, false, true, null);

      var thread = new Thread(() => PublishQuotes(channel));
      thread.Start();

      Console.WriteLine("Press 'x' to exit");
      var input = (char) Console.Read();
      _cancelling = true;

      channel.Close();
      connection.Close();
    }

    static void PublishQuotes(IModel channel)
    {
      while (true)
      {
        if (_cancelling) return;
        IEnumerable<string> quotes = FetchStockQuotes(new[] {"GOOG", "HD", "MCD"});
        foreach (string quote in quotes)
        {
          byte[] message = Encoding.UTF8.GetBytes(quote);
          channel.BasicPublish("direct-exchange-example", "", null, message);
        }
        Thread.Sleep(5000);
      }
    }

    static IEnumerable&lt;string> FetchStockQuotes(string[] symbols)
    {
      var quotes = new List&lt;string>();

      string url = string.Format("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20({0})&#038;env=store://datatables.org/alltableswithkeys",
          String.Join("%2C", symbols.Select(s => "%22" + s + "%22")));
      var wc = new WebClient {Proxy = WebRequest.DefaultWebProxy};
      var ms = new MemoryStream(wc.DownloadData(url));
      var reader = new XmlTextReader(ms);
      XDocument doc = XDocument.Load(reader);
      XElement results = doc.Root.Element("results");

      foreach (string symbol in symbols)
      {
        XElement q = results.Elements("quote").First(w => w.Attribute("symbol").Value == symbol);
        quotes.Add(symbol + ":" + q.Element("AskRealtime").Value);
      }

      return quotes;
    }
  }
}
</pre>
<p>Our Consumer application will be similar to the one used in our logging example, but we’ll change the exchange name, queue name, and exchange type and put the processing of the messages within a while loop to continually display our any updates to our stock prices.  Here’s the full listing for our Consumer app:</p>
<pre class="prettyprint">
using System;
using System.IO;
using System.Text;
using RabbitMQ.Client;
using RabbitMQ.Client.Events;

namespace Consumer
{
  class Program
  {
    static void Main(string[] args)
    {
      var connectionFactory = new ConnectionFactory();
      IConnection connection = connectionFactory.CreateConnection();
      IModel channel = connection.CreateModel();

      channel.ExchangeDeclare("direct-exchange-example", ExchangeType.Fanout, false, true, null);
      channel.QueueDeclare("quotes", false, false, true, null);
      channel.QueueBind("quotes", "direct-exchange-example", "");

      var consumer = new QueueingBasicConsumer(channel);
      channel.BasicConsume("quotes", true, consumer);

      while (true)
      {
        try
        {
          var eventArgs = (BasicDeliverEventArgs) consumer.Queue.Dequeue();
          string message = Encoding.UTF8.GetString(eventArgs.Body);
          Console.WriteLine(message);
        }
        catch (EndOfStreamException)
        {
          // The consumer was cancelled, the model closed, or the connection went away.
          break;
        }
      }

      channel.Close();
      connection.Close();
    }
  }
}
</pre>
<p>Setting our solution startup projects to run both the Producer and Consumer apps together, we should see messages similar to the following for the Consumer output:</p>
<pre class="prettyprint">
GOOG:611.62
HD:48.66
MCD:91.06
GOOG:611.58
HD:48.66
MCD:91.06
</pre>
<p>To show our queue would receive messages published to the fanout exchange regardless of the routing key value, we can change the value of the routing key to “anything”:</p>
<pre class="prettyprint">
channel.QueueBind("quotes", "direct-exchange-example", "anything");
</pre>
<p>Running the application again shows the same values:</p>
<pre class="prettyprint">
GOOG:611.62
HD:48.66
MCD:91.06
GOOG:611.58
HD:48.66
MCD:91.06
</pre>
<p>That concludes our fanout exchange example.  Next time, we’ll take a look at the topic exchange type.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/LosTechies?a=Q6L3t_9tnaQ:d7WD8RYkB48:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/LosTechies?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=Q6L3t_9tnaQ:d7WD8RYkB48:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/LosTechies?i=Q6L3t_9tnaQ:d7WD8RYkB48:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=Q6L3t_9tnaQ:d7WD8RYkB48:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/LosTechies?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=Q6L3t_9tnaQ:d7WD8RYkB48:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/LosTechies?i=Q6L3t_9tnaQ:d7WD8RYkB48:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/LosTechies/~4/Q6L3t_9tnaQ" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://lostechies.com/derekgreer/2012/05/16/rabbitmq-for-windows-fanout-exchanges/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
            <media:content url="http://www.gravatar.com/avatar/9e02fc4b81dce4323e7d2652935e870d?s=96&amp;d=http%3A%2F%2Fwww.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
            <media:title type="html">Derek Greer</media:title>
        </media:content>
    		<feedburner:origLink>http://lostechies.com/derekgreer/2012/05/16/rabbitmq-for-windows-fanout-exchanges/</feedburner:origLink></item>
	<item>
		<title>Mixing async and sync in distributed systems</title>
		<link>http://feedproxy.google.com/~r/LosTechies/~3/-B123S0ZcBE/</link>
		<comments>http://lostechies.com/jimmybogard/2012/05/15/mixing-async-and-sync-in-distributed-systems/#comments</comments>
		<pubDate>Tue, 15 May 2012 13:21:28 +0000</pubDate>
		<dc:creator>Jimmy Bogard</dc:creator>
				<category><![CDATA[Domain-Driven Design]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://lostechies.com/jimmybogard/2012/05/15/mixing-async-and-sync-in-distributed-systems/]]></guid>
		<description><![CDATA[One of the more difficult transitions when moving from a synchronous UI to an inherently async/CQRS-based UI is the burden of figuring out what to do with all these synchronous operations. Especially when dealing with existing systems, users that expect&#160;&#8230; <a href="http://lostechies.com/jimmybogard/2012/05/15/mixing-async-and-sync-in-distributed-systems/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p>One of the more difficult transitions when moving from a synchronous UI to an inherently async/CQRS-based UI is the burden of figuring out what to do with all these synchronous operations. Especially when dealing with existing systems, users that expect everything to be synchronous don’t really appreciate what used to tell them success right away now.</p>
<p>The problem really exacerbates itself when too much was happening at once, and the need to break things out to improve throughput requires a different protocol for integration.</p>
<p>Consider going to the grocery store. When you place an item in your basket, it’s inherently a synchronous operation. Either the jar of pickles makes it into your cart, or it doesn’t, there is no middle ground there. If you drop the jar of pickles onto the ground, you don’t wait for some async process to come by and let you know by email, “sorry, it seems there was a problem with your request to add the item to your shopping cart.”</p>
<h3>Blending async in</h3>
<p>Consider another system that requires to you to register with the site, using a local database for “who is registered” and a web service for downstream email communication:</p>
<p><a href="http://lostechies.com/jimmybogard/files/2012/05/image.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lostechies.com/jimmybogard/files/2012/05/image_thumb.png" width="314" height="340"></a></p>
<p>In this system, we block the registration of the user against both the local database and the 3rd party web service. We need to check the local database to make sure the username/email is not already used, but what about that web service? What happens when that web service is slow, or unavailable?</p>
<p>We’ve coupled the availability of our system with a system we don’t own, which is potentially disastrous. In the real-world system that the above diagram is based on, when that 3rd party system goes into scheduled maintenance, the web application is brought down for maintenance too! Not a good user experience by any means. Are we really going to turn users away based on the availability of a downstream service?</p>
<p>But there’s another way – shifting the protocol of how this system is built. Let’s make sure what needs to be synchronous is, what what doesn’t need to be, isn’t. Instead of coupling the web service and local database calls together, let’s separate the two out with messaging:</p>
<p><a href="http://lostechies.com/jimmybogard/files/2012/05/image1.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lostechies.com/jimmybogard/files/2012/05/image_thumb1.png" width="638" height="340"></a></p>
<p>Instead of performing the web service call in the same thread of the UI request, we instead send an asynchronous command as a message to perform the downstream operation. We’ve now decoupled the operation of calling the web service (what doesn’t need to be synchronous) with what does need (registering the user). The downstream operations of registering the user in the 3rd party email provider doesn’t need to happen at the same time.</p>
<p>To put it another way – does it affect the user’s registration if the email service provider rejects the message? No! Instead, that’s likely an administrative operation to figure out what happened, but the user is still successfully registered.</p>
<h3>Defining the boundaries</h3>
<p>When it comes time to figure out what should be synchronous and what shouldn’t, the key is to figure out what information, operations and behaviors your system owns versus are owned by someone else. If you own the UI and the database, then synchronous is a good possibility. If you <em>don’t</em> own the system (like our web service above), then async is a good possibility.</p>
<p>Next time: sync, async and CQRS.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/LosTechies?a=-B123S0ZcBE:Q6HPoDtmu-U:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/LosTechies?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=-B123S0ZcBE:Q6HPoDtmu-U:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/LosTechies?i=-B123S0ZcBE:Q6HPoDtmu-U:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=-B123S0ZcBE:Q6HPoDtmu-U:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/LosTechies?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=-B123S0ZcBE:Q6HPoDtmu-U:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/LosTechies?i=-B123S0ZcBE:Q6HPoDtmu-U:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/LosTechies/~4/-B123S0ZcBE" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://lostechies.com/jimmybogard/2012/05/15/mixing-async-and-sync-in-distributed-systems/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
            <media:content url="http://www.gravatar.com/avatar/cc359c5ccf90d7a24b5976316797b5ec?s=96&amp;d=http%3A%2F%2Fwww.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
            <media:title type="html">Jimmy Bogard</media:title>
        </media:content>
    		<feedburner:origLink>http://lostechies.com/jimmybogard/2012/05/15/mixing-async-and-sync-in-distributed-systems/</feedburner:origLink></item>
	<item>
		<title>Workflow In Backbone Apps: Triggering View Events From DOM Events</title>
		<link>http://feedproxy.google.com/~r/LosTechies/~3/k7cQRiMo8b0/</link>
		<comments>http://lostechies.com/derickbailey/2012/05/15/workflow-in-backbone-apps-triggering-view-events-from-dom-events/#comments</comments>
		<pubDate>Tue, 15 May 2012 13:04:05 +0000</pubDate>
		<dc:creator>Derick Bailey</dc:creator>
				<category><![CDATA[Backbone]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Workflow]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://lostechies.com/derickbailey/?p=930]]></guid>
		<description><![CDATA[In my previous blog post, I talked about modeling an explicit workflow in JavaScript and Backbone application. The last code sample I showed had the implementation of the workflow object itself, but omitted all of the details of the views&#160;&#8230; <a href="http://lostechies.com/derickbailey/2012/05/15/workflow-in-backbone-apps-triggering-view-events-from-dom-events/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p>In my previous blog post, I talked about <a href="http://lostechies.com/derickbailey/2012/05/10/modeling-explicit-workflow-with-code-in-javascript-and-backbone-apps/">modeling an explicit workflow in JavaScript and Backbone application</a>. The last code sample I showed had the implementation of the workflow object itself, but omitted all of the details of the views that I was using.</p>
<p>Here&#8217;s the gist of that again:</p>
<div id="gist-2651039" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="nx">orgChart</span> <span class="o">=</span> <span class="p">{</span></div><div class='line' id='LC2'><br/></div><div class='line' id='LC3'>&nbsp;&nbsp;<span class="nx">addNewEmployee</span><span class="o">:</span> <span class="kd">function</span><span class="p">(){</span></div><div class='line' id='LC4'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">that</span> <span class="o">=</span> <span class="k">this</span><span class="p">;</span></div><div class='line' id='LC5'><br/></div><div class='line' id='LC6'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">employeeDetail</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">getEmployeeDetail</span><span class="p">();</span></div><div class='line' id='LC7'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">employeeDetail</span><span class="p">.</span><span class="nx">on</span><span class="p">(</span><span class="s2">&quot;complete&quot;</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">employee</span><span class="p">){</span></div><div class='line' id='LC8'><br/></div><div class='line' id='LC9'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">managerSelector</span> <span class="o">=</span> <span class="nx">that</span><span class="p">.</span><span class="nx">selectManager</span><span class="p">(</span><span class="nx">employee</span><span class="p">);</span></div><div class='line' id='LC10'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">managerSelector</span><span class="p">.</span><span class="nx">on</span><span class="p">(</span><span class="s2">&quot;save&quot;</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">employee</span><span class="p">){</span></div><div class='line' id='LC11'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">employee</span><span class="p">.</span><span class="nx">save</span><span class="p">();</span></div><div class='line' id='LC12'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">});</span></div><div class='line' id='LC13'><br/></div><div class='line' id='LC14'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">});</span></div><div class='line' id='LC15'>&nbsp;&nbsp;<span class="p">},</span></div><div class='line' id='LC16'><br/></div><div class='line' id='LC17'>&nbsp;&nbsp;<span class="nx">getEmployeeDetail</span><span class="o">:</span> <span class="kd">function</span><span class="p">(){</span></div><div class='line' id='LC18'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">form</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">EmployeeDetailForm</span><span class="p">();</span></div><div class='line' id='LC19'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">form</span><span class="p">.</span><span class="nx">render</span><span class="p">();</span></div><div class='line' id='LC20'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">$</span><span class="p">(</span><span class="s2">&quot;#wizard&quot;</span><span class="p">).</span><span class="nx">html</span><span class="p">(</span><span class="nx">form</span><span class="p">.</span><span class="nx">el</span><span class="p">);</span></div><div class='line' id='LC21'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">return</span> <span class="nx">form</span><span class="p">;</span></div><div class='line' id='LC22'>&nbsp;&nbsp;<span class="p">},</span></div><div class='line' id='LC23'><br/></div><div class='line' id='LC24'>&nbsp;&nbsp;<span class="nx">selectManager</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">employee</span><span class="p">){</span></div><div class='line' id='LC25'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">form</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">SelectManagerForm</span><span class="p">({</span></div><div class='line' id='LC26'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">model</span><span class="o">:</span> <span class="nx">employee</span></div><div class='line' id='LC27'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">});</span></div><div class='line' id='LC28'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">form</span><span class="p">.</span><span class="nx">render</span><span class="p">();</span></div><div class='line' id='LC29'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">$</span><span class="p">(</span><span class="s2">&quot;#wizard&quot;</span><span class="p">).</span><span class="nx">html</span><span class="p">(</span><span class="nx">form</span><span class="p">.</span><span class="nx">el</span><span class="p">);</span></div><div class='line' id='LC30'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">return</span> <span class="nx">form</span><span class="p">;</span></div><div class='line' id='LC31'>&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC32'><span class="p">}</span></div><div class='line' id='LC33'><br/></div><div class='line' id='LC34'><span class="c1">// implementation details for EmployeeDetailForm go here</span></div><div class='line' id='LC35'><br/></div><div class='line' id='LC36'><span class="c1">// implementation details for SelectManagerForm go here</span></div><div class='line' id='LC37'><br/></div><div class='line' id='LC38'><span class="c1">// implementation details for Employee model go here</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2651039/f0d01867e96cef419acbc01c7f6610e04f8f0dfc/3.js" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2651039#file_3.js" style="float:right;margin-right:10px;color:#666">3.js</a>
            <a href="https://gist.github.com/2651039">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>I&#8217;ve implemented various views and objects in various manners, in order to facilitate that workflow, but what it always comes down to is that the objects facilitating the workflow need to trigger events. </p>
<h2>A Basic Implementation</h2>
<p>The most common way of triggering an event from a Backbone.View is to have some DOM events handled, and from the event handler/callback method for that, trigger the event you want:</p>
<div id="gist-2653055" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="nx">SomeView</span> <span class="o">=</span> <span class="nx">Backbone</span><span class="p">.</span><span class="nx">View</span><span class="p">.</span><span class="nx">extend</span><span class="p">({</span></div><div class='line' id='LC2'><br/></div><div class='line' id='LC3'>&nbsp;&nbsp;<span class="nx">events</span><span class="o">:</span> <span class="p">{</span></div><div class='line' id='LC4'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="s2">&quot;click .next&quot;</span><span class="o">:</span> <span class="s2">&quot;nextClicked&quot;</span><span class="p">,</span></div><div class='line' id='LC5'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="s2">&quot;click .previous&quot;</span><span class="o">:</span> <span class="s2">&quot;previousClicked&quot;</span></div><div class='line' id='LC6'>&nbsp;&nbsp;<span class="p">},</span></div><div class='line' id='LC7'><br/></div><div class='line' id='LC8'>&nbsp;&nbsp;<span class="nx">nextClicked</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">e</span><span class="p">){</span></div><div class='line' id='LC9'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">e</span><span class="p">.</span><span class="nx">preventDefault</span><span class="p">();</span></div><div class='line' id='LC10'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">trigger</span><span class="p">(</span><span class="s2">&quot;next&quot;</span><span class="p">)</span></div><div class='line' id='LC11'>&nbsp;&nbsp;<span class="p">},</span></div><div class='line' id='LC12'><br/></div><div class='line' id='LC13'>&nbsp;&nbsp;<span class="nx">previousClicked</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">e</span><span class="p">){</span></div><div class='line' id='LC14'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">e</span><span class="p">.</span><span class="nx">preventDefault</span><span class="p">();</span></div><div class='line' id='LC15'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">trigger</span><span class="p">(</span><span class="s2">&quot;previous&quot;</span><span class="p">);</span></div><div class='line' id='LC16'>&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC17'><br/></div><div class='line' id='LC18'><span class="p">});</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2653055/8010b523746f224647525a96b5690b01126e2864/1.js" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2653055#file_1.js" style="float:right;margin-right:10px;color:#666">1.js</a>
            <a href="https://gist.github.com/2653055">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>This works well. I&#8217;ve done this more times than I can count. But there&#8217;s a lot of redundancy here. You can see that both of the DOM events that I&#8217;m handling have a callback method, and both of the callback methods do nothing more than trigger an event from the view itself so that the workflow can move forward.</p>
<p>We can do better than that… enter Marionette&#8217;s new &#8220;triggers&#8221;.</p>
<h2>Reducing Event Triggering To Configuration</h2>
<p>With the v0.8.2 release of <a href="https://github.com/derickbailey/backbone.marionette">Marionette</a>, I&#8217;ve introduced the idea of <a href="https://github.com/derickbailey/backbone.marionette#viewtriggers">view triggers</a> &#8211; a way to configure a DOM event to trigger a view event. So instead of having to write all of that redundant code, where the only real difference is the name of the callback method and the name of the event that&#8217;s triggered, we can write this:</p>
<div id="gist-2653055" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="nx">SomeView</span> <span class="o">=</span> <span class="nx">Backbone</span><span class="p">.</span><span class="nx">Marionette</span><span class="p">.</span><span class="nx">ItemView</span><span class="p">.</span><span class="nx">extend</span><span class="p">({</span></div><div class='line' id='LC2'><br/></div><div class='line' id='LC3'>&nbsp;&nbsp;<span class="c1">// ...</span></div><div class='line' id='LC4'><br/></div><div class='line' id='LC5'>&nbsp;&nbsp;<span class="nx">triggers</span><span class="o">:</span> <span class="p">{</span></div><div class='line' id='LC6'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="s2">&quot;click .next&quot;</span><span class="o">:</span> <span class="s2">&quot;next&quot;</span><span class="p">,</span></div><div class='line' id='LC7'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="s2">&quot;click .previous&quot;</span><span class="o">:</span> <span class="s2">&quot;previous&quot;</span></div><div class='line' id='LC8'>&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC9'><br/></div><div class='line' id='LC10'><span class="p">});</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2653055/90cfa68a1904fa5e9714d04c2a5a032565ac1d95/2.js" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2653055#file_2.js" style="float:right;margin-right:10px;color:#666">2.js</a>
            <a href="https://gist.github.com/2653055">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>Must shorter. Much cleaner.</p>
<p>You can see that the left side of the hash is a standard Backbone.View events setup where you specify the DOM event and element selector. Then on the right hand side, specify the name of the event that you want the view to trigger when that DOM event fires. Then, when I click on the &#8220;.next&#8221; element, the view will trigger a &#8220;next&#8221; event for me. Similarly, clicking the &#8220;.previous&#8221; element will trigger a &#8220;previous&#8221; event.</p>
<h2>Trigger From Any Marionette View</h2>
<p>Triggers can be used from any Marionette view. You&#8217;re not limited to the ItemView type that I showed. In fact, the trigger functionality is built in to the base Backbone.Marionette.View, so even if you are creating your own specialized view type, you only need to extend from that in order to get this functionality.</p>
<h2>Limitations</h2>
<p>Of course this isn&#8217;t a &#8220;complete&#8221; solution for handling events in your views, by any means. If you need to do anything more than trigger the event by itself, you should still use a standard event handler and callback method. At this point, there&#8217;s no way for you to configure any kind of data or objects to be passed through the event itself. But this may be added at some point in the future. I wrote this fairy quickly last night, and it suits my needs right now. </p>
<p>For simple scenarios where you just need to trigger an event from the view, though, this works well. I&#8217;m using it in several places where my workflow is just to display a button or a link, and have that clickable item move on to another part of the application.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/LosTechies?a=k7cQRiMo8b0:AvuRscbm0AQ:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/LosTechies?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=k7cQRiMo8b0:AvuRscbm0AQ:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/LosTechies?i=k7cQRiMo8b0:AvuRscbm0AQ:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=k7cQRiMo8b0:AvuRscbm0AQ:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/LosTechies?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=k7cQRiMo8b0:AvuRscbm0AQ:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/LosTechies?i=k7cQRiMo8b0:AvuRscbm0AQ:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/LosTechies/~4/k7cQRiMo8b0" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://lostechies.com/derickbailey/2012/05/15/workflow-in-backbone-apps-triggering-view-events-from-dom-events/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
            <media:content url="http://www.gravatar.com/avatar/e592bd1326b1e80188ed4c0bf26b9f75?s=96&amp;d=http%3A%2F%2Fwww.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
            <media:title type="html">Derick Bailey</media:title>
        </media:content>
    		<feedburner:origLink>http://lostechies.com/derickbailey/2012/05/15/workflow-in-backbone-apps-triggering-view-events-from-dom-events/</feedburner:origLink></item>
	<item>
		<title>The post you don’t want to read on the topic I don’t want to write about</title>
		<link>http://feedproxy.google.com/~r/LosTechies/~3/y43uxoVwYec/</link>
		<comments>http://lostechies.com/sharoncichelli/2012/05/10/the-post-you-dont-want-to-read/#comments</comments>
		<pubDate>Thu, 10 May 2012 17:55:15 +0000</pubDate>
		<dc:creator>Sharon Cichelli</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://lostechies.com/sharoncichelli/?p=105]]></guid>
		<description><![CDATA[I&#8217;m going to give you a phrase of power. Use it wisely. Ready? I want to hear what you have to say. If you know a developer who ought to be presenting at conferences or writing blog posts and isn&#8217;t,&#160;&#8230; <a href="http://lostechies.com/sharoncichelli/2012/05/10/the-post-you-dont-want-to-read/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p>I&#8217;m going to give you a phrase of power. Use it wisely. Ready?</p>
<p><span style="font-weight:bold; margin-left:3em;">I want to hear what you have to say.</span></p>
<p>If you know a developer who ought to be presenting at conferences or writing blog posts and isn&#8217;t, deploy that phrase. Say to him or her, &#8220;I wish you would submit a talk to [conference|user group] on [subject of expertise] because you have good ideas, and I want to hear your thoughts on the subject.&#8221;</p>
<p>You feel exasperated about your powerlessness to change the lack of diversity in our profession? To the point that you feel antagonized just hearing about it? Me, too. <em>This</em> is something you can do. A <strong>personal appeal</strong>, delivered one-on-one, can do so much good. Do it.</p>
<p>I resisted Twitter <em>forever</em> because, every time I asked someone why I should sign up, they answered with something irrelevant about all the funny things you could read, or whatever. No one ever said, &#8220;I wish you&#8217;d join Twitter, Sharon, because <strong>I want to hear what you have to say.</strong>&#8221; </p>
<p>How many of us dismiss those calls for speakers, thinking &#8220;What would I talk about? I&#8217;m not doing anything cutting-edge&#8221;? Imagine if someone encouraged you, reminded you of a skill you&#8217;ve forgotten is interesting and valuable, simply asked you to share your knowledge and ideas. Would that feel empowering? Do that for someone.</p>
<p>A lot of you wish our industry were more diverse. You&#8217;d welcome it if it could somehow happen. But it feels like a problem far bigger than the reach of one person. Scarily so, if you want my take on it. This, however, we can do, one person, by one person, by one person:</p>
<p><span style="font-weight:bold; margin-left:3em;">I want to hear what you have to say.</span></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/LosTechies?a=y43uxoVwYec:_5YqWSk8GAc:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/LosTechies?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=y43uxoVwYec:_5YqWSk8GAc:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/LosTechies?i=y43uxoVwYec:_5YqWSk8GAc:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=y43uxoVwYec:_5YqWSk8GAc:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/LosTechies?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=y43uxoVwYec:_5YqWSk8GAc:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/LosTechies?i=y43uxoVwYec:_5YqWSk8GAc:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/LosTechies/~4/y43uxoVwYec" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://lostechies.com/sharoncichelli/2012/05/10/the-post-you-dont-want-to-read/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
            <media:content url="http://www.gravatar.com/avatar/7a03e19970cbd58f328126aa71d98f53?s=96&amp;d=retro&amp;r=G" medium="image">
            <media:title type="html">Sharon Cichelli</media:title>
        </media:content>
    		<feedburner:origLink>http://lostechies.com/sharoncichelli/2012/05/10/the-post-you-dont-want-to-read/</feedburner:origLink></item>
	<item>
		<title>Modeling Explicit Workflow With Code, In JavaScript And Backbone Apps</title>
		<link>http://feedproxy.google.com/~r/LosTechies/~3/80NnIDpZiCI/</link>
		<comments>http://lostechies.com/derickbailey/2012/05/10/modeling-explicit-workflow-with-code-in-javascript-and-backbone-apps/#comments</comments>
		<pubDate>Thu, 10 May 2012 13:02:23 +0000</pubDate>
		<dc:creator>Derick Bailey</dc:creator>
				<category><![CDATA[AntiPatterns]]></category>
		<category><![CDATA[Backbone]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Principles and Patterns]]></category>
		<category><![CDATA[Workflow]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://lostechies.com/derickbailey/?p=928]]></guid>
		<description><![CDATA[A long time ago, in what seems to be a previous life at this point, I wrote a small blog post about modeling and creating an explicit return value from a dialog form in a Windows application. Fast forward a&#160;&#8230; <a href="http://lostechies.com/derickbailey/2012/05/10/modeling-explicit-workflow-with-code-in-javascript-and-backbone-apps/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p>A long time ago, in what seems to be a previous life at this point, I wrote a small blog post about modeling and <a href="http://lostechies.com/derickbailey/2009/05/19/result-lt-t-gt-directing-workflow-with-a-return-status-and-value/">creating an explicit return value from a dialog</a> form in a Windows application. Fast forward a lifetime (3 years) and I&#8217;m finding that this knowledge and experience is resurfacing itself on almost a daily basis with my work in Backbone and Marionette. In fact, I&#8217;ve used almost this exact pattern that I first used in WinForms, with several Backbone applications now. But I found it to be rather limiting in how I was able to implement it, because of the language and runtime differences. What I&#8217;ve settled on, though, is giving me the same benefit of explicit modeling, semantics, and encapsulating workflow: events.</p>
<h2>A Poorly Constructed Workflow</h2>
<p>It seems to be common in the JavaScript applications world, to have very poorly defined and constructed workflow in applications. We take one object and build some functionality. Then when the next part of the app needs to fire up, we call the object that runs it directly from the first object. Then when the next part of the app is requested, we call that object from the second one. And we continue on down this path ad-infinitum, creating a mess of tightly coupled concerns, tightly coupled concepts, tightly coupled objects, and a brittle and fragile system that is dependent entirely on the implementation details to understand the higher level concept.</p>
<p>For example, might have a human resources application that allows you to add a new employee and select a manager for the employee. After entering a name and email address, we would show the form to select the manager. When the user clicks save, we create the employee. A crude, but all too common implementation of this workflow might look something like this:</p>
<div id="gist-2651039" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="nx">EmployeeInfoForm</span> <span class="o">=</span> <span class="nx">Backbone</span><span class="p">.</span><span class="nx">View</span><span class="p">.</span><span class="nx">extend</span><span class="p">({</span></div><div class='line' id='LC2'>&nbsp;&nbsp;<span class="nx">events</span><span class="o">:</span> <span class="p">{</span></div><div class='line' id='LC3'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="s2">&quot;click .next&quot;</span><span class="o">:</span> <span class="s2">&quot;nextClicked&quot;</span></div><div class='line' id='LC4'>&nbsp;&nbsp;<span class="p">},</span></div><div class='line' id='LC5'><br/></div><div class='line' id='LC6'>&nbsp;&nbsp;<span class="nx">nextClicked</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">e</span><span class="p">){</span></div><div class='line' id='LC7'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">e</span><span class="p">.</span><span class="nx">preventDefault</span><span class="p">();</span></div><div class='line' id='LC8'><br/></div><div class='line' id='LC9'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">data</span> <span class="o">=</span> <span class="p">{</span></div><div class='line' id='LC10'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">name</span><span class="o">:</span> <span class="k">this</span><span class="p">.</span><span class="nx">$</span><span class="p">(</span><span class="s2">&quot;.name&quot;</span><span class="p">).</span><span class="nx">val</span><span class="p">(),</span></div><div class='line' id='LC11'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">email</span><span class="o">:</span> <span class="k">this</span><span class="p">.</span><span class="nx">$</span><span class="p">(</span><span class="s2">&quot;.email&quot;</span><span class="p">).</span><span class="nx">val</span><span class="p">()</span></div><div class='line' id='LC12'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">};</span></div><div class='line' id='LC13'><br/></div><div class='line' id='LC14'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">employee</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Employee</span><span class="p">(</span><span class="nx">data</span><span class="p">);</span></div><div class='line' id='LC15'><br/></div><div class='line' id='LC16'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">selectManager</span><span class="p">(</span><span class="nx">employee</span><span class="p">);</span></div><div class='line' id='LC17'>&nbsp;&nbsp;<span class="p">},</span></div><div class='line' id='LC18'><br/></div><div class='line' id='LC19'>&nbsp;&nbsp;<span class="nx">selectManager</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">employee</span><span class="p">){</span></div><div class='line' id='LC20'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">view</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">SelectManagerForm</span><span class="p">({</span></div><div class='line' id='LC21'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">model</span><span class="o">:</span> <span class="nx">employee</span></div><div class='line' id='LC22'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">});</span></div><div class='line' id='LC23'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">view</span><span class="p">.</span><span class="nx">render</span><span class="p">();</span></div><div class='line' id='LC24'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">$</span><span class="p">(</span><span class="s2">&quot;.wizard&quot;</span><span class="p">).</span><span class="nx">show</span><span class="p">(</span><span class="nx">view</span><span class="p">.</span><span class="nx">el</span><span class="p">);</span></div><div class='line' id='LC25'>&nbsp;&nbsp;<span class="p">},</span></div><div class='line' id='LC26'><br/></div><div class='line' id='LC27'>&nbsp;&nbsp;<span class="c1">// ...</span></div><div class='line' id='LC28'>&nbsp;&nbsp;<span class="nx">render</span><span class="o">:</span> <span class="kd">function</span><span class="p">(){</span> <span class="p">...</span> <span class="p">}</span></div><div class='line' id='LC29'>&nbsp;&nbsp;<span class="c1">// ... etc</span></div><div class='line' id='LC30'><span class="p">});</span></div><div class='line' id='LC31'><br/></div><div class='line' id='LC32'><span class="nx">SelectManagerForm</span> <span class="o">=</span> <span class="nx">Backbone</span><span class="p">.</span><span class="nx">View</span><span class="p">.</span><span class="nx">extend</span><span class="p">({</span></div><div class='line' id='LC33'>&nbsp;&nbsp;<span class="nx">events</span><span class="o">:</span> <span class="p">{</span></div><div class='line' id='LC34'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="s2">&quot;click .save&quot;</span><span class="o">:</span> <span class="s2">&quot;saveClicked&quot;</span></div><div class='line' id='LC35'>&nbsp;&nbsp;<span class="p">},</span></div><div class='line' id='LC36'><br/></div><div class='line' id='LC37'>&nbsp;&nbsp;<span class="nx">saveClicked</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">e</span><span class="p">){</span></div><div class='line' id='LC38'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">e</span><span class="p">.</span><span class="nx">preventDefault</span><span class="p">();</span></div><div class='line' id='LC39'><br/></div><div class='line' id='LC40'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">managerId</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">$</span><span class="p">(</span><span class="s2">&quot;.manager&quot;</span><span class="p">).</span><span class="nx">val</span><span class="p">();</span></div><div class='line' id='LC41'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">model</span><span class="p">.</span><span class="nx">set</span><span class="p">({</span><span class="nx">managerId</span><span class="o">:</span> <span class="nx">managerId</span><span class="p">});</span></div><div class='line' id='LC42'><br/></div><div class='line' id='LC43'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">model</span><span class="p">.</span><span class="nx">save</span><span class="p">();</span></div><div class='line' id='LC44'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="c1">// do something to close the wizard and move on  </span></div><div class='line' id='LC45'>&nbsp;&nbsp;<span class="p">},</span></div><div class='line' id='LC46'><br/></div><div class='line' id='LC47'>&nbsp;&nbsp;<span class="c1">// ...</span></div><div class='line' id='LC48'>&nbsp;&nbsp;<span class="nx">render</span><span class="o">:</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span> <span class="p">...</span> <span class="p">}</span></div><div class='line' id='LC49'>&nbsp;&nbsp;<span class="c1">// ... etc</span></div><div class='line' id='LC50'><span class="p">});</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2651039/65db5640bca08b48c99c8448003417c42571baa9/1.js" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2651039#file_1.js" style="float:right;margin-right:10px;color:#666">1.js</a>
            <a href="https://gist.github.com/2651039">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>Can you quickly and easily describe the workflow in this example? If you can, then you&#8217;re a better person than I am. I have to spend time looking at the implementation details of both views in order to see what&#8217;s going on and why. I have to piece together the bits from multiple places and form a more coherent high level overview in my head. It&#8217;s not easy for me to see what&#8217;s going on because every time I look at another part of the code, I have to put together the pieces again to make sure I am not breaking someone from the other parts.</p>
<h2>Too Many Concerns</h2>
<p>We&#8217;ve mixed two different concerns in to very few objects, and we&#8217;ve taken those concerns and split them apart in some rather un-natural ways at that.</p>
<p>The first concern is the high level workflow:</p>
<ol>
<li>enter employee info</li>
<li>select manager</li>
<li>create employee</li>
</ol>
<p>The second concern is the implementation detail:</p>
<ol>
<li>Show the EmployeeInfoForm </li>
<li>Allow the user to enter a name and email address</li>
<li>When &#8220;next&#8221; is clicked, gather the name and email address of the employee. </li>
<li>Then show the SelectManagerForm with a list of possible managers to select from. </li>
<li>When &#8220;save&#8221; is clicked, grab the selected manager</li>
<li>Then take all of the employee information and create a new employee record on the server</li>
</ol>
<p>And I haven&#8217;t even gone through any of the secondary and third level workflow in this. What happens when the user hits cancel on the first screen? Or on the second? What about invalid email address validation? If we start adding in all of those steps to the list of implementation details, this list of steps to follow is going to get out of hand very quickly.</p>
<p>By implementing both the high level workflow and the implementation detail in the views &#8211; the details and implementation &#8211; we&#8217;ve destroyed our ability to see the high level workflow at a glance. That will cause problems for us as developers, because we will forget some of those details when changing the system, and we will break things.</p>
<h2>Modeling An Explicit Workflow In Code</h2>
<p>What we want to do, instead, is get back to that high level workflow with fewer bullet points and very little text in each point. But we don&#8217;t want to have to dig through all of the implementation details in order to get to it. We want to see the high level workflow in our code, separated from the implementation details. This makes it easier to change the workflow and to change any specific implementation detail without having to rework the entire workflow.</p>
<p>Wouldn&#8217;t it be nice if we could write this code, for example:</p>
<div id="gist-2651039" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="nx">orgChart</span> <span class="o">=</span> <span class="p">{</span></div><div class='line' id='LC2'><br/></div><div class='line' id='LC3'>&nbsp;&nbsp;<span class="nx">addNewEmployee</span><span class="o">:</span> <span class="kd">function</span><span class="p">(){</span></div><div class='line' id='LC4'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">employeeDetail</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">getEmployeeDetail</span><span class="p">();</span></div><div class='line' id='LC5'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">employeeDetail</span><span class="p">.</span><span class="nx">on</span><span class="p">(</span><span class="s2">&quot;complete&quot;</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">employee</span><span class="p">){</span></div><div class='line' id='LC6'><br/></div><div class='line' id='LC7'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">managerSelector</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">selectManager</span><span class="p">(</span><span class="nx">employee</span><span class="p">);</span></div><div class='line' id='LC8'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">managerSelector</span><span class="p">.</span><span class="nx">on</span><span class="p">(</span><span class="s2">&quot;save&quot;</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">employee</span><span class="p">){</span></div><div class='line' id='LC9'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">employee</span><span class="p">.</span><span class="nx">save</span><span class="p">();</span></div><div class='line' id='LC10'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">});</span></div><div class='line' id='LC11'><br/></div><div class='line' id='LC12'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">});</span></div><div class='line' id='LC13'>&nbsp;&nbsp;<span class="p">},</span></div><div class='line' id='LC14'><br/></div><div class='line' id='LC15'>&nbsp;&nbsp;<span class="c1">// ...</span></div><div class='line' id='LC16'><span class="p">}</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2651039/7b7ad1fa2ac231919b0cad2ec0f45e3409ffdea9/2.js" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2651039#file_2.js" style="float:right;margin-right:10px;color:#666">2.js</a>
            <a href="https://gist.github.com/2651039">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>In this pseudo-code example, we can more clearly see the high level workflow. When we complete the employee info, we move on to the selecting a manager. When that completes, we save the employee with the data that we had entered. It all looks very clean and simple. We could even add in some of the secondary and third level workflow without creating too much mess. And more importantly, we could <a href="http://wekeroad.com/2012/04/05/cleaning-up-deep-callback-nesting-with-nodes-eventemitter">get rid of some of the nested callbacks</a> with better patterns and function separation.</p>
<p>But let&#8217;s see what this would really look like in code that we could execute:</p>
<div id="gist-2651039" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="nx">orgChart</span> <span class="o">=</span> <span class="p">{</span></div><div class='line' id='LC2'><br/></div><div class='line' id='LC3'>&nbsp;&nbsp;<span class="nx">addNewEmployee</span><span class="o">:</span> <span class="kd">function</span><span class="p">(){</span></div><div class='line' id='LC4'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">employeeDetail</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">getEmployeeDetail</span><span class="p">();</span></div><div class='line' id='LC5'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">employeeDetail</span><span class="p">.</span><span class="nx">on</span><span class="p">(</span><span class="s2">&quot;complete&quot;</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">employee</span><span class="p">){</span></div><div class='line' id='LC6'><br/></div><div class='line' id='LC7'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">managerSelector</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">selectManager</span><span class="p">(</span><span class="nx">employee</span><span class="p">);</span></div><div class='line' id='LC8'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">managerSelector</span><span class="p">.</span><span class="nx">on</span><span class="p">(</span><span class="s2">&quot;save&quot;</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">employee</span><span class="p">){</span></div><div class='line' id='LC9'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">employee</span><span class="p">.</span><span class="nx">save</span><span class="p">();</span></div><div class='line' id='LC10'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">});</span></div><div class='line' id='LC11'><br/></div><div class='line' id='LC12'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">});</span></div><div class='line' id='LC13'>&nbsp;&nbsp;<span class="p">},</span></div><div class='line' id='LC14'><br/></div><div class='line' id='LC15'>&nbsp;&nbsp;<span class="c1">// ...</span></div><div class='line' id='LC16'><span class="p">}</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2651039/7b7ad1fa2ac231919b0cad2ec0f45e3409ffdea9/2.js" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2651039#file_2.js" style="float:right;margin-right:10px;color:#666">2.js</a>
            <a href="https://gist.github.com/2651039">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>Yeah &#8211; turns out this is code that we can actually run, and it can be implemented fairly easily with a couple of Backbone views and a model for the details:</p>
<div id="gist-2651039" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="nx">orgChart</span> <span class="o">=</span> <span class="p">{</span></div><div class='line' id='LC2'><br/></div><div class='line' id='LC3'>&nbsp;&nbsp;<span class="nx">addNewEmployee</span><span class="o">:</span> <span class="kd">function</span><span class="p">(){</span></div><div class='line' id='LC4'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">that</span> <span class="o">=</span> <span class="k">this</span><span class="p">;</span></div><div class='line' id='LC5'><br/></div><div class='line' id='LC6'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">employeeDetail</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">getEmployeeDetail</span><span class="p">();</span></div><div class='line' id='LC7'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">employeeDetail</span><span class="p">.</span><span class="nx">on</span><span class="p">(</span><span class="s2">&quot;complete&quot;</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">employee</span><span class="p">){</span></div><div class='line' id='LC8'><br/></div><div class='line' id='LC9'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">managerSelector</span> <span class="o">=</span> <span class="nx">that</span><span class="p">.</span><span class="nx">selectManager</span><span class="p">(</span><span class="nx">employee</span><span class="p">);</span></div><div class='line' id='LC10'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">managerSelector</span><span class="p">.</span><span class="nx">on</span><span class="p">(</span><span class="s2">&quot;save&quot;</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">employee</span><span class="p">){</span></div><div class='line' id='LC11'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">employee</span><span class="p">.</span><span class="nx">save</span><span class="p">();</span></div><div class='line' id='LC12'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">});</span></div><div class='line' id='LC13'><br/></div><div class='line' id='LC14'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">});</span></div><div class='line' id='LC15'>&nbsp;&nbsp;<span class="p">},</span></div><div class='line' id='LC16'><br/></div><div class='line' id='LC17'>&nbsp;&nbsp;<span class="nx">getEmployeeDetail</span><span class="o">:</span> <span class="kd">function</span><span class="p">(){</span></div><div class='line' id='LC18'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">form</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">EmployeeDetailForm</span><span class="p">();</span></div><div class='line' id='LC19'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">form</span><span class="p">.</span><span class="nx">render</span><span class="p">();</span></div><div class='line' id='LC20'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">$</span><span class="p">(</span><span class="s2">&quot;#wizard&quot;</span><span class="p">).</span><span class="nx">html</span><span class="p">(</span><span class="nx">form</span><span class="p">.</span><span class="nx">el</span><span class="p">);</span></div><div class='line' id='LC21'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">return</span> <span class="nx">form</span><span class="p">;</span></div><div class='line' id='LC22'>&nbsp;&nbsp;<span class="p">},</span></div><div class='line' id='LC23'><br/></div><div class='line' id='LC24'>&nbsp;&nbsp;<span class="nx">selectManager</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">employee</span><span class="p">){</span></div><div class='line' id='LC25'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">form</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">SelectManagerForm</span><span class="p">({</span></div><div class='line' id='LC26'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">model</span><span class="o">:</span> <span class="nx">employee</span></div><div class='line' id='LC27'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">});</span></div><div class='line' id='LC28'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">form</span><span class="p">.</span><span class="nx">render</span><span class="p">();</span></div><div class='line' id='LC29'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">$</span><span class="p">(</span><span class="s2">&quot;#wizard&quot;</span><span class="p">).</span><span class="nx">html</span><span class="p">(</span><span class="nx">form</span><span class="p">.</span><span class="nx">el</span><span class="p">);</span></div><div class='line' id='LC30'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">return</span> <span class="nx">form</span><span class="p">;</span></div><div class='line' id='LC31'>&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC32'><span class="p">}</span></div><div class='line' id='LC33'><br/></div><div class='line' id='LC34'><span class="c1">// implementation details for EmployeeDetailForm go here</span></div><div class='line' id='LC35'><br/></div><div class='line' id='LC36'><span class="c1">// implementation details for SelectManagerForm go here</span></div><div class='line' id='LC37'><br/></div><div class='line' id='LC38'><span class="c1">// implementation details for Employee model go here</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2651039/f0d01867e96cef419acbc01c7f6610e04f8f0dfc/3.js" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2651039#file_3.js" style="float:right;margin-right:10px;color:#666">3.js</a>
            <a href="https://gist.github.com/2651039">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>I&#8217;ve obviously omitted some of the details of the views and model, but you get the idea.</p>
<h2>The Benefits</h2>
<p>There are a number of benefits to writing code like this. It&#8217;s easy to see the high level workflow. We don&#8217;t have to worry about all of the implementation details for each of the views or the model when dealing with the workflow. We can change any of the individual view implementations when we need to, without affecting the rest of the workflow (<a href="http://lostechies.com/derickbailey/2011/09/22/dependency-injection-is-not-the-same-as-the-dependency-inversion-principle/">as long as the view conforms to the protocol that the workflow defines</a>). And there&#8217;s probably a handful of other benefits, as well. </p>
<p>But the largest single benefit of all these, in my experience, is being able to see the workflow at a glance. 6 months from now &#8211; or if you&#8217;re like me, 6 hours from now &#8211; you won&#8217;t remember that you have to trace through 5 different Views and three different custom objects and models, in order to piece together the workflow that you spun together in the sample at the very top of this post. But if you have a workflow as simple as the one that we just saw, where the workflow is more explicit within a higher level method, separated from the implementation details… well, then you&#8217;re more likely to pick up the code and understand the workflow quickly. </p>
<h2>The Drawbacks</h2>
<p>Everything has a price, right? But the price for this is fairly small. You will end up with a few more objects and a few more methods to keep track of. There&#8217;s a mild overhead associated with this in the world of browser based JavaScript, but that&#8217;s likely to be so small that you won&#8217;t notice.</p>
<p>The real cost, though, is that you&#8217;re going to have to learn new implementation patterns and styles of development in order to get this working, and that takes time. Sure, looking at an example like this is easy. But it&#8217;s a simple example and a simple implementation. When you get down to actually trying to write this style of code for yourself, in your project, with your 20 variations on the flow through the application, it will get more complicated, quickly. And there&#8217;s no simple answer for this complication in design, other than to say that you need to learn to break down the larger workflow in to smaller pieces that can look as simple as this one.</p>
<h2>But It&#8217;s Worth It</h2>
<p>In the end, in spite of potential drawbacks and learning curves, making an effort to explicitly model your workflow in your application is important. And it really doesn&#8217;t matter what language your writing your code in. I&#8217;ve shown these examples in JavaScript and Backbone because that&#8217;s what I&#8217;m using on a daily basis at this point. But I&#8217;ve been applying these same rules to C#/.NET, Ruby and other languages for years. The principles are the same, it&#8217;s just the implementation specifics that change.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/LosTechies?a=80NnIDpZiCI:ItlYlA3Ogsw:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/LosTechies?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=80NnIDpZiCI:ItlYlA3Ogsw:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/LosTechies?i=80NnIDpZiCI:ItlYlA3Ogsw:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=80NnIDpZiCI:ItlYlA3Ogsw:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/LosTechies?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=80NnIDpZiCI:ItlYlA3Ogsw:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/LosTechies?i=80NnIDpZiCI:ItlYlA3Ogsw:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/LosTechies/~4/80NnIDpZiCI" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://lostechies.com/derickbailey/2012/05/10/modeling-explicit-workflow-with-code-in-javascript-and-backbone-apps/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
            <media:content url="http://www.gravatar.com/avatar/e592bd1326b1e80188ed4c0bf26b9f75?s=96&amp;d=http%3A%2F%2Fwww.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
            <media:title type="html">Derick Bailey</media:title>
        </media:content>
    		<feedburner:origLink>http://lostechies.com/derickbailey/2012/05/10/modeling-explicit-workflow-with-code-in-javascript-and-backbone-apps/</feedburner:origLink></item>
	<item>
		<title>Help Me Improve The Marionette Wiki</title>
		<link>http://feedproxy.google.com/~r/LosTechies/~3/TNw8vVD2B1g/</link>
		<comments>http://lostechies.com/derickbailey/2012/05/09/help-me-improve-the-marionette-wiki/#comments</comments>
		<pubDate>Wed, 09 May 2012 13:28:56 +0000</pubDate>
		<dc:creator>Derick Bailey</dc:creator>
				<category><![CDATA[Community]]></category>
		<category><![CDATA[Marionette]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://lostechies.com/derickbailey/?p=926]]></guid>
		<description><![CDATA[Documentation is difficult to write, and even more difficult to write well so that it covers all of the nuances and details that the people building the actual project tend to assume and forget. My Marionette project is no different.&#160;&#8230; <a href="http://lostechies.com/derickbailey/2012/05/09/help-me-improve-the-marionette-wiki/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p>Documentation is difficult to write, and even more difficult to write well so that it covers all of the nuances and details that the people building the actual project tend to assume and forget. My Marionette project is no different. I continue to receive feedback that it&#8217;s hard to know what each piece is really best suited for, questions on which View type is best suited for a scenario, and general inquiries for examples on how to implement specific behaviors and features.</p>
<p>And I need your help to answer these questions and improve the documentation and <a href="https://github.com/derickbailey/backbone.marionette/wiki">wiki</a>.</p>
<h2>The Marionette Wiki</h2>
<p>In addition to the technical documentation in the project&#8217;s readme, I&#8217;ve started up the wiki on the github project page. I&#8217;ve begun with two simple pages: an overview on the different view types, and page to let Marionette users show of their projects and websites that are using it.</p>
<p>Help me and the rest of the community of Marionette users improve the documentation for this project by providing examples, best practices, answers to frequently asked questions, and more. </p>
<p>Head over to the <a href="https://github.com/derickbailey/backbone.marionette/wiki">wiki</a> and start helping! </p>
<h3><strong><a href="https://github.com/derickbailey/backbone.marionette/wiki">https://github.com/derickbailey/backbone.marionette/wiki</a></strong></h3>
<h2>Topics To Cover</h2>
<p>Example topics that should be covered in the wiki:</p>
<ul>
<li>Using Marionette with RequireJS</li>
<li>Using JST templates with Marionette views</li>
<li>Using Handlebars templates with Marionette views</li>
<li>Using jQuery plugins and visual controls with Marionette</li>
<li>and much, much more</li>
</ul>
<p>I realize that some of these are items that I&#8217;ve blogged about here. One of my hopes and goals is to have many of the Marionette blog posts from this blog, copied in to the Wiki in a manner that makes sense for the wiki. I will try to do some of this myself, but it would also be wonderfully helpful if other members of the Marionette community could assist in doing this.</p>
<h2>I Need Your Help. Yes. YOU.</h2>
<p>I know I&#8217;m asking a lot &#8211; but I believe the community of Marionette users is up to it. It only takes a few minutes of time to improve one page or create a new one with some very basic information. Then another person can come along and make another improvement. Then another, and another. </p>
<p>Lastly: don&#8217;t think &#8220;oh, someone else will do it&#8221;. They won&#8217;t. Believe me. The distribution of responsibility is the single largest reason that people won&#8217;t take responsibility or put effort in to something. Everyone assumes that someone else will do it, and no one actually does it.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/LosTechies?a=TNw8vVD2B1g:ut-7W5ChBXs:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/LosTechies?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=TNw8vVD2B1g:ut-7W5ChBXs:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/LosTechies?i=TNw8vVD2B1g:ut-7W5ChBXs:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=TNw8vVD2B1g:ut-7W5ChBXs:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/LosTechies?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=TNw8vVD2B1g:ut-7W5ChBXs:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/LosTechies?i=TNw8vVD2B1g:ut-7W5ChBXs:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/LosTechies/~4/TNw8vVD2B1g" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://lostechies.com/derickbailey/2012/05/09/help-me-improve-the-marionette-wiki/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
            <media:content url="http://www.gravatar.com/avatar/e592bd1326b1e80188ed4c0bf26b9f75?s=96&amp;d=http%3A%2F%2Fwww.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
            <media:title type="html">Derick Bailey</media:title>
        </media:content>
    		<feedburner:origLink>http://lostechies.com/derickbailey/2012/05/09/help-me-improve-the-marionette-wiki/</feedburner:origLink></item>
	<item>
		<title>Austin Code Camp Schedule</title>
		<link>http://feedproxy.google.com/~r/LosTechies/~3/Acbt-GxGCIU/</link>
		<comments>http://lostechies.com/johnteague/2012/05/09/austin-code-camp-schedule-2/#comments</comments>
		<pubDate>Wed, 09 May 2012 04:56:00 +0000</pubDate>
		<dc:creator>John Teague</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://lostechies.com/johnteague/?p=110]]></guid>
		<description><![CDATA[We&#8217;ve got an amazing line up of presentations this year.  A lot of great people from the community have volunteered their time to share with the rest of what they&#8217;ve learned and what they are passionate about.  With over 40&#160;&#8230; <a href="http://lostechies.com/johnteague/2012/05/09/austin-code-camp-schedule-2/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p>We&#8217;ve got an amazing line up of presentations this year.  A lot of great people from the community have volunteered their time to share with the rest of what they&#8217;ve learned and what they are passionate about.  With over 40 sessions submitted it&#8217;s going to be a great conference.</p>
<p>The list of proposed sessions are available on the web site <a href="http://austincodecamp2012.com/">http://austincodecamp2012.com</a>. Please look at the sessions and vote for the ones you find most interesting.  We use this information to place the presenations in an appropriately sized room (though some will be cancelled I&#8217;m sure)</p>
<p>It&#8217;s going to be a great conference!</p>
<p>Also if your company would like to sponsor, please contact us.</p>
<p><a href="http://www.eventbrite.com/event/3028354891?ref=ebtnebregn" target="_blank"><img src="http://www.eventbrite.com/custombutton?eid=3028354891" alt="Eventbrite - Austin Code Camp 2012" /></a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/LosTechies?a=Acbt-GxGCIU:6Qi0rWMMVhw:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/LosTechies?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=Acbt-GxGCIU:6Qi0rWMMVhw:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/LosTechies?i=Acbt-GxGCIU:6Qi0rWMMVhw:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=Acbt-GxGCIU:6Qi0rWMMVhw:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/LosTechies?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=Acbt-GxGCIU:6Qi0rWMMVhw:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/LosTechies?i=Acbt-GxGCIU:6Qi0rWMMVhw:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/LosTechies/~4/Acbt-GxGCIU" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://lostechies.com/johnteague/2012/05/09/austin-code-camp-schedule-2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
            <media:content url="http://www.gravatar.com/avatar/4ec3c07d6f4527238a3f5c6ec5fefd63?s=96&amp;d=http%3A%2F%2Fwww.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
            <media:title type="html">John Teague</media:title>
        </media:content>
    		<feedburner:origLink>http://lostechies.com/johnteague/2012/05/09/austin-code-camp-schedule-2/</feedburner:origLink></item>
	<item>
		<title>posh-git v0.4</title>
		<link>http://feedproxy.google.com/~r/LosTechies/~3/eB1gaeuue1w/</link>
		<comments>http://lostechies.com/keithdahlby/2012/05/07/posh-git-v0-4/#comments</comments>
		<pubDate>Mon, 07 May 2012 15:04:49 +0000</pubDate>
		<dc:creator>Keith Dahlby</dc:creator>
				<category><![CDATA[git]]></category>
		<category><![CDATA[posh-git]]></category>
		<category><![CDATA[powershell]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://lostechies.com/keithdahlby/?p=106]]></guid>
		<description><![CDATA[I figure a year between releases is plenty, so I&#8217;ve tagged a v0.4 release of posh-git. Really the notion of versions for a bunch of scripts on which noone depends seems a bit silly&#8230;if a feature seems to be missing,&#160;&#8230; <a href="http://lostechies.com/keithdahlby/2012/05/07/posh-git-v0-4/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p>I figure a year between <a title="posh-git Release v0.3" href="http://lostechies.com/keithdahlby/2011/04/06/posh-git-release-v0-3/">releases</a> is plenty, so I&#8217;ve tagged a <a title="posh-git v0.3 on GitHub" href="https://github.com/dahlbyk/posh-git/tree/v0.4">v0.4 release</a> of <a title="posh-git on GitHub" href="https://github.com/dahlbyk/posh-git">posh-git</a>.</p>
<p>Really the notion of versions for a bunch of scripts on which noone  depends seems a bit silly&#8230;if a feature seems to be missing, get latest from master. If it&#8217;s still missing, send me a pull request (or log an issue). But I suppose it&#8217;s good to check in periodically to document what we&#8217;ve been up to.</p>
<p>New in this release:</p>
<ul>
<li>Git 1.7.2 or better is required
<ul>
<li>And I fixed a bug that prevented it from working with 1.7.10.</li>
</ul>
</li>
<li>Prompt status now plays nicely with <a href="http://github.com/JeremySkinner/posh-hg">posh-hg</a> without extra hacks</li>
<li>Functions are now provided for using <code>ssh-agent</code> to save credentials
<ul>
<li>If you get a warning that <code>ssh-agent</code> could not be found, either add an <code>ssh-agent</code> PowerShell alias or <a href="http://blog.ryanrust.net/?p=67">add the path to <code>Git\bin</code> in your <code>PATH</code> environment variable</a></li>
</ul>
</li>
<li>Branch in prompt status is now colored according to being ahead of or behind a tracked reference (see <a title="posh-git Readme" href="https://github.com/dahlbyk/posh-git#readme">readme</a> for an explanation of default colors)</li>
<li>Added tab expansion for a bunch of new commands and options (remote refs, <code>revert</code>, <code>tfs</code>, <code>bisect</code>, <code>submodule</code>, and more!)</li>
<li>Tab expansion works for aliases of <code>git</code> (I recommend <code>g</code>)<br />
<em>Contributed by <a href="http://fooberry.com/">Mark Borcherding</a></em></li>
<li>The list of commands expanded by default now covers most porcelain commands.
<ul>
<li>You can always get all commands to expand by setting <code>$GitTabSettings.AllCommands = $true</code></li>
</ul>
</li>
<li>Values of <code>$LASTERRORCODE</code> for the last real command are preserved through the prompt</li>
<li>If prompt performance for a repository is not acceptable, that repo&#8217;s path can be added to <code>$GitPromptSettings.RepositoriesInWhichToDisableFileStatus</code><br />
<em>Contributed by <a href="http://saintgimp.org">Eric Lee</a></em></li>
<li>posh-git should work in the Nuget Package Manager Console, though you&#8217;ll probably want to <a title="Git customizing colors for Windows including posh-git" href="http://sedodream.com/2012/05/05/GitCustomizingColorsForWindowsIncludingPoshgit.aspx">change the colors</a></li>
<li>The <code>GIT_DIR</code> environment variable is used if defined<br />
<em>Contributed by <a href="http://rod.42n.pl">Daniel Dabrowski</a></em></li>
</ul>
<p><a title="posh-git Contributors" href="https://github.com/dahlbyk/posh-git/graphs/contributors">Several others</a> have contributed bug fixes as well—thanks everyone! It&#8217;s pretty awesome to work on something that someone else cares enough about to help improve.</p>
<p>If all goes according to plan, the next time you hear from me (about posh-git) will be to announce that migration to <a href="https://github.com/libgit2/libgit2sharp">LibGit2Sharp</a> is complete. I&#8217;m optimistic that the move will address the persistent performance concerns for large repositories. If you have a particularly troublesome repo, feel free to try <a href="https://github.com/dahlbyk/posh-git/commits/libgit2">my libgit2 branch</a> and let me know if it&#8217;s better (or worse).</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/LosTechies?a=eB1gaeuue1w:hkaw-enR444:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/LosTechies?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=eB1gaeuue1w:hkaw-enR444:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/LosTechies?i=eB1gaeuue1w:hkaw-enR444:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=eB1gaeuue1w:hkaw-enR444:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/LosTechies?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=eB1gaeuue1w:hkaw-enR444:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/LosTechies?i=eB1gaeuue1w:hkaw-enR444:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/LosTechies/~4/eB1gaeuue1w" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://lostechies.com/keithdahlby/2012/05/07/posh-git-v0-4/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
            <media:content url="http://www.gravatar.com/avatar/43a5676a300a54ffdc903e49a2db9060?s=96&amp;d=http%3A%2F%2Fwww.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
            <media:title type="html">Keith Dahlby</media:title>
        </media:content>
    		<feedburner:origLink>http://lostechies.com/keithdahlby/2012/05/07/posh-git-v0-4/</feedburner:origLink></item>
	<item>
		<title>Wrapping $.ajax In A Thin “Command” Framework For Backbone Apps</title>
		<link>http://feedproxy.google.com/~r/LosTechies/~3/UPAozqmEBc0/</link>
		<comments>http://lostechies.com/derickbailey/2012/05/04/wrapping-ajax-in-a-thin-command-framework-for-backbone-apps/#comments</comments>
		<pubDate>Fri, 04 May 2012 14:45:16 +0000</pubDate>
		<dc:creator>Derick Bailey</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Backbone]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Semantics]]></category>
		<category><![CDATA[Underscore]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://lostechies.com/derickbailey/?p=922]]></guid>
		<description><![CDATA[A large number of my recent client applications, built on Backbone, have been using straight jQuery AJAX calls. Sometimes its in combination with Backbone&#8217;s persistence method, but other times I end up using AJAX calls in place of Backbone calls.&#160;&#8230; <a href="http://lostechies.com/derickbailey/2012/05/04/wrapping-ajax-in-a-thin-command-framework-for-backbone-apps/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p>A large number of my recent client applications, built on Backbone, have been using straight jQuery AJAX calls. Sometimes its in combination with Backbone&#8217;s persistence method, but other times I end up using AJAX calls in place of Backbone calls.</p>
<h2>Non-CRUD-y Apps</h2>
<p>Now I don&#8217;t think that there&#8217;s anything wrong with Backbone&#8217;s &#8220;save&#8221;, &#8220;fetch&#8221; and &#8220;destroy&#8221; methods. They&#8217;re quite handy, and very well done. The deciding factor in using them is whether or not my application is CRUD-y or not. That is to say, many of my recent apps are taking more of a command approach to user interaction and data updates. Instead of just having simple Create, Read, Update and Delete forms on my apps, I tend to have smaller and more focused commands that are called.</p>
<p>For example, signing a terms of service agreement is a command to sign the agreement, not just a &#8220;create&#8221; on a resource. Sure, the implementation of that may be a &#8220;POST&#8221; on a resource location. But that doesn&#8217;t mean I need a full Backbone model, or need to think about the signature as a RESTful resource from my JavaScript code.</p>
<h2>Executing Commands vs Making AJAX Calls</h2>
<p>As a result of all this, I end up using $.ajax a lot… and it&#8217;s getting really ugly and obnoxious seeing this all over my code:</p>
<div id="gist-2595175" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="kd">var</span> <span class="nx">signForm</span> <span class="o">=</span> <span class="nx">$</span><span class="p">.</span><span class="nx">ajax</span><span class="p">({</span></div><div class='line' id='LC2'>&nbsp;&nbsp;<span class="nx">type</span><span class="o">:</span> <span class="s2">&quot;POST&quot;</span><span class="p">,</span></div><div class='line' id='LC3'>&nbsp;&nbsp;<span class="nx">url</span><span class="o">:</span> <span class="s2">&quot;/some/form&quot;</span><span class="p">,</span></div><div class='line' id='LC4'>&nbsp;&nbsp;<span class="nx">dataType</span><span class="o">:</span> <span class="s2">&quot;JSON&quot;</span><span class="p">,</span></div><div class='line' id='LC5'>&nbsp;&nbsp;<span class="nx">data</span><span class="o">:</span> <span class="nx">myData</span></div><div class='line' id='LC6'><span class="p">});</span></div><div class='line' id='LC7'><br/></div><div class='line' id='LC8'><span class="nx">signForm</span><span class="p">.</span><span class="nx">done</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">response</span><span class="p">){</span></div><div class='line' id='LC9'>&nbsp;&nbsp;<span class="c1">// handle success here</span></div><div class='line' id='LC10'><span class="p">});</span></div><div class='line' id='LC11'><br/></div><div class='line' id='LC12'><span class="nx">signForm</span><span class="p">.</span><span class="nx">fail</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">response</span><span class="p">){</span></div><div class='line' id='LC13'>&nbsp;&nbsp;<span class="c1">// handle failure here</span></div><div class='line' id='LC14'><span class="p">});</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2595175/6af7fc7b62957323c04ae68bbfd116f181a5c1e9/1.js" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2595175#file_1.js" style="float:right;margin-right:10px;color:#666">1.js</a>
            <a href="https://gist.github.com/2595175">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>Not only is this ugly when you repeat the $.ajax calls all over the code, but it doesn&#8217;t really give the semantic benefit of knowing what the code is really doing. I&#8217;m not just making a call across an AJAX connection. I&#8217;m trying to execute a command &#8211; I&#8217;m trying to do something important, and I want my code to reflect that.</p>
<p>So I wrapped up my $.ajax calls in a thin &#8220;command&#8221; wrapper for my current client app (built with Backbone of course), and ended up with this instead:</p>
<div id="gist-2595175" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="c1">// Register a command to use</span></div><div class='line' id='LC2'><span class="c1">// -------------------------</span></div><div class='line' id='LC3'><br/></div><div class='line' id='LC4'><span class="nx">Backbone</span><span class="p">.</span><span class="nx">AjaxCommands</span><span class="p">.</span><span class="nx">register</span><span class="p">(</span><span class="s2">&quot;signForm&quot;</span><span class="p">,</span> <span class="p">{</span></div><div class='line' id='LC5'>&nbsp;&nbsp;<span class="nx">url</span><span class="o">:</span> <span class="s2">&quot;/some/form&quot;</span><span class="p">,</span></div><div class='line' id='LC6'>&nbsp;&nbsp;<span class="nx">type</span><span class="o">:</span> <span class="s2">&quot;POST&quot;</span></div><div class='line' id='LC7'><span class="p">});</span></div><div class='line' id='LC8'><br/></div><div class='line' id='LC9'><br/></div><div class='line' id='LC10'><span class="c1">// somewhere else in the application, use the command</span></div><div class='line' id='LC11'><span class="c1">// --------------------------------------------------</span></div><div class='line' id='LC12'><br/></div><div class='line' id='LC13'><span class="kd">var</span> <span class="nx">signForm</span> <span class="o">=</span> <span class="nx">Backbone</span><span class="p">.</span><span class="nx">AjaxCommands</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="s2">&quot;signForm&quot;</span><span class="p">);</span></div><div class='line' id='LC14'><br/></div><div class='line' id='LC15'><span class="nx">signForm</span><span class="p">.</span><span class="nx">on</span><span class="p">(</span><span class="s2">&quot;success&quot;</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">response</span><span class="p">){</span></div><div class='line' id='LC16'>&nbsp;&nbsp;<span class="c1">// handle success here</span></div><div class='line' id='LC17'><span class="p">});</span></div><div class='line' id='LC18'><br/></div><div class='line' id='LC19'><span class="nx">signForm</span><span class="p">.</span><span class="nx">on</span><span class="p">(</span><span class="s2">&quot;error&quot;</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">response</span><span class="p">){</span></div><div class='line' id='LC20'>&nbsp;&nbsp;<span class="c1">// handle failure here</span></div><div class='line' id='LC21'><span class="p">});</span></div><div class='line' id='LC22'><br/></div><div class='line' id='LC23'><span class="c1">// execute the command and send this data with it</span></div><div class='line' id='LC24'><span class="nx">signForm</span><span class="p">.</span><span class="nx">execute</span><span class="p">(</span><span class="nx">myData</span><span class="p">);</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2595175/5468abf85cb67fa9ddef2126937412074085173b/2.js" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2595175#file_2.js" style="float:right;margin-right:10px;color:#666">2.js</a>
            <a href="https://gist.github.com/2595175">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>Looking at this in comparison to the original $.ajax calls, there are a few less lines of code. Since I have a thin wrapper around the ajax calls and setup, I can make a few assumptions about the calls and provide a little bit of default configuration. </p>
<p>I can also move the registration of commands somewhere other than the execution of the commands, which is a huge win for readability and organization of the code when it comes time to execute a command.</p>
<p>Of course the handling of events for success, error and completed doesn&#8217;t give me any advantage over $.ajax and deferred objects. But the big benefit here and why I don&#8217;t mind the thin wraper around the done/fail/always deferred methods, is the semantic value of executing a named command vs configuring an ajax call.</p>
<p>And before you go in to a &#8220;semantics are not important&#8221; lapse of sanity, just think a little about this line that I once heard from <a href="https://twitter.com/#!/scichelli">Sharon Cichelli</a>:</p>
<blockquote>
<p>&#8220;<em>Semantics will continue to be important until we learn to communicate in something other than language.</em>&#8220;</p>
</blockquote>
<h2>Implementing The Command Structure</h2>
<p>This implementation relies on Backbone, Underscore and jQuery, so it&#8217;s really only useful in Backbone applications at this point. It&#8217;s also important to note that this code is not unit tested at all. I&#8217;m using it in my current client application and it is functional for me, but I don&#8217;t recommend taking this code as a great implementation, yet. I have plans on turning this into a real plugin, with full testing around it. But like most of my plugins and libraries, it started out as a quick hack in order to get something cleaned up in one of my applications.</p>
<div id="gist-2595175" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="c1">// Backbone.AjaxCommands</span></div><div class='line' id='LC2'><span class="c1">// ---------------------</span></div><div class='line' id='LC3'><br/></div><div class='line' id='LC4'><span class="nx">Backbone</span><span class="p">.</span><span class="nx">AjaxCommands</span> <span class="o">=</span> <span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">Backbone</span><span class="p">,</span> <span class="nx">$</span><span class="p">,</span> <span class="nx">_</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC5'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">Commands</span> <span class="o">=</span> <span class="p">{};</span></div><div class='line' id='LC6'><br/></div><div class='line' id='LC7'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="c1">// Private data</span></div><div class='line' id='LC8'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="c1">// ------------</span></div><div class='line' id='LC9'><br/></div><div class='line' id='LC10'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">commandList</span> <span class="o">=</span> <span class="p">{};</span></div><div class='line' id='LC11'><br/></div><div class='line' id='LC12'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="c1">// Public API</span></div><div class='line' id='LC13'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="c1">// ----------</span></div><div class='line' id='LC14'><br/></div><div class='line' id='LC15'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">Commands</span><span class="p">.</span><span class="nx">register</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">commandName</span><span class="p">,</span> <span class="nx">options</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC16'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">commandList</span><span class="p">[</span><span class="nx">commandName</span><span class="p">]</span> <span class="o">=</span> <span class="nx">options</span><span class="p">;</span></div><div class='line' id='LC17'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC18'><br/></div><div class='line' id='LC19'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">Commands</span><span class="p">.</span><span class="nx">get</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">commandName</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC20'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">options</span> <span class="o">=</span> <span class="nx">commandList</span><span class="p">[</span><span class="nx">commandName</span><span class="p">];</span></div><div class='line' id='LC21'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">options</span> <span class="o">=</span> <span class="nx">options</span> <span class="o">||</span> <span class="p">{};</span></div><div class='line' id='LC22'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">options</span> <span class="o">=</span> <span class="nx">_</span><span class="p">.</span><span class="nx">clone</span><span class="p">(</span><span class="nx">options</span><span class="p">);</span></div><div class='line' id='LC23'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">command</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Commands</span><span class="p">.</span><span class="nx">Command</span><span class="p">(</span><span class="nx">commandName</span><span class="p">,</span> <span class="nx">options</span><span class="p">);</span></div><div class='line' id='LC24'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">return</span> <span class="nx">command</span><span class="p">;</span></div><div class='line' id='LC25'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">};</span></div><div class='line' id='LC26'><br/></div><div class='line' id='LC27'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="c1">// Command Type</span></div><div class='line' id='LC28'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="c1">// -------------------</span></div><div class='line' id='LC29'><br/></div><div class='line' id='LC30'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">Commands</span><span class="p">.</span><span class="nx">Command</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">name</span><span class="p">,</span> <span class="nx">options</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC31'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">name</span> <span class="o">=</span> <span class="nx">name</span><span class="p">;</span></div><div class='line' id='LC32'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">options</span> <span class="o">=</span> <span class="nx">options</span></div><div class='line' id='LC33'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">};</span></div><div class='line' id='LC34'><br/></div><div class='line' id='LC35'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">_</span><span class="p">.</span><span class="nx">extend</span><span class="p">(</span><span class="nx">Commands</span><span class="p">.</span><span class="nx">Command</span><span class="p">.</span><span class="nx">prototype</span><span class="p">,</span> <span class="nx">Backbone</span><span class="p">.</span><span class="nx">Events</span><span class="p">,</span> <span class="p">{</span></div><div class='line' id='LC36'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">execute</span><span class="o">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">data</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC37'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">that</span> <span class="o">=</span> <span class="k">this</span><span class="p">;</span></div><div class='line' id='LC38'><br/></div><div class='line' id='LC39'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">config</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">getAjaxConfig</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">options</span><span class="p">,</span> <span class="nx">data</span><span class="p">);</span></div><div class='line' id='LC40'><br/></div><div class='line' id='LC41'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">trigger</span><span class="p">(</span><span class="s2">&quot;before:execute&quot;</span><span class="p">);</span></div><div class='line' id='LC42'><br/></div><div class='line' id='LC43'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">request</span> <span class="o">=</span> <span class="nx">$</span><span class="p">.</span><span class="nx">ajax</span><span class="p">(</span><span class="nx">config</span><span class="p">);</span></div><div class='line' id='LC44'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">request</span><span class="p">.</span><span class="nx">done</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">response</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC45'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">that</span><span class="p">.</span><span class="nx">trigger</span><span class="p">(</span><span class="s2">&quot;success&quot;</span><span class="p">,</span> <span class="nx">response</span><span class="p">);</span></div><div class='line' id='LC46'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">});</span></div><div class='line' id='LC47'><br/></div><div class='line' id='LC48'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">request</span><span class="p">.</span><span class="nx">fail</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">response</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC49'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">that</span><span class="p">.</span><span class="nx">trigger</span><span class="p">(</span><span class="s2">&quot;error&quot;</span><span class="p">,</span> <span class="nx">response</span><span class="p">);</span></div><div class='line' id='LC50'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">});</span></div><div class='line' id='LC51'><br/></div><div class='line' id='LC52'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">request</span><span class="p">.</span><span class="nx">always</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">response</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC53'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">that</span><span class="p">.</span><span class="nx">trigger</span><span class="p">(</span><span class="s2">&quot;complete&quot;</span><span class="p">,</span> <span class="nx">response</span><span class="p">);</span></div><div class='line' id='LC54'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">});</span></div><div class='line' id='LC55'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">},</span></div><div class='line' id='LC56'><br/></div><div class='line' id='LC57'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">getAjaxConfig</span><span class="o">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">options</span><span class="p">,</span> <span class="nx">data</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC58'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">url</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">getUrl</span><span class="p">(</span><span class="nx">options</span><span class="p">,</span> <span class="nx">data</span><span class="p">);</span></div><div class='line' id='LC59'><br/></div><div class='line' id='LC60'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">ajaxConfig</span> <span class="o">=</span> <span class="p">{</span></div><div class='line' id='LC61'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">type</span><span class="o">:</span> <span class="s2">&quot;GET&quot;</span><span class="p">,</span></div><div class='line' id='LC62'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">dataType</span><span class="o">:</span> <span class="s2">&quot;JSON&quot;</span><span class="p">,</span></div><div class='line' id='LC63'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">url</span><span class="o">:</span> <span class="nx">url</span></div><div class='line' id='LC64'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">};</span></div><div class='line' id='LC65'><br/></div><div class='line' id='LC66'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">_</span><span class="p">.</span><span class="nx">extend</span><span class="p">(</span><span class="nx">ajaxConfig</span><span class="p">,</span> <span class="nx">options</span><span class="p">);</span></div><div class='line' id='LC67'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">ajaxConfig</span><span class="p">.</span><span class="nx">data</span> <span class="o">=</span> <span class="nx">data</span><span class="p">;</span></div><div class='line' id='LC68'><br/></div><div class='line' id='LC69'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">return</span> <span class="nx">ajaxConfig</span><span class="p">;</span></div><div class='line' id='LC70'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">},</span></div><div class='line' id='LC71'><br/></div><div class='line' id='LC72'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">getUrl</span><span class="o">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">options</span><span class="p">,</span> <span class="nx">data</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC73'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">return</span> <span class="nx">options</span><span class="p">.</span><span class="nx">url</span><span class="p">;</span></div><div class='line' id='LC74'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC75'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">});</span></div><div class='line' id='LC76'><br/></div><div class='line' id='LC77'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">return</span> <span class="nx">Commands</span><span class="p">;</span></div><div class='line' id='LC78'><span class="p">})(</span><span class="nx">Backbone</span><span class="p">,</span> <span class="nx">$</span><span class="p">,</span> <span class="nx">_</span><span class="p">);</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2595175/a9270544570e17a7fad1352d2c2133fefa33532f/backbone.ajaxcommands.js" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2595175#file_backbone.ajaxcommands.js" style="float:right;margin-right:10px;color:#666">backbone.ajaxcommands.js</a>
            <a href="https://gist.github.com/2595175">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>There ar ea couple of things you&#8217;ll want to note in this code:</p>
<p>The call to &#8220;register&#8221; a command stores the configuration that you provide. The call to &#8220;get&#8221; a command creates a new command instance and hands it back to you. This is done so that you can have single-use command objects and not have to worry about unbinding events from the command after it has completed. If I held on to a single command instance and just handed that back to you, you would be responsible for unbinding the event handlers after executing the command. </p>
<p>The wrapper events for &#8220;success&#8221;, &#8220;error&#8221;, and &#8220;complete&#8221; also don&#8217;t guarantee to fire if you subscribe to them after the command has been executed. So, it&#8217;s important to set up your event handlers before calling .execute on the command object.</p>
<p>I&#8217;ve also extracted the &#8220;getUrl&#8221; method specifically because I need to provide a very custom implementation of this method in my client&#8217;s application. I have another plugin that I&#8217;m looking at writing, which handles storage and retrieval of URLs in my Backbone apps, including :token replacement in the urls … but that&#8217;s another blog post and another plugin to write.</p>
<h2>A Timed Polling Mechanism</h2>
<p>One of the more interesting things I&#8217;m doing with this is using it as a timed polling mechanism. I set up a command and then I wrap the commands &#8220;execute&#8221; function in another method that I can call from a setTimeout. When the command executes, I check the response. If I find the data I need, I move on. If I don&#8217;t find the data I need, I call the wrapper function again, inside of a setTimeout.</p>
<div id="gist-2595175" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="kd">var</span> <span class="nx">myCommand</span> <span class="o">=</span> <span class="nx">Backbone</span><span class="p">.</span><span class="nx">AjaxCommands</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="s2">&quot;myCommand&quot;</span><span class="p">);</span></div><div class='line' id='LC2'><br/></div><div class='line' id='LC3'><span class="kd">var</span> <span class="nx">executeCommand</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(){</span></div><div class='line' id='LC4'>&nbsp;&nbsp;<span class="nx">myCommand</span><span class="p">.</span><span class="nx">execute</span><span class="p">(</span><span class="nx">someData</span><span class="p">);</span></div><div class='line' id='LC5'><span class="p">};</span></div><div class='line' id='LC6'><br/></div><div class='line' id='LC7'><span class="nx">myCommand</span><span class="p">.</span><span class="nx">on</span><span class="p">(</span><span class="s2">&quot;success&quot;</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">response</span><span class="p">){</span></div><div class='line' id='LC8'>&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="nx">response</span><span class="p">.</span><span class="nx">someValueImChecking</span><span class="p">){</span></div><div class='line' id='LC9'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="c1">// move on to the next thing, here</span></div><div class='line' id='LC10'>&nbsp;&nbsp;<span class="p">}</span> <span class="k">else</span> <span class="p">{</span></div><div class='line' id='LC11'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="c1">// poll again, 1 second from now</span></div><div class='line' id='LC12'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">setTimeout</span><span class="p">(</span><span class="nx">executeCommand</span><span class="p">,</span> <span class="mi">1000</span><span class="p">);</span></div><div class='line' id='LC13'>&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC14'><span class="p">});</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2595175/250eb8e53bb735f28d4bdb29783bf0e26e4b6eb9/3.js" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2595175#file_3.js" style="float:right;margin-right:10px;color:#666">3.js</a>
            <a href="https://gist.github.com/2595175">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>There&#8217;s lot of fun little tricks you can do with a simple object wrapper like this, that would be a little more cumbersome and awkward when directly using $.ajax. </p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/LosTechies?a=UPAozqmEBc0:kvmkmxrJN9Q:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/LosTechies?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=UPAozqmEBc0:kvmkmxrJN9Q:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/LosTechies?i=UPAozqmEBc0:kvmkmxrJN9Q:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=UPAozqmEBc0:kvmkmxrJN9Q:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/LosTechies?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=UPAozqmEBc0:kvmkmxrJN9Q:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/LosTechies?i=UPAozqmEBc0:kvmkmxrJN9Q:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/LosTechies/~4/UPAozqmEBc0" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://lostechies.com/derickbailey/2012/05/04/wrapping-ajax-in-a-thin-command-framework-for-backbone-apps/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
            <media:content url="http://www.gravatar.com/avatar/e592bd1326b1e80188ed4c0bf26b9f75?s=96&amp;d=http%3A%2F%2Fwww.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
            <media:title type="html">Derick Bailey</media:title>
        </media:content>
    		<feedburner:origLink>http://lostechies.com/derickbailey/2012/05/04/wrapping-ajax-in-a-thin-command-framework-for-backbone-apps/</feedburner:origLink></item>
	<item>
		<title>Limits of performance optimization</title>
		<link>http://feedproxy.google.com/~r/LosTechies/~3/DHe5f5DKf-c/</link>
		<comments>http://lostechies.com/jimmybogard/2012/05/03/limits-of-performance-optimization/#comments</comments>
		<pubDate>Thu, 03 May 2012 13:31:26 +0000</pubDate>
		<dc:creator>Jimmy Bogard</dc:creator>
				<category><![CDATA[Architecture]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://lostechies.com/jimmybogard/2012/05/03/limits-of-performance-optimization/]]></guid>
		<description><![CDATA[Back in college, where I was an Electrical Engineering undergrad, I had an especially difficult professor for my microcontrollers course. In this course, we would hand-roll assembly language instructions and upload them to the 68HC12 testing board. (Side-note, I never,&#160;&#8230; <a href="http://lostechies.com/jimmybogard/2012/05/03/limits-of-performance-optimization/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p><img style="display: inline; float: right" alt="Datasheet Thumbnail" align="right" src="http://www.datasheetarchive.com/ThumbnailsIndexer/Scans-004/tnScans-0088808.jpg">Back in college, where I was an Electrical Engineering undergrad, I had an especially difficult professor for my microcontrollers course. In this course, we would hand-roll assembly language instructions and upload them to the <a href="http://en.wikipedia.org/wiki/Freescale_68HC12">68HC12</a> testing board. (Side-note, I never, EVER want to hand-roll assembly language again. Or hand-compile C code to assembly).</p>
<p>In microcontrollers, onboard memory is a huge limiting factor. Modern devices have lots of available memory, but for embedded devices, your ROM pretty much decides how complicated your program can be.</p>
<p>As part of the course, we were graded on how <em>compact</em> our code was, rather than merely how <em>correct</em> it was. And this makes sense, since compactness can allow for more features/decisions etc.</p>
<p>So we all made reasonable efforts to compact our code using common tricks like shift-operators for multiplication and so on. However, what we didn’t know is that our professor had spent 20-30 years optimizing assembly code for compactness, and our efforts were being graded against his. Any deviation from his solution was a deduction in our grade. </p>
<p>After receiving poor marks, and seeing why, we all as a class reviewed the (his) solution. And wouldn’t you know that while compact, <strong>code optimized to its maximum is nearly impossible to understand or maintain</strong>. No one in the class, viewing the code for the first time, would be able to decipher what it actually did.</p>
<h3>Long-term maintainability</h3>
<p>Since we change code far more often than we write code, optimizing solely for performance can make it difficult or impossible to change that code in the future. In the case of our college course, we were being held to standards that were nearly impossible to reach, let alone understand. <strong>Performance isn’t an accomplishment, it’s a feature</strong>.</p>
<p>It’s a feature that needs to be balanced against all other constraints, like the ability to maintain the code in the future. Highly optimized code often becomes more difficult to understand or comprehend, making it difficult to tweak or refactor in the future.</p>
<p>So when looking at performance optimization, which is many times a necessary endeavor, always keep an eye on the true goal of the performance optimization. How much more optimized does it need to be? What is the threshold for success?</p>
<p>Performance optimization without a clear definition of success just leads down the path of obfuscation and unmaintainability. Optimization does have an upper limit, not only in terms of gains, but of losses in maintainability.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/LosTechies?a=DHe5f5DKf-c:5u74fHGkk4s:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/LosTechies?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=DHe5f5DKf-c:5u74fHGkk4s:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/LosTechies?i=DHe5f5DKf-c:5u74fHGkk4s:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=DHe5f5DKf-c:5u74fHGkk4s:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/LosTechies?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=DHe5f5DKf-c:5u74fHGkk4s:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/LosTechies?i=DHe5f5DKf-c:5u74fHGkk4s:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/LosTechies/~4/DHe5f5DKf-c" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://lostechies.com/jimmybogard/2012/05/03/limits-of-performance-optimization/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
            <media:content url="http://www.gravatar.com/avatar/cc359c5ccf90d7a24b5976316797b5ec?s=96&amp;d=http%3A%2F%2Fwww.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
            <media:title type="html">Jimmy Bogard</media:title>
        </media:content>
    		<feedburner:origLink>http://lostechies.com/jimmybogard/2012/05/03/limits-of-performance-optimization/</feedburner:origLink></item>
	<item>
		<title>Persisting enumeration classes with NHibernate</title>
		<link>http://feedproxy.google.com/~r/LosTechies/~3/Ufvp50Ujoig/</link>
		<comments>http://lostechies.com/jimmybogard/2012/05/01/persisting-enumeration-classes-with-nhibernate/#comments</comments>
		<pubDate>Tue, 01 May 2012 13:31:40 +0000</pubDate>
		<dc:creator>Jimmy Bogard</dc:creator>
				<category><![CDATA[Domain-Driven Design]]></category>
		<category><![CDATA[NHibernate]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://lostechies.com/jimmybogard/2012/05/01/persisting-enumeration-classes-with-nhibernate/]]></guid>
		<description><![CDATA[As part of my “Crafting Wicked Domain Models” talk, I walk through the concept of enumeration classes, yanked from Java and on Jon Skeet’s list of biggest C# mistakes (or missing features). In my talk, I leave out how to&#160;&#8230; <a href="http://lostechies.com/jimmybogard/2012/05/01/persisting-enumeration-classes-with-nhibernate/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p>As part of my “<a href="http://youtu.be/GubLNJL47K8">Crafting Wicked Domain Models</a>” talk, I walk through the concept of <a href="http://lostechies.com/jimmybogard/2008/08/12/enumeration-classes/">enumeration classes</a>, yanked from Java and on Jon Skeet’s <a href="http://vimeo.com/17151234">list of biggest C# mistakes</a> (or missing features). In my talk, I leave out how to bridge the gap from your domain model to an ORM, simply because it’s just out of scope for that talk to address persistence concerns. Besides, the ORM I use these days to persist relational domain models (NHibernate) handles all the crazy cases an more, so I don’t feel like looking at anything else.</p>
<p>But what I leave out of a talk, I can certainly blog about! Suppose we have one of our enumeration classes (available <a href="http://nuget.org/packages/Enumeration">here on NuGet</a>):</p>
<div id="gist-2567716" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="k">public</span> <span class="k">class</span> <span class="nc">Color</span> <span class="p">:</span> <span class="n">Enumeration</span><span class="p">&lt;</span><span class="n">Color</span><span class="p">&gt;</span></div><div class='line' id='LC2'><span class="p">{</span></div><div class='line' id='LC3'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">private</span> <span class="nf">Color</span><span class="p">(</span><span class="kt">int</span> <span class="k">value</span><span class="p">,</span> <span class="kt">string</span> <span class="n">displayName</span><span class="p">)</span> </div><div class='line' id='LC4'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">:</span> <span class="k">base</span><span class="p">(</span><span class="k">value</span><span class="p">,</span> <span class="n">displayName</span><span class="p">)</span></div><div class='line' id='LC5'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">{</span></div><div class='line' id='LC6'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC7'><br/></div><div class='line' id='LC8'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">public</span> <span class="k">static</span> <span class="k">readonly</span> <span class="n">Color</span> <span class="n">Red</span> </div><div class='line' id='LC9'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">=</span> <span class="k">new</span> <span class="n">Color</span><span class="p">(</span><span class="m">1</span><span class="p">,</span> <span class="s">&quot;Red&quot;</span><span class="p">);</span></div><div class='line' id='LC10'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">public</span> <span class="k">static</span> <span class="k">readonly</span> <span class="n">Color</span> <span class="n">Blue</span> </div><div class='line' id='LC11'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">=</span> <span class="k">new</span> <span class="n">Color</span><span class="p">(</span><span class="m">2</span><span class="p">,</span> <span class="s">&quot;Blue&quot;</span><span class="p">);</span></div><div class='line' id='LC12'><span class="p">}</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2567716/c59d75ddfe5213eb62f74765e7df719424143d8e/Color.cs" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2567716#file_color.cs" style="float:right;margin-right:10px;color:#666">Color.cs</a>
            <a href="https://gist.github.com/2567716">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>When it comes time to persisting this enumeration class, we want to make sure that the database schema uses the integer value as what gets persisted. When it writes, we want the value to persist, and when it reads, we want the correct enumeration value (Red/Blue) to be hydrated.</p>
<p>To do this in NHibernate, we’ll first need a custom type:</p>
<div id="gist-2567876" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="k">public</span> <span class="k">class</span> <span class="nc">EnumerationType</span><span class="p">&lt;</span><span class="n">T</span><span class="p">&gt;</span> <span class="p">:</span> <span class="n">PrimitiveType</span> <span class="k">where</span> <span class="n">T</span> <span class="p">:</span> <span class="n">Enumeration</span><span class="p">&lt;</span><span class="n">T</span><span class="p">&gt;</span></div><div class='line' id='LC2'><span class="p">{</span></div><div class='line' id='LC3'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">public</span> <span class="nf">EnumerationType</span><span class="p">()</span></div><div class='line' id='LC4'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">:</span> <span class="k">base</span><span class="p">(</span><span class="k">new</span> <span class="n">SqlType</span><span class="p">(</span><span class="n">DbType</span><span class="p">.</span><span class="n">Int32</span><span class="p">))</span></div><div class='line' id='LC5'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">{</span></div><div class='line' id='LC6'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC7'><br/></div><div class='line' id='LC8'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">public</span> <span class="k">override</span> <span class="kt">object</span> <span class="nf">Get</span><span class="p">(</span><span class="n">IDataReader</span> <span class="n">rs</span><span class="p">,</span> <span class="kt">int</span> <span class="n">index</span><span class="p">)</span></div><div class='line' id='LC9'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">{</span></div><div class='line' id='LC10'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="kt">var</span> <span class="n">o</span> <span class="p">=</span> <span class="n">rs</span><span class="p">[</span><span class="n">index</span><span class="p">];</span></div><div class='line' id='LC11'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="kt">var</span> <span class="k">value</span> <span class="p">=</span> <span class="n">Convert</span><span class="p">.</span><span class="n">ToInt32</span><span class="p">(</span><span class="n">o</span><span class="p">);</span></div><div class='line' id='LC12'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">return</span> <span class="n">Enumeration</span><span class="p">&lt;</span><span class="n">T</span><span class="p">&gt;.</span><span class="n">FromInt32</span><span class="p">(</span><span class="k">value</span><span class="p">);</span></div><div class='line' id='LC13'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC14'><br/></div><div class='line' id='LC15'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">public</span> <span class="k">override</span> <span class="kt">object</span> <span class="nf">Get</span><span class="p">(</span><span class="n">IDataReader</span> <span class="n">rs</span><span class="p">,</span> <span class="kt">string</span> <span class="n">name</span><span class="p">)</span></div><div class='line' id='LC16'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">{</span></div><div class='line' id='LC17'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="kt">var</span> <span class="n">ordinal</span> <span class="p">=</span> <span class="n">rs</span><span class="p">.</span><span class="n">GetOrdinal</span><span class="p">(</span><span class="n">name</span><span class="p">);</span></div><div class='line' id='LC18'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">return</span> <span class="nf">Get</span><span class="p">(</span><span class="n">rs</span><span class="p">,</span> <span class="n">ordinal</span><span class="p">);</span></div><div class='line' id='LC19'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC20'><br/></div><div class='line' id='LC21'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">public</span> <span class="k">override</span> <span class="n">Type</span> <span class="n">ReturnedClass</span></div><div class='line' id='LC22'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">{</span></div><div class='line' id='LC23'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">get</span> <span class="p">{</span> <span class="k">return</span> <span class="k">typeof</span><span class="p">(</span><span class="n">T</span><span class="p">);</span> <span class="p">}</span></div><div class='line' id='LC24'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC25'><br/></div><div class='line' id='LC26'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">public</span> <span class="k">override</span> <span class="kt">object</span> <span class="nf">FromStringValue</span><span class="p">(</span><span class="kt">string</span> <span class="n">xml</span><span class="p">)</span></div><div class='line' id='LC27'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">{</span></div><div class='line' id='LC28'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">return</span> <span class="kt">int</span><span class="p">.</span><span class="n">Parse</span><span class="p">(</span><span class="n">xml</span><span class="p">);</span></div><div class='line' id='LC29'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC30'><br/></div><div class='line' id='LC31'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">public</span> <span class="k">override</span> <span class="kt">string</span> <span class="n">Name</span></div><div class='line' id='LC32'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">{</span></div><div class='line' id='LC33'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">get</span> <span class="p">{</span> <span class="k">return</span> <span class="s">&quot;enumeration&quot;</span><span class="p">;</span> <span class="p">}</span></div><div class='line' id='LC34'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC35'><br/></div><div class='line' id='LC36'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">public</span> <span class="k">override</span> <span class="k">void</span> <span class="nf">Set</span><span class="p">(</span><span class="n">IDbCommand</span> <span class="n">cmd</span><span class="p">,</span> <span class="kt">object</span> <span class="k">value</span><span class="p">,</span> <span class="kt">int</span> <span class="n">index</span><span class="p">)</span></div><div class='line' id='LC37'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">{</span></div><div class='line' id='LC38'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="kt">var</span> <span class="n">parameter</span> <span class="p">=</span> <span class="p">(</span><span class="n">IDataParameter</span><span class="p">)</span><span class="n">cmd</span><span class="p">.</span><span class="n">Parameters</span><span class="p">[</span><span class="n">index</span><span class="p">];</span></div><div class='line' id='LC39'><br/></div><div class='line' id='LC40'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="kt">var</span> <span class="n">val</span> <span class="p">=</span> <span class="p">(</span><span class="n">Enumeration</span><span class="p">&lt;</span><span class="n">T</span><span class="p">&gt;)</span><span class="k">value</span><span class="p">;</span></div><div class='line' id='LC41'><br/></div><div class='line' id='LC42'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">parameter</span><span class="p">.</span><span class="n">Value</span> <span class="p">=</span> <span class="n">val</span><span class="p">.</span><span class="n">Value</span><span class="p">;</span></div><div class='line' id='LC43'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC44'><br/></div><div class='line' id='LC45'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">public</span> <span class="k">override</span> <span class="kt">string</span> <span class="nf">ObjectToSQLString</span><span class="p">(</span><span class="kt">object</span> <span class="k">value</span><span class="p">,</span> <span class="n">Dialect</span> <span class="n">dialect</span><span class="p">)</span></div><div class='line' id='LC46'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">{</span></div><div class='line' id='LC47'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">return</span> <span class="k">value</span><span class="p">.</span><span class="n">ToString</span><span class="p">();</span></div><div class='line' id='LC48'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC49'><br/></div><div class='line' id='LC50'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">public</span> <span class="k">override</span> <span class="n">Type</span> <span class="n">PrimitiveClass</span></div><div class='line' id='LC51'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">{</span></div><div class='line' id='LC52'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">get</span> <span class="p">{</span> <span class="k">return</span> <span class="k">typeof</span><span class="p">(</span><span class="kt">int</span><span class="p">);</span> <span class="p">}</span></div><div class='line' id='LC53'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC54'><br/></div><div class='line' id='LC55'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">public</span> <span class="k">override</span> <span class="kt">object</span> <span class="n">DefaultValue</span></div><div class='line' id='LC56'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">{</span></div><div class='line' id='LC57'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">get</span> <span class="p">{</span> <span class="k">return</span> <span class="m">0</span><span class="p">;</span> <span class="p">}</span></div><div class='line' id='LC58'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC59'><span class="p">}</span></div><div class='line' id='LC60'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2567876/9984e19a10c66d54b1e88d4ce42b5a311fadd4e5/EnumerationType.cs" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2567876#file_enumeration_type.cs" style="float:right;margin-right:10px;color:#666">EnumerationType.cs</a>
            <a href="https://gist.github.com/2567876">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>This class is the bridge between our ORM (NHibernate) and our enumeration class. NHibernate is fantastic in its ability to provide easy ways to bridge to value objects. Value objects help avoid primitive obsession, but is only useful if you can actually use them when you’re mapping to your persistence layer.</p>
<p>To instruct NHibernate to use our custom types when reading/writing, the easiest way to do so is with a <a href="https://github.com/jagregory/fluent-nhibernate/wiki/Conventions">Fluent NHibernate convention</a>:</p>
<div id="gist-2567888" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="k">public</span> <span class="k">class</span> <span class="nc">EnumerationTypeConvention</span> <span class="p">:</span> <span class="n">IPropertyConvention</span><span class="p">,</span> <span class="n">IPropertyConventionAcceptance</span></div><div class='line' id='LC2'><span class="p">{</span></div><div class='line' id='LC3'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">private</span> <span class="k">static</span> <span class="k">readonly</span> <span class="n">Type</span> <span class="n">OpenType</span> <span class="p">=</span> <span class="k">typeof</span><span class="p">(</span><span class="n">EnumerationType</span><span class="p">&lt;&gt;);</span></div><div class='line' id='LC4'><br/></div><div class='line' id='LC5'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">public</span> <span class="k">void</span> <span class="nf">Apply</span><span class="p">(</span><span class="n">IPropertyInstance</span> <span class="n">instance</span><span class="p">)</span></div><div class='line' id='LC6'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">{</span></div><div class='line' id='LC7'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="kt">var</span> <span class="n">closedType</span> <span class="p">=</span> <span class="n">OpenType</span><span class="p">.</span><span class="n">MakeGenericType</span><span class="p">(</span><span class="n">instance</span><span class="p">.</span><span class="n">Property</span><span class="p">.</span><span class="n">PropertyType</span><span class="p">);</span></div><div class='line' id='LC8'><br/></div><div class='line' id='LC9'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">instance</span><span class="p">.</span><span class="n">CustomType</span><span class="p">(</span><span class="n">closedType</span><span class="p">);</span></div><div class='line' id='LC10'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC11'><br/></div><div class='line' id='LC12'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">public</span> <span class="k">void</span> <span class="nf">Accept</span><span class="p">(</span><span class="n">IAcceptanceCriteria</span><span class="p">&lt;</span><span class="n">IPropertyInspector</span><span class="p">&gt;</span> <span class="n">criteria</span><span class="p">)</span></div><div class='line' id='LC13'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">{</span></div><div class='line' id='LC14'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">criteria</span><span class="p">.</span><span class="n">Expect</span><span class="p">(</span><span class="n">x</span> <span class="p">=&gt;</span> <span class="n">IsEnumerationType</span><span class="p">(</span><span class="n">x</span><span class="p">.</span><span class="n">Property</span><span class="p">.</span><span class="n">PropertyType</span><span class="p">));</span></div><div class='line' id='LC15'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC16'><br/></div><div class='line' id='LC17'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">private</span> <span class="kt">bool</span> <span class="nf">IsEnumerationType</span><span class="p">(</span><span class="n">Type</span> <span class="n">type</span><span class="p">)</span></div><div class='line' id='LC18'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">{</span></div><div class='line' id='LC19'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">return</span> <span class="nf">GetTypeHierarchy</span><span class="p">(</span><span class="n">type</span><span class="p">)</span></div><div class='line' id='LC20'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">.</span><span class="n">Where</span><span class="p">(</span><span class="n">t</span> <span class="p">=&gt;</span> <span class="n">t</span><span class="p">.</span><span class="n">IsGenericType</span><span class="p">)</span></div><div class='line' id='LC21'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">.</span><span class="n">Select</span><span class="p">(</span><span class="n">t</span> <span class="p">=&gt;</span> <span class="n">t</span><span class="p">.</span><span class="n">GetGenericTypeDefinition</span><span class="p">())</span></div><div class='line' id='LC22'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">.</span><span class="n">Any</span><span class="p">(</span><span class="n">t</span> <span class="p">=&gt;</span> <span class="n">t</span> <span class="p">==</span> <span class="k">typeof</span><span class="p">(</span><span class="n">Enumeration</span><span class="p">&lt;&gt;));</span></div><div class='line' id='LC23'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC24'><br/></div><div class='line' id='LC25'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">private</span> <span class="n">IEnumerable</span><span class="p">&lt;</span><span class="n">Type</span><span class="p">&gt;</span> <span class="n">GetTypeHierarchy</span><span class="p">(</span><span class="n">Type</span> <span class="n">type</span><span class="p">)</span></div><div class='line' id='LC26'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">{</span></div><div class='line' id='LC27'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">while</span> <span class="p">(</span><span class="n">type</span> <span class="p">!=</span> <span class="k">null</span><span class="p">)</span></div><div class='line' id='LC28'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">{</span></div><div class='line' id='LC29'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">yield</span> <span class="k">return</span> <span class="n">type</span><span class="p">;</span></div><div class='line' id='LC30'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">type</span> <span class="p">=</span> <span class="n">type</span><span class="p">.</span><span class="n">BaseType</span><span class="p">;</span></div><div class='line' id='LC31'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC32'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC33'><span class="p">}</span></div><div class='line' id='LC34'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2567888/7cff98c6f676a86c49ee09c694444bb9ee44cd8c/EnumerationTypeConvention.cs" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2567888#file_enumeration_type_convention.cs" style="float:right;margin-right:10px;color:#666">EnumerationTypeConvention.cs</a>
            <a href="https://gist.github.com/2567888">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>This convention walks the type hierarchy for each property type given, and checks to see if the property type’s type hierarchy is a generic type that closes the open generic type of our enumeration class. Finally, we just need to hook our convention up to <a href="http://www.fluentnhibernate.org/">Fluent NHibernate</a>, but that really depends on how we have Fluent NHibernate hooked up. We don’t have to use Fluent NHibernate to hook up our custom user type, but it’s <em>much</em> easier this way.</p>
<p>With NHibernate, we get the benefits of using Java-style enumeration classes, and have it seamlessly plug in to our persistence layer, which is the whole point of ORMs, right?</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/LosTechies?a=Ufvp50Ujoig:Ygqm1Uwn_no:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/LosTechies?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=Ufvp50Ujoig:Ygqm1Uwn_no:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/LosTechies?i=Ufvp50Ujoig:Ygqm1Uwn_no:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=Ufvp50Ujoig:Ygqm1Uwn_no:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/LosTechies?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=Ufvp50Ujoig:Ygqm1Uwn_no:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/LosTechies?i=Ufvp50Ujoig:Ygqm1Uwn_no:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/LosTechies/~4/Ufvp50Ujoig" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://lostechies.com/jimmybogard/2012/05/01/persisting-enumeration-classes-with-nhibernate/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
            <media:content url="http://www.gravatar.com/avatar/cc359c5ccf90d7a24b5976316797b5ec?s=96&amp;d=http%3A%2F%2Fwww.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
            <media:title type="html">Jimmy Bogard</media:title>
        </media:content>
    		<feedburner:origLink>http://lostechies.com/jimmybogard/2012/05/01/persisting-enumeration-classes-with-nhibernate/</feedburner:origLink></item>
	<item>
		<title>Huboard – New feature overview</title>
		<link>http://feedproxy.google.com/~r/LosTechies/~3/0LJoiPeLPjw/</link>
		<comments>http://lostechies.com/ryanrauh/2012/04/28/huboard-new-feature-overview/#comments</comments>
		<pubDate>Sat, 28 Apr 2012 17:14:52 +0000</pubDate>
		<dc:creator>Ryan Rauh</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[huboard]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://lostechies.com/ryanrauh/?p=152]]></guid>
		<description><![CDATA[Huboard! I&#8217;ve been working one a few new features in my side project huboard and they are pretty awesome. Since the start I&#8217;ve always prioritized features by what adds the most value to github issues. That means features github already&#160;&#8230; <a href="http://lostechies.com/ryanrauh/2012/04/28/huboard-new-feature-overview/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<h1> Huboard! </h1>
<p>I&#8217;ve been working one a few new features in my side project <a href="http://huboard.com">huboard</a><br />
and they are pretty awesome. </p>
<p>Since the start I&#8217;ve always prioritized features by what  <strong>adds</strong> the most value to github issues. That means features github already provides are much lower in priority, which is why you still can&#8217;t add issues from huboard. Eventually I will add it, but github already provides that functionality or you could use other tools <code>gem install ghi</code>. Even more importantly huboard is <a href="https://github.com/rauhryan/huboard">open source</a>, I would love it if someone would fork it and add those features.</p>
<p>So what&#8217;s new in huboard that github doesn&#8217;t provide?</p>
<h3> Milestone ordering </h3>
<p>Huboard provides the ability to prioritize your milestones using a more macro oriented manager pants view. </p>
<p><img style="max-width: 100%;"  src="http://f.cl.ly/items/3k0S3A1v1B3q3o1F0e0n/milestones.jpg" alt="milestone ordering" /></p>
<p>From here you can happily drag your milestones into the desired order</p>
<p><img style="max-width: 100%;" src="http://f.cl.ly/items/0y2T3N3E0X1r1I441W1M/huboard____Huboard-20120428-113911.jpg" alt="view milestones" /></p>
<h3> Issue ordering </h3>
<p>Huboard provides the same ordering ability for issues.</p>
<p><img style="max-width: 100%;"  src="http://f.cl.ly/items/2y1G05131U2z2w190H21/milestones2.jpg" alt="view issues" /></p>
<p>Notice how issue #23 is between #31 and #35 </p>
<p><img style="max-width: 100%;"  src="http://f.cl.ly/items/1t251q163V2U383Z183u/huboard____Huboard-20120428-114706.jpg" alt="issue order" /></p>
<h3> Aggregate issues from multiple repositories </h3>
<p>Huboard can now aggregate issues from multiple repositories into one singular overview of all your repositories</p>
<p>Simple as adding a label to your repo name <code> Link &lt;=&gt; rauhryan/ghee </code></p>
<p><img style="max-width: 100%;" src="http://f.cl.ly/items/3B0G3w0c3G1s320y2y13/Issues_%C2%B7_rauhryan_huboard-20120428-115302.jpg" alt="link label" /></p>
<p>Huboard shows issues from both repositories! </p>
<p><img style="max-width: 100%;" src="http://f.cl.ly/items/0t450v2n2G3U363i2H1I/huboard____Huboard-20120428-115439.jpg" alt="other repo" /></p>
<p>Github issues just got a little more awesome!</p>
<p>-Ryan</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/LosTechies?a=0LJoiPeLPjw:jVyGH6MzYm8:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/LosTechies?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=0LJoiPeLPjw:jVyGH6MzYm8:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/LosTechies?i=0LJoiPeLPjw:jVyGH6MzYm8:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=0LJoiPeLPjw:jVyGH6MzYm8:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/LosTechies?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=0LJoiPeLPjw:jVyGH6MzYm8:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/LosTechies?i=0LJoiPeLPjw:jVyGH6MzYm8:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/LosTechies/~4/0LJoiPeLPjw" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://lostechies.com/ryanrauh/2012/04/28/huboard-new-feature-overview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
            <media:content url="http://www.gravatar.com/avatar/29283ede6c447fdc62f0ceac42df33ea?s=96&amp;d=http%3A%2F%2Fwww.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
            <media:title type="html">Ryan Rauh</media:title>
        </media:content>
    		<feedburner:origLink>http://lostechies.com/ryanrauh/2012/04/28/huboard-new-feature-overview/</feedburner:origLink></item>
	<item>
		<title>View Helpers For Underscore Templates</title>
		<link>http://feedproxy.google.com/~r/LosTechies/~3/yOsRcUZLXoQ/</link>
		<comments>http://lostechies.com/derickbailey/2012/04/26/view-helpers-for-underscore-templates/#comments</comments>
		<pubDate>Thu, 26 Apr 2012 12:50:55 +0000</pubDate>
		<dc:creator>Derick Bailey</dc:creator>
				<category><![CDATA[Backbone]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Marionette]]></category>
		<category><![CDATA[Underscore]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://lostechies.com/derickbailey/?p=912]]></guid>
		<description><![CDATA[Underscore&#8217;s template engine lets you run any arbitrary JavaScript code that you want, within a template. You could write an entire JavaScript application within an underscore template if you want. But this is a really bad idea. Templates should be&#160;&#8230; <a href="http://lostechies.com/derickbailey/2012/04/26/view-helpers-for-underscore-templates/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p>Underscore&#8217;s template engine lets you run any arbitrary JavaScript code that you want, within a template. You could write an entire JavaScript application within an underscore template if you want. But this is a really bad idea. Templates should be clean and simple. Some people go so far as to say &#8220;logic-less templates&#8221;, but I honestly don&#8217;t think that&#8217;s reasonable. I also don&#8217;t think it&#8217;s reasonable or responsible to have a bunch of JavaScript code littered throughout the template, though. </p>
<p>Fortunately, it&#8217;s easy to build helper methods for <a href="http://underscorejs.org/">Underscore</a> <a href="http://underscorejs.org/#template">templates</a> (and they end up looking a lot like Rails view helpers).</p>
<h2>Logic In Templates: A Bad Idea</h2>
<p>On a client project recently, I had a JavaScript object that needed to be bound to my template. The object looked somewhat like this:</p>
<div id="gist-2489539" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="kd">var</span> <span class="nx">data</span> <span class="o">=</span> <span class="p">{</span></div><div class='line' id='LC2'>&nbsp;&nbsp;<span class="nx">type</span><span class="o">:</span> <span class="s2">&quot;something&quot;</span><span class="p">,</span></div><div class='line' id='LC3'>&nbsp;&nbsp;<span class="nx">name</span><span class="o">:</span> <span class="s2">&quot;whatever&quot;</span><span class="p">,</span></div><div class='line' id='LC4'>&nbsp;&nbsp;<span class="nx">addresses</span><span class="o">:</span> <span class="p">[</span></div><div class='line' id='LC5'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">{</span></div><div class='line' id='LC6'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">type</span><span class="o">:</span> <span class="s2">&quot;read_address&quot;</span><span class="p">,</span></div><div class='line' id='LC7'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">address</span><span class="o">:</span> <span class="s2">&quot;1/2/3&quot;</span><span class="p">,</span></div><div class='line' id='LC8'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">value</span><span class="o">:</span> <span class="s2">&quot;10&quot;</span></div><div class='line' id='LC9'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">},</span></div><div class='line' id='LC10'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">{</span></div><div class='line' id='LC11'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">type</span><span class="o">:</span> <span class="s2">&quot;write_address&quot;</span><span class="p">,</span></div><div class='line' id='LC12'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">address</span><span class="o">:</span> <span class="s2">&quot;1/2/4&quot;</span></div><div class='line' id='LC13'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC14'>&nbsp;&nbsp;<span class="p">]</span></div><div class='line' id='LC15'><span class="p">}</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2489539/823372e2c9d41e266e7ebad70d6702a76b32105c/1.js" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2489539#file_1.js" style="float:right;margin-right:10px;color:#666">1.js</a>
            <a href="https://gist.github.com/2489539">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>I needed to take all of the &#8220;addresses&#8221; and find each specific address within the array, by name, so that I could get the right information in place at the right time in my template.</p>
<p>The first pass of code that I wrote to do this, looked like this:</p>
<div id="gist-2489539" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="nt">&lt;script </span><span class="na">id=</span><span class="s">&quot;my-template&quot;</span> <span class="na">type=</span><span class="s">&quot;text/template&quot;</span><span class="nt">&gt;</span></div><div class='line' id='LC2'>&nbsp;&nbsp;<span class="o">&lt;</span><span class="nx">p</span><span class="o">&gt;</span><span class="nx">type</span><span class="o">:</span> <span class="o">&lt;%=</span> <span class="nx">type</span> <span class="o">%&gt;&lt;</span><span class="err">/p&gt;</span></div><div class='line' id='LC3'>&nbsp;&nbsp;<span class="o">&lt;</span><span class="nx">p</span><span class="o">&gt;</span><span class="nx">name</span><span class="o">:</span> <span class="o">&lt;%=</span> <span class="nx">name</span> <span class="o">%&gt;&lt;</span><span class="err">/p&gt;</span></div><div class='line' id='LC4'>&nbsp;&nbsp;<span class="o">&lt;</span><span class="nx">p</span><span class="o">&gt;</span><span class="nx">read</span> <span class="nx">address</span><span class="o">:</span> <span class="o">&lt;%=</span> <span class="nx">_</span><span class="p">.</span><span class="nx">find</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">addresses</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">addr</span><span class="p">){</span> <span class="k">return</span> <span class="nx">addr</span><span class="p">.</span><span class="nx">type</span> <span class="o">==</span> <span class="s2">&quot;read_address&quot;</span> <span class="p">}).</span><span class="nx">address</span> <span class="o">%&gt;</span> <span class="o">&lt;</span><span class="err">/p&gt;</span></div><div class='line' id='LC5'>&nbsp;&nbsp;<span class="o">&lt;</span><span class="nx">p</span><span class="o">&gt;</span><span class="nx">read</span> <span class="nx">address</span> <span class="nx">value</span><span class="o">:</span> <span class="o">&lt;%=</span> <span class="nx">_</span><span class="p">.</span><span class="nx">find</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">addresses</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">addr</span><span class="p">){</span> <span class="k">return</span> <span class="nx">addr</span><span class="p">.</span><span class="nx">type</span> <span class="o">==</span> <span class="s2">&quot;read_address&quot;</span> <span class="p">}).</span><span class="nx">value</span> <span class="o">%&gt;</span> <span class="o">&lt;</span><span class="err">/p&gt;</span></div><div class='line' id='LC6'>&nbsp;&nbsp;<span class="o">&lt;</span><span class="nx">p</span><span class="o">&gt;</span><span class="nx">write</span> <span class="nx">address</span><span class="o">:</span> <span class="o">&lt;%=</span> <span class="nx">_</span><span class="p">.</span><span class="nx">find</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">addresses</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">addr</span><span class="p">){</span> <span class="k">return</span> <span class="nx">addr</span><span class="p">.</span><span class="nx">type</span> <span class="o">==</span> <span class="s2">&quot;write_address&quot;</span> <span class="p">}).</span><span class="nx">address</span> <span class="o">%&gt;</span> <span class="o">&lt;</span><span class="err">/p&gt;</span></div><div class='line' id='LC7'><span class="nt">&lt;/script&gt;</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2489539/104d2318482c3e97c54a65d54bb246dbad26c244/2.html" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2489539#file_2.html" style="float:right;margin-right:10px;color:#666">2.html</a>
            <a href="https://gist.github.com/2489539">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>And this worked, but it&#8217;s a bad idea. I have a lot of duplication in this template and I have a lot of logic and processing of data in the template, too. This is going to make for a very painful setup when it comes to maintenance &#8211; especially if / when I have to change how the address is looked up.</p>
<h2>View Helper Methods: A Better Idea</h2>
<p>In asking around on twitter for some suggestions on how to clean this up, I received several responses. Out of everything that everyone said, though, I liked the response I got from <a href="https://twitter.com/#!/davetheninja">DaveTheNinja</a> because of it&#8217;s simplicity.</p>
<p>The basic idea is to recognize that the data I send to my template is a JavaScript object. Since this is an object, it can have methods. If I can have methods on my object, why not put methods on it as view helper methods?</p>
<div id="gist-2489539" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="kd">var</span> <span class="nx">viewHelpers</span> <span class="o">=</span> <span class="p">{</span></div><div class='line' id='LC2'>&nbsp;&nbsp;<span class="nx">getAddress</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">type</span><span class="p">){</span></div><div class='line' id='LC3'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">address</span> <span class="o">=</span> <span class="nx">_</span><span class="p">.</span><span class="nx">find</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">addresses</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">addr</span><span class="p">)</span> <span class="p">{</span> </div><div class='line' id='LC4'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">return</span> <span class="nx">addr</span><span class="p">.</span><span class="nx">type</span> <span class="o">==</span> <span class="nx">type</span> </div><div class='line' id='LC5'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">});</span></div><div class='line' id='LC6'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">return</span> <span class="nx">address</span><span class="p">;</span></div><div class='line' id='LC7'>&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC8'><span class="p">}</span></div><div class='line' id='LC9'><br/></div><div class='line' id='LC10'><br/></div><div class='line' id='LC11'><span class="nx">_</span><span class="p">.</span><span class="nx">extend</span><span class="p">(</span><span class="nx">data</span><span class="p">,</span> <span class="nx">viewHelpers</span><span class="p">);</span></div><div class='line' id='LC12'><br/></div><div class='line' id='LC13'><span class="nx">_</span><span class="p">.</span><span class="nx">template</span><span class="p">(</span><span class="nx">myTemplate</span><span class="p">,</span> <span class="nx">data</span><span class="p">);</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2489539/97faf89850a31e2121be7c599300f48b6de4769c/3.js" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2489539#file_3.js" style="float:right;margin-right:10px;color:#666">3.js</a>
            <a href="https://gist.github.com/2489539">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>The helper method &#8211; &#8220;getAddress&#8221; &#8211; is pretty much the same code. But now it&#8217;s consolidated in to a single location and I&#8217;m able to give better formatting for it which makes it easier to read and understand.</p>
<p>You can also see that I&#8217;ve kept the data separate from the objects until just before rendering the template. I&#8217;m using Underscore&#8217;s &#8220;extend&#8221; method to copy all of the methods from my &#8220;viewHelpers&#8221; object on to my data object.</p>
<p>Then when I pass the data object to my template, I can call my &#8220;getAddress&#8221; method like this:</p>
<div id="gist-2489539" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="nt">&lt;script </span><span class="na">id=</span><span class="s">&quot;my-template&quot;</span> <span class="na">type=</span><span class="s">&quot;text/template&quot;</span><span class="nt">&gt;</span></div><div class='line' id='LC2'>&nbsp;&nbsp;<span class="o">&lt;</span><span class="nx">p</span><span class="o">&gt;</span><span class="nx">type</span><span class="o">:</span> <span class="o">&lt;%=</span> <span class="nx">type</span> <span class="o">%&gt;&lt;</span><span class="err">/p&gt;</span></div><div class='line' id='LC3'>&nbsp;&nbsp;<span class="o">&lt;</span><span class="nx">p</span><span class="o">&gt;</span><span class="nx">name</span><span class="o">:</span> <span class="o">&lt;%=</span> <span class="nx">name</span> <span class="o">%&gt;&lt;</span><span class="err">/p&gt;</span></div><div class='line' id='LC4'>&nbsp;&nbsp;<span class="o">&lt;</span><span class="nx">p</span><span class="o">&gt;</span><span class="nx">read</span> <span class="nx">address</span><span class="o">:</span> <span class="o">&lt;%=</span> <span class="nx">getAddress</span><span class="p">(</span><span class="s2">&quot;read_address&quot;</span><span class="p">).</span><span class="nx">address</span> <span class="o">%&gt;</span> <span class="o">&lt;</span><span class="err">/p&gt;</span></div><div class='line' id='LC5'>&nbsp;&nbsp;<span class="o">&lt;</span><span class="nx">p</span><span class="o">&gt;</span><span class="nx">read</span> <span class="nx">address</span> <span class="nx">value</span><span class="o">:</span> <span class="o">&lt;%=</span> <span class="nx">getAddress</span><span class="p">(</span><span class="s2">&quot;read_address&quot;</span><span class="p">).</span><span class="nx">value</span> <span class="o">%&gt;</span> <span class="o">&lt;</span><span class="err">/p&gt;</span></div><div class='line' id='LC6'>&nbsp;&nbsp;<span class="o">&lt;</span><span class="nx">p</span><span class="o">&gt;</span><span class="nx">write</span> <span class="nx">address</span><span class="o">:</span> <span class="o">&lt;%=</span> <span class="nx">getAddress</span><span class="p">(</span><span class="s2">&quot;write_address&quot;</span><span class="p">).</span><span class="nx">address</span> <span class="o">%&gt;</span> <span class="o">&lt;</span><span class="err">/p&gt;</span></div><div class='line' id='LC7'><span class="nt">&lt;/script&gt;</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2489539/914c36323f283fb035a8f4b02a393c84c7610a07/4.html" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2489539#file_4.html" style="float:right;margin-right:10px;color:#666">4.html</a>
            <a href="https://gist.github.com/2489539">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>And we&#8217;re done! I now have view helper methods that I can call from within my templates.</p>
<h2>Using This With Backbone</h2>
<p>I use this technique with Backbone a lot. The code that I showed above is really no different than what I do with my Backbone views, either. When you get to the point where you need to render your template, just extend the view helper methods on to your data before doing the actual rendering:</p>
<div id="gist-2489539" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="nx">Backbone</span><span class="p">.</span><span class="nx">View</span><span class="p">.</span><span class="nx">extend</span><span class="p">({</span></div><div class='line' id='LC2'>&nbsp;&nbsp;<span class="nx">template</span><span class="o">:</span> <span class="s2">&quot;#my-template&quot;</span><span class="p">,</span></div><div class='line' id='LC3'><br/></div><div class='line' id='LC4'>&nbsp;&nbsp;<span class="nx">render</span><span class="o">:</span> <span class="kd">function</span><span class="p">(){</span></div><div class='line' id='LC5'><br/></div><div class='line' id='LC6'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">data</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">model</span><span class="p">.</span><span class="nx">toJSON</span><span class="p">();</span></div><div class='line' id='LC7'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">_</span><span class="p">.</span><span class="nx">extend</span><span class="p">(</span><span class="nx">data</span><span class="p">,</span> <span class="nx">viewHelpers</span><span class="p">);</span></div><div class='line' id='LC8'><br/></div><div class='line' id='LC9'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">html</span> <span class="o">=</span> <span class="nx">_</span><span class="p">.</span><span class="nx">template</span><span class="p">(</span><span class="nx">$</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">template</span><span class="p">),</span> <span class="nx">data</span><span class="p">);</span></div><div class='line' id='LC10'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">$el</span><span class="p">.</span><span class="nx">html</span><span class="p">(</span><span class="nx">html</span><span class="p">);</span></div><div class='line' id='LC11'><br/></div><div class='line' id='LC12'>&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC13'><span class="p">});</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2489539/977a299ae934ccceee2c294fb1dbdab7cbb59d07/5.js" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2489539#file_5.js" style="float:right;margin-right:10px;color:#666">5.js</a>
            <a href="https://gist.github.com/2489539">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<h2>Using This With Backbone.Marionette</h2>
<p>I&#8217;ve added this functionality in to <a href="https://github.com/derickbailey/backbone.marionette">Backbone.Marionette</a> as well. ItemView, CompositeView and Layout will all look for a `templateHelpers` attribute on a view definition. If it finds it, it will mix that object in to the data that is used to render the template: </p>
<div id="gist-2489539" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="nx">Backbone</span><span class="p">.</span><span class="nx">Marionette</span><span class="p">.</span><span class="nx">ItemView</span><span class="p">.</span><span class="nx">extend</span><span class="p">({</span></div><div class='line' id='LC2'><br/></div><div class='line' id='LC3'>&nbsp;&nbsp;<span class="nx">template</span><span class="o">:</span> <span class="s2">&quot;#my-template&quot;</span><span class="p">,</span></div><div class='line' id='LC4'>&nbsp;&nbsp;<span class="nx">templateHelpers</span><span class="o">:</span> <span class="nx">viewHelpers</span></div><div class='line' id='LC5'><br/></div><div class='line' id='LC6'><span class="p">});</span></div><div class='line' id='LC7'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2489539/063472cc4e2c389eaa52a929aed8302fbf0b14f8/6.js" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2489539#file_6.js" style="float:right;margin-right:10px;color:#666">6.js</a>
            <a href="https://gist.github.com/2489539">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>You can specify a reference to the viewHelpers object as shown in this example, provide an object literal as the templateHelpers directly, or specify a function that returns an object with the helper methods that you want. For more information see <a href="http://derickbailey.github.com/backbone.marionette/#marionette-view/view-templatehelpers">the documentation for Marionette</a>.</p>
<h2>Other Template Engines</h2>
<p>This basic technique will probably work with other template engines, too. Some engines like Handlebars, though, have this idea baked in to them directly. But if you&#8217;re using Underscore&#8217;s templates, then this is a good way to keep your templates clean while still providing the logic you need.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/LosTechies?a=yOsRcUZLXoQ:MNdDMzUY23Y:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/LosTechies?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=yOsRcUZLXoQ:MNdDMzUY23Y:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/LosTechies?i=yOsRcUZLXoQ:MNdDMzUY23Y:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=yOsRcUZLXoQ:MNdDMzUY23Y:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/LosTechies?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=yOsRcUZLXoQ:MNdDMzUY23Y:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/LosTechies?i=yOsRcUZLXoQ:MNdDMzUY23Y:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/LosTechies/~4/yOsRcUZLXoQ" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://lostechies.com/derickbailey/2012/04/26/view-helpers-for-underscore-templates/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
            <media:content url="http://www.gravatar.com/avatar/e592bd1326b1e80188ed4c0bf26b9f75?s=96&amp;d=http%3A%2F%2Fwww.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
            <media:title type="html">Derick Bailey</media:title>
        </media:content>
    		<feedburner:origLink>http://lostechies.com/derickbailey/2012/04/26/view-helpers-for-underscore-templates/</feedburner:origLink></item>
	<item>
		<title>Executing A Project-Specific Node/NPM Package A-la “bundle exec”</title>
		<link>http://feedproxy.google.com/~r/LosTechies/~3/WDkZFSzj9aE/</link>
		<comments>http://lostechies.com/derickbailey/2012/04/24/executing-a-project-specific-nodenpm-package-a-la-bundle-exec/#comments</comments>
		<pubDate>Tue, 24 Apr 2012 12:52:13 +0000</pubDate>
		<dc:creator>Derick Bailey</dc:creator>
				<category><![CDATA[Command Line]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[NodeJS]]></category>
		<category><![CDATA[NPM]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://lostechies.com/derickbailey/?p=906]]></guid>
		<description><![CDATA[It&#8217;s no secret that I love NodeJS, though I really haven&#8217;t blogged about it much (if at all). Frankly, I think Node and NPM are going to be eating Ruby, RubyGems and Bundler&#8217;s $25,000 lunch &#8211; at least on OSX.&#160;&#8230; <a href="http://lostechies.com/derickbailey/2012/04/24/executing-a-project-specific-nodenpm-package-a-la-bundle-exec/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p>It&#8217;s no secret that I love NodeJS, though I really haven&#8217;t blogged about it much (if at all). Frankly, I think Node and NPM are going to be eating Ruby, RubyGems and Bundler&#8217;s $25,000 lunch &#8211; at least on OSX. But there&#8217;s at least one piece of bundler that I miss from NPM: the ability to say &#8216;bundle exec&#8217; and have it run a specific gem&#8217;s bin file (binary / executable) for the current project gem configuration and version.</p>
<p>If I run &#8220;npm install express&#8221; from within a folder, the &#8220;express&#8221; package will be installed in to my ./node_modules folder.</p>
<p><img title="Screen Shot 2012-04-17 at 6.28.41 PM.png" src="http://lostechies.com/derickbailey/files/2012/04/Screen-Shot-2012-04-17-at-6.28.41-PM.png" alt="Screen Shot 2012 04 17 at 6 28 41 PM" width="600" height="222" border="0" /></p>
<p>But I can&#8217;t say &#8220;express foo&#8221; on the command line at this point, to run express. And I can&#8217;t say &#8220;npm express foo&#8221; or &#8220;npm exec express foo&#8221; or anything like that. This ability is sadly missing from NPM. There are a few ways to get around this, though.</p>
<h2>Global Modules</h2>
<p>When you install a Node module with the `-g` option, it installs in to the global module list. Global modules can have their bin files run from the command line just like any other command. So if you install the &#8220;express&#8221; module, for example, with the global flag then you&#8217;ll be able to say &#8220;express foo&#8221; from the command line and watch it build a fresh new project for you in the &#8220;foo&#8221; folder.</p>
<p><img title="Screen Shot 2012-04-17 at 6.30.23 PM.png" src="http://lostechies.com/derickbailey/files/2012/04/Screen-Shot-2012-04-17-at-6.30.23-PM.png" alt="Screen Shot 2012 04 17 at 6 30 23 PM" width="456" height="600" border="0" /></p>
<p>This is nice for packages that you want to have available for any application you&#8217;re building. I use global packages a lot because some of the tools that you can find in node packages are quite useful, even outside the context of a node project. But not every package should be installed in the global package repository for your computer.</p>
<h2>Run Bin From Relative Path</h2>
<p>You can also run bin files from node modules by using the relative path of ./node_modules/.bin/ to find the command.</p>
<p><img title="Screen Shot 2012-04-17 at 6.32.44 PM.png" src="http://lostechies.com/derickbailey/files/2012/04/Screen-Shot-2012-04-17-at-6.32.44-PM.png" alt="Screen Shot 2012 04 17 at 6 32 44 PM" width="442" height="125" border="0" /></p>
<p>This is a bit tedious, though it is functional. I&#8217;ve build a few simple command / shell scripts to execute some of my installed modules this way, for some of my projects. That makes it a bit easier overall, but you have to set up a shell script for each package you want.</p>
<h2>Run Bin From Generic Shell Script</h2>
<p>Since all of the bin files for all of the node packages are installed in to ./node_modules/.bin/ for a given project, why not build a generic &#8220;npm_exec&#8221; shell script and just forward all the parameters?</p>
<p>Easy enough:</p>
<div id="gist-2409904" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'>./node_modules/.bin/<span class="nv">$@</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2409904/10d0fa0fece1b941cc24bb4e98a2cc014c9dbd8d/npm_exec.sh" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2409904#file_npm_exec.sh" style="float:right;margin-right:10px;color:#666">npm_exec.sh</a>
            <a href="https://gist.github.com/2409904">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>Just &#8220;chmod +x npm_exec&#8221; to make this file executable, and away we go.</p>
<p>Now I can run any arbitrary package binary I want. I could even put this little shell script in my /usr/local/bin folder and it would be available for all of my node projects, anywhere on my box.</p>
<p><img title="Screen Shot 2012-04-17 at 6.35.03 PM.png" src="http://lostechies.com/derickbailey/files/2012/04/Screen-Shot-2012-04-17-at-6.35.03-PM.png" alt="Screen Shot 2012 04 17 at 6 35 03 PM" width="332" height="124" border="0" /></p>
<p>This is a nice little solution, even if it&#8217;s a work around for something that should be built in to npm.</p>
<h2>NPM Scripts In package.json</h2>
<p>This last option is one that I&#8217;m using more and more often for project specific, recurring needs.</p>
<p>When you create an express app, it builds a package.json file for you. One of the pieces that it sticks in there is the &#8220;scripts&#8221; setting which contains a &#8220;start&#8221; setting, by default.</p>
<div id="gist-2409904" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="p">{</span></div><div class='line' id='LC2'>&nbsp;&nbsp;<span class="nt">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;application-name&quot;</span><span class="p">,</span></div><div class='line' id='LC3'>&nbsp;&nbsp;<span class="nt">&quot;version&quot;</span><span class="p">:</span> <span class="s2">&quot;0.0.1&quot;</span><span class="p">,</span></div><div class='line' id='LC4'>&nbsp;&nbsp;<span class="nt">&quot;private&quot;</span><span class="p">:</span> <span class="kc">true</span><span class="p">,</span></div><div class='line' id='LC5'>&nbsp;&nbsp;<span class="nt">&quot;scripts&quot;</span><span class="p">:</span> <span class="p">{</span></div><div class='line' id='LC6'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&quot;start&quot;</span><span class="p">:</span> <span class="s2">&quot;start app&quot;</span></div><div class='line' id='LC7'>&nbsp;&nbsp;<span class="p">},</span></div><div class='line' id='LC8'>&nbsp;&nbsp;<span class="nt">&quot;dependencies&quot;</span><span class="p">:</span> <span class="p">{</span></div><div class='line' id='LC9'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&quot;express&quot;</span><span class="p">:</span> <span class="s2">&quot;3.0.0alpha1&quot;</span><span class="p">,</span></div><div class='line' id='LC10'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&quot;jade&quot;</span><span class="p">:</span> <span class="s2">&quot;*&quot;</span></div><div class='line' id='LC11'>&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC12'><span class="p">}</span></div><div class='line' id='LC13'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2409904/0b91aca167f7265fa87142819a3a8c133b216be1/package.json" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2409904#file_package.json" style="float:right;margin-right:10px;color:#666">package.json</a>
            <a href="https://gist.github.com/2409904">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>It turns out you can use these &#8220;scripts&#8221; from the npm command line. When you call &#8220;npm start&#8221;, npm will execute the &#8220;scripts&#8221;/&#8221;start&#8221; configuration for you. By default, this is just a call to &#8220;node app&#8221; which runs the app.js file in node and gets your express.js app up and running.</p>
<p>You can do more with &#8220;scripts&#8221;, too. You can add your own named script, in fact.</p>
<div id="gist-2409904" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="p">{</span></div><div class='line' id='LC2'>&nbsp;&nbsp;<span class="err">...</span></div><div class='line' id='LC3'><br/></div><div class='line' id='LC4'>&nbsp;&nbsp;<span class="nt">&quot;scripts&quot;</span><span class="p">:</span> <span class="p">{</span></div><div class='line' id='LC5'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&quot;start&quot;</span><span class="p">:</span> <span class="s2">&quot;node app&quot;</span><span class="p">,</span></div><div class='line' id='LC6'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&quot;foo&quot;</span><span class="p">:</span> <span class="s2">&quot;node -e &#39;console.log(1+2)&#39;&quot;</span></div><div class='line' id='LC7'>&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC8'><br/></div><div class='line' id='LC9'>&nbsp;&nbsp;<span class="err">...</span></div><div class='line' id='LC10'><span class="p">}</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2409904/466d0c3f0f63050a961e39f2077fd1322249b45f/scripts.json" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2409904#file_scripts.json" style="float:right;margin-right:10px;color:#666">scripts.json</a>
            <a href="https://gist.github.com/2409904">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>But you can&#8217;t just &#8220;npm foo&#8221;. The &#8220;start&#8221; script is recognized by npm explicitly. For other non-standard script names, you have to use the &#8220;run-script&#8221; command from node: npm run-script foo</p>
<p><img title="Screen Shot 2012-04-17 at 6.38.18 PM.png" src="http://lostechies.com/derickbailey/files/2012/04/Screen-Shot-2012-04-17-at-6.38.18-PM.png" alt="Screen Shot 2012 04 17 at 6 38 18 PM" width="505" height="195" border="0" /></p>
<p>The other thing that this does for us, is give us direct access to all of the bin files that our node packages have installed. So within a &#8220;script&#8221; configuration, we can call any arbitrary package&#8217;s bin file.</p>
<p>For example, if I want to use the node-supervisor package to restart my app whenever any files change, I can set up my package.json file to look like this:</p>
<div id="gist-2409904" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="p">{</span></div><div class='line' id='LC2'>&nbsp;&nbsp;<span class="nt">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;application-name&quot;</span><span class="p">,</span></div><div class='line' id='LC3'>&nbsp;&nbsp;<span class="nt">&quot;version&quot;</span><span class="p">:</span> <span class="s2">&quot;0.0.1&quot;</span><span class="p">,</span></div><div class='line' id='LC4'>&nbsp;&nbsp;<span class="nt">&quot;private&quot;</span><span class="p">:</span> <span class="kc">true</span><span class="p">,</span></div><div class='line' id='LC5'>&nbsp;&nbsp;<span class="nt">&quot;scripts&quot;</span><span class="p">:</span> <span class="p">{</span></div><div class='line' id='LC6'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&quot;start&quot;</span><span class="p">:</span> <span class="s2">&quot;supervisor app&quot;</span></div><div class='line' id='LC7'>&nbsp;&nbsp;<span class="p">},</span></div><div class='line' id='LC8'>&nbsp;&nbsp;<span class="nt">&quot;dependencies&quot;</span><span class="p">:</span> <span class="p">{</span></div><div class='line' id='LC9'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&quot;express&quot;</span><span class="p">:</span> <span class="s2">&quot;3.0.0alpha1&quot;</span><span class="p">,</span></div><div class='line' id='LC10'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&quot;jade&quot;</span><span class="p">:</span> <span class="s2">&quot;*&quot;</span></div><div class='line' id='LC11'>&nbsp;&nbsp;<span class="p">},</span></div><div class='line' id='LC12'>&nbsp;&nbsp;<span class="nt">&quot;devDependencies&quot;</span><span class="p">:</span> <span class="p">{</span></div><div class='line' id='LC13'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&quot;supervisor&quot;</span><span class="p">:</span> <span class="s2">&quot;*&quot;</span></div><div class='line' id='LC14'>&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC15'><span class="p">}</span></div><div class='line' id='LC16'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2409904/714c9092686c825f7b0a83f55f3df94d43eb59f1/supervisor.json" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2409904#file_supervisor.json" style="float:right;margin-right:10px;color:#666">supervisor.json</a>
            <a href="https://gist.github.com/2409904">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>This will install the &#8220;supervisor&#8221; package for development only, and set up the &#8220;start&#8221; script to run &#8220;supervisor app&#8221;. Now from the command line, I can&#8217;t run &#8220;supervisor app&#8221; directly:</p>
<p><img title="Screen Shot 2012-04-17 at 6.40.56 PM.png" src="http://lostechies.com/derickbailey/files/2012/04/Screen-Shot-2012-04-17-at-6.40.56-PM.png" alt="Screen Shot 2012 04 17 at 6 40 56 PM" width="448" height="60" border="0" /></p>
<p>But I can run &#8220;node start&#8221; and node will pick up the ./node_modules/.bin/ folder for me, allowing supervisor to be executed:</p>
<p><img title="Screen Shot 2012-04-17 at 6.41.49 PM.png" src="http://lostechies.com/derickbailey/files/2012/04/Screen-Shot-2012-04-17-at-6.41.49-PM.png" alt="Screen Shot 2012 04 17 at 6 41 49 PM" width="542" height="495" border="0" /></p>
<p>This works well for recurring / repetitive tasks within a project. But if you want ad-hoc package commands, you&#8217;re going to be in for a little more work and will likely have to fall back to one of the other solutions I&#8217;ve mentioned.</p>
<h2>Other Options?</h2>
<p>I really do miss the &#8220;bundle exec&#8221; feature of bundler. I honestly don&#8217;t know why npm doesn&#8217;t have an equivalent built in to it. Maybe it just needs someone to come along and contribute this feature. Maybe this feature was rejected. I don&#8217;t know. I haven&#8217;t looked in to it. But I wanted to get something in place now, so that I don&#8217;t have to install all of my project specific packages in the global package list.</p>
<p>There might be better option than the ones I&#8217;ve listed, as well. So, what am I missing? Is there something built in to npm to make this easier? Are there other ways that you&#8217;ve worked around this? Or am I going to stick with my &#8220;npm_exec&#8221; script and using npm &#8220;scripts&#8221; in my package.json fil?</p>
<p> </p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/LosTechies?a=WDkZFSzj9aE:LeC2LCOnJ6A:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/LosTechies?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=WDkZFSzj9aE:LeC2LCOnJ6A:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/LosTechies?i=WDkZFSzj9aE:LeC2LCOnJ6A:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=WDkZFSzj9aE:LeC2LCOnJ6A:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/LosTechies?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=WDkZFSzj9aE:LeC2LCOnJ6A:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/LosTechies?i=WDkZFSzj9aE:LeC2LCOnJ6A:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/LosTechies/~4/WDkZFSzj9aE" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://lostechies.com/derickbailey/2012/04/24/executing-a-project-specific-nodenpm-package-a-la-bundle-exec/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
            <media:content url="http://www.gravatar.com/avatar/e592bd1326b1e80188ed4c0bf26b9f75?s=96&amp;d=http%3A%2F%2Fwww.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
            <media:title type="html">Derick Bailey</media:title>
        </media:content>
    		<feedburner:origLink>http://lostechies.com/derickbailey/2012/04/24/executing-a-project-specific-nodenpm-package-a-la-bundle-exec/</feedburner:origLink></item>
	<item>
		<title>The *nix Rube Goldberg machine – functions!</title>
		<link>http://feedproxy.google.com/~r/LosTechies/~3/iVIhCARQ6Rk/</link>
		<comments>http://lostechies.com/ryanrauh/2012/04/23/the-nix-rube-goldberg-machine-functions/#comments</comments>
		<pubDate>Mon, 23 Apr 2012 15:44:07 +0000</pubDate>
		<dc:creator>Ryan Rauh</dc:creator>
				<category><![CDATA[Shell]]></category>
		<category><![CDATA[bash]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://lostechies.com/ryanrauh/?p=147]]></guid>
		<description><![CDATA[Learn your shell! So a couple weeks ago I finally decided to learn how to use bash functions. I knew they existed but I decided to ignore them for the longest time. Often times you find yourself typing the same&#160;&#8230; <a href="http://lostechies.com/ryanrauh/2012/04/23/the-nix-rube-goldberg-machine-functions/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<h1> Learn your shell! </h1>
<p>So a couple weeks ago I finally decided to learn how to use bash functions. I knew they existed but I decided to ignore them for the longest time. </p>
<p>Often times you find yourself typing the same things over and over again into the shell. In our app we deploy 3 windows services and managing them can get really tedious. </p>
<p><code>~/lecode&gt;sc query DovetailEmail-default</code><br />
<code>~/lecode&gt;sc stop DovetailEmail-default</code><br />
<code>~/lecode&gt;sc delete DovetailEmail-default</code></p>
<p><code>~/lecode&gt;sc query DovetailRulesEngine-default</code><br />
<code>~/lecode&gt;sc stop DovetailRulesEngine-default</code><br />
<code>~/lecode&gt;sc delete DovetailRulesEngine-default</code></p>
<p><code>~/lecode&gt;sc query DovetailMessaging-default</code><br />
<code>~/lecode&gt;sc stop DovetailMessaging-default</code><br />
<code>~/lecode&gt;sc delete DovetailMessaging-default</code></p>
<p>That&#8217;s a lot of typing, granted its not that bad when you use your bash history. But you end up hitting the up arrow and changing one word a lot. </p>
<h3> Functions! </h3>
<p>So when you keep repeating yourself over and over again you can quickly write a function that can save you precious keystrokes</p>
<p><code>~/lecode&gt;function fsc() {<br />
    for name in Email RulesEngine Messaging<br />
    do<br />
        sc $1 Dovetail$name-$2<br />
    done<br />
}<br />
</code></p>
<p>Now I can happily type<br />
<code>~/lecode&gt;fsc query default</code><br />
<code>~/lecode&gt;fsc stop default</code><br />
<code>~/lecode&gt;fsc start default</code></p>
<p>It works for other repetitive tasks as well, ie the steps to deploy our app is as follows</p>
<p><code>~/lecode&gt;rm -rf mydefault</code><br />
<code>~/lecode&gt;bottles create-all</code><br />
<code>~/lecode&gt;bottles bundle mydefault -profile default</code><br />
<code>~/lecode&gt;mydefault/BottleRunner.exe deploy -profile default</code></p>
<p>Again&#8230; pretty easy to just use my bash history and hit the up arrow to run all the commands<br />
but its really easy to make a function</p>
<p><code>~/lecode&gt;function fdeploy() {<br />
    rm -rf my$1<br />
    bottles create-all<br />
    bottles bundle my$1 -profile $1<br />
    my$1/BottleRunner.exe deploy -profile $1<br />
}<br />
</code></p>
<p>Then bam!</p>
<p><code>~/lecode&gt;fdeploy default</code><br />
<code>~/lecode&gt;fdeploy storyteller</code><br />
<code>~/lecode&gt;fdeploy hrdemo</code></p>
<p>See thats way mo &#8216;betta than creating a .bat file cause then you have run in cmd.exe, you have to ignore it in git repository, clean up after yourself later&#8230;.</p>
<p>And I just don&#8217;t like that, not one bit.</p>
<p>-Ryan</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/LosTechies?a=iVIhCARQ6Rk:JhqVqmeQmTI:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/LosTechies?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=iVIhCARQ6Rk:JhqVqmeQmTI:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/LosTechies?i=iVIhCARQ6Rk:JhqVqmeQmTI:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=iVIhCARQ6Rk:JhqVqmeQmTI:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/LosTechies?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=iVIhCARQ6Rk:JhqVqmeQmTI:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/LosTechies?i=iVIhCARQ6Rk:JhqVqmeQmTI:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/LosTechies/~4/iVIhCARQ6Rk" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://lostechies.com/ryanrauh/2012/04/23/the-nix-rube-goldberg-machine-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
            <media:content url="http://www.gravatar.com/avatar/29283ede6c447fdc62f0ceac42df33ea?s=96&amp;d=http%3A%2F%2Fwww.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
            <media:title type="html">Ryan Rauh</media:title>
        </media:content>
    		<feedburner:origLink>http://lostechies.com/ryanrauh/2012/04/23/the-nix-rube-goldberg-machine-functions/</feedburner:origLink></item>
	<item>
		<title>WatchMeCode: Using LiveReload In Web Development</title>
		<link>http://feedproxy.google.com/~r/LosTechies/~3/MaoAhTkFqaE/</link>
		<comments>http://lostechies.com/derickbailey/2012/04/23/watchmecode-using-livereload-in-web-development/#comments</comments>
		<pubDate>Mon, 23 Apr 2012 12:38:59 +0000</pubDate>
		<dc:creator>Derick Bailey</dc:creator>
				<category><![CDATA[Screencast]]></category>
		<category><![CDATA[WatchMeCode]]></category>
		<category><![CDATA[Web Sockets]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://lostechies.com/derickbailey/?p=908]]></guid>
		<description><![CDATA[From all of the screencasts that I&#8217;ve produced at WatchMeCode so far, the number one question that I get is: What tool do you use to refresh your browser when you change a file in your editor? It&#8217;s LiveReload, and&#160;&#8230; <a href="http://lostechies.com/derickbailey/2012/04/23/watchmecode-using-livereload-in-web-development/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p>From all of the screencasts that I&#8217;ve produced at <a href="http://www.watchmecode.net/">WatchMeCode</a> so far, the number one question that I get is:</p>
<blockquote>
<p><em>What tool do you use to refresh your browser when you change a file in your editor?</em></p>
</blockquote>
<p>It&#8217;s <a href="http://livereload.com/">LiveReload</a>, and I&#8217;ve put together <a href="http://www.watchmecode.net/livereload">a 10 minute introduction</a> that shows how to get up and running with the GUI application and the Guard plugin, how to use it to compile your assets such as SASS or CoffeeScript, and more.</p>
<p><iframe src="http://www.youtube-nocookie.com/embed/uLh2rmSpa48?rel=0" width="560" height="315" frameborder="0"></iframe></p>
<p>Personally, I can&#8217;t live without this tool anymore. It takes the &#8220;refresh&#8221; button out of my development effort and greatly simplifies my workflow.</p>
<p>Be sure to checkout my other screencasts (paid and free) at <a href="http://www.watchmecode.net/">WatchMeCode.net</a> as well.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/LosTechies?a=MaoAhTkFqaE:9O9RH11Dgzo:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/LosTechies?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=MaoAhTkFqaE:9O9RH11Dgzo:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/LosTechies?i=MaoAhTkFqaE:9O9RH11Dgzo:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=MaoAhTkFqaE:9O9RH11Dgzo:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/LosTechies?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LosTechies?a=MaoAhTkFqaE:9O9RH11Dgzo:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/LosTechies?i=MaoAhTkFqaE:9O9RH11Dgzo:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/LosTechies/~4/MaoAhTkFqaE" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://lostechies.com/derickbailey/2012/04/23/watchmecode-using-livereload-in-web-development/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
            <media:content url="http://www.gravatar.com/avatar/e592bd1326b1e80188ed4c0bf26b9f75?s=96&amp;d=http%3A%2F%2Fwww.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
            <media:title type="html">Derick Bailey</media:title>
        </media:content>
    		<feedburner:origLink>http://lostechies.com/derickbailey/2012/04/23/watchmecode-using-livereload-in-web-development/</feedburner:origLink></item>
</channel>
</rss><!-- 261 queries 1.536 seconds. --><!-- Dynamic page generated in 1.536 seconds. --><!-- Cached page generated by WP-Super-Cache on 2012-05-27 17:46:49 -->

