<?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[Parsable Blog - Medium]]></title>
        <description><![CDATA[Jobs done right, every time - Medium]]></description>
        <link>https://medium.com/parsable-blog?source=rss----8f8fb474314f---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Parsable Blog - Medium</title>
            <link>https://medium.com/parsable-blog?source=rss----8f8fb474314f---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 01:39:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/parsable-blog" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[React Full Stack Tests with Nightwatch]]></title>
            <link>https://medium.com/parsable-blog/react-full-stack-tests-and-continuous-delivery-part-1-4-nightwatch-c378b6fbac8a?source=rss----8f8fb474314f---4</link>
            <guid isPermaLink="false">https://medium.com/p/c378b6fbac8a</guid>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Adam Neary]]></dc:creator>
            <pubDate>Tue, 22 Mar 2016 15:50:41 GMT</pubDate>
            <atom:updated>2016-04-19T19:29:07.380Z</atom:updated>
            <content:encoded><![CDATA[<p>Plenty of great ink has been spilled over unit testing React components and Redux reducers et al, but we had a lot of difficulty finding meaty posts about settings up proper full-stack integration tests for the modern JS stack.</p><p>This is article 1 in a 4-part series:</p><ul><li><strong>Nightwatch</strong> and API Calls for Clean, Tight, Isolated Full Stack Tests</li><li><a href="https://medium.com/@AdamRNeary/react-full-stack-tests-and-continuous-delivery-part-3-4-gulp-aws-and-terraform-5c6bf88a26e5"><strong>Gulp, AWS, and Terraform </strong>for Effortless Continuous Delivery</a></li><li><a href="https://medium.com/@AdamRNeary/react-full-stack-test-automation-with-saucelabs-and-circle-ci-40e819581818#.b29dhg7yc"><strong>Circle CI</strong> and <strong>Saucelabs</strong> to Automate All the Things</a></li></ul><p>Our setup was particularly tricky because we have a handful of fully decoupled backend services and two React apps sharing a lot of code. If you’re going down a similar road, hopefully this series saves you a couple steps.</p><h3><strong>Nightwatch</strong> and API Calls for Clean, Tight, Isolated Full Stack Tests</h3><p>The goal is to write a set of tests that actually pressure test how the front end apps and back end services work together. More, since we have users around the world using Chrome, Firefox, and IE on Windows and Mac, we want to be certain we don’t break on any combination of browser, OS, and screen size we commit to supporting.</p><p>Here’s a debug preview of what we execute via CI every push to Github, every branch:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F7Nyv1IOzR7A9a%2Ftwitter%2Fiframe&amp;src_secure=1&amp;url=http%3A%2F%2Fgiphy.com%2Fgifs%2F7Nyv1IOzR7A9a&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F7Nyv1IOzR7A9a%2Fgiphy.gif&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/ff5d9259f4991f565954020a9585104e/href">https://medium.com/media/ff5d9259f4991f565954020a9585104e/href</a></iframe><p><em>Critical note: </em>The above tests are running without mocks. All backend services are available for these tests.</p><p><strong>Trap A: </strong>I have often seen full stack “smoke tests” written for Phantom or Selenium wrappers that run a long chain of commands in series, each building on the previous, logging in and then stepping through the scope of an application’s features to make sure everything works. Every time you need to change or add something, it breaks something downstream. No thanks.</p><p><strong>Trap B:</strong> Similarly, I have seen engineers build macros of sorts that perform common actions, and these actions are then performed repeatedly in the browser to create common states. Effective but slow, particularly if those steps involve a lot of UI.</p><p>This time around, we avoided both problems by leaning on API utilities to set up tests precisely as we need them:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/88334def380f8c368d106f936aa09a39/href">https://medium.com/media/88334def380f8c368d106f936aa09a39/href</a></iframe><p>There are a couple useful tricks buried in these initial Promises. <em>helpers.createTeam</em> uses our API to create a new team and user (hat tip to <a href="http://marak.com/faker.js/">faker.js</a>), then uses the generated credentials both to login with Nightwatch…</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/32256f6d78522b929727a35719bd75d5/href">https://medium.com/media/32256f6d78522b929727a35719bd75d5/href</a></iframe><p>…and then separately to retrieve an API token it can use for subsequent requests:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf36d4d8d494b60c0a29054870207281/href">https://medium.com/media/cf36d4d8d494b60c0a29054870207281/href</a></iframe><p>The simple <em>assign() </em>function stores away the returned objects for subsequent use.</p><p>This means that <em>for each and every block of tests</em>, we create a new team and user, as well as all of the data objects we will need for the tests. Seems excessive except that we now have automated tests we can be confident are isolated…and this also means they can be run in <strong>parallel</strong>. More on that to come.</p><h4>Aligning Nightwatch Page Objects with React Router</h4><p>Nightwatch <a href="http://nightwatchjs.org/guide#page-objects">Page Objects</a> implement an idea Martin Fowler proposed <a href="http://martinfowler.com/bliki/PageObject.html">here</a>, that you can separate the code that hooks into a given page from the tests that verify its functionality.</p><p>We have found this to be huge for test code reuse, and it helps us think logically about functionality we are building, particularly for non-trivial features.</p><p>The benefit is particularly apparent when reviewing a heavier pull request. With a glance, it is quite clear what’s going on:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fca2976680bfe1cc200b673f5012f550/href">https://medium.com/media/fca2976680bfe1cc200b673f5012f550/href</a></iframe><p>Then you can view the page object for a sense of how we use UI to achieve what the tests are asking for:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8213f5397838447d6ce36df6aa14bb9c/href">https://medium.com/media/8213f5397838447d6ce36df6aa14bb9c/href</a></iframe><p>You may notice that to archive a template requires accepting a <a href="http://t4t5.github.io/sweetalert/">SweetAlert</a> confirmation dialog. We have concepts such as modals and sweetalert captured as their own Nigthwatch page objects, so accounting for this step is trivial, and since it built into the command on the page object, the test doesn’t need to know that a confirmation is required.</p><p>Once finished reviewing the tests and page objects, it’s a small jump to view the React components that implement the page object and the Redux/Thrift machinery that handle what the React components need. If you have ever had your eyes blur trying to consume a larger PR, believe me this is an incredible step forward.</p><p>Since React Router gives us such a clean view into our site map, we can ensure that the page objects remain in sync with our routes for both apps, and we are good to go.</p><h4>Upgrade Nightwatch with Power Tools like Drag-and-Drop</h4><p><a href="http://nightwatchjs.org/">NightwatchJS</a> is a Selenium wrapper that provides out of the box most of the UI navigation functionality we need. But they also allow you to inject scripts to level up your testing capabilities.</p><p>In our app, we make extensive use of Dan Abramov’s fabulous <a href="https://github.com/gaearon/react-dnd">React DnD</a> library. To test it, <a href="https://twitter.com/@aarongloege">Aaron</a> set up a Nightwatch command that wraps Andy Wermke’s <a href="https://github.com/andywer/drag-mock">Drag Mock</a> thusly:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/04a71c3ff67bfb89410e17944deea4b2/href">https://medium.com/media/04a71c3ff67bfb89410e17944deea4b2/href</a></iframe><p>This allows us to include drag actions on page objects:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aa50b9db81a00c9ca7a99a3f1ad7a241/href">https://medium.com/media/aa50b9db81a00c9ca7a99a3f1ad7a241/href</a></iframe><p>Which gives us a simple and semantic way to define drag behaviors in tests:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/db611ece5f75e732135f7b0be75ece67/href">https://medium.com/media/db611ece5f75e732135f7b0be75ece67/href</a></iframe><p>Just like using JSX has opened the door to our designers submitting more design PRs, these testing techniques allow us to tag in pretty junior QA automation engineers to help write high quality tests for us, and manual QA testers on the team can identify faulty interpretation of requirements early in the process. Everyone wins.</p><h4>The Role of Full Stack Integration Tests</h4><p>Mind you, none of these techniques obviate the need for solid units. We use Mocha to test Redux reducers/actions/etc., and we use Enzyme to test React components in isolation. We also fail a test run if the source doesn’t pass ESLint.</p><p>But I place far more value in these full stack tests, because they confirm for us that when you take the mocks away and plug in all the backend services, we still have all the functionality we promise our users, and not just in Chrome on a Cinema Display in Soma, but in the wild on a busted Vista laptop running IE11 on an oil rig. That’s where our software needs to deliver, and Nightwatch helps give us confidence that we are there.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c378b6fbac8a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/parsable-blog/react-full-stack-tests-and-continuous-delivery-part-1-4-nightwatch-c378b6fbac8a">React Full Stack Tests with Nightwatch</a> was originally published in <a href="https://medium.com/parsable-blog">Parsable Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How (and Why) To Write an Awesome Commit Message (or PR)]]></title>
            <link>https://medium.com/parsable-blog/how-and-why-to-write-an-awesome-commit-message-or-pr-39834622b7d9?source=rss----8f8fb474314f---4</link>
            <guid isPermaLink="false">https://medium.com/p/39834622b7d9</guid>
            <category><![CDATA[github]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Sam Vilain]]></dc:creator>
            <pubDate>Wed, 02 Mar 2016 22:15:16 GMT</pubDate>
            <atom:updated>2016-07-18T17:48:38.198Z</atom:updated>
            <content:encoded><![CDATA[<p>Writing a good commit message is a great way to capture the logic that’s going into your work as you work. Sometimes this might seem like unnecessary work, because the person who is reviewing your code already knows the reasons why you’re doing what you’re doing. Perhaps you’re the only one working on the code base. So you just write something very short instead of a good commit message. Who cares? Think about all of these people:</p><ul><li><strong>Someone on your team</strong> <strong>you <em>didn’t</em> expect</strong> <strong>to review your work</strong> has some free cycles, but looks at it, doesn’t understand what is going on or why and doesn’t review your work. You just missed the chance to get additional hands on deck!</li><li><strong>Someone on another team</strong> is trying to read and understand what you’re doing to gain a new skill. You could have passively coached them and grown your team!</li><li><strong>Someone later, perhaps a new hire</strong>, is looking back at the code to try and understand <em>why</em> something is the way it is. They have to figure it out without the benefit of all of the real-life meetings you had about it. Without having read all the requirements documents and tech specs. They might make some wrong assumptions, and break something important you worked on because they didn’t understand the code, changing the tests you wrote, too. Perhaps they’re not as clever as you and can’t see what you see as obvious. You might not still be working here by then, but perhaps you’ve exercised your shares — therefore <strong>you</strong> still have an interest that the time and energy you’ve put in to solving the problem becomes part of the <em>institutional knowledge</em> of the company, and doesn’t leave with you. Don’t let those late stage hires ruin your chances of reaping the rewards of your hard work!</li><li><strong>You in the long-term future</strong> are debugging your code and you hit a code branch you wrote and forgot why it was there. You missed the chance to remind yourself instantly with a quick git blame of all of the things that were going through your head when you wrote that code. You would be surprised at how quickly you can forget.</li><li><strong>You in the near-term future</strong> are working on something not so straightforward, and so you are simply trying to formulate a working theory of what you are trying to do. So, you can write down your own reasoning and then later, through techniques like rebasing or patch stack systems like stacked git, either disprove your earlier theory or support it. This way, you can make your own changes smaller and easier for your team to review.<em> (clearly, for this point to apply, you need to apply this to every change, and not just do it on the PR, as well as be very good with a tool like stacked git).</em></li><li><strong>The upstream maintainer</strong> of the code you just patches might have no idea of the unique problems you’re experiencing. They didn’t have those problems, and so they might reject your change, forcing your fork into exile from the main branch, a maintenance burden that might impact the stock payout, too!</li></ul><p>The key thing to note is that it isn’t just for others — it’s for yourself. Think of how much faster you can move, with the cognitive burden of remembering everything removed! Don’t think of the short moments you have following the below steps as an impediment. Use them as an opportunity to truly master the Zen of programming. Taking a brief moment to focus on your breathing and clear your mind of any irrelevant distractions of the ego are recommended, but not required.</p><h4>The Questions Every Commit Message (or PR Cover) Should Answer—or — a Checklist For Every Commit Message</h4><ol><li><strong>What problem or scenario is this change solving?</strong> — stand back. Describe the problem the the change addresses, or the sequence of events that lead to the problem. It might seem obvious now, but trust me — this is the most frequent source of “wha…?” moments when maintaining code. <strong>State the obvious</strong> — don’t let you or others lose sight of the <strong>why</strong>. At the very minimum, including a reference to your JIRA or whatever can help people resume context, but just putting a ticket ID in is bare compliance, and not Zen mastery.</li><li><strong>What was wrong with the old code?</strong> — it can often help to explain how the code prior to your change didn’t work. Where did it go wrong? Did you already figure out a failed assumption of another commit? Mention the commit ID and what the other commit got wrong!</li><li><strong>What is your approach to solve the problem, tactically?</strong> I don’t mean to describe what your change does. I can read that from the actual diff. That’s not interesting. If you have a <em>higher level description</em> of your change, such as the name of an algorithm, or an entertaining analogy, write it in! Another super useful thing to know is that if there is another approach to solve the problem which you considered, but decided not to do or figured out couldn’t work, say why that approach was inappropriate.</li><li><strong>A subject: can you summarize it in plain English in 10 words or less?</strong> a lot of git tooling is geared towards the practices of the core git and linux community, and they have a limit of 55 or 60 characters or something like that. Try to look back at your commit message, and then explain it to somebody non-technical in a few words. Your experience with git, and especially things like rebasing and cherry picking, will be improved by this practice. Use the imperative mood (“Make X do Y”) and not progressive (“Making X do Y”) or past tense (“Made X do Y”). (<strong>Update</strong>: an easier way to express this is to make the statement complete the sentence, “Once merged, this commit will…”) I would recommend not including things like function names, classes, and to limit use of acronyms and jargon in the subject. Try to spell out any abbreviations in full in the commit message body if you put them in the subject. The biggest exception to this is one word before a colon; if the codebase is modular, and your change affects just one module or component, then feel free to include that at the start of the subject line with a colon.</li></ol><p>If, after doing this, the change message seems boring, obvious or droll, don’t worry about it and just commit it. Sometimes the changes themselves are like that. With the detail written down, <strong>you are now free to forget</strong> its inanity. Banish it from your mind and think about more exciting things!</p><h4>Skipping Questions</h4><p>As you get better at running through this list, you will find that in particular steps 2 and 3 don’t apply to many changes: for example, when adding new functionality, you can typically imply that the problem with the old code was that it didn’t exist by using a verb like “Add” or “Implement” in the subject. Not all changes are significant enough to need a tactical summary. Sometimes the problem can even be described in the subject. But be careful here: err on the side of quickly writing information you think is not required, because it doesn’t take long, whereas the head scratching which can occur without that “obvious” information can take hours or even longer.</p><h4>Use the Right Tool</h4><p><strong>Use a tool like GitX or git gui to make commits</strong> — both of these will help you keep your commit messages well formed, and help you pick out related changes into a patch series from that working tree you got working by making dozens of iterative changes. Explain each part of it. You’ll be surprised at the bugs you shake out before they make it out to the wild! Make sure you know how to use the ‘-p’ flag to git add, the dynamic duo of the ‘ — fixup’ flag to ‘git commit’ and the ‘— autosquash’ flag to ‘git rebase -i’ — and don’t be afraid to force push to your PR branch.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=39834622b7d9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/parsable-blog/how-and-why-to-write-an-awesome-commit-message-or-pr-39834622b7d9">How (and Why) To Write an Awesome Commit Message (or PR)</a> was originally published in <a href="https://medium.com/parsable-blog">Parsable Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Human Readable JSON Endpoints with Thrift (for Free)]]></title>
            <link>https://medium.com/parsable-blog/using-human-readable-json-endpoints-with-thrift-for-free-774ba505c893?source=rss----8f8fb474314f---4</link>
            <guid isPermaLink="false">https://medium.com/p/774ba505c893</guid>
            <category><![CDATA[thrift]]></category>
            <category><![CDATA[json]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Devansh Gupta]]></dc:creator>
            <pubDate>Tue, 20 Oct 2015 17:38:35 GMT</pubDate>
            <atom:updated>2015-10-23T07:26:24.731Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Shameless plug: I work at WI (</em><a href="http://wi.co/"><em>http://wi.co/</em></a><em>). We are changing the way people outside Silicon Valley work. If you are interested have a look at our careers page (</em><a href="http://wi.co/careers"><em>http://wi.co/careers</em></a><em>) or send me an email at </em><a href="/service/mailto:devansh@wi.co"><em>devansh@wi.co</em></a></p><p><strong>About Thrift: </strong>If you are not familiar with RPC or Thrift you might want to have a look at <a href="https://thrift.apache.org/">https://thrift.apache.org/</a></p><p>So, one problem I have heard is, “Hey, so we are publishing our Thrift APIs to third party vendors, and we need it to be easy to use.” Now, you either:</p><ol><li>Expose the Thrift endpoints and coach your API consumers on Thrift and help them debug any issues.</li><li>You maintain a library that is wrapper around the different Thrift services for each language/platform you want to support.</li><li>Create a way to manually convert between <strong><em>human readable JSON </em></strong>to<strong><em> </em></strong>Thrift and vice versa, and maintain it for every single struct, service &amp; function.</li></ol><p>If these options sound unappealing to you, you’re right — they can be a lot of work. But is there another way?</p><p>I will be using the following simple Thrift file in my article below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f598e4b6260078a92193a1a82c24cfc3/href">https://medium.com/media/f598e4b6260078a92193a1a82c24cfc3/href</a></iframe><p>Now, Thrift does support a <strong><em>JSONProtocol</em></strong> which transmits data as JSON between the client and server (this is what we use for our web front end). However, one look at the data being sent will tell you it’s not going to be possible to expose this to third parties:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9ad62d8c2677715d42f771eae1b1631c/href">https://medium.com/media/9ad62d8c2677715d42f771eae1b1631c/href</a></iframe><p>And this is for a <em>very simple </em>call:<strong> login(email, password)</strong>.</p><p>The Thrift JSON has a whole bunch of jargon it uses to parse out the exact call like the types of each argument/field, the length of arrays/sets, the <em>key number </em>of each field in a struct, etc.</p><p>So we came up with a way to convert human readable JSON to Thrift without:</p><ol><li>Adding a whole bunch of jargon</li><li>Doing any maintenance. Any changes to the Thrift definitions should automatically be usable.</li></ol><p>An example of the same call using the new way:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f405305ff161fbd49ac60c7aaf6f0f12/href">https://medium.com/media/f405305ff161fbd49ac60c7aaf6f0f12/href</a></iframe><p>Much more readable!</p><blockquote>The format is simple. The method key’s values should be the exact name of the method in the Thrift definition. The arguments object is the list of arguments. The keys inside the arguments object are again the same as the name of the function parameters in the Thrift definition.</blockquote><p>Here is a sample response:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/64c23a218d24fb056718156c33b6e1de/href">https://medium.com/media/64c23a218d24fb056718156c33b6e1de/href</a></iframe><p>An example of an API defined Exception which was thrown:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5ae76cd27f7ad0acfd2625ca7dad4953/href">https://medium.com/media/5ae76cd27f7ad0acfd2625ca7dad4953/href</a></iframe><blockquote>Note, it can easily handle Structs (and structs embedded inside structs) too. Above <em>currentUser </em>is a struct. In JSON it is simply a JSON object whose keys are the same as the field names inside the Thrift Struct definition.</blockquote><p>Also, above <strong>err</strong> (the exception) is also a Struct since in Thrift exceptions are simply special kind of structs.</p><p>Furthermore, note that the success object itself is a struct. Its is an auto generated struct whose name is usually <em>&lt;MethodName&gt;_result</em> (in this case <em>login_result</em>). You can see it if you ever peek into the generated code for any other language. It has two fields: <strong>result</strong> for a successful call and <strong>err</strong> for any api defined error that was thrown.</p><p>Similarly, the arguments is also an auto generated Struct, usually call <em>&lt;MethodName&gt;_args</em> (in this case <em>login_args</em>). Its fields are simply the function arguments. Thus, this format follows very closely to how actual Thrift works.</p><p>There is JSON generator for Thrift, which generates all the metadata of the</p><ol><li>Services: name, list of functions</li><li>Functions: name, argument list</li><li>Structs: name, fields along with their names and types</li></ol><p>Below is an example of the generated metadata for Thrift file above.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bbbd0adb885d506a60eafcf39900a04e/href">https://medium.com/media/bbbd0adb885d506a60eafcf39900a04e/href</a></iframe><p>I used this metadata inside a new <em>Protocol. </em>A <em>Protocol </em>is<em> </em>the way Thrift marshals and un-marshals data. The problem is that <em>Protocols </em>in Thrift are strongly typed. It needs to be able to pass up the exact type of field (or the element type of the array or the key and value type of the map) and other stuff like the size of the map or array. That’s why the Thrift <em>JSONProtocol</em> has so much jargon inside it. It carries exactly this information.</p><p>This new <em>Protocol</em>, the <em>HumanReadableJsonProtocol</em>, uses the JSON that the Client sends up along with the metadata from the Thrift JSON generator to figure exactly what function was called, what arguments were sent and what their exact types are.</p><p>For example, in the above call it will first look up the metadata for the <em>login</em> method. Then for each key inside the <em>argument</em>s object in the client JSON it will find the associated key in the <em>arguments </em>array in the metadata. Depending on the type it will parse it out (if it is a struct or list or map, it will keep on recursing till it reaches a base type — int, string, boolean, double, etc). For example, in this case it will look for an object whose “<em>name” </em>value is “<em>email”</em> in the metadata, see it has a type of String and then verify that the value of “<em>email” </em>in the <em>arguments </em>object in the client JSON is also a String. Similarly for “<em>password.”</em></p><blockquote>This new <em>HumanReadableJsonProtocol</em> is still strongly typed. If you send up a key whose value doesn’t map correctly to the type defined the metadata, it will throw an error.</blockquote><p>Here is an error thrown in such a case, where I tried to pass a number instead of a string to the <em>password</em> field:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9886e52715e9c0fe0bd7cf20d89ef6ff/href">https://medium.com/media/9886e52715e9c0fe0bd7cf20d89ef6ff/href</a></iframe><p>Note that this JSON has an <em>exception</em> key, the above ones had a <em>result </em>key followed by either <em>success </em>or <em>error. </em>This is similar to how Thrift treats the different response types. You either get back a <em>Result </em>or an <em>Exception</em>. <em>Result </em>means that the call succeeded and no error <em>other than API defined</em> errors (the ones in the method signature) were thrown. Thus, <em>Result</em> has two fields: one for <em>success </em>which has the successful result of the call and one for <em>error</em> which holds the <em>API defined error</em> that was thrown. <em>Exception</em> holds any other error (including Thrift errors like corrupted data, unable to parse data, wrong types, etc.).</p><p>Since, it is just a protocol (way to marshal/un-marshal data) the Thrift generated code using it will automatically take care of stuff like required or optional fields.</p><p>So, for example, if the request has a content-type of <em>application/json, </em>all you need to do is use the <em>HumanReadableJsonProtocol</em> to parse it, otherwise use whatever standard protocol you use. You will also need pass in the directory where the generated JSON metadata lives.</p><p>Finally, it automatically uses any new changes to the Thrift definitions (as long as you also generate the JSON using the JSON generator).</p><p>Here is the source code to the project: <a href="https://github.com/wearableintelligence/human_readable_json_protocol">HumanReadableJsonProtocol</a></p><p><a href="https://github.com/wearableintelligence/human_readable_json_protocol">wearableintelligence/human_readable_json_protocol</a></p><blockquote>If you would like the code for this or would like to help expand the code for more languages and help write tests for it, please contact me.</blockquote><h3>HumanReadableJsonProtocol Snippet in Ruby</h3><p>Here is a snippet of the code that does the parsing in Ruby:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2164c7a6f3d9f2f1bc65d0f7a1d94976/href">https://medium.com/media/2164c7a6f3d9f2f1bc65d0f7a1d94976/href</a></iframe><p><em>Shameless plug again: I work at WI (</em><a href="http://wi.co/"><em>http://wi.co/</em></a><em>). We are changing the way people outside Silicon Valley work. If you are interested have a look at our careers page (</em><a href="http://wi.co/careers"><em>http://wi.co/careers</em></a><em>) or send me an email at </em><a href="/service/mailto:devansh@wi.co"><em>devansh@wi.co</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=774ba505c893" width="1" height="1" alt=""><hr><p><a href="https://medium.com/parsable-blog/using-human-readable-json-endpoints-with-thrift-for-free-774ba505c893">Using Human Readable JSON Endpoints with Thrift (for Free)</a> was originally published in <a href="https://medium.com/parsable-blog">Parsable Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Keeping the Big Idea Alive]]></title>
            <link>https://medium.com/parsable-blog/keeping-the-big-idea-alive-d93a66880bd8?source=rss----8f8fb474314f---4</link>
            <guid isPermaLink="false">https://medium.com/p/d93a66880bd8</guid>
            <category><![CDATA[ideas]]></category>
            <category><![CDATA[entrepreneurship]]></category>
            <category><![CDATA[startup]]></category>
            <dc:creator><![CDATA[Ryan Junee]]></dc:creator>
            <pubDate>Tue, 20 Oct 2015 00:59:59 GMT</pubDate>
            <atom:updated>2015-10-21T00:06:36.719Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0E39EpkJsdEN5mn5UPStXA.jpeg" /></figure><p>Lately, I’ve been thinking about big ideas and how hard they are to work on.</p><p>I’m not talking about how hard it is to solve fundamental problems in science and engineering (although those are certainly hard). Rather, I’m talking about how hard it is to <em>actually commit to working on big ideas</em>. I think most entrepreneurs dream about changing the world in a meaningful way (and hopefully making a lot of money in the process), but if you look around Silicon Valley it often seems like the majority of entrepreneurs <em>aren’t</em> working on big and meaningful problems. Why is that?</p><p>I think we often start out with a big idea idea in mind. It’s what gives us that jolt of adrenaline when the idea first comes to us, and powers us through many hours of sleepless nights as we flesh out the details. It causes us to excitedly tell all our friends at every opportunity, and to eventually build a team, incorporate a company, and get started.</p><p>But then something happens. When we’re in the muck of trying to make a company work, we find we need to continually narrow and narrow and narrow the focus of what we are working on, until we have something very small and concrete that we can launch to the world. It’s impossible to ‘boil the ocean’ as they say — to try and work on something too big from the outset. So we set out merely to establish a beach head, and expand from there.</p><p>Then we discover our first hypothesis didn’t quite work as planned. We learn from our customers, we iterate and pivot, and before too long we find that we are now all-consumed with just solving this one damn thing. It’s no longer about solving a big change-the-world problem, it’s just about getting <em>something</em> working. The big idea seems lost.</p><p>Let me illustrate with two of the companies that I started. The first, Omnisio, set out to revolutionize online education. I’d read Neal Stephenson’s <a href="http://en.wikipedia.org/wiki/The_Diamond_Age">The Diamond Age</a>, and Danny Hillis’ paper on <a href="http://www.edge.org/3rd_culture/hillis10/hillis10_index.html">“Aristotle” — the knowledge web</a>, and man did I want to build the the Primer. Wouldn’t that be cool? And yet, after testing, pivoting, and iterating we ended up launching a video player with annotations and synchronized powerpoint slides. Would we have gotten back to the big vision had we not <a href="http://techcrunch.com/2008/07/30/google-acquires-omnisio-to-spice-up-youtube/">sold</a> to YouTube? It’s hard to say — the realities of trying to survive as a startup and pay rent are very real constraints.</p><p>The second example is Inporia. We founded the company with a grand vision of changing the way commerce is done online. There hadn’t been any groundbreaking innovation since Amazon launched in 1994, we figured. Surely we could build some amazing technology that would change the way people shop online forever. Since we had no prior experience, we launched several experiments that explored the space — everything from machine learning and personalization (inporia.com), to massive data gathering and analysis (stylefeed.com). And even a pure game, called Fashion Blitz. We ended up with a mobile app for browsing and buying fashion called Kaleidoscope. Don’t get me wrong, it was a great app and judging by user feedback we nailed the UX and built something that users absolutely love. But it was a far cry from changing the way commerce is done online.</p><p>How can we retain the big picture? How can we work on truly big ideas? Am I being too hard on myself, and impatient? (It wouldn’t be the first time.)</p><p>I actually started this blog post more than two years ago, and I stopped at this point because I didn’t have many answers. I wrote the post to help me think through the issue. In the two years since I’ve started a <a href="http://wi.co/">third company</a> — one that so far appears to be doing quite well — and I have some new insight on the topic.</p><blockquote>I think the solution is to keep two realities in mind simultaneously. By that I mean keeping a relentless focus on doing everything necessary to stay alive in the short term, while at the same time keeping the ‘big idea’ in mind and making sure you are moving toward it.</blockquote><p>This is not easy and requires a some skill in managing one’s own psychology as an entrepreneur — this is a topic I plan on writing much more about on this blog.</p><p>It may be possible to drop the first reality and focus <em>only</em> on the ‘big idea’ <em>if </em>you are independently wealthy. Elon Musk and Richard Branson come to mind as people who are working on some particularly audacious projects, and they are fortunate enough to no longer need other people’s money to make their ideas happen. At a company level, Google is an example of a company that can afford to work on big, audacious projects (self-driving cars, glucose sensing contact lenses) because they have an awesome cash cow in their search advertising business.</p><p>Without that luxury, for example when running a company backed by venture capital and faced with a runway that is rapidly diminishing, there is significant pressure to focus on the short term and just get <em>something</em> working with the hopes of raising additional capital, even if it is at the expense of the original big idea. Maybe it is necessary to get one tiny thing working first, something that makes enough money to pay the bills and finally free us to work on ‘the big thing’. Yet even this is hard and requires tremendous discipline. If you have something that is making money, and can be improved to make even more money, it is very hard to ignore it and spend your time working on something that may not show a return for many years.</p><p>I’ll end with a story from my <a href="http://wi.co/">latest venture</a>. We started with the big idea of transforming the way work is performed by deskless workers, whose state of the art technology today is often paper and a clipboard. The release of Google Glass gave us an exciting platform that we could use to deliver information and communication to this class of workers. It turned out that wearable computing hardware is still too early to be practical in a wide variety of situations, but customers saw tremendous value in running our software solution on “traditional” smartphones and tablets. We are earning significant revenues on these form factors today, and this gives us the resources to continue as a business and <em>allows</em> us to pursue the same ‘big idea’ we began with. We are slowly putting the building blocks in place to make our big idea a reality, and continue to aim to put “a dent in the world” by improving the lives of deskless workers globally, irrespective of the hardware platform our solution is delivered on as technology progresses: mobile &amp; tablets → wearables → a chip in your head, etc…</p><p>Lesson learned: Do whatever is necessary to stay alive in the short term. And when you feel stuck in the muck keep the big picture in mind to keep your passion alive.</p><p><em>By the way, </em><a href="http://wi.co/careers"><em>we are hiring</em></a></p><p><em>Header image by </em><a href="https://www.flickr.com/photos/renneville/3052194640/in/photolist-7TgSPm-e3b88U-aWZD3n-aWZD3c-aWZD2Z-aWZD3H-dV87G-aWZD2x-6fdLBn-Bc3bG-7qxNwY-cUWmnE-pHBtVm-9xnZP6-f62iv8-NmZuL-7jEx5k-84nt6N-7Dpa6X-5DHi8w-cDGVMN-aEAAbe-4TLtzH-bFkDZX-Ahzdh-64iZNC-DwRqs-4q14QY-oMEVLi-egc33t-cUWjh5-5TXH3Y-7TdDpc-btz6Ju-9oVybV-9kGL8p-oDGAbz-8JiXGg-9B1J9J-8gwSAM-5ojnzy-oDGraE-oW9SZG-7icrsa-7x7iXP-eUPyGE-7x7ibk-vu6hsc-p1vHMC-x4TS1/"><em>Fe Ilya</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d93a66880bd8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/parsable-blog/keeping-the-big-idea-alive-d93a66880bd8">Keeping the Big Idea Alive</a> was originally published in <a href="https://medium.com/parsable-blog">Parsable Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Promoting Foreign Key Data Fetching from React to NuclearJS]]></title>
            <link>https://medium.com/parsable-blog/promoting-foreign-key-data-fetching-from-react-to-nuclearjs-c84a8f799d33?source=rss----8f8fb474314f---4</link>
            <guid isPermaLink="false">https://medium.com/p/c84a8f799d33</guid>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Adam Neary]]></dc:creator>
            <pubDate>Fri, 21 Aug 2015 16:45:15 GMT</pubDate>
            <atom:updated>2015-08-21T18:00:59.138Z</atom:updated>
            <content:encoded><![CDATA[<h4>Because We Don’t Have GraphQL (Yet)</h4><p>In some halcyon future, we will just use something like GraphQL to dynamically compose data requests from the server, retrieving no more nor less than we need. But that day is not today.</p><p>In the meantime, we need to request resources via the same API our customers use, which sometimes includes supporting data and sometimes does not.</p><p>Take, for example, our <em>Job</em> endpoint, as represented in Thrift:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ceb71e650740baed9e3e9c0ddccc146f/href">https://medium.com/media/ceb71e650740baed9e3e9c0ddccc146f/href</a></iframe><p>As it happens, a request from the API for job data will include arrays of job users and documents, and only reference via foreign keys to job templates. Setting the business context of a Job aside, you can imagine a simple list of these jobs on a side bar, the selection of which becomes the focus on the main panel.</p><h4>First Iteration: React Passing Props</h4><p>When we took our first pass at building a UI around this concept, we let React own a lot of the data management, passing data — sometimes quite a lot — down as props to child components.</p><p>Let’s continue with the example of a list of jobs (left sidebar above). Here is a relatively noble first pass:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f6723ccee77995f6ecdc4772d7fcef3a/href">https://medium.com/media/f6723ccee77995f6ecdc4772d7fcef3a/href</a></iframe><p>The key things to notices are:</p><ul><li>The parent component <em>receives as props</em> the currently selected job, a list of all jobs, and an “idObjectCache” which is simply a manually-maintained dumping ground of lookup data</li><li>The parent passes to the child all the same information</li><li>Data munging in the form of chained Underscore functions within getRows <em>(Pardon me, Lodash, of course. Sorry, everyone.)</em></li><li>A silly little lookup function in the child called templateIdFromName</li></ul><p>This is a relatively contained example, but the situation gets rapidly out of hand for more complex areas of the app where we have to marry more disparate data resources.</p><p>Add to that, it turns out that buried in the job model is the full team model, which we use in the above code (<em>this.props.job.team.name</em>) but never abstract for other components. On the same page view we’re also making an API call for the current job’s team.</p><h4>Second Iteration: Foreign Key Data Fetching to NuclearJS</h4><p>It’s no secret. I love the shit out of NuclearJS. Here’s a rough first pass at dumping Alt in favor of my new crush:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7e555f01f4c8b86b2dc7004755646593/href">https://medium.com/media/7e555f01f4c8b86b2dc7004755646593/href</a></iframe><p>The differences are subtle, and the importance may be non-obvious if you haven’t [yet] used React in anger.</p><ul><li>The parent container now leans on Nuclear getters for retrieving Immutable Lists of data with all the filtering and sorting taken care of</li><li>The only props the component receives relates to UI state (e.g. “fetching jobs”), but it manages its own data retrieval internally, which means the component and its parent can be refactored or moved around safely.</li><li>The <em>Job</em> module is a common module which we use in two different apps, but <em>currentJobId</em> is particular to the WebEx (Web Execution — please forgive the internal jargon) application and thus to its own module</li><li>We get away with the much safer <em>getIn() </em>for deep retrieval.</li></ul><p>The result is much less verbose, much easier for our designers to consume, style, and adapt. Great, but what about the data fetching?</p><h4>Manage Foreign Key Data like Jason Bourne Would</h4><p>The Nuclear docs offer a great strategy to <a href="https://github.com/optimizely/nuclear-js/blob/master/examples/rest-api/src/modules/rest-api/create-api-actions.js">creating API actions</a> model by model. Since the wrapper we wrote around Thrift returns Promises, many of our model implementations are simple assignments:</p><pre>exports.fetchAll = Thrift.enhanced.JobRole.index;</pre><p>But in cases where we want to manage the foreign key data of what comes back, we can swiftly dispatch our foes like Jason Bourne would, thusly:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e9b3142b1681bbae30c568ae66920297/href">https://medium.com/media/e9b3142b1681bbae30c568ae66920297/href</a></iframe><p><em>Note: </em>There are a few places in the above code where we could be more succinct, but at least it is abundantly clear for the next engineer (I hope!) what’s going on.</p><p><strong>Intercepting the API Response</strong></p><p>The first trick is that depending on the params sent by the UI (i.e. a React component), the action uses different API endpoints. Because the Thrift and Nuclear functions both return Promises, we can jump in the middle and pass the resulting jobs array to <em>processForeignKeys</em>.</p><p><strong>Requesting Required Foreign Key Data</strong></p><p>The second trick is retrieving a unique list of job template IDs from the job list (for 50+ jobs you might have only 3–4 templates). An index call to templates would have to be paged, and so instead of pulling all, we can fire off requests for just what we need. If the index endpoint ever supports receiving an array of IDs, we could ship that over in one call.</p><p>Of course, these actions are fire-and-forget. For free, our getters will update React components when the foreign key data arrives. Smoking hot.</p><p><strong>Loading Embedded Foreign Key Data</strong></p><p>The third trick is that we can take the job users, job roles, and team data across jobs and load it via a simple receiveAll function we created:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/144294877d7903f7dbe8a8fa08b99ba8/href">https://medium.com/media/144294877d7903f7dbe8a8fa08b99ba8/href</a></iframe><p>For each model, the receiveAll function just pretends it is handling an API fetch request it initiated. The results are the same.</p><p>You may also notice above that while processing duplicative foreign key data across jobs, we hijack <em>uniq()</em> to simply compare IDs. This is a lot easier than doing a deep comparison. though it relies on our confidence that the server won’t send us different data with the same IDs in the same request. If we cannot count on that, we have bigger problems.</p><h4>The Last Leg: Getters</h4><p>You made it this far. Let’s get the football in the end zone.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/97e0ff31aec3f10eb2924ed6e2b74342/href">https://medium.com/media/97e0ff31aec3f10eb2924ed6e2b74342/href</a></iframe><p>The format for Nuclear getters is a bit sugary at first glance, but it’s great.</p><ul><li>The raw job data itself is stored as an Immutable Map of String&lt;jobId&gt; to Map&lt;job&gt;</li><li>The jobList observes job <em>and</em> job template data, performing lookups as templates become available, returning the results as an Immutable List</li><li>The activeJobList and completedJobList exports simply apply filters and sorts like you would see in any language/framework. You just get one-way data binding for free.</li></ul><p>In the end, we have…</p><ul><li>All our API code in a Thrift wrapper</li><li>All our API data stored as Immutable objects, managed end-to-end by Nuclear, including foreign key data dependencies</li><li>All our UI in React with data retrieval and binding localized as much as possible</li></ul><p>…which is so easy it frees me up to write a Medium post about it all.</p><p><em>If you found this helpful, don’t feel bad about recommending it.</em></p><p><strong>Oh yeah, and we are hiring our third Front End Engineer if you feel like getting paid to get scrappy with React, Nuclear, and ImmutableJS at a Series-A funded startup backed by Andreessen Horowitz, First Round, Kleiner Perkins, and Google Ventures, among others. Ping me.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c84a8f799d33" width="1" height="1" alt=""><hr><p><a href="https://medium.com/parsable-blog/promoting-foreign-key-data-fetching-from-react-to-nuclearjs-c84a8f799d33">Promoting Foreign Key Data Fetching from React to NuclearJS</a> was originally published in <a href="https://medium.com/parsable-blog">Parsable Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WebSocket Connections and UI with React, NuclearJS, and ImmutableJS]]></title>
            <link>https://medium.com/parsable-blog/websocket-connections-and-ui-with-react-nuclearjs-and-immutablejs-7fd341dd050b?source=rss----8f8fb474314f---4</link>
            <guid isPermaLink="false">https://medium.com/p/7fd341dd050b</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Adam Neary]]></dc:creator>
            <pubDate>Fri, 21 Aug 2015 16:44:32 GMT</pubDate>
            <atom:updated>2015-08-21T16:38:31.166Z</atom:updated>
            <content:encoded><![CDATA[<p><em>— tl;dr plenty of code below —</em></p><p>At <a href="http://wi.co/">WI</a> we need reliable real time connection for workers out in the field. Most critically, we need to display a disconnected state accurately on web and mobile clients.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/978/1*WUvMfZb-oSr-bsgUQwQoXg.png" /></figure><p>There’s nothing revolutionary about the Gmail-style reconnect banner, but how we manage it using <a href="https://facebook.github.io/react">React</a> and <a href="https://github.com/optimizely/nuclear-js">NuclearJS</a> (the flux implementation we use and love) is pretty cool, I think, and after a few iterations we have the quirks of native WebSockets wrestled to the ground quite elegantly. Hopefully there’s some useful stuff in here if you’re playing in similar areas.</p><h4>Guideposts</h4><ul><li>React is used for UI <em>only</em>. No business logic — they just bind to Nuclear getters and call Nuclear actions.</li><li>Nuclear getters are pure functions pulling data from stores, and Nuclear stores only update state based on Nuclear actions. Neither Nuclear getters or stores take any external actions themselves.</li><li>All WebSocket logic is isolated cleanly to a service entirely outside of Nuclear.</li><li>Nuclear actions tie everything together, managing the connection and responding to user and socket maintenance events.</li></ul><h4>React: Just the UI, Ma’am</h4><p>We use a “Signaling” server to broadcast real time events to web and mobile clients. To drop this capability into any of our web apps, we just need to include a Signaling component in any Authenticated parent component.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6fc0e70ce147b39967e06cfb661d0256/href">https://medium.com/media/6fc0e70ce147b39967e06cfb661d0256/href</a></iframe><p>Nuclear allows us to bind the status of the signaling connection as an Immutable map. We can fire off a connect action when the component mounts and when the user explicitly requests one, and we can disconnect when the component is unmounted.</p><p>The rest is UI. It’s dead simple for our designers to see how it all works without giving any thought to all the machinery that drives it, and they can happily edit the markup or related SCSS. Boom.</p><h4>The WebSocket Provider: Carefully Containing Singletons</h4><p>In the past, my real time connection life has been a lot simpler through the use of <a href="http://socket.io/">Socket.io</a>, but in this case, we need to build and manage WebSockets natively to connect to an existing server (perhaps a topic for another post).</p><p>The tricky part is that we will need Nuclear actions to reference the current socket instance, so we need a singleton we can persist and mutate, something best kept out of Nuclear entirely.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2ec9669a6bae96c816d99db2c0fb0642/href">https://medium.com/media/2ec9669a6bae96c816d99db2c0fb0642/href</a></iframe><p>This provider can safely be called from any action and be counted on to deliver the current instance. As requested, the instance can be hard reset, which is an unfortunate necessity during the reconnect process.</p><p>As a bonus, the provider also maintains a persistent map of timers, preventing Nuclear stores from having to set and clear intervals.</p><p>Our specific socket implementation requires that we ping the server with a presence packet every ~30 seconds, so the provider has this capability built into it, and it maintains a map of message type to its handlers (each of which calls Nuclear actions from other modules).</p><h4>Nuclear Actions: The Workhorses</h4><p>To keep everything neat and clear, we only want to expose “connect” and “disconnect” actions. Everything else is an internal implementation detail.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/808b75716b0ca7b0f12a80b5fee40108/href">https://medium.com/media/808b75716b0ca7b0f12a80b5fee40108/href</a></iframe><p>“Connect” is the only method that triggers a hard reset of the socket by passing true as the third argument. Other instantiations of the WebSocketProvider simply return the existing instance.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c2d161c39bccc92467e43096f153ef09/href">https://medium.com/media/c2d161c39bccc92467e43096f153ef09/href</a></iframe><p>The rest of the internal functions are where the real action takes place. The event handlers also start and stop the appropriate timers.</p><p>If the connection is in a ready state, the <em>identify</em> timer triggers a ping every 30 seconds, meeting our presence requirement for the signaling server itself.</p><p>If the connection closes or goes “cold” (no close event, but no response to pings for over a minute), the <em>identify</em> timer is stopped, and the <em>reconnect</em> timer is started. Every second, the <em>UPDATE_RECONNECT_TIMER</em> action is fired, which our store uses to update its state so that our React component doesn’t need to get its hands dirty with the same.</p><p>Since the WebSocketProvider checks for the existence of a timer before setting interval, there’s no risk in functions like <em>checkConnection</em> getting called too many times.</p><h4>NuclearJS Debugging is a Dream Come True</h4><p>When is the last time you heard that? Here’s what I see when debugging a new change:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/440/1*Yymtc7j24KsI9jJQCFr6fg.png" /><figcaption>Mmmmm…NuclearJS debug mode</figcaption></figure><p>Any of those log objects can be expanded to display the action payload as well as the app state as of that point in time. No more dropping in <em>console.log</em> all over to determine what happened between events.</p><p>In this case, on login you can see the app initiate a connection attempt, report the change in state when the connection is opened, fire off a presence ping, and receive the result. A pair of identify and receive pings come in 30 seconds later.</p><p>Then I killed the signaling server manually (locally!), and you see the close event come through followed by an immediate and unsuccessful reconnect attempt. The reconnect timer updates every second, but once I turn signaling back on, we get the expected connection events.</p><p>On logout, everything is disconnected and cleaned up, and we see our login page rendered.</p><p><em>If you found this helpful, don’t feel bad about recommending it.</em></p><p><strong>Oh yeah, and we are hiring our third Front End Engineer if you feel like getting paid to get scrappy with React, Nuclear, and ImmutableJS at a Series-A funded startup backed by Andreessen Horowitz, First Round, Kleiner Perkins, and Google Ventures, among others. Ping me at </strong><a href="http://adam+hiring@wi.co/"><strong>adam+hiring@wi.co</strong></a><strong>.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7fd341dd050b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/parsable-blog/websocket-connections-and-ui-with-react-nuclearjs-and-immutablejs-7fd341dd050b">WebSocket Connections and UI with React, NuclearJS, and ImmutableJS</a> was originally published in <a href="https://medium.com/parsable-blog">Parsable Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>