<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>The Codeaholic</title>
	<atom:link href="http://jholtscode.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://jholtscode.wordpress.com</link>
	<description>The Journey of a Loving Husband, Father, and all around Nutcase.</description>
	<lastBuildDate>Fri, 09 Oct 2009 19:58:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='jholtscode.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>The Codeaholic</title>
		<link>http://jholtscode.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://jholtscode.wordpress.com/osd.xml" title="The Codeaholic" />
	<atom:link rel='hub' href='http://jholtscode.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Nifty Trick with Root Controller Paradigm</title>
		<link>http://jholtscode.wordpress.com/2009/10/09/nifty-trick-with-root-controller-paradigm/</link>
		<comments>http://jholtscode.wordpress.com/2009/10/09/nifty-trick-with-root-controller-paradigm/#comments</comments>
		<pubDate>Fri, 09 Oct 2009 19:58:49 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Sproutcore]]></category>

		<guid isPermaLink="false">http://jholtscode.wordpress.com/?p=16</guid>
		<description><![CDATA[I want to start this off by saying that I am constantly amazed by the power baked right into sproutcore. Most of the time what you need is there already, you just have to read the code and the comments. With that said lets talk about this nifty trick shall we? First and foremost if [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jholtscode.wordpress.com&amp;blog=9782696&amp;post=16&amp;subd=jholtscode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I want to start this off by saying that I am constantly amazed by the power baked right into sproutcore. Most of the time what you need is there already, you just have to read the code and the comments.</p>
<p>With that said lets talk about this nifty trick shall we? First and foremost if you have not read Evin&#8217;s post about the &#8220;Root Controller Paradigm&#8221; click <a style="color:#007bff;" title="here" href="http://www.itsgotwhatplantscrave.com/2009/07/30/root-controller-paradigm/" target="_blank">here</a>, I will wait&#8230;</p>
<p>Ok now that you have that out of the way, let&#8217;s say that I am using this technique to build up a tree of objects to display in a source list. While I am building this tree I decide that I want to have some dynamically calculated value appended to the the end of the text in the collapsible header row. A good example would be a list of tasks and the header row&#8217;s text displays as the name of the task list. The dynamically calculated value would be based on the number of tasks, the effort each task will take, and it&#8217;s priority. The purpose of this value would be to display an estimated time-to-completion for this task list.</p>
<p>To do this you need to know when the effort and priority properties change on each task in this particular list ( <strong><em>the length of the list is already being observed for you because it is the content array of the controller</em></strong> ). Right at this moment you start trying to figure out how to observe these properties on each task in the list ( <strong><em>the content array of your controller building this tree of objects</em></strong> ). You might try adding the following method to your controller as I did.<br />
<pre class="brush: jscript;">
someMethodName: function(){
/*
do something to recreate the tree
of objects to update the display
*/
}.observes('[]*effort')
</pre><br />
The previous method will not work, although you and I both feel that it would because we have this idea that using the &#8220;*&#8221; wild card after the content array would allow us access to it&#8217;s contents. Now that I have you wondering why this does not work, here is the explanation. The content array has it&#8217;s own properties that can be observed, so using the wild card doesn&#8217;t really give you access to it&#8217;s contents.</p>
<p>You say on with the solution, well I&#8217;m here to tell you that the solution is fairly straight forward once you step back for a second to think about what you really want to do here. And now for the solution: We know that every item in the content array inherits from SC.Object ( <strong><em>if the objects are created using some construct bundled with sproutcore</em></strong> ). Because of this they also have the observable mixin applied and with this knowledge we have all of the tools we need to make this happen.</p>
<p>In your controller you have a method that builds each object in the tree of objects for your source list. In this method you have access to the the task list object and it&#8217;s array of tasks and their properties. This is how you are providing your header row text and calculated value. The observable mixin gives us the methods we need, &#8220;addObserver&#8221;, &#8220;removeObserver&#8221;, and &#8220;hasObserverFor&#8221;. With these methods we can now add observers to the effort and priority properties that will fire a method when they are changed and cause the tree to be rebuilt and the UI will display the result immediately. Here is the code:<br />
<pre class="brush: jscript;">
for (var i = 0; i &amp;lt; len; i++){
task = tasks.objectAt(i);
// Removed usage of hasObserverFor via Charles' Comments
task.removeObserver('effort',this,'_contentHasChanged');
task.removeObserver('priority',this,'_contentHasChanged');
task.addObserver('effort',this,'_contentHasChanged');
task.addObserver('priority',this,'_contentHasChanged');
effortString = task.get('effort');
if(effortString &amp;amp;&amp;amp;
task.get('priority') !== CoreTasks.TASK_PRIORITY_LOW) {
// sum up effort for High/Medium priority tasks
effortMin = parseInt(effortString, 10);
var idx = effortString.indexOf('-'); // see if effort is a range
if(idx === -1) { // not a range
effortMax = effortMin;
} else {
// effort IS a range, extract max
effortMax = parseInt(effortString.slice(idx+1), 10);
}
totalEffortMin += effortMin;
totalEffortMax += effortMax;
}
}
if(totalEffortMin !== 0) {
var totalEffort = '' + totalEffortMin;
if (totalEffortMax !== totalEffortMin) {
totalEffort += '-' + totalEffortMax;
}
displayName = displayName + ' {' + totalEffort + '}';
}
return SC.Object.create({
displayName: displayName,
assignee: assigneeObj.assignee,
treeItemChildren: tasks,
treeItemIsExpanded: YES
});
</pre><br />
The important parts here are lines 3-10. These lines check to see if the current task object has an observer for the properties that we would like to observe. If the task object does we remove the observer and then add new observers to observe the new value that these properties hold. These observes fire a method on the controller that rebuilds the tree, which will cause the UI to immediately reflect the changes of each task in the task list array.</p>
<p>Hopefully this will help you on your way and point you in the right direction. Just remember this, when you think you&#8217;ve hit a wall look to the comments and the code in sproutcore&#8217;s source and you will probably find the answer. If by some chance you are not able to find the answer there you can always look to this blog, as I will post any way that I find to get the most out of the sproutcore frame work. Don&#8217;t forget to drop into the #sproutcore IRC channel on irc.freenode.net.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jholtscode.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jholtscode.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jholtscode.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jholtscode.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jholtscode.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jholtscode.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jholtscode.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jholtscode.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jholtscode.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jholtscode.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jholtscode.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jholtscode.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jholtscode.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jholtscode.wordpress.com/16/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jholtscode.wordpress.com&amp;blog=9782696&amp;post=16&amp;subd=jholtscode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jholtscode.wordpress.com/2009/10/09/nifty-trick-with-root-controller-paradigm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1b1b0667ae135bee37478ea2fd5306b4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Josh</media:title>
		</media:content>
	</item>
		<item>
		<title>The Delegate Pattern &amp; SproutCore</title>
		<link>http://jholtscode.wordpress.com/2009/10/09/the-delegate-pattern-sproutcore/</link>
		<comments>http://jholtscode.wordpress.com/2009/10/09/the-delegate-pattern-sproutcore/#comments</comments>
		<pubDate>Fri, 09 Oct 2009 19:49:15 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Sproutcore]]></category>

		<guid isPermaLink="false">http://jholtscode.wordpress.com/?p=13</guid>
		<description><![CDATA[In my previous post I promised some information on the &#8220;Delegate Design Pattern&#8221;, how Sproutcore uses it, and how to take advantage of it. In part 1 I will try my best to describe the Delegate Design Pattern. In part 2 I will explain this pattern in the context of Sproutcore ( with examples ), [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jholtscode.wordpress.com&amp;blog=9782696&amp;post=13&amp;subd=jholtscode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In my previous post I promised some information on the &#8220;Delegate Design Pattern&#8221;, how Sproutcore uses it, and how to take advantage of it. In part 1 I will try my best to describe the Delegate Design Pattern. In part 2 I will explain this pattern in the context of Sproutcore ( with examples ), and part 3 is still in the works.</p>
<p><strong><em>What is the &#8220;Delegate Design Pattern&#8221; ?</em></strong></p>
<p>Let&#8217;s talk about the meaning of a delegate. In languages such as C#, Java, etc&#8230; you usually think of a delegate as nothing more than a function pointer. In languages such as Objective-C, javascript, ruby, etc&#8230; you can think of a delegate as an instance of a class (an object) to which work is delegated. It may or may not be obvious how powerful this concept is, so I&#8217;ll give an example:</p>
<p>In most applications you will inevitably need to display a list of data. There are several approaches to get the data into the list. You could use straight data binding and cram all of the data into your view ( inefficient ) and let the view deal with pagination and so on, or you can use a delegate with data binding. The use of a delegate will allow the view to just worry about displaying data and it decouples the view from the model. In this case the delegate and the controller ( sometimes the same object ) work together to provide the data that the list needs at any given time.</p>
<p>Given a list in this fashion you can set up the view so that all it cares about is it&#8217;s size and that it is displaying a &#8220;name property&#8221;.  The List can then ask the controller for the data it needs and only the data it needs based on it&#8217;s size. The controller will then [call | invoke] a method on the delegate to calculate the number of records that can be displayed in the area of the list, then it returns this number of records to the controller and the controller will give this to the list(view) and it gets displayed.</p>
<p><strong>There are at least two distinct advantages that I can think of here:</strong></p>
<ol>
<li>In straight data binding it becomes too easy to tie your view down to just one specific model.</li>
<li>In straight data binding your controller will stuff all of the result-set (RecordArray) down the list&#8217;s throat and expect the list to be ok with it, not choke and spew. What I&#8217;m trying to get at here is that this can really be inefficient.</li>
</ol>
<p>Well that&#8217;s it for my humble explanation of the delegate design pattern, In the next post I will expand on my example of a list view and show you how this pattern is used in sproutcore&#8217;s CollectionView.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jholtscode.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jholtscode.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jholtscode.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jholtscode.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jholtscode.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jholtscode.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jholtscode.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jholtscode.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jholtscode.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jholtscode.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jholtscode.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jholtscode.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jholtscode.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jholtscode.wordpress.com/13/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jholtscode.wordpress.com&amp;blog=9782696&amp;post=13&amp;subd=jholtscode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jholtscode.wordpress.com/2009/10/09/the-delegate-pattern-sproutcore/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1b1b0667ae135bee37478ea2fd5306b4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Josh</media:title>
		</media:content>
	</item>
		<item>
		<title>What&#8217;s going on here?</title>
		<link>http://jholtscode.wordpress.com/2009/10/04/hello-world/</link>
		<comments>http://jholtscode.wordpress.com/2009/10/04/hello-world/#comments</comments>
		<pubDate>Sun, 04 Oct 2009 19:36:48 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Yeah, so as the title says I already have this other blog over here. Why do I need this one too? Well let me answer that question: My other blog is on Tumblr, which is a great service with some smashing styles and flexibility but you can&#8217;t always make your code look good with out [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jholtscode.wordpress.com&amp;blog=9782696&amp;post=1&amp;subd=jholtscode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Yeah, so as the title says I already have this other blog over <a title="here" href="http://blog.thesempiternalholts.com" target="_blank">here</a>. Why do I need this one too? Well let me answer that question: My other blog is on Tumblr, which is a great service with some smashing styles and flexibility but you can&#8217;t always make your code look good with out some extra work and the Disqus comments don&#8217;t always look great either. I am going to move my more technical posts here, where I have builtin comments and code highlighting.</p>
<p>Now, don&#8217;t get me wrong here I don&#8217;t mind the extra work to spruce up a tumble-log, but the concept of tumblr doesn&#8217;t really foster the longer post model, so for now I&#8217;ll avoid the extra work and use WP&#8217;s built-ins.</p>
<p>Do check back within the next day or so, I will have my technical posts here as well as some new material on #sproutcore and Google App Engine.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jholtscode.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jholtscode.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jholtscode.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jholtscode.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jholtscode.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jholtscode.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jholtscode.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jholtscode.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jholtscode.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jholtscode.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jholtscode.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jholtscode.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jholtscode.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jholtscode.wordpress.com/1/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jholtscode.wordpress.com&amp;blog=9782696&amp;post=1&amp;subd=jholtscode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jholtscode.wordpress.com/2009/10/04/hello-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1b1b0667ae135bee37478ea2fd5306b4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Josh</media:title>
		</media:content>
	</item>
	</channel>
</rss>
