<?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>VinylFox &#187; Ref Config</title>
	<atom:link href="http://www.vinylfox.com/tag/ref-config/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vinylfox.com</link>
	<description>The Playground of VinylFox (Shea Frederick)</description>
	<lastBuildDate>Thu, 29 Jul 2010 16:37:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>The Hottest ExtJS 3.0 Feature You&#8217;ve Never Heard About</title>
		<link>http://www.vinylfox.com/the-hottest-extjs-30-feature-youve-never-heard-about/</link>
		<comments>http://www.vinylfox.com/the-hottest-extjs-30-feature-youve-never-heard-about/#comments</comments>
		<pubDate>Tue, 09 Jun 2009 16:07:55 +0000</pubDate>
		<dc:creator>Shea Frederick</dc:creator>
				<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[ExtJS News]]></category>
		<category><![CDATA[Ref Config]]></category>

		<guid isPermaLink="false">http://www.vinylfox.com/?p=260</guid>
		<description><![CDATA[Alright, now that I have your attention with that snappy title, I can talk about a little unknown feature of ExtJS 3.0 that will definitely make your life easier and shorten your code by a few lines &#8211; &#8220;ref&#8221; (everything should come with a &#8220;web 2.0&#8243; logo) This new config that was introduced in ExtJS [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.vinylfox.com/wp-content/uploads/2009/05/ref1.png" alt="ref1" title="ref1" class="alignleft size-thumbnail wp-image-271" align="left" style="margin: 10px; border: solid 1px #000;"/>Alright, now that I have your attention with that snappy title, I can talk about a little unknown feature of ExtJS 3.0 that will definitely make your life easier and shorten your code by a few lines &#8211; <b>&#8220;ref&#8221;</b> (everything should come with a &#8220;web 2.0&#8243; logo)</p>
</p>
<p>This new config that was introduced in ExtJS 3.0 provides us with a way to create a reference to a component right in the config. It&#8217;s so simple its complicated, so I think it&#8217;s quickly become time for an  example&#8230;</p>
<p>Let&#8217;s say your extending panel to create a custom component with two buttons in a bottom toolbar, it might look something like this:</p>
<p><textarea class="js" cols="100" name="code">Ext.ux.mySweetCmp = Ext.extend(Ext.Panel, {<br />
    initComponent: function(){<br />
        Ext.applyIf(this, {<br />
            html: &#8216;Bwah bwah&#8217;,<br />
            bbar: [{<br />
                text: 'Boo',<br />
                itemId: 'button-boo',<br />
                handler: this.myBtnClick,<br />
                scope: this<br />
            }, {<br />
                text: 'Bleh',<br />
                itemId: 'button-bleh'<br />
            }]<br />
        });<br />
        Ext.ux.mySweetCmp.superclass.initComponent.call(this);<br />
    },<br />
    afterRender: function(){<br />
        this.btmTb = this.getBottomToolbar();<br />
        this.buttonBoo = this.btmTb.getComponent(&#8216;button-boo&#8217;);<br />
        this.buttonBleh = this.btmTb.getComponent(&#8216;button-bleh&#8217;);<br />
        Ext.ux.mySweetCmp.superclass.afterRender.call(this);<br />
    },<br />
    myBtnClick: function(){<br />
        this.buttonBoo.setText(&#8216;New Boo&#8217;);<br />
        this.buttonBleh.setText(&#8216;New Bleh&#8217;).disable();<br />
    }<br />
});</textarea></p>
<p>It&#8217;s lines 18, 19 &#038; 20 that make me uneasy. When im inside extending a component, I don&#8217;t feel like it should be necessary for me to have to locate a component that is nested within the component im creating and manually assign it to the scope &#8211; right?</p>
<p>When we put the new <i>ref</i> config into use, our code will look something like this:</p>
<p><textarea class="js" cols="100" name="code">Ext.ux.mySweetCmp = Ext.extend(Ext.Panel, {<br />
    initComponent: function(){<br />
        Ext.applyIf(this, {<br />
            html: &#8216;Bwah bwah&#8217;,<br />
            bbar: [{<br />
                text: 'Boo',<br />
                ref: '../buttonBoo',<br />
                handler: this.myBtnClick,<br />
                scope: this<br />
            },{<br />
                text: 'Bleh',<br />
                ref: '../buttonBleh'<br />
            }]<br />
        });<br />
        Ext.ux.mySweetCmp.superclass.initComponent.call(this);<br />
    },<br />
    myBtnClick: function(){<br />
        this.buttonBoo.setText(&#8216;New Boo&#8217;);<br />
        this.buttonBleh.setText(&#8216;New Bleh&#8217;).disable();<br />
    }<br />
});</textarea></p>
<p>The only way to describe this is &#8220;clean&#8221;. Now lines 18 &#038; 19 are working directly from my local scoped variables, referencing components contained within my component. No messing around with finding the component and manually assigning it to a variable in the scope. Not to mention, with this very short example we were able to save six lines of code, which is a great savings when your only talking about twenty-seven lines of code total &#8211; that&#8217;s a 20% savings!</p>
<h2>The Nitty Gritty</h2>
<p>The <i>ref</i> config works much like changing folders on a linux command line, two dots and a slash travel up one level of folder, or in the case of <i>ref</i>, a level of nested component. It takes care of adding the scoped variables for you using the name you provide in the <i>ref</i> config.</p>
<h2>Summary</h2>
<p>This is one of those things you find often in ExtJS that really set it apart from other RIA libraries &#8211; one of the many reasons I use and recommend the ExtJS library for projects over and over again. Simplicity in a highly configurable UI component is not an easy thing to balance, but ExtJS has managed to do it again and again.</p>
<p><b>NOTE:</b> Something as trivial as adding a toolbar and buttons to a panel is not a reason in itself to create an extended component, this is simply for the purpose of having a minimalistic example &#8211; no matter how pointless it might be.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vinylfox.com/the-hottest-extjs-30-feature-youve-never-heard-about/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
	</channel>
</rss>
