<?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 Alex Wilmer on Medium]]></title>
        <description><![CDATA[Stories by Alex Wilmer on Medium]]></description>
        <link>https://medium.com/@benevolentNinja?source=rss-81bc57426c80------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*rs6sAm_aveeSF-l-.png</url>
            <title>Stories by Alex Wilmer on Medium</title>
            <link>https://medium.com/@benevolentNinja?source=rss-81bc57426c80------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 07:11:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@benevolentNinja/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[Use `let`, it’s fine.]]></title>
            <link>https://medium.com/@benevolentNinja/use-let-its-fine-aa758adec325?source=rss-81bc57426c80------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa758adec325</guid>
            <category><![CDATA[politeness]]></category>
            <category><![CDATA[communication]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Alex Wilmer]]></dc:creator>
            <pubDate>Fri, 29 Sep 2017 02:48:58 GMT</pubDate>
            <atom:updated>2017-09-29T02:48:58.736Z</atom:updated>
            <content:encoded><![CDATA[<p>I frequently post miniature code blocks in Slack channels, reddit threads and other forums to explain or discuss something. Here’s a recent example:</p><pre>let menu = document.querySelector(&#39;.menu&#39;)<br>menu.onclick = () =&gt; menu.classList.toggle(&#39;open&#39;)</pre><p>All too often I’m accused of not thinking about the children.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*M20YbDmAnj39gPqmpz7u8w.png" /><figcaption>Said, seemingly, everyone ever.</figcaption></figure><p>Because, as you may or may not know, let is signal to readers that the variable is going to change. How could I be so inconsiderate of my poor readers, looking beyond the fold of my five line module for an eventual reassignment like an unterminated bash script.</p><p>By far, I get this criticism the most when quickly mocking React components.</p><pre>let mapP = fn =&gt; C =&gt; p =&gt; &lt;C {...fn(p)} /&gt;<br>let C = mapP(p =&gt; ({ header: p.username }))(<br>  p =&gt; &lt;h1&gt;{p.header}&lt;/h1&gt;<br>)<br>export default () =&gt; &lt;C username=&quot;Alex&quot; /&gt;</pre><p>Remember when we did this with var and it was fine because there was no other option, like, totally not that long ago?</p><p>Actual code bases should, and do, demand higher standards for committed code. However when evaluating an idea or principle, leave the emotional attachments to red herrings aside, otherwise you’re doing no differently than correcting a foreigner on their grammar during a casual conversation. Typically unwarranted.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa758adec325" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Minimal Redux Setup]]></title>
            <link>https://medium.com/@benevolentNinja/minimal-redux-setup-e6a10fcbcb68?source=rss-81bc57426c80------2</link>
            <guid isPermaLink="false">https://medium.com/p/e6a10fcbcb68</guid>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Alex Wilmer]]></dc:creator>
            <pubDate>Fri, 09 Dec 2016 01:25:21 GMT</pubDate>
            <atom:updated>2016-12-09T13:59:20.674Z</atom:updated>
            <content:encoded><![CDATA[<p>(disclaimer: This is not a post about best practices, but food for thought when dealing with Redux boilerplate)</p><p>The Redux docs have a <a href="http://redux.js.org/docs/recipes/ReducingBoilerplate.html">great page</a> . I’d like to take this to the extreme and explore the benefits of having the most minimal possible Redux setup.</p><p>To take a step back, consider what drove many of us “vanilla” React users to giving Redux a shot — the ability to connect arbitrary components to our global app state instead of passing down state and update functions through every node from App to leaves.</p><p>I found this to be very helpful, especially after adding React Router and discovering the need to clone children, passing in app state and various functions to update said state:</p><pre>let children = Children.map(this.props.children, child =&gt; <br>  cloneElement(child, { <br>    …this.props, <br>    …this.state, <br>    setState: payload =&gt; this.setState(payload)<br>  }) <br>})</pre><p>Passing setState down to children may seem way too cavalier and for important applications I would agree, but not all apps are important or will have multiple maintainers or will have any users whatsoever. Sometimes you just want to make something that works, fast. Knowing what the minimum requirements are for a working program can be empowering.</p><p>Then I added Redux and suddenly had ten times as much code as I would have liked to have. I was trading brevity for predictability — actions for all the events in my app, action creators to wrap those and many reducers whose switch statements had a long list of cases. I didn’t think I was building a very complex application but it seemed like every little feature bloated my already verbose, though highly predictable, business logic.</p><p>Over time I noticed more logic being pushed up to thunks / epics / sagas, and reducers thinning out to be barely visible.</p><pre>function reducer (state = init, action) {<br>  switch (action.type) {<br>    case &#39;UPDATE&#39;:<br>      return {<br>        ...state,<br>        ...action.payload,        <br>      }<br>  }<br>}</pre><p>Some day later I needed to make another small app and thought to myself, “All I really want is a single store that notifies me on changes — maybe something I can add middleware to later if I want.” That’s all this app needs. What might that look like to setup?</p><pre>import { createStore } from &#39;redux&#39;</pre><pre>let init = { /* stuff */ }</pre><pre>function reducer (state = init, action) {<br>  switch (action.type) {<br>    case &#39;UPDATE&#39;:<br>      return {<br>        ...state,<br>        ...action.payload,<br>      }<br>  }<br>  return state<br>}</pre><pre>function update (payload) {<br>  return {<br>    type: &#39;UPDATE&#39;, <br>    payload,<br>  }<br>}</pre><pre>let store = createStore(reducer)</pre><pre>export { store, update }</pre><p>That’s it. One reducer, one action and one action creator. I still get all the benefits of Redux the technology, without the overhead of boilerplate, which I could easily add later on if I wanted to.</p><p>Used in some random component:</p><pre>import { connect } from &#39;react-redux&#39;<br>import { update } from &#39;./store&#39;</pre><pre>export default <br>connect(state =&gt; state)(<br>  ({ dispatch, state }) =&gt;<br>    &lt;div&gt;<br>      &lt;h1&gt;{state.title}&lt;/h1&gt;<br>      &lt;button <br>        onClick={e =&gt; dispatch(update({ title: &#39;so minimal!&#39; }))}<br>      &gt;<br>        Give&#39;r<br>      &lt;/button&gt;<br>    &lt;/div&gt;<br>)</pre><p>I can already hear someone telling me to use MobX.</p><p>I’ve used it. I like it. I like Redux better. ¯\_(ツ)_/¯</p><p>Keep minimal, my friends.</p><p>/* — — — — — — — — — — — */</p><p>BTW I highly recommend:</p><p>* <a href="https://github.com/acdlite/recompose">recompose</a></p><p>* <a href="https://github.com/acdlite/redux-actions">redux-actions</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e6a10fcbcb68" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>