<?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 Fox Donut on Medium]]></title>
        <description><![CDATA[Stories by Fox Donut on Medium]]></description>
        <link>https://medium.com/@foxdonut00?source=rss-d580173afc09------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Ri_ZIvtdx4-ZkB5-.</url>
            <title>Stories by Fox Donut on Medium</title>
            <link>https://medium.com/@foxdonut00?source=rss-d580173afc09------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 06:04:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@foxdonut00/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[Addressing Performance Concerns in Meiosis]]></title>
            <link>https://medium.com/@foxdonut00/addressing-performance-concerns-in-meiosis-789466cfed6b?source=rss-d580173afc09------2</link>
            <guid isPermaLink="false">https://medium.com/p/789466cfed6b</guid>
            <category><![CDATA[single-page-applications]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Fox Donut]]></dc:creator>
            <pubDate>Mon, 28 May 2018 12:44:48 GMT</pubDate>
            <atom:updated>2018-05-28T12:44:48.033Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Not an issue for most of the time, easy to address issue for the rest of the time. Avoid premature optimization!</blockquote><p>Following my <a href="https://medium.com/@foxdonut00/you-dont-need-redux-mobx-rxjs-cerebral-6a735b150a02">first article</a>, the most frequently asked question people have once they’ve looked at <a href="http://meiosis.js.org/">the Meiosis pattern</a> is “what about performance?” This question arises naturally because Meiosis is based on re-rendering the whole view on every update.</p><h4>Virtual DOM Libraries Minimize Real DOM Updates</h4><p>The majority of the time, re-rendering the whole view is <strong>not</strong> <strong>a performance concern</strong>. After all, this is what virtual DOM libraries such as React are good at: determining the <strong>minimal</strong> changes needed on the real DOM to reflect the representation described by the virtual DOM.</p><h4>Producing a Virtual DOM Representation Is Cheap</h4><p>Moreover, producing the virtual DOM representation is generally fast enough that it isn’t a performance bottleneck. When you consider everything else that is going on in a web application — network requests, database access, and so on — the JavaScript code that creates the virtual DOM view is not often at the top of time consumption.</p><h4>(Re-)Consider Your User Interface Design</h4><p>If you determine that the re-rendering of a certain area of your web application <strong>is</strong> causing a performance problem, consider whether your user interface is addressing the needs of your users.</p><p>If a table with thousands of rows of data is responsible for slowing down your application, ask yourself whether users want to look at all that data at once on the page. Perhaps pagination would be more appropriate? Or, think about whether adding some filters will help users narrow down what they are looking for.</p><h4>You Can Easily Prevent Re-Rendering</h4><p>If, despite all that has been said so far, you find yourself in a situation where you truly want to prevent re-rendering of an area of the view, you can easily do that. Again, please don’t do this “just in case”; only when the performance gain truly has an impact on the user experience.</p><p>To prevent re-rendering of a section of the view, you can let the virtual DOM library know whether or not that section needs re-rendering. One way to do this is to use <strong>immutable</strong> objects for the model. Then, you can use a strict equals comparison, next === previous, to determine whether or not the model has changed. If it has not, you can skip the re-rendering of that section of the view.</p><h4>Using React’s PureComponent</h4><p>React’s <a href="https://reactjs.org/docs/react-api.html#reactpurecomponent">PureComponent</a> automatically implements the shouldComponentUpdate() method to return true or false. This method determines whether or not to re-render the component. It does so with a shallow comparison of props and state. Using immutable objects makes this comparison fast and easy: when the model has changed, the strict equals test, ===, will return false.</p><p>To take advantage of this, we must do two things:</p><ol><li>Use class extends React.PureComponent to define the component</li><li>Return a <strong>new object instance</strong> from update() instead of using mutation. For example:</li></ol><p>update(model =&gt; Object.assign({}, model, { value: newValue }))</p><p>Now, the component’s render method will not be called if the component’s model has not changed.</p><p>You can see a working example in the <a href="http://meiosis.js.org/wiki/05-Lifecycle-and-other-Techniques-B-Preventing-Rerenders.html">Preventing Re-renders</a> section of the <a href="http://meiosis.js.org/wiki/toc.html">Meiosis Wiki</a>.</p><h4>Using Other Virtual DOM libraries</h4><p>If you are using a virtual DOM library other than React, look at its documentation to find the equivalent way of preventing re-rendering of sections of the view based on whether or not the model has changed.</p><p>For example, in the <a href="/service/file:///Users/freddy/fd/git/foxdonut/meiosis/wiki/dist/05-Lifecycle-and-other-Techniques-B-Preventing-Rerenders.html">Preventing Re-renders</a> section mentioned above, I also demonstrate how to use <a href="https://mithril.js.org/lifecycle-methods.html#onbeforeupdate">Mithril’s onbeforeupdate lifecycle method</a> to achieve the same result.</p><h4>Conclusion</h4><p>Again, remember to avoid premature optimization. Virtual DOM libraries are good at minimizing real DOM updates, which means that re-rendering the view in the Meiosis pattern generally does not affect performance. If you do identify a problematic section, it is simple to minimize re-renders.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=789466cfed6b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[You Don’t Need Redux, MobX, RxJS, Cerebral]]></title>
            <link>https://medium.com/@foxdonut00/you-dont-need-redux-mobx-rxjs-cerebral-6a735b150a02?source=rss-d580173afc09------2</link>
            <guid isPermaLink="false">https://medium.com/p/6a735b150a02</guid>
            <category><![CDATA[single-page-applications]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Fox Donut]]></dc:creator>
            <pubDate>Sun, 29 Apr 2018 20:55:29 GMT</pubDate>
            <atom:updated>2018-04-29T20:55:29.035Z</atom:updated>
            <content:encoded><![CDATA[<h4>For state management, try this simple pattern instead of a library</h4><p>Don’t get me wrong. Those libraries are great. But I’m suggesting a different, unique approach.</p><p>I know what you’re thinking: <em>Redux alternatives are a dime a dozen.</em> But this isn’t yet another library. In fact, <strong>it’s not a library at all</strong>.</p><p>It’s just a simple pattern: <a href="http://meiosis.js.org/">Meiosis</a>.</p><h3>Why a Pattern?</h3><p>Using a pattern instead of a library means that you have more freedom. You are not dependent on a library’s features, bugfixes, and release dates. You are not worried about backward compatibility, deprecation, upgrade migration paths, or project abandonment. You are never waiting for a missing feature.</p><h3>No More Black Box</h3><p>Sometimes when using a framework or library, you get that uneasy “black box” feeling where you stop knowing what’s happening with your code. You call a framework function, something magical happens in the black box, and out comes the result. If the result is unexpected, you have to start searching for answers, or (gasp) digging into the framework’s source code.</p><p>With Meiosis, you can easily follow everything that is happening with the code. <strong>Because there is no black box</strong>. You can fully and completely implement the pattern from scratch, so you know exactly what the code is doing. There is no mystery. You get that satisfying feeling of being in control, of understanding how all of the code works.</p><h3>No Library Lock-In</h3><p>Using a pattern means that you are not tying your state management code to a library-specific API. No more annotations, wrapping in proprietary objects, using a dozen different stream operators, or piling up plugins, middleware, and other dependencies.</p><p>Instead, Meiosis is based on first principles: use plain JavaScript objects and functions to manage state in your web application. No import or require of a state management library.</p><p>This also means that you can achieve the equivalent of such things as <a href="https://reactjs.org/docs/context.html">React Context</a> and <a href="https://reactjs.org/docs/render-props.html">Render Props</a> without having to use React or even needing to upgrade your version of React to use these types of features.</p><h3>Less Boilerplate</h3><p>No more action constants, if/else or switch statements, providers, connectors, thunks, sagas, annotations, mappers, etc.</p><p>No special code needed for asynchronous actions!</p><h3>Use with any virtual DOM library</h3><p>It is <strong>very</strong> simple to use the Meiosis pattern with any virtual DOM library: <a href="http://reactjs.org/">React</a>, <a href="https://preactjs.com/">Preact</a>, <a href="https://infernojs.org/">Inferno</a>, <a href="http://mithril.js.org/">Mithril</a>, <a href="https://github.com/snabbdom/snabbdom">Snabbdom</a>, and so on. Other view libraries such as <a href="https://github.com/Polymer/lit-html">lit-html</a> and <a href="https://viperhtml.js.org/">hyperHTML</a> work just as well.</p><p>All you need to know is the library’s function to render/re-render into a DOM node. For example, with React this is ReactDOM.render. So really it’s one line of code that sets up the pattern with a view library.</p><h3>So What is the Meiosis Pattern?</h3><p>The <a href="http://meiosis.js.org/">Meiosis</a> pattern is a reactive loop, illustrated below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/387/1*3F5JXTPh2jEmkZvkSGw6jw.png" /><figcaption>Meiosis Reactive Loop</figcaption></figure><ul><li>We start with a <strong>model</strong>, which is a plain JavaScript object. This represents our application state.</li><li>Then, we have a <strong>view</strong>, which is a function of the model that produces a virtual-DOM node suitable for our chosen view library to render. Above, you can see that with React, this would be ReactDOM.render.</li><li>When an event happens, such as the user clicking on a button, we call an update function to produce an updated model.</li><li>The view is automatically re-rendered, by calling view and ReactDOM.render.</li></ul><h3>What Do We Gain?</h3><p>By using the Meiosis pattern, we reach some important goals in implementing a web application:</p><ul><li>We have a single root model. This is our application state, as a plain JavaScript object. This is our <strong>single source of truth</strong>.</li><li>The view is a function of the model. <strong>The view can be fully determined from the model</strong>.</li><li>We have a <strong>controlled, well-defined way</strong> to update the model.</li><li>Updating the model <strong>automatically re-renders the view</strong>. Because we implement the pattern ourselves, we know exactly how this works.</li></ul><h3>Implementing the Meiosis Pattern</h3><p>The Meiosis Pattern can be implemented in different ways. First, you decide how you want to implement the reactive loop, and second, you choose how to structure model updates.</p><p>For most of the examples, I implement the reactive loop with a <strong>simple</strong>, <strong>minimal </strong>stream library. I <strong>only </strong>use map and scan, and I only use them in <strong>one</strong> place. You do <strong>not </strong>have to use stream operators anywhere else in the application!</p><p>However, you can also implement a bare-bones map and scan from scratch with just a handful of lines of code, and that is sufficient to implement the Meiosis Pattern.</p><p>I explain all of this in the <a href="http://meiosis.js.org/tutorial/toc.html">Meiosis Tutorial</a>.</p><h3>Time-Travel Tool: The Meiosis Tracer</h3><p>Meiosis is not a library. However, Meiosis <em>does</em> include a time-travel debugging tool, called the <a href="https://github.com/foxdonut/meiosis-tracer">Meiosis Tracer</a>. If you are already using a time-travel tool, know that you don’t have to abandon that possibility when using Meiosis.</p><p>You can see an example of the tracer below. Notice how you can not only trace back and forth through the history of application states, you can even directly type in a model and see the resulting view.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/816/1*3EzZOAyfpvQU9hugsJ3s7g.gif" /><figcaption>Routing Example — With Time Travel!</figcaption></figure><p>This example also demonstrates that routing can be implemented with Meiosis such that the application state still fully determines the view, including the route in the location bar.</p><h3>Yes, You Can Do That With Meiosis</h3><p>Meiosis is a simple pattern. Beyond that, Meiosis is documentation and examples to show how to achieve useful features in web application development:</p><ul><li>Computed properties</li><li>Reusable components as plain objects with functions</li><li>Nesting component models within the single state object</li><li>Routing</li><li><a href="https://reactjs.org/docs/render-props.html">Render Props</a> equivalent</li><li><a href="https://reactjs.org/docs/context.html">React Context</a> equivalent</li><li>Using view library lifecycle methods</li><li>Imperative widgets (Bootstrap, jQuery, …)</li><li>Preventing re-renders of unchanged components</li><li>and so on.</li></ul><h3>Try It Out</h3><p>You can learn the <a href="http://meiosis.js.org/">Meiosis</a> pattern with the <a href="http://meiosis.js.org/tutorial/toc.html">Meiosis Tutorial</a>. Once you are comfortable with the pattern, you can learn more techniques by visiting the <a href="https://github.com/foxdonut/meiosis/wiki">Meiosis Wiki</a>.</p><p>Give it a try. I hope you find it useful!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a735b150a02" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>