<?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" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ features - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ features - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Sat, 23 May 2026 11:01:13 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/features/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ React 18 New Features – Concurrent Rendering, Automatic Batching, and More ]]>
                </title>
                <description>
                    <![CDATA[ React 18 was released in March 2022. This release focuses on performance improvements and updating the rendering engine.  React 18 sets the foundation for concurrent rendering APIs that future React features will be built on top of.  In this tutorial... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/react-18-new-features/</link>
                <guid isPermaLink="false">66b99d004ed1a5964b77008f</guid>
                
                    <category>
                        <![CDATA[ features ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                    <category>
                        <![CDATA[ update  ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Shruti Kapoor ]]>
                </dc:creator>
                <pubDate>Thu, 14 Apr 2022 21:58:00 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/04/featured.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>React 18 was released in March 2022. This release focuses on performance improvements and updating the rendering engine. </p>
<p>React 18 sets the foundation for concurrent rendering APIs that future React features will be built on top of. </p>
<p>In this tutorial, I will give a quick guide of the features released in React 18, and explain a few major concepts such as concurrent rendering, automatic batching and transitions.</p>
<h3 id="heading-react-18-feature-quick-guide">React 18 Feature Quick Guide</h3>
<table>
<thead>
<tr>
<th>Category</th>
<th>Feature</th>
</tr>
</thead>
<tbody>
<tr>
<td>Concept</td>
<td>Concurrent React</td>
</tr>
<tr>
<td>Features</td>
<td>Automatic Batching,  Transitions, Suspense on the server</td>
</tr>
<tr>
<td>APIs</td>
<td>createRoot, hydrateRoot, renderToPipeableStream, renderToReadableStream</td>
</tr>
<tr>
<td>Hooks</td>
<td>useId, useTransition, useDeferredValue, useSyncExternalStore, useInsertionEffect</td>
</tr>
<tr>
<td>Updates</td>
<td>Strict mode</td>
</tr>
<tr>
<td>Deprecated/discouraged</td>
<td>ReactDOM.render, renderToString</td>
</tr>
</tbody>
</table>

<p>Now let's look at each of these updates in more detail. But first, if you haven't already, let's learn how to update React.</p>
<h2 id="heading-how-to-upgrade-to-react-18">How to upgrade to React 18</h2>
<p>Install React 18 and React DOM from npm or yarn, like this:</p>
<p><code>npm install react react-dom</code></p>
<p>Then, you'll want to use <code>createRoot</code> instead of <code>render</code>.</p>
<p>In your index.js, update <code>ReactDOM.render</code> to <code>ReactDOM.createRoot</code> to create a root, and render your app using root.</p>
<p>Here's what it would look like in React 17:</p>
<pre><code class="lang-jsx"><span class="hljs-keyword">import</span> ReactDOM <span class="hljs-keyword">from</span> <span class="hljs-string">'react-dom'</span>;
<span class="hljs-keyword">import</span> App <span class="hljs-keyword">from</span> <span class="hljs-string">'App'</span>;

<span class="hljs-keyword">const</span> container = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'app'</span>);

ReactDOM.render(<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">App</span> /&gt;</span></span>, container);
</code></pre>
<p>And here's what it looks like in React 18:</p>
<pre><code class="lang-jsx"><span class="hljs-keyword">import</span> ReactDOM <span class="hljs-keyword">from</span> <span class="hljs-string">'react-dom'</span>;
<span class="hljs-keyword">import</span> App <span class="hljs-keyword">from</span> <span class="hljs-string">'App'</span>;

<span class="hljs-keyword">const</span> container = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'app'</span>);

<span class="hljs-comment">// create a root</span>
<span class="hljs-keyword">const</span> root = ReactDOM.createRoot(container);

<span class="hljs-comment">//render app to root</span>
root.render(<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">App</span> /&gt;</span></span>);
</code></pre>
<h2 id="heading-concurrency-in-react-18">Concurrency in React 18</h2>
<p>To understand concurrency, let’s consider <a target="_blank" href="https://github.com/reactwg/react-18/discussions/46">this example</a> by Dan Abramov from React 18 Working group discussions.</p>
<p>Let’s say that we need to call two people – Alice and Bob. In a non-concurrent setting, we can only have one call at a time. We would first call Alice, end the call, and then call Bob. </p>
<p>This is fine when calls are short, but if call with Alice has a long waiting period (such as on-hold), this can be a time sink.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/io6s64j30dt3na6yxzp4.png" alt="Non-concurrent call" width="1808" height="418" loading="lazy">
<em>Image showing that in a typical non-concurrent phone conversation, you have to wait for a call to be over before starting a new call.</em></p>
<p>In a concurrent setting, we could call Alice and, once we were put on hold, we could then call Bob. </p>
<p>This doesn’t mean that we are talking to two people at the same time. It just means that we can have two or more concurrent calls at the same time and decide which call is more important.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v4zgvausl6go1ur769cd.png" alt="Concurrent call" width="1580" height="590" loading="lazy">
<em>Image showing phone conversation between Alice and Bob can be concurrent, by placing a call on hold and answering a more urgent call with Bob first.</em></p>
<p>Similarly, in React 18 with concurrent rendering, React can interrupt, pause, resume, or abandon a render. This allows React to respond to the user interaction quickly even if it is in the middle of a heavy rendering task. </p>
<p>Before React 18, rendering was a single, uninterrupted, synchronous transaction and once rendering started, it couldn’t be interrupted.</p>
<p>Concurrency is a foundational update to React’s rendering mechanism. Concurrency allows React to interrupt rendering. </p>
<p>React 18 introduces the foundation of concurrent rendering and new features such as suspense, streaming server rendering, and transitions are powered by concurrent rendering.</p>
<h2 id="heading-new-react-18-features">New React 18 Features</h2>
<h3 id="heading-automatic-batching">Automatic Batching</h3>
<p>React 18 features automatic batching. To understand batching, let’s consider the example of grocery shopping from the <a target="_blank" href="https://github.com/reactwg/react-18/discussions/46#discussioncomment-846694">same React Working Group discussion</a>. </p>
<p>Let’s say that you are making pasta for dinner. If you were to optimize your grocery trip, you would create a list of all the ingredients that you need to buy, make a trip to the grocery store, and get all your ingredients in one trip. </p>
<p>This is batching. Without batching, you would start cooking, find out you need an ingredient, go to the grocery store and buy the ingredient, come back and continue cooking, only to find out you need another ingredient, go to the grocery store...and drive yourself crazy.</p>
<p>In React, batching helps to reduce the number of re-renders that happen when a state changes, when you call <code>setState</code>. Previously, React batched state updates in event handlers, for example:</p>
<pre><code class="lang-jsx"><span class="hljs-keyword">const</span> handleClick = <span class="hljs-function">() =&gt;</span> {
setCounter();
setActive();
setValue();
}

<span class="hljs-comment">//re-rendered once at the end.</span>
</code></pre>
<p>However, state updates that happened outside of event handlers were not batched. For example, if you had a promise or were making a network call, the state updates would not be batched. Like this:</p>
<pre><code class="lang-jsx">fetch(<span class="hljs-string">'/network'</span>).then( <span class="hljs-function">() =&gt;</span> {
setCounter(); <span class="hljs-comment">//re-rendered 1 times</span>
setActive();  <span class="hljs-comment">//re-rendered 2 times</span>
setValue();   <span class="hljs-comment">//re-rendered 3 times</span>
});

<span class="hljs-comment">//Total 3 re-renders</span>
</code></pre>
<p>As you can tell, this is not performant. React 18 introduces automatic batching which allows all state updates – even within promises, setTimeouts, and event callbacks – to be batched. This significantly reduces the work that React has to do in the background. React will wait for a micro-task to finish before re-rendering.</p>
<p>Automatic batching is available out of the box in React, but if you want to opt-out you can use <code>flushSync</code>.</p>
<h3 id="heading-transitions">Transitions</h3>
<p>Transitions can be used to mark UI updates that do not need urgent resources for updating. </p>
<p>For example, when typing in a typeahead field, there are two things happening: a blinking cursor that shows visual feedback of your content being typed, and a search functionality in the background that searches for the data that is typed.</p>
<p>Showing a visual feedback to the user is important and therefore urgent. Searching is not so urgent, and so can be marked as non-urgent. </p>
<p>These non-urgent updates are called transitions. By marking non-urgent UI updates as "transitions", React will know which updates to prioritize. This makes it easier to optimize rendering and get rid of stale rendering.</p>
<p>You can mark updates as non-urgent by using <code>startTransition</code>. Here is an example of what a typeahead component would like when marked with transitions:</p>
<pre><code class="lang-jsx"><span class="hljs-keyword">import</span> { startTransition } <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;

<span class="hljs-comment">// Urgent: Show what was typed</span>
setInputValue(input);

<span class="hljs-comment">// Mark any non-urgent state updates inside as transitions</span>
startTransition(<span class="hljs-function">() =&gt;</span> {
  <span class="hljs-comment">// Transition: Show the results</span>
  setSearchQuery(input);
});
</code></pre>
<h4 id="heading-how-are-transitions-different-from-debouncing-or-settimeout">How are transitions different from debouncing or setTimeout?</h4>
<ol>
<li>startTransition executes immediately, unlike setTimeout.</li>
<li>setTimeout has a guaranteed delay, whereas startTransition's delay depends on the speed of the device, and other urgent renders.</li>
<li>startTransition updates can be interrupted unlike setTimeout and won't freeze the page.</li>
<li>React can track the pending state for you when marked with startTransition.</li>
</ol>
<h3 id="heading-suspense-on-the-server">Suspense on the server</h3>
<p>React 18 introduces:</p>
<ol>
<li>Code splitting on the server with suspense</li>
<li>Streaming rendering on the server</li>
</ol>
<h4 id="heading-client-rendering-vs-server-rendering">Client rendering vs server rendering</h4>
<p>In a client-rendered app, you load the HTML of your page from the server along with all the JavaScript that is needed to run the page, and make it interactive. </p>
<p>If, however, your JavaScript bundle is huge, or you have a slow connection, this process can take a long time and the user will be waiting for the page to become interactive, or to see meaningful content.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ccfllg117u8ycgnl5mv7.png" alt="Illustration of client rendering flow. Source: React Conf 2021 Streaming Server Rendering with Suspense by Shaundai Person https://www.youtube.com/watch?v=pj5N-Khihgc" width="1944" height="956" loading="lazy">
<em>In a client rendering flow, a user has to wait a long time before the page becomes interactive. <a target="_blank" href="https://www.youtube.com/watch?v=pj5N-Khihgc">Source</a>: React Conf 2021 <strong>Streaming Server Rendering with Suspense</strong> by Shaundai Person</em></p>
<p>For optimizing the user experience and avoiding the user having to sit on a blank screen, we can use server rendering. </p>
<p>Server rendering is a technique where you render the HTML output of your React components on the server and send HTML from the server. This lets the user view some UI while JS bundles are loading and before the app becomes interactive. </p>
<p>For a detailed overview of client vs server rendering, <a target="_blank" href="https://www.youtube.com/watch?v=pj5N-Khihgc">check out Shaundai Person’s React Conf 2021 talk</a>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/4.jpeg" alt="Image" width="600" height="400" loading="lazy">
<em>In a server rendering flow, we can display meaningful data to the user much faster by sending HTML from the server. <a target="_blank" href="https://www.youtube.com/watch?v=pj5N-Khihgc">Source</a>: React Conf 2021 <strong>Streaming Server Rendering with Suspense</strong> by Shaundai Person</em></p>
<p>Server rendering further enhances the user experience of loading the page and reducing time to interactive.</p>
<p>Now what if most of your app is fast except for one part? Maybe this part loads data slowly, or maybe it needs to download a lot of JS before it gets interactive.</p>
<p>Before React 18, this part was often the bottleneck of the app, and would increase the time it took to render the component. </p>
<p>One slow component can slow down the entire page. This is because server rendering was all or nothing – you couldn’t tell React to defer loading of a slow component and couldn’t tell React to send HTML for other components.</p>
<p>React 18 adds support for Suspense on server. With the help of suspense, you can wrap a slow part of your app within the Suspense component, telling React to delay the loading of the slow component. This can also be used to specify a loading state that can be shown while it's loading.</p>
<p>In React 18, one slow component doesn’t have to slow the render of your entire app. With Suspense, you can tell React to send HTML for other components first along with the HTML for the placeholder, like a loading spinner. Then when the slow component is ready and has fetched its data, the server renderer will pop in its HTML in the same stream.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/taxrh7y9ylx0l68u2btx.png" alt="You can add suspense to a slow server rendered component in React 18" width="1930" height="986" loading="lazy">
<em>Image showing that suspense on the server can allow a slow component to show a loading state while others are fully rendered.</em></p>
<p>This way the user can see the skeleton of the page as early as possible and see it gradually reveal more content as more pieces of HTML Arrive. </p>
<p>All of this happens before any JS or React loads on the page, which significantly improves the user experience and user-perceived latency.</p>
<h3 id="heading-strict-mode">Strict mode</h3>
<p>Strict mode in React 18 will simulate mounting, unmounting, and re-mounting the component with a previous state. This sets the ground for reusable state in the future where React can immediately mount a previous screen by remounting trees using the same component state before unmounting. </p>
<p>Strict mode will ensure components are resilient to effects being mounted and unmounted multiple times.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In a summary, React 18 sets the foundation for future releases and focusses on improving the user experience. </p>
<p>Upgrading to React 18 should be straightforward and your existing code should not break after the update. The upgrade process should not take more than an afternoon. </p>
<p>Give it a go and let me know what you think!</p>
<p>Sources:</p>
<ol>
<li><a target="_blank" href="https://github.com/reactjs/rfcs/blob/react-18/text/0000-react-18.md">React RFC</a></li>
<li><a target="_blank" href="https://dev.to/shrutikapoor08/what-s-new-in-react-18-1713">My previous React 18 post</a></li>
<li><a target="_blank" href="https://reactjs.org/blog/2022/03/29/react-v18.html">React V18 blog</a></li>
<li><a target="_blank" href="https://www.youtube.com/watch?v=ytudH8je5ko">React Conf 2021 - React for App developers</a></li>
<li><a target="_blank" href="https://www.youtube.com/watch?v=pj5N-Khihgc">React Conf 2021 - Streaming Server Rendering with Suspense</a></li>
</ol>
<p>If you enjoyed this article, give it a ❤️ so others can find it too.</p>
<ul>
<li>For more frequent tips, <a target="_blank" href="http://twitter.com/shrutikapoor08">stay in touch on Twitter</a></li>
<li><a target="_blank" href="http://tinyletter.com/shrutikapoor">Want articles like this directly in your inbox?</a></li>
</ul>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Unleash the Power of Feature Based JS Development — with feature-u V1 ]]>
                </title>
                <description>
                    <![CDATA[ By Kevin Bridges This article is an introduction to a new JS library called feature-u, that facilitates feature-based development in your React project. Note_: On 8/14/2018 feature-u V1 was released, that re-designed Cross Feature Communication to i... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/feature-u-v1-b84e2372c5e6/</link>
                <guid isPermaLink="false">66d45f63b6b7f664236cbdeb</guid>
                
                    <category>
                        <![CDATA[ features ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Libraries ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Utilities ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Sat, 22 Sep 2018 00:31:55 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*79altp9cNA9V31OonG_pSA.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Kevin Bridges</p>
<p>This article is an introduction to a new JS library called <a target="_blank" href="https://feature-u.js.org/">feature-u</a>, that <em>facilitates feature-based development in your <a target="_blank" href="https://reactjs.org/">React</a> project</em>.</p>
<blockquote>
<p><strong><em>Note</em></strong>_: On 8/14/2018 <a target="_blank" href="https://feature-u.js.org/1.0.0/history.html#v1_0_0"><strong>feature-u V1</strong></a> was released, that re-designed <a target="_blank" href="https://feature-u.js.org/1.0.1/crossCommunication.html">Cross Feature Communication</a> to include <a target="_blank" href="https://feature-u.js.org/1.0.1/crossCommunication.html#ui-composition">UI Composition</a> as a core offering. This article covers the V1 release. The first article, based on <a target="_blank" href="https://feature-u.js.org/0.1.3/history.html#v0_1_3">feature-u V0</a>, can be found <a target="_blank" href="http://bit.ly/feature-u">here</a>. We are very excited about this update because it <strong>promotes one solution for all feature collaboration</strong>!_</p>
</blockquote>
<p>Most developers would agree that organizing your project by feature is much preferred over type-based patterns. Because <strong>application domains grow</strong> in the real world, project <strong>organization by type simply doesn’t scale</strong>, <em>it just becomes unmanageable</em>!</p>
<p>There are a number of good articles that discuss this topic with insight on feature-based design and structure (see: <a class="post-section-overview" href="#8e25">References</a> below). However when it comes to the implementation, you are pretty much left to fend for yourself.</p>
<p><a target="_blank" href="https://feature-u.js.org/"><strong>feature-u</strong></a> is a utility library that manages and streamlines this process. It automates the mundane details of managing features and helps to promote features that are truly <strong>plug-and-play</strong>.</p>
<p>This article provides a foundation of <a target="_blank" href="https://feature-u.js.org/"><strong>feature-u</strong></a> concepts and terminology, building insight into how you can promote individual <strong>plug-and-play</strong> features within your project. It makes the case for why <strong>feature-u</strong> was developed and gives you a better understanding of it’s benefits.</p>
<p>Check out the <a target="_blank" href="https://feature-u.js.org/">full docs</a>, <a target="_blank" href="https://github.com/KevinAst/feature-u">source</a>, and <a target="_blank" href="https://www.npmjs.com/package/feature-u">npm package</a>.</p>
<p><a target="_blank" href="https://feature-u.js.org/"><strong>feature-u</strong></a> opens new doors into the exciting world of feature-based development. It frees you up to <strong>focus your attention on the “business end” of your features</strong>!</p>
<h3 id="heading-at-a-glance">At a Glance</h3>
<p>For your convenience, this <strong>Table of Contents</strong> (TOC) links directly to <strong>each section. Also note that each section title links back to the TOC</strong>.</p>
<pre><code>Feature Based Development  Segregating Features  Feature Goals    Feature Runtime Consolidation    Feature CollaborationThe feature-u Solution  launchApp()  Feature <span class="hljs-built_in">Object</span>  aspects  Running the App    App Initialization    Framework Configuration    Launching Your Application  Cross Feature Communication  Feature Based UI Composition    Resource Contracts  Feature EnablementIn SummaryBenefitsReferences
</code></pre><blockquote>
<p><em>Please <strong>help me get the word</strong> <strong>out</strong> on <strong>feature-u</strong>. Your claps determine the distribution/promotion of this article. If you think <strong>feature-u</strong> has potential, please give this article multiple claps :-)</em></p>
</blockquote>
<h3 id="heading-feature-based-developmente98c"><a class="post-section-overview" href="#e98c">Feature Based Development</a></h3>
<p>At a 30,000 ft view, feature-based development (as in most software) is all about dissecting hard problems into smaller pieces. Even when I started my career <em>(back in the 70's)</em>, this was a prominent quote:</p>
<blockquote>
<p>“All problems in computer science can be solved by another level of indirection.” <strong>David Wheeler</strong></p>
</blockquote>
<p>By breaking up your application into features, each feature can focus on a more specific and isolated set of tasks. <strong>In some ways you can think of a feature as a “mini application”</strong>!</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*50bxcswJEzugLESSDiFW7w.jpeg" alt="Image" width="800" height="533" loading="lazy"></p>
<p>There are many design considerations in defining your feature boundaries. You can find several articles on this topic that provide insight on feature-based design.</p>
<p>For the most part, these considerations are part of the design of each individual project. While <strong>feature-u</strong> does not dictate overall design considerations, it does facilitate good feature-based principles (such as encapsulation). <em>This will be the focus of this article</em>.</p>
<h3 id="heading-segregating-featurese98c"><a class="post-section-overview" href="#e98c">Segregating Features</a></h3>
<p>If you are like me, when you think about feature-based development, the first thing that comes to mind is to isolate your code into feature directories.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*8GHt18xe1e1tG9VQOXTMRQ.png" alt="Image" width="800" height="470" loading="lazy"></p>
<p>In doing this your code is organized by what it accomplishes (i.e. features), rather than what it is (i.e. components, routes, logic, actions, reducers, selectors, etc.).</p>
<p>By segregating your features into individual directories, there is a semblance of isolation.</p>
<h3 id="heading-feature-goalse98c"><a class="post-section-overview" href="#e98c">Feature Goals</a></h3>
<p>Our goal is to <strong>encapsulate each feature</strong> in such a way as to make them truly <strong>plug-and-play</strong>. <em>But how is this accomplished</em>?</p>
<p>The directory structure is just a start. There are <strong>several hurdles</strong> that must be overcome to realize our goal …</p>
<ul>
<li>How do we encapsulate and isolate our features, while still allowing them to collaborate with one another?</li>
<li>How can selected features introduce start-up initialization (even injecting utility at the root DOM), without relying on some external startup process?</li>
<li>How can feature-based UI Composition be accomplished in an isolated and autonomous way?</li>
<li>How do we configure our chosen frameworks now that our code is so spread out?</li>
<li>How do we enable/disable selected features which are either optional, or require a license upgrade?</li>
</ul>
<p><strong>In short</strong>, how do we achieve a running application from these isolated features?</p>
<p>When you boil it all down, there are <strong>two overriding characteristics</strong> that must be accomplished to achieve our goals:</p>
<ol>
<li><code>[**Feature Runtime Consolidation**](#c8d1)</code>: <em>pulling our features back together into one running application</em></li>
<li><code>[**Feature Collaboration**](#abbc)</code>: <em>provide a mechanism by which our features can interact with one another</em></li>
</ol>
<p>As it turns out, <em>everything else is a byproduct of these two artifacts</em>. Let’s take a closer look at each of these items.</p>
<h3 id="heading-feature-runtime-consolidatione98c"><a class="post-section-overview" href="#e98c">Feature Runtime Consolidation</a></h3>
<p>Now that we have isolated our features into separate entities, how do we bring them back together so they run as <strong>one application</strong>? We must be able to pull and configure various aspects of our individual features, and “launch” them as a single homogeneous running application.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0*k1La5g-6jXlOCIP-.png" alt="Image" width="721" height="524" loading="lazy"></p>
<p>This concern can be further divided into two sub-concerns:</p>
<ul>
<li><code>[App Initialization](#d44a)</code><br>Some features may require certain startup initialization. As an example, a feature that encapsulates some DB abstraction will rely on a run-time setup of a DB service.<br>Certainly we don’t want to rely on some global app logic to accomplish this <em>(once again, we want our features to be encapsulated and self-sufficient)</em>.</li>
<li><code>[Framework Configuration](#c339)</code><br>If your application relies on other frameworks, chances are there are resources contained within each feature that must be accumulated and fed into the framework configuration process.<br>How is this accomplished?</li>
</ul>
<h3 id="heading-feature-collaboratione98c"><a class="post-section-overview" href="#e98c">Feature Collaboration</a></h3>
<p>The second characteristic (mentioned above) is <strong>Feature Collaboration</strong> — <em>providing a mechanism by which our features can interact with one another</em>.</p>
<p>A <strong>best practice</strong> of feature-based development <em>(to the extent possible)</em> is to <strong>treat each feature as an isolated implementation</strong>. Most aspects of a feature are internal to that feature’s implementation <em>(for example, actions are typically created and consumed exclusively by logic/reducers/components that are internal to that feature)</em>.</p>
<p>From this perspective, you can think of each feature as its <strong>own isolated mini application</strong>.</p>
<p>With that said, however, we know that <em>“</em><strong>no man is an island</strong><em>”</em>! Any given feature ultimately exists as part of a larger application. There are cases where a feature needs to promote a limited subset of its aspects to other features. For example, a feature may need to:</p>
<ul>
<li>be knowledgeable of some external state (via a selector)</li>
<li>emit or monitor actions of other features</li>
<li>consolidate component resources from other features — as in <strong>UI Composition</strong></li>
<li>invoke the API of other features</li>
<li>etc. etc. etc.</li>
</ul>
<p>These items form the basis of why <code>[**Cross Feature Communication**](#5369)</code> and <code>[**Feature Based UI Composition**](#a480)</code> are needed.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0*S6DWAwYUVlWsTR5Q.png" alt="Image" width="721" height="524" loading="lazy"></p>
<p>To complicate matters, as a general rule, <strong>JS imports should NOT cross feature boundaries</strong>. The reason being that this cross-communication should be <strong>limited to public access points</strong> — helping to <strong>facilitate true plug-and-play</strong>.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0*rUqXNI_dmUnyaPQn.png" alt="Image" width="721" height="524" loading="lazy"></p>
<p>Given all this then, <strong>how is Cross Feature Communication achieved</strong> <em>in a way that doesn’t break encapsulation</em>?</p>
<p>Features need a way to promote their <strong>Public Interface</strong> to other features, and consume other feature’s <strong>Public Assets</strong>.</p>
<h3 id="heading-the-feature-u-solutione98c"><a class="post-section-overview" href="#e98c">The feature-u Solution</a></h3>
<p>Let’s take a look at the solution <strong>feature-u</strong> provides for all of these goals. The following sections will build <strong>feature-u</strong> concepts incrementally.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*GBSlbLZegIq6vN-6tPY02A.jpeg" alt="Image" width="800" height="403" loading="lazy"></p>
<h3 id="heading-launchappe98c"><a class="post-section-overview" href="#e98c">launchApp()</a></h3>
<p><code>[launchApp()](https://feature-u.js.org/1.0.1/api.html#launchApp)</code> is an essential utility in <strong>feature-u</strong>. It is an agent, working on your behalf, which provides the foundation that <strong>accomplishes all the goals</strong> of <strong>feature-u</strong>! It facilitates both <code>[**Feature Runtime Consolidation**](#c8d1)</code> and <code>[**Feature Collaboration**](#abbc)</code>.</p>
<p>With this utility, <strong>your mainline startup process is extremely simple</strong> … it merely invokes <code>[launchApp()](https://feature-u.js.org/1.0.1/api.html#launchApp)</code>, and you are done!</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0*73_25clr2UP2Vbqb.png" alt="Image" width="721" height="524" loading="lazy"></p>
<p>The <code>[launchApp()](https://feature-u.js.org/1.0.1/api.html#launchApp)</code> function actually starts your application running, employing various hooks that drive BOTH <strong>App Initialization</strong> and <strong>Framework Configuration</strong>!</p>
<p>You can find <code>[launchApp()](https://feature-u.js.org/1.0.1/api.html#launchApp)</code> examples in the <code>[Usage](https://feature-u.js.org/1.0.1/usage.html#launchapp)</code> section, and <code>[Launching Your Application](https://feature-u.js.org/1.0.1/detail.html#launching-your-application)</code>.</p>
<p><strong>How does this work? What are the bindings to <code>[launchApp()](https://feature-u.js.org/1.0.1/api.html#launchApp)</code></strong>? ... <em>let's delve a bit deeper…</em></p>
<h3 id="heading-feature-objecte98c"><a class="post-section-overview" href="#e98c">Feature Object</a></h3>
<p>To accomplish this, each feature promotes a <code>[Feature](https://feature-u.js.org/1.0.1/api.html#Feature)</code> object <em>(using <code>[createFeature()](https://feature-u.js.org/1.0.1/api.html#createFeature)</code>)</em>, that catalogs aspects of interest to <strong>feature-u</strong>.</p>
<p>This is the primary input to <code>[launchApp()](https://feature-u.js.org/1.0.1/api.html#launchApp)</code>.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0*5vyM9ekRX_AYaaXw.png" alt="Image" width="721" height="524" loading="lazy"></p>
<h3 id="heading-aspectse98c"><a class="post-section-overview" href="#e98c">aspects</a></h3>
<p>In <strong>feature-u</strong>, “aspect” <em>(little “a”)</em> is a generalized term used to refer to the various ingredients that (when combined) constitute your application. Aspects can take on many different forms: <strong>UI Components</strong> • <strong>Routes</strong> • <strong>State Management</strong><em>(actions, reducers, selectors)</em> • <strong>Business Logic</strong> • <strong>Startup Initialization Code</strong> • <em>etc. etc. etc.</em></p>
<p><strong>Not all aspects are of interest to feature-u</strong> … <em>only those that are needed to setup and launch the application</em> … all others are considered an internal implementation detail of the feature. As an example, consider the Redux state manager: while it uses actions, reducers, and selectors … only reducers are needed to setup and configure Redux.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0*fCOFHW2dFyYYSrd-.png" alt="Image" width="594" height="454" loading="lazy"></p>
<p>The <code>[Feature](https://feature-u.js.org/1.0.1/api.html#Feature)</code> object is merely a lightweight container that holds aspects of interest to <strong>feature-u</strong>. These aspects can either be <code>[Built-In aspects](https://feature-u.js.org/1.0.1/detail.html#built-in-aspects)</code> <em>(from core <strong>feature-u</strong>)</em>, or <code>[Extendable aspects](https://feature-u.js.org/1.0.1/detail.html#extendable-aspects)</code> <em>(from plugin extensions)</em>.</p>
<h3 id="heading-running-the-appe98c"><a class="post-section-overview" href="#e98c">Running the App</a></h3>
<p>Let’s see how <code>[launchApp()](https://feature-u.js.org/1.0.1/api.html#launchApp)</code> accommodates the two sub-goals of running the app:</p>
<ul>
<li><code>[App Initialization](#d44a)</code></li>
<li><code>[Framework Configuration](#c339)</code></li>
</ul>
<h3 id="heading-app-initializatione98c"><a class="post-section-overview" href="#e98c">App Initialization</a></h3>
<p>Because <code>[launchApp()](https://feature-u.js.org/1.0.1/api.html#launchApp)</code> is in control of starting the app, it can introduce <code>[Application Life Cycle Hooks](https://feature-u.js.org/1.0.1/appLifeCycle.html)</code>.</p>
<p>This allows each feature to perform app-specific initialization, and even inject components into the root of the app.</p>
<p>There are two hooks:</p>
<ol>
<li><code>[Feature.appWillStart()](https://feature-u.js.org/1.0.1/appLifeCycle.html#appwillstart)</code> - invoked one time at app startup time</li>
<li><code>[Feature.appDidStart()](https://feature-u.js.org/1.0.1/appLifeCycle.html#appdidstart)</code> - invoked one time immediately after app has started</li>
</ol>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0*9EzmrTLQ-pglIoek.png" alt="Image" width="800" height="985" loading="lazy"></p>
<p><code>[Application Life Cycle Hooks](https://feature-u.js.org/1.0.1/appLifeCycle.html)</code> <strong>greatly simplify your app's mainline startup process</strong>, because <em>initialization specific to a given feature can be encapsulated in that feature</em>.</p>
<h3 id="heading-framework-configuratione98c"><a class="post-section-overview" href="#e98c">Framework Configuration</a></h3>
<p>A fundamental goal of <strong>feature-u</strong> is to <strong>automatically configure the framework(s)</strong> used in your run-time-stack <em>(by accumulating the necessary resources across all your features)</em>. This greatly reduces the boilerplate code within your app.</p>
<p>How can this be accomplished when there are so many frameworks out there … and every project uses a different mix?</p>
<p><strong>feature-u</strong> is extendable! It operates in an open plugable architecture where <strong>Extendable Aspects</strong> integrate <strong>feature-u</strong> to other frameworks, matching your specific run-time stack. <strong>This is good,</strong> <em>because not everyone uses the same frameworks</em>!</p>
<p><strong>Extendable Aspects</strong> can be found in external NPM packages <em>(the normal case)</em>, or you can create your own using <code>[createAspect()](https://feature-u.js.org/1.0.1/api.html#createAspect)</code> <em>(a more advanced topic)</em>.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0*be_uSLWT5KxyCiTD.png" alt="Image" width="800" height="852" loading="lazy"></p>
<p>The <code>[Aspect](https://feature-u.js.org/1.0.1/api.html#Aspect)</code> object contains a series of <code>[Aspect Life Cycle Hooks](https://feature-u.js.org/1.0.1/extending.html#aspect-life-cycle-methods)</code> that are invoked under the control of <strong>feature-u</strong>(<code>[launchApp()](https://feature-u.js.org/1.0.1/api.html#launchApp)</code>). In general, an Aspect's responsibility is to:</p>
<ul>
<li>accumulate <code>[AspectContent](https://feature-u.js.org/1.0.1/api.html#AspectContent)</code> across all features</li>
<li>perform some desired setup and configuration</li>
<li>expose it’s functionality in some way (typically a framework integration)</li>
</ul>
<p>An <code>[Aspect](https://feature-u.js.org/1.0.1/api.html#Aspect)</code> automatically extends the <code>[Feature](https://feature-u.js.org/1.0.1/api.html#Feature)</code> object by allowing it's <code>[AspectContent](https://feature-u.js.org/1.0.1/api.html#AspectContent)</code> to be <strong>"cataloged"</strong> in the <code>Feature</code> using <code>Aspect.name</code> as it's key. In the diagram above, you can see that</p>
<ul>
<li>the <code>reducerAspect</code> (<code>Aspect.name: 'reducer'</code>) permits a <code>Feature.reducer: reducerContent</code> construct</li>
<li>and the <code>logicAspect</code> (<code>Aspect.name: 'logic'</code>) permits a <code>Feature.logic: logicContent</code> construct</li>
</ul>
<p>It is important to understand that the interface to your chosen frameworks is not altered in any way. You use them the same way you always have <em>(just within your feature boundary)</em>. <strong>feature-u</strong> merely provides a well-defined organizational layer, where the frameworks are automatically setup and configured by accumulating the necessary resources across all your features.</p>
<h3 id="heading-launching-your-applicatione98c"><a class="post-section-overview" href="#e98c">Launching Your Application</a></h3>
<p>In <strong>feature-u,</strong> the application mainline is very simple and generic. There is no real app-specific code in it … <strong>not even any global initialization</strong>! That is because <strong>each feature can inject their own app-specific constructs</strong>!! The mainline merely accumulates the <code>[Aspects](https://feature-u.js.org/1.0.1/api.html#Aspect)</code> and <code>[Features](https://feature-u.js.org/1.0.1/api.html#Feature)</code>, and starts the app by invoking <code>[launchApp()](https://feature-u.js.org/1.0.1/api.html#launchApp)</code>:</p>
<p>Here are some <strong>important points of interest</strong> <em>(match the numbers to <code>*n*</code> in the code above)</em>:</p>
<ol>
<li>the supplied <code>[Aspects](https://feature-u.js.org/1.0.1/api.html#Aspect)</code> <em>(pulled from separate npm packages)</em> reflect the frameworks of our run-time stack <em>(in our example <code>[redux](http://redux.js.org/)</code>, <code>[redux-logic](https://github.com/jeffbski/redux-logic)</code>, and <code>[feature-router](https://github.com/KevinAst/feature-router)</code>)</em> and extend the acceptable Feature properties <em>(<code>Feature.reducer</code>, <code>Feature.logic</code>, and <code>Feature.route</code> respectively)</em> ... <strong><em>see:</em></strong> <code>[Extendable aspects](https://feature-u.js.org/1.0.1/detail.html#extendable-aspects)</code></li>
<li>all of our app features are supplied (accumulated from the <code>features/</code> directory)</li>
<li>a <code>[registerRootAppElm()](https://feature-u.js.org/1.0.1/api.html#registerRootAppElmCB)</code> callback is used to catalog the supplied <code>rootAppElm</code> to the specific React platform in use. Because this registration is accomplished by your app-specific code, <strong>feature-u</strong> can operate in any of the React platforms, such as: <code>[react-web](https://reactjs.org/)</code>, <code>[react-native](https://facebook.github.io/react-native/)</code>, and <code>[expo](https://expo.io/)</code> ... <strong><em>see:</em></strong> <code>[React Registration](https://feature-u.js.org/1.0.1/detail.html#react-registration)</code></li>
<li><em>as a bit of a preview</em>, the return value of <code>[launchApp()](https://feature-u.js.org/1.0.1/api.html#launchApp)</code> is a <code>[Fassets object](https://feature-u.js.org/1.0.1/api.html#Fassets)</code>, which promotes the accumulated Public Face of all features, and is exported to provide <code>[Cross Feature Communication](https://feature-u.js.org/1.0.1/crossCommunication.html)</code>.</li>
</ol>
<h3 id="heading-cross-feature-communicatione98c"><a class="post-section-overview" href="#e98c">Cross Feature Communication</a></h3>
<p>In support of <strong>Feature Collaboration</strong> <em>that doesn’t break encapsulation</em>, <strong>feature-u</strong> promotes feature-based resources through something called <code>fassets</code> (feature assets). This is how all <strong>Cross Feature Communication</strong> is accomplished. You can think of this as the <strong>Public Face</strong> of a feature.</p>
<p><strong>SideBar</strong>: The term <code>fassets</code> is a play on words. While it is pronounced "facet" <em>and is loosely related to this term</em>, it is spelled fassets (i.e. feature assets).</p>
<p>A feature can expose whatever it deems necessary through the built-in <code>[Feature.fassets aspect](https://feature-u.js.org/1.0.1/api.html#fassets)</code>). There is no real constraint on this resource. It is truly open.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0*TbIrHeN2HxFwFzhY.png" alt="Image" width="800" height="686" loading="lazy"></p>
<p>The <code>[fassets aspect](https://feature-u.js.org/1.0.1/api.html#fassets)</code> has a <code>define</code> directive where resources are cataloged.</p>
<p>Here is a simple example of how <code>fassets</code> are defined:</p>
<p><strong>feature-u</strong> accumulates <code>fassets</code> from all active features, and promotes them through the <code>[Fassets object](https://feature-u.js.org/1.0.1/api.html#Fassets)</code> <em>(emitted from <code>[launchApp()](https://feature-u.js.org/1.0.1/api.html#launchApp)</code>)</em>.</p>
<p><strong>SideBar</strong>: There are several ways to obtain access the <code>Fassets object</code> <em>(see <code>[Obtaining fassets object](https://feature-u.js.org/1.0.1/crossCommunication.html#obtaining-fassets-object)</code>)</em>.</p>
<p>To reference a <code>fassets</code> resource, simply dereference it as any other object reference. There is also a <code>[Fassets.get()](https://feature-u.js.org/1.0.1/api.html#Fassets_get)</code>method that can be supplied <code>[Wildcards](https://feature-u.js.org/1.0.1/crossCommunication.html#wildcards-adding-dynamics)</code>, returning an array of resources.</p>
<p>This is an example of a <strong>push</strong> philosophy. Here the supplier is is simply publicly promoting a resource for other features to use <strong>(take it or leave it)</strong>. The supplier is merely saying: <em>“this is my Public Face”</em>.</p>
<p>You can find more information about this topic in <code>[Cross Feature Communication](https://feature-u.js.org/1.0.1/crossCommunication.html)</code>.</p>
<h3 id="heading-feature-based-ui-compositione98c"><a class="post-section-overview" href="#e98c">Feature Based UI Composition</a></h3>
<p>It is common for a UI component to be an accumulation of sub-components that span several features. As a result, <strong>UI Composition is a very important part of Cross Feature Communication</strong>.</p>
<p>In support of this, <strong>feature-u</strong> introduces the <code>[withFassets()](https://feature-u.js.org/1.0.1/api.html#withFassets)</code> Higher-order Component (HoC) that auto-wires fasset properties into a component. This is a common pattern popularized by Redux <code>connect()</code> <em>(simplifying component access to application state)</em>.</p>
<p>Here is how a component would access a <code>company.logo</code> <em>(defined by another feature)</em>:</p>
<p>The <code>[withFassets()](https://feature-u.js.org/1.0.1/api.html#withFassets)</code> HoC auto-wires named feature assets as component properties through the <code>[mapFassetsToPropsStruct](https://feature-u.js.org/1.0.1/api.html#mapFassetsToPropsStruct)</code> hook. In this example, because the <code>Logo</code> property is a component, <code>MyComponent</code> can simply reference it using JSX.</p>
<p>You can find more information about this topic in <code>[UI Composition](https://feature-u.js.org/1.0.1/crossCommunication.html#ui-composition)</code>.</p>
<h3 id="heading-resource-contractse98c"><a class="post-section-overview" href="#e98c">Resource Contracts</a></h3>
<p>It is common for UI Composition to be represented as a contract, where a component in one feature has a series of injection needs that are to be supplied by other features.</p>
<p>The <code>[fassets aspect](https://feature-u.js.org/1.0.1/api.html#fassets)</code> has additional constructs to facilitate this contractual arrangement, allowing <strong>feature-u</strong> to provide more validation in the process.</p>
<p>Rather than just defining resources in one feature and using them in another:</p>
<ul>
<li>A given feature can specify a series of injection needs using the <code>fassets.use</code> directive. This identifies a set of <strong>injection keys</strong> that uniquely identify these resources.</li>
<li>Other features will supply this content using the <code>fassets.defineUse</code> directive, by referencing these same <strong>injection keys</strong>.</li>
</ul>
<p>This represents more of a <strong>pull</strong> philosophy. It gives <strong>feature-u</strong> more knowledge of the process, allowing it to verify that supplied resources are correct.</p>
<p>Wildcards (<code>*</code>) can be used to add additional dynamics to the process, allowing features to inject their content autonomously.</p>
<p>Here is a <code>main</code> feature that is pulling in a series of sub-components <em>(links and bodies)</em> from other features:</p>
<p><strong>main feature:</strong></p>
<p>Because our specification includes wildcards, a series of definitions will match!</p>
<p>Here is the <code>MainPage</code> component that fulfills the usage contract:</p>
<p>When <code>[withFassets()](https://feature-u.js.org/1.0.1/api.html#withFassets)</code> encounters wildcards (<code>*</code>), it merely accumulates all matching definitions, and promotes them as arrays.</p>
<p>Through this implementation, <strong>any feature may dynamically inject itself in the process autonomously</strong>! In addition, this dynamic implicitly handles the case where a feature is dynamically disabled <strong>(very kool indeed)</strong>!!</p>
<p>The following snippets are taken from other features that supply the definitions for the content to inject:</p>
<p><strong>cart feature</strong></p>
<p><strong>search feature</strong></p>
<p>Two external features (<strong>cart</strong> and <strong>search</strong>) define the content that is requested by the <strong>main</strong> feature.</p>
<p>The <code>fassets.defineUse</code> directive requires that the resource keys match a <code>fassets.use</code> feature request. This is the contract that provides <strong>feature-u</strong> insight when enforcing it's validation.</p>
<p><strong>SideBar</strong>: Because we are also dealing with navigation, we introduce <code>[react-router](https://reacttraining.com/react-router/)</code> into the mix (with the <code>Link</code> and <code>Route</code> components). Because of RR's V4 design, our routes are also handled through component composition <em>(see <code>[Feature Based Routes](https://feature-u.js.org/1.0.1/featureRouter.html)</code> for more information)</em>.</p>
<p>You can find more information about this topic in <code>[UI Composition](https://feature-u.js.org/1.0.1/crossCommunication.html#ui-composition)</code>.</p>
<h3 id="heading-feature-enablemente98c"><a class="post-section-overview" href="#e98c">Feature Enablement</a></h3>
<p>Features can be dynamically disabled by setting the <code>Feature.enabled</code> boolean property <em>(part of the <code>[Built-In aspects](https://feature-u.js.org/1.0.1/detail.html#built-in-aspects)</code>)</em>:</p>
<p>In this example, it is just as though the <code>sandbox</code> feature doesn't exist. In other words <strong>it has been logically removed</strong>.</p>
<p>Typically, this indicator is based on some run-time expression, allowing packaged code to be dynamically enabled/disabled during the application’s start-up process:</p>
<p>This dynamic is useful in a number of different situations. For example:</p>
<ul>
<li>some features may require a license upgrade</li>
<li>other features may only be used for diagnostic purposes, and are disabled by default</li>
</ul>
<p>You can find more information about this topic in <code>[Feature Enablement](https://feature-u.js.org/1.0.1/enablement.html)</code>.</p>
<h3 id="heading-in-summarye98c"><a class="post-section-overview" href="#e98c">In Summary</a></h3>
<p>The following diagram summarizes <strong>feature-u</strong>’s Basic Concepts <em>(as discussed above)</em>:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*qsohsNr9SgLca22xW6r1eQ.png" alt="Image" width="800" height="625" loading="lazy"></p>
<h3 id="heading-benefitse98c"><a class="post-section-overview" href="#e98c">Benefits</a></h3>
<p>There are many benefits in using <strong>feature-u</strong>!</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*SJ-3bETYSjbchI28hEXlUw.jpeg" alt="Image" width="800" height="533" loading="lazy"></p>
<p>The two fundamental artifacts from which most benefits are derived are:</p>
<ul>
<li>A formal means by which features can collaborate with one another <em>(<code>[Cross Feature Communication](http://localhost:4000/crossCommunication.html)</code>)</em>, making them truly <strong>plug-and-play</strong><br>This includes the ability for <code>[UI Composition](http://localhost:4000/crossCommunication.html#ui-composition)</code> to cross feature boundaries. It even allows UI Content to be injected autonomously. This is something that has to be seen ... it shows off <strong>feature-u</strong> very well.</li>
<li>A significant reduction in boilerplate code through:<br>Auto configuration of the frameworks in-use <em>(via plugin extensions — <code>[Extendable aspects](http://localhost:4000/detail.html#extendable-aspects)</code>)</em><br>Startup initialization that is encapsulated within features <em>(via <code>[Application Life Cycle Hooks](http://localhost:4000/appLifeCycle.html)</code>)</em></li>
</ul>
<p>The following list of benefits can be directly correlated to the considerations that formed the basis of why <strong>feature-u</strong> was developed <em>(see: <code>[Why feature-u?](http://localhost:4000/why.html)</code>)</em>.</p>
<ol>
<li><strong>Feature Encapsulation:</strong> <em>isolating feature boundaries improves code manageability</em></li>
<li><strong>Feature Collaboration:</strong> <em>promote <strong>Cross Feature Communication</strong> through a well-defined feature-based Public Interface</em></li>
<li><strong>Feature Based UI Composition:</strong> <em>facilitate seamless <strong>cross-feature component composition</strong></em></li>
<li><strong>Application Life Cycle Hooks:</strong> <em>features can initialize themselves without relying on an external process</em></li>
<li><strong>Feature Enablement:</strong> <em>enable/disable features through a run-time switch</em></li>
<li><strong>Minimize Feature Order Dependency Issues</strong> <em>during in-line code expansion</em></li>
<li><strong>Framework Integration:</strong> <em>automatically configure used framework(s) (matching the app’s run-time-stack) by accumulating all feature aspects (employing an extendable API)</em></li>
<li><strong>UI Component Promotion:</strong> <em>features can autonomously promote their UI components through Feature Based Route Management</em></li>
<li><strong>Single Source of Truth:</strong> <em>is facilitated in a number of ways within a feature’s implementation</em></li>
<li><strong>Simplified App Startup:</strong> <em>launching an app can be accomplished through a single line of executable code!</em></li>
<li><strong>Operates in any React Platform</strong> <em>React Web, React Native, Expo, etc.</em></li>
<li><strong>Plug-and-Play:</strong> <em>features can be more easily added or removed</em></li>
</ol>
<p><strong>feature-u</strong> allows you to <strong>focus your attention on the “business end” of your features!</strong></p>
<p><em>Go forth and compute!!</em></p>
<h3 id="heading-referencese98c"><a class="post-section-overview" href="#e98c">References</a></h3>
<ul>
<li><a target="_blank" href="http://ryanlanciaux.com/blog/2017/08/20/a-feature-based-approach-to-react-development/">A feature based approach to React development</a> <em>… Ryan Lanciaux</em></li>
<li><a target="_blank" href="https://medium.com/@alexmngn/how-to-better-organize-your-react-applications-2fd3ea1920f1">How to better organize your React applications?</a> <em>… Alexis Mangin</em></li>
<li><a target="_blank" href="https://medium.com/@alexmngn/how-to-use-redux-on-highly-scalable-javascript-applications-4e4b8cb5ef38">How to use Redux on highly scalable javascript applications?</a> <em>… Alexis Mangin</em></li>
<li><a target="_blank" href="https://hackernoon.com/the-100-correct-way-to-structure-a-react-app-or-why-theres-no-such-thing-3ede534ef1ed">The 100% correct way to structure a React app (or why there’s no such thing)</a> <em>… David Gilbertson</em></li>
<li><a target="_blank" href="https://blog.mapbox.com/redux-for-state-management-in-large-web-apps-c7f3fab3ce9b">Redux for state management in large web apps</a> <em>… David Clark</em></li>
</ul>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ feature-u (Feature Based Project Organization for React) ]]>
                </title>
                <description>
                    <![CDATA[ By Kevin Bridges This article is an introduction to feature-u — a library that facilitates feature-based project organization in your react project. This utility assists in organizing your project by individual features. Most developers would agree t... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/feature-u-cf3277b11318/</link>
                <guid isPermaLink="false">66c34a494f1fc448a3679003</guid>
                
                    <category>
                        <![CDATA[ features ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Redux ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 12 Mar 2018 06:38:54 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*D9PDIbwiUfWLB8zd7xPawQ.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Kevin Bridges</p>
<p>This article is an introduction to <a target="_blank" href="https://feature-u.js.org/">feature-u</a> — a library that facilitates <strong>feature-based project organization</strong> in your <a target="_blank" href="https://reactjs.org/">react</a> project. This utility assists in organizing your project by individual features.</p>
<p>Most developers would agree that organizing your project by features is much preferred over type-based patterns. Because <strong>application domains grow</strong> in the real world, project <strong>organization by type</strong> simply doesn’t scale, it just becomes unmanageable!</p>
<p>There are many good articles on this topic with insights on feature-based design and structure (see: <a class="post-section-overview" href="#15dd">References</a> below).</p>
<p>This article outlines my excursion into feature-based composition. In working through the details, I realized there was an opportunity for a library to help manage and streamline some of the hurdles incurred in this process. The result: <strong>feature-u</strong> (check out the <a target="_blank" href="https://feature-u.js.org/">full docs</a>, <a target="_blank" href="https://github.com/KevinAst/feature-u">GitHub source</a>, and <a target="_blank" href="https://www.npmjs.com/package/feature-u">NPM package</a>).</p>
<blockquote>
<p><strong><em>Update</em></strong>: On 8/14/2018 <a target="_blank" href="https://feature-u.js.org/1.0.0/history.html#v1_0_0">feature-u V1</a> was released, that re-designed Cross <a target="_blank" href="https://feature-u.js.org/1.0.0/crossCommunication.html">Feature Communication <code>new</code></a> to include <a target="_blank" href="https://feature-u.js.org/1.0.0/crossCommunication.html#ui-composition">UI Composition <code>new</code></a> as a core offering. <strong>A new article can be found <a target="_blank" href="http://bit.ly/feature-u-V1">here</a></strong> that takes a comprehensive approach in introducing you to all of <strong>feature-u</strong> (including <strong>V1</strong>). We are very excited about this update, because it <strong><em>promotes one solution for all feature collaboration</em></strong>! While upgrading to V1 requires some client code mods (see <a target="_blank" href="https://feature-u.js.org/1.0.0/migration.1.0.0.html">V1 Migration Notes</a>), it is well worth it. This article is based on <a target="_blank" href="https://feature-u.js.org/0.1.3/history.html#v0_1_3">feature-u V0</a>, and is using some antiquated APIs (mostly <code>Feature.publicFace</code>, and the <code>app</code> object). Still, this is a good resource to get your feet wet with feature-u.</p>
</blockquote>
<h4 id="heading-at-a-glance"><strong><em>At a Glance</em></strong></h4>
<p><a class="post-section-overview" href="#e4bb">Backdrop</a> — why feature-u was created</p>
<p><a class="post-section-overview" href="#b996">feature-u Basics</a> — introduce high-level feature-u concepts</p>
<p><a class="post-section-overview" href="#077e">eatery-nod App</a> — the sample app used to demonstrate feature-u</p>
<p><a class="post-section-overview" href="#688e">Before &amp; After</a> — <strong>eatery-nod</strong> project structure before and after features</p>
<p><a class="post-section-overview" href="#ecd3">feature-u In Action</a> — explore feature-u aspects through concrete examples</p>
<p><a class="post-section-overview" href="#3ef6">feature-u Benefits</a> — in summary</p>
<p><a class="post-section-overview" href="#15dd">References</a> — feature-based articles</p>
<h3 id="heading-backdrope80d"><a class="post-section-overview" href="#e80d">Backdrop</a></h3>
<p>Let’s start by chronicling my journey in this process</p>
<h4 id="heading-out-of-the-starting-gate"><strong>out of the Starting Gate …</strong></h4>
<p><em>Sooo … I had decided to restructure my project by features</em>. From a design perspective, there were a number of considerations in determining the feature boundaries. I had read all the articles, and applied my design to a <strong>new feature-based directory structure.</strong></p>
<p>In general, I was feeling good about my progress. I was starting to see concrete benefits … <strong>feature segregation was going to result in code that is much more manageable!</strong></p>
<h4 id="heading-the-hurdles"><strong>the Hurdles …</strong></h4>
<p>However, there were a number of hurdles yet to be resolved …</p>
<p>How can I encapsulate and isolate my features, while still allowing them to collaborate with one another?</p>
<p>How can selected features introduce start-up initialization (even injecting utility at the root DOM), without relying on some external startup process?</p>
<p>How can I promote feature-based UI components in an isolated and autonomous way?</p>
<p>How can I configure my chosen frameworks now that my code is so spread out?</p>
<p>How can I enable/disable selected features which are either optional, or require a license upgrade?</p>
<p>In short, how can I pull it all together so that my individual features operate as one application?</p>
<h4 id="heading-the-goal-what-now"><strong>the Goal <em>(what now?)</em></strong></h4>
<p>The <strong>overriding goal</strong> of feature-u is two-fold:</p>
<ol>
<li>Allow features to <strong>Plug-and-Play!</strong> This encompasses many things, such as: encapsulation, cross communication, enablement, initialization, and so on. We will build on these concepts throughout this article.</li>
<li><strong>Automate the startup of your application!!</strong> You have the features. Allow them to promote their characteristics, so a central utility can <strong>automatically</strong> configure the frameworks used in your app, thereby launching your application. This task must be accomplished in an extendable way, because not everyone uses the same set of frameworks.</li>
</ol>
<h3 id="heading-feature-u-basicse80d"><a class="post-section-overview" href="#e80d">feature-u Basics</a></h3>
<p>The basic process of <strong>feature-u</strong> is that each feature promotes a <a target="_blank" href="https://feature-u.js.org/0.1.3/api.html#Feature">Feature</a> object that contains various aspects of that feature — things like the feature's name, its Public API, whether it is enabled, initialization constructs, and resources used to configure its slice of the frameworks in use.</p>
<p>In turn, these Feature objects are supplied to <a target="_blank" href="https://feature-u.js.org/0.1.3/api.html#launchApp">launchApp()</a>, which configures and starts your application running. In addition, the returned <a target="_blank" href="https://feature-u.js.org/0.1.3/api.html#App">App</a> object is exported, in order to promote the public API of each feature.</p>
<h4 id="heading-aspects">aspects</h4>
<p>In feature-u, “aspect” is a generalized term used to refer to the various ingredients that (when combined) constitute your application.</p>
<p>Aspects can take on many different forms:</p>
<ul>
<li>UI Components and Routes</li>
<li>State Management (actions, reducers, selectors)</li>
<li>Business Logic</li>
<li>Startup Initialization Code</li>
<li>And so on…</li>
</ul>
<p>Not all aspects are of interest to feature-u — only those that are needed to setup and launch the app — all others are considered an internal implementation detail of the feature.</p>
<p>As an example, consider the redux state manager. While it uses actions, reducers, and selectors … only reducers are needed to setup and configure redux.</p>
<h4 id="heading-framework-integration">framework integration</h4>
<p>A fundamental goal of feature-u is to <strong>automatically configure the framework</strong>(s) used in your run-time-stack (by accumulating the necessary resources across all your features). Because not everyone uses the same frameworks, feature-u accomplishes this through <strong>Extendable Aspects</strong> (you can find them in external NPM packages, or you can create your own).</p>
<p>It is important to understand that the interface to your chosen frameworks is not altered in any way. You use them the same way you always have (just within your feature boundary).</p>
<p>feature-u merely provides a well defined organizational layer, where the frameworks are automatically setup and configured by accumulating the necessary resources across all your features.</p>
<h3 id="heading-eatery-nod-appe80d"><a class="post-section-overview" href="#e80d">eatery-nod App</a></h3>
<p><a target="_blank" href="https://github.com/KevinAst/eatery-nod/tree/after-features"><strong>eatery-nod</strong></a> is the application where feature-u was conceived. It is a <a target="_blank" href="https://facebook.github.io/react-native/">react-native</a> <a target="_blank" href="https://expo.io/">expo</a> mobile app, and is one of my sandbox applications that I use to test frameworks. I like to develop apps that I can use, but have enough real-world requirements to make it interesting.</p>
<p>eatery-nod randomly selects a “date night” restaurant from a pool of favorites. My wife and I have a steady “date night”, and we are always indecisive on which of our favorite restaurants to frequent :-) So eatery-nod provides the spinning wheel!</p>
<p>Take a look at the eatery-nod <a target="_blank" href="https://github.com/KevinAst/eatery-nod/blob/after-features/README.md">README</a> to get a feel for the application. Screen flows are available, so it really helps in your orientation to the project.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*DDrt1xRlOmM8jywM4ABSCg.png" alt="Image" width="800" height="618" loading="lazy">
<em><strong>eatery-nod’s</strong> primary screen flow</em></p>
<p>In addition, <a target="_blank" href="https://github.com/KevinAst/eatery-nod/blob/after-features/src/feature/README.md">README files</a> are found in each feature, describing what each feature accomplishes. Take some time now and skim through these resources:</p>
<ul>
<li><a target="_blank" href="https://github.com/KevinAst/eatery-nod/blob/after-features/src/feature/device/README.md"><strong>device</strong></a> — initializes the device for use by the app, and promotes a device API abstraction</li>
<li><a target="_blank" href="https://github.com/KevinAst/eatery-nod/blob/after-features/src/feature/auth/README.md"><strong>auth</strong></a> — promotes complete user authentication</li>
<li><a target="_blank" href="https://github.com/KevinAst/eatery-nod/blob/after-features/src/feature/leftNav/README.md"><strong>leftNav</strong></a> — promotes the app-specific Drawer/SideBar on the app’s left side</li>
<li><a target="_blank" href="https://github.com/KevinAst/eatery-nod/blob/after-features/src/feature/currentView/README.md"><strong>currentView</strong></a> — maintains the currentView with get/set cross-feature communication bindings</li>
<li><a target="_blank" href="https://github.com/KevinAst/eatery-nod/blob/after-features/src/feature/eateries/README.md"><strong>eateries</strong></a> — manages and promotes the eateries view</li>
<li><a target="_blank" href="https://github.com/KevinAst/eatery-nod/blob/after-features/src/feature/discovery/README.md"><strong>discovery</strong></a> — manages and promotes the discovery view</li>
<li><a target="_blank" href="https://github.com/KevinAst/eatery-nod/blob/after-features/src/feature/firebase/README.md"><strong>firebase</strong></a> — initializes the Google Firebase service</li>
<li><a target="_blank" href="https://github.com/KevinAst/eatery-nod/blob/after-features/src/feature/logActions/README.md"><strong>logActions</strong></a> — logs all dispatched actions and resulting state</li>
<li><a target="_blank" href="https://github.com/KevinAst/eatery-nod/blob/after-features/src/feature/sandbox/README.md"><strong>sandbox</strong></a> — promotes a variety of interactive tests, used in development, that can easily be disabled</li>
</ul>
<h3 id="heading-before-amp-aftere80d"><a class="post-section-overview" href="#e80d">Before &amp; After</a></h3>
<p>Anyone who knows me will tell you that I have an appreciation for a good before/after analysis. Whether it is a home remodel or a software refactor, it helps to chronicle where you have been, so as to quantify concrete achievements, and gives you a sense of accomplishment.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0*dIpbZMgqHN5DrE6S.jpg" alt="Image" width="300" height="300" loading="lazy"></p>
<p>Let’s take a look at eatery-nod’s directory structure (before/after).</p>
<p>For illustration purposes, I have only expanded a few directories, but I think you get the idea.</p>
<p><strong>Before</strong>: here is my project's <a target="_blank" href="https://github.com/KevinAst/eatery-nod/tree/before-features/src">before features</a> …</p>
<pre><code>eatery-nod src BEFORE featuressrc/├──actions/        ... redux actions│     auth.js│     discovery.js│     eateries.js│     ... snip snip├──api/            ... various abstract APIs│     device.js│     discovery.js│     ... snip snip├──app/            ... mainline startup **<span class="hljs-number">1</span>**│  │  ScreenRouter.js│  │  SideBar.js│  │  index.js│  └──startup/│     │  createAppStore.js│     │  platformSetup.android.js│     │  platformSetup.ios.js│     └──firebase/│           firebaseAppConfig.js│           initFireBase.js├──appState/       ... redux reducers│     auth.js│     discovery.js│     eateries.js│     ... snip snip├──comp/           ... UI Component Screens│     DiscoveryListScreen.js│     EateriesListScreen.js│     ... snip snip├──logic/          ... redux-logic modules│     auth.js│     discovery.js│     eateries.js│     ... snip snip└──util/           ... common utilities
</code></pre><p><strong>After</strong>: and here is the same project's <a target="_blank" href="https://github.com/KevinAst/eatery-nod/tree/after-features/src">after features</a> …</p>
<pre><code>eatery-nod src AFTER featuressrc/│  app.js          ... launches app via launchApp() **<span class="hljs-number">2</span>**├──feature/│  │  index.js     ... accumulate/promote all app Feature objects│  ├──auth/        ... the app<span class="hljs-string">'s authorization feature│  │  │  actions.js│  │  │  featureName.js│  │  │  index.js│  │  │  logic.js│  │  │  publicFace.js│  │  │  route.js│  │  │  signInFormMeta.js│  │  │  state.js│  │  └──comp/│  │        SignInScreen.js│  │        SignInVerifyScreen.js│  ├──currentView/ ... other features│  ├──device/      ... feature to initialize the device│  │  │  actions.js│  │  │  api.js│  │  │  appDidStart.js│  │  │  appWillStart.js│  │  │  featureName.js│  │  │  index.js│  │  │  logic.js│  │  │  publicFace.js│  │  │  route.js│  │  │  state.js│  │  └──init/│  │        platformSetup.android.js│  │        platformSetup.ios.js│  ├──discovery/   ... more features│  ├──eateries/│  ├──firebase/│  ├──leftNav/│  ├──logActions/│  └──sandbox/└──util/           ... common utilities used across all features</span>
</code></pre><p>As expected, the difference in project organization is dramatic!</p>
<ul>
<li><strong>Before features —</strong> you find constructs for a given feature spread over numerous typed directories.</li>
<li><strong>After features</strong>: all aspects of a given feature are contained in its own isolated directory.</li>
<li>A notable difference is the <strong>dramatic reduction in complexity of the application startup process!</strong> The “before features” contained an entire <code>app\</code> directory of startup code (see <code>[**1**](#226c)</code> above), while the "after features" simply contains a single <code>app.js</code> startup file (see <code>[**2**](#f98f)</code> above). <strong>Where did all the complexity go?</strong> ... stay tuned!</li>
</ul>
<h3 id="heading-feature-u-in-actione80d"><a class="post-section-overview" href="#e80d">feature-u In Action</a></h3>
<p>To better understand feature-u, let’s take a closer look at some eatery-nod examples in action.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0*1OHVaxVpTBYvW_ZT.jpg" alt="Image" width="416" height="274" loading="lazy"></p>
<p>Each of the following sections briefly introduce a new feature-u topic, correlating sample code from eatery-nod. Additional information is provided through links, both to the feature-u docs, and eatery-nod source code. In some cases the in-lined sample code has been streamlined (to emphasize a focal point), however the caption link will take you to the actual code (hosted on GitHub).</p>
<p>Here are our topics …</p>
<ol>
<li><a class="post-section-overview" href="#5974">Simplified App Startup</a></li>
<li><a class="post-section-overview" href="#af00">React Platforms</a></li>
<li><a class="post-section-overview" href="#6db0">Feature Object</a></li>
<li><a class="post-section-overview" href="#c1a5">Feature Initialization</a></li>
<li><a class="post-section-overview" href="#1895">Feature Collaboration</a></li>
<li><a class="post-section-overview" href="#cfeb">Framework Integration</a></li>
<li><a class="post-section-overview" href="#e557">Feature Enablement</a></li>
<li><a class="post-section-overview" href="#5fab">Managed Code Expansion</a></li>
<li><a class="post-section-overview" href="#2666">UI Component Promotion</a></li>
<li><a class="post-section-overview" href="#c174">Single Source of Truth</a></li>
</ol>
<h3 id="heading-1-simplified-app-startup6561"><a class="post-section-overview" href="#6561">1. Simplified App Startup</a></h3>
<p>After breaking your application up into pieces (as with features), how do you pull them all back together, and actually start your app running? At first glance, this may seem like a daunting task. As it turns out, however, because of the structure promoted by feature-u, it actually is a very simple process.</p>
<p>To solve this, feature-u provides the <code>[launchApp()](https://feature-u.js.org/0.1.3/api.html#launchApp)</code> function (see: <a target="_blank" href="https://feature-u.js.org/0.1.3/detail.html#launching-your-application">Launching Your Application</a>).</p>
<p>Here is eatery-nod’s mainline …</p>
<p>The first thing to note is just how simple and generic the mainline startup process is. There is no real app-specific code in it … not even any global initialization!</p>
<p>That is because feature-u provides various hooks that allow your features to inject their own app-specific constructs.</p>
<p>The mainline merely accumulates the Aspects and Features, and starts the app by invoking <code>launchApp()</code>.</p>
<p>Here are some important points of interest (match the numbers to <code>*n*</code> in the code above):</p>
<ol>
<li><code>([*1*](#a002))</code> the supplied Aspects (pulled from separate NPM packages) reflect the frameworks of our run-time stack (in our example <code>[redux](http://redux.js.org/)</code>, <code>[redux-logic](https://github.com/jeffbski/redux-logic)</code>, and <code>[feature-router](https://github.com/KevinAst/feature-router)</code>) and extend the acceptable Feature properties — <code>Feature.reducer</code>, <code>Feature.logic</code>, and <code>Feature.route</code> respectively. (See <a target="_blank" href="https://feature-u.js.org/0.1.3/detail.html#extendable-aspects">Extendable aspects</a>).</li>
<li><code>([*2*](#a002))</code>all app features are accumulated from our <code>feature/</code> directory</li>
<li><code>([*3*](#a002))</code>as a preview to <a class="post-section-overview" href="#1895">Feature Collaboration</a>, the exported return value of <code>launchApp()</code> is an <code>App</code> object, which promotes the accumulated Public API of all features.</li>
</ol>
<h3 id="heading-2-react-platforms6561"><a class="post-section-overview" href="#6561">2. React Platforms</a></h3>
<p>In the example above (see <code>[*4*](#a002)</code>), you see that <code>launchApp()</code> uses a <code>[registerRootAppElm()](https://feature-u.js.org/0.1.3/api.html#registerRootAppElmCB)</code> callback hook to register the supplied <code>rootAppElm</code> to the specific React platform in use. Because this registration is accomplished by app-specific code, feature-u can operate in any of the React platforms (see <a target="_blank" href="https://feature-u.js.org/0.1.3/detail.html#react-registration">React Registration</a>).</p>
<p>Here are some <code>[registerRootAppElm()](https://feature-u.js.org/0.1.3/api.html#registerRootAppElmCB)</code> variations:</p>
<p><a target="_blank" href="https://reactjs.org/">react web</a>:</p>
<p><a target="_blank" href="https://facebook.github.io/react-native/">react-native</a>:</p>
<p><a target="_blank" href="https://expo.io/">expo</a>:</p>
<h3 id="heading-3-feature-object6561"><a class="post-section-overview" href="#6561">3. Feature Object</a></h3>
<p>Each feature is located in its own directory, and promotes aspect content through a <code>Feature</code> object (using <code>[createFeature()](https://feature-u.js.org/0.1.3/api.html#createFeature)</code>).</p>
<p>Here is an example from eatery-nod’s <a target="_blank" href="https://github.com/KevinAst/eatery-nod/blob/after-features/src/feature/device/README.md">device</a> feature.</p>
<p>As you can see, the <code>Feature</code> object is merely a container that holds aspect content of interest to feature-u. The sole purpose of the <code>Feature</code> object is to communicate this aspect information to <code>launchApp()</code>.</p>
<p>We will fill in more detail a bit later, but for now notice that the feature is conveying reducers, logic modules, routes, and does some type of initialization (<code>appWillStart</code>/<code>appDidStart</code>). It also promotes a <code>publicFace</code> that can be used by other features (such as the feature’s Public API).</p>
<p>For more information, please refer to <a target="_blank" href="https://feature-u.js.org/0.1.3/detail.html#feature-object-relaying-aspect-content">Feature &amp; aspect content</a>.</p>
<h3 id="heading-4-feature-initialization6561"><a class="post-section-overview" href="#6561">4. Feature Initialization</a></h3>
<p>Any given feature should not have to rely on an external startup process to perform the initialization that it needs. Rather, the feature should be able to spawn initialization that it depends on.</p>
<p>This could be any number of things, such as:</p>
<ul>
<li>initialize some service API</li>
<li>inject a utility react component at the App root</li>
<li>dispatch an action that kicks off a startup process</li>
<li>And more...</li>
</ul>
<p>To solve this, feature-u introduces two <a target="_blank" href="https://feature-u.js.org/0.1.3/appLifeCycle.html">Application Life Cycle Hooks</a>, injected through the following Feature aspects:</p>
<ol>
<li><code>[Feature.appWillStart({app, curRootAppElm}): rootAppElm || falsy](https://feature-u.js.org/0.1.3/appLifeCycle.html#appwillstart)</code> Invoked one time, just before the app starts up. This can do any type of initialization, including supplementing the app's top-level root element (such as the React <code>component</code> instance).</li>
<li><code>[Feature.appDidStart({app, appState, dispatch}): void](https://feature-u.js.org/0.1.3/appLifeCycle.html#appDidStart)</code><br>Invoked one time immediately after the app has started. A typical usage for this hook is to dispatch some type of <code>bootstrap action</code>.</li>
</ol>
<p>Here are some examples from eatery-nod:</p>
<p>FireBase Initialization:</p>
<p>Bootstrap Action:</p>
<p>Inject DOM Root Elm:</p>
<h3 id="heading-5-feature-collaboration6561"><a class="post-section-overview" href="#6561">5. Feature Collaboration</a></h3>
<p>Even though a feature’s implementation is encapsulated, it still needs to interact with its surroundings. To complicate matters, one feature should never import resources from another feature, because it should strive to be plug-and-play. As a result, we need a well-defined feature-based Public API.</p>
<p>To solve this, feature-u promotes a <a target="_blank" href="https://feature-u.js.org/0.1.3/crossCommunication.html">Cross Feature Communication</a>. This is accomplished through the <code>Feature.publicFace</code><a target="_blank" href="https://feature-u.js.org/0.1.3/detail.html#built-in-aspects">Built-In aspect</a> property. A feature can expose whatever it deems necessary through its <code>publicFace</code>. There are no real constraints on this resource. It is truly open.</p>
<p>Typically this involves promoting selected:</p>
<ul>
<li>actions</li>
<li>selectors</li>
<li>APIs</li>
<li>And so on</li>
</ul>
<p>The <code>publicFace</code> of all features are accumulated and exposed through the <code>App</code> object (emitted from <code>launchApp()</code>).</p>
<p>It contains named feature nodes, as follows:</p>
<pre><code>App.{featureName}.{publicFace}
</code></pre><p>Here is an example from eatery-nod’s <a target="_blank" href="https://github.com/KevinAst/eatery-nod/blob/after-features/src/feature/auth/README.md">auth</a> feature.</p>
<p>Out of all the items found in the <code>auth</code> feature, only two actions and one selector are public.</p>
<p>Here is what the <code>App</code> object would look like for this example:</p>
<pre><code>app: {  <span class="hljs-attr">auth</span>: {    <span class="hljs-attr">actions</span>: {      userProfileChanged(userProfile),      signOut(),    },    <span class="hljs-attr">sel</span>: {      getUserPool(appState),    },  },  <span class="hljs-attr">currentView</span>: {   <span class="hljs-comment">// other features    ... snip snip  },}</span>
</code></pre><p>As a result, the <code>auth</code> feature's public API can be accessed as follows:</p>
<pre><code>app.auth.actions.userProfileChanged(userProfile)app.auth.actions.signOut()app.auth.sel.getUserPool(appState)
</code></pre><h3 id="heading-6-framework-integration6561"><a class="post-section-overview" href="#6561">6. Framework Integration</a></h3>
<p>Most likely your application employs one or more frameworks (such as <code>redux</code> or <code>[redux-logic](https://github.com/jeffbski/redux-logic)</code>). How are the resources needed by these frameworks accumulated and configured across the many features of your app?</p>
<p>To solve this, feature-u introduces <a target="_blank" href="https://feature-u.js.org/0.1.3/detail.html#extendable-aspects">Extendable aspects</a>. <strong>feature-u</strong> is <a target="_blank" href="https://feature-u.js.org/0.1.3/extending.html">extendable</a>. It provides integration points between your features and your chosen frameworks.</p>
<p>Extendable Aspects are packaged separately from feature-u, so as to not introduce unwanted dependencies (because not everyone uses the same frameworks). You pick and choose them based on the framework(s) used in your project (matching your project’s run-time stack). They are created with feature-u’s extendable API, using <a target="_blank" href="https://feature-u.js.org/0.1.3/api.html#createAspect">createAspect()</a>. You can define your own Aspect, if the one you need doesn't already exist.</p>
<p>Let’s take a look at a redux example from eatery-nod.</p>
<p>The <code>device</code> feature maintains its own slice of the state tree.</p>
<p>It promotes its reducer through the <code>Feature.reducer</code> aspect:</p>
<p>Because <code>Feature.reducer</code> is an extended aspect (verses a built-in aspect), it is only available because we registered the <a target="_blank" href="https://github.com/KevinAst/feature-redux">feature-redux</a> <code>reducerAspect</code> to <code>launchApp()</code> (please refer to <a class="post-section-overview" href="#5974">Simplified App Startup</a> above).</p>
<p>The key thing to understand is that feature-u (through the feature-redux extension) will automatically configure redux by accumulating all feature reducers into one overall appState.</p>
<p>Here is the reducer code …</p>
<p>A feature-based reducer is simply a normal reducer that manages the feature’s slice of the the overall appState. The only difference is it must be embellished with <code>[slicedReducer()](https://github.com/KevinAst/feature-redux#slicedreducer)</code>, which provides instructions on where to insert it in the overall top-level appState.</p>
<p>As a result, the <code>device</code> reducer only maintains the state relevant to the <code>device</code> feature (like its little slice of the world) — a status, a fontsLoaded indicator, and the device location.</p>
<p><strong>SideBar</strong>: We are using the <a target="_blank" href="https://astx-redux-util.js.org/">astx-redux-util</a> utility’s <code>[reducerHash()](https://astx-redux-util.js.org/1.0.0/api.html#reducerHash)</code> function to concisely implement the feature's reducer (providing an alternative to the common switch statement). I have found that in using a utility like this, for most cases it is feasible to implement all the reducers of a feature in one file (due in part to the smaller boundary of a feature). astx-redux-util also promotes other <a target="_blank" href="https://medium.com/@mange_vibration/reducer-composition-with-higher-order-reducers-35c3977ed08f">Higher-Order Reducer</a>s. You may want to check this out.</p>
<h3 id="heading-7-feature-enablement6561"><a class="post-section-overview" href="#6561">7. Feature Enablement</a></h3>
<p>Some of your features may need to be dynamically enabled or disabled. As an example, certain features may only be enabled with a license upgrade, or other features may only be used for diagnostic purposes.</p>
<p>To solve this, feature-u introduces <a target="_blank" href="https://feature-u.js.org/0.1.3/enablement.html">Feature Enablement</a>. Using the <code>Feature.enabled</code> Built-In aspect (a boolean property), you can enable or disable your feature.</p>
<p>Here is an example from eatery-nod’s <a target="_blank" href="https://github.com/KevinAst/eatery-nod/blob/after-features/src/feature/sandbox/README.md">sandbox</a> feature:</p>
<p>The sandbox feature promotes a variety of interactive tests, used in development, that can easily be disabled.</p>
<p>Typically this indicator is based on a dynamic expression, but in this case it is simply hard-coded (to be set by a developer).</p>
<p><strong>SideBar</strong>: When other features interact with a feature that can be disabled, you can use the <code>App</code> object to determine if a feature is present or not (see: <a target="_blank" href="https://feature-u.js.org/cur/enablement.html">Feature Enablement</a> for more information).</p>
<h3 id="heading-8-managed-code-expansion6561"><a class="post-section-overview" href="#6561">8. Managed Code Expansion</a></h3>
<p>In general, accessing <strong>imported resources</strong> during in-line code expansion can be problematic, due to the order in which these resources are expanded. The feature-u <code>App</code> object is such a critical resource (because it promotes the Public API of all features), <strong>it must be available even during code expansion</strong>. In other words, we cannot rely on an "imported app" being resolved during code expansion time.</p>
<p>To solve this, feature-u introduces <a target="_blank" href="https://feature-u.js.org/0.1.3/crossCommunication.html#managed-code-expansion">Managed Code Expansion</a>.</p>
<p>When aspect content definitions require the <code>App</code> object at code expansion time, you simply wrap the definition in a <code>[managedExpansion()](https://feature-u.js.org/0.1.3/api.html#managedExpansion)</code> function. In other words, your aspect content can either be the actual content itself (such as a reducer), or a function that returns the content.</p>
<p>When this is done, feature-u will expand it by invoking it in a controlled way, passing the fully resolved <code>App</code> object as a parameter.</p>
<p>Here is a logic module from eatery-nod’s <a target="_blank" href="https://github.com/KevinAst/eatery-nod/blob/after-features/src/feature/auth/README.md">auth</a> feature:</p>
<p>You can see that the auth feature is using an action from the <a target="_blank" href="https://github.com/KevinAst/eatery-nod/blob/after-features/src/feature/device/README.md">device</a> feature, requiring access to the <code>app</code> object (see <code>[*2*](#8030)</code>). Because the <code>app</code> object is needed during code expansion, we use the <code>managedExpansion()</code> function (see <code>[*1*](#8030)</code>), allowing feature-u to expand it in a controlled way, passing the fully resolved <code>app</code> object as a parameter.</p>
<h3 id="heading-9-ui-component-promotion6561"><a class="post-section-overview" href="#6561">9. UI Component Promotion</a></h3>
<p>Features that maintain their own UI Components need a way to promote them in the overall app’s GUI. Because features are encapsulated, how is this accomplished in an autonomous way?</p>
<p>To address this, feature-u recommends considering <a target="_blank" href="https://feature-u.js.org/0.1.3/featureRouter.html">Feature Based Routes</a> via the <a target="_blank" href="https://github.com/KevinAst/feature-router">feature-router</a> extendable Aspect (packaged separately). This approach can even be used in conjunction with other navigational solutions.</p>
<p>Feature Routes are based on a very simple concept: allow the application state to drive the routes! It operates through a series of feature-based routing functions that reason about the appState, and either return a rendered component, or null to allow downstream routes the same opportunity.</p>
<p>Here is a simple example from the <a target="_blank" href="https://github.com/KevinAst/eatery-nod/blob/after-features/src/feature/device/README.md">device</a> feature.</p>
<p>This route analyzes the current appState, and displays a SplashScreen until the system is ready:</p>
<p>In feature based routing, you will not find the typical “route path to component” mapping catalog, where (for example) some pseudo <code>route('device')</code> directive causes the Device screen to display, which in turn causes the system to accommodate the request by adjusting its state appropriately.</p>
<p>Rather, the appState is analyzed, and if the device is NOT ready, no other screens are given the option to even render ... Easy Peasy!</p>
<p>Depending on your perspective, this approach can be more natural, but more importantly, it allows features to promote their own screens in an encapsulated and autonomous way.</p>
<h3 id="heading-10-single-source-of-truth6561"><a class="post-section-overview" href="#6561">10. Single Source of Truth</a></h3>
<p>Feature implementations (like all coding constructs) should strive to follow the <strong>single-source-of-truth</strong> principle. In doing this, a single line modification can propagate to many areas of your implementation.</p>
<p>What are some <strong>Best Practices</strong> for single-source-of-truth as it relates to features, and how can feature-u help?</p>
<p>The <a target="_blank" href="https://feature-u.js.org/0.1.3/bestPractices.html">Best Practices</a> section highlights a number of feature-based single-source-of-truth items of interest. These are guidelines, because you must implement them in your application code (feature-u is not in control of this).</p>
<p>Here is an example from the <a target="_blank" href="https://github.com/KevinAst/eatery-nod/blob/after-features/src/feature/eateries/README.md">eateries</a> feature:</p>
<p>The <code>featureName</code> is used to specify the top-level state location of this feature (see <code>[*1*](#d59b)</code>). feature-u guarantees the feature name is unique. As a result, it can be used to qualify the identity of several feature aspects.</p>
<p>For example:</p>
<ul>
<li>prefix action types with featureName, guaranteeing their uniqueness app-wide (see: <a target="_blank" href="https://github.com/KevinAst/feature-redux#action-uniqueness-single-source-of-truth">feature-redux</a> docs)</li>
<li>prefix logic module names with featureName, identifying where that module lives (see: <a target="_blank" href="https://github.com/KevinAst/feature-redux-logic#single-source-of-truth">feature-redux-logic</a> docs)</li>
<li>depending on the context, the featureName can be used as the root of your feature state’s shape (see: <a target="_blank" href="https://github.com/KevinAst/feature-redux#state-root-single-source-of-truth">feature-redux</a> docs)</li>
</ul>
<p>Because feature-u relies on <code>[slicedReducer()](https://github.com/KevinAst/feature-redux#slicedreducer)</code> (in the feature-redux package), a best practice is to use the reducer's embellished selector to qualify your feature state root in all your selector definitions. As a result the slice definition is maintained in one spot (see <code>[*2*](#d59b)</code>).</p>
<h3 id="heading-feature-u-benefitse80d"><a class="post-section-overview" href="#e80d">feature-u Benefits</a></h3>
<p>In summary, the benefits of using feature-u include:</p>
<ul>
<li><strong>Feature Encapsulation</strong> — isolating feature implementations improves code manageability</li>
<li><strong>Cross Feature Communication</strong> — a feature’s public API is promoted through a well-defined standard</li>
<li><strong>Feature Enablement</strong> — enable/disable features through a run-time switch</li>
<li><strong>Application Life Cycle Hooks</strong> — features can initialize themselves without relying on an external process</li>
<li><strong>Single Source of Truth</strong> — is facilitated in a number of ways within a feature’s implementation</li>
<li><strong>Framework Integration</strong> — configure the framework(s) of your choice (matching your run-time-stack) using feature-u’s extendable API</li>
<li><strong>UI Component Promotion</strong> — through Feature Routes</li>
<li><strong>Minimize Feature Order Dependency Issues</strong> — even in code that is expanded in-line</li>
<li><strong>Plug-and-Play</strong> — features can be added/removed easily</li>
<li><strong>Simplified Mainline</strong> — <code>launcApp()</code> starts the app running by configuring the frameworks in use, all driven by a simple set of features.</li>
<li><strong>Operates in any React Platform</strong> (including React Web, React Native and Expo)</li>
</ul>
<p>Hopefully this article gives you a feel for how feature-u can improve your project. Please refer to the <a target="_blank" href="https://feature-u.js.org/">full documentation</a> for more details.</p>
<p>feature-u allows you to focus your attention on the “business end” of your features! Go forth and compute!!</p>
<h3 id="heading-referencese80d"><a class="post-section-overview" href="#e80d">References</a></h3>
<ul>
<li><a target="_blank" href="http://ryanlanciaux.com/blog/2017/08/20/a-feature-based-approach-to-react-development/">A feature based approach to React development</a> … Ryan Lanciaux</li>
<li><a target="_blank" href="https://medium.com/@alexmngn/how-to-better-organize-your-react-applications-2fd3ea1920f1">How to better organize your React applications?</a> … Alexis Mangin</li>
<li><a target="_blank" href="https://medium.com/@alexmngn/how-to-use-redux-on-highly-scalable-javascript-applications-4e4b8cb5ef38">How to use Redux on highly scalable javascript applications?</a> … Alexis Mangin</li>
<li><a target="_blank" href="https://hackernoon.com/the-100-correct-way-to-structure-a-react-app-or-why-theres-no-such-thing-3ede534ef1ed">The 100% correct way to structure a React app (or why there’s no such thing)</a> … David Gilbertson</li>
<li><a target="_blank" href="https://blog.mapbox.com/redux-for-state-management-in-large-web-apps-c7f3fab3ce9b">Redux for state management in large web apps</a> … David Clark</li>
</ul>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
