<?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>Doctyper &#187; Flow</title>
	<atom:link href="http://doctyper.com/archives/category/flow/feed/" rel="self" type="application/rss+xml" />
	<link>http://doctyper.com</link>
	<description>Doctyper is the website of Richard Herrera, a front-end developer with a strong commitment to the web standards movement.</description>
	<lastBuildDate>Sat, 31 Jul 2010 00:17:23 +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>Flow 1.1</title>
		<link>http://doctyper.com/archives/200906/flow-11/</link>
		<comments>http://doctyper.com/archives/200906/flow-11/#comments</comments>
		<pubDate>Mon, 15 Jun 2009 00:44:24 +0000</pubDate>
		<dc:creator>doctyper</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Flow]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://doctyper.com/?p=47</guid>
		<description><![CDATA[And just like that, a new update. Several small fixes worthy of a point upgrade:

Switched QuerySelector engine to Sizzle 1.0
querySelector/querySelectorAll can now be run on any element (via Selectors API)
IE 8 does not like setAttribute on type elements. Reverting to DOM 1 method.
Fixed minor assertion bug in Require.js

]]></description>
			<content:encoded><![CDATA[<p>And just like that, <a href="http://flowjs.com">a new update</a>. Several small fixes worthy of a point upgrade:</p>
<ul>
<li>Switched QuerySelector engine to <a href="http://sizzlejs.com/">Sizzle 1.0</a></li>
<li id="_mc_tmp">querySelector/querySelectorAll can now be run on any element (via Selectors API)</li>
<li id="_mc_tmp">IE 8 does not like setAttribute on type elements. Reverting to DOM 1 method.</li>
<li id="_mc_tmp">Fixed minor assertion bug in Require.js</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://doctyper.com/archives/200906/flow-11/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flow 1.0.8</title>
		<link>http://doctyper.com/archives/200906/flow-108/</link>
		<comments>http://doctyper.com/archives/200906/flow-108/#comments</comments>
		<pubDate>Sun, 14 Jun 2009 14:44:23 +0000</pubDate>
		<dc:creator>doctyper</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Flow]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://doctyper.com/?p=45</guid>
		<description><![CDATA[A tiny update that fixes IE 8 browser identification. It previously incorrectly identified IE 8 as IE 5.
]]></description>
			<content:encoded><![CDATA[<p>A <a href="http://flowjs.com">tiny update</a> that fixes IE 8 browser identification. It previously incorrectly identified IE 8 as IE 5.</p>
]]></content:encoded>
			<wfw:commentRss>http://doctyper.com/archives/200906/flow-108/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Breaking out of a forEach loop</title>
		<link>http://doctyper.com/archives/200807/breaking-out-of-a-foreach-loop/</link>
		<comments>http://doctyper.com/archives/200807/breaking-out-of-a-foreach-loop/#comments</comments>
		<pubDate>Fri, 25 Jul 2008 00:40:02 +0000</pubDate>
		<dc:creator>doctyper</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Flow]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://doctyper.com/?p=43</guid>
		<description><![CDATA[An email going around the client-side mailing list at Schematic casually mentioned forEach loops. The sender liked them, but tended to avoid them because there was no way to break out of one.
Naturally, this sent me on the hunt to see if it was at all possible. A furious Google search led me to a [...]]]></description>
			<content:encoded><![CDATA[<p>An email going around the client-side mailing list at Schematic casually mentioned forEach loops. The sender liked them, but tended to avoid them because there was no way to break out of one.</p>
<p>Naturally, this sent me on the hunt to see if it was at all possible. A furious Google search led me to a <a href="http://dean.edwards.name/weblog/2006/07/enum/#comment104722">comment by Dean Edwards</a> (who else?). He suggested throwing yourself out of the loop and wrapping the throw in a try catch statement to silence the throw. Like so:</p>
<p><code>var array = [1, 2, 0, 3, 4, 5];<br />
try {<br />
&nbsp;&nbsp;array.forEach(function(item) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;if (item === 0) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw new Error(); // Simulated break<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;console.log(item);<br />
&nbsp;&nbsp;});<br />
} catch (e) {}</code></p>
<p><a href="http://doctyper.com/stuff/flow/forEach/test-1.html">That does the trick.</a> Fellow developer/comrade <a title="Don't mind the light!" href="http://rule52.com/">Lenny Burdette</a> pointed out that this was exactly the method <a href="http://github.com/sstephenson/prototype/tree/master/src/enumerable.js#L1">Prototype uses</a> to break their own custom loops.</p>
<p>But of course, there&#8217;s caveats. With Prototype, you merely have to call <em>$break</em> to have it automate this for you. With Flow, you&#8217;re exposed to the elements and need to handle it yourself. It&#8217;s a neat trick, but quite honestly it&#8217;s not very user friendly, and looks a bit unwieldy as a workaround.</p>
<p>I browsed the forEach documentation and went through possible solutions. One was to extend forEach and include a custom break function in it. But I decided against this for a few reasons. One, it would violate the <a href="http://dean.edwards.name/weblog/2007/03/rules/">rules</a> (#3, to be exact). Over-extending a native function would bring more hurt than it would good. Second, Safari 2 has a problem with extending forEach, so it wasn&#8217;t a viable solution either.</p>
<p>But I had a hunch. What if I simulated a break by splicing off the remaining objects in the array, thereby terminating the loop entirely? I gave it a try:</p>
<p><code>var array = [1, 2, 0, 3, 4, 5];<br />
array.forEach(function(item, i) {<br />
&nbsp;&nbsp;if (item === 0) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;array.splice(i, array.length - i); // Simulated break<br />
&nbsp;&nbsp;} else {<br />
&nbsp;&nbsp;&nbsp;&nbsp;console.log(item);<br />
&nbsp;&nbsp;}<br />
});</code></p>
<p><a href="http://doctyper.com/stuff/flow/forEach/test-2.html">Success!</a> The loop terminates, because there are no more objects to continue to. There&#8217;s just one problem: there are no more objects to continue to. It mutates the array, so it&#8217;s not reliable if you need to reuse the array. You&#8217;re limited to using it only once, or having to rebuild the array.</p>
<p>Ah, but what if you splice the array, and immediately concatenate it? Would it have the same effect and stop the array in its tracks?</p>
<p><code>var array = [1, 2, 0, 3, 4, 5];<br />
array.forEach(function(item, i) {<br />
&nbsp;&nbsp;if (item === 0) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;array = array.concat(array.splice(i, array.length - i)); // F-f-f-forEach breaker!<br />
&nbsp;&nbsp;} else {<br />
&nbsp;&nbsp;&nbsp;&nbsp;console.log(item);<br />
&nbsp;&nbsp;}<br />
});</code></p>
<p><a href="http://doctyper.com/stuff/flow/forEach/test-3.html">Double success!</a> In this example, the array is spliced from the current index point, and all remaining objects are dropped off, ending the loop. The magic happens when we rejoin the array using concat, and reassign the newly constructed object to the array variable. The array is mutated back to its original form, and you&#8217;ve broken the forEach loop.</p>
<p>Still, it&#8217;s not as satisfyingly simple as a break, is it? Well, we can&#8217;t call a break, but we can get close. The next Flow revision will contain the <em>exit</em> Array extra, which will provide you with a keyword (or, as close enough a keyword as I could get) to break a forEach loop:</p>
<p><code>var array = [1, 2, 0, 3, 4, 5];<br />
array.forEach(function(item, i) {<br />
&nbsp;&nbsp;if (item === 0) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;array = array.exit(i);<br />
&nbsp;&nbsp;} else {<br />
&nbsp;&nbsp;&nbsp;&nbsp;console.log(item);<br />
&nbsp;&nbsp;}<br />
});</code></p>
]]></content:encoded>
			<wfw:commentRss>http://doctyper.com/archives/200807/breaking-out-of-a-foreach-loop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flow 1.0.2</title>
		<link>http://doctyper.com/archives/200807/flow-102/</link>
		<comments>http://doctyper.com/archives/200807/flow-102/#comments</comments>
		<pubDate>Wed, 16 Jul 2008 19:19:52 +0000</pubDate>
		<dc:creator>doctyper</dc:creator>
				<category><![CDATA[(X)HTML]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Flow]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://doctyper.com/?p=41</guid>
		<description><![CDATA[I just pushed release 1.0.2 out the door.
Bug fix:
Flow will no longer choke with SWFObject.
Early this morning I received a report about Flow not playing nicely with SWFObject. After debugging, it turned out it was a case of doing too much.
SWFObject correctly cleans up after itself in IE by removing its generated code on unload. [...]]]></description>
			<content:encoded><![CDATA[<p>I just pushed release 1.0.2 out the door.</p>
<h4>Bug fix:</h4>
<p>Flow will no longer choke with SWFObject.</p>
<p>Early this morning I received a report about Flow not playing nicely with SWFObject. After debugging, it turned out it was a case of doing too much.</p>
<p>SWFObject correctly cleans up after itself in IE by removing its generated code on unload. The conflict appears because Flow does the same with its code, going as far as eliminating all extended element properties.</p>
<p>So when SWFObject tried to removeChild, it returned null because Flow extends that property, and by the time SWFObject got to it, it was already wiped out.</p>
<p>Flow now merely restores an extended property back to its original implementation, rather than nullifying the property. This will fix the error.</p>
<h4>Feature:</h4>
<p>dispatchEvent is now implemented in Flow. You can use it to fire events on elements from another element. Confusing? Here&#8217;s an example:</p>
<p><code>var test = document.getById(&quot;test&quot;);<br />
test.addEventListener(&quot;click&quot;, function() {<br />
&nbsp;&nbsp;&nbsp;&nbsp;// console.log(this.id);<br />
}, false);<br />
&nbsp;<br />
document.getById(&quot;dispatcher&quot;).addEventListener(&quot;click&quot;, function() {<br />
&nbsp;&nbsp;&nbsp;&nbsp;test.dispatchEvent(&quot;click&quot;);<br />
}, false);</code></p>
<p>You can pass any event type and it will fire all events coupled with that type.</p>
<p>As usual, you can download the Flow framework at <a href="http://flowjs.com">http://flowjs.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://doctyper.com/archives/200807/flow-102/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
