<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	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/"
	>

<channel>
	<title>Ed Spencer &#187; Misc</title>
	<atom:link href="http://edspencer.net/category/1/feed" rel="self" type="application/rss+xml" />
	<link>http://edspencer.net</link>
	<description>A Sencha Architect</description>
	<lastBuildDate>Sat, 11 Feb 2012 09:20:06 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Building a data-driven image carousel with Sencha Touch 2</title>
		<link>http://edspencer.net/2012/02/building-a-data-driven-image-carousel-with-sencha-touch-2.html</link>
		<comments>http://edspencer.net/2012/02/building-a-data-driven-image-carousel-with-sencha-touch-2.html#comments</comments>
		<pubDate>Sat, 11 Feb 2012 09:04:02 +0000</pubDate>
		<dc:creator>Ed Spencer</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[Misc]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[touch]]></category>
		<category><![CDATA[apod]]></category>
		<category><![CDATA[astronomy]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[pretty]]></category>
		<category><![CDATA[sencha touch]]></category>

		<guid isPermaLink="false">http://edspencer.net/?p=722</guid>
		<description><![CDATA[<p>This evening I embarked on a little stellar voyage that I&#8217;d like to share with you all. Most people with great taste love astronomy and Sencha Touch 2, so why not combine them in a fun evening&#8217;s web app building?</p>
<p>NASA has been running a small site called <a href="http://apod.nasa.gov/apod/astropix.html">APOD</a> (Astronomy Picture Of the Day) for a long time now, as you can probably tell by the <a href="http://apod.nasa.gov/apod/astropix.html">awesome web design</a> of that page. Despite its 1998-era styling, this site incorporates some pretty stunning images of the universe and is begging for a mobile app interpretation.</p>
<p>We&#8217;re not going to go crazy, in fact this whole thing only took about an hour to create, but hopefully it&#8217;s a useful look at how to put something like this together. In this case, we&#8217;re just going to write a quick app that pulls down the last 20 pictures and shows them in a carousel with an optional title.</p>
<p>Here&#8217;s what it looks like live. You&#8217;ll need a webkit browser (Chrome or Safari) to see this, alternatively load up <a href="http://code.edspencer.net/apod">http://code.edspencer.net/apod</a> on a phone or tablet device:</p>
<p><iframe src="http://code.edspencer.net/apod" width="670" height="500" frameborder="0"></iframe></p>
<p>The full source code for <a href="https://github.com/edspencer/APOD">the app is up on github</a>, and we&#8217;ll go through it bit by bit below.</p>
<h2>The App</h2>
<p>Our app consists of 5 files:</p>
<p><b>index.html</b>, which includes our JavaScript files and a little CSS<br />
<b>app.js</b>, which boots our application up<br />
<b>app/model/Picture.js</b>, which represents a single APOD picture<br />
<b>app/view/Picture.js</b>, which shows a picture on the page<br />
<b>app/store/Pictures.js</b>, which fetches the pictures from the APOD RSS feed</p>
<p>The whole thing is up on github and you can <a href="http://code.edspencer.net/apod">see a live demo at http://code.edspencer.net/apod</a>. To see what it&#8217;s doing tap that link on your phone or tablet, and to really feel it add it to your homescreen to get rid of that browser chrome.</p>
<h2>The Code</h2>
<p>Most of the action happens in app.js, which for your enjoyment is more documentation than code. Here&#8217;s the gist of it:</p>
<div id="gist-1797867" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="cm">/*</span></div><div class='line' id='LC2'><span class="cm"> * This app uses a Carousel and a JSON-P proxy so make sure they&#39;re loaded first</span></div><div class='line' id='LC3'><span class="cm"> */</span></div><div class='line' id='LC4'><span class="nx">Ext</span><span class="p">.</span><span class="nx">require</span><span class="p">([</span></div><div class='line' id='LC5'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="s1">&#39;Ext.carousel.Carousel&#39;</span><span class="p">,</span></div><div class='line' id='LC6'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="s1">&#39;Ext.data.proxy.JsonP&#39;</span></div><div class='line' id='LC7'><span class="p">]);</span></div><div class='line' id='LC8'><br/></div><div class='line' id='LC9'><span class="cm">/**</span></div><div class='line' id='LC10'><span class="cm"> * Our app is pretty simple - it just grabs the latest images from NASA&#39;s Astronomy Picture Of the Day </span></div><div class='line' id='LC11'><span class="cm"> * (http://apod.nasa.gov/apod/astropix.html) and displays them in a Carousel. This file drives most of</span></div><div class='line' id='LC12'><span class="cm"> * the application, but there&#39;s also:</span></div><div class='line' id='LC13'><span class="cm"> * </span></div><div class='line' id='LC14'><span class="cm"> * * A Store - app/store/Pictures.js - that fetches the data from the APOD RSS feed</span></div><div class='line' id='LC15'><span class="cm"> * * A Model - app/model/Picture.js - that represents a single image from the feed</span></div><div class='line' id='LC16'><span class="cm"> * * A View - app/view/Picture.js - that displays each image</span></div><div class='line' id='LC17'><span class="cm"> * </span></div><div class='line' id='LC18'><span class="cm"> * Our application&#39;s launch function is called automatically when everything is loaded.</span></div><div class='line' id='LC19'><span class="cm"> */</span></div><div class='line' id='LC20'><span class="nx">Ext</span><span class="p">.</span><span class="nx">application</span><span class="p">({</span></div><div class='line' id='LC21'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">name</span><span class="o">:</span> <span class="s1">&#39;apod&#39;</span><span class="p">,</span></div><div class='line' id='LC22'>&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC23'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">models</span><span class="o">:</span> <span class="p">[</span><span class="s1">&#39;Picture&#39;</span><span class="p">],</span></div><div class='line' id='LC24'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">stores</span><span class="o">:</span> <span class="p">[</span><span class="s1">&#39;Pictures&#39;</span><span class="p">],</span></div><div class='line' id='LC25'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">views</span><span class="o">:</span> <span class="p">[</span><span class="s1">&#39;Picture&#39;</span><span class="p">],</span></div><div class='line' id='LC26'>&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC27'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">launch</span><span class="o">:</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span></div><div class='line' id='LC28'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">titleVisible</span> <span class="o">=</span> <span class="kc">false</span><span class="p">,</span></div><div class='line' id='LC29'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">info</span><span class="p">,</span> <span class="nx">carousel</span><span class="p">;</span></div><div class='line' id='LC30'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC31'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="cm">/**</span></div><div class='line' id='LC32'><span class="cm">         * The main carousel that drives our app. We&#39;re just telling it to use the Pictures store and</span></div><div class='line' id='LC33'><span class="cm">         * to update the info bar whenever a new image is swiped to</span></div><div class='line' id='LC34'><span class="cm">         */</span></div><div class='line' id='LC35'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">carousel</span> <span class="o">=</span> <span class="nx">Ext</span><span class="p">.</span><span class="nx">create</span><span class="p">(</span><span class="s1">&#39;Ext.Carousel&#39;</span><span class="p">,</span> <span class="p">{</span></div><div class='line' id='LC36'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">store</span><span class="o">:</span> <span class="s1">&#39;Pictures&#39;</span><span class="p">,</span></div><div class='line' id='LC37'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">direction</span><span class="o">:</span> <span class="s1">&#39;horizontal&#39;</span><span class="p">,</span></div><div class='line' id='LC38'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC39'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">listeners</span><span class="o">:</span> <span class="p">{</span></div><div class='line' id='LC40'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">activeitemchange</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">carousel</span><span class="p">,</span> <span class="nx">item</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC41'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">info</span><span class="p">.</span><span class="nx">setHtml</span><span class="p">(</span><span class="nx">item</span><span class="p">.</span><span class="nx">getPicture</span><span class="p">().</span><span class="nx">get</span><span class="p">(</span><span class="s1">&#39;title&#39;</span><span class="p">));</span></div><div class='line' id='LC42'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC43'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC44'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">});</span></div><div class='line' id='LC45'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC46'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="cm">/**</span></div><div class='line' id='LC47'><span class="cm">         * This is just a reusable Component that we pin to the top of the page. This is hidden by default</span></div><div class='line' id='LC48'><span class="cm">         * and appears when the user taps on the screen. The activeitemchange listener above updates the </span></div><div class='line' id='LC49'><span class="cm">         * content of this Component whenever a new image is swiped to</span></div><div class='line' id='LC50'><span class="cm">         */</span></div><div class='line' id='LC51'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">info</span> <span class="o">=</span> <span class="nx">Ext</span><span class="p">.</span><span class="nx">create</span><span class="p">(</span><span class="s1">&#39;Ext.Component&#39;</span><span class="p">,</span> <span class="p">{</span></div><div class='line' id='LC52'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">cls</span><span class="o">:</span> <span class="s1">&#39;apod-title&#39;</span><span class="p">,</span></div><div class='line' id='LC53'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">top</span><span class="o">:</span> <span class="mi">0</span><span class="p">,</span></div><div class='line' id='LC54'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">left</span><span class="o">:</span> <span class="mi">0</span><span class="p">,</span></div><div class='line' id='LC55'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">right</span><span class="o">:</span> <span class="mi">0</span></div><div class='line' id='LC56'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">});</span></div><div class='line' id='LC57'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC58'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="c1">//add both of our views to the Viewport so they&#39;re rendered and visible</span></div><div class='line' id='LC59'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">Ext</span><span class="p">.</span><span class="nx">Viewport</span><span class="p">.</span><span class="nx">add</span><span class="p">(</span><span class="nx">carousel</span><span class="p">);</span></div><div class='line' id='LC60'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">Ext</span><span class="p">.</span><span class="nx">Viewport</span><span class="p">.</span><span class="nx">add</span><span class="p">(</span><span class="nx">info</span><span class="p">);</span></div><div class='line' id='LC61'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC62'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="cm">/**</span></div><div class='line' id='LC63'><span class="cm">         * The Pictures store (see app/store/Pictures.js) is set to not load automatically, so we load it </span></div><div class='line' id='LC64'><span class="cm">         * manually now. This loads data from the APOD RSS feed and calls our callback function once it&#39;s</span></div><div class='line' id='LC65'><span class="cm">         * loaded.</span></div><div class='line' id='LC66'><span class="cm">         * </span></div><div class='line' id='LC67'><span class="cm">         * All we do here is iterate over all of the data, creating an apodimage Component for each item. </span></div><div class='line' id='LC68'><span class="cm">         * Then we just add those items to the Carousel and set the first item active.</span></div><div class='line' id='LC69'><span class="cm">         */</span></div><div class='line' id='LC70'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">Ext</span><span class="p">.</span><span class="nx">getStore</span><span class="p">(</span><span class="s1">&#39;Pictures&#39;</span><span class="p">).</span><span class="nx">load</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">pictures</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC71'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">items</span> <span class="o">=</span> <span class="p">[];</span></div><div class='line' id='LC72'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC73'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">Ext</span><span class="p">.</span><span class="nx">each</span><span class="p">(</span><span class="nx">pictures</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">picture</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC74'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">picture</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="s1">&#39;image&#39;</span><span class="p">))</span> <span class="p">{</span></div><div class='line' id='LC75'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">return</span><span class="p">;</span></div><div class='line' id='LC76'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC77'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC78'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">items</span><span class="p">.</span><span class="nx">push</span><span class="p">({</span></div><div class='line' id='LC79'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">xtype</span><span class="o">:</span> <span class="s1">&#39;apodimage&#39;</span><span class="p">,</span></div><div class='line' id='LC80'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">picture</span><span class="o">:</span> <span class="nx">picture</span></div><div class='line' id='LC81'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">});</span></div><div class='line' id='LC82'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">});</span></div><div class='line' id='LC83'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC84'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">carousel</span><span class="p">.</span><span class="nx">setItems</span><span class="p">(</span><span class="nx">items</span><span class="p">);</span></div><div class='line' id='LC85'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">carousel</span><span class="p">.</span><span class="nx">setActiveItem</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span></div><div class='line' id='LC86'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">});</span></div><div class='line' id='LC87'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC88'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="cm">/**</span></div><div class='line' id='LC89'><span class="cm">         * The final thing is to add a tap listener that is called whenever the user taps on the screen.</span></div><div class='line' id='LC90'><span class="cm">         * We do a quick check to make sure they&#39;re not tapping on the carousel indicators (tapping on</span></div><div class='line' id='LC91'><span class="cm">         * those indicators moves you between items so we don&#39;t want to override that), then either hide </span></div><div class='line' id='LC92'><span class="cm">         * or show the info Component.</span></div><div class='line' id='LC93'><span class="cm">         * </span></div><div class='line' id='LC94'><span class="cm">         * Note that to hide or show this Component we&#39;re adding or removing the apod-title-visible class.</span></div><div class='line' id='LC95'><span class="cm">         * If you look at index.html you&#39;ll see the CSS rules style the info bar and also cause it to fade</span></div><div class='line' id='LC96'><span class="cm">         * in and out when you tap.</span></div><div class='line' id='LC97'><span class="cm">         */</span></div><div class='line' id='LC98'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">Ext</span><span class="p">.</span><span class="nx">Viewport</span><span class="p">.</span><span class="nx">element</span><span class="p">.</span><span class="nx">on</span><span class="p">(</span><span class="s1">&#39;tap&#39;</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">e</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC99'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">e</span><span class="p">.</span><span class="nx">getTarget</span><span class="p">(</span><span class="s1">&#39;.x-carousel-indicator&#39;</span><span class="p">))</span> <span class="p">{</span></div><div class='line' id='LC100'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="nx">titleVisible</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC101'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">info</span><span class="p">.</span><span class="nx">element</span><span class="p">.</span><span class="nx">removeCls</span><span class="p">(</span><span class="s1">&#39;apod-title-visible&#39;</span><span class="p">);</span></div><div class='line' id='LC102'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">titleVisible</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span></div><div class='line' id='LC103'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span> <span class="k">else</span> <span class="p">{</span></div><div class='line' id='LC104'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">info</span><span class="p">.</span><span class="nx">element</span><span class="p">.</span><span class="nx">addCls</span><span class="p">(</span><span class="s1">&#39;apod-title-visible&#39;</span><span class="p">);</span></div><div class='line' id='LC105'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">titleVisible</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span></div><div class='line' id='LC106'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC107'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC108'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">});</span></div><div class='line' id='LC109'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC110'><span class="p">});</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/1797867/106be284198dadd27fad8d90481e1062221c5d2b/APOD-app.js" style="float:right;">view raw</a>
            <a href="https://gist.github.com/1797867#file_apod_app.js" style="float:right;margin-right:10px;color:#666">APOD-app.js</a>
            <a href="https://gist.github.com/1797867">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>This is pretty simple stuff and you can probably just follow the comments to see what&#8217;s going on. Basically though the app.js is responsible for launching our application, creating the Carousel and info Components, and setting up a couple of convenient event listeners.</p>
<p>We also had a few other files:</p>
<h2>Picture Model</h2>
<p>Found in app/model/Picture.js, our model is mostly just a list of fields sent back in the RSS feed. There is one that&#8217;s somewhat more complicated than the rest though &#8211; the &#8216;image&#8217; field. Ideally, the RSS feed would have sent back the url of the image in a separate field and we could just pull it out like any other, but alas it is embedded inside the main content.</p>
<p>To get around this, we just specify a convert function that grabs the content field, finds the first image url inside of it and pulls it out. To make sure it looks good on any device we also pass it through <a href="http://www.sencha.com/learn/how-to-use-src-sencha-io/">Sencha IO src</a>, which resizes the image to fit the screen size of whatever device we happen to be viewing it on:</p>
<div id="gist-1797867" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="cm">/**</span></div><div class='line' id='LC2'><span class="cm"> * Simple Model that represents an image from NASA&#39;s Astronomy Picture Of the Day. The only remarkable</span></div><div class='line' id='LC3'><span class="cm"> * thing about this model is the &#39;image&#39; field, which uses a regular expression to pull its value out </span></div><div class='line' id='LC4'><span class="cm"> * of the main content of the RSS feed. Ideally the image url would have been presented in its own field</span></div><div class='line' id='LC5'><span class="cm"> * in the RSS response, but as it wasn&#39;t we had to use this approach to parse it out</span></div><div class='line' id='LC6'><span class="cm"> */</span></div><div class='line' id='LC7'><span class="nx">Ext</span><span class="p">.</span><span class="nx">define</span><span class="p">(</span><span class="s1">&#39;apod.model.Picture&#39;</span><span class="p">,</span> <span class="p">{</span></div><div class='line' id='LC8'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">extend</span><span class="o">:</span> <span class="s1">&#39;Ext.data.Model&#39;</span><span class="p">,</span></div><div class='line' id='LC9'>&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC10'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">config</span><span class="o">:</span> <span class="p">{</span></div><div class='line' id='LC11'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">fields</span><span class="o">:</span> <span class="p">[</span></div><div class='line' id='LC12'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="s1">&#39;id&#39;</span><span class="p">,</span> <span class="s1">&#39;title&#39;</span><span class="p">,</span> <span class="s1">&#39;link&#39;</span><span class="p">,</span> <span class="s1">&#39;author&#39;</span><span class="p">,</span> <span class="s1">&#39;content&#39;</span><span class="p">,</span></div><div class='line' id='LC13'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">{</span></div><div class='line' id='LC14'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">name</span><span class="o">:</span> <span class="s1">&#39;image&#39;</span><span class="p">,</span></div><div class='line' id='LC15'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">type</span><span class="o">:</span> <span class="s1">&#39;string&#39;</span><span class="p">,</span></div><div class='line' id='LC16'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">convert</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">value</span><span class="p">,</span> <span class="nx">record</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC17'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">content</span> <span class="o">=</span> <span class="nx">record</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="s1">&#39;content&#39;</span><span class="p">),</span></div><div class='line' id='LC18'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">regex</span>   <span class="o">=</span> <span class="sr">/img src=\&quot;([a-zA-Z0-9\_\.\/\:]*)\&quot;/</span><span class="p">,</span></div><div class='line' id='LC19'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">match</span>   <span class="o">=</span> <span class="nx">content</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="nx">regex</span><span class="p">),</span></div><div class='line' id='LC20'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">src</span>     <span class="o">=</span> <span class="nx">match</span><span class="p">[</span><span class="mi">1</span><span class="p">];</span></div><div class='line' id='LC21'><br/></div><div class='line' id='LC22'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="nx">src</span> <span class="o">!=</span> <span class="s2">&quot;&quot;</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="nx">src</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="sr">/\.gif$/</span><span class="p">))</span> <span class="p">{</span></div><div class='line' id='LC23'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">src</span> <span class="o">=</span> <span class="s2">&quot;http://src.sencha.io/screen.width/&quot;</span> <span class="o">+</span> <span class="nx">src</span><span class="p">;</span></div><div class='line' id='LC24'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC25'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC26'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">return</span> <span class="nx">src</span><span class="p">;</span></div><div class='line' id='LC27'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC28'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC29'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">]</span></div><div class='line' id='LC30'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC31'><span class="p">});</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/1797867/96169d323970625b7ac66c51e1a32e5384fdec2e/APOD-model.js" style="float:right;">view raw</a>
            <a href="https://gist.github.com/1797867#file_apod_model.js" style="float:right;margin-right:10px;color:#666">APOD-model.js</a>
            <a href="https://gist.github.com/1797867">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<h2>Pictures Store</h2>
<p>Our Store is even simpler than our Model. All it does is load the APOD RSS feed over JSON-P (via Google&#8217;s <a href="https://developers.google.com/feed/">RSS Feed API</a>) and decode the data with a very simple JSON Reader. This automatically pulls down the images and runs them through our Model&#8217;s convert function:</p>
<div id="gist-1797867" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="cm">/**</span></div><div class='line' id='LC2'><span class="cm"> * Grabs the APOD RSS feed from Google&#39;s Feed API, passes the data to our Model to decode</span></div><div class='line' id='LC3'><span class="cm"> */</span></div><div class='line' id='LC4'><span class="nx">Ext</span><span class="p">.</span><span class="nx">define</span><span class="p">(</span><span class="s1">&#39;apod.store.Pictures&#39;</span><span class="p">,</span> <span class="p">{</span></div><div class='line' id='LC5'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">extend</span><span class="o">:</span> <span class="s1">&#39;Ext.data.Store&#39;</span><span class="p">,</span></div><div class='line' id='LC6'>&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC7'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">config</span><span class="o">:</span> <span class="p">{</span></div><div class='line' id='LC8'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">model</span><span class="o">:</span> <span class="s1">&#39;apod.model.Picture&#39;</span><span class="p">,</span></div><div class='line' id='LC9'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC10'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">proxy</span><span class="o">:</span> <span class="p">{</span></div><div class='line' id='LC11'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">type</span><span class="o">:</span> <span class="s1">&#39;jsonp&#39;</span><span class="p">,</span></div><div class='line' id='LC12'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">url</span><span class="o">:</span> <span class="s1">&#39;https://ajax.googleapis.com/ajax/services/feed/load?v=1.0&amp;q=http://www.acme.com/jef/apod/rss.xml&amp;num=20&#39;</span><span class="p">,</span></div><div class='line' id='LC13'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC14'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">reader</span><span class="o">:</span> <span class="p">{</span></div><div class='line' id='LC15'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">type</span><span class="o">:</span> <span class="s1">&#39;json&#39;</span><span class="p">,</span></div><div class='line' id='LC16'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">rootProperty</span><span class="o">:</span> <span class="s1">&#39;responseData.feed.entries&#39;</span></div><div class='line' id='LC17'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC18'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC19'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC20'><span class="p">});</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/1797867/2356e837605a27fea7ffd31165bc8bc1d6f19b6d/APOD-store.js" style="float:right;">view raw</a>
            <a href="https://gist.github.com/1797867#file_apod_store.js" style="float:right;margin-right:10px;color:#666">APOD-store.js</a>
            <a href="https://gist.github.com/1797867">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<h2>Tying it all together</h2>
<p>Our app.js loads our Model and Store, plus a really simple Picture view that is basically just an <a href="http://docs.sencha.com/touch/2-0/#!/api/Ext.Img">Ext.Img</a>. All it does then is render the Carousel and Info Component to the screen and tie up a couple of listeners.</p>
<p>In case you weren&#8217;t paying attention before, the info component is just an Ext.Component that we rendered up in app.js as a place to render the title of the image you&#8217;re currently looking at. When you swipe between items in the carousel the <a href="http://docs.sencha.com/touch/2-0/#!/api/Ext.carousel.Carousel-event-activeitemchange">activeitemchange event</a> is fired, which we listen to near the top of app.js. All our activeitemchange listener does is update the HTML of the info component to the title of the image we just swiped to.</p>
<p>But what about the info component itself? Well at the bottom of app.js we added a tap listener on Ext.Viewport that hides or shows the info Component whenever you tap anywhere on the screen (except if you tap on the Carousel indicator icons). With a little CSS transition loveliness we get a nice fade in/out transition when we tap the screen to reveal the image title. Here&#8217;s that tap listener again:</p>
<div id="gist-1797867" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="cm">/**</span></div><div class='line' id='LC2'><span class="cm"> * The final thing is to add a tap listener that is called whenever the user taps on the screen.</span></div><div class='line' id='LC3'><span class="cm"> * We do a quick check to make sure they&#39;re not tapping on the carousel indicators (tapping on</span></div><div class='line' id='LC4'><span class="cm"> * those indicators moves you between items so we don&#39;t want to override that), then either hide </span></div><div class='line' id='LC5'><span class="cm"> * or show the info Component.</span></div><div class='line' id='LC6'><span class="cm"> */</span></div><div class='line' id='LC7'><span class="nx">Ext</span><span class="p">.</span><span class="nx">Viewport</span><span class="p">.</span><span class="nx">element</span><span class="p">.</span><span class="nx">on</span><span class="p">(</span><span class="s1">&#39;tap&#39;</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">e</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC8'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">e</span><span class="p">.</span><span class="nx">getTarget</span><span class="p">(</span><span class="s1">&#39;.x-carousel-indicator&#39;</span><span class="p">))</span> <span class="p">{</span></div><div class='line' id='LC9'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="nx">titleVisible</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC10'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">info</span><span class="p">.</span><span class="nx">element</span><span class="p">.</span><span class="nx">removeCls</span><span class="p">(</span><span class="s1">&#39;apod-title-visible&#39;</span><span class="p">);</span></div><div class='line' id='LC11'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">titleVisible</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span></div><div class='line' id='LC12'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span> <span class="k">else</span> <span class="p">{</span></div><div class='line' id='LC13'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">info</span><span class="p">.</span><span class="nx">element</span><span class="p">.</span><span class="nx">addCls</span><span class="p">(</span><span class="s1">&#39;apod-title-visible&#39;</span><span class="p">);</span></div><div class='line' id='LC14'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">titleVisible</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span></div><div class='line' id='LC15'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC16'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC17'><span class="p">});</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/1797867/d07b38cec0f7fb4a1155e9fe30da255df16bafbb/APOD-app-tap-listener.js" style="float:right;">view raw</a>
            <a href="https://gist.github.com/1797867#file_apod_app_tap_listener.js" style="float:right;margin-right:10px;color:#666">APOD-app-tap-listener.js</a>
            <a href="https://gist.github.com/1797867">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<h2>The End of the Beginning</h2>
<p>This was a really simple app that shows how easy it is to put these things together with Sencha Touch 2. Like with most stories though there&#8217;s more to come so keep an eye out for parts 2 and 3 of this intergalactic adventure.</p>
]]></description>
			<content:encoded><![CDATA[<p>This evening I embarked on a little stellar voyage that I&#8217;d like to share with you all. Most people with great taste love astronomy and Sencha Touch 2, so why not combine them in a fun evening&#8217;s web app building?</p>
<p>NASA has been running a small site called <a href="http://apod.nasa.gov/apod/astropix.html">APOD</a> (Astronomy Picture Of the Day) for a long time now, as you can probably tell by the <a href="http://apod.nasa.gov/apod/astropix.html">awesome web design</a> of that page. Despite its 1998-era styling, this site incorporates some pretty stunning images of the universe and is begging for a mobile app interpretation.</p>
<p>We&#8217;re not going to go crazy, in fact this whole thing only took about an hour to create, but hopefully it&#8217;s a useful look at how to put something like this together. In this case, we&#8217;re just going to write a quick app that pulls down the last 20 pictures and shows them in a carousel with an optional title.</p>
<p>Here&#8217;s what it looks like live. You&#8217;ll need a webkit browser (Chrome or Safari) to see this, alternatively load up <a href="http://code.edspencer.net/apod">http://code.edspencer.net/apod</a> on a phone or tablet device:</p>
<p><iframe src="http://code.edspencer.net/apod" width="670" height="500" frameborder="0"></iframe></p>
<p>The full source code for <a href="https://github.com/edspencer/APOD">the app is up on github</a>, and we&#8217;ll go through it bit by bit below.</p>
<h2>The App</h2>
<p>Our app consists of 5 files:</p>
<p><b>index.html</b>, which includes our JavaScript files and a little CSS<br />
<b>app.js</b>, which boots our application up<br />
<b>app/model/Picture.js</b>, which represents a single APOD picture<br />
<b>app/view/Picture.js</b>, which shows a picture on the page<br />
<b>app/store/Pictures.js</b>, which fetches the pictures from the APOD RSS feed</p>
<p>The whole thing is up on github and you can <a href="http://code.edspencer.net/apod">see a live demo at http://code.edspencer.net/apod</a>. To see what it&#8217;s doing tap that link on your phone or tablet, and to really feel it add it to your homescreen to get rid of that browser chrome.</p>
<h2>The Code</h2>
<p>Most of the action happens in app.js, which for your enjoyment is more documentation than code. Here&#8217;s the gist of it:</p>
<div id="gist-1797867" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="cm">/*</span></div><div class='line' id='LC2'><span class="cm"> * This app uses a Carousel and a JSON-P proxy so make sure they&#39;re loaded first</span></div><div class='line' id='LC3'><span class="cm"> */</span></div><div class='line' id='LC4'><span class="nx">Ext</span><span class="p">.</span><span class="nx">require</span><span class="p">([</span></div><div class='line' id='LC5'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="s1">&#39;Ext.carousel.Carousel&#39;</span><span class="p">,</span></div><div class='line' id='LC6'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="s1">&#39;Ext.data.proxy.JsonP&#39;</span></div><div class='line' id='LC7'><span class="p">]);</span></div><div class='line' id='LC8'><br/></div><div class='line' id='LC9'><span class="cm">/**</span></div><div class='line' id='LC10'><span class="cm"> * Our app is pretty simple - it just grabs the latest images from NASA&#39;s Astronomy Picture Of the Day </span></div><div class='line' id='LC11'><span class="cm"> * (http://apod.nasa.gov/apod/astropix.html) and displays them in a Carousel. This file drives most of</span></div><div class='line' id='LC12'><span class="cm"> * the application, but there&#39;s also:</span></div><div class='line' id='LC13'><span class="cm"> * </span></div><div class='line' id='LC14'><span class="cm"> * * A Store - app/store/Pictures.js - that fetches the data from the APOD RSS feed</span></div><div class='line' id='LC15'><span class="cm"> * * A Model - app/model/Picture.js - that represents a single image from the feed</span></div><div class='line' id='LC16'><span class="cm"> * * A View - app/view/Picture.js - that displays each image</span></div><div class='line' id='LC17'><span class="cm"> * </span></div><div class='line' id='LC18'><span class="cm"> * Our application&#39;s launch function is called automatically when everything is loaded.</span></div><div class='line' id='LC19'><span class="cm"> */</span></div><div class='line' id='LC20'><span class="nx">Ext</span><span class="p">.</span><span class="nx">application</span><span class="p">({</span></div><div class='line' id='LC21'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">name</span><span class="o">:</span> <span class="s1">&#39;apod&#39;</span><span class="p">,</span></div><div class='line' id='LC22'>&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC23'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">models</span><span class="o">:</span> <span class="p">[</span><span class="s1">&#39;Picture&#39;</span><span class="p">],</span></div><div class='line' id='LC24'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">stores</span><span class="o">:</span> <span class="p">[</span><span class="s1">&#39;Pictures&#39;</span><span class="p">],</span></div><div class='line' id='LC25'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">views</span><span class="o">:</span> <span class="p">[</span><span class="s1">&#39;Picture&#39;</span><span class="p">],</span></div><div class='line' id='LC26'>&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC27'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">launch</span><span class="o">:</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span></div><div class='line' id='LC28'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">titleVisible</span> <span class="o">=</span> <span class="kc">false</span><span class="p">,</span></div><div class='line' id='LC29'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">info</span><span class="p">,</span> <span class="nx">carousel</span><span class="p">;</span></div><div class='line' id='LC30'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC31'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="cm">/**</span></div><div class='line' id='LC32'><span class="cm">         * The main carousel that drives our app. We&#39;re just telling it to use the Pictures store and</span></div><div class='line' id='LC33'><span class="cm">         * to update the info bar whenever a new image is swiped to</span></div><div class='line' id='LC34'><span class="cm">         */</span></div><div class='line' id='LC35'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">carousel</span> <span class="o">=</span> <span class="nx">Ext</span><span class="p">.</span><span class="nx">create</span><span class="p">(</span><span class="s1">&#39;Ext.Carousel&#39;</span><span class="p">,</span> <span class="p">{</span></div><div class='line' id='LC36'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">store</span><span class="o">:</span> <span class="s1">&#39;Pictures&#39;</span><span class="p">,</span></div><div class='line' id='LC37'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">direction</span><span class="o">:</span> <span class="s1">&#39;horizontal&#39;</span><span class="p">,</span></div><div class='line' id='LC38'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC39'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">listeners</span><span class="o">:</span> <span class="p">{</span></div><div class='line' id='LC40'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">activeitemchange</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">carousel</span><span class="p">,</span> <span class="nx">item</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC41'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">info</span><span class="p">.</span><span class="nx">setHtml</span><span class="p">(</span><span class="nx">item</span><span class="p">.</span><span class="nx">getPicture</span><span class="p">().</span><span class="nx">get</span><span class="p">(</span><span class="s1">&#39;title&#39;</span><span class="p">));</span></div><div class='line' id='LC42'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC43'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC44'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">});</span></div><div class='line' id='LC45'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC46'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="cm">/**</span></div><div class='line' id='LC47'><span class="cm">         * This is just a reusable Component that we pin to the top of the page. This is hidden by default</span></div><div class='line' id='LC48'><span class="cm">         * and appears when the user taps on the screen. The activeitemchange listener above updates the </span></div><div class='line' id='LC49'><span class="cm">         * content of this Component whenever a new image is swiped to</span></div><div class='line' id='LC50'><span class="cm">         */</span></div><div class='line' id='LC51'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">info</span> <span class="o">=</span> <span class="nx">Ext</span><span class="p">.</span><span class="nx">create</span><span class="p">(</span><span class="s1">&#39;Ext.Component&#39;</span><span class="p">,</span> <span class="p">{</span></div><div class='line' id='LC52'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">cls</span><span class="o">:</span> <span class="s1">&#39;apod-title&#39;</span><span class="p">,</span></div><div class='line' id='LC53'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">top</span><span class="o">:</span> <span class="mi">0</span><span class="p">,</span></div><div class='line' id='LC54'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">left</span><span class="o">:</span> <span class="mi">0</span><span class="p">,</span></div><div class='line' id='LC55'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">right</span><span class="o">:</span> <span class="mi">0</span></div><div class='line' id='LC56'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">});</span></div><div class='line' id='LC57'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC58'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="c1">//add both of our views to the Viewport so they&#39;re rendered and visible</span></div><div class='line' id='LC59'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">Ext</span><span class="p">.</span><span class="nx">Viewport</span><span class="p">.</span><span class="nx">add</span><span class="p">(</span><span class="nx">carousel</span><span class="p">);</span></div><div class='line' id='LC60'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">Ext</span><span class="p">.</span><span class="nx">Viewport</span><span class="p">.</span><span class="nx">add</span><span class="p">(</span><span class="nx">info</span><span class="p">);</span></div><div class='line' id='LC61'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC62'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="cm">/**</span></div><div class='line' id='LC63'><span class="cm">         * The Pictures store (see app/store/Pictures.js) is set to not load automatically, so we load it </span></div><div class='line' id='LC64'><span class="cm">         * manually now. This loads data from the APOD RSS feed and calls our callback function once it&#39;s</span></div><div class='line' id='LC65'><span class="cm">         * loaded.</span></div><div class='line' id='LC66'><span class="cm">         * </span></div><div class='line' id='LC67'><span class="cm">         * All we do here is iterate over all of the data, creating an apodimage Component for each item. </span></div><div class='line' id='LC68'><span class="cm">         * Then we just add those items to the Carousel and set the first item active.</span></div><div class='line' id='LC69'><span class="cm">         */</span></div><div class='line' id='LC70'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">Ext</span><span class="p">.</span><span class="nx">getStore</span><span class="p">(</span><span class="s1">&#39;Pictures&#39;</span><span class="p">).</span><span class="nx">load</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">pictures</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC71'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">items</span> <span class="o">=</span> <span class="p">[];</span></div><div class='line' id='LC72'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC73'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">Ext</span><span class="p">.</span><span class="nx">each</span><span class="p">(</span><span class="nx">pictures</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">picture</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC74'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">picture</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="s1">&#39;image&#39;</span><span class="p">))</span> <span class="p">{</span></div><div class='line' id='LC75'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">return</span><span class="p">;</span></div><div class='line' id='LC76'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC77'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC78'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">items</span><span class="p">.</span><span class="nx">push</span><span class="p">({</span></div><div class='line' id='LC79'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">xtype</span><span class="o">:</span> <span class="s1">&#39;apodimage&#39;</span><span class="p">,</span></div><div class='line' id='LC80'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">picture</span><span class="o">:</span> <span class="nx">picture</span></div><div class='line' id='LC81'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">});</span></div><div class='line' id='LC82'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">});</span></div><div class='line' id='LC83'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC84'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">carousel</span><span class="p">.</span><span class="nx">setItems</span><span class="p">(</span><span class="nx">items</span><span class="p">);</span></div><div class='line' id='LC85'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">carousel</span><span class="p">.</span><span class="nx">setActiveItem</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span></div><div class='line' id='LC86'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">});</span></div><div class='line' id='LC87'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC88'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="cm">/**</span></div><div class='line' id='LC89'><span class="cm">         * The final thing is to add a tap listener that is called whenever the user taps on the screen.</span></div><div class='line' id='LC90'><span class="cm">         * We do a quick check to make sure they&#39;re not tapping on the carousel indicators (tapping on</span></div><div class='line' id='LC91'><span class="cm">         * those indicators moves you between items so we don&#39;t want to override that), then either hide </span></div><div class='line' id='LC92'><span class="cm">         * or show the info Component.</span></div><div class='line' id='LC93'><span class="cm">         * </span></div><div class='line' id='LC94'><span class="cm">         * Note that to hide or show this Component we&#39;re adding or removing the apod-title-visible class.</span></div><div class='line' id='LC95'><span class="cm">         * If you look at index.html you&#39;ll see the CSS rules style the info bar and also cause it to fade</span></div><div class='line' id='LC96'><span class="cm">         * in and out when you tap.</span></div><div class='line' id='LC97'><span class="cm">         */</span></div><div class='line' id='LC98'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">Ext</span><span class="p">.</span><span class="nx">Viewport</span><span class="p">.</span><span class="nx">element</span><span class="p">.</span><span class="nx">on</span><span class="p">(</span><span class="s1">&#39;tap&#39;</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">e</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC99'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">e</span><span class="p">.</span><span class="nx">getTarget</span><span class="p">(</span><span class="s1">&#39;.x-carousel-indicator&#39;</span><span class="p">))</span> <span class="p">{</span></div><div class='line' id='LC100'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="nx">titleVisible</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC101'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">info</span><span class="p">.</span><span class="nx">element</span><span class="p">.</span><span class="nx">removeCls</span><span class="p">(</span><span class="s1">&#39;apod-title-visible&#39;</span><span class="p">);</span></div><div class='line' id='LC102'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">titleVisible</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span></div><div class='line' id='LC103'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span> <span class="k">else</span> <span class="p">{</span></div><div class='line' id='LC104'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">info</span><span class="p">.</span><span class="nx">element</span><span class="p">.</span><span class="nx">addCls</span><span class="p">(</span><span class="s1">&#39;apod-title-visible&#39;</span><span class="p">);</span></div><div class='line' id='LC105'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">titleVisible</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span></div><div class='line' id='LC106'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC107'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC108'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">});</span></div><div class='line' id='LC109'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC110'><span class="p">});</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/1797867/106be284198dadd27fad8d90481e1062221c5d2b/APOD-app.js" style="float:right;">view raw</a>
            <a href="https://gist.github.com/1797867#file_apod_app.js" style="float:right;margin-right:10px;color:#666">APOD-app.js</a>
            <a href="https://gist.github.com/1797867">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>This is pretty simple stuff and you can probably just follow the comments to see what&#8217;s going on. Basically though the app.js is responsible for launching our application, creating the Carousel and info Components, and setting up a couple of convenient event listeners.</p>
<p>We also had a few other files:</p>
<h2>Picture Model</h2>
<p>Found in app/model/Picture.js, our model is mostly just a list of fields sent back in the RSS feed. There is one that&#8217;s somewhat more complicated than the rest though &#8211; the &#8216;image&#8217; field. Ideally, the RSS feed would have sent back the url of the image in a separate field and we could just pull it out like any other, but alas it is embedded inside the main content.</p>
<p>To get around this, we just specify a convert function that grabs the content field, finds the first image url inside of it and pulls it out. To make sure it looks good on any device we also pass it through <a href="http://www.sencha.com/learn/how-to-use-src-sencha-io/">Sencha IO src</a>, which resizes the image to fit the screen size of whatever device we happen to be viewing it on:</p>
<div id="gist-1797867" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="cm">/**</span></div><div class='line' id='LC2'><span class="cm"> * Simple Model that represents an image from NASA&#39;s Astronomy Picture Of the Day. The only remarkable</span></div><div class='line' id='LC3'><span class="cm"> * thing about this model is the &#39;image&#39; field, which uses a regular expression to pull its value out </span></div><div class='line' id='LC4'><span class="cm"> * of the main content of the RSS feed. Ideally the image url would have been presented in its own field</span></div><div class='line' id='LC5'><span class="cm"> * in the RSS response, but as it wasn&#39;t we had to use this approach to parse it out</span></div><div class='line' id='LC6'><span class="cm"> */</span></div><div class='line' id='LC7'><span class="nx">Ext</span><span class="p">.</span><span class="nx">define</span><span class="p">(</span><span class="s1">&#39;apod.model.Picture&#39;</span><span class="p">,</span> <span class="p">{</span></div><div class='line' id='LC8'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">extend</span><span class="o">:</span> <span class="s1">&#39;Ext.data.Model&#39;</span><span class="p">,</span></div><div class='line' id='LC9'>&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC10'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">config</span><span class="o">:</span> <span class="p">{</span></div><div class='line' id='LC11'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">fields</span><span class="o">:</span> <span class="p">[</span></div><div class='line' id='LC12'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="s1">&#39;id&#39;</span><span class="p">,</span> <span class="s1">&#39;title&#39;</span><span class="p">,</span> <span class="s1">&#39;link&#39;</span><span class="p">,</span> <span class="s1">&#39;author&#39;</span><span class="p">,</span> <span class="s1">&#39;content&#39;</span><span class="p">,</span></div><div class='line' id='LC13'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">{</span></div><div class='line' id='LC14'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">name</span><span class="o">:</span> <span class="s1">&#39;image&#39;</span><span class="p">,</span></div><div class='line' id='LC15'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">type</span><span class="o">:</span> <span class="s1">&#39;string&#39;</span><span class="p">,</span></div><div class='line' id='LC16'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">convert</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">value</span><span class="p">,</span> <span class="nx">record</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC17'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">content</span> <span class="o">=</span> <span class="nx">record</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="s1">&#39;content&#39;</span><span class="p">),</span></div><div class='line' id='LC18'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">regex</span>   <span class="o">=</span> <span class="sr">/img src=\&quot;([a-zA-Z0-9\_\.\/\:]*)\&quot;/</span><span class="p">,</span></div><div class='line' id='LC19'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">match</span>   <span class="o">=</span> <span class="nx">content</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="nx">regex</span><span class="p">),</span></div><div class='line' id='LC20'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">src</span>     <span class="o">=</span> <span class="nx">match</span><span class="p">[</span><span class="mi">1</span><span class="p">];</span></div><div class='line' id='LC21'><br/></div><div class='line' id='LC22'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="nx">src</span> <span class="o">!=</span> <span class="s2">&quot;&quot;</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="nx">src</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="sr">/\.gif$/</span><span class="p">))</span> <span class="p">{</span></div><div class='line' id='LC23'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">src</span> <span class="o">=</span> <span class="s2">&quot;http://src.sencha.io/screen.width/&quot;</span> <span class="o">+</span> <span class="nx">src</span><span class="p">;</span></div><div class='line' id='LC24'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC25'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC26'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">return</span> <span class="nx">src</span><span class="p">;</span></div><div class='line' id='LC27'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC28'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC29'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">]</span></div><div class='line' id='LC30'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC31'><span class="p">});</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/1797867/96169d323970625b7ac66c51e1a32e5384fdec2e/APOD-model.js" style="float:right;">view raw</a>
            <a href="https://gist.github.com/1797867#file_apod_model.js" style="float:right;margin-right:10px;color:#666">APOD-model.js</a>
            <a href="https://gist.github.com/1797867">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<h2>Pictures Store</h2>
<p>Our Store is even simpler than our Model. All it does is load the APOD RSS feed over JSON-P (via Google&#8217;s <a href="https://developers.google.com/feed/">RSS Feed API</a>) and decode the data with a very simple JSON Reader. This automatically pulls down the images and runs them through our Model&#8217;s convert function:</p>
<div id="gist-1797867" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="cm">/**</span></div><div class='line' id='LC2'><span class="cm"> * Grabs the APOD RSS feed from Google&#39;s Feed API, passes the data to our Model to decode</span></div><div class='line' id='LC3'><span class="cm"> */</span></div><div class='line' id='LC4'><span class="nx">Ext</span><span class="p">.</span><span class="nx">define</span><span class="p">(</span><span class="s1">&#39;apod.store.Pictures&#39;</span><span class="p">,</span> <span class="p">{</span></div><div class='line' id='LC5'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">extend</span><span class="o">:</span> <span class="s1">&#39;Ext.data.Store&#39;</span><span class="p">,</span></div><div class='line' id='LC6'>&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC7'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">config</span><span class="o">:</span> <span class="p">{</span></div><div class='line' id='LC8'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">model</span><span class="o">:</span> <span class="s1">&#39;apod.model.Picture&#39;</span><span class="p">,</span></div><div class='line' id='LC9'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC10'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">proxy</span><span class="o">:</span> <span class="p">{</span></div><div class='line' id='LC11'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">type</span><span class="o">:</span> <span class="s1">&#39;jsonp&#39;</span><span class="p">,</span></div><div class='line' id='LC12'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">url</span><span class="o">:</span> <span class="s1">&#39;https://ajax.googleapis.com/ajax/services/feed/load?v=1.0&amp;q=http://www.acme.com/jef/apod/rss.xml&amp;num=20&#39;</span><span class="p">,</span></div><div class='line' id='LC13'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC14'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">reader</span><span class="o">:</span> <span class="p">{</span></div><div class='line' id='LC15'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">type</span><span class="o">:</span> <span class="s1">&#39;json&#39;</span><span class="p">,</span></div><div class='line' id='LC16'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">rootProperty</span><span class="o">:</span> <span class="s1">&#39;responseData.feed.entries&#39;</span></div><div class='line' id='LC17'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC18'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC19'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC20'><span class="p">});</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/1797867/2356e837605a27fea7ffd31165bc8bc1d6f19b6d/APOD-store.js" style="float:right;">view raw</a>
            <a href="https://gist.github.com/1797867#file_apod_store.js" style="float:right;margin-right:10px;color:#666">APOD-store.js</a>
            <a href="https://gist.github.com/1797867">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<h2>Tying it all together</h2>
<p>Our app.js loads our Model and Store, plus a really simple Picture view that is basically just an <a href="http://docs.sencha.com/touch/2-0/#!/api/Ext.Img">Ext.Img</a>. All it does then is render the Carousel and Info Component to the screen and tie up a couple of listeners.</p>
<p>In case you weren&#8217;t paying attention before, the info component is just an Ext.Component that we rendered up in app.js as a place to render the title of the image you&#8217;re currently looking at. When you swipe between items in the carousel the <a href="http://docs.sencha.com/touch/2-0/#!/api/Ext.carousel.Carousel-event-activeitemchange">activeitemchange event</a> is fired, which we listen to near the top of app.js. All our activeitemchange listener does is update the HTML of the info component to the title of the image we just swiped to.</p>
<p>But what about the info component itself? Well at the bottom of app.js we added a tap listener on Ext.Viewport that hides or shows the info Component whenever you tap anywhere on the screen (except if you tap on the Carousel indicator icons). With a little CSS transition loveliness we get a nice fade in/out transition when we tap the screen to reveal the image title. Here&#8217;s that tap listener again:</p>
<div id="gist-1797867" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="cm">/**</span></div><div class='line' id='LC2'><span class="cm"> * The final thing is to add a tap listener that is called whenever the user taps on the screen.</span></div><div class='line' id='LC3'><span class="cm"> * We do a quick check to make sure they&#39;re not tapping on the carousel indicators (tapping on</span></div><div class='line' id='LC4'><span class="cm"> * those indicators moves you between items so we don&#39;t want to override that), then either hide </span></div><div class='line' id='LC5'><span class="cm"> * or show the info Component.</span></div><div class='line' id='LC6'><span class="cm"> */</span></div><div class='line' id='LC7'><span class="nx">Ext</span><span class="p">.</span><span class="nx">Viewport</span><span class="p">.</span><span class="nx">element</span><span class="p">.</span><span class="nx">on</span><span class="p">(</span><span class="s1">&#39;tap&#39;</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">e</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC8'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">e</span><span class="p">.</span><span class="nx">getTarget</span><span class="p">(</span><span class="s1">&#39;.x-carousel-indicator&#39;</span><span class="p">))</span> <span class="p">{</span></div><div class='line' id='LC9'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="nx">titleVisible</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC10'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">info</span><span class="p">.</span><span class="nx">element</span><span class="p">.</span><span class="nx">removeCls</span><span class="p">(</span><span class="s1">&#39;apod-title-visible&#39;</span><span class="p">);</span></div><div class='line' id='LC11'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">titleVisible</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span></div><div class='line' id='LC12'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span> <span class="k">else</span> <span class="p">{</span></div><div class='line' id='LC13'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">info</span><span class="p">.</span><span class="nx">element</span><span class="p">.</span><span class="nx">addCls</span><span class="p">(</span><span class="s1">&#39;apod-title-visible&#39;</span><span class="p">);</span></div><div class='line' id='LC14'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">titleVisible</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span></div><div class='line' id='LC15'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC16'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC17'><span class="p">});</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/1797867/d07b38cec0f7fb4a1155e9fe30da255df16bafbb/APOD-app-tap-listener.js" style="float:right;">view raw</a>
            <a href="https://gist.github.com/1797867#file_apod_app_tap_listener.js" style="float:right;margin-right:10px;color:#666">APOD-app-tap-listener.js</a>
            <a href="https://gist.github.com/1797867">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<h2>The End of the Beginning</h2>
<p>This was a really simple app that shows how easy it is to put these things together with Sencha Touch 2. Like with most stories though there&#8217;s more to come so keep an eye out for parts 2 and 3 of this intergalactic adventure.</p>
]]></content:encoded>
			<wfw:commentRss>http://edspencer.net/2012/02/building-a-data-driven-image-carousel-with-sencha-touch-2.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Sencha Touch 2 PR4 &#8211; Big Improvements in Data and MVC</title>
		<link>http://edspencer.net/2012/01/sencha-touch-2-pr4-big-improvements-in-data-and-mvc.html</link>
		<comments>http://edspencer.net/2012/01/sencha-touch-2-pr4-big-improvements-in-data-and-mvc.html#comments</comments>
		<pubDate>Tue, 24 Jan 2012 08:59:44 +0000</pubDate>
		<dc:creator>Ed Spencer</dc:creator>
				<category><![CDATA[Misc]]></category>

		<guid isPermaLink="false">http://edspencer.net/?p=659</guid>
		<description><![CDATA[<p>Today <a href="http://www.sencha.com/forum/announcement.php?f=92&#038;a=28">we released Sencha Touch 2.0 PR4</a> &#8211; the fourth and final preview release before we hit beta. While we&#8217;re technically calling this one a preview release, we&#8217;re pretty happy with the performance, stability and overall quality of this release and consider it exceptionally close to beta quality.</p>
<p>As well as a good number of <a href="http://dev.sencha.com/deploy/sencha-touch-2-pr4/release-notes.html">enhancements and bug fixes</a> PR4 brings a couple of long-awaited improvements to two of the most important parts of Sencha Touch &#8211; the data package and the application architecture.</p>
<p>First up, the data package has been ported to use the new config system, which normalizes all of the configuration options for every class in the data package, providing a clean and predictable way to configure and update your data classes. We&#8217;re still cleaning up some of the data package documentation and given the scope of some of the changes we&#8217;re expecting a few bugs to appear as a result but overall we&#8217;re very happy with the improved capabilities of Ext.data.</p>
<h2>MVC Improvements</h2>
<p>The second big improvement in PR4 is to the application architecture. The MVC classes have also been upgraded to use the new config system, again yielding big improvements in the API and general flexibility of your code.</p>
<p>History support has been baked directly into <a href="http://docs.sencha.com/touch/2-0/#!/api/Ext.app.Controller">Controllers</a>, enabling you to easily define routes that your Controller cares about, as well as the functions that handle those routes right there in your Controller file. The <a href="http://dev.sencha.com/deploy/sencha-touch-2-pr4/examples/kitchensink">Kitchen Sink example</a> has been upgraded to use routes out of the box &#8211; try it on a mobile device or desktop browser and watch how it reacts to the back/forward buttons.</p>
<p>Equally important, <a href="http://docs.sencha.com/touch/2-0/#!/guide/profiles">Device Profiles</a> have been upgraded to make creating apps that adapt to different screen sizes much simpler than ever before. Once again the <a href="http://dev.sencha.com/deploy/sencha-touch-2-pr4/examples/kitchensink">Kitchen Sink</a> has been upgraded to take advantage of device profiles. If you load it on a tablet device you&#8217;ll see a split screen view with the menu on the left and the content on the right, whereas the phone version employs a nested list to save screen space.</p>
<p>To cap it off the deep linking support means you can navigate to any view on a phone, send the link to a friend on a tablet and they&#8217;ll be taken to the same view customized for their screen size. As an example, try opening <a href="http://dev.sencha.com/deploy/sencha-touch-2-pr4/examples/kitchensink/#demo/forms">http://dev.sencha.com/deploy/sencha-touch-2-pr4/examples/kitchensink/#demo/forms</a> on a tablet and a phone to see it show the Forms demo specialized for each type of device.</p>
<p>As PR4 is the first time we&#8217;ve exposed this expanded functionality to the public we expect that there will be bugs and edge cases that crop up. We&#8217;ll be keeping a close eye on the bug forums and addressing any issues as quickly as possible, as well as creating additional MVC-driven examples for you to learn from. For now, the kitchen sink is the best example of Sencha Touch 2 MVC in action.</p>
<h2>Docs</h2>
<p>We&#8217;ve made a huge push over the last couple of years to radically improve our documentation, and I think that even in the pre-beta PR4 release Sencha Touch 2 has the best docs we&#8217;ve ever created. While there are still holes to be filled in, we already ship with <a href="http://docs.sencha.com/touch/2-0/#!/guide">20 guides on how to use the framework</a>, including 4 brand new guides for PR4:</p>
<ul>
<li><a href="http://docs.sencha.com/touch/2-0/#!/guide/upgrade_1_to_2">Migrating from 1.x</a></li>
<li><a href="http://docs.sencha.com/touch/2-0/#!/guide/apps_intro">Intro to MVC</a></li>
<li><a href="http://docs.sencha.com/touch/2-0/#!/guide/profiles">Using Device Profiles</a></li>
<li><a href="http://docs.sencha.com/touch/2-0/#!/guide/controllers">Using Controllers</a></li>
</ul>
<p>As well as the guides, most of the classes now contain generous documentation explaining their function and the context in which they operate. As we move to beta and then to GA we&#8217;ll be shifting our focus onto producing great demos and examples to showcase the framework&#8217;s capabilities and provide realistic sample code to draw from.</p>
<p>There&#8217;s a full set of <a href="http://dev.sencha.com/deploy/sencha-touch-2-pr4/release-notes.html">release notes</a> explaining the improvements in PR4 and the important known issues. We expect to be shipping regular releases from now until GA so be sure to keep an eye on the forums, twitter and the <a href="http://sencha.com/blog">sencha blog</a> for more details.</p>
]]></description>
			<content:encoded><![CDATA[<p>Today <a href="http://www.sencha.com/forum/announcement.php?f=92&#038;a=28">we released Sencha Touch 2.0 PR4</a> &#8211; the fourth and final preview release before we hit beta. While we&#8217;re technically calling this one a preview release, we&#8217;re pretty happy with the performance, stability and overall quality of this release and consider it exceptionally close to beta quality.</p>
<p>As well as a good number of <a href="http://dev.sencha.com/deploy/sencha-touch-2-pr4/release-notes.html">enhancements and bug fixes</a> PR4 brings a couple of long-awaited improvements to two of the most important parts of Sencha Touch &#8211; the data package and the application architecture.</p>
<p>First up, the data package has been ported to use the new config system, which normalizes all of the configuration options for every class in the data package, providing a clean and predictable way to configure and update your data classes. We&#8217;re still cleaning up some of the data package documentation and given the scope of some of the changes we&#8217;re expecting a few bugs to appear as a result but overall we&#8217;re very happy with the improved capabilities of Ext.data.</p>
<h2>MVC Improvements</h2>
<p>The second big improvement in PR4 is to the application architecture. The MVC classes have also been upgraded to use the new config system, again yielding big improvements in the API and general flexibility of your code.</p>
<p>History support has been baked directly into <a href="http://docs.sencha.com/touch/2-0/#!/api/Ext.app.Controller">Controllers</a>, enabling you to easily define routes that your Controller cares about, as well as the functions that handle those routes right there in your Controller file. The <a href="http://dev.sencha.com/deploy/sencha-touch-2-pr4/examples/kitchensink">Kitchen Sink example</a> has been upgraded to use routes out of the box &#8211; try it on a mobile device or desktop browser and watch how it reacts to the back/forward buttons.</p>
<p>Equally important, <a href="http://docs.sencha.com/touch/2-0/#!/guide/profiles">Device Profiles</a> have been upgraded to make creating apps that adapt to different screen sizes much simpler than ever before. Once again the <a href="http://dev.sencha.com/deploy/sencha-touch-2-pr4/examples/kitchensink">Kitchen Sink</a> has been upgraded to take advantage of device profiles. If you load it on a tablet device you&#8217;ll see a split screen view with the menu on the left and the content on the right, whereas the phone version employs a nested list to save screen space.</p>
<p>To cap it off the deep linking support means you can navigate to any view on a phone, send the link to a friend on a tablet and they&#8217;ll be taken to the same view customized for their screen size. As an example, try opening <a href="http://dev.sencha.com/deploy/sencha-touch-2-pr4/examples/kitchensink/#demo/forms">http://dev.sencha.com/deploy/sencha-touch-2-pr4/examples/kitchensink/#demo/forms</a> on a tablet and a phone to see it show the Forms demo specialized for each type of device.</p>
<p>As PR4 is the first time we&#8217;ve exposed this expanded functionality to the public we expect that there will be bugs and edge cases that crop up. We&#8217;ll be keeping a close eye on the bug forums and addressing any issues as quickly as possible, as well as creating additional MVC-driven examples for you to learn from. For now, the kitchen sink is the best example of Sencha Touch 2 MVC in action.</p>
<h2>Docs</h2>
<p>We&#8217;ve made a huge push over the last couple of years to radically improve our documentation, and I think that even in the pre-beta PR4 release Sencha Touch 2 has the best docs we&#8217;ve ever created. While there are still holes to be filled in, we already ship with <a href="http://docs.sencha.com/touch/2-0/#!/guide">20 guides on how to use the framework</a>, including 4 brand new guides for PR4:</p>
<ul>
<li><a href="http://docs.sencha.com/touch/2-0/#!/guide/upgrade_1_to_2">Migrating from 1.x</a></li>
<li><a href="http://docs.sencha.com/touch/2-0/#!/guide/apps_intro">Intro to MVC</a></li>
<li><a href="http://docs.sencha.com/touch/2-0/#!/guide/profiles">Using Device Profiles</a></li>
<li><a href="http://docs.sencha.com/touch/2-0/#!/guide/controllers">Using Controllers</a></li>
</ul>
<p>As well as the guides, most of the classes now contain generous documentation explaining their function and the context in which they operate. As we move to beta and then to GA we&#8217;ll be shifting our focus onto producing great demos and examples to showcase the framework&#8217;s capabilities and provide realistic sample code to draw from.</p>
<p>There&#8217;s a full set of <a href="http://dev.sencha.com/deploy/sencha-touch-2-pr4/release-notes.html">release notes</a> explaining the improvements in PR4 and the important known issues. We expect to be shipping regular releases from now until GA so be sure to keep an eye on the forums, twitter and the <a href="http://sencha.com/blog">sencha blog</a> for more details.</p>
]]></content:encoded>
			<wfw:commentRss>http://edspencer.net/2012/01/sencha-touch-2-pr4-big-improvements-in-data-and-mvc.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>SenchaCon 2011: The Best Bits</title>
		<link>http://edspencer.net/2011/10/senchacon-2011-the-best-bits.html</link>
		<comments>http://edspencer.net/2011/10/senchacon-2011-the-best-bits.html#comments</comments>
		<pubDate>Wed, 26 Oct 2011 21:46:42 +0000</pubDate>
		<dc:creator>Ed Spencer</dc:creator>
				<category><![CDATA[Misc]]></category>

		<guid isPermaLink="false">http://edspencer.net/?p=650</guid>
		<description><![CDATA[<p>SenchaCon 2011 is drawing to a close and it&#8217;s been another awesome ride. We were joined by 600 of the best and brightest of the Sencha community and I think it&#8217;s pretty safe to say we had an awesome time. Day 3 is just drawing to a close so here&#8217;s a few highlights from the week.</p>
<h2>Ext JS 4.1 Performance Preview Released</h2>
<p>There were a number of big announcements on day 1. Probably the most exciting one for me was the release of <a href="http://www.sencha.com/blog/ext-js-4-1-developer-preview">Ext JS 4.1 Performance Preview</a>. We&#8217;ve been working like fiends to improve Ext JS&#8217;s performance profile on older browsers (IE6, IE7 and IE8 in particular) and on Monday we were able to share some of what we&#8217;ve achieved.</p>
<p>Page load, render and layout times are all enormously improved and have been the focus of our optimizations so far. Since 4.0 we&#8217;ve been building up a performance benchmarking rig that tests all of our 100+ examples (and a number of real-world customer apps) on consumer grade hardware with a range of browsers. We&#8217;ve seen massive improvements in loading time on these older browsers &#8211; for example the Themes Viewer example with its 300 Components all rendered at load time now starts up twice as fast as it did in 4.0.7.</p>
<p>To give a flavor for the breadth of the improvement we ran the tests on every example and summed up the loading time for each browser. As you can see below, 4.1 is able to speed through all of the examples significantly faster than 4.0.7, giving a massive performance boost across the board. It got so much faster that IE8 is now able to load all 100+ examples in a little under 20 seconds, compared with almost 60 in 4.0.7:</p>
<p><img src="http://img1.sencha.com/files/misc/IE-performance-on-4.0.7-vs-4.1.png" /></p>
<p><a href="http://www.sencha.com/blog/ext-js-4-1-developer-preview/">See the full announcement</a> on the sencha.com blog, but like we said there, this is a pre-beta release with a number of known issues. We&#8217;d love for you to verify the speed improvements with your own apps but please don&#8217;t take it anywhere near production yet! We&#8217;ll have more content on what&#8217;s in 4.1 in later blog posts.</p>
<h2>Other Announcements</h2>
<p>While Ext JS is closest to my heart, there were a number of other announcements made over the last few days. First up is Sencha.IO, our new cloud service and <a href="http://www.sencha.com/blog/introducing-sencha-io-the-first-mobile-html5-cloud/">now launching in beta</a>. This is a set of 4 services &#8211; data, messages, login and app deployment &#8211; that make creating and deploying web apps a snap, especially when you integrate the social aspects of Sencha.IO data and messages.</p>
<p>We also announced that we&#8217;ve just closed a second round of funding, raising another $15 million to further advance the state of the art in HTML5 technologies. This is going to enable us to push forward even faster and bring you some exciting new technologies. It was great that Sequoia Capital and Radar Partners were so happy with their first round with us that they decided to invest again. The future is definitely very exciting at Sencha right now.</p>
<h2>Favorite Sessions</h2>
<p>There were over 50 sessions this year and with several tracks going on simultaneously it was impossible to go to them all. Jacky Nguyen definitely stole the show with his talk on the Sencha Class System. He has a ridiculously over the top presentation style and totally brought the house down. We&#8217;ll be sure to get him on stage more often!</p>
<p>Jamie and Nicolas&#8217; talk on charting was very cool and generated lots of spontaneous applause (that happened a lot during the conference, which must be a good thing), and Rob and Dave&#8217;s demonstration of styling using the new beta Neptune theme was equally awesome.</p>
<p>Don lit the place up with his talk detailing the work that went into making Ext JS 4.1 so much faster, along with all the other new features in the release. Another mind blowing talk was given by John Willander, who demo&#8217;d a series of client-side attacks along with the <a href="http://beefproject.com/">BeEF Project</a>, which happens to be writen in Ext JS. Based on what John presented we&#8217;ll definitely be looking at what we can do to help you secure your apps with Ext JS.</p>
<p>Of course, I had a couple of sessions myself, though a few technical problems early on made them rather more challenging than expected (it&#8217;s hard to talk to people when your microphone cuts out after every second word!). The Intro to MVC talk was a blast and the sacrifice to the gods of live demos seemed to pay off as the 20 minute live coding session went without a hitch. Anyone who wants the code I put together during that session can find it <a href="https://github.com/edspencer/SenchaConDemo">up on github</a>.</p>
<h2>Meeting Everyone</h2>
<p>Although there were 600 people here this time it felt like I was able to meet almost everyone. Your intense enthusiasm for what we do really came through and to everyone who came up and gave us such great feedback it really drives us forward to keep improving your framework so thank you!</p>
<p>I saw more awesome Ext JS and Sencha Touch apps than I could count, and was pleasantly surprised to see how many people had been able to construct full applications using Sencha Touch 2 despite it only being <a href="http://www.sencha.com/blog/sencha-touch-2-developer-preview/">in Developer Preview</a> right now. It was also great getting to spend time hanging out with people and seeing them get excited when they start to see what&#8217;s possible with these products. Spending time in the flesh with developers is probably the most important part of the whole conference so it was great to meet so many of you.</p>
<p>Finally, Grgur announced that the second SourceCon Europe will be taking place in London around April of next year. The first SourceCon was an awesome experience in beautiful Split, Croatia, and next year we&#8217;ll be heading to London, England for this community-organized, Sencha-centric conference. They&#8217;ll be launching the conference website in a couple of weeks and given how good it was last year you&#8217;ll probably have to rush to get your tickets. Hope to see you there!</p>
]]></description>
			<content:encoded><![CDATA[<p>SenchaCon 2011 is drawing to a close and it&#8217;s been another awesome ride. We were joined by 600 of the best and brightest of the Sencha community and I think it&#8217;s pretty safe to say we had an awesome time. Day 3 is just drawing to a close so here&#8217;s a few highlights from the week.</p>
<h2>Ext JS 4.1 Performance Preview Released</h2>
<p>There were a number of big announcements on day 1. Probably the most exciting one for me was the release of <a href="http://www.sencha.com/blog/ext-js-4-1-developer-preview">Ext JS 4.1 Performance Preview</a>. We&#8217;ve been working like fiends to improve Ext JS&#8217;s performance profile on older browsers (IE6, IE7 and IE8 in particular) and on Monday we were able to share some of what we&#8217;ve achieved.</p>
<p>Page load, render and layout times are all enormously improved and have been the focus of our optimizations so far. Since 4.0 we&#8217;ve been building up a performance benchmarking rig that tests all of our 100+ examples (and a number of real-world customer apps) on consumer grade hardware with a range of browsers. We&#8217;ve seen massive improvements in loading time on these older browsers &#8211; for example the Themes Viewer example with its 300 Components all rendered at load time now starts up twice as fast as it did in 4.0.7.</p>
<p>To give a flavor for the breadth of the improvement we ran the tests on every example and summed up the loading time for each browser. As you can see below, 4.1 is able to speed through all of the examples significantly faster than 4.0.7, giving a massive performance boost across the board. It got so much faster that IE8 is now able to load all 100+ examples in a little under 20 seconds, compared with almost 60 in 4.0.7:</p>
<p><img src="http://img1.sencha.com/files/misc/IE-performance-on-4.0.7-vs-4.1.png" /></p>
<p><a href="http://www.sencha.com/blog/ext-js-4-1-developer-preview/">See the full announcement</a> on the sencha.com blog, but like we said there, this is a pre-beta release with a number of known issues. We&#8217;d love for you to verify the speed improvements with your own apps but please don&#8217;t take it anywhere near production yet! We&#8217;ll have more content on what&#8217;s in 4.1 in later blog posts.</p>
<h2>Other Announcements</h2>
<p>While Ext JS is closest to my heart, there were a number of other announcements made over the last few days. First up is Sencha.IO, our new cloud service and <a href="http://www.sencha.com/blog/introducing-sencha-io-the-first-mobile-html5-cloud/">now launching in beta</a>. This is a set of 4 services &#8211; data, messages, login and app deployment &#8211; that make creating and deploying web apps a snap, especially when you integrate the social aspects of Sencha.IO data and messages.</p>
<p>We also announced that we&#8217;ve just closed a second round of funding, raising another $15 million to further advance the state of the art in HTML5 technologies. This is going to enable us to push forward even faster and bring you some exciting new technologies. It was great that Sequoia Capital and Radar Partners were so happy with their first round with us that they decided to invest again. The future is definitely very exciting at Sencha right now.</p>
<h2>Favorite Sessions</h2>
<p>There were over 50 sessions this year and with several tracks going on simultaneously it was impossible to go to them all. Jacky Nguyen definitely stole the show with his talk on the Sencha Class System. He has a ridiculously over the top presentation style and totally brought the house down. We&#8217;ll be sure to get him on stage more often!</p>
<p>Jamie and Nicolas&#8217; talk on charting was very cool and generated lots of spontaneous applause (that happened a lot during the conference, which must be a good thing), and Rob and Dave&#8217;s demonstration of styling using the new beta Neptune theme was equally awesome.</p>
<p>Don lit the place up with his talk detailing the work that went into making Ext JS 4.1 so much faster, along with all the other new features in the release. Another mind blowing talk was given by John Willander, who demo&#8217;d a series of client-side attacks along with the <a href="http://beefproject.com/">BeEF Project</a>, which happens to be writen in Ext JS. Based on what John presented we&#8217;ll definitely be looking at what we can do to help you secure your apps with Ext JS.</p>
<p>Of course, I had a couple of sessions myself, though a few technical problems early on made them rather more challenging than expected (it&#8217;s hard to talk to people when your microphone cuts out after every second word!). The Intro to MVC talk was a blast and the sacrifice to the gods of live demos seemed to pay off as the 20 minute live coding session went without a hitch. Anyone who wants the code I put together during that session can find it <a href="https://github.com/edspencer/SenchaConDemo">up on github</a>.</p>
<h2>Meeting Everyone</h2>
<p>Although there were 600 people here this time it felt like I was able to meet almost everyone. Your intense enthusiasm for what we do really came through and to everyone who came up and gave us such great feedback it really drives us forward to keep improving your framework so thank you!</p>
<p>I saw more awesome Ext JS and Sencha Touch apps than I could count, and was pleasantly surprised to see how many people had been able to construct full applications using Sencha Touch 2 despite it only being <a href="http://www.sencha.com/blog/sencha-touch-2-developer-preview/">in Developer Preview</a> right now. It was also great getting to spend time hanging out with people and seeing them get excited when they start to see what&#8217;s possible with these products. Spending time in the flesh with developers is probably the most important part of the whole conference so it was great to meet so many of you.</p>
<p>Finally, Grgur announced that the second SourceCon Europe will be taking place in London around April of next year. The first SourceCon was an awesome experience in beautiful Split, Croatia, and next year we&#8217;ll be heading to London, England for this community-organized, Sencha-centric conference. They&#8217;ll be launching the conference website in a couple of weeks and given how good it was last year you&#8217;ll probably have to rush to get your tickets. Hope to see you there!</p>
]]></content:encoded>
			<wfw:commentRss>http://edspencer.net/2011/10/senchacon-2011-the-best-bits.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Ext JS 4.0.7 Released</title>
		<link>http://edspencer.net/2011/10/ext-js-4-0-7-released.html</link>
		<comments>http://edspencer.net/2011/10/ext-js-4-0-7-released.html#comments</comments>
		<pubDate>Thu, 20 Oct 2011 19:21:38 +0000</pubDate>
		<dc:creator>Ed Spencer</dc:creator>
				<category><![CDATA[Misc]]></category>

		<guid isPermaLink="false">http://edspencer.net/?p=647</guid>
		<description><![CDATA[<p>I&#8217;m very happy to report that we released Ext JS 4.0.7 to the public today. This is the seventh patch release to the 4.0.x series and contains several hundred improvements and bug fixes compared to the last public version, 4.0.2a.</p>
<p>4.0.7 is all about robustness &#8211; we&#8217;ve found that our support subscribers have had a lot of success with the newer builds of Ext JS 4 so I&#8217;m really pleased that we can share this with you. We&#8217;re releasing this publicly earlier than we would usually do because it has taken us longer than we expected to get Ext JS 4.1 into your hands.</p>
<p>Michael put out <a href="http://www.sencha.com/blog/ext-js-4-1-update/">a post on our blog</a> last week with some updates on 4.1 and our desires around releases and communications with the community. Not being able to ship 4.1 to you yet has been a frustrating experience but I think that once you see it you&#8217;ll enjoy the vast improvements it brings.</p>
<p>In the meantime, I&#8217;m happy to answer questions in the comments, via twitter or email (ed @ sencha). You can <a href="http://www.sencha.com/products/extjs/download">download the build here</a> and see the <a href="http://dev.sencha.com/deploy/ext-4.0.7-gpl/release-notes.html">full release notes for 4.0.7</a> all the way back to 4.0.0.</p>
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m very happy to report that we released Ext JS 4.0.7 to the public today. This is the seventh patch release to the 4.0.x series and contains several hundred improvements and bug fixes compared to the last public version, 4.0.2a.</p>
<p>4.0.7 is all about robustness &#8211; we&#8217;ve found that our support subscribers have had a lot of success with the newer builds of Ext JS 4 so I&#8217;m really pleased that we can share this with you. We&#8217;re releasing this publicly earlier than we would usually do because it has taken us longer than we expected to get Ext JS 4.1 into your hands.</p>
<p>Michael put out <a href="http://www.sencha.com/blog/ext-js-4-1-update/">a post on our blog</a> last week with some updates on 4.1 and our desires around releases and communications with the community. Not being able to ship 4.1 to you yet has been a frustrating experience but I think that once you see it you&#8217;ll enjoy the vast improvements it brings.</p>
<p>In the meantime, I&#8217;m happy to answer questions in the comments, via twitter or email (ed @ sencha). You can <a href="http://www.sencha.com/products/extjs/download">download the build here</a> and see the <a href="http://dev.sencha.com/deploy/ext-4.0.7-gpl/release-notes.html">full release notes for 4.0.7</a> all the way back to 4.0.0.</p>
]]></content:encoded>
			<wfw:commentRss>http://edspencer.net/2011/10/ext-js-4-0-7-released.html/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>SourceDevCon 2011 &#8211; an awesome conference</title>
		<link>http://edspencer.net/2011/05/sourcedevcon-2011-an-awesome-conference.html</link>
		<comments>http://edspencer.net/2011/05/sourcedevcon-2011-an-awesome-conference.html#comments</comments>
		<pubDate>Tue, 10 May 2011 22:11:42 +0000</pubDate>
		<dc:creator>Ed Spencer</dc:creator>
				<category><![CDATA[Misc]]></category>

		<guid isPermaLink="false">http://edspencer.net/?p=619</guid>
		<description><![CDATA[<p>The inaugural <a href="http://www.sourcedevcon.eu/">SouceDevCon</a> just wrapped up in Split, Croatia so I&#8217;d like to share a few thoughts on the last few days. The conference was an enormous success, featuring some great speakers, inspiring presentations and a fantastic group of attendees. Split itself is beautiful, and the weather was equally equitable. More than a few of us are returning a lot browner/redder than we came.</p>
<p><a href="http://www.flickr.com/photos/nils-dehl/sets/72157626533490549/"><img src="http://farm6.static.flickr.com/5143/5696912895_5bd7b3c58b_z.jpg" alt="Grgur" title="Grgur" width="640" height="424" class="aligncenter size-full wp-image-625" /></a></p>
<h2>Day 1</h2>
<p>The conference was spread across 3 days &#8211; the first two were spent listening and learning across the three concurrent tracks, the third on a boat sailing around the Adriatic Sea. Day one kicked off with my colleagues Aditya and James setting out a little of what to expect from Sencha in 2011 in the opening keynote.</p>
<p>Straight after that I took to the stage to introduce a few of the features of Ext JS 4. My session started a little late and I forgot what I was talking about a couple of times (sorry guys <img src='http://edspencer.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ) but I think it turned out well enough. I spliced together the deadly combination of sleep deprivation and live coding but with a little help from the audience we were able to stumble through. I think it would make for a good screencast.</p>
<p>Aditya came on next and introduced our new Sencha.IO services, which seem to have garnered a lot of interest. James showed off the new Ext JS 4 theming support using SASS and Compass and Nils Dehl did a great job explaining the Ext.data and Ext.direct packages. Jay Garcia gave a well-received talk on creating extensions and plugins, during which I think a lot of people learned a great deal about how classes work in Ext JS 4. I also very much enjoyed Tomislav Car&#8217;s investigation into getting Sencha Touch to run on phones other than Androids and iPhones.</p>
<p>Day 1 ended with a long party (I counted at least 8 hours) with inordinate amounts of Croatian beer, which went down very well. It was great meeting so many new people and hearing how much people are getting out of Ext JS and Sencha Touch, as well as what we can improve.</p>
<h2>Day 2</h2>
<p>Day 2 started in a somewhat hungover fashion with some awesome material from our very own Brian Moeskau, who demonstrated how to use the 3.x -> 4.x compatibility file, upgrading an application from 3.3.1 to 4.0.0 in front of our eyes. Nige (Animal) White demonstrated several of Ext JS&#8217;s layout managers before giving one of the highlights of the conference in his debugging JavaScript presentation (by contrast he calls the introduction of errors into code &#8220;bebugging&#8221;).</p>
<p>Tobias Uhlig showed off FieldManager, a sports centre management management application with a Sencha Touch mobile app, while Matz Bryntse and Brian Moeskau demoed their awesome Scheduler and Calendar components. Josef Sakalos (Saki) spent the afternoon teaching people to use Ext JS 4&#8217;s new MVC package, which makes writing apps a faster and more enjoyable experience. He is an excellent teacher.</p>
<p>Our host the inimitable Grgur finished things off with a typically heartfelt ending keynote to wrap up the business end of the conference. The evening was a great opportunity to see some of Split and spend an enjoyable meal with Croatian locals Tomislav, Miro and the ever-logical Lucia. Unfortunately their attempts to teach me Croatian did not yield much success.</p>
<h2>Day 3</h2>
<p>Day 3 was a stroke of genius by Grgur. We took a chartered boat down to the town and looked around the old Roman-era palace. The boat was well stocked with beer and with so many community members in one place the conversation was pretty lively. All of this relaxing was great but with a head full of ideas I&#8217;m anxious to get back to California and better tune our products based on all the feedback I received this week.</p>
<p>All of the sessions were recorded on video and I believe they&#8217;ll be made available in around a month&#8217;s time. If you can&#8217;t wait until then we have a meetup schedule for<a href="http://www.meetup.com/The-San-Francisco-ExtJS-Meetup-Group/events/17576007/"> May 23rd hosted at Sencha HQ</a> in northern California, to which you&#8217;re all invited. Just in case you&#8217;ve never been to Split before perhaps the sight that greeted us when we arrived will prompt you to get yourself on a flight.</p>
<p><img src="http://edspencer.net/wp-content/uploads/2011/05/adriatic.jpg" alt="adriatic" title="adriatic" width="660" height="493" class="aligncenter size-full wp-image-625" /></p>
]]></description>
			<content:encoded><![CDATA[<p>The inaugural <a href="http://www.sourcedevcon.eu/">SouceDevCon</a> just wrapped up in Split, Croatia so I&#8217;d like to share a few thoughts on the last few days. The conference was an enormous success, featuring some great speakers, inspiring presentations and a fantastic group of attendees. Split itself is beautiful, and the weather was equally equitable. More than a few of us are returning a lot browner/redder than we came.</p>
<p><a href="http://www.flickr.com/photos/nils-dehl/sets/72157626533490549/"><img src="http://farm6.static.flickr.com/5143/5696912895_5bd7b3c58b_z.jpg" alt="Grgur" title="Grgur" width="640" height="424" class="aligncenter size-full wp-image-625" /></a></p>
<h2>Day 1</h2>
<p>The conference was spread across 3 days &#8211; the first two were spent listening and learning across the three concurrent tracks, the third on a boat sailing around the Adriatic Sea. Day one kicked off with my colleagues Aditya and James setting out a little of what to expect from Sencha in 2011 in the opening keynote.</p>
<p>Straight after that I took to the stage to introduce a few of the features of Ext JS 4. My session started a little late and I forgot what I was talking about a couple of times (sorry guys <img src='http://edspencer.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ) but I think it turned out well enough. I spliced together the deadly combination of sleep deprivation and live coding but with a little help from the audience we were able to stumble through. I think it would make for a good screencast.</p>
<p>Aditya came on next and introduced our new Sencha.IO services, which seem to have garnered a lot of interest. James showed off the new Ext JS 4 theming support using SASS and Compass and Nils Dehl did a great job explaining the Ext.data and Ext.direct packages. Jay Garcia gave a well-received talk on creating extensions and plugins, during which I think a lot of people learned a great deal about how classes work in Ext JS 4. I also very much enjoyed Tomislav Car&#8217;s investigation into getting Sencha Touch to run on phones other than Androids and iPhones.</p>
<p>Day 1 ended with a long party (I counted at least 8 hours) with inordinate amounts of Croatian beer, which went down very well. It was great meeting so many new people and hearing how much people are getting out of Ext JS and Sencha Touch, as well as what we can improve.</p>
<h2>Day 2</h2>
<p>Day 2 started in a somewhat hungover fashion with some awesome material from our very own Brian Moeskau, who demonstrated how to use the 3.x -> 4.x compatibility file, upgrading an application from 3.3.1 to 4.0.0 in front of our eyes. Nige (Animal) White demonstrated several of Ext JS&#8217;s layout managers before giving one of the highlights of the conference in his debugging JavaScript presentation (by contrast he calls the introduction of errors into code &#8220;bebugging&#8221;).</p>
<p>Tobias Uhlig showed off FieldManager, a sports centre management management application with a Sencha Touch mobile app, while Matz Bryntse and Brian Moeskau demoed their awesome Scheduler and Calendar components. Josef Sakalos (Saki) spent the afternoon teaching people to use Ext JS 4&#8217;s new MVC package, which makes writing apps a faster and more enjoyable experience. He is an excellent teacher.</p>
<p>Our host the inimitable Grgur finished things off with a typically heartfelt ending keynote to wrap up the business end of the conference. The evening was a great opportunity to see some of Split and spend an enjoyable meal with Croatian locals Tomislav, Miro and the ever-logical Lucia. Unfortunately their attempts to teach me Croatian did not yield much success.</p>
<h2>Day 3</h2>
<p>Day 3 was a stroke of genius by Grgur. We took a chartered boat down to the town and looked around the old Roman-era palace. The boat was well stocked with beer and with so many community members in one place the conversation was pretty lively. All of this relaxing was great but with a head full of ideas I&#8217;m anxious to get back to California and better tune our products based on all the feedback I received this week.</p>
<p>All of the sessions were recorded on video and I believe they&#8217;ll be made available in around a month&#8217;s time. If you can&#8217;t wait until then we have a meetup schedule for<a href="http://www.meetup.com/The-San-Francisco-ExtJS-Meetup-Group/events/17576007/"> May 23rd hosted at Sencha HQ</a> in northern California, to which you&#8217;re all invited. Just in case you&#8217;ve never been to Split before perhaps the sight that greeted us when we arrived will prompt you to get yourself on a flight.</p>
<p><img src="http://edspencer.net/wp-content/uploads/2011/05/adriatic.jpg" alt="adriatic" title="adriatic" width="660" height="493" class="aligncenter size-full wp-image-625" /></p>
]]></content:encoded>
			<wfw:commentRss>http://edspencer.net/2011/05/sourcedevcon-2011-an-awesome-conference.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Proxies in Ext JS 4</title>
		<link>http://edspencer.net/2011/02/proxies-extjs-4.html</link>
		<comments>http://edspencer.net/2011/02/proxies-extjs-4.html#comments</comments>
		<pubDate>Wed, 02 Feb 2011 16:22:59 +0000</pubDate>
		<dc:creator>Ed Spencer</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[Misc]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[proxy]]></category>
		<category><![CDATA[reader]]></category>
		<category><![CDATA[sencha]]></category>
		<category><![CDATA[senchatouch]]></category>

		<guid isPermaLink="false">http://edspencer.net/?p=583</guid>
		<description><![CDATA[<p>One of the classes that has a lot more prominence in Ext JS 4 is the data Proxy. Proxies are responsible for all of the loading and saving of data in an Ext JS 4 or Sencha Touch application. Whenever you&#8217;re creating, updating, deleting or loading any type of data in your app, you&#8217;re almost certainly doing it via an Ext.data.Proxy.</p>
<p>If you&#8217;ve seen <a href="http://t.co/wTRxmlE">January&#8217;s Sencha newsletter</a> you may have read an article called <a href="http://www.sencha.com/blog/ext-js-4-anatomy-of-a-model/">Anatomy of a Model</a>, which introduces the most commonly-used Proxies. All a Proxy really needs is four functions &#8211; create, read, update and destroy. For an AjaxProxy, each of these will result in an Ajax request being made. For a LocalStorageProxy, the functions will create, read, update or delete records from HTML5 localStorage.</p>
<p>Because Proxies all implement the same interface they&#8217;re completely interchangeable, so you can swap out your data source &#8211; at design time or run time &#8211; without changing any other code. Although the local Proxies like LocalStorageProxy and MemoryProxy are self-contained, the remote Proxies like AjaxProxy and ScriptTagProxy make use of Readers and Writers to encode and decode their data when communicating with the server.</p>
<p><img src="http://edspencer.net/wp-content/uploads/2011/02/Proxy-Reader-and-Writer.png" alt="Proxy-Reader-and-Writer" title="Proxy-Reader-and-Writer" width="660" height="289" class="aligncenter size-full wp-image-585" /></p>
<p>Whether we are reading data from a server or preparing data to be sent back, usually we format it as either JSON or XML. Both of our frameworks come with JSON and XML Readers and Writers which handle all of this for you with a very simple API.</p>
<h3>Using a Proxy with a Model</h3>
<p>Proxies are usually used along with either a Model or a Store. The simplest setup is just with a model:</p>
<pre class="brush: jscript;">
var User = Ext.regModel('User', {
    fields: ['id', 'name', 'email'],

    proxy: {
        type: 'rest',
        url : '/users',
        reader: {
            type: 'json',
            root: 'users'
        }
    }
});
</pre>
<p>Here we&#8217;ve created a User model with a RestProxy. RestProxy is a special form of AjaxProxy that can automatically figure out Restful urls for our models. The Proxy that we set up features a JsonReader to decode any server responses &#8211; check out the recent <a href="http://www.sencha.com/blog/2011/01/21/countdown-to-ext-js-4-data-package/">data package post</a> on the Sencha blog to see Readers in action.</p>
<p>When we use the following functions on the new User model, the Proxy is called behind the scenes:</p>
<pre class="brush: jscript;">
var user = new User({name: 'Ed Spencer'});

//CREATE: calls the RestProxy's create function because the user has never been saved
user.save();

//UPDATE: calls the RestProxy's update function because it has been saved before
user.set('email', 'ed@sencha.com');

//DESTROY: calls the RestProxy's destroy function
user.destroy();

//READ: calls the RestProxy's read function
User.load(123, {
    success: function(user) {
        console.log(user);
    }
});
</pre>
<p>We were able to perform all four CRUD operations just by specifying a Proxy for our Model. Notice that the first 3 calls are instance methods whereas the fourth (User.load) is static on the User model. Note also that you can create a Model without a Proxy, you just won&#8217;t be able to persist it.</p>
<h3>Usage with Stores</h3>
<p>In Ext JS 3.x, most of the data manipulation was done via Stores. A chief purpose of a Store is to be a local subset of some data plus delta. For example, you might have 1000 products in your database and have 25 of them loaded into a Store on the client side (the local subset). While operating on that subset, your user may have added, updated or deleted some of the Products. Until these changes are synchronized with the server they are known as a delta.</p>
<p>In order to read data from and sync to the server, Stores also need to be able to call those CRUD operations. We can give a Store a Proxy in the same way:</p>
<pre class="brush: jscript;">
var store = new Ext.data.Store({
    model: 'User',
    proxy: {
        type: 'rest',
        url : '/users',
        reader: {
            type: 'json',
            root: 'users'
        }
    }
});
</pre>
<p>We created the exact same Proxy for the Store because that&#8217;s how our server side is set up to deliver data. Because we&#8217;ll usually want to use the same Proxy mechanism for all User manipulations, it&#8217;s usually best to just define the Proxy once on the Model and then simply tell the Store which Model to use. This automatically picks up the User model&#8217;s Proxy:</p>
<pre class="brush: jscript;">
//no need to define proxy - this will reuse the User's Proxy
var store = new Ext.data.Store({
    model: 'User'
});
</pre>
<p>Store invokes the CRUD operations via its <em>load</em> and <em>sync</em> functions. Calling load uses the Proxy&#8217;s read operation, which sync utilizes one or more of create, update and destroy depending on the current Store delta.</p>
<pre class="brush: jscript;">
//CREATE: calls the RestProxy's create function to create the Tommy record on the server
store.add({name: 'Tommy Maintz'});
store.sync();

//UPDATE: calls the RestProxy's update function to update the Tommy record on the server
store.getAt(1).set('email', 'tommy@sencha.com');
store.sync();

//DESTROY: calls the RestProxy's destroy function
store.remove(store.getAt(1));
store.sync();

//READ: calls the RestProxy's read function
store.load();
</pre>
<p>Store has used the exact same CRUD operations on the shared Proxy. In all of the examples above we have used the exact same RestProxy instance from three different places: statically on our Model (User.load), as a Model instance method (user.save, user.destroy) and via a Store instance (store.load, store.sync):</p>
<p><img src="http://edspencer.net/wp-content/uploads/2011/02/Proxy-reuse.png" alt="Proxy-reuse" title="Proxy-reuse" width="599" height="236" class="aligncenter size-full wp-image-598" /></p>
<p>Of course, most Proxies have their own private methods to do the actual work, but all a Proxy needs to do is implement those four functions to be usable with Ext JS 4 and Sencha Touch. This means it&#8217;s easy to create new Proxies, as James Pearce did in a <a href="http://www.sencha.com/learn/Tutorial:A_Sencha_Touch_MVC_application_with_PhoneGap">recent Sencha Touch example</a> where he needed to read address book data from a mobile phone. Everything he does to set up his Proxy <a href="http://www.sencha.com/learn/Tutorial:A_Sencha_Touch_MVC_application_with_PhoneGap">in the article</a> (about 1/3rd of the way down) works the same way for Ext JS 4 too.</p>
]]></description>
			<content:encoded><![CDATA[<p>One of the classes that has a lot more prominence in Ext JS 4 is the data Proxy. Proxies are responsible for all of the loading and saving of data in an Ext JS 4 or Sencha Touch application. Whenever you&#8217;re creating, updating, deleting or loading any type of data in your app, you&#8217;re almost certainly doing it via an Ext.data.Proxy.</p>
<p>If you&#8217;ve seen <a href="http://t.co/wTRxmlE">January&#8217;s Sencha newsletter</a> you may have read an article called <a href="http://www.sencha.com/blog/ext-js-4-anatomy-of-a-model/">Anatomy of a Model</a>, which introduces the most commonly-used Proxies. All a Proxy really needs is four functions &#8211; create, read, update and destroy. For an AjaxProxy, each of these will result in an Ajax request being made. For a LocalStorageProxy, the functions will create, read, update or delete records from HTML5 localStorage.</p>
<p>Because Proxies all implement the same interface they&#8217;re completely interchangeable, so you can swap out your data source &#8211; at design time or run time &#8211; without changing any other code. Although the local Proxies like LocalStorageProxy and MemoryProxy are self-contained, the remote Proxies like AjaxProxy and ScriptTagProxy make use of Readers and Writers to encode and decode their data when communicating with the server.</p>
<p><img src="http://edspencer.net/wp-content/uploads/2011/02/Proxy-Reader-and-Writer.png" alt="Proxy-Reader-and-Writer" title="Proxy-Reader-and-Writer" width="660" height="289" class="aligncenter size-full wp-image-585" /></p>
<p>Whether we are reading data from a server or preparing data to be sent back, usually we format it as either JSON or XML. Both of our frameworks come with JSON and XML Readers and Writers which handle all of this for you with a very simple API.</p>
<h3>Using a Proxy with a Model</h3>
<p>Proxies are usually used along with either a Model or a Store. The simplest setup is just with a model:</p>
<pre class="brush: jscript;">
var User = Ext.regModel('User', {
    fields: ['id', 'name', 'email'],

    proxy: {
        type: 'rest',
        url : '/users',
        reader: {
            type: 'json',
            root: 'users'
        }
    }
});
</pre>
<p>Here we&#8217;ve created a User model with a RestProxy. RestProxy is a special form of AjaxProxy that can automatically figure out Restful urls for our models. The Proxy that we set up features a JsonReader to decode any server responses &#8211; check out the recent <a href="http://www.sencha.com/blog/2011/01/21/countdown-to-ext-js-4-data-package/">data package post</a> on the Sencha blog to see Readers in action.</p>
<p>When we use the following functions on the new User model, the Proxy is called behind the scenes:</p>
<pre class="brush: jscript;">
var user = new User({name: 'Ed Spencer'});

//CREATE: calls the RestProxy's create function because the user has never been saved
user.save();

//UPDATE: calls the RestProxy's update function because it has been saved before
user.set('email', 'ed@sencha.com');

//DESTROY: calls the RestProxy's destroy function
user.destroy();

//READ: calls the RestProxy's read function
User.load(123, {
    success: function(user) {
        console.log(user);
    }
});
</pre>
<p>We were able to perform all four CRUD operations just by specifying a Proxy for our Model. Notice that the first 3 calls are instance methods whereas the fourth (User.load) is static on the User model. Note also that you can create a Model without a Proxy, you just won&#8217;t be able to persist it.</p>
<h3>Usage with Stores</h3>
<p>In Ext JS 3.x, most of the data manipulation was done via Stores. A chief purpose of a Store is to be a local subset of some data plus delta. For example, you might have 1000 products in your database and have 25 of them loaded into a Store on the client side (the local subset). While operating on that subset, your user may have added, updated or deleted some of the Products. Until these changes are synchronized with the server they are known as a delta.</p>
<p>In order to read data from and sync to the server, Stores also need to be able to call those CRUD operations. We can give a Store a Proxy in the same way:</p>
<pre class="brush: jscript;">
var store = new Ext.data.Store({
    model: 'User',
    proxy: {
        type: 'rest',
        url : '/users',
        reader: {
            type: 'json',
            root: 'users'
        }
    }
});
</pre>
<p>We created the exact same Proxy for the Store because that&#8217;s how our server side is set up to deliver data. Because we&#8217;ll usually want to use the same Proxy mechanism for all User manipulations, it&#8217;s usually best to just define the Proxy once on the Model and then simply tell the Store which Model to use. This automatically picks up the User model&#8217;s Proxy:</p>
<pre class="brush: jscript;">
//no need to define proxy - this will reuse the User's Proxy
var store = new Ext.data.Store({
    model: 'User'
});
</pre>
<p>Store invokes the CRUD operations via its <em>load</em> and <em>sync</em> functions. Calling load uses the Proxy&#8217;s read operation, which sync utilizes one or more of create, update and destroy depending on the current Store delta.</p>
<pre class="brush: jscript;">
//CREATE: calls the RestProxy's create function to create the Tommy record on the server
store.add({name: 'Tommy Maintz'});
store.sync();

//UPDATE: calls the RestProxy's update function to update the Tommy record on the server
store.getAt(1).set('email', 'tommy@sencha.com');
store.sync();

//DESTROY: calls the RestProxy's destroy function
store.remove(store.getAt(1));
store.sync();

//READ: calls the RestProxy's read function
store.load();
</pre>
<p>Store has used the exact same CRUD operations on the shared Proxy. In all of the examples above we have used the exact same RestProxy instance from three different places: statically on our Model (User.load), as a Model instance method (user.save, user.destroy) and via a Store instance (store.load, store.sync):</p>
<p><img src="http://edspencer.net/wp-content/uploads/2011/02/Proxy-reuse.png" alt="Proxy-reuse" title="Proxy-reuse" width="599" height="236" class="aligncenter size-full wp-image-598" /></p>
<p>Of course, most Proxies have their own private methods to do the actual work, but all a Proxy needs to do is implement those four functions to be usable with Ext JS 4 and Sencha Touch. This means it&#8217;s easy to create new Proxies, as James Pearce did in a <a href="http://www.sencha.com/learn/Tutorial:A_Sencha_Touch_MVC_application_with_PhoneGap">recent Sencha Touch example</a> where he needed to read address book data from a mobile phone. Everything he does to set up his Proxy <a href="http://www.sencha.com/learn/Tutorial:A_Sencha_Touch_MVC_application_with_PhoneGap">in the article</a> (about 1/3rd of the way down) works the same way for Ext JS 4 too.</p>
]]></content:encoded>
			<wfw:commentRss>http://edspencer.net/2011/02/proxies-extjs-4.html/feed</wfw:commentRss>
		<slash:comments>39</slash:comments>
		</item>
		<item>
		<title>Introduction to Ext JS 4</title>
		<link>http://edspencer.net/2011/01/introducing-ext-js-4.html</link>
		<comments>http://edspencer.net/2011/01/introducing-ext-js-4.html#comments</comments>
		<pubDate>Thu, 27 Jan 2011 16:30:20 +0000</pubDate>
		<dc:creator>Ed Spencer</dc:creator>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[extjs4]]></category>
		<category><![CDATA[senchacon]]></category>
		<category><![CDATA[talk]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://edspencer.net/?p=566</guid>
		<description><![CDATA[<p>At the end of last 2010 we capped off an incredible year with SenchaCon &#8211; by far the biggest gathering of Sencha developers ever assembled. We descended on San Francisco, 500 strong, and spent an amazing few days sharing the awesome new stuff we&#8217;re working on, learning from each other, and addressing the web&#8217;s most pressing problems.</p>
<p>Now, we&#8217;re proud to release <a href="http://www.sencha.com/conference/sessions/videos.php">all of the videos</a> from the conference completely free for everyone. You can see a <a href="http://www.sencha.com/conference/sessions/videos.php">full list</a> on our conference site, where you&#8217;ll find days worth of material all about Ext JS 4, Sencha Touch and all of the other treats we&#8217;re working on at the moment. </p>
<p>Some of the videos in particular stand out for me &#8211; Jamie&#8217;s <a href="http://vimeo.com/17673342">Charting</a> and <a href="http://vimeo.com/17917111">Layouts</a> talks were spectacular, as was Rob&#8217;s <a href="http://vimeo.com/19159630">Theming Ext JS 4</a> talk. On the Touch side, Tommy&#8217;s talks on <a href="http://vimeo.com/17699976">Performance</a> and <a href="http://vimeo.com/17853133">Debugging</a> are required viewing, as is Dave Kaneda&#8217;s characteristically off the cuff <a href="http://vimeo.com/17705448">Theming</a> talk.</p>
<p>My personal high point was standing in front of all of you and introducing Ext JS 4 and its three core goals &#8211; speed, stability and ease of use. I think you&#8217;re going to love what we&#8217;ve done with the framework in version 4, but for now I&#8217;ll let the video do the talking:</p>
<p><iframe src="http://player.vimeo.com/video/17666102" width="650" height="380" frameborder="0"></iframe></p>
<p>If you&#8217;re so inclined, you can find the <a href="http://www.slideshare.net/edspencer/intro-to-ext-4">slides for this talk</a> on slideshare, and if you can still stand the sound of my voice check out my other presentation on <a href="http://vimeo.com/17733892">Ext JS 4 Architecture</a>, focusing chiefly on the new data package (<a href="http://www.slideshare.net/edspencer/ext-js-4-architecture">slides</a>).</p>
]]></description>
			<content:encoded><![CDATA[<p>At the end of last 2010 we capped off an incredible year with SenchaCon &#8211; by far the biggest gathering of Sencha developers ever assembled. We descended on San Francisco, 500 strong, and spent an amazing few days sharing the awesome new stuff we&#8217;re working on, learning from each other, and addressing the web&#8217;s most pressing problems.</p>
<p>Now, we&#8217;re proud to release <a href="http://www.sencha.com/conference/sessions/videos.php">all of the videos</a> from the conference completely free for everyone. You can see a <a href="http://www.sencha.com/conference/sessions/videos.php">full list</a> on our conference site, where you&#8217;ll find days worth of material all about Ext JS 4, Sencha Touch and all of the other treats we&#8217;re working on at the moment. </p>
<p>Some of the videos in particular stand out for me &#8211; Jamie&#8217;s <a href="http://vimeo.com/17673342">Charting</a> and <a href="http://vimeo.com/17917111">Layouts</a> talks were spectacular, as was Rob&#8217;s <a href="http://vimeo.com/19159630">Theming Ext JS 4</a> talk. On the Touch side, Tommy&#8217;s talks on <a href="http://vimeo.com/17699976">Performance</a> and <a href="http://vimeo.com/17853133">Debugging</a> are required viewing, as is Dave Kaneda&#8217;s characteristically off the cuff <a href="http://vimeo.com/17705448">Theming</a> talk.</p>
<p>My personal high point was standing in front of all of you and introducing Ext JS 4 and its three core goals &#8211; speed, stability and ease of use. I think you&#8217;re going to love what we&#8217;ve done with the framework in version 4, but for now I&#8217;ll let the video do the talking:</p>
<p><iframe src="http://player.vimeo.com/video/17666102" width="650" height="380" frameborder="0"></iframe></p>
<p>If you&#8217;re so inclined, you can find the <a href="http://www.slideshare.net/edspencer/intro-to-ext-4">slides for this talk</a> on slideshare, and if you can still stand the sound of my voice check out my other presentation on <a href="http://vimeo.com/17733892">Ext JS 4 Architecture</a>, focusing chiefly on the new data package (<a href="http://www.slideshare.net/edspencer/ext-js-4-architecture">slides</a>).</p>
]]></content:encoded>
			<wfw:commentRss>http://edspencer.net/2011/01/introducing-ext-js-4.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Ext JS 4: The Class Definition Pipeline</title>
		<link>http://edspencer.net/2011/01/ext-js-4-the-class-definition-pipeline.html</link>
		<comments>http://edspencer.net/2011/01/ext-js-4-the-class-definition-pipeline.html#comments</comments>
		<pubDate>Tue, 25 Jan 2011 16:25:00 +0000</pubDate>
		<dc:creator>Ed Spencer</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[Misc]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[classes]]></category>
		<category><![CDATA[extjs4]]></category>

		<guid isPermaLink="false">http://edspencer.net/?p=538</guid>
		<description><![CDATA[<p>Last time, we looked at some of the features of the <a href="http://edspencer.net/2011/01/classes-in-ext-js-4-under-the-hood.html">new class system in Ext JS 4</a>, and explored some of the code that makes it work. Today we&#8217;re going to dig a little deeper and look at the class definition pipeline &#8211; the framework responsible for creating every class in Ext JS 4.</p>
<p><a href="http://edspencer.net/2011/01/classes-in-ext-js-4-under-the-hood.html">As I mentioned last time</a>, every class in Ext JS 4 is an instance of Ext.Class. When an Ext.Class is constructed, it hands itself off to a pipeline populated by small, focused processors, each of which handles one part of the class definition process. We ship a number of these processors out of the box &#8211; there are processors for handling mixins, setting up configuration functions and handling class extension.</p>
<p>The pipeline is probably best explained with a picture. Think of your class starting its definition journey at the bottom left, working its way up the preprocessors on the left hand side and then down the postprocessors on the right, until finally it reaches the end, where it signals its readiness to a callback function:</p>
<p><img src="http://edspencer.net/wp-content/uploads/2011/01/Processors.png" alt="Ext JS 4 Class Definition Pipeline" title="Ext JS 4 Class Definition Pipeline" width="687" height="537" class="aligncenter size-full wp-image-528" /></p>
<p>The distinction between preprocessors and postprocessors is that a class is considered ‘ready’ (e.g. can be instantiated) after the preprocessors have all been executed. Postprocessors typically perform functions like aliasing the class name to an xtype or back to a legacy class name &#8211; things that don&#8217;t affect the class&#8217; behavior.</p>
<p>Each processor runs asynchronously, calling back to the Ext.Class constructor when it is ready &#8211; this is what enables us to extend classes that don’t exist on the page yet. The first preprocessor is the Loader, which checks to see if all of the new Class’ dependencies are available. If they are not, the Loader can dynamically load those dependencies before calling back to Ext.Class and allowing the next preprocessor to run. We&#8217;ll take another look at the Loader in another post.</p>
<p>After running the Loader, the new Class is set up to inherit from the declared superclass by the Extend preprocessor. The Mixins preprocessor takes care of copying all of the functions from each of our mixins, and the Config preprocessor handles the creation of the 4 config functions we saw last time (e.g. getTitle, setTitle, resetTitle, applyTitle &#8211; check out <a href="http://edspencer.net/2011/01/classes-in-ext-js-4-under-the-hood.html">yesterday&#8217;s post</a> to see how the Configs processor helps out).</p>
<p>Finally, the Statics preprocessor looks for any static functions that we set up on our new class and makes them available statically on the class. The processors that are run are completely customizable, and it’s easy to add custom processors at any point. Let&#8217;s take a look at that Statics preprocessor as an example:</p>
<pre class="brush: jscript;">
//Each processor is passed three arguments - the class under construction,
//the configuration for that class and a callback function to call when the processor has finished
Ext.Class.registerPreprocessor('statics', function(cls, data, callback) {
    if (Ext.isObject(data.statics)) {
        var statics = data.statics,
            name;

        //here we just copy each static function onto the new Class
        for (name in statics) {
            if (statics.hasOwnProperty(name)) {
                cls[name] = statics[name];
            }
        }
    }

    delete data.statics;

    //Once the processor's work is done, we just call the callback function to kick off the next processor
    if (callback) {
        callback.call(this, cls, data);
    }
});

//Changing the order that the preprocessors are called in is easy too - this is the default
Ext.Class.setDefaultPreprocessors(['extend', 'mixins', 'config', 'statics']);
</pre>
<p>What happens above is pretty straightforward. We&#8217;re registering a preprocessor called &#8217;statics&#8217; with Ext.Class. The function we provide is called whenever the &#8217;statics&#8217; preprocessor is invoked, and is passed the new Ext.Class instance, the configuration for that class, and a callback to call when the preprocessor has finished its work.</p>
<p>The actual work that this preprocessor does is trivial &#8211; it just looks to see if we declared a &#8217;statics&#8217; property in our class configuration and if so copies it onto the new class. For example, let&#8217;s say we want to create a static getNextId function on a class:</p>
<pre class="brush: jscript;">
Ext.define('MyClass', {
    statics: {
        idSeed: 1000,
        getNextId: function() {
            return this.idSeed++;
        }
    }
});
</pre>
<p>Because of the Statics preprocessor, we can now call the function statically on the Class (e.g. without creating an instance of MyClass):</p>
<pre class="brush: jscript;">
MyClass.getNextId(); //1000
MyClass.getNextId(); //1001
MyClass.getNextId(); //1002
... etc
</pre>
<p>Finally, let&#8217;s come back to that callback at the bottom of the picture above. If we supply one, a callback function is run after all of the processors have run. At this point the new class is completely ready for use in your application. Here we create an instance of MyClass using the callback function, guaranteeing that the dependency on Ext.Window has been honored:</p>
<pre class="brush: jscript;">
Ext.define('MyClass', {
    extend: 'Ext.Window'
}, function() {
   //this callback is called when MyClass is ready for use
   var cls = new MyClass();
   cls.setTitle('Everything is ready');
   cls.show();
});
</pre>
<p>That&#8217;s it for today. Next time we&#8217;ll look at some of the new features in the part of Ext JS 4 that is closest to my heart &#8211; the data package.</p>
]]></description>
			<content:encoded><![CDATA[<p>Last time, we looked at some of the features of the <a href="http://edspencer.net/2011/01/classes-in-ext-js-4-under-the-hood.html">new class system in Ext JS 4</a>, and explored some of the code that makes it work. Today we&#8217;re going to dig a little deeper and look at the class definition pipeline &#8211; the framework responsible for creating every class in Ext JS 4.</p>
<p><a href="http://edspencer.net/2011/01/classes-in-ext-js-4-under-the-hood.html">As I mentioned last time</a>, every class in Ext JS 4 is an instance of Ext.Class. When an Ext.Class is constructed, it hands itself off to a pipeline populated by small, focused processors, each of which handles one part of the class definition process. We ship a number of these processors out of the box &#8211; there are processors for handling mixins, setting up configuration functions and handling class extension.</p>
<p>The pipeline is probably best explained with a picture. Think of your class starting its definition journey at the bottom left, working its way up the preprocessors on the left hand side and then down the postprocessors on the right, until finally it reaches the end, where it signals its readiness to a callback function:</p>
<p><img src="http://edspencer.net/wp-content/uploads/2011/01/Processors.png" alt="Ext JS 4 Class Definition Pipeline" title="Ext JS 4 Class Definition Pipeline" width="687" height="537" class="aligncenter size-full wp-image-528" /></p>
<p>The distinction between preprocessors and postprocessors is that a class is considered ‘ready’ (e.g. can be instantiated) after the preprocessors have all been executed. Postprocessors typically perform functions like aliasing the class name to an xtype or back to a legacy class name &#8211; things that don&#8217;t affect the class&#8217; behavior.</p>
<p>Each processor runs asynchronously, calling back to the Ext.Class constructor when it is ready &#8211; this is what enables us to extend classes that don’t exist on the page yet. The first preprocessor is the Loader, which checks to see if all of the new Class’ dependencies are available. If they are not, the Loader can dynamically load those dependencies before calling back to Ext.Class and allowing the next preprocessor to run. We&#8217;ll take another look at the Loader in another post.</p>
<p>After running the Loader, the new Class is set up to inherit from the declared superclass by the Extend preprocessor. The Mixins preprocessor takes care of copying all of the functions from each of our mixins, and the Config preprocessor handles the creation of the 4 config functions we saw last time (e.g. getTitle, setTitle, resetTitle, applyTitle &#8211; check out <a href="http://edspencer.net/2011/01/classes-in-ext-js-4-under-the-hood.html">yesterday&#8217;s post</a> to see how the Configs processor helps out).</p>
<p>Finally, the Statics preprocessor looks for any static functions that we set up on our new class and makes them available statically on the class. The processors that are run are completely customizable, and it’s easy to add custom processors at any point. Let&#8217;s take a look at that Statics preprocessor as an example:</p>
<pre class="brush: jscript;">
//Each processor is passed three arguments - the class under construction,
//the configuration for that class and a callback function to call when the processor has finished
Ext.Class.registerPreprocessor('statics', function(cls, data, callback) {
    if (Ext.isObject(data.statics)) {
        var statics = data.statics,
            name;

        //here we just copy each static function onto the new Class
        for (name in statics) {
            if (statics.hasOwnProperty(name)) {
                cls[name] = statics[name];
            }
        }
    }

    delete data.statics;

    //Once the processor's work is done, we just call the callback function to kick off the next processor
    if (callback) {
        callback.call(this, cls, data);
    }
});

//Changing the order that the preprocessors are called in is easy too - this is the default
Ext.Class.setDefaultPreprocessors(['extend', 'mixins', 'config', 'statics']);
</pre>
<p>What happens above is pretty straightforward. We&#8217;re registering a preprocessor called &#8217;statics&#8217; with Ext.Class. The function we provide is called whenever the &#8217;statics&#8217; preprocessor is invoked, and is passed the new Ext.Class instance, the configuration for that class, and a callback to call when the preprocessor has finished its work.</p>
<p>The actual work that this preprocessor does is trivial &#8211; it just looks to see if we declared a &#8217;statics&#8217; property in our class configuration and if so copies it onto the new class. For example, let&#8217;s say we want to create a static getNextId function on a class:</p>
<pre class="brush: jscript;">
Ext.define('MyClass', {
    statics: {
        idSeed: 1000,
        getNextId: function() {
            return this.idSeed++;
        }
    }
});
</pre>
<p>Because of the Statics preprocessor, we can now call the function statically on the Class (e.g. without creating an instance of MyClass):</p>
<pre class="brush: jscript;">
MyClass.getNextId(); //1000
MyClass.getNextId(); //1001
MyClass.getNextId(); //1002
... etc
</pre>
<p>Finally, let&#8217;s come back to that callback at the bottom of the picture above. If we supply one, a callback function is run after all of the processors have run. At this point the new class is completely ready for use in your application. Here we create an instance of MyClass using the callback function, guaranteeing that the dependency on Ext.Window has been honored:</p>
<pre class="brush: jscript;">
Ext.define('MyClass', {
    extend: 'Ext.Window'
}, function() {
   //this callback is called when MyClass is ready for use
   var cls = new MyClass();
   cls.setTitle('Everything is ready');
   cls.show();
});
</pre>
<p>That&#8217;s it for today. Next time we&#8217;ll look at some of the new features in the part of Ext JS 4 that is closest to my heart &#8211; the data package.</p>
]]></content:encoded>
			<wfw:commentRss>http://edspencer.net/2011/01/ext-js-4-the-class-definition-pipeline.html/feed</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Classes in Ext JS 4: Under the hood</title>
		<link>http://edspencer.net/2011/01/classes-in-ext-js-4-under-the-hood.html</link>
		<comments>http://edspencer.net/2011/01/classes-in-ext-js-4-under-the-hood.html#comments</comments>
		<pubDate>Mon, 24 Jan 2011 16:37:22 +0000</pubDate>
		<dc:creator>Ed Spencer</dc:creator>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[classes]]></category>
		<category><![CDATA[dynamic loading]]></category>
		<category><![CDATA[extjs4]]></category>

		<guid isPermaLink="false">http://edspencer.net/?p=518</guid>
		<description><![CDATA[<p>Last week we unveiled a the brand new class system coming in Ext JS 4. If you haven’t seen the new system in action I hope you’ll take a look at the <a href="http://www.sencha.com/blog/2011/01/19/countdown-to-ext-js-4-dynamic-loading-and-new-class-system/">blog post</a> on sencha.com and check out the <a href="http://dev.sencha.com/deploy/LoaderDemo/">live demo</a>. Today we’re going to dig a little deeper into the class system to see how it actually works.</p>
<p>To briefly recap, the new class system enables us to define classes like this:</p>
<pre class="brush: jscript;">
Ext.define('Ext.Window', {
    extend: 'Ext.Panel',
    requires: 'Ext.Tool',
    mixins: {
        draggable: 'Ext.util.Draggable'
    },

    config: {
        title: &quot;Window Title&quot;
    }
});
</pre>
<p>Here we’ve set up a slightly simplified version of the Ext.Window class. We’ve set Window up to be a subclass of Panel, declared that it requires the Ext.Tool class and that it mixes in functionality from the Ext.util.Draggable class.</p>
<p>There are a few new things here so we’ll attack them one at a time. The ‘extend’ declaration does what you’d expect &#8211; we’re just saying that Window should be a subclass of Panel. The ‘requires’ declaration means that the named classes (just Ext.Tool in this case) have to be present before the Window class can be considered ‘ready’ for use (more on class readiness in a moment).</p>
<p>The ‘mixins’ declaration is a brand new concept when it comes to Ext JS. A mixin is just a set of functions (and sometimes properties) that are merged into a class. For example, the Ext.util.Draggable mixin we defined above might contain a function called ‘startDragging’ &#8211; this gets copied into Ext.Window to enable us to use the function in a window instance:</p>
<pre class="brush: jscript;">
//a simplified Draggable mixin
Ext.define('Ext.util.Draggable', {
    startDragging: function() {
        console.log('started dragging');
    }
});
</pre>
<p>When we create a new Ext.Window instance now, we can call the function that was mixed in from Ext.util.Draggable:</p>
<pre class="brush: jscript;">
var win = Ext.create('Ext.Window');
win.startDragging(); //&quot;started dragging&quot;
</pre>
<p>Mixins are really useful when a class needs to inherit multiple traits but can’t do so easily using a traditional single inheritance mechanism. For example, Ext.Windows is a draggable component, as are Sliders, Grid headers, and many other UI elements. Because this behavior crops up in many different places it’s not feasible to work the draggable behavior into a single superclass because not all of those UI elements actually share a common superclass. Creating a Draggable mixin solves this problem &#8211; now anything can be made draggable with a couple of lines of code.</p>
<p>The last new piece of functionality I’ll mention briefly is the ‘config’ declaration. Most of the classes in Ext JS take configuration parameters, many of which can be changed at runtime. In the Ext.Window above example we declared that the class has a ‘title’ configuration, which takes the default value of ‘Window Title’. By setting the class up like this we get 4 methods for free &#8211; getTitle, setTitle, resetTitle and applyTitle.</p>
<ul>
<li><b>getTitle</b> &#8211; returns the current title</li>
<li><b>setTitle</b> &#8211; sets the title to a new value</li>
<li><b>resetTitle</b> &#8211;  reverts the title to its default value (‘Window Title’)</li>
<li><b>applyTitle</b> &#8211; this is a template method that you can choose to define. It is called whenever setTitle is called.
</ul>
<p>The applyTitle function is the place to put any logic that needs to be called when the title is changed &#8211; for example we might want to update a DOM Element with the new title:</p>
<pre class="brush: jscript;">
Ext.define(‘Ext.Window’, {
    //..as above,

    config: {
        title: 'Window Title'
    },

    //updates the DOM element that contains the window title
    applyTitle: function(newTitle) {
        this.titleEl.update(newTitle);
    }
});
</pre>
<p>This saves us a lot of time and code while providing a consistent API for all configuration options: win-win.</p>
<h3>Digging Deeper</h3>
<p>Ext JS 4 introduces 4 new classes to make all this magic work:</p>
<ul>
<li><b>Ext.Base</b> &#8211; all classes inherit from Ext.Base. It provides basic low-level functionality used by all classes</li>
<li><b>Ext.Class</b> &#8211; a factory for making new classes</li>
<li><b>Ext.ClassLoader</b> &#8211; responsible for ensuring that classes are available, loading them if they aren’t on the page already</li>
<li><b>Ext.ClassManager</b> &#8211; kicks off class creation and manages dependencies</li>
</ul>
<p>These all work together behind the scenes and most of the time you won’t even need to be aware of what is being called when you define and use a class. The two functions that you’ll use most often &#8211; Ext.define and Ext.create &#8211; both call Ext.ClassManager under the hood, which in turn utilizes the other three classes to put everything together.</p>
<p>The distinction between Ext.Class and Ext.Base is important. Ext.Base is the top-level <i>superclass</i> for every class ever defined &#8211; every class inherits from Ext.Base at some point. Ext.Class represents the class itself &#8211; every class you define is an <i>instance</i> of Ext.Class, and a <i>subclass</i> of Ext.Base. To illustrate, let’s say we created a class called MyClass, which doesn’t extend any other class:</p>
<pre class="brush: jscript;">
Ext.define('MyClass', {
    someFunction: function() {
        console.log('Ran some function');
    }
});
</pre>
<p>The direct superclass for MyClass is Ext.Base because we didn’t specify that MyClass should extend anything else. If you imagine a tree of all the classes we’ve defined so far, it will look something like this:</p>
<p><img src="http://edspencer.net/wp-content/uploads/2011/01/Sample-inheritance-tree.png" alt="Sample-inheritance-tree" title="Sample-inheritance-tree" width="435" height="398" class="aligncenter size-full wp-image-522" /></p>
<p>This tree bases its hierarchy on the inheritance structure of our classes, and the root is always Ext.Base &#8211; that is, every class eventually inherits from Ext.Base. So every item in the diagram above is a <i>subclass</i> of Ext.Base, but every item is also an <i>instance</i> of Ext.Class. Classes themselves are instances of Ext.Class, which means we can easily modify the Class at a later time &#8211; for example mixing in additional functionality:</p>
<pre class="brush: jscript;">
//we can define some mixins at definition time
Ext.define('MyClass', {
    mixins: {
        observable: 'Ext.util.Observable'
    }
});

//it’s easy to add more later too
MyClass.mixin('draggable', 'Ext.util.Draggable');
</pre>
<p>This architecture opens up new possibilities for dynamic class creation and metaprogramming, which were difficult to pull off in earlier versions.</p>
<p>In the next episode, we’ll look at how the class definition pipeline is structured and how to extend it to add your own features.</p>
]]></description>
			<content:encoded><![CDATA[<p>Last week we unveiled a the brand new class system coming in Ext JS 4. If you haven’t seen the new system in action I hope you’ll take a look at the <a href="http://www.sencha.com/blog/2011/01/19/countdown-to-ext-js-4-dynamic-loading-and-new-class-system/">blog post</a> on sencha.com and check out the <a href="http://dev.sencha.com/deploy/LoaderDemo/">live demo</a>. Today we’re going to dig a little deeper into the class system to see how it actually works.</p>
<p>To briefly recap, the new class system enables us to define classes like this:</p>
<pre class="brush: jscript;">
Ext.define('Ext.Window', {
    extend: 'Ext.Panel',
    requires: 'Ext.Tool',
    mixins: {
        draggable: 'Ext.util.Draggable'
    },

    config: {
        title: &quot;Window Title&quot;
    }
});
</pre>
<p>Here we’ve set up a slightly simplified version of the Ext.Window class. We’ve set Window up to be a subclass of Panel, declared that it requires the Ext.Tool class and that it mixes in functionality from the Ext.util.Draggable class.</p>
<p>There are a few new things here so we’ll attack them one at a time. The ‘extend’ declaration does what you’d expect &#8211; we’re just saying that Window should be a subclass of Panel. The ‘requires’ declaration means that the named classes (just Ext.Tool in this case) have to be present before the Window class can be considered ‘ready’ for use (more on class readiness in a moment).</p>
<p>The ‘mixins’ declaration is a brand new concept when it comes to Ext JS. A mixin is just a set of functions (and sometimes properties) that are merged into a class. For example, the Ext.util.Draggable mixin we defined above might contain a function called ‘startDragging’ &#8211; this gets copied into Ext.Window to enable us to use the function in a window instance:</p>
<pre class="brush: jscript;">
//a simplified Draggable mixin
Ext.define('Ext.util.Draggable', {
    startDragging: function() {
        console.log('started dragging');
    }
});
</pre>
<p>When we create a new Ext.Window instance now, we can call the function that was mixed in from Ext.util.Draggable:</p>
<pre class="brush: jscript;">
var win = Ext.create('Ext.Window');
win.startDragging(); //&quot;started dragging&quot;
</pre>
<p>Mixins are really useful when a class needs to inherit multiple traits but can’t do so easily using a traditional single inheritance mechanism. For example, Ext.Windows is a draggable component, as are Sliders, Grid headers, and many other UI elements. Because this behavior crops up in many different places it’s not feasible to work the draggable behavior into a single superclass because not all of those UI elements actually share a common superclass. Creating a Draggable mixin solves this problem &#8211; now anything can be made draggable with a couple of lines of code.</p>
<p>The last new piece of functionality I’ll mention briefly is the ‘config’ declaration. Most of the classes in Ext JS take configuration parameters, many of which can be changed at runtime. In the Ext.Window above example we declared that the class has a ‘title’ configuration, which takes the default value of ‘Window Title’. By setting the class up like this we get 4 methods for free &#8211; getTitle, setTitle, resetTitle and applyTitle.</p>
<ul>
<li><b>getTitle</b> &#8211; returns the current title</li>
<li><b>setTitle</b> &#8211; sets the title to a new value</li>
<li><b>resetTitle</b> &#8211;  reverts the title to its default value (‘Window Title’)</li>
<li><b>applyTitle</b> &#8211; this is a template method that you can choose to define. It is called whenever setTitle is called.
</ul>
<p>The applyTitle function is the place to put any logic that needs to be called when the title is changed &#8211; for example we might want to update a DOM Element with the new title:</p>
<pre class="brush: jscript;">
Ext.define(‘Ext.Window’, {
    //..as above,

    config: {
        title: 'Window Title'
    },

    //updates the DOM element that contains the window title
    applyTitle: function(newTitle) {
        this.titleEl.update(newTitle);
    }
});
</pre>
<p>This saves us a lot of time and code while providing a consistent API for all configuration options: win-win.</p>
<h3>Digging Deeper</h3>
<p>Ext JS 4 introduces 4 new classes to make all this magic work:</p>
<ul>
<li><b>Ext.Base</b> &#8211; all classes inherit from Ext.Base. It provides basic low-level functionality used by all classes</li>
<li><b>Ext.Class</b> &#8211; a factory for making new classes</li>
<li><b>Ext.ClassLoader</b> &#8211; responsible for ensuring that classes are available, loading them if they aren’t on the page already</li>
<li><b>Ext.ClassManager</b> &#8211; kicks off class creation and manages dependencies</li>
</ul>
<p>These all work together behind the scenes and most of the time you won’t even need to be aware of what is being called when you define and use a class. The two functions that you’ll use most often &#8211; Ext.define and Ext.create &#8211; both call Ext.ClassManager under the hood, which in turn utilizes the other three classes to put everything together.</p>
<p>The distinction between Ext.Class and Ext.Base is important. Ext.Base is the top-level <i>superclass</i> for every class ever defined &#8211; every class inherits from Ext.Base at some point. Ext.Class represents the class itself &#8211; every class you define is an <i>instance</i> of Ext.Class, and a <i>subclass</i> of Ext.Base. To illustrate, let’s say we created a class called MyClass, which doesn’t extend any other class:</p>
<pre class="brush: jscript;">
Ext.define('MyClass', {
    someFunction: function() {
        console.log('Ran some function');
    }
});
</pre>
<p>The direct superclass for MyClass is Ext.Base because we didn’t specify that MyClass should extend anything else. If you imagine a tree of all the classes we’ve defined so far, it will look something like this:</p>
<p><img src="http://edspencer.net/wp-content/uploads/2011/01/Sample-inheritance-tree.png" alt="Sample-inheritance-tree" title="Sample-inheritance-tree" width="435" height="398" class="aligncenter size-full wp-image-522" /></p>
<p>This tree bases its hierarchy on the inheritance structure of our classes, and the root is always Ext.Base &#8211; that is, every class eventually inherits from Ext.Base. So every item in the diagram above is a <i>subclass</i> of Ext.Base, but every item is also an <i>instance</i> of Ext.Class. Classes themselves are instances of Ext.Class, which means we can easily modify the Class at a later time &#8211; for example mixing in additional functionality:</p>
<pre class="brush: jscript;">
//we can define some mixins at definition time
Ext.define('MyClass', {
    mixins: {
        observable: 'Ext.util.Observable'
    }
});

//it’s easy to add more later too
MyClass.mixin('draggable', 'Ext.util.Draggable');
</pre>
<p>This architecture opens up new possibilities for dynamic class creation and metaprogramming, which were difficult to pull off in earlier versions.</p>
<p>In the next episode, we’ll look at how the class definition pipeline is structured and how to extend it to add your own features.</p>
]]></content:encoded>
			<wfw:commentRss>http://edspencer.net/2011/01/classes-in-ext-js-4-under-the-hood.html/feed</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Writing Compressible JavaScript</title>
		<link>http://edspencer.net/2010/06/writing-compressible-javascript.html</link>
		<comments>http://edspencer.net/2010/06/writing-compressible-javascript.html#comments</comments>
		<pubDate>Sat, 19 Jun 2010 22:02:38 +0000</pubDate>
		<dc:creator>Ed Spencer</dc:creator>
				<category><![CDATA[Misc]]></category>

		<guid isPermaLink="false">http://edspencer.net/?p=435</guid>
		<description><![CDATA[<p>Writing a library is a balancing act between the (sometimes competing) interests of API clarity, code clarity, performance and compressibility. In this article I&#8217;m going to detail three of the approaches we take to meet this balance and suggest them for your own usage.</p>
<h3>1. Collecting var statements</h3>
<p>Every time we declare variables we add 4 bytes to the compressed file size. Variables are declared sufficiently often that this can really add up, so instead of this:</p>
<pre class="brush: jscript;">
var myFirstVar = 'something';
var myOtherVar = 'another thing';
var answer = 42;
var adama = true;
</pre>
<p>One should use this form:</p>
<pre class="brush: jscript;">
var myFirstVar = 'something',
    myOtherVar = 'another thing',
    answer = 42,
    adama = true;
</pre>
<p>When this code is compressed, each variable name above is turned into a single-letter name, meaning that the wasted 4 bytes per useless additional &#8216;var &#8216; in the first example would have contributed significantly to code size with no benefit.</p>
<h3>2. Local variable pointers to object properties</h3>
<p>The following code (pruned from a previous version of Ext JS) is not as compressible as it could be:</p>
<pre class="brush: jscript;">
var cs = {};
for (var n in this.modified) {
    if (this.modified.hasOwnProperty(n)) {
        cs[n] = this.data[n];
    }
}
return cs;
</pre>
<p>We&#8217;re better off aliasing &#8216;this.modified&#8217; to a local variable first. Aside from the performance benefits some JS engines derive from not having to perform object property lookups over and over again, we save precious bytes this way too:</p>
<pre class="brush: jscript;">
var modified = this.modified,
    changes  = {},
    field; 

for (field in modified) {
    if (modified.hasOwnProperty(field)) {
        changes[field] = this.data[field];
    }
}

return changes;
</pre>
<p>Again, the minifier will compress those variable names down to a single character each, so for our &#8216;this.modified&#8217; example we&#8217;re going to use 15 bytes to define the variable plus 1 byte each time we use it (totalling 15), vs the 26 bytes for that code previously. This approach scales especially well &#8211; were we to refer to this.modified a third time in the function, as our code will now minify to 16 bytes, vs 39 without the variable declaration.</p>
<p>Side note: in the first example here the variable &#8216;n&#8217; was being used in the for&#8230;in loop. We can always safely exchange that for a meaningful variable name (in this case &#8216;field&#8217;) and leave the rest to the minifier.</p>
<h3>3. Aliasing &#8216;this&#8217; to &#8216;me&#8217;</h3>
<p>In Ext.data.Record&#8217;s markDirty method we have the following code:</p>
<pre class="brush: jscript;">
this.dirty = true;
if(!this.modified){
    this.modified = {};
}
this.fields.each(function(f) {
    this.modified[f.name] = this.data[f.name];
},this);
</pre>
<p>There are 7 references to &#8216;this&#8217; in that method, taking 28 bytes and completely incompressible. We could rewrite it like this (note that the final &#8216;this&#8217; can be removed in this format):</p>
<pre class="brush: jscript;">
var me = this; 

me.dirty = true;
if (!me.modified) {
    me.modified = {};
}
me.fields.each(function(f) {
    me.modified[f.name] = me.data[f.name];
});
</pre>
<p>Again, our minifier will change the &#8216;me&#8217; var to a single character, saving us 8 bytes in this instance. That might not sound like a lot but after minification it equates to a 7% reduction in code size for this function.</p>
<p>In each of the cases above we&#8217;re generally talking about single-digit percentage savings after minification. There is value in that small slice though, especially as more and more applications shift onto bandwidth-constrained mobile platforms.</p>
<p>The first two approaches are no-brainers and must always be done but the third is slightly more controversial. Personally I find it makes the code a little harder to read, largely because my syntax highlighter doesn&#8217;t recognise that &#8216;me&#8217; is now the same as &#8216;this&#8217;. Its value also varies significantly by function &#8211; some functions can contain over a dozen references to &#8216;this&#8217;, in which case this approach makes a big difference.</p>
]]></description>
			<content:encoded><![CDATA[<p>Writing a library is a balancing act between the (sometimes competing) interests of API clarity, code clarity, performance and compressibility. In this article I&#8217;m going to detail three of the approaches we take to meet this balance and suggest them for your own usage.</p>
<h3>1. Collecting var statements</h3>
<p>Every time we declare variables we add 4 bytes to the compressed file size. Variables are declared sufficiently often that this can really add up, so instead of this:</p>
<pre class="brush: jscript;">
var myFirstVar = 'something';
var myOtherVar = 'another thing';
var answer = 42;
var adama = true;
</pre>
<p>One should use this form:</p>
<pre class="brush: jscript;">
var myFirstVar = 'something',
    myOtherVar = 'another thing',
    answer = 42,
    adama = true;
</pre>
<p>When this code is compressed, each variable name above is turned into a single-letter name, meaning that the wasted 4 bytes per useless additional &#8216;var &#8216; in the first example would have contributed significantly to code size with no benefit.</p>
<h3>2. Local variable pointers to object properties</h3>
<p>The following code (pruned from a previous version of Ext JS) is not as compressible as it could be:</p>
<pre class="brush: jscript;">
var cs = {};
for (var n in this.modified) {
    if (this.modified.hasOwnProperty(n)) {
        cs[n] = this.data[n];
    }
}
return cs;
</pre>
<p>We&#8217;re better off aliasing &#8216;this.modified&#8217; to a local variable first. Aside from the performance benefits some JS engines derive from not having to perform object property lookups over and over again, we save precious bytes this way too:</p>
<pre class="brush: jscript;">
var modified = this.modified,
    changes  = {},
    field; 

for (field in modified) {
    if (modified.hasOwnProperty(field)) {
        changes[field] = this.data[field];
    }
}

return changes;
</pre>
<p>Again, the minifier will compress those variable names down to a single character each, so for our &#8216;this.modified&#8217; example we&#8217;re going to use 15 bytes to define the variable plus 1 byte each time we use it (totalling 15), vs the 26 bytes for that code previously. This approach scales especially well &#8211; were we to refer to this.modified a third time in the function, as our code will now minify to 16 bytes, vs 39 without the variable declaration.</p>
<p>Side note: in the first example here the variable &#8216;n&#8217; was being used in the for&#8230;in loop. We can always safely exchange that for a meaningful variable name (in this case &#8216;field&#8217;) and leave the rest to the minifier.</p>
<h3>3. Aliasing &#8216;this&#8217; to &#8216;me&#8217;</h3>
<p>In Ext.data.Record&#8217;s markDirty method we have the following code:</p>
<pre class="brush: jscript;">
this.dirty = true;
if(!this.modified){
    this.modified = {};
}
this.fields.each(function(f) {
    this.modified[f.name] = this.data[f.name];
},this);
</pre>
<p>There are 7 references to &#8216;this&#8217; in that method, taking 28 bytes and completely incompressible. We could rewrite it like this (note that the final &#8216;this&#8217; can be removed in this format):</p>
<pre class="brush: jscript;">
var me = this; 

me.dirty = true;
if (!me.modified) {
    me.modified = {};
}
me.fields.each(function(f) {
    me.modified[f.name] = me.data[f.name];
});
</pre>
<p>Again, our minifier will change the &#8216;me&#8217; var to a single character, saving us 8 bytes in this instance. That might not sound like a lot but after minification it equates to a 7% reduction in code size for this function.</p>
<p>In each of the cases above we&#8217;re generally talking about single-digit percentage savings after minification. There is value in that small slice though, especially as more and more applications shift onto bandwidth-constrained mobile platforms.</p>
<p>The first two approaches are no-brainers and must always be done but the third is slightly more controversial. Personally I find it makes the code a little harder to read, largely because my syntax highlighter doesn&#8217;t recognise that &#8216;me&#8217; is now the same as &#8216;this&#8217;. Its value also varies significantly by function &#8211; some functions can contain over a dozen references to &#8216;this&#8217;, in which case this approach makes a big difference.</p>
]]></content:encoded>
			<wfw:commentRss>http://edspencer.net/2010/06/writing-compressible-javascript.html/feed</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Answering Nicholas Zakas&#8217; JavaScript quiz</title>
		<link>http://edspencer.net/2010/02/answering-nicholas-zakas-javascript-quiz.html</link>
		<comments>http://edspencer.net/2010/02/answering-nicholas-zakas-javascript-quiz.html#comments</comments>
		<pubDate>Tue, 16 Feb 2010 20:41:17 +0000</pubDate>
		<dc:creator>Ed Spencer</dc:creator>
				<category><![CDATA[Misc]]></category>

		<guid isPermaLink="false">http://edspencer.net/?p=408</guid>
		<description><![CDATA[<p>A current meme that&#8217;s floating around the JavaScript geek corner of the internet is setting quizzes on some of the more unusual aspects of JavaScript. This time round <a href="http://www.nczonline.net/blog/2010/02/16/my-javascript-quiz/">Nicholas Zakas is providing the entertainment</a>, so I thought I&#8217;d provide some answers. Let&#8217;s get started:</p>
<h2>Question 1</h2>
<p>Question 1 looks like this:</p>
<pre class="brush: jscript;">
var num1 = 5,
    num2 = 10,
    result = num1+++num2;
</pre>
<p>We&#8217;re asked what the values of result, num2 and num1 are. First, let&#8217;s deconstruct what that +++ is doing. There is no +++ operator in JavaScript &#8211; instead we have a num1++ followed by a + num2.</p>
<p>JavaScript has two ways of incrementing a number by 1 &#8211; we can either put the ++ before the variable or after it. The variable is incremented either way &#8211; the only difference is what is returned. ++10 returns 11, whereas 10++ returns 10:</p>
<pre class="brush: jscript;">
var a = 10;

var b = a++; //a is set to 11 now, but b is set to 10
var c = ++a; //a is set to 12 now, c is also set to 12
</pre>
<p>So &#8216;result&#8217; is the sum of num1++ (which is 5) and num2, which is 10, so result equals 15. num2 remains at 10 as it was not modified. num1 is now equal to 6 because we incremented it by 1, though the incrementation did not affect the sum passed to result.</p>
<h2>Question 2</h2>
<pre class="brush: jscript;">
var x = 5,
    o = {
        x: 10,
        doIt: function doIt(){
            var x = 20;
            setTimeout(function(){
                alert(this.x);
            }, 10);
        }
    };
o.doIt();
</pre>
<p>We&#8217;re asked what is alerted. This is mostly smoke and mirrors &#8211; there&#8217;s some indirection with all the duplicate names but the important thing here is the setTimeout. The function we pass to setTimeout gets run in the global scope, meaning &#8216;this&#8217; refers to the window object. Declaring x as a variable in the global scope (var x = 5) is the same as setting window.x = 5, so 5 is alerted.</p>
<h2>Question 3</h2>
<pre class="brush: jscript;">
var num1 = &quot;10&quot;,
    num2 = &quot;9&quot;;
</pre>
<p>We&#8217;re asked:</p>
<ul>
<li>What is the value of num1 < num2?</li>
<li>What is the value of +num1 < num2?</li>
<li>What is the value of num1 + num2?</li>
<li>What is the value of +num1 + num2?</li>
</ul>
<p>This question is all about type casting.</p>
<ul>
<li>num1 < num2 is true - if both operands are strings JavaScript will compare them alphabetically, and "10" is lower alphabetically than "9"</li>
<li>+num1 < num2 is false - placing a "+" operator before a string casts it into a number, so we're actually testing 10 < "9". When testing a mixture of numbers and strings like this, everything is cast into a number, so we're testing 10 < 9, which is false</li>
<li>num1 + num2 === &#8220;109&#8243; &#8211; the plus sign can mean both addition and concatenation, depending on the operand types. Here we have 2 strings so we&#8217;re concatenating them together</li>
<li>+num1 + num2 === &#8220;109&#8243; also &#8211; again we&#8217;re casting num1 into a number, but the + operator means concatenation if at least one operand is a string</li>
</ul>
<p>The confusion around this comes largely from the fact that the plus sign is used for both addition and concatenation in JavaScript. This causes the engine to have to test the typeof each operand and cast accordingly. All of the other math operators (e.g. /, *, % etc) cast both operands to numbers.</p>
<h2>Question 4</h2>
<pre class="brush: jscript;">
var message = &quot;Hello world!&quot;;
</pre>
<p>We&#8217;re asked:</p>
<ul>
<li>What is the value of message.substring(1, 4)?</li>
<li>What is the value of message.substr(1,4)?</li>
<ul>
</p>
<p>substring and substr do similar things. The first argument to each is the character index to start from, but whereas substring&#8217;s second argument is the character index to end at, substr&#8217;s second argument is the number of characters to return.  Therefore message.substr(1, 4) will return a string of length 4, whereas message.substring(1, 4) will return a string of length 3 (4 &#8211; 1):</p>
<ul>
<li>message.substring(1, 4); //&#8221;ell&#8221;</li>
<li>message.substr(1, 4); //&#8221;ello&#8221;</li>
</ul>
<p></p>
<h2>Question 5</h2>
<pre class="brush: jscript;">
var o = {
        x: 8,

        valueOf: function(){
            return this.x + 2;
        },
        toString: function(){
            return this.x.toString();
        }
    },
    result = o &lt; &quot;9&quot;;
alert(o);
</pre>
<p>We&#8217;re asked the value of &#8216;result&#8217;, and what gets alerted. This requires an understanding of the special valueOf and toString functions available on every object. These functions are used internally by the JavaScript engine to pull out the best representation of an object&#8217;s value based on the situation.</p>
<p>When alerting a value, we want a string representation so toString is called. When comparing the value to another object, valueOf is called instead. So alert(o) alerts &#8220;8&#8243;, and result is set equal to the result of 10 < "9". The JavaScript engine will decide when to use which option, or we can specify it ourselves:</p>
<pre class="brush: jscript;">
var num1 = 8, num2 = 9;

num1 + num2; //17
num1.toString() + num2.toString(); //&quot;89&quot;
num1.valueOf() + num2.valueOf(); //17
</pre>
<p>The 'result' assignment needs a little explanation. First, the engine calls valueOf on the object, which returns 10. Second, because one of the operands to the < operator is a number, the other is also cast into a number, so we are testing 10 < 9, which returns false. We could instead force it to use toString: o.toString() < "9" returns true.</p>
<p>Quizzes like this are great for getting your teeth into some of the guts of JavaScript, but don't mistake them for a good way to write code. The point is to demonstrate how quirky JS code can be unless you write it in a sensible way. </p>
]]></description>
			<content:encoded><![CDATA[<p>A current meme that&#8217;s floating around the JavaScript geek corner of the internet is setting quizzes on some of the more unusual aspects of JavaScript. This time round <a href="http://www.nczonline.net/blog/2010/02/16/my-javascript-quiz/">Nicholas Zakas is providing the entertainment</a>, so I thought I&#8217;d provide some answers. Let&#8217;s get started:</p>
<h2>Question 1</h2>
<p>Question 1 looks like this:</p>
<pre class="brush: jscript;">
var num1 = 5,
    num2 = 10,
    result = num1+++num2;
</pre>
<p>We&#8217;re asked what the values of result, num2 and num1 are. First, let&#8217;s deconstruct what that +++ is doing. There is no +++ operator in JavaScript &#8211; instead we have a num1++ followed by a + num2.</p>
<p>JavaScript has two ways of incrementing a number by 1 &#8211; we can either put the ++ before the variable or after it. The variable is incremented either way &#8211; the only difference is what is returned. ++10 returns 11, whereas 10++ returns 10:</p>
<pre class="brush: jscript;">
var a = 10;

var b = a++; //a is set to 11 now, but b is set to 10
var c = ++a; //a is set to 12 now, c is also set to 12
</pre>
<p>So &#8216;result&#8217; is the sum of num1++ (which is 5) and num2, which is 10, so result equals 15. num2 remains at 10 as it was not modified. num1 is now equal to 6 because we incremented it by 1, though the incrementation did not affect the sum passed to result.</p>
<h2>Question 2</h2>
<pre class="brush: jscript;">
var x = 5,
    o = {
        x: 10,
        doIt: function doIt(){
            var x = 20;
            setTimeout(function(){
                alert(this.x);
            }, 10);
        }
    };
o.doIt();
</pre>
<p>We&#8217;re asked what is alerted. This is mostly smoke and mirrors &#8211; there&#8217;s some indirection with all the duplicate names but the important thing here is the setTimeout. The function we pass to setTimeout gets run in the global scope, meaning &#8216;this&#8217; refers to the window object. Declaring x as a variable in the global scope (var x = 5) is the same as setting window.x = 5, so 5 is alerted.</p>
<h2>Question 3</h2>
<pre class="brush: jscript;">
var num1 = &quot;10&quot;,
    num2 = &quot;9&quot;;
</pre>
<p>We&#8217;re asked:</p>
<ul>
<li>What is the value of num1 < num2?</li>
<li>What is the value of +num1 < num2?</li>
<li>What is the value of num1 + num2?</li>
<li>What is the value of +num1 + num2?</li>
</ul>
<p>This question is all about type casting.</p>
<ul>
<li>num1 < num2 is true - if both operands are strings JavaScript will compare them alphabetically, and "10" is lower alphabetically than "9"</li>
<li>+num1 < num2 is false - placing a "+" operator before a string casts it into a number, so we're actually testing 10 < "9". When testing a mixture of numbers and strings like this, everything is cast into a number, so we're testing 10 < 9, which is false</li>
<li>num1 + num2 === &#8220;109&#8243; &#8211; the plus sign can mean both addition and concatenation, depending on the operand types. Here we have 2 strings so we&#8217;re concatenating them together</li>
<li>+num1 + num2 === &#8220;109&#8243; also &#8211; again we&#8217;re casting num1 into a number, but the + operator means concatenation if at least one operand is a string</li>
</ul>
<p>The confusion around this comes largely from the fact that the plus sign is used for both addition and concatenation in JavaScript. This causes the engine to have to test the typeof each operand and cast accordingly. All of the other math operators (e.g. /, *, % etc) cast both operands to numbers.</p>
<h2>Question 4</h2>
<pre class="brush: jscript;">
var message = &quot;Hello world!&quot;;
</pre>
<p>We&#8217;re asked:</p>
<ul>
<li>What is the value of message.substring(1, 4)?</li>
<li>What is the value of message.substr(1,4)?</li>
<ul>
</p>
<p>substring and substr do similar things. The first argument to each is the character index to start from, but whereas substring&#8217;s second argument is the character index to end at, substr&#8217;s second argument is the number of characters to return.  Therefore message.substr(1, 4) will return a string of length 4, whereas message.substring(1, 4) will return a string of length 3 (4 &#8211; 1):</p>
<ul>
<li>message.substring(1, 4); //&#8221;ell&#8221;</li>
<li>message.substr(1, 4); //&#8221;ello&#8221;</li>
</ul>
<p></p>
<h2>Question 5</h2>
<pre class="brush: jscript;">
var o = {
        x: 8,

        valueOf: function(){
            return this.x + 2;
        },
        toString: function(){
            return this.x.toString();
        }
    },
    result = o &lt; &quot;9&quot;;
alert(o);
</pre>
<p>We&#8217;re asked the value of &#8216;result&#8217;, and what gets alerted. This requires an understanding of the special valueOf and toString functions available on every object. These functions are used internally by the JavaScript engine to pull out the best representation of an object&#8217;s value based on the situation.</p>
<p>When alerting a value, we want a string representation so toString is called. When comparing the value to another object, valueOf is called instead. So alert(o) alerts &#8220;8&#8243;, and result is set equal to the result of 10 < "9". The JavaScript engine will decide when to use which option, or we can specify it ourselves:</p>
<pre class="brush: jscript;">
var num1 = 8, num2 = 9;

num1 + num2; //17
num1.toString() + num2.toString(); //&quot;89&quot;
num1.valueOf() + num2.valueOf(); //17
</pre>
<p>The 'result' assignment needs a little explanation. First, the engine calls valueOf on the object, which returns 10. Second, because one of the operands to the < operator is a number, the other is also cast into a number, so we are testing 10 < 9, which returns false. We could instead force it to use toString: o.toString() < "9" returns true.</p>
<p>Quizzes like this are great for getting your teeth into some of the guts of JavaScript, but don't mistake them for a good way to write code. The point is to demonstrate how quirky JS code can be unless you write it in a sensible way. </p>
]]></content:encoded>
			<wfw:commentRss>http://edspencer.net/2010/02/answering-nicholas-zakas-javascript-quiz.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ext JS is looking for a QA rockstar</title>
		<link>http://edspencer.net/2010/01/ext-js-is-looking-for-a-qa-rockstar.html</link>
		<comments>http://edspencer.net/2010/01/ext-js-is-looking-for-a-qa-rockstar.html#comments</comments>
		<pubDate>Tue, 19 Jan 2010 08:05:18 +0000</pubDate>
		<dc:creator>Ed Spencer</dc:creator>
				<category><![CDATA[Misc]]></category>

		<guid isPermaLink="false">http://edspencer.net/?p=387</guid>
		<description><![CDATA[<p>This has been <a href="http://www.extjs.com/forum/showthread.php?t=90018">cross-posted from our Open Discussion Forum</a>.</p>
<p>As part of our ambition of creating the world&#8217;s best JavaScript framework, we&#8217;re looking to hire a special somebody to help maintain the high quality of our components.</p>
<p>While we have one eye on implementing new features and improving Ext JS&#8217;s performance, the other is on making sure what we already have still works well.</p>
<p>This is a difficult job and we need someone smart, focused and well versed in Ext JS.  Somebody who will:</p>
<p>* Use our existing systems to test components as new builds of the library are landed<br />
* Maintain a strong presence in the forums and be the first to know of any reported issues<br />
* Respond to bug tickets such as rendering issues and broken functionality<br />
* Totally own the Quality Assurance of Ext JS &#8211; we want your ideas and your initiative as well as your expertise with Ext<br />
* Liaise with the core team on a daily basis</p>
<p>This is a full-time position, though allowances can be made for the right person.  If you think you would enjoy working with Ext JS, and have what it takes to help us keep Ext at the forefront of our field, <a href="http://www.extjs.com/forum/private.php?do=newpm&#038;u=59955">drop me a private message</a> with the following information:</p>
<p>* Your name<br />
* Email address<br />
* Location (city, country, timezone)<br />
* All experience with Ext JS<br />
* Bonus points for links to open source software</p>
]]></description>
			<content:encoded><![CDATA[<p>This has been <a href="http://www.extjs.com/forum/showthread.php?t=90018">cross-posted from our Open Discussion Forum</a>.</p>
<p>As part of our ambition of creating the world&#8217;s best JavaScript framework, we&#8217;re looking to hire a special somebody to help maintain the high quality of our components.</p>
<p>While we have one eye on implementing new features and improving Ext JS&#8217;s performance, the other is on making sure what we already have still works well.</p>
<p>This is a difficult job and we need someone smart, focused and well versed in Ext JS.  Somebody who will:</p>
<p>* Use our existing systems to test components as new builds of the library are landed<br />
* Maintain a strong presence in the forums and be the first to know of any reported issues<br />
* Respond to bug tickets such as rendering issues and broken functionality<br />
* Totally own the Quality Assurance of Ext JS &#8211; we want your ideas and your initiative as well as your expertise with Ext<br />
* Liaise with the core team on a daily basis</p>
<p>This is a full-time position, though allowances can be made for the right person.  If you think you would enjoy working with Ext JS, and have what it takes to help us keep Ext at the forefront of our field, <a href="http://www.extjs.com/forum/private.php?do=newpm&#038;u=59955">drop me a private message</a> with the following information:</p>
<p>* Your name<br />
* Email address<br />
* Location (city, country, timezone)<br />
* All experience with Ext JS<br />
* Bonus points for links to open source software</p>
]]></content:encoded>
			<wfw:commentRss>http://edspencer.net/2010/01/ext-js-is-looking-for-a-qa-rockstar.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript FizzBuzz in a tweet</title>
		<link>http://edspencer.net/2009/09/javascript-fizzbuzz-in-a-tweet.html</link>
		<comments>http://edspencer.net/2009/09/javascript-fizzbuzz-in-a-tweet.html#comments</comments>
		<pubDate>Thu, 17 Sep 2009 14:15:54 +0000</pubDate>
		<dc:creator>Ed Spencer</dc:creator>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[fizzbuzz]]></category>
		<category><![CDATA[geekery]]></category>
		<category><![CDATA[why]]></category>

		<guid isPermaLink="false">http://edspencer.net/?p=188</guid>
		<description><![CDATA[<p>The <a href="http://imranontech.com/2007/01/24/using-fizzbuzz-to-find-developers-who-grok-coding/">FizzBuzz</a> challenge has been around a while but I stumbled across it again after reading <a href="http://gilesbowkett.blogspot.com/2009/09/rails-code-quality-checklist-here.html">another unique Giles Bowkett post</a>.</p>
<p>If you&#8217;re not familiar with FizzBuzz, it&#8217;s a little &#8216;challenge&#8217; designed to test a candidate programmer&#8217;s ability to perform a simple task.  In this case, you just have to print out the numbers from 1 to 100, unless the number is a multiple of 3, when you should instead print &#8220;Fizz&#8221;, 5 in which case you print &#8220;Buzz&#8221;, or both 3 and 5 in which case you print &#8220;FizzBuzz&#8221;.</p>
<p>Here&#8217;s a trivial JavaScript implementation:</p>
<pre class="brush: jscript;">
for (var i=1; i &lt;= 100; i++) {
  if (i % 3 == 0) {
    if (i % 5 == 0) {
      console.log('FizzBuzz');
    } else {
     console.log('Fizz');
   }
  } else if (i % 5 == 0) {
    console.log('Buzz');
  } else {
    console.log(i);
  }
};
</pre>
<p>Pretty simple stuff, but a bit verbose.  I wanted something that would fit into a tweet. It turns out that&#8217;s pretty simple &#8211; this is 133 characters including whitespace, 7 within tolerance for a twitter message:</p>
<pre class="brush: jscript;">
for (var i = 1; i &lt;= 100; i++) {
  var f = i % 3 == 0, b = i % 5 == 0;
  console.log(f ? b ? &quot;FizzBuzz&quot; : &quot;Fizz&quot; : b ? &quot;Buzz&quot; : i);
}
</pre>
<p>Which of course begs the question &#8211; just how short can a JavaScript FizzBuzz implementation be? Here&#8217;s my baseline, which is a tortured and contorted version of the above:</p>
<pre class="brush: jscript;">
for(i=1;i&lt;101;i++){console.log(i%3?i%5?i:&quot;Buzz&quot;:i%5?&quot;Fizz&quot;:&quot;FizzBuzz&quot;)}
</pre>
<p>The above is 71 characters &#8211; I expect you to do better.  The rules are that the only dependency is Firebug&#8217;s console.log being available, and you can&#8217;t replace &#8216;console.log&#8217; for anything else.</p>
<p>Of course, if we did swap &#8216;console.log&#8217; for &#8216;alert&#8217;, the whole thing would fit in a tweet twice, but that would be damn annoying.</p>
<p><strong>Hint:</strong> you can take at least three more characters off the above &#8211; can you see how?</p>
]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://imranontech.com/2007/01/24/using-fizzbuzz-to-find-developers-who-grok-coding/">FizzBuzz</a> challenge has been around a while but I stumbled across it again after reading <a href="http://gilesbowkett.blogspot.com/2009/09/rails-code-quality-checklist-here.html">another unique Giles Bowkett post</a>.</p>
<p>If you&#8217;re not familiar with FizzBuzz, it&#8217;s a little &#8216;challenge&#8217; designed to test a candidate programmer&#8217;s ability to perform a simple task.  In this case, you just have to print out the numbers from 1 to 100, unless the number is a multiple of 3, when you should instead print &#8220;Fizz&#8221;, 5 in which case you print &#8220;Buzz&#8221;, or both 3 and 5 in which case you print &#8220;FizzBuzz&#8221;.</p>
<p>Here&#8217;s a trivial JavaScript implementation:</p>
<pre class="brush: jscript;">
for (var i=1; i &lt;= 100; i++) {
  if (i % 3 == 0) {
    if (i % 5 == 0) {
      console.log('FizzBuzz');
    } else {
     console.log('Fizz');
   }
  } else if (i % 5 == 0) {
    console.log('Buzz');
  } else {
    console.log(i);
  }
};
</pre>
<p>Pretty simple stuff, but a bit verbose.  I wanted something that would fit into a tweet. It turns out that&#8217;s pretty simple &#8211; this is 133 characters including whitespace, 7 within tolerance for a twitter message:</p>
<pre class="brush: jscript;">
for (var i = 1; i &lt;= 100; i++) {
  var f = i % 3 == 0, b = i % 5 == 0;
  console.log(f ? b ? &quot;FizzBuzz&quot; : &quot;Fizz&quot; : b ? &quot;Buzz&quot; : i);
}
</pre>
<p>Which of course begs the question &#8211; just how short can a JavaScript FizzBuzz implementation be? Here&#8217;s my baseline, which is a tortured and contorted version of the above:</p>
<pre class="brush: jscript;">
for(i=1;i&lt;101;i++){console.log(i%3?i%5?i:&quot;Buzz&quot;:i%5?&quot;Fizz&quot;:&quot;FizzBuzz&quot;)}
</pre>
<p>The above is 71 characters &#8211; I expect you to do better.  The rules are that the only dependency is Firebug&#8217;s console.log being available, and you can&#8217;t replace &#8216;console.log&#8217; for anything else.</p>
<p>Of course, if we did swap &#8216;console.log&#8217; for &#8216;alert&#8217;, the whole thing would fit in a tweet twice, but that would be damn annoying.</p>
<p><strong>Hint:</strong> you can take at least three more characters off the above &#8211; can you see how?</p>
]]></content:encoded>
			<wfw:commentRss>http://edspencer.net/2009/09/javascript-fizzbuzz-in-a-tweet.html/feed</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Using the ExtJS Row Editor</title>
		<link>http://edspencer.net/2009/09/using-the-extjs-row-editor.html</link>
		<comments>http://edspencer.net/2009/09/using-the-extjs-row-editor.html#comments</comments>
		<pubDate>Wed, 16 Sep 2009 14:25:47 +0000</pubDate>
		<dc:creator>Ed Spencer</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[Misc]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[grid]]></category>
		<category><![CDATA[roweditor]]></category>

		<guid isPermaLink="false">http://192.168.2.15/Projects/wordpress/?p=41</guid>
		<description><![CDATA[<p>The <a href="http://www.extjs.com/deploy/dev/examples/grid/row-editor.html">RowEditor plugin</a> was recently added to the <a href="http://www.extjs.com/deploy/dev/examples/">ExtJS examples page</a>.  It works a lot like a normal Grid Editor, except you can edit several fields on a given row at once before saving.</p>
<p>This neatly solves the problem of adding a new row to an editor grid, entering data into the first field and finding it save itself straight away, which is rarely desired.  In this fashion we can provide full CRUD for simple models in a single page.</p>
<h2>Installation</h2>
<p>You&#8217;ll need to get a copy of the javascript, css and images from the server.  This is a bit of a pain.  If you still have the <a href="http://www.extjs.com/products/extjs/download.php">ExtJS SDK</a> around you can find these in the examples folder, if not you can get each file as follows:</p>
<p>Grab the plugin JS file below and put it where you usually put your .js files:<br />
<a href="http://www.extjs.com/deploy/dev/examples/ux/RowEditor.js">http://www.extjs.com/deploy/dev/examples/ux/RowEditor.js</a></p>
<p>This needs to go with your other stylesheets, usually in a directory called &#8216;css&#8217;:<br />
<a href="http://www.extjs.com/deploy/dev/examples/ux/css/RowEditor.css">http://www.extjs.com/deploy/dev/examples/ux/css/RowEditor.css</a></p>
<p>Download these two images and put them into your existing &#8216;images&#8217; folder (the same place the other ExtJS images live):<br />
<a href="http://www.extjs.com/deploy/dev/examples/ux/images/row-editor-bg.gif">http://www.extjs.com/deploy/dev/examples/ux/images/row-editor-bg.gif</a><br />
<a href="http://www.extjs.com/deploy/dev/examples/ux/images/row-editor-btns.gif">http://www.extjs.com/deploy/dev/examples/ux/images/row-editor-btns.gif</a></p>
<p>Include the .js and .css files on your page and you should be ready to go.</p>
<h2>Usage</h2>
<p>RowEditor is a normal grid plugin, so you&#8217;ll need to instantiate it and add to your grid&#8217;s &#8216;plugins&#8217; property.  You also need to define what type of Editor is available (if any) on each column:</p>
<pre class="brush: jscript;">
var editor = new Ext.ux.grid.RowEditor();

var grid = new Ext.grid.GridPanel({
  plugins: [editor],
  columns: [
    {
      header   : 'User Name',
      dataIndex: 'name',
      editor   : new Ext.form.TextField()
    },
    {
      header   : 'Email',
      dataIndex: 'email',
      editor   : new Ext.form.TextField()
    }
  ]
  ... the rest of your grid config here
});
</pre>
<p>RowEditor defines a few events, the most useful one being &#8216;afteredit&#8217;. Its signature looks like this:</p>
<pre class="brush: jscript;">
/**
 * @event afteredit
 * Fired after a row is edited and passes validation.  This event is fired
 * after the store's update event is fired with this edit.
 * @param {Ext.ux.grid.RowEditor} roweditor This object
 * @param {Object} changes Object with changes made to the record.
 * @param {Ext.data.Record} r The Record that was edited.
 * @param {Number} rowIndex The rowIndex of the row just edited
 */
'afteredit'
</pre>
<p>All you need to do is listen to that event on your RowEditor and save your model object appropriately.  First though, we&#8217;ll define the Ext.data.Record that we&#8217;re using in this grid&#8217;s store:</p>
<pre class="brush: jscript;">
var User = Ext.data.Record.create([
  {name: 'user_id', type: 'int'},
  {name: 'name',    type: 'string'},
  {name: 'email',   type: 'string'}
]);
</pre>
<p>And now the afteredit listener itself</p>
<pre class="brush: jscript;">
editor.on({
  scope: this,
  afteredit: function(roweditor, changes, record, rowIndex) {
    //your save logic here - might look something like this:
    Ext.Ajax.request({
      url   : record.phantom ? '/users' : '/users/' + record.get('user_id'),
      method: record.phantom ? 'POST'   : 'PUT',
      params: changes,
      success: function() {
        //post-processing here - this might include reloading the grid if there are calculated fields
      }
    });
  }
});
</pre>
<p>The code above simply takes the changes object (which is just key: value object with all the changed fields) and issues a request to your server backend.  &#8216;record.phantom&#8217; returns true if this record does not yet exist on the server &#8211; we use this information above to specify whether we&#8217;re POSTing to /users or PUTing to /users/123, in line with normal RESTful practices.</p>
<h2>Adding a new record</h2>
<p>The example above allows for editing an existing record, but how do we add a new one? Like this:</p>
<pre class="brush: jscript;">
var grid = new Ext.grid.GridPanel({
  //... the same config from above goes here,
  tbar: [
    {
      text   : &quot;Add User&quot;,
      handler: function() {
        //make a new empty User and stop any current editing
        var newUser = new User({});
        rowEditor.stopEditing();

        //add our new record as the first row, select it
        grid.store.insert(0, newUser);
        grid.getView().refresh();
        grid.getSelectionModel().selectRow(0);

        //start editing our new User
        rowEditor.startEditing(0);
      }
    }
  ]
});
</pre>
<p>Pretty simple stuff &#8211; we&#8217;ve just added a toolbar with a button which, when clicked, creates a new User record, inserts it at the top of the grid and focusses the RowEditor on it.</p>
<h2>Configuration Options</h2>
<p>Although not documented, the plugin has a few configuration options:</p>
<pre class="brush: jscript;">
var editor = new Ext.ux.grid.RowEditor({
  saveText  : &quot;My Save Button Text&quot;,
  cancelText: &quot;My Cancel Button Text&quot;,
  clicksToEdit: 1, //this changes from the default double-click activation to single click activation
  errorSummary: false //disables display of validation messages if the row is invalid
});
</pre>
<p>If you want to customise other elements of the RowEditor you probably can, but you&#8217;ll need to <a href="http://www.extjs.com/deploy/dev/examples/ux/RowEditor.js">take a look at the source</a> (it&#8217;s not scary).</p>
<h2>Final Thought</h2>
<p>RowEditor is a really nice component which can provide an intuitive interface and save you writing a lot of CRUD code.  It is best employed on grids with only a few columns &#8211; for models with lots of data fields you&#8217;re better off with a full FormPanel.</p>
<p>I&#8217;d be pretty happy to see this included in the default ExtJS distribution, as I find myself returning to it frequently.</p>
]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.extjs.com/deploy/dev/examples/grid/row-editor.html">RowEditor plugin</a> was recently added to the <a href="http://www.extjs.com/deploy/dev/examples/">ExtJS examples page</a>.  It works a lot like a normal Grid Editor, except you can edit several fields on a given row at once before saving.</p>
<p>This neatly solves the problem of adding a new row to an editor grid, entering data into the first field and finding it save itself straight away, which is rarely desired.  In this fashion we can provide full CRUD for simple models in a single page.</p>
<h2>Installation</h2>
<p>You&#8217;ll need to get a copy of the javascript, css and images from the server.  This is a bit of a pain.  If you still have the <a href="http://www.extjs.com/products/extjs/download.php">ExtJS SDK</a> around you can find these in the examples folder, if not you can get each file as follows:</p>
<p>Grab the plugin JS file below and put it where you usually put your .js files:<br />
<a href="http://www.extjs.com/deploy/dev/examples/ux/RowEditor.js">http://www.extjs.com/deploy/dev/examples/ux/RowEditor.js</a></p>
<p>This needs to go with your other stylesheets, usually in a directory called &#8216;css&#8217;:<br />
<a href="http://www.extjs.com/deploy/dev/examples/ux/css/RowEditor.css">http://www.extjs.com/deploy/dev/examples/ux/css/RowEditor.css</a></p>
<p>Download these two images and put them into your existing &#8216;images&#8217; folder (the same place the other ExtJS images live):<br />
<a href="http://www.extjs.com/deploy/dev/examples/ux/images/row-editor-bg.gif">http://www.extjs.com/deploy/dev/examples/ux/images/row-editor-bg.gif</a><br />
<a href="http://www.extjs.com/deploy/dev/examples/ux/images/row-editor-btns.gif">http://www.extjs.com/deploy/dev/examples/ux/images/row-editor-btns.gif</a></p>
<p>Include the .js and .css files on your page and you should be ready to go.</p>
<h2>Usage</h2>
<p>RowEditor is a normal grid plugin, so you&#8217;ll need to instantiate it and add to your grid&#8217;s &#8216;plugins&#8217; property.  You also need to define what type of Editor is available (if any) on each column:</p>
<pre class="brush: jscript;">
var editor = new Ext.ux.grid.RowEditor();

var grid = new Ext.grid.GridPanel({
  plugins: [editor],
  columns: [
    {
      header   : 'User Name',
      dataIndex: 'name',
      editor   : new Ext.form.TextField()
    },
    {
      header   : 'Email',
      dataIndex: 'email',
      editor   : new Ext.form.TextField()
    }
  ]
  ... the rest of your grid config here
});
</pre>
<p>RowEditor defines a few events, the most useful one being &#8216;afteredit&#8217;. Its signature looks like this:</p>
<pre class="brush: jscript;">
/**
 * @event afteredit
 * Fired after a row is edited and passes validation.  This event is fired
 * after the store's update event is fired with this edit.
 * @param {Ext.ux.grid.RowEditor} roweditor This object
 * @param {Object} changes Object with changes made to the record.
 * @param {Ext.data.Record} r The Record that was edited.
 * @param {Number} rowIndex The rowIndex of the row just edited
 */
'afteredit'
</pre>
<p>All you need to do is listen to that event on your RowEditor and save your model object appropriately.  First though, we&#8217;ll define the Ext.data.Record that we&#8217;re using in this grid&#8217;s store:</p>
<pre class="brush: jscript;">
var User = Ext.data.Record.create([
  {name: 'user_id', type: 'int'},
  {name: 'name',    type: 'string'},
  {name: 'email',   type: 'string'}
]);
</pre>
<p>And now the afteredit listener itself</p>
<pre class="brush: jscript;">
editor.on({
  scope: this,
  afteredit: function(roweditor, changes, record, rowIndex) {
    //your save logic here - might look something like this:
    Ext.Ajax.request({
      url   : record.phantom ? '/users' : '/users/' + record.get('user_id'),
      method: record.phantom ? 'POST'   : 'PUT',
      params: changes,
      success: function() {
        //post-processing here - this might include reloading the grid if there are calculated fields
      }
    });
  }
});
</pre>
<p>The code above simply takes the changes object (which is just key: value object with all the changed fields) and issues a request to your server backend.  &#8216;record.phantom&#8217; returns true if this record does not yet exist on the server &#8211; we use this information above to specify whether we&#8217;re POSTing to /users or PUTing to /users/123, in line with normal RESTful practices.</p>
<h2>Adding a new record</h2>
<p>The example above allows for editing an existing record, but how do we add a new one? Like this:</p>
<pre class="brush: jscript;">
var grid = new Ext.grid.GridPanel({
  //... the same config from above goes here,
  tbar: [
    {
      text   : &quot;Add User&quot;,
      handler: function() {
        //make a new empty User and stop any current editing
        var newUser = new User({});
        rowEditor.stopEditing();

        //add our new record as the first row, select it
        grid.store.insert(0, newUser);
        grid.getView().refresh();
        grid.getSelectionModel().selectRow(0);

        //start editing our new User
        rowEditor.startEditing(0);
      }
    }
  ]
});
</pre>
<p>Pretty simple stuff &#8211; we&#8217;ve just added a toolbar with a button which, when clicked, creates a new User record, inserts it at the top of the grid and focusses the RowEditor on it.</p>
<h2>Configuration Options</h2>
<p>Although not documented, the plugin has a few configuration options:</p>
<pre class="brush: jscript;">
var editor = new Ext.ux.grid.RowEditor({
  saveText  : &quot;My Save Button Text&quot;,
  cancelText: &quot;My Cancel Button Text&quot;,
  clicksToEdit: 1, //this changes from the default double-click activation to single click activation
  errorSummary: false //disables display of validation messages if the row is invalid
});
</pre>
<p>If you want to customise other elements of the RowEditor you probably can, but you&#8217;ll need to <a href="http://www.extjs.com/deploy/dev/examples/ux/RowEditor.js">take a look at the source</a> (it&#8217;s not scary).</p>
<h2>Final Thought</h2>
<p>RowEditor is a really nice component which can provide an intuitive interface and save you writing a lot of CRUD code.  It is best employed on grids with only a few columns &#8211; for models with lots of data fields you&#8217;re better off with a full FormPanel.</p>
<p>I&#8217;d be pretty happy to see this included in the default ExtJS distribution, as I find myself returning to it frequently.</p>
]]></content:encoded>
			<wfw:commentRss>http://edspencer.net/2009/09/using-the-extjs-row-editor.html/feed</wfw:commentRss>
		<slash:comments>38</slash:comments>
		</item>
		<item>
		<title>Moving from Blogger to Wordpress</title>
		<link>http://edspencer.net/2009/09/moving-from-blogger-to-wordpress.html</link>
		<comments>http://edspencer.net/2009/09/moving-from-blogger-to-wordpress.html#comments</comments>
		<pubDate>Mon, 14 Sep 2009 15:38:37 +0000</pubDate>
		<dc:creator>Ed Spencer</dc:creator>
				<category><![CDATA[Misc]]></category>

		<guid isPermaLink="false">http://new.edspencer.net/?p=123</guid>
		<description><![CDATA[<p>Over the weekend I migrated from Blogger (hosted by Google) to Wordpress (hosted by me).  Overall, Wordpress feels far superior, but the migration was not without problems. Here&#8217;s a short guide to what I had to do:</p>
<h2>Get Wordpress</h2>
<p><a href="http://wordpress.org/download/">First, grab the latest version of Wordpress</a>. Being a PHP application, it just drops into a directory and works <img src='http://edspencer.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h2>Create a database, set config</h2>
<p>Wordpress has a setup script but being a bit of a noob I couldn&#8217;t give it write permission to my filesystem.  If you are also afflicted by such inadequacies the following steps may help you.  For clarity I&#8217;ll call my DB &#8216;wordpress&#8217;.  First, set up your database:</p>
<ol>
<li>mysql -u root</li>
<li>CREATE DATABASE wordpress;</li>
<li>GRANT ALL on wordpress.* TO &#8216;wordpress&#8217;@'localhost&#8217; identified by &#8216;wordpress&#8217;;</li>
</ol>
<p>You&#8217;ll need a wp-config.php file &#8211; Wordpress comes with a default one which you can copy thusly (in the root directory of your wordpress directory):</p>
<pre>cp wp-config-sample.php wp-config.php</pre>
<p>Now edit wp-config.php, and fill in the details to make it look a little like this:</p>
<p>// ** MySQL settings &#8211; You can get this info from your web host ** //<br />
/** The name of the database for WordPress */<br />
define(&#8217;DB_NAME&#8217;, &#8216;wordpress&#8217;);</p>
<p>/** MySQL database username */<br />
define(&#8217;DB_USER&#8217;, &#8216;wordpress&#8217;);</p>
<p>/** MySQL database password */<br />
define(&#8217;DB_PASSWORD&#8217;, &#8216;wordpress&#8217;);</p>
<p>/** MySQL hostname */<br />
define(&#8217;DB_HOST&#8217;, &#8216;localhost&#8217;);</p>
<p>Hitting the site now should show a default Wordpress installation with some dummy content. Whoop.</p>
<h2>Import from Blogger</h2>
<p>Importing from Blogger is pleasingly simple &#8211; just use the Tools -> Import option on the menu.  It&#8217;ll ask you to verify access and then pull down all your posts and comments.</p>
<p>It&#8217;s not perfect though &#8211; for me the post Tags were imported as Categories.  To get them to be Tags again, go to the Posts -> Categories menu and use the handy Categories to Tags converter.</p>
<p>I found that the imported Post markup was pretty mangled (I think this is Blogger&#8217;s fault, not Wordpress&#8217;) &#8211; &lt;br /&gt;s everywhere and no line breaks.  To resolve this I cracked open mysql again and ran the following:</p>
<ol>
<li>use wordpress;</li>
<li>UPDATE wp_posts SET post_content = REPLACE(post_content, &#8220;&lt;br /&gt;&#8221;, &#8220;\n&#8221;);</li>
</ol>
<p>That sorted me out alright.  Next we need to set up how our permalinks work.  Set this in the Settings -> Permalinks menu, and use the following format to mimic the Blogger urls:</p>
<pre class="brush: plain;">/%year%/%monthnum%/%postname%.html</pre>
<p>Wordpress will either write a .htaccess file for you at this point, or tell you it can&#8217;t write to the filesystem and give you a short text config which you must manually copy into a file called .htaccess.</p>
<p>One final thing to note is that Wordpress constructs its slug urls differently to Blogger (Wordpress would use &#8216;the-trouble-with-new&#8217; vs Blogger&#8217;s &#8216;trouble-with-new&#8217;, for example).  If you&#8217;re importing blog posts this means your urls won&#8217;t always match, so any incoming links will be broken.  I couldn&#8217;t find an easier way to correct them than just copy/paste by hand &#8211; doesn&#8217;t take long though.</p>
<h3>Syntax Highlighting</h3>
<p>This whole step is entirely optional.</p>
<p>Because I&#8217;m a geek I post code fairly often.  I used the SyntaxHighlighter library back in the Blogger days and wanted to keep using it.  You can install the Wordpress plugin version from <a href="http://www.viper007bond.com/wordpress-plugins/syntaxhighlighter/">http://www.viper007bond.com/wordpress-plugins/syntaxhighlighter/</a>.  The old syntax didn&#8217;t seem to work, so I needed to go back into mysql and run the following:</p>
<pre>
UPDATE wp_posts SET post_content = REPLACE(post_content, "&lt;pre name=\&quot;code\&quot; class=\&quot;js\&quot;&gt;", "[c0de language=\"js\"]");
UPDATE wp_posts SET post_content = REPLACE(post_content, "&lt;/pre&gt;", "[/c0de]");
</pre>
<p><strong>NOTE</strong>: So that Wordpress doesn&#8217;t interpret those tags above I&#8217;ve changed the &#8216;o&#8217; in code to a &#8216;0&#8242;.  You need to change it back <img src='http://edspencer.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>This just swaps all your old &lt;pre name=&quot;code&quot; class=&quot;js&quot;&gt; and &lt;/pre&gt; tags for [c0de language="js"]and [/c0de] respectively.  Repeat the first line for any other languages you have used (for me this was xml, css, html and ruby).</p>
<h2>Fixing feeds</h2>
<p>Wordpress doesn&#8217;t like the world to see your content via RSS.  Odd, isn&#8217;t it?  There&#8217;s an option in Settings -> Reading which claims to output the full text of each article into your feed, but it doesn&#8217;t seem to work.  Instead, what you need to do is hack your theme a little.  You&#8217;ll need to edit the wp-includes/feed-rss2.php file and change line 47 from &lt;?php the_excerpt_rss() ?&gt; to &lt;?php the_content() ?&gt;.</p>
<p>If you&#8217;re using Feedburner or similar, don&#8217;t forget to give it your new feed url too.  In this case you should also update wp-content/themes/yourTheme/header.php and swap out the <?php bloginfo('rss2_url') ?> occurrences with your Feedburner url.</p>
<h2>Upload and update DNS</h2>
<p>At this point everything should be working nicely, so upload your blog folder and update your DNS settings.  I&#8217;m guessing if you&#8217;re hosting Wordpress yourself you don&#8217;t need help with this.  I&#8217;ve made my own blog into a git repository up on <a href="http://github.com/edspencer">Github</a>, allowing me to deploy any changes I make using Capistrano.  It&#8217;s a nice solution &#8211; for more information see <a href="http://devblog.imedo.de/2008/6/23/wordpress-deployment-with-capistrano-2-and-git">this lovely post by the gentlemen at imedo</a>.</p>
]]></description>
			<content:encoded><![CDATA[<p>Over the weekend I migrated from Blogger (hosted by Google) to Wordpress (hosted by me).  Overall, Wordpress feels far superior, but the migration was not without problems. Here&#8217;s a short guide to what I had to do:</p>
<h2>Get Wordpress</h2>
<p><a href="http://wordpress.org/download/">First, grab the latest version of Wordpress</a>. Being a PHP application, it just drops into a directory and works <img src='http://edspencer.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h2>Create a database, set config</h2>
<p>Wordpress has a setup script but being a bit of a noob I couldn&#8217;t give it write permission to my filesystem.  If you are also afflicted by such inadequacies the following steps may help you.  For clarity I&#8217;ll call my DB &#8216;wordpress&#8217;.  First, set up your database:</p>
<ol>
<li>mysql -u root</li>
<li>CREATE DATABASE wordpress;</li>
<li>GRANT ALL on wordpress.* TO &#8216;wordpress&#8217;@'localhost&#8217; identified by &#8216;wordpress&#8217;;</li>
</ol>
<p>You&#8217;ll need a wp-config.php file &#8211; Wordpress comes with a default one which you can copy thusly (in the root directory of your wordpress directory):</p>
<pre>cp wp-config-sample.php wp-config.php</pre>
<p>Now edit wp-config.php, and fill in the details to make it look a little like this:</p>
<p>// ** MySQL settings &#8211; You can get this info from your web host ** //<br />
/** The name of the database for WordPress */<br />
define(&#8217;DB_NAME&#8217;, &#8216;wordpress&#8217;);</p>
<p>/** MySQL database username */<br />
define(&#8217;DB_USER&#8217;, &#8216;wordpress&#8217;);</p>
<p>/** MySQL database password */<br />
define(&#8217;DB_PASSWORD&#8217;, &#8216;wordpress&#8217;);</p>
<p>/** MySQL hostname */<br />
define(&#8217;DB_HOST&#8217;, &#8216;localhost&#8217;);</p>
<p>Hitting the site now should show a default Wordpress installation with some dummy content. Whoop.</p>
<h2>Import from Blogger</h2>
<p>Importing from Blogger is pleasingly simple &#8211; just use the Tools -> Import option on the menu.  It&#8217;ll ask you to verify access and then pull down all your posts and comments.</p>
<p>It&#8217;s not perfect though &#8211; for me the post Tags were imported as Categories.  To get them to be Tags again, go to the Posts -> Categories menu and use the handy Categories to Tags converter.</p>
<p>I found that the imported Post markup was pretty mangled (I think this is Blogger&#8217;s fault, not Wordpress&#8217;) &#8211; &lt;br /&gt;s everywhere and no line breaks.  To resolve this I cracked open mysql again and ran the following:</p>
<ol>
<li>use wordpress;</li>
<li>UPDATE wp_posts SET post_content = REPLACE(post_content, &#8220;&lt;br /&gt;&#8221;, &#8220;\n&#8221;);</li>
</ol>
<p>That sorted me out alright.  Next we need to set up how our permalinks work.  Set this in the Settings -> Permalinks menu, and use the following format to mimic the Blogger urls:</p>
<pre class="brush: plain;">/%year%/%monthnum%/%postname%.html</pre>
<p>Wordpress will either write a .htaccess file for you at this point, or tell you it can&#8217;t write to the filesystem and give you a short text config which you must manually copy into a file called .htaccess.</p>
<p>One final thing to note is that Wordpress constructs its slug urls differently to Blogger (Wordpress would use &#8216;the-trouble-with-new&#8217; vs Blogger&#8217;s &#8216;trouble-with-new&#8217;, for example).  If you&#8217;re importing blog posts this means your urls won&#8217;t always match, so any incoming links will be broken.  I couldn&#8217;t find an easier way to correct them than just copy/paste by hand &#8211; doesn&#8217;t take long though.</p>
<h3>Syntax Highlighting</h3>
<p>This whole step is entirely optional.</p>
<p>Because I&#8217;m a geek I post code fairly often.  I used the SyntaxHighlighter library back in the Blogger days and wanted to keep using it.  You can install the Wordpress plugin version from <a href="http://www.viper007bond.com/wordpress-plugins/syntaxhighlighter/">http://www.viper007bond.com/wordpress-plugins/syntaxhighlighter/</a>.  The old syntax didn&#8217;t seem to work, so I needed to go back into mysql and run the following:</p>
<pre>
UPDATE wp_posts SET post_content = REPLACE(post_content, "&lt;pre name=\&quot;code\&quot; class=\&quot;js\&quot;&gt;", "[c0de language=\"js\"]");
UPDATE wp_posts SET post_content = REPLACE(post_content, "&lt;/pre&gt;", "[/c0de]");
</pre>
<p><strong>NOTE</strong>: So that Wordpress doesn&#8217;t interpret those tags above I&#8217;ve changed the &#8216;o&#8217; in code to a &#8216;0&#8242;.  You need to change it back <img src='http://edspencer.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>This just swaps all your old &lt;pre name=&quot;code&quot; class=&quot;js&quot;&gt; and &lt;/pre&gt; tags for [c0de language="js"]and [/c0de] respectively.  Repeat the first line for any other languages you have used (for me this was xml, css, html and ruby).</p>
<h2>Fixing feeds</h2>
<p>Wordpress doesn&#8217;t like the world to see your content via RSS.  Odd, isn&#8217;t it?  There&#8217;s an option in Settings -> Reading which claims to output the full text of each article into your feed, but it doesn&#8217;t seem to work.  Instead, what you need to do is hack your theme a little.  You&#8217;ll need to edit the wp-includes/feed-rss2.php file and change line 47 from &lt;?php the_excerpt_rss() ?&gt; to &lt;?php the_content() ?&gt;.</p>
<p>If you&#8217;re using Feedburner or similar, don&#8217;t forget to give it your new feed url too.  In this case you should also update wp-content/themes/yourTheme/header.php and swap out the <?php bloginfo('rss2_url') ?> occurrences with your Feedburner url.</p>
<h2>Upload and update DNS</h2>
<p>At this point everything should be working nicely, so upload your blog folder and update your DNS settings.  I&#8217;m guessing if you&#8217;re hosting Wordpress yourself you don&#8217;t need help with this.  I&#8217;ve made my own blog into a git repository up on <a href="http://github.com/edspencer">Github</a>, allowing me to deploy any changes I make using Capistrano.  It&#8217;s a nice solution &#8211; for more information see <a href="http://devblog.imedo.de/2008/6/23/wordpress-deployment-with-capistrano-2-and-git">this lovely post by the gentlemen at imedo</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://edspencer.net/2009/09/moving-from-blogger-to-wordpress.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

