<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Ojay &#8211; a chaining wrapper for the YUI</title>
	<atom:link href="http://ajaxian.com/archives/ojay-a-chaining-wrapper-for-the-yui/feed" rel="self" type="application/rss+xml" />
	<link>http://ajaxian.com/archives/ojay-a-chaining-wrapper-for-the-yui</link>
	<description>Cleaning up the web with Ajax</description>
	<lastBuildDate>Thu, 09 Feb 2012 06:55:33 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
	<item>
		<title>By: irinasheik</title>
		<link>http://ajaxian.com/archives/ojay-a-chaining-wrapper-for-the-yui/comment-page-1#comment-285543</link>
		<dc:creator>irinasheik</dc:creator>
		<pubDate>Wed, 15 Dec 2010 07:36:02 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/ojay-a-chaining-wrapper-for-the-yui#comment-285543</guid>
		<description>I was going to say.. “this is what DED&#124;Chain was.” But now that I know it got the inspiration from it, I feel better now :)</description>
		<content:encoded><![CDATA[<p>I was going to say.. “this is what DED|Chain was.” But now that I know it got the inspiration from it, I feel better now :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: DiSiLLUSiON</title>
		<link>http://ajaxian.com/archives/ojay-a-chaining-wrapper-for-the-yui/comment-page-1#comment-261579</link>
		<dc:creator>DiSiLLUSiON</dc:creator>
		<pubDate>Sun, 24 Feb 2008 22:57:58 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/ojay-a-chaining-wrapper-for-the-yui#comment-261579</guid>
		<description>I would still like to be able to write this though:

&lt;code&gt;
$(&quot;a#run-this-code&quot;).on(&quot;click&quot;, $.stopEvent)
	.setContent(&quot;Running...&quot;)
	._(&quot;#example&quot;).animate(&quot;heightTo=0,opacity=1:0&quot;, 0.5)
	._($.HTTP).GET(&quot;/service/hello.html&quot;)
	._(&quot;#example&quot;).animate(&quot;heightTo=80,opacity=0:1&quot;, 0.7);
&lt;/code&gt;

Oh well, I can dream, can I not?</description>
		<content:encoded><![CDATA[<p>I would still like to be able to write this though:</p>
<p><code><br />
$("a#run-this-code").on("click", $.stopEvent)<br />
	.setContent("Running...")<br />
	._("#example").animate("heightTo=0,opacity=1:0", 0.5)<br />
	._($.HTTP).GET("/service/hello.html")<br />
	._("#example").animate("heightTo=80,opacity=0:1", 0.7);<br />
</code></p>
<p>Oh well, I can dream, can I not?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: DiSiLLUSiON</title>
		<link>http://ajaxian.com/archives/ojay-a-chaining-wrapper-for-the-yui/comment-page-1#comment-261578</link>
		<dc:creator>DiSiLLUSiON</dc:creator>
		<pubDate>Sun, 24 Feb 2008 22:53:10 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/ojay-a-chaining-wrapper-for-the-yui#comment-261578</guid>
		<description>...Very cool indeed: I&#039;ve been reading the link you provided, and it does a better job of explaining Ojay then this post on Ajaxian does. I kinda missed the point: thought it was about readability concerning the syntax, but it&#039;s not. It&#039;s about readability concerning the structure! In that case, please disregard my earlier posts. :)

The way it flattens out async behaviour is quite good, since it makes the &#039;flow&#039; of code much easier to grasp at a glance. Nice.</description>
		<content:encoded><![CDATA[<p>&#8230;Very cool indeed: I&#8217;ve been reading the link you provided, and it does a better job of explaining Ojay then this post on Ajaxian does. I kinda missed the point: thought it was about readability concerning the syntax, but it&#8217;s not. It&#8217;s about readability concerning the structure! In that case, please disregard my earlier posts. :)</p>
<p>The way it flattens out async behaviour is quite good, since it makes the &#8216;flow&#8217; of code much easier to grasp at a glance. Nice.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: DiSiLLUSiON</title>
		<link>http://ajaxian.com/archives/ojay-a-chaining-wrapper-for-the-yui/comment-page-1#comment-261577</link>
		<dc:creator>DiSiLLUSiON</dc:creator>
		<pubDate>Sun, 24 Feb 2008 22:42:21 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/ojay-a-chaining-wrapper-for-the-yui#comment-261577</guid>
		<description>Oh, the asynchronous behavior is a big plus: very cool.</description>
		<content:encoded><![CDATA[<p>Oh, the asynchronous behavior is a big plus: very cool.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: DiSiLLUSiON</title>
		<link>http://ajaxian.com/archives/ojay-a-chaining-wrapper-for-the-yui/comment-page-1#comment-261576</link>
		<dc:creator>DiSiLLUSiON</dc:creator>
		<pubDate>Sun, 24 Feb 2008 22:40:05 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/ojay-a-chaining-wrapper-for-the-yui#comment-261576</guid>
		<description>&lt;b&gt;James Coglan&lt;/b&gt;: I see your point. Though the extreme indenting in your &#039;flat&#039; example can be averted when the anonymous functions are defined beforehand, it does distort the &#039;flow&#039; extremely:

&lt;code&gt;
var example = $(&#039;#example&#039;);

var before = function(link, e) {
	e.stopEvent();
	link.setContent(&#039;Running...&#039;);
	example.animate({
		height: { to: 0 },
		opacity: { from: 1, to: 0 }
    }, 0.5, { after: getstuff });
};

var after = function(transport) {
	example.setContent(transport.responseText);
	example.animate({
		height: { to: 80 },
		opacity: { from: 0, to: 1 }
	}, 0.7);
}

var getstuff = function() {
	$.HTTP.GET(&#039;/service/hello.html&#039;, {}, { onSuccess: after })
};

$(&#039;a#run-this-code&#039;).on(&#039;click&#039;, before);
&lt;/code&gt;

Quite readable, however, naming those functions isn&#039;t really a good idea...

While (judging on your examples) Ojay does a good job of increasing the readability of the code, compared to YUI, while retaining a &#039;natural&#039; flow, how far are you willing to take it? It&#039;s not bad, but it&#039;s not perfect either. That&#039;s basically the point I tried to make: While chaining is one thing, how about using strings and .toSource() them into objects to feed YUI when an object will never contain a function? Perhaps even create wrappers with a few parameters for often-used combinations (like the example on your frontpage) so there&#039;s even less typing?</description>
		<content:encoded><![CDATA[<p><b>James Coglan</b>: I see your point. Though the extreme indenting in your &#8216;flat&#8217; example can be averted when the anonymous functions are defined beforehand, it does distort the &#8216;flow&#8217; extremely:</p>
<p><code><br />
var example = $('#example');</p>
<p>var before = function(link, e) {<br />
	e.stopEvent();<br />
	link.setContent('Running...');<br />
	example.animate({<br />
		height: { to: 0 },<br />
		opacity: { from: 1, to: 0 }<br />
    }, 0.5, { after: getstuff });<br />
};</p>
<p>var after = function(transport) {<br />
	example.setContent(transport.responseText);<br />
	example.animate({<br />
		height: { to: 80 },<br />
		opacity: { from: 0, to: 1 }<br />
	}, 0.7);<br />
}</p>
<p>var getstuff = function() {<br />
	$.HTTP.GET('/service/hello.html', {}, { onSuccess: after })<br />
};</p>
<p>$('a#run-this-code').on('click', before);<br />
</code></p>
<p>Quite readable, however, naming those functions isn&#8217;t really a good idea&#8230;</p>
<p>While (judging on your examples) Ojay does a good job of increasing the readability of the code, compared to YUI, while retaining a &#8216;natural&#8217; flow, how far are you willing to take it? It&#8217;s not bad, but it&#8217;s not perfect either. That&#8217;s basically the point I tried to make: While chaining is one thing, how about using strings and .toSource() them into objects to feed YUI when an object will never contain a function? Perhaps even create wrappers with a few parameters for often-used combinations (like the example on your frontpage) so there&#8217;s even less typing?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ded</title>
		<link>http://ajaxian.com/archives/ojay-a-chaining-wrapper-for-the-yui/comment-page-1#comment-261574</link>
		<dc:creator>ded</dc:creator>
		<pubDate>Sun, 24 Feb 2008 20:46:09 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/ojay-a-chaining-wrapper-for-the-yui#comment-261574</guid>
		<description>I was going to say.. &quot;this is what DED&#124;Chain was.&quot; But now that I know it got the inspiration from it, I feel better now :)</description>
		<content:encoded><![CDATA[<p>I was going to say.. &#8220;this is what DED|Chain was.&#8221; But now that I know it got the inspiration from it, I feel better now :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: michaelhart</title>
		<link>http://ajaxian.com/archives/ojay-a-chaining-wrapper-for-the-yui/comment-page-1#comment-261573</link>
		<dc:creator>michaelhart</dc:creator>
		<pubDate>Sun, 24 Feb 2008 20:26:17 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/ojay-a-chaining-wrapper-for-the-yui#comment-261573</guid>
		<description>This is one case where syntax highlighting, for me, gets in the way. I find the non-highlighted version on the original page very easy to read, but here I&#039;m distracted by the way the color breaks up the flow.</description>
		<content:encoded><![CDATA[<p>This is one case where syntax highlighting, for me, gets in the way. I find the non-highlighted version on the original page very easy to read, but here I&#8217;m distracted by the way the color breaks up the flow.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Coglan</title>
		<link>http://ajaxian.com/archives/ojay-a-chaining-wrapper-for-the-yui/comment-page-1#comment-261571</link>
		<dc:creator>James Coglan</dc:creator>
		<pubDate>Sun, 24 Feb 2008 19:44:31 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/ojay-a-chaining-wrapper-for-the-yui#comment-261571</guid>
		<description>If I could correct one small misaprehension: the chaining in Ojay is more powerful than that in jQuery, in that it handles asynchronous behaviour for you rather than just calling a sequence of methods synchronously on the same object. If I were to rewrite the example without chaining, it would need to look like this:

&lt;code&gt;
$(&#039;a#run-this-code&#039;).on(&#039;click&#039;, function(link, e) {
    e.stopEvent();
    link.setContent(&#039;Running...&#039;);
    var example = $(&#039;#example&#039;);
    example.animate({
        height:     {to: 0},
        opacity:    {from: 1, to: 0}
    }, 0.5, {
        after: function() {
            $.HTTP.GET(&#039;/service/hello.html&#039;, {}, {
                onSuccess: function(transport) {
                    example.setContent(transport.responseText);
                    example.animate({
                        height:     {to: 80},
                        opacity:    {from: 0, to: 1}
                    }, 0.7);
                }
            })
        }
    });
});
&lt;/code&gt;

I&#039;ve run into plenty of examples where the nesting gets so deep the flow of the code is completely intractable, so I wanted to come up with something that made it clear which order things are happening in. Also, using chaining rather than nested functions, setTimeouts etc means if you want to remove one of the steps, you only need to modify the code in one place rather than two or more.

I know the example is not particularly elegant, but I wanted to demonstrate several concepts -- events, ajax, animation, asynchronous chaining -- in one short snippet. Hopefully the other examples through the documentation are better examples of style.</description>
		<content:encoded><![CDATA[<p>If I could correct one small misaprehension: the chaining in Ojay is more powerful than that in jQuery, in that it handles asynchronous behaviour for you rather than just calling a sequence of methods synchronously on the same object. If I were to rewrite the example without chaining, it would need to look like this:</p>
<p><code><br />
$('a#run-this-code').on('click', function(link, e) {<br />
    e.stopEvent();<br />
    link.setContent('Running...');<br />
    var example = $('#example');<br />
    example.animate({<br />
        height:     {to: 0},<br />
        opacity:    {from: 1, to: 0}<br />
    }, 0.5, {<br />
        after: function() {<br />
            $.HTTP.GET('/service/hello.html', {}, {<br />
                onSuccess: function(transport) {<br />
                    example.setContent(transport.responseText);<br />
                    example.animate({<br />
                        height:     {to: 80},<br />
                        opacity:    {from: 0, to: 1}<br />
                    }, 0.7);<br />
                }<br />
            })<br />
        }<br />
    });<br />
});<br />
</code></p>
<p>I&#8217;ve run into plenty of examples where the nesting gets so deep the flow of the code is completely intractable, so I wanted to come up with something that made it clear which order things are happening in. Also, using chaining rather than nested functions, setTimeouts etc means if you want to remove one of the steps, you only need to modify the code in one place rather than two or more.</p>
<p>I know the example is not particularly elegant, but I wanted to demonstrate several concepts &#8212; events, ajax, animation, asynchronous chaining &#8212; in one short snippet. Hopefully the other examples through the documentation are better examples of style.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tr0y</title>
		<link>http://ajaxian.com/archives/ojay-a-chaining-wrapper-for-the-yui/comment-page-1#comment-261570</link>
		<dc:creator>Tr0y</dc:creator>
		<pubDate>Sun, 24 Feb 2008 18:46:57 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/ojay-a-chaining-wrapper-for-the-yui#comment-261570</guid>
		<description>Not bad this might ease the transition from a jQuery project to a YUI one, however I would worry about this project not keeping up to date with YUI and it becomes harder to upgrade.

I could see myself using jQuery accidentally with this. :-x</description>
		<content:encoded><![CDATA[<p>Not bad this might ease the transition from a jQuery project to a YUI one, however I would worry about this project not keeping up to date with YUI and it becomes harder to upgrade.</p>
<p>I could see myself using jQuery accidentally with this. :-x</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: DiSiLLUSiON</title>
		<link>http://ajaxian.com/archives/ojay-a-chaining-wrapper-for-the-yui/comment-page-1#comment-261569</link>
		<dc:creator>DiSiLLUSiON</dc:creator>
		<pubDate>Sun, 24 Feb 2008 11:59:15 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/ojay-a-chaining-wrapper-for-the-yui#comment-261569</guid>
		<description>I forgot to post the pseudo code:
&lt;code&gt;
var e = lib.select(&quot;a#run-this-code&quot;);
var ex = lib.select(&quot;#example&quot;);

lib.setContent(e, &quot;Running&quot;);
lib.animate(ex, &quot;height-to:0,opacity-from:1,opacity-to:0&quot;, 0.5);

var dat = lib.get(&quot;/service/hello.html&quot;);

lib.insertInto(ex, dat);
lib.animate(ex, &quot;height-to:80,opacity-from:0,opacity-to:1&quot;, 0.7);
&lt;/code&gt;

The more readable your code is, the easier it is to maintain by multiple developers and especially new developers.</description>
		<content:encoded><![CDATA[<p>I forgot to post the pseudo code:<br />
<code><br />
var e = lib.select("a#run-this-code");<br />
var ex = lib.select("#example");</p>
<p>lib.setContent(e, "Running");<br />
lib.animate(ex, "height-to:0,opacity-from:1,opacity-to:0", 0.5);</p>
<p>var dat = lib.get("/service/hello.html");</p>
<p>lib.insertInto(ex, dat);<br />
lib.animate(ex, "height-to:80,opacity-from:0,opacity-to:1", 0.7);<br />
</code></p>
<p>The more readable your code is, the easier it is to maintain by multiple developers and especially new developers.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: DiSiLLUSiON</title>
		<link>http://ajaxian.com/archives/ojay-a-chaining-wrapper-for-the-yui/comment-page-1#comment-261568</link>
		<dc:creator>DiSiLLUSiON</dc:creator>
		<pubDate>Sun, 24 Feb 2008 11:55:14 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/ojay-a-chaining-wrapper-for-the-yui#comment-261568</guid>
		<description>Oh by the way: I&#039;d personally change the object variables passing to a function as well -- since it degrades readability as well (not to mention how many times people forget to correctly put a , after the line in an object except the last one) -- to a string like &quot;height=80,opacity-from:0,opacity-to:1&quot;;</description>
		<content:encoded><![CDATA[<p>Oh by the way: I&#8217;d personally change the object variables passing to a function as well &#8212; since it degrades readability as well (not to mention how many times people forget to correctly put a , after the line in an object except the last one) &#8212; to a string like &#8220;height=80,opacity-from:0,opacity-to:1&#8243;;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: DiSiLLUSiON</title>
		<link>http://ajaxian.com/archives/ojay-a-chaining-wrapper-for-the-yui/comment-page-1#comment-261567</link>
		<dc:creator>DiSiLLUSiON</dc:creator>
		<pubDate>Sun, 24 Feb 2008 11:52:24 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/ojay-a-chaining-wrapper-for-the-yui#comment-261567</guid>
		<description>Personally, I agree that code should tell a story; in other words: be self-explainable. But I do believe that, while superficially a good idea, chaining functions has serious downsides in that respect, as well: just like a story, code should be formatted for readability. When chaining functions, this readability gets a good kick because of all the punctuation and syntax characters.
Look at the code posted:
&lt;code&gt;
$(&#039;a#run-this-code&#039;).on(&#039;click&#039;, $.stopEvent)
    .setContent(&#039;Running...&#039;)
    ._(&#039;#example&#039;).animate({
        height: {to: 0},
        opacity: {from: 1, to: 0}
    }, 0.5)
    ._($.HTTP).GET(&#039;/service/hello.html&#039;)
    .insertInto(&#039;#example&#039;)
    ._(&#039;#example&#039;).animate({
        height: {to: 80},
        opacity: {from: 0, to: 1}
    }, 0.7);
&lt;/code&gt;
And some pseudo code:
&lt;code&gt;
var e = lib.select(&quot;a#run-this-code&quot;);
var ex = lib.select(&quot;#example&quot;);

lib.setContent(e, &quot;Running&quot;);

lib.animate(ex, {
	height: { to: 0 },
	opacity: { from: 1, to: 0 }
}, 0.5);

var dat = lib.get(&quot;/service/hello.html&quot;);

lib.insertInto(ex, dat);

lib.animate(ex, {
	height: { to: 80 },
	opacity: { from: 0, to: 1 }
}, 0.7);
&lt;/code&gt;

Which one has a high degree of readability? I&#039;d wager the second one, at least, in a glance. Yes, chained code is just as self-explanatory, but it&#039;s my experience that when I&#039;m scanning a document with lots of chained coding, the reading speed suffers considerably because of all the punctuation and characters.</description>
		<content:encoded><![CDATA[<p>Personally, I agree that code should tell a story; in other words: be self-explainable. But I do believe that, while superficially a good idea, chaining functions has serious downsides in that respect, as well: just like a story, code should be formatted for readability. When chaining functions, this readability gets a good kick because of all the punctuation and syntax characters.<br />
Look at the code posted:<br />
<code><br />
$('a#run-this-code').on('click', $.stopEvent)<br />
    .setContent('Running...')<br />
    ._('#example').animate({<br />
        height: {to: 0},<br />
        opacity: {from: 1, to: 0}<br />
    }, 0.5)<br />
    ._($.HTTP).GET('/service/hello.html')<br />
    .insertInto('#example')<br />
    ._('#example').animate({<br />
        height: {to: 80},<br />
        opacity: {from: 0, to: 1}<br />
    }, 0.7);<br />
</code><br />
And some pseudo code:<br />
<code><br />
var e = lib.select("a#run-this-code");<br />
var ex = lib.select("#example");</p>
<p>lib.setContent(e, "Running");</p>
<p>lib.animate(ex, {<br />
	height: { to: 0 },<br />
	opacity: { from: 1, to: 0 }<br />
}, 0.5);</p>
<p>var dat = lib.get("/service/hello.html");</p>
<p>lib.insertInto(ex, dat);</p>
<p>lib.animate(ex, {<br />
	height: { to: 80 },<br />
	opacity: { from: 0, to: 1 }<br />
}, 0.7);<br />
</code></p>
<p>Which one has a high degree of readability? I&#8217;d wager the second one, at least, in a glance. Yes, chained code is just as self-explanatory, but it&#8217;s my experience that when I&#8217;m scanning a document with lots of chained coding, the reading speed suffers considerably because of all the punctuation and characters.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: skippyK</title>
		<link>http://ajaxian.com/archives/ojay-a-chaining-wrapper-for-the-yui/comment-page-1#comment-261564</link>
		<dc:creator>skippyK</dc:creator>
		<pubDate>Sun, 24 Feb 2008 02:27:16 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/ojay-a-chaining-wrapper-for-the-yui#comment-261564</guid>
		<description>I&#039;m not sure about the morale of the story either, but I&#039;m quite sure its different from its moral.</description>
		<content:encoded><![CDATA[<p>I&#8217;m not sure about the morale of the story either, but I&#8217;m quite sure its different from its moral.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

