<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Travis Huff on Medium]]></title>
        <description><![CDATA[Stories by Travis Huff on Medium]]></description>
        <link>https://medium.com/@tron1k?source=rss-6605cb9f4eeb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*7kX4vmGOXoRJuBDJGlTsNQ.jpeg</url>
            <title>Stories by Travis Huff on Medium</title>
            <link>https://medium.com/@tron1k?source=rss-6605cb9f4eeb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 15:24:15 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tron1k/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Real-time Node.js with EventEmitter]]></title>
            <link>https://medium.com/@tron1k/real-time-node-js-with-eventemitter-cbd12caf5afd?source=rss-6605cb9f4eeb------2</link>
            <guid isPermaLink="false">https://medium.com/p/cbd12caf5afd</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[reactive-programming]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Travis Huff]]></dc:creator>
            <pubDate>Thu, 08 Dec 2016 01:11:50 GMT</pubDate>
            <atom:updated>2017-02-17T02:04:32.510Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qSArmtY7vQuQylQxEe6HFg.jpeg" /></figure><p>Given the popularity of modern web apps like Google Docs, Trello, Quora, Twitter and Instagram, users now expect real-time experiences with client interfaces that live in the browser. Frameworks like Angular and React make this possible, as does the simple DOM EventListener:</p><pre>document.querySelector(&#39;.menu-nav&#39;).addEventListener(&#39;click&#39;, someFunction);</pre><p>Likewise on the server, the Node environment makes it possible to react to this real-time stream of events coming in from the front-end (as well as processes running on the back-end) through the use of it’s native EventEmitter:</p><pre>var events = require(&#39;events&#39;);<br>var eventEmitter = new events.EventEmitter();<br><br>var ringBell = function ringBell() {<br>  console.log(&#39;ring ring ring&#39;);<br>}</pre><pre>eventEmitter.on(&#39;doorOpen&#39;, ringBell);<br><br>eventEmitter.emit(&#39;doorOpen&#39;);   // will log &#39;ring ring ring&#39;</pre><p>Much of the core Node.js API is built around this asynchronous, event-driven architecture where certain objects (called “emitters”) emit named events that cause function objects (“listeners”) to be called.</p><p>This is an interesting programming paradigm that flips procedural code on it’s head. With event emitters, functions await event notifications to start running instead of simply running as soon as the previous function finishes.</p><p>Why is this a good thing? For one, it speeds up your app by making these function calls non-blocking; that is, you don’t have to wait for one function to end before the next one can be read and queued up. As soon as the event is heard, the function is put into the event loop where it waits for it’s turn to execute.</p><p>Another important benefit of using this pub/sub design pattern with event emitters and real-time streams is that it makes your code less brittle. That is, the events become the middlemen for the various functions and essentially decouple what would otherwise be tightly bound code. Once functions are listening for events instead of other specific pieces of code, it becomes easier to swap out code and add new code without breaking what is already there.</p><p>It’s easy to turn your Node.js application into a real-time streaming machine with the built-in event emitters and the pub/sub design pattern. Try it out!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cbd12caf5afd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Metaprogramming and the Proxy Object in Javascript]]></title>
            <link>https://medium.com/@tron1k/metaprogramming-and-the-proxy-object-in-javascript-a53639e77b4d?source=rss-6605cb9f4eeb------2</link>
            <guid isPermaLink="false">https://medium.com/p/a53639e77b4d</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[expressjs]]></category>
            <dc:creator><![CDATA[Travis Huff]]></dc:creator>
            <pubDate>Fri, 04 Nov 2016 00:26:37 GMT</pubDate>
            <atom:updated>2019-01-17T16:37:44.953Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D1FxAK-a7RoD6LM8Ueaalw.jpeg" /></figure><p><strong>Metaprogramming</strong> — the art of writing of computer programs with the ability to treat programs as their data. It means that <em>a program could be designed to read, generate, analyze or transform other programs,</em> and even modify itself while running.</p><p>As a software developer, there are times when you wished you knew what was really going on under the hood of your program. Maybe bugs are crashing the party. Maybe results are different than what you would expect. One of the lesser known areas of computer science, termed “metaprogramming”, actually takes on the task of using code to analyze code.</p><blockquote>“using code to analyze code.”</blockquote><p>From MDN: “The <strong>Proxy</strong> object is used to define custom behavior for fundamental operations (e.g. property lookup, assignment, enumeration, function invocation, etc).”</p><pre>var p = new Proxy(target, handler);</pre><p>In Javascript, there’s a new feature in ES6, called the“proxy object” that allows you to hook into your code and log what’s going on under the hood when certain actions take place, like functions being run or variables being get or set.</p><p>To use a proxy, you simply instantiate a new proxy on a target. The target can be an object, a function object, an array or even another proxy. Then you give the proxy a handler, which is an object whose properties are functions which define the behavior of the proxy when an operation is performed on the target.</p><p>For example, I recently worked on a team that forked Express to create a server that tracked all the changes to the request and response objects in a typical http call.</p><pre>req = new Proxy(req, {<br>   set(target, property, value) {<br>     monoStore._temp.changes.req[monoStore._counter][property] = value;<br>     return true;<br>   }<br> });</pre><p>Here, we’re encapsulating the request object in a proxy and logging every time a value is being “set” on it- a typical pattern in the request-response cycle. We save the data being generated to a JSON object which is then delivered to the end user via a RESTful API at a hidden “/debug” path where we can easily see everything that’s happening to the request object.</p><p>I think this is an interesting use of the Javascript proxy, because visualizing how and where the request object gets changed as it goes through the various routes and middleware in Express can be difficult. Is that cookie being set correctly? Is that session being started or destroyed? Is the username being set to the right key? With a proxy set on the request (and response) objects, you can finally see if it is.</p><p>Hopefully this technique can help you discover new insights into your code!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a53639e77b4d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>