<?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"
	>
<channel>
	<title>Comments on: Separating event handling from event filtering</title>
	<atom:link href="http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/</link>
	<description></description>
	<pubDate>Fri, 21 Nov 2008 13:09:43 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
		<item>
		<title>By: Eric Greveson</title>
		<link>http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/#comment-7530</link>
		<dc:creator>Eric Greveson</dc:creator>
		<pubDate>Wed, 03 Sep 2008 21:30:11 +0000</pubDate>
		<guid isPermaLink="false">http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/#comment-7530</guid>
		<description>&lt;p&gt;I like the guard function method over the key mapper method (which I've been using up to now), it's more flexible and reminds me that I should be making use of first-class functions (I'm from a C++ background so I keep forgetting about them)! I'd like to see your higher order functions library being released too - simple, lightweight libraries that really improve the way people code are something that's mostly missing from the Flex community at the moment (although I've been trying Mate recently, after your recommendation, and it's pretty cool).&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I like the guard function method over the key mapper method (which I&#8217;ve been using up to now), it&#8217;s more flexible and reminds me that I should be making use of first-class functions (I&#8217;m from a C++ background so I keep forgetting about them)! I&#8217;d like to see your higher order functions library being released too - simple, lightweight libraries that really improve the way people code are something that&#8217;s mostly missing from the Flex community at the moment (although I&#8217;ve been trying Mate recently, after your recommendation, and it&#8217;s pretty cool).</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Tom Carden</title>
		<link>http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/#comment-7262</link>
		<dc:creator>Tom Carden</dc:creator>
		<pubDate>Fri, 15 Aug 2008 06:03:36 +0000</pubDate>
		<guid isPermaLink="false">http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/#comment-7262</guid>
		<description>&lt;p&gt;It took me a couple of attempts to fully understand the appeal of this approach, but I like it very much.  It feels somehow "well rounded" :)&lt;/p&gt;

&lt;p&gt;If you're still leaning towards releasing your higher order functions library, I'd gladly contribute time to helping with documentation or testing.  I have some array filtering classes of my own that might fit with such a library, too.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>It took me a couple of attempts to fully understand the appeal of this approach, but I like it very much.  It feels somehow &#8220;well rounded&#8221; :)</p>

<p>If you&#8217;re still leaning towards releasing your higher order functions library, I&#8217;d gladly contribute time to helping with documentation or testing.  I have some array filtering classes of my own that might fit with such a library, too.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Marcus Stade</title>
		<link>http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/#comment-6971</link>
		<dc:creator>Marcus Stade</dc:creator>
		<pubDate>Sat, 05 Jul 2008 17:00:05 +0000</pubDate>
		<guid isPermaLink="false">http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/#comment-6971</guid>
		<description>&lt;p&gt;I LOVE this concept, thank you very much for sharing! Great blog btw, just stumbled upon it.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I LOVE this concept, thank you very much for sharing! Great blog btw, just stumbled upon it.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Joshua E Cook</title>
		<link>http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/#comment-6735</link>
		<dc:creator>Joshua E Cook</dc:creator>
		<pubDate>Fri, 16 May 2008 13:58:27 +0000</pubDate>
		<guid isPermaLink="false">http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/#comment-6735</guid>
		<description>&lt;p&gt;Stephan, although your KeyMapper works elegantly for associating an action with a particular keycode, the guarding method is more flexible.  Consider if you wanted to associate a different action for a keycode when the SHIFT or CTRL keys are held down.  This would require significant changes to your KeyMapper class, but only a simple change to the guard function is required.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Stephan, although your KeyMapper works elegantly for associating an action with a particular keycode, the guarding method is more flexible.  Consider if you wanted to associate a different action for a keycode when the SHIFT or CTRL keys are held down.  This would require significant changes to your KeyMapper class, but only a simple change to the guard function is required.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Bjorn Schultheiss</title>
		<link>http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/#comment-6208</link>
		<dc:creator>Bjorn Schultheiss</dc:creator>
		<pubDate>Sun, 13 Apr 2008 13:45:30 +0000</pubDate>
		<guid isPermaLink="false">http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/#comment-6208</guid>
		<description>&lt;p&gt;The only time this seems useful is if your repeating the same 'if statement' in multiple methods, otherwise you've simply wrapped the if statement in another function...&lt;/p&gt;

&lt;p&gt;I was interested to see how you were going to modify
sendButton.addEventListener(MouseEvent.CLICK, onSendButtonClicked);&lt;/p&gt;

&lt;p&gt;but later you replaced it with
sendButton.addEventListener(MouseEvent.CLICK, onSendForm);&lt;/p&gt;

&lt;p&gt;ahh well.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>The only time this seems useful is if your repeating the same &#8216;if statement&#8217; in multiple methods, otherwise you&#8217;ve simply wrapped the if statement in another function&#8230;</p>

<p>I was interested to see how you were going to modify
sendButton.addEventListener(MouseEvent.CLICK, onSendButtonClicked);</p>

<p>but later you replaced it with
sendButton.addEventListener(MouseEvent.CLICK, onSendForm);</p>

<p>ahh well.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Functional ActionScript &#8211; Part III &#8212; RTFM / Daniel Gasienica</title>
		<link>http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/#comment-5889</link>
		<dc:creator>Functional ActionScript &#8211; Part III &#8212; RTFM / Daniel Gasienica</dc:creator>
		<pubDate>Wed, 02 Apr 2008 01:03:59 +0000</pubDate>
		<guid isPermaLink="false">http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/#comment-5889</guid>
		<description>&lt;p&gt;[...] Iconara: Separating event handling from event filtering [...]&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>[...] Iconara: Separating event handling from event filtering [...]</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Theo</title>
		<link>http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/#comment-5831</link>
		<dc:creator>Theo</dc:creator>
		<pubDate>Mon, 31 Mar 2008 11:44:53 +0000</pubDate>
		<guid isPermaLink="false">http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/#comment-5831</guid>
		<description>&lt;p&gt;Stephan: yes, I agree, your solution is quite elegant. I have nothing against the if-statement in your handleKeyEvent, it is not of the kind that makes code fragile.&lt;/p&gt;

&lt;p&gt;guards are very general and there are absolutely better ways to solve specific cases.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Stephan: yes, I agree, your solution is quite elegant. I have nothing against the if-statement in your handleKeyEvent, it is not of the kind that makes code fragile.</p>

<p>guards are very general and there are absolutely better ways to solve specific cases.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Stephan Bezoen</title>
		<link>http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/#comment-5830</link>
		<dc:creator>Stephan Bezoen</dc:creator>
		<pubDate>Mon, 31 Mar 2008 11:37:59 +0000</pubDate>
		<guid isPermaLink="false">http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/#comment-5830</guid>
		<description>&lt;p&gt;Hi Theo,&lt;/p&gt;

&lt;p&gt;I agree that filtering events is a pain in the butt. However in this particular case (handling keyboard events), a map approach seems to me a lot more concise (and thereby more elegant :D). 
Now let's see if the comment system allows me to submit code in a legible way. For testing, I wrote this little class called KeyMapper:
&lt;code&gt;
/**
 * @author stephan.bezoen
 */
public class KeyMapper {
    private var mMap : Object = new Object();
    private var mStage : Stage;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;public function KeyMapper (inStage:Stage) {
    mStage = inStage;
     mStage.addEventListener(KeyboardEvent.KEY_UP, handleKeyEvent);
}

public function setMapping (inKey:uint, inHandler:Function) : void {
    mMap[inKey] = inHandler;
}

public function die () : void {
    mMap = null;
    mStage.removeEventListener(KeyboardEvent.KEY_UP, handleKeyEvent);
}

private function handleKeyEvent(e : KeyboardEvent) : void {
    if (mMap[e.keyCode]) mMap[e.keyCode]();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;}
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;As you can see in the KeyMapper.handleKeyEvent() function, the only comparison that is still needed, is to check whether a mapping is defined for the pressed key.&lt;/p&gt;

&lt;p&gt;To use this in an application, do the following:
&lt;code&gt;
var km : KeyMapper = new KeyMapper(stage);
km.setMapping(Keyboard.ENTER, submit);
km.setMapping(Keyboard.ESCAPE, cancel);
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In my view, this approach really takes away the inner workings of the keyboard event system from the user. It's easily readable, and very easy to extend when more keys have to be handled.&lt;/p&gt;

&lt;p&gt;As for multiple asynchronous events, that is a place where guards could very well come in handy. Just have to get used to the term I guess :D&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Hi Theo,</p>

<p>I agree that filtering events is a pain in the butt. However in this particular case (handling keyboard events), a map approach seems to me a lot more concise (and thereby more elegant :D). 
Now let&#8217;s see if the comment system allows me to submit code in a legible way. For testing, I wrote this little class called KeyMapper:
<code>
/**
 * @author stephan.bezoen
 */
public class KeyMapper {
    private var mMap : Object = new Object();
    private var mStage : Stage;</code></p>

<pre><code>public function KeyMapper (inStage:Stage) {
    mStage = inStage;
     mStage.addEventListener(KeyboardEvent.KEY_UP, handleKeyEvent);
}

public function setMapping (inKey:uint, inHandler:Function) : void {
    mMap[inKey] = inHandler;
}

public function die () : void {
    mMap = null;
    mStage.removeEventListener(KeyboardEvent.KEY_UP, handleKeyEvent);
}

private function handleKeyEvent(e : KeyboardEvent) : void {
    if (mMap[e.keyCode]) mMap[e.keyCode]();
}
</code></pre>

<p>}
</p>

<p>As you can see in the KeyMapper.handleKeyEvent() function, the only comparison that is still needed, is to check whether a mapping is defined for the pressed key.</p>

<p>To use this in an application, do the following:
<code>
var km : KeyMapper = new KeyMapper(stage);
km.setMapping(Keyboard.ENTER, submit);
km.setMapping(Keyboard.ESCAPE, cancel);
</code></p>

<p>In my view, this approach really takes away the inner workings of the keyboard event system from the user. It&#8217;s easily readable, and very easy to extend when more keys have to be handled.</p>

<p>As for multiple asynchronous events, that is a place where guards could very well come in handy. Just have to get used to the term I guess :D</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Theo</title>
		<link>http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/#comment-5822</link>
		<dc:creator>Theo</dc:creator>
		<pubDate>Mon, 31 Mar 2008 06:15:34 +0000</pubDate>
		<guid isPermaLink="false">http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/#comment-5822</guid>
		<description>&lt;p&gt;Daniel: I have worked with Haskell in some computer science courses (I studied software engineering), but I never got very deep into it. The concept of guards more or less came to me when thinking about my ugly event handlers.&lt;/p&gt;

&lt;p&gt;Ruben: Seems like I have to show you my Trampoline some day, it's your ArrayTool on speed =)&lt;/p&gt;

&lt;p&gt;It's nice to see that there are others that are interested in higher order functions and functional programming in ActionScript. If you look at my blog archive I think there are one or two old posts about how to do away with loops by using functional programming concepts.&lt;/p&gt;

&lt;p&gt;I have a small library that I use privately which contains implementations of useful higher order functions and functional programming concepts, one day I'm going to get around to writing about them too.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Daniel: I have worked with Haskell in some computer science courses (I studied software engineering), but I never got very deep into it. The concept of guards more or less came to me when thinking about my ugly event handlers.</p>

<p>Ruben: Seems like I have to show you my Trampoline some day, it&#8217;s your ArrayTool on speed =)</p>

<p>It&#8217;s nice to see that there are others that are interested in higher order functions and functional programming in ActionScript. If you look at my blog archive I think there are one or two old posts about how to do away with loops by using functional programming concepts.</p>

<p>I have a small library that I use privately which contains implementations of useful higher order functions and functional programming concepts, one day I&#8217;m going to get around to writing about them too.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: jimmy fung</title>
		<link>http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/#comment-5821</link>
		<dc:creator>jimmy fung</dc:creator>
		<pubDate>Mon, 31 Mar 2008 00:40:39 +0000</pubDate>
		<guid isPermaLink="false">http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/#comment-5821</guid>
		<description>&lt;p&gt;very nice post. thanks for sharing.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>very nice post. thanks for sharing.</p>]]></content:encoded>
	</item>
</channel>
</rss>
