<?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.codeville.net/~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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Steve Sanderson’s blog</title>
	
	<link>http://blog.stevensanderson.com</link>
	<description>As seen on YouTube™</description>
	<lastBuildDate>Mon, 20 May 2013 12:08:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.codeville.net/SteveCodeville" /><feedburner:info uri="stevecodeville" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Knockout-ES5: a plugin to simplify your syntax</title>
		<link>http://feeds.codeville.net/~r/SteveCodeville/~3/PQMIKR8jSY0/</link>
		<comments>http://blog.stevensanderson.com/2013/05/20/knockout-es5-a-plugin-to-simplify-your-syntax/#comments</comments>
		<pubDate>Mon, 20 May 2013 11:50:45 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Knockout]]></category>

		<guid isPermaLink="false">http://blog.stevensanderson.com/?p=671</guid>
		<description><![CDATA[Knockout-ES5 is a plugin for Knockout.js that lets you use simpler and more natural syntax in your model code and bindings. For example, you can replace this: var latestOrder = this.orders&#40;&#41;&#91;this.orders&#40;&#41;.length - 1&#93;; // Read a value latestOrder.isShipped&#40;true&#41;; // Write [...]]]></description>
			<content:encoded><![CDATA[<p><a href="https://github.com/SteveSanderson/knockout-es5">Knockout-ES5</a> is a plugin for <a href="http://knockoutjs.com">Knockout.js</a> that lets you use simpler and more natural syntax in your model code and bindings. For example, you can replace this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript"><span style="color: #003366; font-weight: bold;">var</span> latestOrder <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">orders</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">orders</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// Read a value</span>
latestOrder.<span style="color: #660066;">isShipped</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>                               <span style="color: #006600; font-style: italic;">// Write a value</span></pre></div></div>

<p>… with this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript"><span style="color: #003366; font-weight: bold;">var</span> latestOrder <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">orders</span><span style="color: #009900;">&#91;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">orders</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>     <span style="color: #006600; font-style: italic;">// Read a value</span>
latestOrder.<span style="color: #660066;">isShipped</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>                              <span style="color: #006600; font-style: italic;">// Write a value</span></pre></div></div>

<p>… while still retaining all of Knockout&#8217;s capabilities of automatically refreshing your UI and automatically detecting dependencies between different model properties.</p>
<p>Basically, it&#8217;s <strong>all the goodness of Knockout, but without <a href="http://stackoverflow.com/questions/10996185/when-should-i-use-parentheses-in-knockout">having to remember parentheses</a></strong>. It requires a moderately up-to-date browser (more about this later).</p>
<h4>Getting started</h4>
<p>Download <a href="https://raw.github.com/SteveSanderson/knockout-es5/master/dist/knockout-es5.min.js">knockout-es5.min.js</a> and add a <code>&lt;script&gt;</code> reference <em>after</em> you reference Knockout itself, e.g.:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript"><span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">'knockout-2.2.1.js'</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">'knockout-es5.min.js'</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Then you can declare model classes without needing any explicit references to <code>ko.observable</code>, e.g.:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript"><span style="color: #003366; font-weight: bold;">function</span> OrderLine<span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066; font-weight: bold;">item</span> <span style="color: #339933;">=</span> data.<span style="color: #000066; font-weight: bold;">item</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">price</span> <span style="color: #339933;">=</span> data.<span style="color: #660066;">price</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">quantity</span> <span style="color: #339933;">=</span> data.<span style="color: #660066;">quantity</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">getSubtotal</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;$&quot;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">price</span> <span style="color: #339933;">*</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">quantity</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toFixed</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// Instead of declaring ko.observable properties, we just have one call to ko.track </span>
    ko.<span style="color: #660066;">track</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Notice that the properties are just plain properties, without being wrapped in <code>ko.observable</code>. This means that during computations, such as in <code>getSubtotal</code>, there&#8217;s no need to invoke them as functions to read their value (e.g., <code>this.quantity()</code>). Similarly if you wanted to change a value, you&#8217;d just use a plain old assignment, e.g.:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript">someOrderLine.<span style="color: #660066;">quantity</span> <span style="color: #339933;">+=</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span></pre></div></div>

<p>… instead of function calls (e.g., <code>someOrderLine.quantity(someOrderLine.quantity() + 1);</code>).</p>
<h4>How it works</h4>
<p>It&#8217;s so very simple. <code>ko.track</code> walks the list of properties on your model object, and for each one, replaces it with an <a href="https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Object/defineProperty">ES5 getter/setter</a> pair that reads/writes a hidden underlying observable (initialised to the existing property value).</p>
<p>The neat thing is that the Knockout.js core library doesn&#8217;t need to know anything about this: when you get/set one of these properties, some observable is read or written, and therefore all of KO&#8217;s existing binding, computed, and dependency detection functionality just works perfectly. Knockout-ES5 doesn&#8217;t have to patch any of the KO internals, so it works with any recent version of KO.</p>
<p><strong>Controlling which properties are upgraded</strong></p>
<p>If you want to restrict which properties are upgraded to observability, pass an array of property names:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript">ko.<span style="color: #660066;">track</span><span style="color: #009900;">&#40;</span>someModelObject<span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'firstName'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'lastName'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'email'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>By design, <code>ko.track</code> does <em>not</em> recurse into child objects. I would encourage you to declare child objects as instances of some class of your own, with its constructor having its own <code>ko.track</code> call &#8212; this gives you far more control over how much of the object graph is walked.</p>
<p><strong>Accessing the observables</strong></p>
<p>If you want to access the underlying <code>ko.observable</code> for a given property, e.g., so that you can subscribe to receive notifications when it changes, use <code>ko.getObservable</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript">ko.<span style="color: #660066;">getObservable</span><span style="color: #009900;">&#40;</span>someModel<span style="color: #339933;">,</span> <span style="color: #3366CC;">'email'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">subscribe</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>newValue<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'The new email address is '</span> <span style="color: #339933;">+</span> newValue<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>About arrays</strong></p>
<p>Array-valued properties are special. As well as upgrading them to support observability like other properties, Knockout-ES5 intercepts calls to <code>push</code>, <code>pop</code>, <code>splice</code>, etc., to trigger change notifications just as you&#8217;d expect. This means that any UI based on the array, such as a list, will update automatically if you add or remove items.</p>
<p>With Knockout-ES5, you can access the array&#8217;s subproperties directly, e.g.:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript"><span style="color: #003366; font-weight: bold;">var</span> numItems <span style="color: #339933;">=</span> myArray.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// Don't have to write myArray().length</span></pre></div></div>

<p>Also, Knockout-ES5 adds a few additional functions that have proven useful on <code>ko.observableArray</code> instances: <a href="http://knockoutjs.com/documentation/observableArrays.html#remove_and_removeall"><code>remove</code>, <code>removeAll</code>, <code>destroy</code>, <code>destroyAll</code>, <code>replace</code></a>.</p>
<h4>Computed properties</h4>
<p>The most important feature of Knockout.js, and what differentiates it from most other Model-View JavaScript libraries, is its &#8220;reactive&#8221; dependency-detection capabilities: its ability to chain computed properties, so that changes propagate through an arbitrary object graph into your UI, without needing you to declare those dependencies anywhere.</p>
<p>Traditionally, Knockout uses <code>ko.computed</code> for this. So how does it work in Knockout-ES5? There are a couple of different patterns you can choose from:</p>
<ol>
<li>
<p><strong>Just put a plain function on your model</strong>. In the example at the top of this blog post, <code>getSubtotal</code> is a plain old function. By invoking it from a binding, KO will detect the function&#8217;s dependencies (in this case, <code>price</code> and <code>quantity</code>) and will automatically refresh the UI when either changes:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript"><span style="color: #339933;">&lt;</span>span data<span style="color: #339933;">-</span>bind<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text: getSubtotal()&quot;</span><span style="color: #339933;">&gt;&lt;/</span>span<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Pretty straightforward.</p>
</li>
<li>
<p><strong>Use ko.defineProperty</strong>. This is provided by Knockout-ES5 and is a KO-style equivalent to <code>Object.defineProperty</code>. It lets you declare a computed property with a <code>get</code> (and optionally <code>set</code>) function, for example:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript">ko.<span style="color: #660066;">defineProperty</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'subtotal'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">price</span> <span style="color: #339933;">*</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">quantity</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Alternatively, the third arg can be an object like { get: function() { ... }, set: ... }</span></pre></div></div>

<p>The advantage of this is that (A) you can read the <code>subtotal</code> property without having to invoke it as a function (as in <code>getSubtotal()</code>), and (B) its value will be cached and reused for all future invocations until a dependency changes, instead of re-running your <code>get</code> logic for each evaluation:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript"><span style="color: #339933;">&lt;</span>span data<span style="color: #339933;">-</span>bind<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text: subtotal&quot;</span><span style="color: #339933;">&gt;&lt;/</span>span<span style="color: #339933;">&gt;</span></pre></div></div>

<p>To ensure dependencies can be detected, place <code>ko.defineProperty</code> calls <em>after</em> your <code>ko.track</code> call. Or, if you want to put <code>ko.defineProperty</code> first, make sure no other code tries to evaluate the computed property before <code>ko.track</code> runs (if it evaluates before dependencies are tracked, it won&#8217;t be able to detect those dependencies).</p>
</li>
</ol>
<h4>Browser support</h4>
<p>Knockout-ES5 works in ECMAScript 5-capable browsers. Let&#8217;s consider whether that&#8217;s appropriate for your project.</p>
<p>Since the Age of Antiquity, browsers such as IE6 have supported the ECMAScript 3 (ES3) JavaScript specification. It&#8217;s a tired old workhorse of a spec. Since then, all modern browsers have moved to ECMAScript 5 (ES5). You&#8217;ve been running ES5 for some years already, at least since IE9/Firefox 4/Chrome 6. ES5 adds a wealth of <a href="http://kangax.github.io/es5-compat-table">language and runtime primitives</a> that open up valuable new possibilities. It&#8217;s no surprise that, when deciding which older IE versions to leave behind, <a href="http://blog.jquery.com/2013/04/18/jquery-2-0-released/">jQuery 2.0</a> chose to support only IE 9 and newer, where ES5 is available.</p>
<p>Of course, Knockout.js itself takes backward compatibility <em>very</em> seriously: it has 100% support for anything from IE6 and Firefox 2 onwards. You can drop it into pretty much any web app with confidence. That is not changing. But today there are <em>many</em> projects where you know for sure your code will run only in an ES5 environment, for example:</p>
<ul>
<li>Large, sophisticated public web apps (such as <a href="http://weblogs.asp.net/scottgu/archive/2012/11/19/more-great-improvements-to-the-windows-azure-management-portal.aspx">the one I currently work on</a>) that already require at least IE9 or another modern browser</li>
<li>Intranet applications for sane corporate environments</li>
<li>PhoneGap apps targetting iOS/Android/WP8</li>
<li>Server-side code running inside Node.js</li>
</ul>
<p><strong>Summary: Knockout.js itself continues to support ES3 browsers such as IE6, and Knockout-ES5 is an optional plugin for those projects where it&#8217;s safe to depend on ES5.</strong></p>
<h4>The source</h4>
<p>If you&#8217;re have Knockout experience already and are interested in more details about the implementation of Knockout-ES5, <a href="https://github.com/SteveSanderson/knockout-es5/blob/master/src/knockout-es5.js">see the source</a>. It&#8217;s shorter than this blog post.</p>
<div class="feedflare">
<a href="http://feeds.codeville.net/~ff/SteveCodeville?a=PQMIKR8jSY0:2RKK6-yZNMM:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/SteveCodeville?i=PQMIKR8jSY0:2RKK6-yZNMM:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.codeville.net/~ff/SteveCodeville?a=PQMIKR8jSY0:2RKK6-yZNMM:G79ilh31hkQ"><img src="http://feeds.feedburner.com/~ff/SteveCodeville?d=G79ilh31hkQ" border="0"></img></a> <a href="http://feeds.codeville.net/~ff/SteveCodeville?a=PQMIKR8jSY0:2RKK6-yZNMM:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/SteveCodeville?i=PQMIKR8jSY0:2RKK6-yZNMM:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.codeville.net/~ff/SteveCodeville?a=PQMIKR8jSY0:2RKK6-yZNMM:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/SteveCodeville?d=yIl2AUoC8zA" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/SteveCodeville/~4/PQMIKR8jSY0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.stevensanderson.com/2013/05/20/knockout-es5-a-plugin-to-simplify-your-syntax/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.stevensanderson.com/2013/05/20/knockout-es5-a-plugin-to-simplify-your-syntax/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=knockout-es5-a-plugin-to-simplify-your-syntax</feedburner:origLink></item>
		<item>
		<title>Animating lists with CSS 3 transitions</title>
		<link>http://feeds.codeville.net/~r/SteveCodeville/~3/QS5qgg6VmYM/</link>
		<comments>http://blog.stevensanderson.com/2013/03/15/animating-lists-with-css-3-transitions/#comments</comments>
		<pubDate>Fri, 15 Mar 2013 11:55:29 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[UI]]></category>

		<guid isPermaLink="false">http://blog.stevensanderson.com/?p=624</guid>
		<description><![CDATA[Ever wanted to implement animated lists or grids, like in the following 12-second video? Your browser does not support the video tag. This may look like a native iOS app, but this UI is all implemented with HTML, CSS, and [...]]]></description>
			<content:encoded><![CDATA[<p>Ever wanted to implement animated lists or grids, like in the following 12-second video?</p>
<p><video id="list-example-video" style="background-color: silver" controls loop="true" autoplay="autoplay" height="330" width="640"><source type="video/mp4" src="https://archive.org/download/Dragdrop60/dragdrop60.mp4" /><b style="color: red">Your browser does not support the <i>video</i> tag.</b> </video></p>
<p>This may look like a native iOS app, but this UI is all implemented with <strong>HTML, CSS, and JavaScript</strong> (see <a href="http://blog.stevensanderson.com/?p=603">the previous post</a> for details about my new iPhone app, <a href="https://itunes.apple.com/us/app/touralot/id602481226" target="_blank">Touralot</a>, built with PhoneGap). So, how does all this slidey stuff work?</p>
<h4>Using “transform” and “transition” in lists</h4>
<p>The basic principles here are:</p>
<ul>
<li>For animations to be smooth and hardware-accelerated, they have to be done with <strong>transform: translate3d</strong>
<li>Even so, element positions should still be determined by the DOM structure (minimizing use of JavaScript)</li>
</ul>
<p>So, consider some markup like the following:</p>

<div class="wp_syntax"><div class="code"><pre class="html">&lt;ul class=&quot;items&quot;&gt;
    &lt;li&gt;Monday&lt;/li&gt;
    &lt;li&gt;Tuesday&lt;/li&gt;
    &lt;li&gt;Wednesday&lt;/li&gt;
    ...
&lt;/ul&gt;</pre></div></div>

<p>The element positions are determined by the DOM structure, but not using <strong>translate3d</strong>. Now consider the following CSS rules:</p>

<div class="wp_syntax"><div class="code"><pre class="css"><span style="color: #6666ff;">.items</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.items</span> li <span style="color: #00AA00;">&#123;</span> 
    <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
    transition<span style="color: #00AA00;">:</span> all 0.2s ease-out<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.items</span> li<span style="color: #3333ff;">:nth-</span>child<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #00AA00;">&#41;</span>  <span style="color: #00AA00;">&#123;</span> transform<span style="color: #00AA00;">:</span> translate3d<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> <span style="color: #933;">0%</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.items</span> li<span style="color: #3333ff;">:nth-</span>child<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #00AA00;">&#41;</span>  <span style="color: #00AA00;">&#123;</span> transform<span style="color: #00AA00;">:</span> translate3d<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> <span style="color: #933;">100%</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.items</span> li<span style="color: #3333ff;">:nth-</span>child<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #00AA00;">&#41;</span>  <span style="color: #00AA00;">&#123;</span> transform<span style="color: #00AA00;">:</span> translate3d<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> <span style="color: #933;">200%</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
...</pre></div></div>

<p>As you can see, the &lt;li&gt; elements will now be positioned absolutely against the parent &lt;ul&gt;, and we use <strong>translate3d</strong> to recover the usual vertical offset based on each element’s position in the DOM. What’s more, there’s a <strong>transition</strong> rule so that, whenever <strong>translate3d</strong> changes, the browser smoothly animates the element to its new position.</p>
<p><em>[Aside: For Webkit, you’d need prefixed rules as well (<strong>-webkit-transform</strong> and <strong>-webkit-transition</strong>). Current versions of IE and Firefox don’t require the prefixes.]</em></p>
<p>What’s the result? Well, now <strong>whenever you change the set of &lt;li&gt; elements inside the &lt;ul&gt;, all the other &lt;li&gt; elements will smoothly animate into their new positions</strong>, without you having to write any code to tell them to do so. This works wonderfully if you’re generating your DOM through any kind of templates/binding library such as with <a href="http://knockoutjs.com/documentation/foreach-binding.html" target="_blank">Knockout’s foreach binding</a>, but also works nicely just with plain old DOM operations. Try this:</p>
<p><iframe style="width: 100%; height: 525px;" src="http://jsfiddle.net/jKhRC/embedded/result,js,html,css" frameborder="0"></iframe></p>
<p>The add and remove functionality doesn’t have to tell the elements to animate. They just do that naturally. For example, the code for add is just:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.append&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;li&gt;New item&lt;/li&gt;&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">insertAfter</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.items&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h4>Browser quirks</h4>
<p>Webkit (or at least Chrome) has annoying bug whereby it doesn’t account for in-flight CSS transitions when computing the scroll extents of a container. So you’ll need to do something like the following to force it to recompute the scroll container bounds at the end of the transition:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript"><span style="color: #006600; font-style: italic;">// Workaround for Webkit bug: force scroll height to be recomputed after the transition ends, not only when it starts</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.items&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">on</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;webkitTransitionEnd&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">offset</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Also, since IE&lt;10 doesn’t support <strong>transform</strong> or <strong>transition</strong>, you might also want to include some conditional CSS like the following to get basic non-animated behaviour on older browsers:</p>

<div class="wp_syntax"><div class="code"><pre class="css">&lt;!--<span style="color: #00AA00;">&#91;</span>if lte IE <span style="color: #cc66cc;">9</span><span style="color: #00AA00;">&#93;</span><span style="color: #00AA00;">&gt;</span>&lt;style type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span><span style="color: #00AA00;">&gt;</span>
    <span style="color: #808080; font-style: italic;">/* Old IE doesn't support CSS transform or transitions */</span>
    <span style="color: #6666ff;">.list-example</span> <span style="color: #6666ff;">.items</span> li <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> inline-<span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
&lt;/style<span style="color: #00AA00;">&gt;</span>&lt;!<span style="color: #00AA00;">&#91;</span>endif<span style="color: #00AA00;">&#93;</span>--<span style="color: #00AA00;">&gt;</span></pre></div></div>

<h4>It works for grids, too</h4>
<p>With this technique, there’s nothing special about one-dimensional vertical lists. It works exactly as well for two-dimensional grids, without any changes.</p>
<p>Well actually, this raises the question of where all those <strong>.items li:nth-child(x)</strong> rules are coming from. So far I assumed you were writing them by hand. But how many such rules should you write? Couldn’t we generate them programmatically? Why yes, of course. Try this utility function:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript"><span style="color: #003366; font-weight: bold;">function</span> createListStyles<span style="color: #009900;">&#40;</span>rulePattern<span style="color: #339933;">,</span> rows<span style="color: #339933;">,</span> cols<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> rules <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> index <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> rowIndex <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> rowIndex <span style="color: #339933;">&lt;</span> rows<span style="color: #339933;">;</span> rowIndex<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> colIndex <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> colIndex <span style="color: #339933;">&lt;</span> cols<span style="color: #339933;">;</span> colIndex<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #003366; font-weight: bold;">var</span> x <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>colIndex <span style="color: #339933;">*</span> <span style="color: #CC0000;">100</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;%&quot;</span><span style="color: #339933;">,</span>
                y <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>rowIndex <span style="color: #339933;">*</span> <span style="color: #CC0000;">100</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;%&quot;</span><span style="color: #339933;">,</span>
                transforms <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;{ -webkit-transform: translate3d(&quot;</span> <span style="color: #339933;">+</span> x <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;, &quot;</span> <span style="color: #339933;">+</span> y <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;, 0); transform: translate3d(&quot;</span> <span style="color: #339933;">+</span> x <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;, &quot;</span> <span style="color: #339933;">+</span> y <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;, 0); }&quot;</span><span style="color: #339933;">;</span>
            rules.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>rulePattern.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;{0}&quot;</span><span style="color: #339933;">,</span> <span style="color: #339933;">++</span>index<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> transforms<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #003366; font-weight: bold;">var</span> headElem <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;head&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
        styleElem <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;style&gt;&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;type&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;text/css&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span>headElem<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>styleElem.<span style="color: #660066;">styleSheet</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        styleElem.<span style="color: #660066;">styleSheet</span>.<span style="color: #660066;">cssText</span> <span style="color: #339933;">=</span> rules.<span style="color: #660066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
        styleElem.<span style="color: #660066;">textContent</span> <span style="color: #339933;">=</span> rules.<span style="color: #660066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>You can specify a maximum number of elements to account for, and the number of columns desired in your grid (or pass 1 for a single-column vertical list). Of course, it would be nicer still if we could write just <em>one</em> rule that specified the <strong>translate3d</strong> values as a function of the element index, but I’m not aware of any way of doing that in CSS 3. Let me know if you can think of one!</p>
<p>Here’s the result, as a three-column grid:</p>
<p><iframe style="width: 100%; height: 330px;" src="http://jsfiddle.net/8XM3q/embedded/result,js,html,css" frameborder="0"></iframe></p>
<h4>Supporting arbitrary reorderings</h4>
<p>The technique so far is great for animating all elements <em>other than</em> the one you’re inserting or reordering. But if you remove and insert an element in a new position, it will appear there instantly, without a transition, because it is a brand new element as far as the CSS transition logic is concerned.</p>
<p>So, how would it be possible to achieve something like the following, where the “reorder” button smoothly moves elements to new positions? Try it: click the <strong>random order</strong> button:</p>
<p><iframe style="width: 100%; height: 525px;" src="http://jsfiddle.net/nT4j5/embedded/result,js,html,css" frameborder="0"></iframe></p>
<p>One possible technique is to override the <strong>translate3d</strong> values for each element with a snapshot of their current values, so that the elements retain their coordinates independently of their DOM order. Then, after mutating the DOM, remove your snapshot values, and then the CSS transition will kick in to move the element smoothly to its final location.</p>
<p>Here’s are a couple of handle jQuery utility functions:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> stylesToSnapshot <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;transform&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;-webkit-transform&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
    $.<span style="color: #660066;">fn</span>.<span style="color: #660066;">snapshotStyles</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">getComputedStyle</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> stylesToSnapshot.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
                    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">style</span><span style="color: #009900;">&#91;</span>stylesToSnapshot<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> getComputedStyle<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>stylesToSnapshot<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    $.<span style="color: #660066;">fn</span>.<span style="color: #660066;">releaseSnapshot</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">offsetHeight</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// Force position to be recomputed before transition starts</span>
            <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> stylesToSnapshot.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
                <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">style</span><span style="color: #009900;">&#91;</span>stylesToSnapshot<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now you can achieve the random reordering thing as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.reorder&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.items li&quot;</span><span style="color: #009900;">&#41;</span>
        .<span style="color: #660066;">snapshotStyles</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
        .<span style="color: #660066;">tsort</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> order<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;rand&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
        .<span style="color: #660066;">releaseSnapshot</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This works just the same with two-dimensional grids as with vertical lists.</p>
<p>For convenience, I used the <a href="http://tinysort.sjeiti.com/" target="_blank">tinysort library</a> here (I only just learned about it this morning – it’s very neat), which can also sort the elements in a meaningful way, not only randomly. But it would work exactly the same if you write manual code to reorder the elements.</p>
<h4>Supporting drag-and-drop reordering</h4>
<p>Getting to this point may have seemed complicated, but it has some great benefits. Since the animation and positioning is controlled entirely by CSS, it composes beautifully with many other techniques for modifying the DOM. For example, if a drag-drop library shuffles the DOM elements, then they will now animate.</p>
<p>As an example, we can throw in <a href="http://jqueryui.com/sortable/" target="_blank">jQuery UI’s sortable</a> mechanism to enable drag-drop reordering. But let’s make it slick, and also animate the “dropping” phase of the operation, where the element you dragged moves from wherever you’re holding it into its final position.</p>
<p>Here’s how you can do that:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ul.items&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">sortable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    start<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>event<span style="color: #339933;">,</span> ui<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">// Temporarily move the dragged item to the end of the list so that it doesn't offset the items</span>
        <span style="color: #006600; font-style: italic;">// below it (jQuery UI adds a 'placeholder' element which creates the desired offset during dragging)</span>
        $<span style="color: #009900;">&#40;</span>ui.<span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;dragging&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #000066;">stop</span><span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>event<span style="color: #339933;">,</span> ui<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">// jQuery UI instantly moves the element to its final position, but we want it to transition there.</span>
        <span style="color: #006600; font-style: italic;">// So, first convert the final top/left position into a translate3d style override</span>
        <span style="color: #003366; font-weight: bold;">var</span> newTranslation <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;translate3d(&quot;</span> <span style="color: #339933;">+</span> ui.<span style="color: #660066;">position</span>.<span style="color: #660066;">left</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;px, &quot;</span> <span style="color: #339933;">+</span> ui.<span style="color: #660066;">position</span>.<span style="color: #660066;">top</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;px, 0)&quot;</span><span style="color: #339933;">;</span>
        $<span style="color: #009900;">&#40;</span>ui.<span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;-webkit-transform&quot;</span><span style="color: #339933;">,</span> newTranslation<span style="color: #009900;">&#41;</span>
                    .<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;transform&quot;</span><span style="color: #339933;">,</span> newTranslation<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #006600; font-style: italic;">// ... then remove that override within a snapshot so that it transitions.</span>
        $<span style="color: #009900;">&#40;</span>ui.<span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">snapshotStyles</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;dragging&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">releaseSnapshot</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Here’s the result. <strong>Be sure to try this in a desktop browser, not a phone/tablet, because jQuery UI sortable doesn’t handle touch events by default</strong>. Also if you’re on IE, be sure to use IE10+ or you won’t see animations.</p>
<p><iframe style="width: 100%; height: 525px;" src="http://jsfiddle.net/Mk4YH/embedded/result,js,html,css" frameborder="0"></iframe></p>
<p><i>Weird flicker in Chrome? It only happens when the example is in this iframe. Try the &#8220;Edit in JSFiddle&#8221; link to see it without.</i></p>
<p>… and here’s a two-dimensional grid, with the same drag-drop code:</p>
<p><iframe style="width: 100%; height: 330px;" src="http://jsfiddle.net/VRPdc/embedded/result,js,html,css" frameborder="0"></iframe></p>
<p>If you want better support for phones and tables, <a href="http://stackoverflow.com/questions/4641590/jquery-ui-sortable-how-to-get-it-work-on-ipad-touchdevices" target="_blank">there are various ways of upgrading jQuery UI “sortable” to respond to touch events</a>. Or write your own.</p>
<p><!-- Firefox can't play MP4, so dynamically replace the above with Flash --><br />
<script type="text/javascript">
   (function() {
       var v = document.createElement('video'),
           isIE = navigator.userAgent.indexOf("MSIE") >= 0;
       if (v.canPlayType) {
           if (v.canPlayType('video/mp4').replace(/no/, '')) {
               return;
           }
       }
       if (isIE) {
           return; // Video insertion fails on IE<9, so let's just not show the video there
       }
       // MP4 not supported
       var vid = document.getElementById('list-example-video'),
           div = document.createElement('div');
       vid.parentNode.insertBefore(div, vid);
       vid.parentNode.removeChild(vid);
       div.innerHTML = '<iframe src="http://archive.org/embed/Dragdrop60" width="640" height="330" frameborder="0" webkitallowfullscreen="true" mozallowfullscreen="true" allowfullscreen></iframe>';
   })();
</script></p>
<div class="feedflare">
<a href="http://feeds.codeville.net/~ff/SteveCodeville?a=QS5qgg6VmYM:aq0K9h-pagE:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/SteveCodeville?i=QS5qgg6VmYM:aq0K9h-pagE:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.codeville.net/~ff/SteveCodeville?a=QS5qgg6VmYM:aq0K9h-pagE:G79ilh31hkQ"><img src="http://feeds.feedburner.com/~ff/SteveCodeville?d=G79ilh31hkQ" border="0"></img></a> <a href="http://feeds.codeville.net/~ff/SteveCodeville?a=QS5qgg6VmYM:aq0K9h-pagE:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/SteveCodeville?i=QS5qgg6VmYM:aq0K9h-pagE:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.codeville.net/~ff/SteveCodeville?a=QS5qgg6VmYM:aq0K9h-pagE:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/SteveCodeville?d=yIl2AUoC8zA" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/SteveCodeville/~4/QS5qgg6VmYM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.stevensanderson.com/2013/03/15/animating-lists-with-css-3-transitions/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		<feedburner:origLink>http://blog.stevensanderson.com/2013/03/15/animating-lists-with-css-3-transitions/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=animating-lists-with-css-3-transitions</feedburner:origLink></item>
		<item>
		<title>Touralot: an iOS app built with PhoneGap, Knockout, and Azure Mobile Services</title>
		<link>http://feeds.codeville.net/~r/SteveCodeville/~3/_kBZCzfReoc/</link>
		<comments>http://blog.stevensanderson.com/2013/03/13/touralot-an-ios-app-built-with-phonegap-knockout-and-azure-mobile-services/#comments</comments>
		<pubDate>Wed, 13 Mar 2013 12:52:21 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Touralot]]></category>

		<guid isPermaLink="false">http://blog.stevensanderson.com/?p=603</guid>
		<description><![CDATA[ul.loose-list > li { margin-bottom: 8px } As a weekend project for the past few months, I’ve been building my first real mobile app: Touralot. Finally, it’s done, and it’s been approved on the iOS App Store! Touralot lets you [...]]]></description>
			<content:encoded><![CDATA[<style type="text/css">ul.loose-list > li { margin-bottom: 8px }</style>
<p>As a weekend project for the past few months, I’ve been building my first real mobile app: <strong>Touralot</strong>. Finally, it’s done, and it’s been <a href="https://itunes.apple.com/us/app/touralot/id602481226" target="_blank">approved on the iOS App Store</a>!</p>
<p>Touralot lets you <strong>publish your own web-based guides to your favourite places to go and see</strong>. Maybe you’re off on vacation and would like to build a record of cool places you see, add <strong>photos</strong>, <strong>ratings</strong>, <strong>descriptions</strong>, plot them on a <strong>map</strong>, and then <strong>publish</strong> it all to the web. Or maybe you’re at home and are particularly knowledgeable about local restaurants, kids’ play centres, or whatever, and want to share your expertise.</p>
<p>This video gives a sense of the user experience:</p>
<p><video id="touralot-video" style="background-color: silver" controls height="762" width="480"><source type="video/mp4" src="https://archive.org/download/TouralotVideo/touralot-video-60.mp4" /><b style="color: red">Your browser does not support the <i>video</i> tag.</b> </video></p>
<p><i>Video looks blurry? Use a different browser, or <a href='https://archive.org/download/TouralotVideo/touralot-video-60.mp4' target='_blank'>open the video directly</a>.</i></p>
<p>If you’re on an iPhone, you can <a href="https://itunes.apple.com/us/app/touralot/id602481226" target="_blank">get it now from the App Store</a> (free).</p>
<h4>The technology</h4>
<p>Touralot is a <a href="http://phonegap.com/">Cordova/PhoneGap</a> app, with the UI powered by <a href="http://knockoutjs.com/">Knockout.js</a>, and a backend data service provided by <a href="http://www.windowsazure.com/en-us/develop/mobile/">Windows Azure Mobile Services</a> (and a couple of other Azure facilities). It works entirely offline, except of course at the point where the user wants to log in and publish their stuff:</p>
<p><a href="http://blog.stevensanderson.com/wp-content/uploads/2013/03/Screen-Shot-2013-03-13-at-12.12.01.png"><img title="Screen Shot 2013-03-13 at 12.12.01" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="Screen Shot 2013-03-13 at 12.12.01" src="http://blog.stevensanderson.com/wp-content/uploads/2013/03/Screen-Shot-2013-03-13-at-12.12.01_thumb.png" width="630" height="391"></a></p>
<p>Why did I use HTML/JS and PhoneGap instead of native code (e.g., Objective-C)?</p>
<ul class="loose-list">
<li>I wanted to see <strong>how far I could push HTML/JS to match the quality experience that people expect from native apps</strong>. This includes:
<ul style="margin-bottom: 4px">
<li>Standardised UI elements that respond intuitively to touch, drag/drop, and swipe gestures
<li>Butter-smooth hardware-accelerated transitions
<li>Retina-sharp professional artwork
<li>Offline/syncing support</li>
</ul>
<p>Assess the result for yourself &#8211; I don’t imagine that it would even occur to normal users, at least on reasonably up-to-date devices (iPhone 4S/5), that this isn’t native.
<li>This app can now be made <strong>cross-platform</strong> with relative ease. There’ll be some restyling effort involved, since Android and Windows Phone have different UI conventions, but hopefully it will mainly just be CSS changes.
<li>I don’t know much Objective-C…</li>
</ul>
<h4>Coming up</h4>
<p>Over the next few weeks I’m planning a series of blog posts to describe many of the techniques I used and challenges I went through while developing this app, along with recommendations and tips for PhoneGap development. Some of these techniques are well known, some might even be original…</p>
<p><!-- Firefox can't play MP4, so dynamically replace the above with Flash --><br />
<script type="text/javascript">
   (function() {
       var v = document.createElement('video'),
           isIE = navigator.userAgent.indexOf("MSIE") >= 0;
       if (v.canPlayType) {
           if (v.canPlayType('video/mp4').replace(/no/, '')) {
               return;
           }
       }
       if (isIE) {
           return; // Video insertion fails on IE<9, so let's just not show the video there
       }
       // MP4 not supported
       var vid = document.getElementById('touralot-video'),
           div = document.createElement('div');
       vid.parentNode.insertBefore(div, vid);
       vid.parentNode.removeChild(vid);
       div.innerHTML = '<iframe src="http://archive.org/embed/TouralotVideo" width="480" height="762" frameborder="0" webkitallowfullscreen="true" mozallowfullscreen="true" allowfullscreen></iframe>';
   })();
</script></p>
<div class="feedflare">
<a href="http://feeds.codeville.net/~ff/SteveCodeville?a=_kBZCzfReoc:_AMzU-n8BXQ:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/SteveCodeville?i=_kBZCzfReoc:_AMzU-n8BXQ:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.codeville.net/~ff/SteveCodeville?a=_kBZCzfReoc:_AMzU-n8BXQ:G79ilh31hkQ"><img src="http://feeds.feedburner.com/~ff/SteveCodeville?d=G79ilh31hkQ" border="0"></img></a> <a href="http://feeds.codeville.net/~ff/SteveCodeville?a=_kBZCzfReoc:_AMzU-n8BXQ:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/SteveCodeville?i=_kBZCzfReoc:_AMzU-n8BXQ:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.codeville.net/~ff/SteveCodeville?a=_kBZCzfReoc:_AMzU-n8BXQ:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/SteveCodeville?d=yIl2AUoC8zA" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/SteveCodeville/~4/_kBZCzfReoc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.stevensanderson.com/2013/03/13/touralot-an-ios-app-built-with-phonegap-knockout-and-azure-mobile-services/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		<feedburner:origLink>http://blog.stevensanderson.com/2013/03/13/touralot-an-ios-app-built-with-phonegap-knockout-and-azure-mobile-services/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=touralot-an-ios-app-built-with-phonegap-knockout-and-azure-mobile-services</feedburner:origLink></item>
		<item>
		<title>Knockout 2.2.0 released</title>
		<link>http://feeds.codeville.net/~r/SteveCodeville/~3/jOMVk15K55s/</link>
		<comments>http://blog.stevensanderson.com/2012/10/29/knockout-2-2-0-released/#comments</comments>
		<pubDate>Mon, 29 Oct 2012 10:57:36 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Knockout]]></category>

		<guid isPermaLink="false">http://blog.stevensanderson.com/?p=591</guid>
		<description><![CDATA[It&#8217;s been five months since the last significant Knockout release, so it&#8217;s about time for another! The core team and many contributors have been hard at work adding some sweet new features, performance upgrades, architectural improvements, and bug fixes. After [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been five months since the last significant Knockout release, so it&#8217;s about time for another! The core team and many contributors have been hard at work adding some sweet new features, performance upgrades, architectural improvements, and bug fixes. After all this, the final code file is <strong>smaller</strong> than the previous version <img src='http://blog.stevensanderson.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>You can <a href="https://github.com/SteveSanderson/knockout/downloads">download Knockout 2.2.0 now</a> from GitHub where we also have the <a href="https://github.com/SteveSanderson/knockout/">source</a>, and see the <a href="http://knockoutjs.com/">updated documentation</a> and <a href="http://knockoutjs.com/spec/runner.html">test suite</a>.</p>
<h4>What&#8217;s improved?</h4>
<p>The theme for KO 2.2.0 was &#8220;all the small things&#8221;. We processed and closed many, many, <em>many</em> work items tracked on GitHub, fixed a bunch of niggly little issues, improved our code structure, and put in some enhancements we&#8217;ve been wanting for a while.</p>
<p>My favourite enhancement is that the <strong>foreach</strong> binding will now detect when you have reordered elements in an array, and will simply move the corresponding DOM elements into the new order (previously, a &#8220;move&#8221; was handled as an &#8220;add&#8221; and a &#8220;delete&#8221;). You don&#8217;t have to change your code to enable this &#8211; it just works, even if you&#8217;re moving, adding, and deleting multiple items as a single atomic operation. Example:</p>
<p><iframe src="http://jsfiddle.net/yATaq/embedded/result,html,js/" style="width: 100%; height: 285px;" frameborder="0"></iframe></p>
<p>If you want to animate the movements of DOM nodes into their new positions, you can make use of the new <strong>beforeMove</strong> and <strong>afterMove</strong> callbacks.</p>
<p>We&#8217;ve also made some features work more like you might always have thought they should work. For example, the <strong>css</strong> binding can now attach programmatically-generated CSS class names to elements (previously, it was limited to toggling predefined CSS class names). Example:</p>
<p><iframe src="http://jsfiddle.net/qRmfH/embedded/result,js,css,html/" style="width: 100%; height: 225px;" frameborder="0"></iframe></p>
<p>Other improvements include: </p>
<ul>
<li>The <strong>with</strong>, <strong>if</strong>, and <strong>ifnot</strong> bindings have been enhanced to preserve their original DOM elements on initial binding, so they are lighter and won&#8217;t unnecessarily strip out any special behaviours inserted by third-party libraries. I know a lot of people asked for this.</li>
<li>The dependency detection mechanism is now smarter in many places to avoid registering subscriptions that would be unnecessary no-ops</li>
<li>Support for IE10 (well, we basically already supported it, but there was one edge-case issue with autocompletion that we fixed)</li>
<li>Improved AMD support (the <strong>ko</strong> variable is now available in the context of all custom binding handlers, even if it isn&#8217;t in global scope)</li>
<li>The <strong>text</strong> binding can now be used in a virtual element (e.g., <tt>&lt;!--ko text: myValue--&gt;&lt;!--/ko--&gt;)</tt></li>
<li>Observable and computed properties have a new <strong>peek</strong> function for advanced control over dependency detection</li>
<li>Bugfixes</li>
</ul>
<p>Big thanks to Michael Best and Ryan Niemeyer &#8211; my fellow KO core team members &#8211; and the many community members who contributed features, specs, and clearly-reproducible bug reports <img src='http://blog.stevensanderson.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div class="feedflare">
<a href="http://feeds.codeville.net/~ff/SteveCodeville?a=jOMVk15K55s:sbSARZbH26w:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/SteveCodeville?i=jOMVk15K55s:sbSARZbH26w:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.codeville.net/~ff/SteveCodeville?a=jOMVk15K55s:sbSARZbH26w:G79ilh31hkQ"><img src="http://feeds.feedburner.com/~ff/SteveCodeville?d=G79ilh31hkQ" border="0"></img></a> <a href="http://feeds.codeville.net/~ff/SteveCodeville?a=jOMVk15K55s:sbSARZbH26w:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/SteveCodeville?i=jOMVk15K55s:sbSARZbH26w:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.codeville.net/~ff/SteveCodeville?a=jOMVk15K55s:sbSARZbH26w:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/SteveCodeville?d=yIl2AUoC8zA" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/SteveCodeville/~4/jOMVk15K55s" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.stevensanderson.com/2012/10/29/knockout-2-2-0-released/feed/</wfw:commentRss>
		<slash:comments>32</slash:comments>
		<feedburner:origLink>http://blog.stevensanderson.com/2012/10/29/knockout-2-2-0-released/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=knockout-2-2-0-released</feedburner:origLink></item>
		<item>
		<title>Using JSHint inside Visual Studio – the basics</title>
		<link>http://feeds.codeville.net/~r/SteveCodeville/~3/mJvd7GpGBGQ/</link>
		<comments>http://blog.stevensanderson.com/2012/08/17/using-jshint-inside-visual-studio-the-basics/#comments</comments>
		<pubDate>Fri, 17 Aug 2012 11:11:46 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://blog.stevensanderson.com/?p=578</guid>
		<description><![CDATA[JSHint is great. It’s a linting tool for JavaScript: a simple tool that can very often spot your mistakes before you do. It can save you from a lot of tedious debugging, lets you refactor JavaScript code with greater confidence, [...]]]></description>
			<content:encoded><![CDATA[<p><strong>JSHint is great</strong>. It’s a linting tool for JavaScript: a simple tool that can very often spot your mistakes before you do. It can save you from a lot of tedious debugging, lets you refactor JavaScript code with greater confidence, and reduces the chances of you deploying broken code to your production server.</p>
<p>I’ve been relying on it day-to-day for the last few months while working on a large JavaScript application, and now I’d be very distressed if I had to work without this instant, zero-effort safety net. So, what does it do?</p>
<ol>
<li>It <strong>identifies definite, objective errors in your code</strong> (e.g., mistyped keywords, mistyped variable names, mismatched parentheses, and other syntactical slip-ups) before they end up in your browser.
<li>Optionally, it <strong>enforces some basic code style consistency rules</strong> (e.g., no trailing whitespace, no use of the == operator, etc.), depending on how you configure it</li>
</ol>
<p>Feature 2 – enforcing style consistency –&nbsp; isn’t hugely beneficial for small, single-developer projects. But for longer-lived, multiple-developer projects, your team will surely benefit in the long run from a few consistency guarantees.</p>
<p>Feature 1 – typo detection – is the killer benefit from my point of view. I’ll show you a good example in a moment.</p>
<p>As you can probably guess, there are two common ways to use JSHint on a project:</p>
<ul>
<li><strong>By integrating it into your build process</strong> (on a CI server). This enforces team-wide consistency.
<li><strong>By integrating it into your IDE</strong>. This gives you instant feedback as you code.</li>
</ul>
<p>My current project uses both, but primarily I appreciate having it in my IDE. So, <strong>in this post I’ll focus on a Visual Studio extension that makes it easy</strong>. Of course you can also find JSHint plugins for many other IDEs or code editors, such as my other favourite: <a href="https://github.com/uipoet/sublime-jshint">Sublime Text 2</a>.</p>
<h4>Why it matters</h4>
<p>Here’s an exaggeratedly simple example. Let’s say you have a perfectly OK function like this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript"><span style="color: #003366; font-weight: bold;">function</span> averageHeight<span style="color: #009900;">&#40;</span>heights<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> sum <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> index<span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>index <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> index <span style="color: #339933;">&lt;</span> heights.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> index <span style="color: #339933;">+=</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        sum <span style="color: #339933;">+=</span> heights<span style="color: #009900;">&#91;</span>index<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">return</span> sum <span style="color: #339933;">/</span> heights.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> myAverageHeight <span style="color: #339933;">=</span> averageHeight<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1.75</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1.78</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1.82</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now you decide you want to rename the function just to “average”, since it’s not really specific to heights at all. So you go ahead and change the function signature. But you forget to the change anything else:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript"><span style="color: #003366; font-weight: bold;">function</span> average<span style="color: #009900;">&#40;</span>values<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// &lt;-- This is the only line I remembered to change</span>
    <span style="color: #003366; font-weight: bold;">var</span> sum <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> index<span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>index <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> index <span style="color: #339933;">&lt;</span> heights.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> index <span style="color: #339933;">+=</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        sum <span style="color: #339933;">+=</span> heights<span style="color: #009900;">&#91;</span>index<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">return</span> sum <span style="color: #339933;">/</span> heights.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> myAverageHeight <span style="color: #339933;">=</span> averageHeight<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1.75</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1.78</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1.82</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now you press Ctrl+S to save the changes. In the tiniest fraction of a second, and without waiting to build your server-side code, the JSHint extension I&#8217;m about to show you will return its verdict about your file:</p>
<p><a href="http://blog.stevensanderson.com/wp-content/uploads/2012/08/image.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blog.stevensanderson.com/wp-content/uploads/2012/08/image_thumb.png" width="651" height="206"></a></p>
<p>Well, you’re going to notice this! The first three errors tell you exactly where you’ve forgotten to change “heights” to “values”, and they won’t go away until you fix every last one. The fourth warns you that you’re trying to invoke a function that no longer exists. The fifth tells you it’s quite pointless to have this new “average” function, because nobody uses it.</p>
<p>Even in this simple case it’s very nice to know exactly how many times you forgot to rename the “heights” variable. You can imagine how valuable (and reassuring) it is in more complex refactorings such as extracting a function.</p>
<p>I’m not saying this eliminates the need for automated testing. This merely adds to JavaScript a subset of the kinds of code validity checks that you might be accustomed to in C# or another strongly-typed language.</p>
<p>In addition, the kinds of optional common stylistic rules that JSHint can enforce include:</p>
<ul>
<li>Require braces around for/if/while/etc blocks</li>
<li>Don’t leave “debugger” statements in your code</li>
<li>Always use single/double quote characters</li>
<li>Allow only one “var” statement per function scope, to ensure you don’t get hit by the subtle <a href="http://blog.stevensanderson.com/2007/09/17/when-is-a-javascript-closure-not-really-a-closure/">that-closure-isn’t-really-closed</a> bug</li>
<li>Well, just look at the <a href="http://www.jshint.com/">list of “warn” options on the homepage</a></li>
</ul>
<h4>Possible drawbacks of JSHint</h4>
<p>In the interest of balance, let me try to give you advance notice of a few downsides to using JSHint, which actually apply to pretty much any linting tool:</p>
<ul>
<li><strong>It’s best when you’re writing fresh new code</strong>. When writing new code files, you can keep them compliant with your rules with little effort right from the beginning. But it’s not easy to start using JSHint on a large legacy codebase, because it will initially report thousands of violations. You can either invest a big chunk of time in cleaning everything up, or you can use <strong>/*ignore jslint */</strong> comments to ignore your old files, removing those comments one-by-one as you clean up each file over the long term.</li>
<li><strong>It’s reliable, but not deeply sophisticated</strong>. JavaScript is fully dynamic, so the linter can’t know whether or not a given object will have a certain property at runtime. So, if for example you’re renaming <em>properties</em> as opposed to <em>variables</em>, don’t expect JSHint to find all the places where the old property name is still referenced. Don’t get caught believing that “<em>no JSHint errors”</em> guarantees “<em>no bugs”</em>.</li>
<li><strong>It needs a bit of configuration to give the best results</strong>. Depending on how you and your IDE work, you’ll need to toggle a bunch of checkboxes in the early days. You’ll get very annoyed if your IDE persistently inserts or reformats code in a way that violates your JSHint rules. Change the IDE settings or the JSHint settings or both.</li>
<li><strong>You need to start tracking global variables</strong>. In the long run, this is a benefit not a drawback, but it might feel like extra work at first. If you use third-party libraries whose APIs live in a global (e.g., <strong>$</strong> for jQuery, <strong>ko</strong> for Knockout), you must explicitly tell JSHint about them otherwise it thinks you’re referencing undefined things. Eventually, though, you’ll be glad to have an unambiguous list of your dependencies.</li>
</ul>
<h4>So, what’s JSLint and how does it relate to JSHint?</h4>
<p>Historically, <a href="http://jshint.com/">JSHint</a> is derived from the longer-established <a href="http://jslint.com/">JSLint</a> project from Douglas Crockford. The <a href="http://anton.kovalyov.net/2011/02/20/why-i-forked-jslint-to-jshint/">reason why JSHint exists</a> is just to offer more flexibility: JSHint has a modest set of rules derived from common use, whereas JSLint is stricter and requires you to code exactly like the legendary Mr Crockford does.</p>
<p>The following Visual Studio extension lets you choose between JSLint and JSHint with a simple config option. Try out both and see which one you like.</p>
<h4>Integrating JSHint into Visual Studio 2010</h4>
<p>Yes, I know Visual Studio 2012 was just released this week! We’ll get to that in a minute. Not everyone upgrades during the first week…</p>
<p>The VS extension I’ve been using for the last few months is called <a href="http://visualstudiogallery.msdn.microsoft.com/961e6734-cd3a-4afb-a121-4541742b912e">JSLint for Visual Studio 2010</a>. It’s free and <a href="http://jslint4vs2010.codeplex.com/">open source</a>, and you can install it directly from inside VS. Go to <strong>Tools</strong> &gt; <strong>Extension Manager</strong>. Click <strong>Online Gallery</strong> then in the search box (top-right), enter <strong>jslint</strong>. </p>
<p><a href="http://blog.stevensanderson.com/wp-content/uploads/2012/08/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://blog.stevensanderson.com/wp-content/uploads/2012/08/image_thumb1.png" width="871" height="229"></a></p>
<p>Once it’s installed, you’ll find a new menu entry: <strong>Tools</strong> &gt; <strong>JS Lint Options</strong>. Personally, I like to set it up like this:</p>
<p><a href="http://blog.stevensanderson.com/wp-content/uploads/2012/08/image2.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://blog.stevensanderson.com/wp-content/uploads/2012/08/image_thumb2.png" width="757" height="226"></a></p>
<p><a href="http://blog.stevensanderson.com/wp-content/uploads/2012/08/image3.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://blog.stevensanderson.com/wp-content/uploads/2012/08/image_thumb3.png" width="756" height="208"></a></p>
<p>I’m not even going to discuss the multitude of code style options represented by the big grid of checkboxes. If you’ve coded JavaScript for a while, you probably have plenty of opinions of your own.</p>
<p>Notice that you can export and import configurations as XML files. You’ll probably want to store a standard team-wide setup in source control.</p>
<p>Now when you’ve got a JavaScript file open, any time you hit <strong>Ctrl+S</strong>, the Visual Studio extension will populate the IDE’s “Error” pane with any issues it found – extremely quickly, because it already has a live JavaScript runtime loaded in memory. Double-click to jump to that line. Either fix it, or modify your config settings to make the linter more tolerant.</p>
<p><strong>Issues with this extension</strong></p>
<p>Of course, it’s not totally perfect. Here are a couple of minor niggles I’ve experienced with this extension:</p>
<ul>
<li>I don’t see a way of making it load project-specific rulesets. This means that all of the projects you work on will need to share the same configuration (or you have to keep importing different configurations manually).</li>
<li>It collects errors from every JavaScript file you open. So for example if you open <strong>jquery-x-x-x.js</strong> to see how something is implemented, JSLint for VS2010 will freak out and report more than 1,000 errors. The errors don’t go away when you close that particular tab, so you must manually right-click on the error list and choose <strong>Clear JS Lint Errors</strong>. Not a big deal, but adds a touch of friction.</li>
</ul>
<h4>Integrating JSHint into Visual Studio 2012</h4>
<p>Unfortunately, there isn’t yet a “JSLint for Visual Studio 2012” on the extensions gallery, or at least not one that I could find. And if you try to download <a href="http://visualstudiogallery.msdn.microsoft.com/961e6734-cd3a-4afb-a121-4541742b912e">the .vsix file for the VS2010 version</a>, it won’t let you install it into VS2012:</p>
<p><a href="http://blog.stevensanderson.com/wp-content/uploads/2012/08/image4.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://blog.stevensanderson.com/wp-content/uploads/2012/08/image_thumb4.png" width="488" height="281"></a></p>
<p>So, how come the screenshot earlier in this blog post shows it running in VS2012? Well, I guess the extension’s developers haven’t got round to testing on VS2012 yet, but if you’re impatient and want it installed <em>right now</em>, it’s just a matter of modifying the “manifest” in the .vsix file to make it allow installation. Here’s what I did:</p>
<ol>
<li>Rename <strong>JSLint.VS2010.vsix</strong> to <strong>JSLint.VS2010.zip</strong>. Turns out these things are really zip archives. Extract the files to a temporary folder.</li>
<li>Open <strong>extension.vsixmanifest</strong> in Notepad.</li>
<li>Find <strong>&lt;VisualStudio Version=&#8221;10.0&#8243;&gt;</strong> and change it to <strong>&lt;VisualStudio Version=&#8221;11.0&#8243;&gt;</strong>.</li>
<li>Zip all the files back up, and rename the result so it has a <strong>.vsix</strong> extension.</li>
<li>Install it.</li>
</ol>
<p>This is <strong>totally unsupported, off piste, entirely at your own risk, and no technical support questions will even be acknowledged much less answered</strong>. But hey, it seems happy enough on my machine:</p>
<p><a href="http://blog.stevensanderson.com/wp-content/uploads/2012/08/image5.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://blog.stevensanderson.com/wp-content/uploads/2012/08/image_thumb5.png" width="734" height="156"></a></p>
<p>Hopefully the extension’s developers will get a chance to make VS2012 support official in the near future. Maybe you (yes – actually <em>you</em>!) could <a href="http://jslint4vs2010.codeplex.com/SourceControl/list/patches">submit a patch</a>. This is open source, after all.</p>
<div class="feedflare">
<a href="http://feeds.codeville.net/~ff/SteveCodeville?a=mJvd7GpGBGQ:Z0xDsi1BIk0:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/SteveCodeville?i=mJvd7GpGBGQ:Z0xDsi1BIk0:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.codeville.net/~ff/SteveCodeville?a=mJvd7GpGBGQ:Z0xDsi1BIk0:G79ilh31hkQ"><img src="http://feeds.feedburner.com/~ff/SteveCodeville?d=G79ilh31hkQ" border="0"></img></a> <a href="http://feeds.codeville.net/~ff/SteveCodeville?a=mJvd7GpGBGQ:Z0xDsi1BIk0:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/SteveCodeville?i=mJvd7GpGBGQ:Z0xDsi1BIk0:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.codeville.net/~ff/SteveCodeville?a=mJvd7GpGBGQ:Z0xDsi1BIk0:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/SteveCodeville?d=yIl2AUoC8zA" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/SteveCodeville/~4/mJvd7GpGBGQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.stevensanderson.com/2012/08/17/using-jshint-inside-visual-studio-the-basics/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		<feedburner:origLink>http://blog.stevensanderson.com/2012/08/17/using-jshint-inside-visual-studio-the-basics/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=using-jshint-inside-visual-studio-the-basics</feedburner:origLink></item>
		<item>
		<title>Rich JavaScript Applications – the Seven Frameworks (Throne of JS, 2012)</title>
		<link>http://feeds.codeville.net/~r/SteveCodeville/~3/hOoxjpMxgw8/</link>
		<comments>http://blog.stevensanderson.com/2012/08/01/rich-javascript-applications-the-seven-frameworks-throne-of-js-2012/#comments</comments>
		<pubDate>Wed, 01 Aug 2012 13:07:05 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[SPA]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.stevensanderson.com/?p=490</guid>
		<description><![CDATA[table.gridtable { border-collapse: collapse; margin-bottom: 8px; } table.gridtable td { border: 1px solid silver; vertical-align: top; padding: 6px; } table.gridtable p:last-child { margin-bottom: 0; padding-bottom: 0; } A week ago was the Throne of JS conference in Toronto, perhaps the [...]]]></description>
			<content:encoded><![CDATA[<style type="text/css">
   table.gridtable { border-collapse: collapse; margin-bottom: 8px; } 
   table.gridtable td { border: 1px solid silver; vertical-align: top; padding: 6px; }
   table.gridtable p:last-child { margin-bottom: 0; padding-bottom: 0; }
</style>
<p>A week ago was the <em><a href="http://throneofjs.com">Throne of JS</a></em> conference in Toronto, perhaps the most interesting and different conference I&#8217;ve been to for a while. Quoting its website:</p>
<blockquote><p><em>It&#8217;s no longer good enough to build web apps around full page loads and then &#8220;progressively enhance&#8221; them to behave more dynamically. Building apps which are fast, responsive and modern require you to completely rethink your approach.</em></p></blockquote>
<p>The premise was to take the seven top JavaScript frameworks/libraries for single-page and rich JavaScript applications &mdash; <strong>AngularJS, Backbone, Batman, CanJS, Ember, Meteor, Knockout, Spine</strong> &mdash; get the creators of all of them in one location, and compare the technologies head to head.*</p>
<p><u>Disclaimer:</u> I was there to represent Knockout, so obviously I&#8217;m not neutral. In this post my focus is on what the creators said about the scope and philosophy of their technologies, and not so much on whether I agree or disagree.</p>
<p><small><em>* Yes, I know that&#8217;s eight frameworks, not seven. This part was never fully explained&#8230;</em></small></p>
<h4>TL;DR Executive Summary</h4>
<ul>
<li> For many web developers, it&#8217;s now taken for granted that such <strong>client-side frameworks are the way to build rich web apps</strong>. If you&#8217;re not using one, you&#8217;re either not building an application, or you&#8217;re just missing out.</li>
<li> There&#8217;s <strong>lots of consensus</strong> among the main frameworks about how to do it (Model-View-* architecture, declarative bindings, etc. &mdash; details below), so to some extent you get similar benefits whichever you choose.</li>
<li> Some major <strong>philosophical differences</strong> remain, especially the big split between frameworks and libraries. Your choice will deeply influence your architecture.</li>
<li> The conference itself was stylish and upbeat, with a lot of socialising and conversations across different technology groups. I&#8217;d like to see more like this.</li>
</ul>
<h4>Technologies: Agreement and Disagreement</h4>
<p>As each SPA technology was presented, some fairly clear patterns of similarity and difference emerged.</p>
<p><strong>Agreement: Progressive enhancement isn&#8217;t for building real apps.</strong></p>
<p>All the technologies follow from the view that serious JavaScript applications require proper data models and ability to do client-side rendering, not just server rendering plus some Ajax and jQuery code.</strong></p>
<p>Quote from Jeremy Ashkenas, the Backbone creator: &#8220;<em>At this point, saying &#8216;single-page application&#8217; is like saying &#8216;horseless carriage&#8217;</em>&#8221; (i.e., it&#8217;s not even a novelty any more).</p>
<p><strong>Agreement: Model-View-Whatever.</strong></p>
<p> All the technologies made use of model-view separation. Some specifically talked about MVC, some about MVVM, and some specifically refused to define the third piece (just saying it&#8217;s models, views, and some kind of application thing that makes them work together). The net result in each case was similar.</p>
<p><strong>Agreement: Data binding is good.</strong></p>
<p> All except Backbone and Spine have a built-in notion of declarative data binding in their views (Backbone instead has a &#8220;bring your own view technology&#8221; design).</p>
<p><strong>Agreement: IE 6 is dead already.</strong></p>
<p> In a panel discussion, most framework creators said their IE support focus was limited to version 7+ (in fact, Ember and AngularJS only go for IE8, and Batman requires an ES5 shim to run on IE older than v9). This is the way of things to come: even <a href="http://blog.jquery.com/2012/06/28/jquery-core-version-1-9-and-beyond/">jQuery 2 is set to drop support for IE older than v9</a>.</p>
<p>The only stalwarts here appear to be Backbone and Knockout which support IE6+ (I don&#8217;t know about Backbone&#8217;s internals, but for KO this means transparently working around a lot of crazy edge-case IE6/7 rendering and eventing weirdnesses).</p>
<p><strong>Agreement: Licensing and source control.</strong></p>
<p> Every single one is MIT licensed and hosted on GitHub.</p>
<p><strong>Disagreement: Libraries vs frameworks.</strong></p>
<p> This is the biggest split right now. You could group them as follows:</p>
<table class="gridtable" width="100%">
<tbody>
<tr>
<td>
          <strong>Libraries</strong>
        </td>
<td>
          <strong>Frameworks</strong>
        </td>
</tr>
<tr>
<td>
<p>Backbone (9552)</p>
<p>Knockout (2357)</p>
<p>Spine (2017)</p>
<p>CanJS (321)</p>
</td>
<td>
<p>Ember (3993)</p>
<p>AngularJS (2925)</p>
<p>Batman (958)</p>
<p>Meteor (4172) &mdash; unusual, see later</p>
</td>
</tr>
</tbody>
</table>
<p><em>Numbers in brackets are a point-in-time snapshot of the number of GitHub watchers, as a crude indicator of relative influence.</em></p>
<p>What does this mean?</p>
<ul>
<li><strong>Libraries</strong> slot into your existing architecture and add specific functionality</li>
<li><strong>Frameworks</strong> give you an architecture (file structure, etc.) that you are meant to follow and, if you do, are intended to handle all common requirements</li>
</ul>
<p>By far the most passionate advocate of the framework model is Ember, whose creator Yehuda Katz is formerly of the Rails and SproutCore projects (similar philosophy). His argument was that anything less is just not ambitious enough and isn&#8217;t seriously advancing the state of the art. The counter-argument is that libraries are more focused, and hence can be easier to learn, adopt, customize, and help minimise project risk because your architecture isn&#8217;t so deeply tied to a specific external project. Based on my conversations, I&#8217;d say the audience was split and supported both sides of this debate.</p>
<p>Note that AngularJS is arguably somewhere in between library and framework: it doesn&#8217;t require a particular layout of files at development time (library-like), but at runtime it provides an &#8220;app lifecycle&#8221; that you fit your code into (framework-like). I&#8217;m listing it as a framework because that&#8217;s the terminology the AngularJS team prefers.</p>
<p><strong>Disagreement: What&#8217;s flexible, what&#8217;s integrated.</strong></p>
<p> Each technology has different levels of prescriptiveness:</p>
<table class="gridtable">
<tbody>
<tr>
<td valign="top"></td>
<td valign="top">
<p><strong>Views</strong></p>
</td>
<td valign="top">
<p><strong>URL routing</strong></p>
</td>
<td>
<p><strong>Data storage</strong></p>
</td>
</tr>
<tr>
<td>
<p><strong>AngularJS</strong></p>
</td>
<td>
<p>Built-in DOM-based templates (mandatory)</p>
</td>
<td>
<p>Built-in (optional)</p>
</td>
<td>
<p>Built-in system (optional)</p>
</td>
</tr>
<tr>
<td>
<p><strong>Backbone</strong></p>
</td>
<td>
<p>Choose your own (most used handlebars.js, a string-based template library)</p>
</td>
<td>
<p>Built-in (optional)</p>
</td>
<td>
<p>Built-in (overridable)</p>
</td>
</tr>
<tr>
<td>
<p><strong>Batman</strong></p>
</td>
<td>
<p>Built-in DOM-based templates (mandatory)</p>
</td>
<td>
<p>Built-in (mandatory)</p>
</td>
<td>
<p>Built-in system (mandatory)</p>
</td>
</tr>
<tr>
<td>
<p><strong>CanJS</strong></p>
</td>
<td>
<p>Built-in string-based templates (mandatory)</p>
</td>
<td>
<p>Built in (optional)</p>
</td>
<td>
<p>Built in (optional)</p>
</td>
</tr>
<tr>
<td>
<p><strong>Ember</strong></p>
</td>
<td>
<p>Built-in string-based templates (mandatory)</p>
</td>
<td>
<p>Built-in (mandatory)</p>
</td>
<td>
<p>Built-in (overridable)</p>
</td>
</tr>
<tr>
<td>
<p><strong>Knockout</strong></p>
</td>
<td>
<p>Built-in DOM-based templates (optional, can do string-based too)</p>
</td>
<td>
<p>Choose your own (most use sammy.js or history.js)</p>
</td>
<td>
<p>Choose your own (e.g., knockout.mapping or just $.ajax)</p>
</td>
</tr>
<tr>
<td>
<p><strong>Meteor</strong></p>
</td>
<td>
<p>Built-in string-based templates (mandatory)</p>
</td>
<td>
<p>Built-in (mandatory?)</p>
</td>
<td>
<p>Built-in (Mongo, mandatory)</p>
</td>
</tr>
<tr>
<td>
<p><strong>Spine</strong></p>
</td>
<td>
<p>Choose your own string-based templates</p>
</td>
<td>
<p>Built-in (optional)</p>
</td>
<td>
<p>Built-in (optional?)</p>
</td>
</tr>
</tbody>
</table>
<p>As expected, whenever a library leaves a decision open, they argue it is better overall to guarantee composablity with arbitrary 3<sup>rd</sup>-party libraries. And the obvious counter-argument is that integration can be more seamless if built-in. Again, based on my conversations, the audience was split and opinions went in all directions &mdash; usually based on how much other technology stack an individual was wedded to.</p>
<p>Quote from Tom Dale of Ember: &#8220;<em>We do a lot of magic, but it&#8217;s <u>good magic</u>, which means it decomposes into sane primitives.</em>&#8220;</p>
<p><strong>Disagreement: String-based vs DOM-based templates</strong></p>
<p>(As shown in the above table.) For string-based templates, almost everyone used Handlebars.js as the template engine, which seems to dominate this space, though CanJS used EJS. Arguments in favour of string-based templates include &#8220;<em>it&#8217;s faster</em>&#8221; (debatable) and &#8220;<em>theoretically, the server can render them too</em>&#8221; (also debatable, as that&#8217;s only true if you can actually run all of your model code on the server, and nobody actually does that in practice).</p>
<p>DOM-based templates means doing control flow (each, if, etc.) purely via bindings in your actual markup and not relying on any external templating library. Argument include &#8220;<em>it&#8217;s faster</em>&#8221; (debatable) and &#8220;<em>the code is easier to read and write, because there&#8217;s no weird chasm between markup and templates, and it&#8217;s obvious how CSS will interact with it</em>&#8220;.</p>
<p>In my view, the strongest argument here came from the AngularJS guys who stated that in the near future, they expect DOM-based templating will be native in browsers, so we&#8217;ll best prepare ourselves for the future by adopting it now. AngularJS is from Google, so they are already working on this with Chromium and standards bodies.</p>
<p><strong>Disagreement: Levels of server-agnosticism</strong></p>
<p>Batman and Meteor express explicit demands on the server: Batman is designed for Rails, and Meteor is its own server. Most others have a goal of being indifferent to what&#8217;s on your server, but in practice the architecture, conventions, and some tooling in Ember leans towards Rails developers. Ember absolutely works on other server technologies too, though today it takes a little more manual setup.</p>
<h4>The technologies &mdash; quick overview</h4>
<p>Here&#8217;s a rundown of the basic details of each technology covered:</p>
<h5>Backbone</h5>
<ul>
<li><strong>Who</strong>: Jeremy Ashkenas and DocumentCloud</li>
<li><strong>What</strong>:
<ul>
<li>Model-View in JavaScript, MIT licensed</li>
<li>Most minimal of all the libraries &mdash; only one file, 800 lines of code!</li>
<li>Extremely tightly-scoped functionality &mdash; just provides REST-persistable models with simple routing and callbacks so you know when to render views (you supply your own view-rendering mechanism).</li>
<li>The best-known of them all, with the most production deployments on big-name sites (perhaps easy to adopt because it&#8217;s so minimal)</li>
</ul>
</li>
<li><strong>Why</strong>:
<ul>
<li>It&#8217;s so small, you can read and understand all of the source before you use it.</li>
<li>No impact on your server architecture or file layout. Can work in a small section of your page &mdash; doesn&#8217;t need to control whole page.</li>
<li>Jeremy seems to exist in a kind of zen state of calm, reasonable opinions about everything. He was like the grown up, supervising all the arguing kids.</li>
</ul>
</li>
<li><strong>Where</strong>: <a href="https://github.com/documentcloud/backbone/">GitHub</a> and <a href="http://backbonejs.org/">own site</a></li>
<li><strong>When</strong>: In production for nearly 2 years now</li>
</ul>
<h5>Meteor</h5>
<ul>
<li><strong>Who</strong>: The <a href="http://www.meteor.com/about/people">Meteor development group</a>, who <a href="http://www.prnewswire.com/news-releases/andreessen-horowitz-matrix-partners-invest-112-million-in-meteor-163687206.html">just raised $11.2 Million</a> so they can do this full-time</li>
<li><strong>What</strong>:
<ul>
<li>Crazy amazing framework from the future, barely reminiscent of anything you&#8217;ve ever seen (except perhaps <a href="http://derbyjs.com/">Derby</a>)</li>
<li>Bridges a server-side runtime (on Node+Mongo) with a client-side one, so your code appears to run on both, including the database. WebSockets syncs between all client(s) and server.</li>
<li>Does &#8220;live deployments&#8221; every time you edit your code &#8211; client-side runtimes are updated on the fly without losing their state</li>
<li>Makes more sense if you <a href="http://www.meteor.com/screencast">watch the video</a></li>
<li>Like everyone I spoke to at the event, I really want this to succeed &mdash; web development needs something this radical to move forwards</li>
</ul>
</li>
<li><strong>Why</strong>: You&#8217;ve had enough of conventional web development and now want to live on the bleeding edge.</li>
<li><strong>Where</strong>: <a href="https://github.com/meteor/meteor">GitHub</a> and <a href="http://www.meteor.com/">own site</a></li>
<li><strong>When</strong>: It&#8217;s still early days; I don&#8217;t know if there are any production Meteor sites yet except built by the core team. They&#8217;re totally serious about doing this, though.</li>
</ul>
<h5>Ember</h5>
<ul>
<li><strong>Who</strong>: Yehuda Katz (formerly of jQuery and Rails), the Ember team, and Yehuda&#8217;s company <a href="http://www.facebook.com/tildeinc">Tilde</a></li>
<li><strong>What</strong>:
<ul>
<li>Everything you need to build an &#8220;ambitious web application&#8221;, MIT license</li>
<li>Biggest framework of them all in both functionality and code size</li>
<li>Lots of thought has gone into how you can decompose your page into a hierarchy of controls, and how this ties in with a statemachine-powered hierarchical routing system</li>
<li>Very sophisticated data access library (Ember.Data) currently in development</li>
<li>Intended to control your whole page at runtime, so not suitable for use in small &#8220;islands of richness&#8221; on a wider page</li>
<li>Pretty heavily opinionated about files, URLs, etc., but everything is overridable if you know how</li>
<li>Design inspired by Rails and Cocoa</li>
<li>Tooling: They supply project templates for Rails (but you can use other server platforms if you write the code manually)</li>
</ul>
</li>
<li><strong>Why</strong>: Common problems should have common solutions &mdash; Ember makes all the common solutions so you only have to think about what&#8217;s unique to your own application</li>
<li><strong>Where</strong>: <a href="https://github.com/emberjs/ember.js/">GitHub</a> and <a href="http://emberjs.com/">own site</a></li>
<li><strong>When</strong>: Not yet at 1.0, but aiming for it soon. API will solidify then.</li>
</ul>
<h5>AngularJS</h5>
<ul>
<li><strong>Who</strong>: Developed by Google; used internally by them and MIT licensed.</li>
<li><strong>What</strong>:
<ul>
<li>Model-View-Whatever in JavaScript, MIT licensed</li>
<li>DOM-based templating with observability, declarative bindings, and an almost-MVVM code style (they say Model-View-Whatever)</li>
<li>Basic URL routing and data persistence built in</li>
<li>Tooling: they ship a Chrome debugger plugin that lets you explore your models while debugging, and a plugin for the Jasmine testing framework.</li>
</ul>
</li>
<li><strong>Why</strong>:
<ul>
<li>Conceptually, they say it&#8217;s a polyfill between what browsers can do today and what they will do natively in a few years (declarative binding and observability), so we should start coding this way right now</li>
<li>No impact on your server architecture or file layout. Can work in a small section of your page &mdash; doesn&#8217;t need to control whole page.</li>
</ul>
</li>
<li><strong>Where</strong>: <a href="https://github.com/AngularJS/AngularJS.js">GitHub</a> and <a href="http://AngularJSjs.org/">own site</a></li>
<li><strong>When</strong>: In production now (has been at Google for a while)</li>
</ul>
<h5>Knockout</h5>
<ul>
<li><strong>Who</strong>: The Knockout team and community (currently three on the core team, including me)</li>
<li><strong>What</strong>:
<ul>
<li>Model-View-ViewModel (MVVM) in JavaScript, MIT licensed</li>
<li>Tightly focused on rich UIs: DOM-based templates with declarative bindings, and observable models with automatic dependency detection</li>
<li>Not opinionated about URL routing or data access &mdash; combines with arbitrary third-party libraries (e.g., Sammy.js for routing and plain ajax for storage)</li>
<li>Big focus on approachability, with extensive documentation and <a href="http://learn.knockoutjs.com/">interactive examples</a></li>
</ul>
</li>
<li><strong>Why</strong>:
<ul>
<li>Does one thing well (UI), right back to IE 6</li>
<li>No impact on your server architecture or file layout. Can work in a small section of your page &mdash; doesn&#8217;t need to control whole page.</li>
</ul>
</li>
<li><strong>Where</strong>: <a href="http://github.com/SteveSanderson/knockout">GitHub</a> and <a href="http://knockoutjs.com">own site</a></li>
<li><strong>When</strong>: In production for nearly 2 years now</li>
</ul>
<h5>Spine</h5>
<ul>
<li><strong>Who</strong>: Alex MacCaw</li>
<li><strong>What</strong>:
<ul>
<li>MVC in JavaScript, MIT license</li>
<li>Worked example originally written for an O&#8217;Reilly book grew into an actual OSS project</li>
<li>Is a kind of modified clone of Backbone (hence the name)</li>
</ul>
</li>
<li><strong>Why</strong>: You like Backbone, but want <a href="http://stackoverflow.com/questions/6530444/backbone-js-vs-spine-js">a few things to be different</a>.</li>
<li><strong>Where</strong>: <a href="https://github.com/maccman/spine">GitHub</a> and <a href="http://spinejs.com/">own site</a></li>
<li><strong>When</strong>: It&#8217;s past v1.0.0 now</li>
</ul>
<h5>Batman</h5>
<ul>
<li><strong>Who</strong>: the team at <a href="http://www.shopify.com/">Shopify</a> (an eCommerce platform company)</li>
<li><strong>What</strong>:
<ul>
<li>MVC in JavaScript, almost exclusively for Rails+CoffeeScript developers, MIT licensed</li>
<li>Most opinionated of them all. You <em>must</em> follow their conventions (e.g., for file layout and URLs) or, as they say in their presentation,&#8221;<em>go use another framework</em>&#8220;</li>
<li>Full-stack framework with pretty rich models, views, and controllers and routing. And observability mechanism of course.</li>
<li>DOM-based templating.</li>
</ul>
</li>
<li><strong>Why</strong>: If you use Rails and CoffeeScript, you&#8217;ll be right at home</li>
<li><strong>Where</strong>: <a href="https://github.com/Shopify/batman">GitHub</a> and <a href="http://batmanjs.org/">own site</a></li>
<li><strong>When</strong>: Currently at 0.9. Aiming for 1.0 in coming months.</li>
</ul>
<h5>CanJS</h5>
<ul>
<li><strong>Who</strong>: the team at <a href="http://bitovi.com/">Bitovi</a> (a JavaScript consulting/training company)</li>
<li><strong>What</strong>:
<ul>
<li>MVC in JavaScript, MIT licensed</li>
<li>REST-persistable models, basic routing, string-based templating</li>
<li>Not widely known (I hadn&#8217;t heard of it before last week), though is actually a reboot of the older <a href="http://javascriptmvc.com/">JavaScriptMVC</a> project</li>
</ul>
</li>
<li><strong>Why:</strong> Aims to be the best of all worlds by delivering features similar to the above libraries while also being small</li>
<li><strong>Where:</strong> <a href="https://github.com/jupiterjs/canjs">GitHub</a> and <a href="http://canjs.us/">own site</a></li>
<li><strong>When:</strong> Past 1.0 already</li>
</ul>
<h4>Summary</h4>
<p>If you&#8217;re trying to make sense of which of these is a good starting point for your project, I&#8217;d suggest two questions areas to consider:</p>
<ul>
<li><strong>Scope</strong>. How much do you want a framework or library to do for you? Are you starting from blank and want a complete pre-prepared architecture to guide you from beginning to end? Or do you prefer to pick your own combinations of patterns and libraries? Either choice has value and is right for different projects and teams.</li>
<li><strong>Design aesthetic</strong>. Have you actually looked at code and tried building something small with each of your candidates? Do you <em>like doing it</em>? Don&#8217;t choose based on descriptions or feature lists alone: they&#8217;re relevant but limited. Ignoring your own subjective coding experience would be like picking a novel based on the number of chapters, or a spouse based on their resume/CV.</li>
</ul>
<p>Despite the differences, I&#8217;d argue there is one killer feature all the above technologies share: the idea of Model/View separation. This is a classic design pattern that predates the web itself by about 20 years. If you&#8217;re building even the most basic kind of web application UI, you&#8217;ll almost certainly benefit from applying this on the client.</p>
<div class="feedflare">
<a href="http://feeds.codeville.net/~ff/SteveCodeville?a=hOoxjpMxgw8:vHSxOgW4ngU:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/SteveCodeville?i=hOoxjpMxgw8:vHSxOgW4ngU:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.codeville.net/~ff/SteveCodeville?a=hOoxjpMxgw8:vHSxOgW4ngU:G79ilh31hkQ"><img src="http://feeds.feedburner.com/~ff/SteveCodeville?d=G79ilh31hkQ" border="0"></img></a> <a href="http://feeds.codeville.net/~ff/SteveCodeville?a=hOoxjpMxgw8:vHSxOgW4ngU:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/SteveCodeville?i=hOoxjpMxgw8:vHSxOgW4ngU:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.codeville.net/~ff/SteveCodeville?a=hOoxjpMxgw8:vHSxOgW4ngU:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/SteveCodeville?d=yIl2AUoC8zA" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/SteveCodeville/~4/hOoxjpMxgw8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.stevensanderson.com/2012/08/01/rich-javascript-applications-the-seven-frameworks-throne-of-js-2012/feed/</wfw:commentRss>
		<slash:comments>104</slash:comments>
		<feedburner:origLink>http://blog.stevensanderson.com/2012/08/01/rich-javascript-applications-the-seven-frameworks-throne-of-js-2012/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=rich-javascript-applications-the-seven-frameworks-throne-of-js-2012</feedburner:origLink></item>
		<item>
		<title>Node.js development with WebMatrix 2 + Express (Part 3)</title>
		<link>http://feeds.codeville.net/~r/SteveCodeville/~3/Z3R0lfXgdLM/</link>
		<comments>http://blog.stevensanderson.com/2012/07/11/node-js-development-with-webmatrix-2-express-part-3/#comments</comments>
		<pubDate>Wed, 11 Jul 2012 08:31:06 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Node.js]]></category>

		<guid isPermaLink="false">http://blog.stevensanderson.com/?p=484</guid>
		<description><![CDATA[This is the third in a three-part series of videos about building a mobile web app with Node.js, Express, and WebMatrix: Getting started with Node and Express using WebMatrix 2 &#8212; 12 minutes Building a web app with static UI [...]]]></description>
			<content:encoded><![CDATA[<p>This is the <strong>third in a three-part series</strong> of videos about building a mobile web app with Node.js, Express, and WebMatrix:</p>
<ol>
<li><a href="http://blog.stevensanderson.com/2012/07/09/node-js-development-with-webmatrix-2-and-express/">Getting started with Node and Express using WebMatrix 2</a> <i>&mdash; 12 minutes</i></li>
<li><a href="http://blog.stevensanderson.com/2012/07/10/node-js-development-with-webmatrix-2-express-part-2/">Building a web app with static UI / dynamic API architecture</a> <i>&mdash; 20 minutes</i></li>
<li><strong>(This post) Hints and tricks for optimising for mobiles</strong> <i>&mdash; 14 minutes</i></li>
</ol>
<p>This third video puts the focus on mobile devices, which is the main target audience for our app. You&#8217;ll see ways of improving the user experience on small screens, using caching to make the app load incredibly quickly even over a low-bandwidth connection, and pushing real-time updates to clients. Finally you&#8217;ll see a few iOS-specific tricks.</p>
<p>Here&#8217;s the video. Be sure to watch it full-screen in 720p quality, by the way, for the most readable code&#8230;</p>
<p><iframe width="640" height="360" src="http://www.youtube.com/embed/S_zPmRBv1SI?vq=hd720" frameborder="0" allowfullscreen></iframe></p>
<h4>Want to download the code?</h4>
<p>As before, <a href="https://github.com/SteveSanderson/nodejs-webmatrix-video-tutorials" target=_blank>the source repo is on GitHub</a>. Or, you can <a href="https://github.com/SteveSanderson/nodejs-webmatrix-video-tutorials/zipball/end-of-part-3">download the exact version of the code corresponding to the end of the part 3 video</a>.</p>
<div class="feedflare">
<a href="http://feeds.codeville.net/~ff/SteveCodeville?a=Z3R0lfXgdLM:buuKgJIlJz8:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/SteveCodeville?i=Z3R0lfXgdLM:buuKgJIlJz8:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.codeville.net/~ff/SteveCodeville?a=Z3R0lfXgdLM:buuKgJIlJz8:G79ilh31hkQ"><img src="http://feeds.feedburner.com/~ff/SteveCodeville?d=G79ilh31hkQ" border="0"></img></a> <a href="http://feeds.codeville.net/~ff/SteveCodeville?a=Z3R0lfXgdLM:buuKgJIlJz8:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/SteveCodeville?i=Z3R0lfXgdLM:buuKgJIlJz8:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.codeville.net/~ff/SteveCodeville?a=Z3R0lfXgdLM:buuKgJIlJz8:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/SteveCodeville?d=yIl2AUoC8zA" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/SteveCodeville/~4/Z3R0lfXgdLM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.stevensanderson.com/2012/07/11/node-js-development-with-webmatrix-2-express-part-3/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		<feedburner:origLink>http://blog.stevensanderson.com/2012/07/11/node-js-development-with-webmatrix-2-express-part-3/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=node-js-development-with-webmatrix-2-express-part-3</feedburner:origLink></item>
		<item>
		<title>Node.js development with WebMatrix 2 + Express (Part 2)</title>
		<link>http://feeds.codeville.net/~r/SteveCodeville/~3/xw4ARVVgrqA/</link>
		<comments>http://blog.stevensanderson.com/2012/07/10/node-js-development-with-webmatrix-2-express-part-2/#comments</comments>
		<pubDate>Tue, 10 Jul 2012 09:05:52 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Node.js]]></category>

		<guid isPermaLink="false">http://blog.stevensanderson.com/?p=470</guid>
		<description><![CDATA[This is the second in a three-part series of videos about building a mobile web app with Node.js, Express, and WebMatrix: Getting started with Node and Express using WebMatrix 2 &#8212; 12 minutes (This post) Building a web app with [...]]]></description>
			<content:encoded><![CDATA[<p>This is the <strong>second in a three-part series</strong> of videos about building a mobile web app with Node.js, Express, and WebMatrix:</p>
<ol>
<li><a href="http://blog.stevensanderson.com/2012/07/09/node-js-development-with-webmatrix-2-and-express/">Getting started with Node and Express using WebMatrix 2</a> <i>&mdash; 12 minutes</i></li>
<li><strong>(This post) Building a web app with static UI / dynamic API architecture</strong> <i>&mdash; 20 minutes</i></li>
<li><a href="http://blog.stevensanderson.com/2012/07/11/node-js-development-with-webmatrix-2-express-part-3/">Hints and tricks for optimising for mobiles</a> <i>&mdash; 14 minutes</i></li>
</ol>
<p>In this second video, we build on the Node.js + Express skills learned in the first video, and create a fun social web app that demonstrates how you can totally separate your application&#8217;s UI from its underlying API by using Express&#8217;s ability to mount one application inside another. This isn&#8217;t only about keeping your code tidy: it also enables some dramatic performance benefits, as you&#8217;ll see in Part 3, and means you could easily attach multiple UI technologies to the same underlying backend.</p>
<p>OK, here&#8217;s the video. Be sure to watch it full-screen in 720p quality, by the way, for the most readable code&#8230;</p>
<p><iframe width="640" height="360" src="http://www.youtube.com/embed/3jaGkSMYcvg?vq=hd720" frameborder="0" allowfullscreen></iframe></p>
<h4>Want to download the code?</h4>
<p>If you want to get a closer look at the code created in this tutorial, you can <a href="https://github.com/SteveSanderson/nodejs-webmatrix-video-tutorials/zipball/end-of-part-2">download the version corresponding to the end of part 2</a>, or <a href="https://github.com/SteveSanderson/nodejs-webmatrix-video-tutorials" target=_blank>browse the whole source repo on GitHub</a>.</p>
<div class="feedflare">
<a href="http://feeds.codeville.net/~ff/SteveCodeville?a=xw4ARVVgrqA:tYvC0VCWzMI:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/SteveCodeville?i=xw4ARVVgrqA:tYvC0VCWzMI:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.codeville.net/~ff/SteveCodeville?a=xw4ARVVgrqA:tYvC0VCWzMI:G79ilh31hkQ"><img src="http://feeds.feedburner.com/~ff/SteveCodeville?d=G79ilh31hkQ" border="0"></img></a> <a href="http://feeds.codeville.net/~ff/SteveCodeville?a=xw4ARVVgrqA:tYvC0VCWzMI:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/SteveCodeville?i=xw4ARVVgrqA:tYvC0VCWzMI:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.codeville.net/~ff/SteveCodeville?a=xw4ARVVgrqA:tYvC0VCWzMI:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/SteveCodeville?d=yIl2AUoC8zA" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/SteveCodeville/~4/xw4ARVVgrqA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.stevensanderson.com/2012/07/10/node-js-development-with-webmatrix-2-express-part-2/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		<feedburner:origLink>http://blog.stevensanderson.com/2012/07/10/node-js-development-with-webmatrix-2-express-part-2/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=node-js-development-with-webmatrix-2-express-part-2</feedburner:origLink></item>
		<item>
		<title>Node.js development with WebMatrix 2 and Express</title>
		<link>http://feeds.codeville.net/~r/SteveCodeville/~3/8YbKRjgSbRI/</link>
		<comments>http://blog.stevensanderson.com/2012/07/09/node-js-development-with-webmatrix-2-and-express/#comments</comments>
		<pubDate>Mon, 09 Jul 2012 10:22:54 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Node.js]]></category>

		<guid isPermaLink="false">http://blog.stevensanderson.com/?p=458</guid>
		<description><![CDATA[I&#8217;m sure by now everyone has heard plenty about Node.js, the lightweight JavaScript-on-the-server web platform. But maybe you&#8217;ve been putting off trying it out because it&#8217;s unclear what exactly to download and install on Windows to get the best development [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m sure by now everyone has heard plenty about <a href="http://nodejs.org/" target="_blank">Node.js</a>, the lightweight JavaScript-on-the-server web platform. But maybe you&#8217;ve been putting off trying it out because it&#8217;s unclear what exactly to download and install on Windows to get the best development experience.</p>
<p>Delay no longer! Get <a href="http://bit.ly/L77V6w" target="_blank">WebMatrix 2 (Release Candidate)</a> and it will take care of installing all the bits you need (Node, Node Package Manager, and IISNode), and will give you a first-rate IDE experience including fancy features like autocompletion that understands Node packages and conventions.</p>
<h4>Tutorial videos</h4>
<p>So then, what can you do with Node and WebMatrix? This is the first in a three-part series of videos about building a mobile web app with Node.js, Express, and WebMatrix:</p>
<ol>
<li><strong>(This post) Getting started with Node and Express using WebMatrix 2</strong> <i>&mdash; 12 minutes</i></li>
<li><a href="http://blog.stevensanderson.com/2012/07/10/node-js-development-with-webmatrix-2-express-part-2/">Building a web app with static UI / dynamic API architecture</a> <i>&mdash; 20 minutes</i></li>
<li><a href="http://blog.stevensanderson.com/2012/07/11/node-js-development-with-webmatrix-2-express-part-3/">Hints and tricks for optimising for mobiles</a> <i>&mdash; 14 minutes</i></li>
</ol>
<p>The material is based on a talk I gave at <a href="http://devsum.se/" target="_blank">DevSum in Stockholm</a> a month or two back.</p>
<p>OK, here it is! Be sure to watch it full-screen in 720p quality, by the way, for the most readable code&#8230;</p>
<p><iframe width="640" height="360" src="http://www.youtube.com/embed/gE4AsGKTv8k?vq=hd720" frameborder="0" allowfullscreen></iframe></p>
<div class="feedflare">
<a href="http://feeds.codeville.net/~ff/SteveCodeville?a=8YbKRjgSbRI:bhwl7icMchw:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/SteveCodeville?i=8YbKRjgSbRI:bhwl7icMchw:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.codeville.net/~ff/SteveCodeville?a=8YbKRjgSbRI:bhwl7icMchw:G79ilh31hkQ"><img src="http://feeds.feedburner.com/~ff/SteveCodeville?d=G79ilh31hkQ" border="0"></img></a> <a href="http://feeds.codeville.net/~ff/SteveCodeville?a=8YbKRjgSbRI:bhwl7icMchw:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/SteveCodeville?i=8YbKRjgSbRI:bhwl7icMchw:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.codeville.net/~ff/SteveCodeville?a=8YbKRjgSbRI:bhwl7icMchw:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/SteveCodeville?d=yIl2AUoC8zA" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/SteveCodeville/~4/8YbKRjgSbRI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.stevensanderson.com/2012/07/09/node-js-development-with-webmatrix-2-and-express/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		<feedburner:origLink>http://blog.stevensanderson.com/2012/07/09/node-js-development-with-webmatrix-2-and-express/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=node-js-development-with-webmatrix-2-and-express</feedburner:origLink></item>
		<item>
		<title>Knockout 2.1.0 released</title>
		<link>http://feeds.codeville.net/~r/SteveCodeville/~3/XsGk1VKxMmo/</link>
		<comments>http://blog.stevensanderson.com/2012/05/09/knockout-2-1-0-released/#comments</comments>
		<pubDate>Wed, 09 May 2012 04:59:07 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Knockout]]></category>

		<guid isPermaLink="false">http://blog.stevensanderson.com/?p=452</guid>
		<description><![CDATA[Last night we released version 2.1.0 of knockout.js. This brings a whole bundle of added functionality and performance improvements. For a more detailed rundown of what’s new, see Ryan Niemeyer’s blog post. With this release we welcome new core team [...]]]></description>
			<content:encoded><![CDATA[<p>Last night we released version 2.1.0 of <a href="http://knockoutjs.com/">knockout.js</a>. This brings a whole bundle of added functionality and performance improvements. For a more detailed rundown of what’s new, see <a href="http://www.knockmeout.net/2012/05/knockout-2-dot-1-is-out.html">Ryan Niemeyer’s blog post</a>.</p>
<p>With this release we welcome new core team member <a href="https://github.com/mbest">Michael Best</a>, who implemented a lot of the 2.1.0 goodness. One of my favourite new features is the <strong>$index</strong> context variable. Here’s a short usage example:</p>
<p><iframe style="width: 100%; height: 300px" src="http://jsfiddle.net/HhXGH/embedded/result,html,js/" frameborder="0" allowfullscreen="allowfullscreen"></iframe></p>
<p>The cool thing is that <strong>$index</strong> is an observable and is updated automatically as you add or remove items in any collection bound to a <strong>foreach</strong> (and so your UI will update to match). Impressively, Michael was able to add this new functionality while simultaneously <em>improving </em>the performance of <strong>foreach</strong> whether or not you are using <strong>$index</strong>!</p>
<p>We also benefited from pull requests, issue reports, and feature suggestions from many others in the community. Special thanks to <a href="https://github.com/neonstalwart">neonstalwart</a> and <a href="https://github.com/mtscout6">mtscout6</a> for not only implementing AMD module loader support and putting up with a lot of questions from me, but even including <a href="http://knockoutjs.com/documentation/amd-loading.html">full documentation pages</a> in their pull request – flawless OSS etiquette!</p>
<p>Again, if you want to know more about what’s new in KO 2.1.0, head on over to <a href="http://www.knockmeout.net/2012/05/knockout-2-dot-1-is-out.html">Ryan’s post</a> for a full rundown.</p>
<div class="feedflare">
<a href="http://feeds.codeville.net/~ff/SteveCodeville?a=XsGk1VKxMmo:M2aYYhhRtfQ:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/SteveCodeville?i=XsGk1VKxMmo:M2aYYhhRtfQ:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.codeville.net/~ff/SteveCodeville?a=XsGk1VKxMmo:M2aYYhhRtfQ:G79ilh31hkQ"><img src="http://feeds.feedburner.com/~ff/SteveCodeville?d=G79ilh31hkQ" border="0"></img></a> <a href="http://feeds.codeville.net/~ff/SteveCodeville?a=XsGk1VKxMmo:M2aYYhhRtfQ:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/SteveCodeville?i=XsGk1VKxMmo:M2aYYhhRtfQ:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.codeville.net/~ff/SteveCodeville?a=XsGk1VKxMmo:M2aYYhhRtfQ:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/SteveCodeville?d=yIl2AUoC8zA" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/SteveCodeville/~4/XsGk1VKxMmo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.stevensanderson.com/2012/05/09/knockout-2-1-0-released/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		<feedburner:origLink>http://blog.stevensanderson.com/2012/05/09/knockout-2-1-0-released/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=knockout-2-1-0-released</feedburner:origLink></item>
	</channel>
</rss><!-- Dynamic page generated in 0.773 seconds. --><!-- Cached page generated by WP-Super-Cache on 2013-05-20 12:09:12 --><!-- Compression = gzip -->
