<?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 Ben Styles on Medium]]></title>
        <description><![CDATA[Stories by Ben Styles on Medium]]></description>
        <link>https://medium.com/@benadamstyles?source=rss-4e17883ba85d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*fuhqGOshk0JVlGVy.jpg</url>
            <title>Stories by Ben Styles on Medium</title>
            <link>https://medium.com/@benadamstyles?source=rss-4e17883ba85d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 20:49:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@benadamstyles/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[React Native’s LayoutAnimation in the post-componentWillUpdate age]]></title>
            <link>https://medium.com/@benadamstyles/react-native-layoutanimation-in-the-post-componentwillupdate-age-9146b3af0243?source=rss-4e17883ba85d------2</link>
            <guid isPermaLink="false">https://medium.com/p/9146b3af0243</guid>
            <category><![CDATA[layoutanimation]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[animation]]></category>
            <dc:creator><![CDATA[Ben Styles]]></dc:creator>
            <pubDate>Wed, 04 Apr 2018 18:32:41 GMT</pubDate>
            <atom:updated>2018-04-07T11:51:38.335Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fQiUdLbuod-6lcKO." /><figcaption>Photo by <a href="https://unsplash.com/@odehpal?utm_source=medium&amp;utm_medium=referral">Ahmad Odeh</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><a href="https://reactjs.org/blog/2018/03/29/react-v-16-3.html">React v16.3 is out!</a> With it, we get a host of new APIs, and some fairly substantial changes which boil down to a simple message:</p><blockquote><strong>The component lifecycle methods </strong><strong>componentWillMount, </strong><strong>componentWillReceiveProps, and </strong><strong>componentWillUpdate have been deprecated.</strong></blockquote><p>Deprecation warnings will appear in a future 16.x release, and the methods will be removed in 17 (you will be able to continue using them by prefixing them with UNSAFE_ – <a href="https://reactjs.org/blog/2018/03/29/react-v-16-3.html#component-lifecycle-changes">read more about it here</a>).</p><p>Initially, this presented me with a quandary. My <a href="https://facebook.github.io/react-native/">React Native</a> app, <a href="https://itunes.apple.com/us/app/mealsup/id1200169378"><strong>MealsUp</strong></a>, makes heavy use of the declarative animation API, <a href="https://facebook.github.io/react-native/docs/animations.html#layoutanimation-api"><strong>LayoutAnimation</strong></a>. This beautiful, magical API is quite literally fire-and-forget: just call one of its easing methods, and the next time your UI changes, that change will animate smoothly rather than just snapping into place.</p><p>I had slipped into a blissful pattern:</p><pre>componentWillUpdate() {<br>  LayoutAnimation.easeOut()<br>}</pre><p>A concise, simple way to make my presentational components <strong>animated by default</strong> – no matter what UI changes were triggered (<a href="https://github.com/facebook/react-native/issues/1440">well, almost</a>).</p><p>However, now that componentWillUpdate() is to be deprecated, I needed another solution. I have found one, and I wanted to share it in case anyone else is wondering the same thing. <strong>To cut straight to it:</strong></p><pre>component<strong>Did</strong>Update() {<br>  LayoutAnimation.easeOut()<br>}</pre><p>If you’re thinking, like I used to, that this won’t work because the animation will be initiated too late, <em>after</em> the UI has changed, then you’ll be as surprised as I was to read this tweet from Andrew Clark, a core contributor to React:</p><h3>Andrew Clark on Twitter</h3><p>@browniefed @mjackson @renatorib_ @brian_d_vaughn setState in didMount/didUpdate is completely flushed by the time React yields to the browser. Since the browser has no opportunity to refresh the screen (paint), you&#39;ll never observe an inconsistency.</p><p>In React Native, we’re not dealing with a browser, but it amounts to the same thing: componentDidUpdate() is called <em>before the UI is painted</em>. This means you can trigger a LayoutAnimation in componentDidUpdate(), and it will still apply <strong>to that same update</strong> when it finally gets painted to the screen.</p><h3>B.A. Styles on Twitter</h3><p>@rm_hartog @dan_abramov Thanks. Would it be correct to say: &quot;cDU runs after e.g. document.appendChild() but before the browser actually paints&quot;?</p><h3>Reinier Hartog on Twitter</h3><p>@BenStyles @dan_abramov That is exactly right.</p><h3>Reinier Hartog on Twitter</h3><p>@BenStyles @dan_abramov Same applies in React Native: all native calls are queued and only flushed when your code yields. Difference between RN and DOM is that you can not read the new layout in cDU, while you can in DOM, which is handy for animation.</p><p>React delivers again!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9146b3af0243" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rapt: wrap any JS value so you can map over it]]></title>
            <link>https://medium.com/@benadamstyles/rapt-wrap-any-js-value-so-you-can-map-over-it-8c1034ea9103?source=rss-4e17883ba85d------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c1034ea9103</guid>
            <category><![CDATA[javascript-library]]></category>
            <category><![CDATA[method-chaining]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Ben Styles]]></dc:creator>
            <pubDate>Tue, 20 Feb 2018 14:46:45 GMT</pubDate>
            <atom:updated>2018-02-20T15:06:25.025Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*d7d9c01hBCX7ruBXLpokEQ.png" /></figure><p>This week, I released <a href="https://www.npmjs.com/package/rapt">Rapt</a>, a small new open source JavaScript library I have been working on. It is my first proper open source release (except for that pretty niche ebook processing monolith I released years ago with its 2 whole github stars), so I’m looking for all the <a href="https://github.com/Leeds-eBooks/rapt/issues">feedback</a> and <a href="https://github.com/Leeds-eBooks/rapt/pulls">contributions</a> I can get: positive, negative or anywhere in between.</p><p>Below is an excerpt of the readme document available <a href="https://github.com/Leeds-eBooks/rapt">on GitHub</a>. It describes why I wrote Rapt, and why you might want to try it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*la1FHAA331wdjv0z." /><figcaption>Photo by <a href="https://unsplash.com/@mariusmasalar?utm_source=medium&amp;utm_medium=referral">Marius Masalar</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Rapt is a small package that wraps any value, allowing you to map over it. A bit like <a href="https://lodash.com/">Lodash</a>’s <a href="https://lodash.com/docs/4.17.5#chain">chain</a>, or <a href="https://gulpjs.com/">Gulp</a>’s <a href="https://github.com/gulpjs/gulp/blob/v3.9.1/docs/API.md">pipe</a>, but for values rather than collections or streams.</p><p>Rapt does not exist to reduce the number of characters in your code, nor to make your code run faster. For many, it will not even be the clearest way to write your code. But if, like me, you find it easier to read and understand a list of functions than a variety of assignments, operators and returns, then Rapt might help you enjoy the code you write a little more.</p><p>It lends itself to a highly functional style of JS programming, allowing you to work with and transform values without having to assign them to variables. It works best with immutable values (numbers, strings, <a href="https://facebook.github.io/immutable-js/">immutable collections</a>). It is particularly well suited to the latter, and is very satisfying if you hate using let just so you can reassign an immutable value after modifying it, i.e.:</p><pre>let x = Map()<br>x = x.set(‘a’, 1) // 🤢</pre><blockquote>It can be used with plain mutable objects and arrays but it may be counter-productive in terms of clarity, as the functions you pass to .map() and .tap() will no longer be side-effect-free.</blockquote><p>Rapt is particularly useful when you want to avoid unnecessarily executing expensive operations, but you don’t want to give up your functional style.</p><h4>Examples</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d3de422180f72c433f9ab9ee51449ac7/href">https://medium.com/media/d3de422180f72c433f9ab9ee51449ac7/href</a></iframe><h4>Try it out!</h4><iframe src="https://cdn.embedly.com/widgets/media.html?url=https%3A%2F%2Frunkit.com%2Fbenstyles%2Frapt-repl&amp;src=https%3A%2F%2Frunkit.com%2Fe%3Fname%3Db8ad9182-e482-48a2-b14c-bb51887c493a%26base64source%3DY29uc3Qge3JhcHR9ID0gcmVxdWlyZSgncmFwdCcpCmNvbnN0IEltbXV0YWJsZSA9IHJlcXVpcmUoJ2ltbXV0YWJsZScpCgpjb25zdCBsaXN0ID0gSW1tdXRhYmxlLmZyb21KUyhbMSwgMiwgM10pCgpyYXB0KGxpc3QpCiAgLm1hcChsID0%252BIGwucHVzaCg0KSkKICAudmFsKCk%253D%26minHeight%3D210%26fixedHeight%3D350%26location%3D%26title%3D%26oembed%3Dtrue&amp;type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=runkit" width="900" height="350" frameborder="0" scrolling="no"><a href="https://medium.com/media/68d70c78ca414f6a5257a92ba5dcdb22/href">https://medium.com/media/68d70c78ca414f6a5257a92ba5dcdb22/href</a></iframe><p><a href="https://github.com/Leeds-eBooks/rapt">Read more about Rapt on GitHub.</a></p><blockquote>Many thanks to <a href="https://medium.com/u/b97a65c2767e">Nelo Mitranim</a> for letting me use the package name. Those <a href="https://twitter.com/erikras/status/958653989549170688">four-letter names</a> are hard to come by these days!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c1034ea9103" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>