<?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 Dane Sirois on Medium]]></title>
        <description><![CDATA[Stories by Dane Sirois on Medium]]></description>
        <link>https://medium.com/@Dane_s?source=rss-790a919608a8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*pEgprdJxwEJFFDR1hSMiIg.png</url>
            <title>Stories by Dane Sirois on Medium</title>
            <link>https://medium.com/@Dane_s?source=rss-790a919608a8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 03:39:15 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Dane_s/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[TypeScript Takeaways — Understanding TypeScript]]></title>
            <link>https://medium.com/@Dane_s/typescript-takeaways-understanding-typescript-a2ceb0628c8f?source=rss-790a919608a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/a2ceb0628c8f</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Dane Sirois]]></dc:creator>
            <pubDate>Thu, 07 Mar 2019 18:30:31 GMT</pubDate>
            <atom:updated>2019-03-13T18:20:15.655Z</atom:updated>
            <content:encoded><![CDATA[<h3>TypeScript Takeaways — Understanding TypeScript</h3><p>I recently took a Udemy course on TypeScript to learn more about the emerging technology. I took notes throughout the course and thought I would share some of my takeaways.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3CiMgJkSbc2drJMduoAzKA.jpeg" /></figure><p>(Disclaimer: I am by no means an expert on this technology. The information in this article is how I understood things as I was learning it. It is <em>not</em> a complete overview of the language).</p><h3>The Course:</h3><ul><li><a href="https://www.udemy.com/understanding-typescript">https://www.udemy.com/understanding-typescript</a></li></ul><h3>What is it?</h3><ul><li>Typescript is a superset of JavaScript meaning that under the hood it is really just JavaScript. You can think of it as being JavaScript with extra features.</li></ul><h3>Types:</h3><p>Types allow you to specify what types of values you are expecting a variable to be. They are enforced at compile time, meaning that your app will not even compile if a value is improperly assigned to a typed variable. This helps catch and prevent bugs before users even get a chance to execute the code.</p><p>There are two ways that types are set in TypeScript. Typing is done either implicitly, or explicitly.</p><h4>Implicit types:</h4><ul><li>When you assign a value to a variable in TypeScript, the variable is automatically “typed” to be the same type as the value:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0898e66e69f79293bee075a5ed9242ed/href">https://medium.com/media/0898e66e69f79293bee075a5ed9242ed/href</a></iframe><ul><li>Variables without a value assignment are of type any meaning that TypeScript does not assign any specific type checking to it. Typing something to any should be avoided as it sort of defeats the purpose of the tool:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/db3c9dcb802dd60c683f9d2f8f8ed7cf/href">https://medium.com/media/db3c9dcb802dd60c683f9d2f8f8ed7cf/href</a></iframe><ul><li>The contents of an array are implicitly typed meaning that an array of strings cannot later be modified to contain numbers:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f53bccb134253bf24911dd00694dd648/href">https://medium.com/media/f53bccb134253bf24911dd00694dd648/href</a></iframe><ul><li>Properties of an object declaration are implicitly typed. When overriding objects, the new object must have the same signature:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b42a4811e51420e4cbb5aeda6943a865/href">https://medium.com/media/b42a4811e51420e4cbb5aeda6943a865/href</a></iframe><h4>Explicit types:</h4><ul><li>You can explicitly type variables by using a colon operator after the variable name:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c41583bb4c1f7e86a06e6319311ab03b/href">https://medium.com/media/c41583bb4c1f7e86a06e6319311ab03b/href</a></iframe><ul><li>Assigning type any to an array allows for the contents to be of any type:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c85c72711b852daf39904612af8349a/href">https://medium.com/media/9c85c72711b852daf39904612af8349a/href</a></iframe><ul><li>You can enforce the types of the contents of an array by manually specifying the types:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c9d8b1d3cf55d4c4b58fa8c14eb7ff7c/href">https://medium.com/media/c9d8b1d3cf55d4c4b58fa8c14eb7ff7c/href</a></iframe><ul><li>You can explicitly define the types for specific items in an array. When you do this for the first two items it is called a “tuple”:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d08dc6a520b7883979c04c53fe518f7f/href">https://medium.com/media/d08dc6a520b7883979c04c53fe518f7f/href</a></iframe><ul><li>When typing functions, you can specify both the argument types as well as the return value:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/876bfa52526ce097261101447149da53/href">https://medium.com/media/876bfa52526ce097261101447149da53/href</a></iframe><ul><li>When a function does not have a return value, you can enforce this behaviour by using the ‘void’ type:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/598fce024f81b22f77e7726ba2b5d1af/href">https://medium.com/media/598fce024f81b22f77e7726ba2b5d1af/href</a></iframe><ul><li>Objects can have explicit property typing:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4d4272840fff0cf1816f5b77a3e309a4/href">https://medium.com/media/4d4272840fff0cf1816f5b77a3e309a4/href</a></iframe><ul><li>When a variable is typed to support being of more than one data type, it is called a “union type”:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/efabba987f96508333c98ac10c1da502/href">https://medium.com/media/efabba987f96508333c98ac10c1da502/href</a></iframe><ul><li>Union types can be used on arrays:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/34b90b68ab4a3ee0076b6398a2704e6e/href">https://medium.com/media/34b90b68ab4a3ee0076b6398a2704e6e/href</a></iframe><h4>Other notes:</h4><ul><li>Floats and integers are both of type number.</li><li>TypeScript does strict type checking (ex: 0 cannot be assigned to a variable set to false).</li><li>There are no hard community conventions around whether you should leverage implicit or explicit typing (at least from what I could gather).</li><li>When TypeScript types are compiled into JavaScript, all of the variable typing code is stripped out. The purpose of the TypeScript types are to stop non-compliant code from compiling into JavaScript in the first place. By the time the code is actually turned into JavaScript, you can be assured that it is in full compliance with the types, hence why no JavaScript equivalent to enforce the types is needed.</li></ul><h4>Interfaces:</h4><ul><li>Interfaces are a way to specify and enforce the structure of an object. With them you can guarantee that an object will always have certain fields.</li><li>They are reusable by nature and exist in part so that you do not have to repeatedly type out the same type definitions in multiple spots.</li><li>You can specify optional properties on an interface by putting a “?” after the property name.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/617/1*eO59Mn9fVd3D97-tKY340g.gif" /><figcaption>optional parameters on an interface</figcaption></figure><ul><li>Inline object literals are checked more strictly against an interface than objects assigned to a variable. If an inline object literal has properties not defined within the interface the compiler will error. However, if an object assigned to a variable has additional properties then the interface the compiler will pass:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b9afa1ff617e67a3160a8784728f4b38/href">https://medium.com/media/b9afa1ff617e67a3160a8784728f4b38/href</a></iframe><h4>Generics:</h4><ul><li>Generics are functions that can take any data type as an argument similar to the usage of any while still providing a level of type safety.</li><li>They can enhance an IDE’s ability to interpret what the return value will be so that it can provide suggestions on what methods you are able to call on it:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/617/0*IvKaOtyR450ZbQnq" /><figcaption><em>generic function IDE suggestions</em></figcaption></figure><ul><li>You can specify what the argument types will be when calling a generic function. This is useful for when you know what you want the data types to be in a given context and want to enforce a specific implementation of the method:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0447f241df3b00b3ab5864bb7fd73f4f/href">https://medium.com/media/0447f241df3b00b3ab5864bb7fd73f4f/href</a></iframe><h4>Notes:</h4><ul><li>The value in between the &lt;&gt; tags can be anything. It is convention to name this value &lt;T&gt; short for “type”.</li><li>You can have multiple generic types by specifying multiple placeholders. It’s convention for subsequent types to follow the alphabet downward (ex: &lt;T, U, V&gt;)</li></ul><p>This was a high level overview of some of the more interesting aspects of TypeScript. As mentioned above, this is not a complete overview of the language. For more information, the official documentation is a good reference (<a href="https://www.typescriptlang.org/docs/home.html">https://www.typescriptlang.org/docs/home.html</a>).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a2ceb0628c8f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The missing layer in application architecture]]></title>
            <link>https://medium.com/@Dane_s/the-missing-layer-in-application-architecture-8c16e900e6d1?source=rss-790a919608a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c16e900e6d1</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[factom]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Dane Sirois]]></dc:creator>
            <pubDate>Mon, 10 Dec 2018 17:01:41 GMT</pubDate>
            <atom:updated>2019-01-21T22:33:27.508Z</atom:updated>
            <content:encoded><![CDATA[<h4>By <a href="https://medium.com/@Dane_s">Dane Sirois</a></h4><p>I’ve been thinking a lot about Blockchain over the past year or so and I think one of the biggest hurdles with it in regards to getting enterprise adoption is the fact that there is so much volatility to the cost of entering data. It means that companies cannot effectively budget as their forecasts for even just months away will be wildly inaccurate. Not to mention the ridiculously high transaction fees which makes it unsuitable for most applications.</p><p>What Blockchain does well, is that it provides a layer of immutability and trust that was never before possible to the extent that it is now. What we have with today’s systems is often just an illusion of trust. In today’s world, there’s a missing layer in the architecture of our applications where we validate our data past the point of its creation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P_oLz1GlVLJUL1YKFPGd8A.jpeg" /></figure><blockquote>There’s a missing layer in the architecture of our applications where we validate our data past the point of its creation.</blockquote><p>We are creating more data at a rate that’s even more impressively hard to comprehend, yet we lack a way to reliably validate and verify it. What good is the data in the first place if you can’t fully trust it’s authenticity?</p><p>As we have seen time and time again exemplified in these massive data breaches, centralized databases are inherently insecure. It requires too much trust in a singular organization to instill the kind of confidence needed. Data stored in a centralized database is under a constant threat of unauthorized modification. That’s not to say that databases are bad, but more to point out that we are missing a system in which to identify when these unauthorized changes happen, and what data has been changed as a result.</p><p>In a lot of ways, data has become one of the world’s most valuable assets. To maintain that value, it’s imperative that we have ways to verify its integrity. I’m of the opinion that technology is only going to allow for more subtle alterations of that data and if we continue without proper integrity checking tactics, the value captured around it will be lost. This is where Blockchain comes in.</p><p>Blockchain and cryptocurrency have taken a ton of flack over the past year, and many of the skepticism is rightfully deserved. If you look deeper past the common surface level applications, many of the underlying concepts are actually quite sound. The Factom protocol® (factomprotocol.org) appears to be one of the best innovations positioned to solve the problem of verifying our data. It aims to become sort of like the TCP/IP of data integrity.<br>It has this concept of a “two token system” which completely removes the need for companies to ever touch cryptocurrency while still inheriting all of the benefits of Blockchain. This is an article written about the “two token system” which dives deeper into the economics around it (<a href="https://factomize.com/the-genius-of-the-factom-two-token-system/">https://factomize.com/the-genius-of-the-factom-two-token-system/</a>).</p><p>All in all, I think a movement towards a more transparent web is needed. I think our standards of trust as a society are shifting, and both the consumer and corporation are going to be demanding more transparency over their data. Blockchain can help in this regard. A discussion is needed around our current engineering practices to support this evolving requirement in the responsibility of data ownership.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c16e900e6d1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React.js — Compound Components]]></title>
            <link>https://medium.com/@Dane_s/react-js-compound-components-a6e54b5c9992?source=rss-790a919608a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/a6e54b5c9992</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Dane Sirois]]></dc:creator>
            <pubDate>Wed, 19 Sep 2018 17:29:13 GMT</pubDate>
            <atom:updated>2018-09-19T17:29:13.533Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5nql7ehsVwg_L_npZcLEmQ.jpeg" /></figure><p>A compound component is a type of component that manages the internal state of a feature while delegating control of the rendering to the place of implementation opposed to the point of declaration. They provide a way to shield feature specific logic from the rest of the app providing a clean and expressive API for consuming the component. Internally they are built to operate on a set of data that is passed in through children instead of props. Behind the scenes they make use of React’s lower level API such as React.children.map(), and React.cloneElement(). Using these methods, the component is able to express itself in such a way that promotes patterns of composition and extensibility.</p><h3>The Problem:</h3><p>Let’s say we are tasked with creating a shopping cart component that displays a grouping of items in either a horizontal or vertical list. Each item must be assigned a click handler to capture click events and have an isActive state conditionally applied to it.</p><p>A common approach would be to design your component to take a list of items as a prop and have the component internally .map() over them:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/59047f12f0c1ed8df1df63340e0e9a15/href">https://medium.com/media/59047f12f0c1ed8df1df63340e0e9a15/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/778d21c8a8e266219ad1c0ed4e1eb74f/href">https://medium.com/media/778d21c8a8e266219ad1c0ed4e1eb74f/href</a></iframe><p>This is a fairly common approach that provides one possible solution to our problem. There is however, an inherit downside to this pattern:</p><ol><li>The responsibility for rending &lt;ShoppingCartItem /&gt; is held by &lt;ShoppingCart /&gt; which causes a coupling between the two components. This takes away the aspect of composition as it forces &lt;ShoppingCart /&gt; to know about which components should be used for each item.</li></ol><h3>The Solution:</h3><p>What if we could express this problem by simply declaring what components we want to be used by passing them to &lt;ShoppingCart /&gt; directly as children ?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9e4e723fc38b8898023865e873450909/href">https://medium.com/media/9e4e723fc38b8898023865e873450909/href</a></iframe><p>Internally, &lt;ShoppingCart /&gt; maps over the children cloning the click handler and direction prop onto each item.</p><p>If we later decide that certain items should use a different click handler, we can simply override the onClick passed in to &lt;ShoppingCart /&gt; by specifying the exception directly on the item that requires differentiation:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b4ed41212487174608d64090b2d376b0/href">https://medium.com/media/b4ed41212487174608d64090b2d376b0/href</a></iframe><p>On top of the immediate improvement to readability, we start to see some of the benefits of composition.</p><p>Let’s say we have an added requirement to display one of the item’s as an expandable card. With our new implementation, it’s as simple as passing the new component as an additional child:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d105e754a81dc1d420973b48aefa07d8/href">https://medium.com/media/d105e754a81dc1d420973b48aefa07d8/href</a></iframe><p>Because no assumptions have been made by &lt;ShoppingCart /&gt; about which components should be rendered, so long as the children passed to it are built to accept the same props, everything will continue to work.</p><p>Let’s take a deeper look at what’s going on beneath the hood.</p><h3>The Code:</h3><p>As you saw in the previous examples, we have updated &lt;ShoppingCart /&gt; to take the cart items as children instead of as a regular prop. To support this change, our new <strong>ShoppingCart.js </strong>file now looks as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/853fa86abf671078ad0267291910334d/href">https://medium.com/media/853fa86abf671078ad0267291910334d/href</a></iframe><p>The first things you will notice are the usage of React.Children.map(), React.isValidElement(), and React.cloneElement() in our renderItems method. The second major change is that we now read the list of items through this.props.children instead of this.props.items. In it’s simplest form, children is really just another way to pass props. It just so happens that it’s a more intuitive way to pass JSX which is why it’s used here.</p><p>Let’s break things down further.</p><p><strong>First</strong>, we use React.Children.map() to loop over each child:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9bd42f852d60f1f1b681b04affe91cc5/href">https://medium.com/media/9bd42f852d60f1f1b681b04affe91cc5/href</a></iframe><p>We use this method instead of a native map because React.Children.map() knows how to handle cases when something other than a React element is passed. Remember how children is basically just another way to pass props? It can also be used to pass things like strings, and functions in which case calling a native map on it would cause an error:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WxuWukVXXs5AJ4zfIi4Ltg.png" /></figure><p><strong>Next</strong>, we use React.isValidElement(child) to check if the item from the current iteration of the map is in fact a valid React element:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f214e0d27e10f605beddbfa33ae84b9f/href">https://medium.com/media/f214e0d27e10f605beddbfa33ae84b9f/href</a></iframe><p>This will guard against cases when something like a string or a number is passed.</p><p><strong>Finally</strong>, we use React.cloneElement(child, [props]) to create a copy of the element, injecting additional feature specific props from &lt;ShoppingCart /&gt; into the clone:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/599c906e5043a87fcefe3b557d2a37c1/href">https://medium.com/media/599c906e5043a87fcefe3b557d2a37c1/href</a></iframe><p>In our example, we use the index from the React.Children.map() method to determine whether the child is the active item. We also apply a custom onClick handler which sets the new activeItemIndex to the index of whatever child was clicked. The click handler then does a check to see if the child was explicitly passed an onClick handler of it’s own, in which case we then proceed to call it to propagate the event. Otherwise we set it to trigger the default handler passed in as a prop to &lt;ShoppingCart /&gt;.</p><p>Putting all the pieces together, what we are left with is an array of cloned children that have feature specific props from &lt;ShoppingCart /&gt; injected into them:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4195fd3fdad1a3e5a9470483751c0dfb/href">https://medium.com/media/4195fd3fdad1a3e5a9470483751c0dfb/href</a></iframe><p>Compound components provide a powerful way to create reusable, consumer centric React components. They give developers a way to separate the business logic for a feature from the rendering logic which ultimately leads to a cleaner and more expressive component API.</p><p>For more information about compound components and an example of them in action, see the sections below.</p><h3>Codepen:</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fdane_s%2Fembed%2Fpreview%2FEeOOLX%3Fheight%3D600%26slug-hash%3DEeOOLX%26default-tabs%3Djs%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io%26embed-version%3D2&amp;url=https%3A%2F%2Fcodepen.io%2Fdane_s%2Fpen%2FEeOOLX%3Feditors%3D1010&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fm.cdpn.io%2Fscreenshot-coming-soon-small.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/d4bec3ae5849b1f02cc16fd96e00a5c5/href">https://medium.com/media/d4bec3ae5849b1f02cc16fd96e00a5c5/href</a></iframe><h3>More resources:</h3><ul><li>Ryan Florence — Compound components (<a href="https://www.youtube.com/watch?v=hEGg-3pIHlE">https://www.youtube.com/watch?v=hEGg-3pIHlE</a>)</li><li>Official React docs (<a href="https://reactjs.org/docs/react-api.html">https://reactjs.org/docs/react-api.html</a>)</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a6e54b5c9992" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Persisting data with localStorage and Redux middleware]]></title>
            <link>https://medium.com/@Dane_s/persisting-data-with-localstorage-and-redux-middleware-4760fd6afdef?source=rss-790a919608a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/4760fd6afdef</guid>
            <category><![CDATA[middleware]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Dane Sirois]]></dc:creator>
            <pubDate>Wed, 30 Aug 2017 04:17:11 GMT</pubDate>
            <atom:updated>2019-01-31T21:15:52.765Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y-AwMg57M9cWGB3G6pauSQ.jpeg" /></figure><p>LocalStorage is one of many powerful tools at your disposal as a Web Developer. If you need to persist data across sessions, localStorage is a great place to do it. For example, you may wish to persist a theme, or other UI related data so that when a user leaves your app, their experience is saved allowing you to restore from their previous session.</p><p>In the following section, I am going to talk about how to use localStorage and where it fits within your application.</p><h3>Enter Redux middleware:</h3><p>One implementation that I have found to work well within the context of a Redux application is to do the majority of your localStorage interaction in your Redux middleware. (If you are not familiar with middleware, check out this in-depth article: <a href="https://medium.com/@meagle/understanding-87566abcfb7a">https://medium.com/@meagle/understanding-87566abcfb7)</a>.</p><p>Redux middleware allows you to intercept your actions by running them through a block of code before they hit your reducers. This is a great place to interact with localStorage. Simply create a listener for an action and read from its payload to persist data.</p><blockquote>&gt; create a listener for an action and read from it’s payload to persist data</blockquote><p>Heres an example of intercepting an action to change the app’s current theme:</p><p><em>components/theme_switcher.js:</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7899f87950b7e8d3a69a51238947f296/href">https://medium.com/media/7899f87950b7e8d3a69a51238947f296/href</a></iframe><p><em>middleware/CHANGE_THEME.js</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/04567532f03a0621d5c0f8488652683e/href">https://medium.com/media/04567532f03a0621d5c0f8488652683e/href</a></iframe><p>In your applications initialize file, you can then configure it to dispatch an action to read the previous theme from localStorage upon connection:</p><p><em>initialize.js</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c699a53a1a07a57938d75f504cb8595e/href">https://medium.com/media/c699a53a1a07a57938d75f504cb8595e/href</a></iframe><h3>To summarize:</h3><p>Redux middleware provides a platform for centralizing your use of localStorage and is a powerful way to extend the utility of your actions.</p><p><strong>Use localStorage when:</strong></p><ol><li>you need to securely persist data</li><li>you need support across browsers (IE. 8+)</li><li>you need to cache relatively large datasets (up to 5mb)</li><li>you want a straightforward API</li></ol><p><strong>Use middleware when:</strong></p><ol><li>you use Redux</li><li>you want to centralize your use of localStorage</li><li>you want to extend the utility of your actions</li></ol><p>See more:</p><p><a href="https://developer.mozilla.org/en/docs/Web/API/Window/localStorage">https://developer.mozilla.org/en/docs/Web/API/Window/localStorage</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4760fd6afdef" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>