<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Mark&#39;s Dev Blog</title>
    <link>https://blog.isquaredsoftware.com/tags/create-react-app/index.xml</link>
    <description>Recent content on Mark&#39;s Dev Blog</description>
    <generator>Hugo -- gohugo.io</generator>
    <atom:link href="https://blog.isquaredsoftware.com/tags/create-react-app/index.xml" rel="self" type="application/rss+xml" />
    
    <item>
      <title>Practical Redux, Part 9: Upgrading Redux-ORM and Updating Dependencies</title>
      <link>https://blog.isquaredsoftware.com/2017/07/practical-redux-part-9-managing-dependencies/</link>
      <pubDate>Tue, 11 Jul 2017 10:00:00 -0400</pubDate>
      
      <guid>https://blog.isquaredsoftware.com/2017/07/practical-redux-part-9-managing-dependencies/</guid>
      <description>&lt;p&gt;&lt;/p&gt;

&lt;h2 id=&#34;intro&#34;&gt;Intro&lt;/h2&gt;

&lt;p&gt;Greetings, and welcome back to the Practical Redux series!  It&#39;s been a few months since the last post, but as promised, I still have a lot of topics I want to cover for this series.&lt;/p&gt;

&lt;p&gt;Picking up where we left off: &lt;strong&gt;&lt;a href=&#34;https://blog.isquaredsoftware.com/2017/01/practical-redux-part-8-form-draft-data-management/&#34;&gt;in Part 8&lt;/a&gt;&lt;/strong&gt;, we added the ability to delete Pilot entries, used our generic entity reducer logic to implement &amp;quot;draft data&amp;quot; handling for the Pilot editing form, and added the ability to cancel and reset form edits.  This time around, we have some housekeeping to do: we&#39;ll &lt;strong&gt;update Redux-ORM to 0.9 and discuss the migration and API changes, update our other dependencies to the latest versions, and look at ways to cache NPM dependencies for consistent project installation even if you&#39;re offline&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The code for this project is on Github at &lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek&#34;&gt;github.com/markerikson/project-minimek&lt;/a&gt;&lt;/strong&gt;.  The original WIP commits I made for this post can be seen in &lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/pull/10&#34;&gt;PR #10: Practical Redux Part 9 WIP&lt;/a&gt;&lt;/strong&gt;, and the final &amp;quot;clean&amp;quot; commits can be seen in in &lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/pull/11&#34;&gt;PR #11: Practical Redux Part 9 Final&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I&#39;ll be linking to each &amp;quot;final&amp;quot; commit as I go through the post, as well as specific files in those commits.  I won&#39;t paste every changed file in here or show every single changed line, to save space, but rather try to show the most relevant changes for each commit as appropriate.&lt;/p&gt;

&lt;h3 id=&#34;table-of-contents&#34;&gt;Table of Contents&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#using-redux-orm-0-9&#34;&gt;Using Redux-ORM 0.9&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#updating-dependencies&#34;&gt;Updating Dependencies&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#managing-dependency-packages-for-offline-installation&#34;&gt;Managing Dependency Packages for Offline Installation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#final-thoughts&#34;&gt;Final Thoughts&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#further-information&#34;&gt;Further Information&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&#34;using-redux-orm-0-9&#34;&gt;Using Redux-ORM 0.9&lt;/h2&gt;

&lt;p&gt;When I started the series, the current version of Redux-ORM was 0.8.1.  Since then, there have been some noticeable changes.  Author Tommi Kaikkonen built and released version 0.9, which includes a number of breaking changes to the API and the library&#39;s behavior.  Sadly, he also no longer has time to maintain the library by himself, but a call for new maintainers resulted in a couple people being given full ownership of the library, and several others (including myself) were given commit rights.  So, Redux-ORM is definitely alive and well.&lt;/p&gt;

&lt;p&gt;Let&#39;s take a look at the major changes in Redux-ORM 0.9, then tackle upgrading &lt;strong&gt;&lt;em&gt;Project Mini-Mek&lt;/em&gt;&lt;/strong&gt; to use it.&lt;/p&gt;

&lt;h3 id=&#34;redux-orm-0-9-changes&#34;&gt;Redux-ORM 0.9 Changes&lt;/h3&gt;

&lt;p&gt;One of the nice things about the Redux-ORM library is its documentation.  Too many JS libraries have nothing more than a few example snippets in their README, but Redux-ORM has had a couple pretty good intro tutorials and decent API docs since the beginning.&lt;/p&gt;

&lt;p&gt;The Redux-ORM 0.9 changes included a helpful &lt;a href=&#34;https://github.com/tommikaikkonen/redux-orm/wiki/0.9-Migration-Guide&#34;&gt;migration guide for using 0.9&lt;/a&gt;.  Since that document is pretty good as-is, I won&#39;t try to restate everything, but I &lt;em&gt;will&lt;/em&gt; highlight the biggest changes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The 0.8 &lt;code&gt;Schema&lt;/code&gt; class has been renamed to &lt;code&gt;ORM&lt;/code&gt;, due to conceptual changes in how it works internally.  Some of the Schema methods have been replaced:

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;schema.from(state)&lt;/code&gt; is now &lt;code&gt;orm.from(state)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;schema.withMutations(state)&lt;/code&gt; is now &lt;code&gt;orm.mutableSession(state)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;schema.getDefaultState()&lt;/code&gt; is now &lt;code&gt;orm.getEmptyState()&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Session&lt;/code&gt; instances now apply changes immediately, instead of queueing up changes to be applied when you called &lt;code&gt;session.reduce()&lt;/code&gt;.  That means that after any change, like &lt;code&gt;myModel.someField = 123&lt;/code&gt;, the &lt;code&gt;session.state&lt;/code&gt; object will have been correctly immutably updated to reflect the current values (so &lt;code&gt;session.state.MyModel.byId[id].someField&lt;/code&gt; would now be &lt;code&gt;123&lt;/code&gt; right away).  This simplifies complex reducer logic considerably, since you no longer have to worry about what updates are currently pending inside the session&#39;s queue and which have been applied.  This also means that the &lt;code&gt;session.state = session.reduce()&lt;/code&gt; trick I showed previously can be dropped, as the session basically does that for you automatically.&lt;/li&gt;
&lt;li&gt;The prior APIs for creating an entities reducer and selectors from a schema have been moved into separate functions.  I haven&#39;t yet used any of those myself, in either this series or elsewhere.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;QuerySet&lt;/code&gt; &amp;quot;flag&amp;quot; properties for &lt;code&gt;someQuerySet.withModels&lt;/code&gt; and &lt;code&gt;someQuerySet.withRefs&lt;/code&gt; have been removed, and you should now use &lt;code&gt;toModelArray()&lt;/code&gt; or &lt;code&gt;toRefArray()&lt;/code&gt; instead.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;QuerySet&lt;/code&gt;s are now lazy, so you can chain them together and only execute when needed&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Model&lt;/code&gt; classes now can take declarations of expected field names.  In 0.8, &lt;code&gt;Model&lt;/code&gt; instances dynamically created ES5 properties for values that were in the underlying plain data object and for relational fields, each time an instance was built.  In 0.9, you can add field declarations to your model class, and Redux-ORM can more efficiently handle those.  (The field declarations are still optional if you prefer not to use them.)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In addition, 0.9.1 added a &lt;code&gt;Model.upsert()&lt;/code&gt; method.  As mentioned in &lt;a href=&#34;https://blog.isquaredsoftware.com/2016/10/practical-redux-part-2-redux-orm-concepts-and-techniques/&#34;&gt;Part 2&lt;/a&gt;, Redux-ORM didn&#39;t merge or de-duplicate items with the same ID the way Normalizr does.  I had &lt;a href=&#34;https://github.com/tommikaikkonen/redux-orm/issues/50&#34;&gt;opened up an issue to discuss possible fixes&lt;/a&gt;, and the new &lt;code&gt;upsert()&lt;/code&gt; method was added as a result.  So, calling &lt;code&gt;upsert()&lt;/code&gt; instead of &lt;code&gt;create()&lt;/code&gt; takes care of things nicely.&lt;/p&gt;

&lt;h3 id=&#34;upgrading-project-mini-mek-to-redux-orm-0-9&#34;&gt;Upgrading Project Mini-Mek to Redux-ORM 0.9&lt;/h3&gt;

&lt;p&gt;With those changes in mind, let&#39;s go ahead and migrate &lt;strong&gt;&lt;em&gt;Project Mini-Mek&lt;/em&gt;&lt;/strong&gt; to use the latest version of Redux-ORM.  At the time of writing, that&#39;s 0.9.4.  For this step, we&#39;ll update this version explicitly.  I played around with both &lt;code&gt;yarn add&lt;/code&gt; and &lt;code&gt;yarn upgrade&lt;/code&gt; a bit.  Both work, but &lt;code&gt;yarn upgrade&lt;/code&gt; seemed to lock the entry in &lt;code&gt;package.json&lt;/code&gt; to the given version even if I added the &lt;code&gt;^&lt;/code&gt; in front of it.  So, we&#39;ll do it with &lt;code&gt;add&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;yarn add redux-orm@0.9.4
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That updates the contents of &lt;code&gt;node_modules/redux-orm&lt;/code&gt; and modifies our &lt;code&gt;package.json&lt;/code&gt; and &lt;code&gt;yarn.lock&lt;/code&gt; files, so let&#39;s commit those:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/commit/2dd60244fad786ec4a4b0008cfa795bf4ccde7de&#34;&gt;Commit 2dd6024: Update Redux-ORM to 0.9.4&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now we can move on to actually modifying the application code to match.  Fortunately, the changes aren&#39;t overly complicated, and mostly break down into a few edits repeated several times.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/commit/3c1994530b18c3195c95cf9e59c9b159a873209f&#34;&gt;Commit 3c19945: Update Redux-ORM usage to work with 0.9.x&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let&#39;s go through examples of each change:&lt;/p&gt;

&lt;p&gt;First, we need to replace creating a &lt;code&gt;Schema&lt;/code&gt; with an &lt;code&gt;ORM&lt;/code&gt; instead:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/3c1994530b18c3195c95cf9e59c9b159a873209f/src/app/schema/schema.js&#34;&gt;app/schema/schema.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-diff&#34;&gt;-import {Schema} from &amp;quot;redux-orm&amp;quot;;
+import {ORM } from &amp;quot;redux-orm&amp;quot;;

import Pilot from &amp;quot;features/pilots/Pilot&amp;quot;;
import MechDesign from &amp;quot;features/mechs/MechDesign&amp;quot;;
import Mech from &amp;quot;features/mechs/Mech&amp;quot;;

-const schema = new Schema();
-schema.register(Pilot, MechDesign, Mech);
+const orm = new ORM();
+orm.register(Pilot, MechDesign, Mech);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Second, we need to use &lt;code&gt;orm.getEmptyState()&lt;/code&gt;, our reducers that use a &lt;code&gt;Session&lt;/code&gt; should stop using &lt;code&gt;session.state = session.reduce()&lt;/code&gt;, and we should use &lt;code&gt;toModelArray()&lt;/code&gt; instead of &lt;code&gt;withModels&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/3c1994530b18c3195c95cf9e59c9b159a873209f/src/app/reducers/entitiesReducer.js&#34;&gt;app/reducers/entitiesReducer.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-diff&#34;&gt;import {DATA_LOADED} from &amp;quot;features/tools/toolConstants&amp;quot;;

-import schema from &amp;quot;app/schema&amp;quot;
+import orm from &amp;quot;app/schema&amp;quot;

-const initialState = schema.getDefaultState();
+const initialState = orm.getEmptyState();

export function loadData(state, payload) {
    // Create a Redux-ORM session from our entities &amp;quot;tables&amp;quot;
-   const session = schema.from(state);
+   const session = orm.session(state);
    // Get a reference to the correct version of model classes for this Session
    const {Pilot, MechDesign, Mech} = session;

// skip ahead

    // Clear out any existing models from state so that we can avoid
    // conflicts from the new data coming in if data is reloaded
    [Pilot, Mech, MechDesign].forEach(modelType =&amp;gt; {
-       modelType.all().withModels.forEach(model =&amp;gt; model.delete());
-       session.state = session.reduce();
+       modelType.all().toModelArray().forEach(model =&amp;gt; model.delete());
    });

-   // Queue up creation commands for each entry
+   // Immutably update the session state as we insert items
    pilots.forEach(pilot =&amp;gt; Pilot.parse(pilot));

    designs.forEach(design =&amp;gt; MechDesign.parse(design));
    mechs.forEach(mech =&amp;gt; Mech.parse(mech));

-   // Apply the queued updates and return the updated &amp;quot;tables&amp;quot;
-   return session.reduce();
+   // Return the new &amp;quot;tables&amp;quot; object containing the updates
+   return session.state;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Third, our &lt;code&gt;Model&lt;/code&gt; classes should be updated to add declarations for the fields they contain, and we can replace uses of &lt;code&gt;create()&lt;/code&gt; with &lt;code&gt;upsert()&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/3c1994530b18c3195c95cf9e59c9b159a873209f/src/features/pilots/Pilot.js&#34;&gt;features/pilots/Pilot.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-diff&#34;&gt;-import {Model, fk} from &amp;quot;redux-orm&amp;quot;;
+import {Model, fk, attr} from &amp;quot;redux-orm&amp;quot;;

export default class Pilot extends Model {
    static get fields() {
        return {
+           id : attr(),
+           name : attr(),
+           rank : attr(),
+           gunnery : attr(),
+           piloting : attr(),
+           age : attr(),
            mech : fk(&amp;quot;Mech&amp;quot;),
        };
    }

    static parse(pilotData) {
        // We could do useful stuff in here with relations,
        // but since we have no relations yet, all we need
        // to do is pass the pilot data on to create() or upsert()

        // Note that in a static class method, `this` is the
        // class itself, not an instance
-       return this.create(pilotData)
+       return this.upsert(pilotData);
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Once we apply those edits consistently across the rest of the codebase, our application &lt;em&gt;should&lt;/em&gt; now run correctly with no errors.&lt;/p&gt;

&lt;p&gt;I haven&#39;t yet played with &lt;code&gt;upsert()&lt;/code&gt; all that much, but at the moment I don&#39;t see any real downside to using it pretty much anywhere in place of &lt;code&gt;create()&lt;/code&gt;.  Note that because we&#39;re now using it, you could actually copy and paste the &lt;code&gt;pilots.forEach(pilot =&amp;gt; Pilot.parse(pilot));&lt;/code&gt; line in &lt;code&gt;loadData()&lt;/code&gt;, and those Pilot entries would load okay.  You could also load a Pilot entry with an existing ID but a couple different values, and it &lt;em&gt;should&lt;/em&gt; be merged in correctly (only overwriting the changed values).&lt;/p&gt;

&lt;h2 id=&#34;updating-dependencies&#34;&gt;Updating Dependencies&lt;/h2&gt;

&lt;p&gt;The React world has continued to move forward over the last few months as well.  React is up to 15.6, Create-React-App hit the big 1.0 and is now at 1.0.10, and many other libs have been updated.  Since we&#39;re updating things, tt would be good to get everything else up to date too.&lt;/p&gt;

&lt;h3 id=&#34;updating-react-scripts&#34;&gt;Updating React-Scripts&lt;/h3&gt;

&lt;p&gt;As mentioned in &lt;a href=&#34;https://blog.isquaredsoftware.com/2016/12/practical-redux-part-5-loading-and-displaying-data/&#34;&gt;Part 5&lt;/a&gt;, Create-React-App is really just the CLI tool that sets up your initial project.  All the build system magic is taken care of inside the &lt;code&gt;react-scripts&lt;/code&gt; package, and we only need to update that one dependency to take advantage of the latest improvements.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;yarn add --dev react-scripts@latest
&lt;/code&gt;&lt;/pre&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/commit/c6621b34fe5415b3499cad9a445784c779a95f72&#34;&gt;Commit c6621b3: Update react-scripts to 1.0.10&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&#34;updating-other-dependencies&#34;&gt;Updating Other Dependencies&lt;/h3&gt;

&lt;p&gt;We&#39;ve got several other dependencies that need to be updated as well.  We could list them all in a single &lt;code&gt;yarn add&lt;/code&gt; or &lt;code&gt;yarn upgrade&lt;/code&gt; command, but maybe we don&#39;t want to actually just automatically bump them all to the latest versions.  Yarn includes a &lt;code&gt;upgrade-interactive&lt;/code&gt; command that shows us the latest versions of each one, and lets us pick and choose which ones to update:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-cmd&#34;&gt;project-minimek&amp;gt; yarn upgrade-interactive
yarn upgrade-interactive
? Choose which packages to update. (Press &amp;lt;space&amp;gt; to select, &amp;lt;a&amp;gt; to toggle all, &amp;lt;i&amp;gt; to inverse selection)
 dependencies
 ( ) lodash                    4.16.6        ?  4.17.4
 ( ) react                     15.3.2        ?  15.6.1
 ( ) react-dom                 15.3.2        ?  15.6.1
 ( ) react-redux               5.0.0-beta.3  ?  5.0.5
 ( ) react-toggle-display      2.1.1         ?  2.2.0
 ( ) redbox-react              1.3.3         ?  1.4.3
 ( ) redux                     3.6.0         ?  3.7.1
 ( ) redux-devtools-extension  1.0.0         ?  2.13.2
 ( ) redux-thunk               2.1.0         ?  2.2.0
 ( ) reselect                  2.5.4         ?  3.0.1
 ( ) semantic-ui-css           2.2.4         ?  2.2.10
 ( ) semantic-ui-react         0.61.1        ?  0.71.0
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Having said that, we might as well go ahead and bump all of them to the latest versions after all.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/commit/e179c95469d2050ffeae9ac9cb7f3d2eefd136c2&#34;&gt;Commit e179c95: Update app dependencies to current versions&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&#34;removing-the-custom-error-overlay&#34;&gt;Removing the Custom Error Overlay&lt;/h3&gt;

&lt;p&gt;When I first set up the &lt;a href=&#34;https://blog.isquaredsoftware.com/2016/11/practical-redux-part-3-project-planning-and-setup/&#34;&gt;support for Hot Module Replacement in Part 3&lt;/a&gt;, I used a library called Redbox-React to show error messages.  I&#39;ll temporarily throw an error inside a component&#39;s render method to show what it looks like:&lt;/p&gt;


&lt;figure &gt;
    &lt;a href=&#34;https://blog.isquaredsoftware.com/images/2017-07-practical-redux-part-9/redbox-react-error-message.png&#34;&gt;
        &lt;img src=&#34;https://blog.isquaredsoftware.com/images/2017-07-practical-redux-part-9/redbox-react-error-message.png&#34; /&gt;
    &lt;/a&gt;
    
&lt;/figure&gt;


&lt;p&gt;That helps, but it could be better.&lt;/p&gt;

&lt;p&gt;Since that time, Create-React-App has added a powerful and informative built-in error overlay.  All we need to do to make use of it is remove our own error handling code from &lt;code&gt;src/index.js&lt;/code&gt;.  While we&#39;re at it, we&#39;ll also remove the dependency on &lt;code&gt;redbox-react&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-cmd&#34;&gt;yarn remove redbox-react
&lt;/code&gt;&lt;/pre&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/commit/9782e30e434a5b86a8e9ce8f57fe9af0138db2f4&#34;&gt;Commit 9782e30: Remove custom error overlay in favor of CRA&#39;s built-in overlay&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/9782e30e434a5b86a8e9ce8f57fe9af0138db2f4/src/index.js&#34;&gt;src/index.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-diff&#34;&gt;if(module.hot) {
-   // Support hot reloading of components
-   // and display an overlay for runtime errors
-   const renderApp = render;
-   const renderError = (error) =&amp;gt; {
-       const RedBox = require(&amp;quot;redbox-react&amp;quot;).default;
-       ReactDOM.render(
-           &amp;lt;RedBox error={error} /&amp;gt;,
-           rootEl,
-       );
-   };
-
-   // In development, we wrap the rendering function to catch errors,
-   // and if something breaks, log the error and render it to the screen
-   render = () =&amp;gt; {
-       try {
-           renderApp();
-       }
-       catch(error) {
-           console.error(error);
-           renderError(error);
-       }
-   };
-
+   // Support hot reloading of components.
    // Whenever the App component file or one of its dependencies
    // is changed, re-import the updated component and re-render it
    module.hot.accept(&amp;quot;./app/layout/App&amp;quot;, () =&amp;gt; {
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now if we throw the same error, the overlay looks like this:&lt;/p&gt;


&lt;figure &gt;
    &lt;a href=&#34;https://blog.isquaredsoftware.com/images/2017-07-practical-redux-part-9/cra-error-message.png&#34;&gt;
        &lt;img src=&#34;https://blog.isquaredsoftware.com/images/2017-07-practical-redux-part-9/cra-error-message.png&#34; /&gt;
    &lt;/a&gt;
    
&lt;/figure&gt;


&lt;p&gt;Ahhh... much more readable, informative, and soothing.  (Now all we need is &lt;a href=&#34;https://en.wikipedia.org/wiki/Phrases_from_The_Hitchhiker&#39;s_Guide_to_the_Galaxy#Don.27t_Panic&#34;&gt;a towel, and an electronic book with the words &amp;quot;Don&#39;t Panic&amp;quot; written on the front&lt;/a&gt;.)&lt;/p&gt;

&lt;h3 id=&#34;fixing-proptypes&#34;&gt;Fixing PropTypes&lt;/h3&gt;

&lt;p&gt;If we restart our dev server and re-run the page, Create-React-App prints out a warning:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-cmd&#34;&gt;Compiled with warnings.

./src/common/components/FormEditWrapper.jsx
  Line 1:  React.PropTypes is deprecated since React 15.5.0, use the npm module prop-types instead  react/no-deprecated

Search for the keywords to learn more about each warning.
To ignore, add // eslint-disable-next-line to the line before.
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;As part of the preparation for React 16, the React team is working on splitting several capabilities out into separate packages.  This includes &lt;code&gt;React.createClass()&lt;/code&gt; and the &lt;code&gt;PropTypes&lt;/code&gt; API.  React 15.5 started showing warnings any time you try to use those out of the &lt;code&gt;&amp;quot;react&amp;quot;&lt;/code&gt; package,  Most of the major libraries in the React ecosystem have now been updated, but we need to do the same.  Fortunately, this is an easy change:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/commit/8573ed7e62971017d0cf4d4116f43b964cf10aef&#34;&gt;Commit 8573ed7: Use prop-types lib instead of React.PropTypes&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/8573ed7e62971017d0cf4d4116f43b964cf10aef/src/common/components/FormEditWrapper.jsx&#34;&gt;common/components/FormEditWrapper.jsx&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-diff&#34;&gt;-import React, {Component, PropTypes} from &amp;quot;react&amp;quot;;
+import React, {Component} from &amp;quot;react&amp;quot;;
+import PropTypes from &amp;quot;prop-types&amp;quot;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If we restart the server one more time, the warning should be gone.&lt;/p&gt;

&lt;h2 id=&#34;managing-dependency-packages-for-offline-installation&#34;&gt;Managing Dependency Packages for Offline Installation&lt;/h2&gt;

&lt;p&gt;Package managers are powerful tools.  With just a config file and a command, we can download all the dependencies our application needs.  Unfortunately, this also introduces many weaknesses and concerns.  What happens if the latest version of a package breaks something for me?  How can I know that I&#39;m getting the same package contents every time?  What if something happens to a package server, or I need to be able to install these packages offline?&lt;/p&gt;

&lt;p&gt;The infamous &lt;code&gt;left-pad&lt;/code&gt; incident and various Github outages have shown that these are very real questions.  While the use of hashes and locked URLs can ensure that a package manager like NPM is actually seeing the same file each time, that doesn&#39;t help if the network is down.&lt;/p&gt;

&lt;p&gt;There&#39;s been a few approaches suggested for handling NPM dependencies without needing a network connection.  Using NPM or Yarn&#39;s local per-machine cache works, but only if you&#39;ve downloaded the necessary packages on that machine before.  A number of people have suggested that you check in your entire &lt;code&gt;node_modules&lt;/code&gt; folder, but that&#39;s a &lt;em&gt;very&lt;/em&gt; bad idea for a variety of reasons.  That&#39;s potentially tens or hundreds of thousands of files taking up hundreds of megs on disk, AND that can include platform-specific binaries built post-install (like &lt;code&gt;node-sass&lt;/code&gt;&#39;s inclusion of &lt;code&gt;libsass&lt;/code&gt;).  If you check in your &lt;code&gt;node_modules&lt;/code&gt; on a Mac, there&#39;s a good chance that it won&#39;t work on Windows or Linux (and vice versa).&lt;/p&gt;

&lt;p&gt;The most ideal solution is to actually check in the downloaded archives for each package.  Since platform-specific artifacts like &lt;code&gt;libsass&lt;/code&gt; are built &lt;em&gt;after&lt;/em&gt; installation, you can safely clone a repo on any machine, install the packages from that per-repo cache, and have things built properly for that machine.&lt;/p&gt;

&lt;p&gt;Yarn includes an &amp;quot;offline mirror&amp;quot; feature built in.  As far as I know, NPM has not had this built in as a specific capability, but there&#39;s a third-party tool called &lt;a href=&#34;https://github.com/JamieMason/shrinkpack&#34;&gt;Shrinkpack&lt;/a&gt; that can use an NPM &amp;quot;shrinkwrap&amp;quot; file file as the basis for caching package tarballs in the repo.  Based on &lt;a href=&#34;https://twitter.com/acemarke/status/883441155035332608&#34;&gt;a recent Twitter conversation&lt;/a&gt;, it seems that this is also a future planned feature for a future NPM5 release, and that it&#39;s possible to sorta-kinda mimic that with a &lt;code&gt;.npmrc&lt;/code&gt; file and the &lt;code&gt;--prefer-offline&lt;/code&gt; flag for NPM right now.&lt;/p&gt;

&lt;p&gt;So, let&#39;s set up a package cache for Yarn to work with.  First, we need to create a &lt;code&gt;.yarnrc&lt;/code&gt; file in the repo:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/commit/326f253d45faa65cef56330ef0afd82bc628d16a&#34;&gt;Commit 326f253: Add Yarn config file for an offline cache&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/326f253d45faa65cef56330ef0afd82bc628d16a/.yarnrc&#34;&gt;.yarnrc&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;yarn-offline-mirror &amp;quot;./offline-mirror&amp;quot;
yarn-offline-mirror-pruning true
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;We&#39;ll set two values.  &lt;code&gt;yarn-offline-mirror&lt;/code&gt; is the folder where we want Yarn to save the package tarballs.  By default, if you update package versions, Yarn will only add new files to that folder, but not remove outdated ones.  If we set &lt;code&gt;yarn-offline-mirror-prune&lt;/code&gt; to &lt;code&gt;true&lt;/code&gt;, it will also remove old package tarballs to match what&#39;s currently installed.&lt;/p&gt;

&lt;p&gt;Next, we need to actually force Yarn to reinstall everything.  The simplest way is to rename the &lt;code&gt;node_modules&lt;/code&gt; folder to something like &lt;code&gt;node_modules.bak&lt;/code&gt;, then run &lt;code&gt;yarn&lt;/code&gt; again.  Now, if you look inside the &lt;code&gt;offline-mirror&lt;/code&gt; older, you should see around 1000 archives, like &lt;code&gt;react-15.6.1.tgz&lt;/code&gt;.  We can &lt;code&gt;git add&lt;/code&gt; the entire folder, and check them all in:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/commit/063e1bf71b10b9f2854e9390ed96ad4dcadc1291&#34;&gt;Commit XYZ: Commit dependency packages&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And with that, anyone else who is using Yarn along with this project &lt;em&gt;should&lt;/em&gt; be able to use exactly the same packages that I have right now, even if you try to install them while you&#39;re offline.  In theory, anyway.  For full disclosure, this is a feature that I&#39;ve only partly played with myself, and I&#39;ve actually spent the last couple days fighting Yarn trying to get a variation of this to cooperate in my project at work, without success.  (Nitty-gritty details at &lt;a href=&#34;https://github.com/yarnpkg/yarn/issues/3910&#34;&gt;yarn#3910&lt;/a&gt;.)  So, seems really useful, but YMMV in practice.&lt;/p&gt;

&lt;h2 id=&#34;final-thoughts&#34;&gt;Final Thoughts&lt;/h2&gt;

&lt;p&gt;This post was probably a lot less exciting than the last few parts, but in today&#39;s world, updating dependencies is a pretty important topic.  I&#39;m still learning a lot of these intricacies myself (and in some cases, actively struggling with the tools), so please don&#39;t take the steps I showed as absolute gospel.&lt;/p&gt;

&lt;p&gt;The good news is that we can now get back to writing code, adding features, and demonstrating useful techniques.  Next time, we&#39;ll look at how to implement Redux-driven modal dialogs and context menus.&lt;/p&gt;

&lt;h2 id=&#34;further-information&#34;&gt;Further Information&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Redux-ORM 0.9&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/tommikaikkonen/redux-orm/wiki/0.9-Migration-Guide&#34;&gt;Redux-ORM 0.9 Migration Guide&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/tommikaikkonen/redux-orm-primer/compare/dc0a17d93bbfe4b5bc31a2042a73c6ca1a83190a...migrate_to_0_9&#34;&gt;Redux-ORM Primer 0.9 Migration Diff&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/tommikaikkonen/redux-orm/pull/62&#34;&gt;Redux-ORM PR #62: 0.9 implementation and major changes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/tommikaikkonen/redux-orm/issues/50&#34;&gt;Redux ORM #50: De-duplication of entries during item creation?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;http://tommikaikkonen.github.io/redux-orm/index.html&#34;&gt;Redux-ORM API docs&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Create-React-App 1.0&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/facebookincubator/create-react-app/releases/tag/v1.0.0&#34;&gt;What&#39;s New in Create-React-App&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/facebookincubator/create-react-app/releases/tag/v1.0.0&#34;&gt;Create-React-App 1.0 release notes&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Offline Package Caching&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/JamieMason/shrinkpack&#34;&gt;jamiemason/Shrinkpack&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://yarnpkg.com/blog/2016/11/24/offline-mirror/&#34;&gt;Running Yarn offline&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;http://codeforcoffee.org/intro-to-yarn-and-offline-module-caching&#34;&gt;Introduction to Yarn and Offline Module Caching&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;http://evbogue.com/distributednodepackages/&#34;&gt;How to live without NPM (using Yarn for distributed package management)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://twitter.com/acemarke/status/883441155035332608&#34;&gt;Twitter: future plans for caching with NPM5&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;</description>
    </item>
    
    <item>
      <title>Declaratively Rendering Earth in 3D, Part 2: Controlling Cesium with React</title>
      <link>https://blog.isquaredsoftware.com/2017/03/declarative-earth-part-2-cesium-react/</link>
      <pubDate>Tue, 07 Mar 2017 09:41:00 -0500</pubDate>
      
      <guid>https://blog.isquaredsoftware.com/2017/03/declarative-earth-part-2-cesium-react/</guid>
      <description>&lt;p&gt;&lt;/p&gt;

&lt;h2 id=&#34;intro&#34;&gt;Intro&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://blog.isquaredsoftware.com/2017/03/declarative-earth-part-1-cesium-webpack/&#34;&gt;In Part 1 of this series&lt;/a&gt;&lt;/strong&gt;, we started a new React project, updated it to load the Cesium 3D globe library with Webpack, and optimized the production build using Webpack&#39;s DllPlugin.  This time, we&#39;ll &lt;strong&gt;use React components to declaratively control Cesium&#39;s imperative API, including rendering of images and vectors, mouse interaction, and camera control&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;As a reminder, &lt;strong&gt;&lt;a href=&#34;http://cesiumjs.org/&#34;&gt;Cesium.js&lt;/a&gt;&lt;/strong&gt; is a powerful Javascript library for rendering a 3D globe.  It can display a wide variety of geospatial visualizations, including icons and text labels, vector geometries, 3D models, and much more, all on top of a fully-viewable 3D Earth with digital 3D terrain and imagery layers.&lt;/p&gt;

&lt;p&gt;This series assumes some familiarity with Cesium, React, and Webpack, and isn&#39;t intended to teach the basics for them.&lt;/p&gt;

&lt;p&gt;The code for the sample project accompanying this series is on Github at &lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo&#34;&gt;github.com/markerikson/cesium-react-webpack-demo&lt;/a&gt;&lt;/strong&gt;.  The  commits I made for this post can be seen in &lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/pull/2&#34;&gt;PR #2: Use React to render Cesium contents&lt;/a&gt;&lt;/strong&gt; I&#39;ll be linking to many of the commits as I go through the post, as well as specific files in those commits.  I won&#39;t paste every changed file in here or show every single changed line, to save space, but rather try to show the most relevant changes for each commit as appropriate.&lt;/p&gt;

&lt;blockquote&gt;
&lt;h4 id=&#34;update-2020&#34;&gt;Update, 2020&lt;/h4&gt;

&lt;p&gt;While the techniques shown here are still usable, I&#39;ve since learned and would recommend newer approaches.  In particular, I recommend:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Using function components with hooks instead of class components&lt;/li&gt;
&lt;li&gt;Using the &lt;a href=&#34;https://resium.darwineducation.com/&#34;&gt;&lt;strong&gt;Resium library for working with Cesium in React&lt;/strong&gt;&lt;/a&gt;, which provides prebuilt React components that wrap Cesium APIs&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h3 id=&#34;table-of-contents&#34;&gt;&lt;strong&gt;Table of Contents&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#encapsulating-cesium-setup&#34;&gt;Encapsulating Cesium Setup&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#declarative-cesium-rendering-with-react&#34;&gt;Declarative Cesium Rendering with React&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#rendering-initial-content&#34;&gt;Rendering Initial Content&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#updating-apis-from-props&#34;&gt;Updating APIs from Props&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#rendering-multiple-billboards&#34;&gt;Rendering Multiple Billboards&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#rendering-more-cesium-primitives&#34;&gt;Rendering More Cesium Primitives&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#interacting-with-cesium&#34;&gt;Interacting with Cesium&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#adding-mouse-interaction&#34;&gt;Adding Mouse Interaction&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#moving-the-cesium-camera-location&#34;&gt;Moving the Cesium Camera Location&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#wrapping-up-cesium-interaction&#34;&gt;Wrapping Up Cesium Interaction&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#final-thoughts&#34;&gt;Final Thoughts&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#further-information&#34;&gt;Further Information&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&#34;encapsulating-cesium-setup&#34;&gt;Encapsulating Cesium Setup&lt;/h2&gt;

&lt;p&gt;Picking up where we left off, we simply have a Cesium Viewer widget being created by our root &lt;code&gt;&amp;lt;App&amp;gt;&lt;/code&gt; component.  Let&#39;s move the process of initializing the Cesium Viewer into a separate component, called &lt;code&gt;&amp;lt;CesiumGlobe&amp;gt;&lt;/code&gt;.  As we do so, we&#39;re going to make some changes to how we initialize the Viewer.&lt;/p&gt;

&lt;p&gt;First, the Cesium Viewer widget has a number of configurable parts that can be enabled or disabled.  This includes the timeline, the imagery layer picker, and several others.  We&#39;re going to turn those off to reduce the clutter.&lt;/p&gt;

&lt;p&gt;Second, Cesium can use many different sources of imagery and terrain data.  By default, it uses the Bing Maps globe imagery servers.  However, use of Bing Maps requires an API key, and it&#39;s a bad idea to continue using Cesium&#39;s API key in our own application.  So, I&#39;ve created my own API key &lt;a href=&#34;https://www.microsoft.com/maps/create-a-bing-maps-key.aspx&#34;&gt;per the instructions from Microsoft&lt;/a&gt;, and we&#39;ll configure Cesium to use that when it displays imagery.  If you&#39;re following along with this tutorial, &lt;strong&gt;you should create your own Bing Maps API key too&lt;/strong&gt;.  We&#39;re also going to configure Cesium to use the &amp;quot;STK Terrain&amp;quot; dataset that is publicly hosted for non-commercial use by AGI, which will give us high-quality terrain visualization if we zoom in.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/commit/944084ffdd2957b80b7af53f55a8ad8759fbbaf8&#34;&gt;Commit 944084f: Add a separate CesiumGlobe component to render Cesium&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/blob/944084ffdd2957b80b7af53f55a8ad8759fbbaf8/src/cesium/CesiumGlobe.jsx&#34;&gt;src/cesium/CesiumGlobe.jsx&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;import React, {Component} from &amp;quot;react&amp;quot;;

import Viewer from &amp;quot;cesium/Source/Widgets/Viewer/Viewer&amp;quot;;
import BingMapsImageryProvider from &amp;quot;cesium/Source/Scene/BingMapsImageryProvider&amp;quot;;
import CesiumTerrainProvider from &amp;quot;cesium/Source/Core/CesiumTerrainProvider&amp;quot;;

const BING_MAPS_URL = &amp;quot;//dev.virtualearth.net&amp;quot;;
const BING_MAPS_KEY = &amp;quot;ABCDEFGH12345678&amp;quot;;
const STK_TERRAIN_URL = &amp;quot;//assets.agi.com/stk-terrain/world&amp;quot;;

export default class CesiumGlobe extends Component {
    state = {viewerLoaded : false}

    componentDidMount() {
        const imageryProvider = new BingMapsImageryProvider({
            url : BING_MAPS_URL,
            key : BING_MAPS_KEY,
        });

        const terrainProvider = new CesiumTerrainProvider({
            url : STK_TERRAIN_URL
        });

        this.viewer = new Viewer(this.cesiumContainer, {
            animation : false,
            baseLayerPicker : false,
            fullscreenButton : false,
            geocoder : false,
            homeButton : false,
            infoBox : false,
            sceneModePicker : false,
            selectionIndicator : true,
            timeline : false,
            navigationHelpButton : false,
            scene3DOnly : true,
            imageryProvider,
            terrainProvider,
        });
    }

    componentWillUnmount() {
        if(this.viewer) {
            this.viewer.destroy();
        }
    }
    render() {
        const containerStyle = {
            width: &#39;100%&#39;,
            height: &#39;100%&#39;,
            top: 0,
            left: 0,
            bottom: 0,
            right: 0,
            position: &#39;fixed&#39;,
            display : &amp;quot;flex&amp;quot;,
            alignItems : &amp;quot;stretch&amp;quot;,
        };

        const widgetStyle = {
            flexGrow : 2
        }

        return (
            &amp;lt;div className=&amp;quot;cesiumGlobeWrapper&amp;quot; style={containerStyle}&amp;gt;
                &amp;lt;div
                    className=&amp;quot;cesiumWidget&amp;quot;
                    ref={ element =&amp;gt; this.cesiumContainer = element }
                    style={widgetStyle}
                /&amp;gt;
            &amp;lt;/div&amp;gt;
        );
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The new &lt;code&gt;&amp;lt;CesiumGlobe&amp;gt;&lt;/code&gt; component follows the same basic pattern as before for creating the Viewer instance, but we&#39;re disabling all the other built-in widgets and passing in the specifically-configured imagery and terrain providers.  We&#39;re also now applying layout styles to force the Cesium container to fill the entire page.&lt;/p&gt;

&lt;p&gt;That wraps up the basic application setup.  Let&#39;s move on to using React to interact with Cesium.&lt;/p&gt;

&lt;h2 id=&#34;declarative-cesium-rendering-with-react&#34;&gt;Declarative Cesium Rendering with React&lt;/h2&gt;

&lt;p&gt;React is primarily used for declarative rendering of specific UI elements, whether they&#39;re &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt;s in standard React, &lt;code&gt;&amp;lt;View&amp;gt;&lt;/code&gt;s in React Native, or something similar.  However, &lt;strong&gt;one of React&#39;s strengths is the ability to create declarative components that wrap up imperative APIs, using React&#39;s component lifecycle methods&lt;/strong&gt;.  This allows React to control things like jQuery plugins, canvas libraries, and much more.  We&#39;re going to apply this pattern to drive our Cesium display.&lt;/p&gt;

&lt;h3 id=&#34;rendering-initial-content&#34;&gt;Rendering Initial Content&lt;/h3&gt;

&lt;p&gt;Right now, our &lt;code&gt;&amp;lt;CesiumGlobe&amp;gt;&lt;/code&gt; component only creates the Cesium viewer.  We&#39;re going to need it to also act as the parent component for all of our Cesium-related React components.  To do that, we need to split the rendering logic into two parts.  The first time &lt;code&gt;&amp;lt;CesiumGlobe&amp;gt;&lt;/code&gt; renders, we want it to &lt;em&gt;only&lt;/em&gt; render the container element for the Cesium widget.  Then, &lt;em&gt;after&lt;/em&gt; Cesium is loaded, we need to re-render and include all of our Cesium-related components, so they can make use of the Cesium Viewer&#39;s properties.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/commit/f02144e3766bcde28e70616d50ed26df9a67f182&#34;&gt;Commit f02144e: Add logic for rendering contents in CesiumGlobe&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/blob/f02144e3766bcde28e70616d50ed26df9a67f182/src/cesium/CesiumGlobe.jsx&#34;&gt;src/cesium/CesiumGlobe.jsx&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-diff&#34;&gt;    componentDidMount() {
        // Skip Viewer init
        
+       // Force immediate re-render now that the Cesium viewer is created
+       this.setState({viewerLoaded : true}); 
    }
    
 
+   renderContents() {
+       const {viewerLoaded} = this.state;
+       let contents = null;
+
+       if(viewerLoaded) {
+           contents = (
+               &amp;lt;span&amp;gt;
+               &amp;lt;/span&amp;gt;
+           );
+       }

+       return contents;
+   }

   
// In render()

+       const contents = this.renderContents()
+
        return (
            &amp;lt;div className=&amp;quot;cesiumGlobeWrapper&amp;quot; style={containerStyle}&amp;gt;
                &amp;lt;div
                    className=&amp;quot;cesiumWidget&amp;quot;
                    ref={ element =&amp;gt; this.cesiumContainer = element }
                    style={widgetStyle}
-               /&amp;gt;
+               &amp;gt;
+                   {contents}
+               &amp;lt;/div&amp;gt;
            &amp;lt;/div&amp;gt;
        );
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;As we start defining our Cesium-based React components, we can insert them into the contents &lt;code&gt;&amp;lt;span&amp;gt;&lt;/code&gt;, and React will render them properly.&lt;/p&gt;

&lt;p&gt;With that in place, it&#39;s time to see our first example of actually controlling Cesium&#39;s API in a React component.  &lt;strong&gt;We&#39;re going to create a small component that renders the React logo as a Cesium billboard&lt;/strong&gt;.  Let&#39;s jump right into the code and see what&#39;s going on:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/commit/9ac0bcaadfd8a46f6c3fd01070d76eb72de33df9&#34;&gt;Commit 9ac0bca: Render React logo as a Cesium billboard&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/blob/9ac0bcaadfd8a46f6c3fd01070d76eb72de33df9/src/cesium/CesiumBillboardExample.jsx&#34;&gt;src/cesium/CesiumBillboardExample.jsx&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;import React, {Component} from &amp;quot;react&amp;quot;;

import Cartesian3 from &amp;quot;cesium/Source/Core/Cartesian3&amp;quot;;
import BillboardCollection from &amp;quot;cesium/Source/Scene/BillboardCollection&amp;quot;;

import logo from &amp;quot;../logo.svg&amp;quot;;

export default class CesiumBillboardExample extends Component {
    constructor(props) {
        super(props);

        this.billboards = new BillboardCollection();

        const {scene} = props;

        if(scene) {
            scene.primitives.add(this.billboards);
        }
    }

    componentWillUnmount() {
        const {billboards} = this;

        if(!billboards.isDestroyed()) {
            billboards.destroy();
        }

        const {scene} = this.props;

        if(scene &amp;amp;&amp;amp; !scene.isDestroyed() &amp;amp;&amp;amp; scene.primitives) {
            scene.primitives.remove(billboards);
        }
    }

    componentDidMount() {
        const lat = 37.484505, lon = -122.147877;
        const position = Cartesian3.fromDegrees(lon, lat);

        this.billboard = this.billboards.add({
            position,
            image : logo,
        });
    }

    render() {
        return null;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;There&#39;s several important things to see here.  First, our &lt;code&gt;render&lt;/code&gt; method simply returns &lt;code&gt;null&lt;/code&gt;.  This component doesn&#39;t render &lt;em&gt;any&lt;/em&gt; normal UI output.  React does require that &lt;code&gt;render&lt;/code&gt; exists, though, so we just tell React this component isn&#39;t rendering anything.&lt;/p&gt;

&lt;p&gt;Second, we create a Cesium BillboardCollection in the constructor, and very carefully clean it up in &lt;code&gt;componentWillUnmount&lt;/code&gt;.  The component also expects to get a Cesium Scene instance as a prop, and if it exists, will tell the Scene to render all Billboards in the BillboardCollection it created.&lt;/p&gt;

&lt;p&gt;Third, when the component mounts, we create a Cesium Billboard instance, and set its position by converting a lat/lon pair into Cartesian XYZ coordinates, which is what Cesium requires.&lt;/p&gt;

&lt;p&gt;If we load the app, here&#39;s what we should see:&lt;/p&gt;


&lt;figure &gt;
    &lt;a href=&#34;https://blog.isquaredsoftware.com/images/2017-03-cesium-react-webpack/react-logo-billboard.jpg&#34;&gt;
        &lt;img src=&#34;https://blog.isquaredsoftware.com/images/2017-03-cesium-react-webpack/react-logo-billboard.jpg&#34; /&gt;
    &lt;/a&gt;
    
&lt;/figure&gt;


&lt;p&gt;Another big step in the right direction, but we can do more.&lt;/p&gt;

&lt;h3 id=&#34;updating-apis-from-props&#34;&gt;Updating APIs From Props&lt;/h3&gt;

&lt;p&gt;That React logo is currently sitting in a fixed location.  Since applications are dynamic, we should be able to update what we&#39;re displaying.  Normally we&#39;d just re-render our app with new state and let React take care of updating the UI, but things are just a bit different here.  Let&#39;s see if we can make the logo jump to a new location when a button is clicked.&lt;/p&gt;

&lt;p&gt;Before we can show a button on screen, we&#39;ll need to make a few tweaks to the styling and layout in the page.  Right now the Cesium container div is filling the entire screen directly, and any other HTML content we try to show will wind up behind the Cesium div.  We&#39;ll have to shuffle things around a bit so that we can overlay some HTML content on top of Cesium.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/commit/81d8d503ebd19f5ebdb1e099f8302f0c90c102ba&#34;&gt;Commit 81d8d50: Rework layout styling to show content over the globe&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Next, let&#39;s tackle making the logo billboard move.  This is where React&#39;s lifecycle methods come into play.  In particular, &lt;strong&gt;&lt;code&gt;componentWillReceiveProps&lt;/code&gt; and &lt;code&gt;componentDidUpdate&lt;/code&gt; are good places to compare previous prop values with new prop values to see if anything&#39;s changed, and do something in response&lt;/strong&gt;.  We&#39;ll start by adding logic to our &lt;code&gt;&amp;lt;CesiumBillboardExample&amp;gt;&lt;/code&gt; to accept some coordinates as a prop, and set the billboard&#39;s position any time those change:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/commit/145e67e613b51edd4f5949183d1b663c06f6a787&#34;&gt;Commit 145e67e: Implement logic to move the logo on button click&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/blob/145e67e613b51edd4f5949183d1b663c06f6a787/src/cesium/CesiumBillboardExample.jsx&#34;&gt;src/cesium/CesiumBillboardExample.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-diff&#34;&gt;+   componentDidUpdate(prevProps) {
+       if(prevProps.logoCoords !== this.props.logoCoords &amp;amp;&amp;amp; this.props.logoCoords) {
+           this.updateIcon();
+       }
+   }
+
+   updateIcon() {
+       const {logoCoords} = this.props;
+       const {lat, lon} = logoCoords;
+
+       if(this.billboard) {
+           const newPosition = Cartesian3.fromDegrees(lon, lat);
+
+           this.billboard.position = newPosition;
+       }
+   }
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Whenever the component has received props, we diff the &lt;code&gt;logoCoords&lt;/code&gt; prop to see if it changed, and if so, call the new &lt;code&gt;updateIcon()&lt;/code&gt; method.  That simply takes whatever the lat/lon coordinates are from props, and applies those to the billboard.  &lt;strong&gt;This is almost identical to normal React rendering in concept - we don&#39;t care what the actual values are, we just take the current values and use them for the output&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;We also need to pass this new &lt;code&gt;logoCoords&lt;/code&gt; prop down the component hierarchy:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/blob/145e67e613b51edd4f5949183d1b663c06f6a787/src/cesium/CesiumGlobe.jsx&#34;&gt;src/cesium/CesiumGlobe.jsx&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-diff&#34;&gt;        if(viewerLoaded) {
            const {scene} = this.viewer;
+           const {logoCoords} = this.props;

            contents = (
                &amp;lt;span&amp;gt;
-                   &amp;lt;CesiumBillboardExample scene={scene} /&amp;gt;
+                   &amp;lt;CesiumBillboardExample scene={scene} logoCoords={logoCoords} /&amp;gt;
                &amp;lt;/span&amp;gt;
            );
        }
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And we&#39;ll update the &lt;code&gt;&amp;lt;App&amp;gt;&lt;/code&gt; component to have logo coordinates in state, and update them when we click a button:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/blob/145e67e613b51edd4f5949183d1b663c06f6a787/src/App.js&#34;&gt;src/App.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-diff&#34;&gt;class App extends Component {
+    state = {logoCoords : null}

+   onMoveLogoClicked = () =&amp;gt; {
+       const logoCoords = {lat : 39.097465, lon : -84.50703};
+       this.setState({logoCoords});
+   }

    render() {
+        const {logoCoords} = this.state;


        return (
            &amp;lt;div style={containerStyle}&amp;gt;
-               &amp;lt;CesiumGlobe/&amp;gt;
+               &amp;lt;CesiumGlobe logoCoords={logoCoords} /&amp;gt;
                &amp;lt;div style={{position : &amp;quot;fixed&amp;quot;, top : 0}}&amp;gt;
                    &amp;lt;div style={{color : &amp;quot;white&amp;quot;, fontSize: 40, }}&amp;gt;
                        Text Over the Globe
                    &amp;lt;/div&amp;gt;
+                   &amp;lt;button
+                       onClick={this.onMoveLogoClicked}
+                       style={{fontSize: 40}}
+                   &amp;gt;
+                       Move Logo
+                   &amp;lt;/button&amp;gt;
                &amp;lt;/div&amp;gt;
            &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If we reload and click the &amp;quot;Move Logo&amp;quot; button, we should see the React logo jump from San Francisco to Cincinnati:&lt;/p&gt;


&lt;figure &gt;
    &lt;a href=&#34;https://blog.isquaredsoftware.com/images/2017-03-cesium-react-webpack/react-logo-moved.jpg&#34;&gt;
        &lt;img src=&#34;https://blog.isquaredsoftware.com/images/2017-03-cesium-react-webpack/react-logo-moved.jpg&#34; /&gt;
    &lt;/a&gt;
    
&lt;/figure&gt;


&lt;p&gt;(There&#39;s a bit of asymmetry here in that the original logo coordinates are still coming from &lt;code&gt;componentDidMount&lt;/code&gt;, but the updated values are coming from the &lt;code&gt;&amp;lt;App&amp;gt;&lt;/code&gt; component as the &lt;code&gt;logoCoords&lt;/code&gt; prop.  I probably should have moved the original coordinates up into &lt;code&gt;&amp;lt;App&amp;gt;&lt;/code&gt;&#39;s initial state, but I didn&#39;t, and don&#39;t feel like going back to rewrite things.)&lt;/p&gt;

&lt;h3 id=&#34;rendering-multiple-billboards&#34;&gt;Rendering Multiple Billboards&lt;/h3&gt;

&lt;p&gt;Rendering one billboard is great, but what happens when we want to render &lt;em&gt;many&lt;/em&gt; billboards?  We need to make this process repeatable.  Let&#39;s extract the core logic for rendering a billboard out into its own component:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/commit/6776f546e69c18acaea8b8467ff9b8c2870b47bb&#34;&gt;Commit 6776f54: Add a reusable CesiumBillboard component&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/blob/6776f546e69c18acaea8b8467ff9b8c2870b47bb/src/cesium/primitives/CesiumBillboard.jsx&#34;&gt;src/cesium/primitives/CesiumBillboard.jsx&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;import {Component} from &amp;quot;react&amp;quot;;

import Cartesian3 from &amp;quot;cesium/Source/Core/Cartesian3&amp;quot;;
import HorizontalOrigin from &amp;quot;cesium/Source/Scene/HorizontalOrigin&amp;quot;;
import VerticalOrigin from &amp;quot;cesium/Source/Scene/VerticalOrigin&amp;quot;;

import {shallowEqual} from &amp;quot;utils/utils&amp;quot;;

export default class CesiumBillboard extends Component {
    componentDidMount() {
        const {billboards} = this.props;

        if(billboards) {
            this.billboard = billboards.add({
                eyeOffset : new Cartesian3(0.0, 0.0, 0.0),
                horizontalOrigin : HorizontalOrigin.CENTER,
                verticalOrigin : VerticalOrigin.CENTER,
            });
        }
        
        this.updateIcon();
    }

    componentDidUpdate(prevProps) {
        if(!shallowEqual(this.props, prevProps)) {
            this.updateIcon();
        }
    }

    updateIcon() {
        const {image, selected, scale = 1.0, lat, lon, alt, show = true, width} = this.props;

        if(this.billboard) {
            const newLocation = Cartesian3.fromDegrees(lon, lat, alt);

            this.billboard.position = newLocation;
            if(image) {
                this.billboard.image = image;
            }
            this.billboard.show = show;
            this.billboard.scale = scale;

            if(width) {
                this.billboard.width = width;
            }
        }
    }

    componentWillUnmount() {
        const {billboards} = this.props;

        if(billboards &amp;amp;&amp;amp; !billboards.isDestroyed() &amp;amp;&amp;amp; this.billboard) {
            billboards.remove(this.billboard);
        }
    }

    render() {
        return null;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It&#39;s the same basic approach we used in the previous example, but cleaned up and made more generic.  Now, our &lt;code&gt;&amp;lt;CesiumBillboard&amp;gt;&lt;/code&gt; component actually receives a BillboardCollection instance as a prop.  It takes several props that match Billboard&#39;s options, and just removes its billboard from the collection when unmounted.&lt;/p&gt;

&lt;p&gt;Next, we&#39;ll create a &lt;code&gt;&amp;lt;CesiumProjectContents&amp;gt;&lt;/code&gt; component that can render the &lt;code&gt;&amp;lt;CesiumBillboard&amp;gt;&lt;/code&gt; instances:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/commit/02077028997db9f3248bc9d1256762ccd729da5b&#34;&gt;Commit 0207702: Add a CesiumContents component to render many billboards&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/blob/02077028997db9f3248bc9d1256762ccd729da5b/src/cesium/CesiumProjectContents.jsx&#34;&gt;src/cesium/CesiumProjectContents.jsx&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;import React, {Component} from &amp;quot;react&amp;quot;;

import BillboardCollection from &amp;quot;cesium/Source/Scene/BillboardCollection&amp;quot;;

import CesiumBillboard from &amp;quot;./primitives/CesiumBillboard&amp;quot;;

export class CesiumProjectContents extends Component {
    constructor(props) {
        super(props);

        this.billboards = new BillboardCollection();

        const {scene} = props;

        if(scene) {
            scene.primitives.add(this.billboards);
        }
    }

    componentWillUnmount() {
        const {billboards} = this;

        if(!billboards.isDestroyed()) {
            billboards.destroy();
        }

        const {scene} = this.props;

        if(scene &amp;amp;&amp;amp; !scene.isDestroyed() &amp;amp;&amp;amp; scene.primitives) {
            scene.primitives.remove(billboards);
        }
    }

    render() {
        const {icons = []} = this.props;

        const renderedBillboards = icons.map( (icon, index) =&amp;gt;
            &amp;lt;CesiumBillboard
                {...icon}
                billboards={this.billboards}
                key={index}
            /&amp;gt;
        );

        return (
            &amp;lt;span&amp;gt;
                {renderedBillboards}
            &amp;lt;/span&amp;gt;
        );
    }
}

export default CesiumProjectContents;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Again, same basic pattern: receive a Cesium Scene as a prop, create a BillboardCollection and attach it to the Scene, clean up on unmount.  This time, though, we&#39;re also receiving an array of &amp;quot;icons&amp;quot; as props, and turning those into &lt;code&gt;&amp;lt;CesiumBillboard&amp;gt;&lt;/code&gt; components.  This is normal React rendering in action.&lt;/p&gt;

&lt;p&gt;Finally, we&#39;ll remove the prior &amp;quot;Move Logo&amp;quot; button from &lt;code&gt;&amp;lt;App&amp;gt;&lt;/code&gt;, and instead have it render two different logos: the React logo over San Francisco, and the Cincinnati Reds logo over the Great American Ballpark in Cincinnati:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/commit/dc7b4c089c4156d391805f41f051d8026c554b3e&#34;&gt;Commit dc7b4c0: Render multiple logos at once&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/blob/dc7b4c089c4156d391805f41f051d8026c554b3e/src/App.js&#34;&gt;src/App.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-diff&#34;&gt;+import reactLogo from &amp;quot;logo.svg&amp;quot;;
+import redsLogo from &amp;quot;./redsLogo.png&amp;quot;;

class App extends Component {
+    state = {
+        reactLogo : {lat : 37.484505, lon : -122.147877, image : reactLogo},
+        redsLogo : { lat : 39.097465, lon : -84.50703, image : redsLogo, scale : 0.3}
+    }

+   render() {
-       const {logoCoords} = this.state;
+       const {reactLogo, redsLogo} = this.state;

+       const icons = [reactLogo, redsLogo];

        return (
            &amp;lt;div style={containerStyle}&amp;gt;
-               &amp;lt;CesiumGlobe logoCoords={logoCoords} /&amp;gt;
+               &amp;lt;CesiumGlobe icons={icons} /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If we reload the application and zoom in a bit, here&#39;s what it looks like:&lt;/p&gt;


&lt;figure &gt;
    &lt;a href=&#34;https://blog.isquaredsoftware.com/images/2017-03-cesium-react-webpack/react-reds-logos.jpg&#34;&gt;
        &lt;img src=&#34;https://blog.isquaredsoftware.com/images/2017-03-cesium-react-webpack/react-reds-logos.jpg&#34; /&gt;
    &lt;/a&gt;
    
&lt;/figure&gt;


&lt;h3 id=&#34;rendering-more-cesium-primitives&#34;&gt;Rendering More Cesium Primitives&lt;/h3&gt;

&lt;p&gt;Now that we have a good pattern set up for rendering Cesium Billboards, we can do the same thing for Labels and Polylines.  We&#39;ll skip the source code for now, but here&#39;s the commits:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/commit/e264e9f30c51be7f18879a4fe51bafbd6b38cfc1&#34;&gt;Commit e264e9f: Add a CesiumLabel component&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/commit/74f81c3869e332854c58f73fa35dc9ea55b30b19&#34;&gt;Commit 74f81c3: Add rendering of labels&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/commit/efa729a86a55153758ee3cc2d347f063f59925df&#34;&gt;Commit efa729a: Add a CesiumPolyline component&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/commit/3fbd2b5c21833bb75aab7f11dde930fa9eb14ee4&#34;&gt;Commit 3fbd2b5: Add rendering of polylines&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here&#39;s another look at the updated globe after adding an example label and polyline:&lt;/p&gt;


&lt;figure &gt;
    &lt;a href=&#34;https://blog.isquaredsoftware.com/images/2017-03-cesium-react-webpack/multiple-primitive-types.jpg&#34;&gt;
        &lt;img src=&#34;https://blog.isquaredsoftware.com/images/2017-03-cesium-react-webpack/multiple-primitive-types.jpg&#34; /&gt;
    &lt;/a&gt;
    
&lt;/figure&gt;


&lt;p&gt;Pretty sweet!&lt;/p&gt;

&lt;h2 id=&#34;interacting-with-cesium&#34;&gt;Interacting with Cesium&lt;/h2&gt;

&lt;p&gt;We now have the ability to render multiple types of visual primitives inside of Cesium.  However, we don&#39;t yet have a way to interact with the globe from the application, other than the basic mouse-based camera controls that are built into Cesium itself.&lt;/p&gt;

&lt;p&gt;Our next task will be to add some interaction capabilities.  We need to hook into Cesium&#39;s event APIs so that we can handle mouse events, and we need to be able to update the Cesium camera position programmatically.&lt;/p&gt;

&lt;h3 id=&#34;adding-mouse-interaction&#34;&gt;Adding Mouse Interaction&lt;/h3&gt;

&lt;p&gt;Cesium&#39;s mouse events API revolves around the &lt;code&gt;ScreenSpaceEventHandler&lt;/code&gt; class, as seen in Cesium&#39;s &lt;a href=&#34;http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Picking.html&amp;amp;label=All&#34;&gt;&amp;quot;Picking&amp;quot; demo&lt;/a&gt;.  Application code creates a &lt;code&gt;ScreenSpaceEventHandler&lt;/code&gt; instance and passes it the &lt;code&gt;scene.canvas&lt;/code&gt; element that Cesium is rendering into, then adds callbacks for various mouse events.  We&#39;re going to create a component that just listens for mouse left click events.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/commit/ab9b68ba198e0a207711525b90d1cc3ae4ce3245&#34;&gt;Commit ab9b68b: Add a basic handler for Cesium mouse events&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/blob/ab9b68ba198e0a207711525b90d1cc3ae4ce3245/src/cesium/CesiumClickHandler.jsx&#34;&gt;src/cesium/CesiumClickHandler.jsx&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;import {Component} from &amp;quot;react&amp;quot;;

import ScreenSpaceEventHandler from &amp;quot;cesium/Source/Core/ScreenSpaceEventHandler&amp;quot;;
import SSET from &amp;quot;cesium/Source/Core/ScreenSpaceEventType&amp;quot;;
import CesiumMath from &amp;quot;cesium/Source/Core/Math&amp;quot;;

import {noop} from &amp;quot;utils/utils&amp;quot;;

export default class CesiumClickHandler extends Component {
    static defaultProps = {
        onLeftClick : noop
    }

    componentDidMount() {
        const {scene} = this.props;

        if(scene &amp;amp;&amp;amp; scene.canvas) {
            this.screenEvents = new ScreenSpaceEventHandler(scene.canvas);
            this.createInputHandlers();
        }
    }

    componentWillUnmount() {
        if(this.screenEvents &amp;amp;&amp;amp; !this.screenEvents.isDestroyed()) {
            this.screenEvents.destroy();
        }
    }

    createInputHandlers() {
        this.screenEvents.setInputAction(this.onMouseLeftClick, SSET.LEFT_CLICK);
    }

    onMouseLeftClick = (e) =&amp;gt; {
        const {position : clientPos} = e;
        const mapCoordsRadians = this.pickMapCoordinates(clientPos);

        if(mapCoordsRadians) {
            const mapCoordsDegrees = {
                lat : CesiumMath.toDegrees(mapCoordsRadians.latitude),
                lon : CesiumMath.toDegrees(mapCoordsRadians.longitude),
            };

            this.props.onLeftClick(mapCoordsDegrees);
        }
    }

    pickMapCoordinates(screenPos) {
        const {scene} = this.props;
        let mapCoords;

        if(scene) {
            const cartesianPos = scene.camera.pickEllipsoid(screenPos);

            if(cartesianPos) {
                mapCoords = scene.globe.ellipsoid.cartesianToCartographic(cartesianPos);
            }
        }

        return mapCoords;
    }

    render() {
        return null;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This component uses the same pattern of creating Cesium API objects in the constructor and cleaning them up in &lt;code&gt;componentWillUnmount&lt;/code&gt;.  In this specific example, we subscribe to Cesium&#39;s &lt;code&gt;ScreenSpaceEventType.LEFT_CLICK&lt;/code&gt; event, and pass a class method as the callback function.&lt;/p&gt;

&lt;p&gt;Cesium has a couple different event object formats for different mouse event types.  For &lt;code&gt;LEFT_CLICK&lt;/code&gt;, the event contains a field called &lt;code&gt;position&lt;/code&gt;, which has the screen X/Y coordinates of the mouse click.  We want to convert those screen coordinates into the lat/lon coordinates on the globe where the mouse click occurred.  Cesium provides the lat/lon coordinates in radians, so we also convert those into degrees.  Finally, we call &lt;code&gt;this.props.onLeftClick(mapCoordsDegrees)&lt;/code&gt; to pass the click coordinates upwards to any component that might have given us a click callback, and use &lt;code&gt;defaultProps&lt;/code&gt; to ensure that the &lt;code&gt;onLeftClick&lt;/code&gt; prop is always a function.&lt;/p&gt;

&lt;p&gt;Now, we just need to hook up the &lt;code&gt;&amp;lt;CesiumClickHandler&amp;gt;&lt;/code&gt; component to the rest of the application, and pass down a click handler:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/commit/96c5223cf6ae3cc36ab0b6b500107509a77dfd38&#34;&gt;Commit 96c5223: Add mouse handling&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/blob/96c5223cf6ae3cc36ab0b6b500107509a77dfd38/src/cesium/CesiumGlobe.jsx&#34;&gt;src/cesium/CesiumGlobe.jsx&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-diff&#34;&gt;import CesiumProjectContents from &amp;quot;./CesiumProjectContents&amp;quot;;
+import CesiumClickHandler from &amp;quot;./CesiumClickHandler&amp;quot;;

// Skip ahead

        if(viewerLoaded) {
            const {scene} = this.viewer;
-           const {icons, labels, polylines} = this.props;
+           const {icons, labels, polylines, onLeftClick} = this.props;

            contents = (
                &amp;lt;span&amp;gt;
                    &amp;lt;CesiumProjectContents
                        scene={scene}
                        icons={icons}
                        labels={labels}
                        polylines={polylines}
                    /&amp;gt;
+                   &amp;lt;CesiumClickHandler
+                       scene={scene}
+                       onLeftClick={onLeftClick}
+                   /&amp;gt;
                &amp;lt;/span&amp;gt;
            );
        }
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/blob/96c5223cf6ae3cc36ab0b6b500107509a77dfd38/src/App.js&#34;&gt;src/App.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-diff&#34;&gt;
+   handleLeftClick = (coords) =&amp;gt; {
+       console.log(&amp;quot;Left mouse clicked at: &amp;quot;, coords)
+   }

// Skip to rendering

-               &amp;lt;CesiumGlobe icons={icons} labels={labels} polylines={polylines} /&amp;gt;
+               &amp;lt;CesiumGlobe
+                   icons={icons}
+                   labels={labels}
+                   polylines={polylines}
+                   onLeftClick={this.handleLeftClick}
+               /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If we click on the globe, we should see output similar to this:&lt;/p&gt;


&lt;figure &gt;
    &lt;a href=&#34;https://blog.isquaredsoftware.com/images/2017-03-cesium-react-webpack/left-mouse-click.png&#34;&gt;
        &lt;img src=&#34;https://blog.isquaredsoftware.com/images/2017-03-cesium-react-webpack/left-mouse-click.png&#34; /&gt;
    &lt;/a&gt;
    
&lt;/figure&gt;


&lt;h3 id=&#34;moving-the-cesium-camera-location&#34;&gt;Moving the Cesium Camera Location&lt;/h3&gt;

&lt;p&gt;Cesium has a &lt;code&gt;Camera&lt;/code&gt; class that provides methods for moving the camera around.  The main method is &lt;code&gt;camera.flyTo()&lt;/code&gt;, which is a &lt;em&gt;very&lt;/em&gt; imperative method for changing the camera location.&lt;/p&gt;

&lt;p&gt;We can wrap this API using roughly the same approach as our other components, but with a bit of a difference.  Thus far, we&#39;ve &lt;em&gt;always&lt;/em&gt; applied the current prop values to the Cesium primitives, such as image URL and lat/lon coordinates.  That&#39;s great for mimicking the same kind of &amp;quot;stateless rendering&amp;quot; approach that React normally uses.&lt;/p&gt;

&lt;p&gt;However, if we follow the same pattern for the camera, we&#39;re going to force the camera to jump to the given coordinates &lt;em&gt;every time the application re-renders&lt;/em&gt;.  That&#39;s not going to be very user-friendly.  What we &lt;em&gt;really&lt;/em&gt; want is to only update the camera position when the request camera coordinates &lt;em&gt;change&lt;/em&gt; from the previous requested values.  So, what we&#39;ll do this time is compare the previous and current coordinate props in &lt;code&gt;componentDidUpdate&lt;/code&gt;, and make the camera update logic conditional.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/commit/60eed65299fa7374ba5800d3fdbbc031abe863fd&#34;&gt;Commit 60eed65: Add a CesiumCameraManager component&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/blob/60eed65299fa7374ba5800d3fdbbc031abe863fd/src/cesium/CesiumCameraManager.jsx&#34;&gt;src/cesium/CesiumCameraManager&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;import {Component} from &amp;quot;react&amp;quot;;

import CesiumMath from &amp;quot;cesium/Source/Core/Math&amp;quot;;
import Cartesian3 from &amp;quot;cesium/Source/Core/Cartesian3&amp;quot;;

import {isUndefined} from &amp;quot;utils/utils&amp;quot;;


export default class CesiumCameraManager extends Component {
    componentDidMount() {
        const {camera} = this.props;

        if(camera) {
            this.handleUpdatedCameraProps({}, this.props.globe, camera);
        }
    }

    componentDidUpdate(prevProps) {
        const {flyToLocation, camera} = this.props;
        if(prevProps.flyToLocation !== flyToLocation) {
            this.handleUpdatedCameraProps(prevProps.flyToLocation, flyToLocation, camera);
        }
    }

    handleUpdatedCameraProps(oldFlyTo, flyToLocation, camera) {
        let newLocationObject = null;

        if(flyToLocation &amp;amp;&amp;amp; oldFlyTo !== flyToLocation) {
            newLocationObject = flyToLocation;
        }

        if(newLocationObject) {
            let {lat, lon, alt = undefined, heading, pitch, roll} = newLocationObject;
            const {delay = 0} = newLocationObject;

            let orientation = undefined;

            if(lat === 0.0 &amp;amp;&amp;amp; lon === 0.0) {
                // Nobody _really_ wants a closeup of the ocean off west Africa
                lat = 35.0;
                lon = -117.0;
                alt = 2500000;
            }

            if(!isUndefined(heading)) {
                orientation = {
                    heading : CesiumMath.toRadians(heading),
                    pitch : CesiumMath.toRadians(pitch),
                    roll : CesiumMath.toRadians(roll),
                };
            }

            camera.flyTo({
                destination : Cartesian3.fromDegrees(lon, lat, alt),
                duration : delay,
                orientation,
            });
        }
    }

    render() {
        return null;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;There&#39;s some handling for various edge cases in there, but the basic idea is pretty simple.  If the &lt;code&gt;flyToLocation&lt;/code&gt; prop has changed, we try to extract the new coordinates from it, and call &lt;code&gt;camera.flyTo()&lt;/code&gt; with the results.&lt;/p&gt;

&lt;p&gt;Let&#39;s hook this component into the application, and add a button that will jump the camera to San Diego&#39;s harbor:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/commit/50af234084687896a045e2462a2d862dfdbc58b1&#34;&gt;Commit 50af234: Add camera management&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/blob/50af234084687896a045e2462a2d862dfdbc58b1/src/cesium/CesiumGlobe.jsx&#34;&gt;src/cesium/CesiumGlobe.jsx&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-diff&#34;&gt;import CesiumClickHandler from &amp;quot;./CesiumClickHandler&amp;quot;;
+import CesiumCameraManager from &amp;quot;./CesiumCameraManager&amp;quot;;

// Skip ahead

        if(viewerLoaded) {
            const {scene} = this.viewer;
-           const {icons, labels, polylines, onLeftClick} = this.props;
+           const {icons, labels, polylines, onLeftClick, flyToLocation} = this.props;

// Skip to rendering

+                   &amp;lt;CesiumCameraManager
+                       camera={scene.camera}
+                       flyToLocation={flyToLocation}
+                   /&amp;gt;
                &amp;lt;/span&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/blob/50af234084687896a045e2462a2d862dfdbc58b1/src/App.js&#34;&gt;src/App.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-diff&#34;&gt;class App extends Component {
    state = {
        reactLogo : {lat : 37.484505, lon : -122.147877, image : reactLogo},
        redsLogo : { lat : 39.097465, lon : -84.50703, image : redsLogo, scale : 0.3},
        label : {lat : 35.0, lon : -100.0, text : &amp;quot;Catch phrase here&amp;quot;},
        line : [
                {lat : 47.5, lon : -122.3, alt : 20000 },
                {lat : 36.2, lon : -115.0, alt : 20000 },
                {lat : 39.0, lon : -94.6, alt : 20000 },
                {lat : 30.4, lon : -81.6, alt : 20000 },
            ],
+        flyToLocation : null,
    }
    
+   handleFlyToClicked = () =&amp;gt; {
+       this.setState({
+           flyToLocation : {lat : 32.6925, lon : -117.1587, alt : 100000}
+       });
+   }

    render() {
-       const {reactLogo, redsLogo, label, line} = this.state;
+       const {reactLogo, redsLogo, label, line, flyToLocation} = this.state;

// Skip to rendering

            &amp;lt;div style={containerStyle}&amp;gt;
                &amp;lt;CesiumGlobe
                    icons={icons}
                    labels={labels}
                    polylines={polylines}
                    onLeftClick={this.handleLeftClick}
+                   flyToLocation={flyToLocation}
                /&amp;gt;
                &amp;lt;div style={{position : &amp;quot;fixed&amp;quot;, top : 0}}&amp;gt;
                    &amp;lt;div style={{color : &amp;quot;white&amp;quot;, fontSize: 40, }}&amp;gt;
                        Text Over the Globe
                    &amp;lt;/div&amp;gt;
+                   &amp;lt;button style={{fontSize : 40}} onClick={this.handleFlyToClicked}&amp;gt;
+                       Jump Camera Location
+                   &amp;lt;/button&amp;gt;
                &amp;lt;/div&amp;gt;
            &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And if we click the &amp;quot;Jump Camera Location&amp;quot; button, we should see the camera jump to show us an aerial overview of San Diego:&lt;/p&gt;


&lt;figure &gt;
    &lt;a href=&#34;https://blog.isquaredsoftware.com/images/2017-03-cesium-react-webpack/camera-san-diego.jpg&#34;&gt;
        &lt;img src=&#34;https://blog.isquaredsoftware.com/images/2017-03-cesium-react-webpack/camera-san-diego.jpg&#34; /&gt;
    &lt;/a&gt;
    
&lt;/figure&gt;


&lt;h3 id=&#34;wrapping-up-cesium-interaction&#34;&gt;Wrapping Up Cesium Interaction&lt;/h3&gt;

&lt;p&gt;These examples should give you a solid foundation for using Cesium with React.  You should be able to take the basic principles and approaches you&#39;ve seen, and adapt or expand them as needed in your own application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;One thing I didn&#39;t demonstrate in this post is testing React components that rely on Cesium&lt;/strong&gt;.  This is another area where Cesium&#39;s architecture presents some difficulties.  Because Cesium&#39;s source files are written as AMD modules, you can&#39;t just import them directly when running under Node.js.  They need to be converted or loaded in some fashion.&lt;/p&gt;

&lt;p&gt;In my &amp;quot;real&amp;quot; app at work, I&#39;m using the &lt;strong&gt;&lt;a href=&#34;https://github.com/zinserjan/mocha-webpack&#34;&gt;mocha-webpack&lt;/a&gt;&lt;/strong&gt; tool to run my tests.  Because it runs all source files through a full Webpack+Babel compilation process before executing tests, I can successfully run tests that reference Cesium.  Here&#39;s one example of what such a test might look like:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;describe(&amp;quot;CesiumPolyline&amp;quot;, () =&amp;gt; {
    it(&amp;quot;Updates values on property change&amp;quot;, () =&amp;gt; {
        const polylines = new PolylineCollection();
        const coords = [];

        const wrapper = mount(&amp;lt;CesiumPolyline polylines={polylines}  coords={coords} selected={false} loop={false} /&amp;gt;);
        const instance = wrapper.instance();

        const {polyline} = instance;
        const oldPositions = [...polyline.positions];
        const {loop : oldLoop} = polyline;
        const {color : oldColor} = polyline.material.uniforms;

        const newCoords = [{latitude : 35.0, longitude : -117.0, altitude : 150000}];
        wrapper.setProps({coords : newCoords, loop : true, selected : true});

        expect(oldPositions).to.not.deep.equal(polyline.positions);
        expect(oldLoop).to.not.equal(polyline.loop);
        expect(oldColor).to.not.equal(polyline.material.uniforms.color);
    });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I had hoped to show how to run the same kinds of test under Jest, but ran into problems getting Jest to load AMD modules.  After browsing some issues, it doesn&#39;t seem to be a supported scenario (per &lt;a href=&#34;https://github.com/facebook/jest/issues/17&#34;&gt;Jest issue #17&lt;/a&gt;).  That issue does reference a Babel plugin called &lt;a href=&#34;https://github.com/msrose/babel-plugin-transform-amd-to-commonjs&#34;&gt;&lt;code&gt;babel-plugin-transform-amd-to-commonjs&lt;/code&gt;&lt;/a&gt; that&#39;s supposed to help, but I was unable to get it to work in a short period of time.&lt;/p&gt;

&lt;p&gt;Another limitation is that Cesium&#39;s Scene class requires WebGL, which doesn&#39;t work under Node.  It&#39;s absolutely possible to test code where the Cesium classes &lt;em&gt;don&#39;t&lt;/em&gt; rely on WebGL, such as the polyline example above, but testing the &lt;code&gt;&amp;lt;CesiumGlobe&amp;gt;&lt;/code&gt; component would be difficult since it creates a &lt;code&gt;Viewer&lt;/code&gt; instance.  (There &lt;em&gt;was&lt;/em&gt; a recent Cesium PR that supposedly added &amp;quot;no-op stubs&amp;quot; for all of its WebGL behavior, which &lt;em&gt;might&lt;/em&gt; make something like this feasible, but I haven&#39;t looked into that further.)&lt;/p&gt;

&lt;p&gt;Overall, testing React components that use Cesium &lt;em&gt;is&lt;/em&gt; possible, it may just require some specific build+test configuration in order to make it work.&lt;/p&gt;

&lt;h2 id=&#34;final-thoughts&#34;&gt;Final Thoughts&lt;/h2&gt;

&lt;p&gt;The idea of wrapping imperative APIs into declarative components using lifecycle methods is a powerful concept.  It lets us encapsulate almost any external logic, and use it as just another component in our React application.  That includes jQuery plugins, canvas libraries, timers, and so much more.&lt;/p&gt;

&lt;p&gt;One other important thing to point out: &lt;strong&gt;anything we can control from React state is also something we can control from Redux&lt;/strong&gt;.  It&#39;s &lt;em&gt;absolutely&lt;/em&gt; possible to have data in a Redux store that drives a React-based HTML list of lat/lon points of interest, &lt;em&gt;and&lt;/em&gt; have those same points being displayed on the globe via Redux-driven React components.  (I can vouch for this, because this is &lt;em&gt;exactly&lt;/em&gt; what my own app does.)&lt;/p&gt;

&lt;p&gt;Hopefully, these examples serve as a great starting point for your own applications, whether you use Cesium, or just React!&lt;/p&gt;

&lt;h2 id=&#34;further-information&#34;&gt;Further Information&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Wrapping Imperative APIs with React Components&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;http://kyleshevlin.com/renderless-components/&#34;&gt;Renderless Components&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://medium.com/@superKalo/how-to-use-jquery-libraries-in-the-react-ecosystem-7dfeb1aafde0&#34;&gt;How to Use jQuery Libraries in the React Ecosystem&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;http://reactkungfu.com/2016/02/mapping-declarative-react-components-to-imperative-external-api/&#34;&gt;Mapping declarative React components to imperative APIs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.fullstackreact.com/articles/how-to-write-a-google-maps-react-component/&#34;&gt;How to Write a Google Maps React Component&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cesium Documentation&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;http://cesiumjs.org/&#34;&gt;Cesium.js Home Page&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;http://cesiumjs.org/tutorials.html&#34;&gt;Cesium Tutorials&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;http://cesiumjs.org/refdoc.html&#34;&gt;Cesium API Reference&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Hello%20World.html&amp;amp;label=Showcases&#34;&gt;Cesium Sandcastle Playground&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://groups.google.com/forum/#!forum/cesium-dev&#34;&gt;Cesium Google Discussion Group&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;</description>
    </item>
    
    <item>
      <title>Declaratively Rendering Earth in 3D, Part 1: Building a Cesium &#43; React App with Webpack</title>
      <link>https://blog.isquaredsoftware.com/2017/03/declarative-earth-part-1-cesium-webpack/</link>
      <pubDate>Tue, 07 Mar 2017 09:40:00 -0500</pubDate>
      
      <guid>https://blog.isquaredsoftware.com/2017/03/declarative-earth-part-1-cesium-webpack/</guid>
      <description>&lt;p&gt;&lt;/p&gt;

&lt;h2 id=&#34;intro&#34;&gt;Intro&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;http://cesiumjs.org/&#34;&gt;Cesium.js&lt;/a&gt;&lt;/strong&gt; is a powerful Javascript library for rendering a 3D globe.  It can display a wide variety of geospatial visualizations, including icons and text labels, vector geometries, 3D models, and much more, all on top of a fully-viewable 3D Earth with digital 3D terrain and imagery layers.&lt;/p&gt;

&lt;p&gt;Cesium is very similar to Google Earth in concept and capabilities.  However, Cesium has many advantages over the now-deprecated Google Earth browser plugin.  The Google Earth Plugin was a binary plugin that had to be installed on client systems, and while it had a Javascript API, the internal implementation was a black box of behavior.  Also, while GEP could be customized to work with a &amp;quot;Google Earth Enterprise&amp;quot; self-hosted globe data server, GEE licensing was &lt;em&gt;expensive&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;On the other hand, while Cesium is primarily developed by employees of AGI, it&#39;s a fully open-source Javascript library.  Cesium does not require a browser plugin, just the WebGL 3D rendering capability that is built into modern browsers.  Cesium also supports a wide variety of imagery and terrain data sources, and can work with both publicly hosted and self-hosted globe data servers.&lt;/p&gt;

&lt;p&gt;I&#39;ve used Cesium in several geospatial applications at work, and have become very familiar with its capabilities.  In the process, I&#39;ve used it with multiple client frameworks, including GWT, Backbone, and now React.&lt;/p&gt;

&lt;p&gt;Cesium is a complex toolkit, and dates back to early 2012.  Because of that, its architecture has several intricacies that make it somewhat difficult to use in a modern React+Webpack application.  While there is existing documentation on how to use Cesium in a Webpack-based application, I haven&#39;t yet seen any discussion of how to use it with React.  In addition, I&#39;ve been able to leverage some of Webpack&#39;s advanced capabilities to improve the development and deployment process.&lt;/p&gt;

&lt;p&gt;In this two-part series, I&#39;ll show you how to :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Set up a basic React app that loads Cesium&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Configure Webpack for faster build times and deployment of an application that uses Cesium using DllPlugin for code splitting&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use React components to declaratively control rendering of Cesium primitives through Cesium&#39;s imperative APIs&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This series assumes some familiarity with Cesium, React, and Webpack, and isn&#39;t intended to teach the basics for them.&lt;/p&gt;

&lt;p&gt;The code for the sample project accompanying this series is on Github at &lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo&#34;&gt;github.com/markerikson/cesium-react-webpack-demo&lt;/a&gt;&lt;/strong&gt;.  The  commits I made for this post can be seen in &lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/pull/1&#34;&gt;PR #1: Configure Webpack&lt;/a&gt;&lt;/strong&gt; I&#39;ll be linking to many of the commits as I go through the post, as well as specific files in those commits.  I won&#39;t paste every changed file in here or show every single changed line, to save space, but rather try to show the most relevant changes for each commit as appropriate.&lt;/p&gt;

&lt;blockquote&gt;
&lt;h4 id=&#34;update-2020&#34;&gt;Update, 2020&lt;/h4&gt;

&lt;p&gt;While the techniques shown here are still usable, I&#39;ve since learned and would recommend newer approaches.  In particular, I recommend:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Using &lt;strong&gt;&lt;a href=&#34;https://github.com/gsoft-inc/craco&#34;&gt;https://github.com/gsoft-inc/craco&lt;/a&gt;&lt;/strong&gt; to override Webpack configs without ejecting&lt;/li&gt;
&lt;li&gt;Using &lt;strong&gt;&lt;a href=&#34;https://github.com/darwin-education/craco-cesium&#34;&gt;https://github.com/darwin-education/craco-cesium&lt;/a&gt;&lt;/strong&gt; to apply the necessary Webpack config changes to allow Cesium to load correctly.&lt;br /&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In addition, CRA&#39;s current vendor chunking works well enough that I no longer see a need to create a separate DLL bundle for the Cesium code.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&#34;table-of-contents&#34;&gt;&lt;strong&gt;Table of Contents&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#creating-a-basic-react-cesium-app&#34;&gt;Creating a Basic React+Cesium App&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#configuring-webpack-to-use-cesium&#34;&gt;Configuring Webpack to Use Cesium&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#loading-cesium-into-the-app&#34;&gt;Loading Cesium Into the App&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#optimizing-cesium-app-deployment&#34;&gt;Optimizing Cesium App Deployment&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#serving-cesium-assets-in-development&#34;&gt;Serving Cesium Assets in Development&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#building-a-cesium-bundle-using-dllplugin&#34;&gt;Building a Cesium Bundle using DllPlugin&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#using-a-dll-bundle-in-the-application&#34;&gt;Using a DLL Bundle in the Application&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#including-cesium-in-production&#34;&gt;Including Cesium In Production&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#wrapping-up-webpack-optimization&#34;&gt;Wrapping Up Webpack Optimization&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#final-thoughts&#34;&gt;Final Thoughts&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#further-information&#34;&gt;Further Information&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&#34;creating-a-basic-react-cesium-app&#34;&gt;Creating a Basic React+Cesium App&lt;/h2&gt;

&lt;h3 id=&#34;initial-setup&#34;&gt;Initial Setup&lt;/h3&gt;

&lt;p&gt;We&#39;re going to start by using the excellent &lt;strong&gt;&lt;a href=&#34;https://github.com/facebookincubator/create-react-app&#34;&gt;Create-React-App&lt;/a&gt;&lt;/strong&gt; tool to create our new project.  To keep things simple, we&#39;ll skip the details of the initial setup steps, but here&#39;s a summary:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;create-react-app&lt;/code&gt; to create the project and commit it to Git&lt;/li&gt;
&lt;li&gt;Use Yarn to set up a lockfile for the project&#39;s dependencies&lt;/li&gt;
&lt;li&gt;Clean out the existing &lt;code&gt;&amp;lt;App&amp;gt;&lt;/code&gt; component so it only renders the text &amp;quot;Empty&amp;quot;&lt;/li&gt;
&lt;li&gt;Use Yarn to add Cesium as a dependency to the project&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At the time of writing, the current versions are CRA 0.9.2 and Cesium 1.31.&lt;/p&gt;

&lt;h3 id=&#34;configuring-webpack-to-use-cesium&#34;&gt;Configuring Webpack to Use Cesium&lt;/h3&gt;

&lt;p&gt;As mentioned, Cesium has many complexities in its architecture that make it difficult to use with Webpack out of the box.  This includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cesium is currently written using the AMD module format for its source files&lt;/li&gt;
&lt;li&gt;It includes some pre-bundled AMD-based third-party libraries&lt;/li&gt;
&lt;li&gt;Cesium makes heavy use of web workers&lt;/li&gt;
&lt;li&gt;Some of the code uses multi-line strings&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The primary documentation on using Cesium with Webpack comes from the article &lt;a href=&#34;https://cesiumjs.org/2016/01/26/Cesium-and-Webpack/&#34;&gt;Cesium and Webpack&lt;/a&gt; on Cesium&#39;s blog, and the sample repo &lt;a href=&#34;https://github.com/mmacaula/cesium-webpack&#34;&gt;mmacaula/cesium-webpack&lt;/a&gt;, both written by &lt;a href=&#34;https://twitter.com/mmacaula&#34;&gt;Mike Macaulay&lt;/a&gt;.  In his tutorial, he discusses two ways to use Cesium: using the pre-built Cesium bundle, and using Cesium&#39;s source directly.  &lt;strong&gt;We&#39;re going to use the &amp;quot;source&amp;quot; approach to start with.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As the blog post points out, &lt;strong&gt;we need to set two specific Webpack config options for this to work right&lt;/strong&gt;.  We need to set &lt;code&gt;sourcePrefix: &#39;&#39;&lt;/code&gt; to fix Webpack indenting multi-line strings improperly, and also set &lt;code&gt;unknownContextCritical: false&lt;/code&gt; to stop Webpack from printing warnings about certain libraries being loaded.&lt;/p&gt;

&lt;p&gt;Unfortunately, since we&#39;re using Creact-React-App, we don&#39;t have direct access to the Webpack config files, since CRA hides them from us by default.  So, we&#39;re going to have to use CRA&#39;s &amp;quot;escape hatch&amp;quot;: the &lt;code&gt;npm run eject&lt;/code&gt; command.  &lt;strong&gt;This will copy &lt;em&gt;all&lt;/em&gt; of CRA&#39;s config files into our own project&lt;/strong&gt;, and update &lt;code&gt;project.json&lt;/code&gt; to include all the individual tool dependencies instead of the single &lt;code&gt;react-scripts&lt;/code&gt; dependency.  After we eject, everything will still run exactly the same, but we can no longer simply upgrade the &lt;code&gt;react-scripts&lt;/code&gt; dependency to get the latest build system updates - we now &amp;quot;own&amp;quot; all the build config ourselves.&lt;/p&gt;

&lt;p&gt;After ejecting and committing the newly visible config files, we can make the necessary config tweaks.&lt;/p&gt;

&lt;p&gt;First, per the instructions in the &amp;quot;Cesium and Webpack&amp;quot; tutorial, we need to &lt;strong&gt;copy Cesium&#39;s pre-built worker files and assets to our public folder&lt;/strong&gt;.  This is a manual step, and doesn&#39;t involve any commits.  Browse into &lt;code&gt;$PROJECT/node_modules/cesium/Build/&lt;/code&gt;.  You should see two folders, &lt;code&gt;Cesium&lt;/code&gt; and &lt;code&gt;CesiumUnminified&lt;/code&gt;.  Copy the entire &lt;code&gt;Cesium&lt;/code&gt; folder over to &lt;code&gt;PROJECT/public/&lt;/code&gt;, and rename it to &lt;code&gt;cesium&lt;/code&gt;.  Then, delete the &lt;code&gt;Cesium.js&lt;/code&gt; file that&#39;s just inside.  You should now have the following folder structure:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;- $PROJECT
  - public
    - cesium
      - Assets
      - ThirdParty
      - Widgets
      - Workers
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Since we don&#39;t want to actually commit these files, it&#39;s a good idea to add a line to the project&#39;s &lt;code&gt;.gitignore&lt;/code&gt; file to ignore these:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/commit/c47204c8f14b4d4aa80ce482c14ee5ed6b090b53&#34;&gt;Commit c47204c: Ignore the public/cesium folder containing the copied Cesium output&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/blob/c47204c8f14b4d4aa80ce482c14ee5ed6b090b53/.gitignore&#34;&gt;.gitignore&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-diff&#34;&gt;# production
/build
+/public/cesium/
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Then, we&#39;ll add the needed config tweaks to the Webpack config files:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/commit/2015273517f4e38f0fb55a1d607f17110a59d95c&#34;&gt;Commit 2015273: Add Webpack config options needed to run Cesium&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/blob/2015273517f4e38f0fb55a1d607f17110a59d95c/config/webpack.config.dev.js&#34;&gt;config/webpack.config.dev.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-diff&#34;&gt;    publicPath: publicPath,
+   sourcePrefix : &#39;&#39;,

// Skip ahead

  module: {
+   unknownContextCritical : false,
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This should be done for &lt;strong&gt;both the development and production configs&lt;/strong&gt;.&lt;/p&gt;

&lt;h3 id=&#34;loading-cesium-into-the-app&#34;&gt;Loading Cesium Into the App&lt;/h3&gt;

&lt;p&gt;Before we can actually load the Cesium Viewer widget into our application, we have to configure Cesium so it knows how to construct the URLs for all of its assets.  That requires a call to the &lt;code&gt;buildModuleUrl()&lt;/code&gt; function that Cesium provides.  Once that&#39;s done, we can load the Viewer instance and have things work correctly.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/commit/17479d39c8b01aa6d3959e59cfccdb3571b88769&#34;&gt;Commit 17479d3: Add initial Cesium viewer to the app&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/blob/17479d39c8b01aa6d3959e59cfccdb3571b88769/src/index.js&#34;&gt;src/index.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-diff&#34;&gt;import App from &#39;./App&#39;;
import &#39;./index.css&#39;;

+import &amp;quot;cesium/Source/Widgets/widgets.css&amp;quot;;
+
+import buildModuleUrl from &amp;quot;cesium/Source/Core/buildModuleUrl&amp;quot;;
+buildModuleUrl.setBaseUrl(&#39;./cesium/&#39;);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Note that we set the base URL to &lt;code&gt;&amp;quot;./cesium/&amp;quot;&lt;/code&gt;, which corresponds to the pre-built Cesium folder we copied earlier into &lt;code&gt;$PROJECT/public&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;From there, all we have to do is use the standard React approach for interacting with code that needs to access a DOM element directly.  We render a div that will serve as the container for our Cesium widget, and &lt;strong&gt;use a &amp;quot;callback ref&amp;quot; to save a reference to the real DOM element&lt;/strong&gt;.  Then, in &lt;code&gt;componentDidMount&lt;/code&gt;, we create the Cesium.Viewer instance, and give it the div reference to serve as its parent:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/blob/17479d39c8b01aa6d3959e59cfccdb3571b88769/src/App.js&#34;&gt;src/App.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;import React, { Component } from &#39;react&#39;;

import Viewer from &amp;quot;cesium/Source/Widgets/Viewer/Viewer&amp;quot;;

class App extends Component {
    componentDidMount() {
        this.viewer = new Viewer(this.cesiumContainer);
    }

    render() {
        return (
            &amp;lt;div&amp;gt;
                &amp;lt;div id=&amp;quot;cesiumContainer&amp;quot; ref={ element =&amp;gt; this.cesiumContainer = element }/&amp;gt;
            &amp;lt;/div&amp;gt;
        );
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Notice that we&#39;re importing pieces from inside Cesium&#39;s folder structure, rather than just &lt;code&gt;import Cesium from &amp;quot;cesium&amp;quot;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If we run the project, here&#39;s what we should see:&lt;/p&gt;


&lt;figure &gt;
    &lt;a href=&#34;https://blog.isquaredsoftware.com/images/2017-03-cesium-react-webpack/initial-cesium-viewer.jpg&#34;&gt;
        &lt;img src=&#34;https://blog.isquaredsoftware.com/images/2017-03-cesium-react-webpack/initial-cesium-viewer.jpg&#34; /&gt;
    &lt;/a&gt;
    
&lt;/figure&gt;


&lt;p&gt;Success!  &lt;strong&gt;We&#39;ve loaded Cesium, and are viewing a 3D globe with the Cesium Viewer in its default configuration&lt;/strong&gt;.  (If you squint carefully at the image, you&#39;ll see that the viewer doesn&#39;t actually fill the whole screen - there&#39;s a bunch of blank space below.  We&#39;ll fix that in the next part.)&lt;/p&gt;

&lt;p&gt;That wraps up the basic application setup.  Let&#39;s move on to setting up a proper production build.&lt;/p&gt;

&lt;h2 id=&#34;optimizing-cesium-app-deployment&#34;&gt;Optimizing Cesium App Deployment&lt;/h2&gt;

&lt;p&gt;Thus far, we&#39;ve been simply importing Cesium directly into our main application.  That&#39;s okay as a starting point, but it also means that our main application bundle is going to include pretty much &lt;em&gt;all&lt;/em&gt; of Cesium.  Unfortunately, Cesium is a &lt;em&gt;big&lt;/em&gt; toolkit.  Let&#39;s run a production build of the application:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;$ node scripts/build.js
Creating an optimized production build...
Compiled successfully.

File sizes after gzip:

  532.54 KB  build\static\js\main.304c45dc.js
  4.78 KB    build\static\css\main.c5310e60.css

Done in 48.13s.
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Hmm.  &amp;quot;532KB after gzip?&amp;quot;  That seems big.  Let&#39;s check out what goes into the bundle, using the &lt;a href=&#34;https://www.npmjs.com/package/source-map-explorer&#34;&gt;&lt;code&gt;source-map-explorer&lt;/code&gt;&lt;/a&gt; to view the contents of the minified bundle:&lt;/p&gt;


&lt;figure &gt;
    &lt;a href=&#34;https://blog.isquaredsoftware.com/images/2017-03-cesium-react-webpack/bundle-size-original.png&#34;&gt;
        &lt;img src=&#34;https://blog.isquaredsoftware.com/images/2017-03-cesium-react-webpack/bundle-size-original.png&#34; /&gt;
    &lt;/a&gt;
    
&lt;/figure&gt;


&lt;p&gt;&lt;strong&gt;EEEP!&lt;/strong&gt;  Our &lt;em&gt;production&lt;/em&gt; app bundle is &lt;strong&gt;over 2MB&lt;/strong&gt;, and Cesium itself is taking up &lt;strong&gt;1.8MB of minified Javascript!!!&lt;/strong&gt;  That&#39;s... not good, to say the least.  Meanwhile, Cesium&#39;s various web workers and assets, while loaded separately, are also a significant chunk of space as well.  Yes, gzipping the bundle will take that down to about 532KB, but that&#39;s still way more than we&#39;d like to load at once.&lt;/p&gt;

&lt;p&gt;The bad news is that there&#39;s only so much we can do to solve this.  Cesium is simply a very large, very complex toolkit, and there&#39;s nothing we can do to fully shrink down the size of Cesium itself.  Any app using Cesium will never win awards for &amp;quot;Smallest Total Loading Size&amp;quot;.&lt;/p&gt;

&lt;p&gt;However, the &lt;em&gt;good&lt;/em&gt; news is that &lt;strong&gt;we can separate Cesium out from our application bundle&lt;/strong&gt;.  We &lt;em&gt;do&lt;/em&gt; still need to load it, and in fact we&#39;ll need to load it before the app bundle, but by separating it out &lt;strong&gt;we can at least make it cached for the next time the user loads the app&lt;/strong&gt;.  Also, by pre-building the Cesium bundle, &lt;strong&gt;we can cut down on production build time for our application&#39;s bundle&lt;/strong&gt;.&lt;/p&gt;

&lt;h3 id=&#34;serving-cesium-assets-in-development&#34;&gt;Serving Cesium Assets in Development&lt;/h3&gt;

&lt;p&gt;Before we get to building Cesium as a separate bundle, we can make an improvement to our development process.  All this time, we&#39;ve had a copy of Cesium&#39;s pre-built output folder sitting in our &lt;code&gt;$PROJECT/public/cesium/&lt;/code&gt; folder, because those files need to be loaded by Cesium at runtime from the server.  We can remove the need for that by modifying the CRA dev server setup so that it serves those files directly out of &lt;code&gt;node_modules/cesium/&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;First, we&#39;ll add a few more entries to CRA&#39;s list of pre-defined paths:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/commit/73bdbe2801347ed795b50e957c9ee915d2a98b71&#34;&gt;Commit 73bdbe2: Add additional paths for use in build config&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/blob/73bdbe2801347ed795b50e957c9ee915d2a98b71/config/paths.js&#34;&gt;config/paths.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-diff&#34;&gt;  ownNodeModules: resolveApp(&#39;node_modules&#39;),
+  app : resolveApp(&#39;.&#39;),
+  appConfig : resolveApp(&#39;config&#39;),
+  cesiumDebugBuild : resolveApp(&#39;node_modules/cesium/Build/CesiumUnminified/&#39;),
+  cesiumProdBuild : resolveApp(&#39;node_modules/cesium/Build/Cesium/&#39;),
+  cesiumSourceFolder : resolveApp(&#39;node_modules/cesium/Source/&#39;),
  nodePaths: nodePaths,
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Then, we&#39;ll make a small edit to CRA&#39;s dev server setup to tell it to serve static files directly out of the right folder:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/commit/eabdcf59766ad0cf7940398a394190515ae4a471&#34;&gt;Commit eabdcf5: Modify CRA dev server to serve Cesium files from node_modules&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/blob/eabdcf59766ad0cf7940398a394190515ae4a471/scripts/start.js&#34;&gt;scripts/start.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-diff&#34;&gt;var openBrowser = require(&#39;react-dev-utils/openBrowser&#39;);
var prompt = require(&#39;react-dev-utils/prompt&#39;);
+var express = require(&amp;quot;express&amp;quot;);

// Skip ahead

function addMiddleware(devServer) {

+  // Handle requests for Cesium static assets that we want to
+  // serve up direct from /node_modules/cesium/.
+  devServer.use(&amp;quot;/cesium&amp;quot;, express.static(paths.cesiumDebugBuild));
+
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;We should now be able to delete the &lt;code&gt;cesium/&lt;/code&gt; folder from &lt;code&gt;$PROJECT/public/&lt;/code&gt;, at least in terms of development.  CRA automatically copies everything inside of &lt;code&gt;/public/&lt;/code&gt; to the build output folder when it does a production build, so we&#39;ll need to add some custom logic to handle copying Cesium&#39;s assets for production builds.  We&#39;ll come back to that in a bit.&lt;/p&gt;

&lt;h3 id=&#34;building-a-cesium-bundle-using-dllplugin&#34;&gt;Building a Cesium Bundle using DllPlugin&lt;/h3&gt;

&lt;p&gt;Webpack has several ways to create bundles and chunks.  The most widely used methods are declaring bundle entry points in the &lt;code&gt;entry&lt;/code&gt; section of a Webpack config, and using the &lt;code&gt;CommonsChunkPlugin&lt;/code&gt; to extract files that are shared between multiple chunks into a separate bundle.&lt;/p&gt;

&lt;p&gt;There&#39;s another Webpack plugin that&#39;s less well known: &lt;code&gt;DllPlugin&lt;/code&gt;.  Named after the idea of a native code &amp;quot;Dynamic Link Library&amp;quot; from Windows (or &lt;code&gt;.so&lt;/code&gt; for you *nix users), the idea is that you pre-build a bundle containing the reusable or shared portions of your code, and also create a metadata file that describes what&#39;s inside the bundle.  Then, when you build your application itself, you add a reference to the metadata so that Webpack knows what code &lt;em&gt;should&lt;/em&gt; already be available.  Webpack will then skip including those pieces in your app bundle.&lt;/p&gt;

&lt;p&gt;Building a DLL bundle requires creating a new Webpack config that&#39;s separate from the application configs.  Here&#39;s what the config looks like:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/commit/4ddc26ab024a90d5f4684eeefa4486cde9378513&#34;&gt;Commit 4ddc26a: Add a Webpack config to pre-build a Cesium bundle&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/blob/4ddc26ab024a90d5f4684eeefa4486cde9378513/config/webpack.cesium.dll.config.js&#34;&gt;config/webpack.cesium.dll.config.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;&amp;quot;use strict&amp;quot;;

const path = require(&amp;quot;path&amp;quot;);
const webpack = require(&amp;quot;webpack&amp;quot;);

const paths = require(&amp;quot;./paths&amp;quot;);
const env = require(&amp;quot;./env&amp;quot;);

const outputPath = path.join(paths.app, &amp;quot;distdll&amp;quot;);

const webpackConfig = {
    entry : {
        cesiumDll : [&amp;quot;cesium/Source/Cesium.js&amp;quot;],
    },
    devtool : &amp;quot;#source-map&amp;quot;,
    output : {
        path : outputPath,
        filename : &amp;quot;[name].js&amp;quot;,
        library : &amp;quot;[name]_[hash]&amp;quot;,
        sourcePrefix: &amp;quot;&amp;quot;,
    },
    plugins : [
        new webpack.DllPlugin({
            path : path.join(outputPath, &amp;quot;[name]-manifest.json&amp;quot;),
            name : &amp;quot;[name]_[hash]&amp;quot;,
            context : paths.cesiumSourceFolder,
        }),

        new webpack.DefinePlugin({
            &#39;process.env.NODE_ENV&#39;: JSON.stringify(&amp;quot;production&amp;quot;)
        }),

        new webpack.optimize.UglifyJsPlugin({
            compress: {
                warnings: false
            }
        })

    ],
    module : {
        unknownContextCritical : false,
        loaders : [
            { test : /\.css$/, loader: &amp;quot;style!css&amp;quot; },
            {
                test : /\.(png|gif|jpg|jpeg)$/,
                loader : &amp;quot;file-loader&amp;quot;,
            },
        ],
    },
};
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Some key things to note here.  First, we&#39;re building this in production mode by setting &lt;code&gt;process.env.NODE_ENV=&amp;quot;production&amp;quot;&lt;/code&gt; and minifying it.  We&#39;ve also included the couple specific config settings we had to tweak earlier.&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;really&lt;/em&gt; important part is that we&#39;re including the &lt;code&gt;DllPlugin&lt;/code&gt; in the config.  The &lt;code&gt;path&lt;/code&gt; option tells Webpack where to write the metadata file, &lt;code&gt;name&lt;/code&gt; is the name of the bundle file itself, and I &lt;em&gt;think&lt;/em&gt; &lt;code&gt;context&lt;/code&gt; has to do with how the imported source files are looked up.  Roughly.  :)&lt;/p&gt;

&lt;p&gt;Now that we have the config file, we need to actually run Webpack with this config to generate our Cesium DLL bundle.  I&#39;ve written a couple new script files to control this process.  One encapsulates the work of running Webpack with a certain config and printing out some readable stats, and the other just calls the Webpack compiler script with the Cesium DLL config.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/commit/b55dbd56c7093a28c54c4294442f67179e895839&#34;&gt;Commit b55dbd5: Add scripts to build a Cesium bundle with DllPlugin&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We&#39;ll skip looking at the script contents, but here&#39;s the output of running the DLL build script:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;$ node ./scripts/buildCesiumDLL.js
Compiling: cesium
  build [====================] 100% (35.5 seconds) ()

Build completed in 35.47s

Hash: 0829da3ac0fb7ef638b5
Version: webpack 1.14.0
Time: 35472ms
           Asset     Size  Chunks             Chunk Names
    cesiumDll.js  2.13 MB       0  [emitted]  cesiumDll
cesiumDll.js.map    19 MB       0  [emitted]  cesiumDll
Done in 37.33s.
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If we look in &lt;code&gt;$PROJECT/distdll&lt;/code&gt;, we should see three files: &lt;code&gt;cesiumDll.js&lt;/code&gt;, &lt;code&gt;cesiumDll.js.map&lt;/code&gt;, and &lt;code&gt;cesiumDll-manifest.json&lt;/code&gt;. Cesium is still a really hefty chunk of code, but at least now it&#39;s a separate file.&lt;/p&gt;

&lt;h3 id=&#34;using-a-dll-bundle-in-the-application&#34;&gt;Using a DLL Bundle in the Application&lt;/h3&gt;

&lt;p&gt;Happily, the hard part is done.  Now that we have the DLL bundle generated, we can point our production Webpack config at the manifest file:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/commit/6db616f533c9c8a96bc09fbf859a679220b0d548&#34;&gt;Commit 6db616f: Update Webpack prod config to use the Cesium DLL bundle&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/blob/6db616f533c9c8a96bc09fbf859a679220b0d548/config/webpack.config.prod.js&#34;&gt;config/webpack/config.prod.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-diff&#34;&gt;+var path = require(&#39;path&#39;);
var autoprefixer = require(&#39;autoprefixer&#39;);

// Skip ahead

  plugins: [
+     new webpack.DllReferencePlugin({
+       context : paths.cesiumSourceFolder,
+         manifest: require(path.join(paths.app, &amp;quot;distdll/cesiumDLL-manifest.json&amp;quot;)),
+     }),
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;We just add &lt;code&gt;DllReferencePlugin&lt;/code&gt; to the production config, set the &lt;code&gt;manifest&lt;/code&gt; option to point to the manifest file that was generated earlier, and use the same &lt;code&gt;context&lt;/code&gt; option we used when we generated the DLL (to make sure that source file references match before and after).&lt;/p&gt;

&lt;p&gt;Let&#39;s re-run a production build of the app and see how things look:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;$ node scripts/build.js
Creating an optimized production build...
Compiled successfully.

File sizes after gzip:

  46.09 KB  build\static\js\main.f984614f.js
  4.78 KB   build\static\css\main.c5310e60.css

Done in 10.43s.
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That looks &lt;strong&gt;much better!&lt;/strong&gt;  The compile time dropped from 48 seconds to about 10 seconds, and the main bundle is down to 46KB gzipped.  Let&#39;s take another look at the contents of the bundle using &lt;code&gt;source-map-explorer&lt;/code&gt;:&lt;/p&gt;


&lt;figure &gt;
    &lt;a href=&#34;https://blog.isquaredsoftware.com/images/2017-03-cesium-react-webpack/bundle-size-dll.png&#34;&gt;
        &lt;img src=&#34;https://blog.isquaredsoftware.com/images/2017-03-cesium-react-webpack/bundle-size-dll.png&#34; /&gt;
    &lt;/a&gt;
    
&lt;/figure&gt;


&lt;p&gt;The overall application bundle is now down to &lt;strong&gt;150KB&lt;/strong&gt;.  We&#39;re now looking at just the application code plus the non-Cesium libraries.  There&#39;s more we &lt;em&gt;could&lt;/em&gt; do to optimize, but this is sufficient for the concepts I wanted to show off.&lt;/p&gt;

&lt;h3 id=&#34;including-cesium-in-production&#34;&gt;Including Cesium in Production&lt;/h3&gt;

&lt;p&gt;We now need to actually include Cesium into the production build output.  Since we deleted the hand-copied &lt;code&gt;public/cesium&lt;/code&gt; folder, Cesium&#39;s assets aren&#39;t being copied to &lt;code&gt;/build/&lt;/code&gt; any more.  We can add some logic to CRA&#39;s existing build script to do that.  It&#39;ll just do some glob searching to collect a list of files under &lt;code&gt;node_modules/cesium/Build/Cesium/&lt;/code&gt;, and copy each one to the output folder, along with the Cesium DLL bundle we&#39;ve created.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/commit/902ba044c3fbdbac34cb6e2b9204c8df728240a8&#34;&gt;Commit 902ba04: Update build script to copy Cesium files to the output folder&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The last step is to actually include the Cesium DLL bundle into our page.  CRA uses the &lt;a href=&#34;https://webpack.js.org/plugins/html-webpack-plugin/&#34;&gt;HtmlWebpackPlugin&lt;/a&gt; to insert the right script tags into the &lt;code&gt;index.html&lt;/code&gt; template during the build process.  We can customize the template so that it only includes the DLL bundle during a production build.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/commit/c65e7bd3aad11d7118f335d4896a613a3b9f61bd&#34;&gt;Commit c65e7bd: Conditionally include Cesium bundle in the HTML host page&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/blob/c65e7bd3aad11d7118f335d4896a613a3b9f61bd/config/webpack.config.prod.js&#34;&gt;config/webpack.config.prod.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-diff&#34;&gt;    new HtmlWebpackPlugin({
      inject: true,
      template: paths.appHtml,
+     production : true,
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;HtmlWebpackPlugin takes a number of specific options, but you can also add any other options you want, and it will pass them through.  So, since we know we&#39;re doing a prod build when this config is being used, we just add a &lt;code&gt;production : true&lt;/code&gt; option that we can use in the template.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/cesium-react-webpack-demo/blob/c65e7bd3aad11d7118f335d4896a613a3b9f61bd/public/index.html&#34;&gt;public/index.html&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-diff&#34;&gt;  &amp;lt;body&amp;gt;
    &amp;lt;div id=&amp;quot;root&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;
+   &amp;lt;% if(htmlWebpackPlugin.options.production) { %&amp;gt;
+       &amp;lt;script src=&amp;quot;cesium/cesiumDll.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;
+   &amp;lt;% } %&amp;gt;
    &amp;lt;!--
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;HtmlWebpackPlugin uses Lodash templating, so we can insert a simple check for the &lt;code&gt;production&lt;/code&gt; option we added, and only include the Cesium DLL script tag if it&#39;s a prod build.&lt;/p&gt;

&lt;p&gt;Note that &lt;strong&gt;the Cesium DLL bundle &lt;em&gt;must&lt;/em&gt; be loaded before the main application bundle!&lt;/strong&gt;  This is because the DLL bundle exposes its contents as a global variable (such as &lt;code&gt;var cesiumDll_0829da3ac0fb7ef638b5&lt;/code&gt; ), and the &lt;code&gt;DllReferencePlugin&lt;/code&gt; adds logic to look for that specific variable.&lt;/p&gt;

&lt;p&gt;With that, we should be able to run an HTTP static file server from our &lt;code&gt;build&lt;/code&gt; folder, and see the application successfully load!&lt;/p&gt;

&lt;h3 id=&#34;wrapping-up-webpack-optimization&#34;&gt;Wrapping Up Webpack Optimization&lt;/h3&gt;

&lt;p&gt;While I was working on this post, I had intended to demonstrate lazy-loading the DLL bundle using Webpack&#39;s code-splitting abilities.  Unfortunately, I realized that what I&#39;m doing in my own app right now doesn&#39;t actually qualify as lazy-loading.  I&#39;ve got some code-splitting in place, but as we just saw, &lt;strong&gt;bundles produced by DllPlugin still have to be loaded manually&lt;/strong&gt;.  Since a DLL bundle is &lt;em&gt;usually&lt;/em&gt; vendor libs, it&#39;s reasonable to have a specific script tag that loads the DLL bundle first.&lt;/p&gt;

&lt;p&gt;There&#39;s a couple threads in the Webpack issues tracker that discuss ways to actually load DLL bundles at runtime, so that they truly are lazy-loaded.  The consensus seems to be that it&#39;s possible, but it requires use of some non-Webpack loading code to make it work. See Webpack issues &lt;a href=&#34;https://github.com/webpack/webpack/issues/2592&#34;&gt;#2592&lt;/a&gt; and &lt;a href=&#34;https://github.com/webpack/webpack/issues/3115&#34;&gt;#3115&lt;/a&gt; for discussion on the topic.&lt;/p&gt;

&lt;p&gt;It&#39;s also important to note that &lt;strong&gt;DllPlugin doesn&#39;t actually reduce the amount of code that has to be loaded, but it &lt;em&gt;does&lt;/em&gt; split things into more cacheable pieces&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&#34;final-thoughts&#34;&gt;Final Thoughts&lt;/h2&gt;

&lt;p&gt;Cesium is a complex and powerful library, and Webpack is a complex and powerful build tool.  Getting them to play nicely together takes a bit of work, but is well worth the effort.&lt;/p&gt;

&lt;p&gt;Next up in Part 2, &lt;strong&gt;&lt;a href=&#34;https://blog.isquaredsoftware.com/2017/03/declarative-earth-part-2-cesium-react/&#34;&gt;we&#39;ll look at how to use React components to control Cesium&#39;s API&lt;/a&gt;&lt;/strong&gt;.  Be sure to check it out!&lt;/p&gt;

&lt;h2 id=&#34;further-information&#34;&gt;Further Information&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Cesium and Webpack&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://cesiumjs.org/2016/01/26/Cesium-and-Webpack/&#34;&gt;Cesium Blog: Cesium and Webpack&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/mmacaula/cesium-webpack&#34;&gt;Repo: Cesium and Webpack tutorial and examples&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/PropellerAero/cesium-webpack&#34;&gt;Repo: Cesium-Webpack project template&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://groups.google.com/forum/#!topic/cesium-dev/fH3oiHZnHgE/discussion&#34;&gt;Cesium group: &amp;quot;Incompatible with Webpack&amp;quot;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://groups.google.com/forum/#!topic/cesium-dev/BtasqaYbS0I&#34;&gt;Cesium group: &amp;quot;Cesium usage with Webpack?&amp;quot;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/AnalyticalGraphicsInc/cesium/issues/2981&#34;&gt;Cesium #2981: Making Cesium Webpack and Browserify friendly&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/AnalyticalGraphicsInc/cesium/issues/4876&#34;&gt;Cesium #4876: Fix remaining issues that require special Webpack config settings?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Webpack Optimization with DllPlugin&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://medium.com/@soederpop/webpack-plugins-been-we-been-keepin-on-the-dll-cdfdd6cb8cd7&#34;&gt;Webpack Plugins we been keeping on the DLL&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/erikras/react-redux-universal-hot-example/issues/616#issuecomment-228956242&#34;&gt;RRUHE #616: DllPlugin usage summary&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/mxstbr/react-boilerplate/pull/495&#34;&gt;React-Boilerplate #495: Implement DllPlugin&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;http://engineering.invisionapp.com/post/optimizing-webpack/&#34;&gt;Optimizing Webpack for Faster React Builds&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://robertknight.github.io/posts/webpack-dll-plugins/&#34;&gt;Optimizing Webpack build times and improving caching with DLL bundles&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;http://odetocode.com/blogs/scott/archive/2016/12/01/building-vendor-and-feature-bundles-with-webpack.aspx&#34;&gt;Building Vendor and Feature Bundles with Webpack&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/webpack/webpack/issues/2592&#34;&gt;Webpack #2592: Proposal - Dll-like plugin for an external context&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/webpack/webpack/issues/3115&#34;&gt;Webpack #3115: How to lazy load a DLL bundle?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/FormidableLabs/formidable-playbook/blob/master/docs/frontend/webpack-shared-libs.md&#34;&gt;Formidable Playbook: Webpack Shared Libs&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;</description>
    </item>
    
    <item>
      <title>Practical Redux, Part 5: Loading and Displaying Data</title>
      <link>https://blog.isquaredsoftware.com/2016/12/practical-redux-part-5-loading-and-displaying-data/</link>
      <pubDate>Mon, 12 Dec 2016 23:00:00 -0500</pubDate>
      
      <guid>https://blog.isquaredsoftware.com/2016/12/practical-redux-part-5-loading-and-displaying-data/</guid>
      <description>&lt;p&gt;&lt;/p&gt;

&lt;h2 id=&#34;intro&#34;&gt;Intro&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://blog.isquaredsoftware.com/2016/11/practical-redux-part-4-ui-layout-and-project-structure/&#34;&gt;Last time&lt;/a&gt;&lt;/strong&gt;, we built up a hardcoded initial UI layout for &lt;strong&gt;&lt;em&gt;Project Mini-Mek&lt;/em&gt;&lt;/strong&gt; using Semantic-UI-React, added a tab bar component controlled by Redux, and started using a &amp;quot;feature-first&amp;quot;-style folder structure for our code.  This time, &lt;strong&gt;we&#39;ll improve debugging support with sourcemaps, define data models with Redux-ORM, use those models to load data into the store and display it, and add the ability to track which items are selected&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The code for this project is on Github at &lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek&#34;&gt;github.com/markerikson/project-minimek&lt;/a&gt;&lt;/strong&gt;.  The original WIP commits I made for this post can be seen in &lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/pull/3&#34;&gt;PR #3: Practical Redux Part 5 WIP&lt;/a&gt;&lt;/strong&gt;, and the final &amp;quot;clean&amp;quot; commits can be seen in in &lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/pull/4&#34;&gt;PR #4: Practical Redux Part 5 Final&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I&#39;ll be linking to each &amp;quot;final&amp;quot; commit as I go through the post, as well as specific files in those commits.  I won&#39;t paste every changed file in here, to save space, but rather try to show the most relevant changes for each commit as appropriate.&lt;/p&gt;

&lt;h3 id=&#34;table-of-contents&#34;&gt;&lt;strong&gt;Table of Contents&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#adding-sourcemap-support-for-better-debugging&#34;&gt;Adding Sourcemap Support for Better Debugging&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#making-file-structure-consistent&#34;&gt;Making File Structure Consistent&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#extracting-components-in-features&#34;&gt;Extracting Components in Features&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#adding-a-mock-api-for-sample-data&#34;&gt;Adding a Mock API for Sample Data&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#connecting-the-unit-info-tab&#34;&gt;Connecting the Unit Info Tab&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#adding-a-redux-orm-schema-and-model&#34;&gt;Adding a Redux-ORM Schema and Model&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#loading-pilot-data-with-redux-orm&#34;&gt;Loading Pilot Data with Redux-ORM&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#displaying-a-list-of-pilots&#34;&gt;Displaying a List of Pilots&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#defining-models-with-relations&#34;&gt;Defining Models with Relations&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#displaying-a-list-of-mechs&#34;&gt;Displaying a List of Mechs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#handling-selection-logic&#34;&gt;Handling Selection Logic&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#final-thoughts&#34;&gt;Final Thoughts&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#further-information&#34;&gt;Further Information&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&#34;adding-sourcemap-support-for-better-debugging&#34;&gt;Adding Sourcemap Support for Better Debugging&lt;/h2&gt;

&lt;p&gt;Before we can start working on the code for this set of improvements, we need to make some library updates that will help improve our development experience, by fixing up a weakness with the debugging process.&lt;/p&gt;

&lt;p&gt;Tools like Webpack and Babel compile our input source code, transform it in various ways, and output a bundle containing all the transformed code in one file.  This is great for production use, since users will load a site faster thanks to smaller files and fewer requests.  However, trying to debug code that&#39;s been compiled, minified, and bundled is just about impossible.  &lt;strong&gt;Fortunately, this can be solved with &lt;a href=&#34;http://blog.teamtreehouse.com/introduction-source-maps&#34;&gt;sourcemaps&lt;/a&gt;, which contain information the debugger can use to show the original code instead of the transformed code.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Webpack has many different options for creating sourcemaps, with &lt;a href=&#34;https://lorefnon.me/2016/12/03/on-webpack-and-source-map-integration.html&#34;&gt;varying tradeoffs for speed, details, and contents&lt;/a&gt;.  Up through &lt;a href=&#34;https://github.com/facebookincubator/create-react-app/releases/tag/v0.7.0&#34;&gt;Create-React-App 0.7.0&lt;/a&gt;, CRA configured Webpack to use the &lt;code&gt;eval&lt;/code&gt; sourcemaps option.  That option shows you individual files in the debugger, but shows the code &lt;em&gt;after&lt;/em&gt; it&#39;s been compiled by Babel.  Looking at that in the debugger is better than trying to read minified/bundled code, but it&#39;s not exactly the prettiest, as seen in this screenshot:&lt;/p&gt;


&lt;figure &gt;
    &lt;a href=&#34;https://blog.isquaredsoftware.com/images/2016-12-practical-redux-part-5/devtools-sourcemaps-eval.png&#34;&gt;
        &lt;img src=&#34;https://blog.isquaredsoftware.com/images/2016-12-practical-redux-part-5/devtools-sourcemaps-eval.png&#34; /&gt;
    &lt;/a&gt;
    
&lt;/figure&gt;


&lt;p&gt;The &lt;code&gt;devtool: &amp;quot;eval&amp;quot;&lt;/code&gt; option was chosen because sourcemap support in both browsers and tools hasn&#39;t always worked right, and this option was known to at least produce usable results.&lt;/p&gt;

&lt;p&gt;After a lot of discussion, in &lt;a href=&#34;https://github.com/facebookincubator/create-react-app/releases/tag/v0.8.0&#34;&gt;Create-React-App 0.8.0&lt;/a&gt;, the sourcemaps option was switched to one that should actually show the original code.  &lt;a href=&#34;https://twitter.com/acemarke/status/805216294140317696&#34;&gt;I was extremely excited about this&lt;/a&gt;, but soon ran into a problem - while I could see the code as expected, &lt;a href=&#34;https://twitter.com/acemarke/status/806353019902316545&#34;&gt;I couldn&#39;t set any breakpoints&lt;/a&gt;.  Fortunately, after some further investigation by the CRA and Webpack teams, fixes were made, and &lt;a href=&#34;https://github.com/facebookincubator/create-react-app/releases/tag/v0.8.2&#34;&gt;Create-React-App 0.8.2&lt;/a&gt; was released with &lt;strong&gt;working sourcemap+breakpoints support.&lt;/strong&gt;  &lt;strong&gt;&lt;a href=&#34;https://twitter.com/acemarke/status/806652942866649090&#34;&gt;This made me &lt;em&gt;very&lt;/em&gt; happy :)&lt;/a&gt;&lt;/strong&gt;.  A couple other bug fix releases were put out while I was working on this post, so at the time of writing the latest version is  &lt;strong&gt;&lt;a href=&#34;https://github.com/facebookincubator/create-react-app/releases/tag/v0.8.4&#34;&gt;Create-React-App 0.8.4&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Technically, &lt;code&gt;create-react-app&lt;/code&gt; is just the CLI tool that&#39;s used to create a new project.  The real magic happens in the &lt;code&gt;react-scripts&lt;/code&gt; package, which includes all the build tool configuration.  So, after running &lt;code&gt;yarn add --dev react-scripts@0.8.4&lt;/code&gt; and restarting the development server, the same debugger view should now look like this:&lt;/p&gt;


&lt;figure &gt;
    &lt;a href=&#34;https://blog.isquaredsoftware.com/images/2016-12-practical-redux-part-5/devtools-sourcemaps-module.png&#34;&gt;
        &lt;img src=&#34;https://blog.isquaredsoftware.com/images/2016-12-practical-redux-part-5/devtools-sourcemaps-module.png&#34; /&gt;
    &lt;/a&gt;
    
&lt;/figure&gt;


&lt;p&gt;Notice that we now see the original source code (even the JSX), the DevTools debugger will let us set breakpoints on most of the lines in the file, and we&#39;ve even added a breakpoint and stopped there during a re-render.  &lt;strong&gt;This will make the development experience &lt;em&gt;much&lt;/em&gt; easier as we go along!&lt;/strong&gt;  Definitely time to save that change.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/commit/01c62c6cc60e9889207ceb272e4148bb6b8ca56b&#34;&gt;Commit 01c62c6: Upgrade react-scripts to 0.8.4&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;With that upgrade in place, we can now turn our attention back to the code.  We&#39;ll start by completing the file reorganization we worked on last time.&lt;/p&gt;

&lt;h2 id=&#34;making-file-structure-consistent&#34;&gt;Making File Structure Consistent&lt;/h2&gt;

&lt;p&gt;As described in &lt;a href=&#34;https://blog.isquaredsoftware.com/2016/11/practical-redux-part-4-ui-layout-and-project-structure/&#34;&gt;Part 4&lt;/a&gt;, we&#39;re using a &amp;quot;feature-first&amp;quot; folder structure.  However, not all the code qualifies as a &amp;quot;feature&amp;quot;.  There&#39;s really three main divisions:  common code that&#39;s generic and reused throughout the application, code that&#39;s specific to a feature, and the application-level code that ties those features together.&lt;/p&gt;

&lt;p&gt;We&#39;ll do some more file shuffling to reflect those concepts:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/commit/611cb6f8577cf33053d4030c02abd3d991510acc&#34;&gt;Commit 611cb6f: Move core project files to /app for consistency&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;After the move, the project file structure now looks like this:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;- src
  - app
    - layout
      - App.js, App.css
    - reducers
      - rootReducer.js
    - store
      - configureStore.js
  - common
    - components
    - utils
  - features
    - mechs
    - pilots
    - tabs
    - unitInfo
    - unitOrganization
  - index.js
&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id=&#34;extracting-components-in-features&#34;&gt;Extracting Components in Features&lt;/h2&gt;

&lt;p&gt;The original UI layout we made in Part 4 has a single component for each of the tab panels.  It also has fake data hardcoded right into the UI layout itself.  That&#39;s not going to work well when we start dealing with actual data.  So, before we can work with data, we should extract some components from those panels.&lt;/p&gt;

&lt;p&gt;Looking at our &lt;code&gt;&amp;lt;Pilots&amp;gt;&lt;/code&gt; component, it really consists of two main parts: the list of pilots, and the form showing the details of a single pilot.  It makes sense to extract separate components for each of those, so we&#39;ll split out a &lt;code&gt;&amp;lt;PilotsList&amp;gt;&lt;/code&gt; component and a &lt;code&gt;&amp;lt;PilotDetails&amp;gt;&lt;/code&gt; component.&lt;/p&gt;

&lt;p&gt;In addition, the pilots list has a couple different parts.  The header section is static and won&#39;t change.  We could leave that as part of, the render method in &lt;code&gt;&amp;lt;PilotsList&amp;gt;&lt;/code&gt;, but we might as well split it out as a &lt;code&gt;PilotsListHeader&amp;gt;&lt;/code&gt; while we&#39;re at it.  At the same time, we definitely need to be able to render an individual row for each pilot entry, so we&#39;ll create a &lt;code&gt;&amp;lt;PilotsListRow&amp;gt;&lt;/code&gt; component that we can use while rendering the list.&lt;/p&gt;

&lt;p&gt;Since we&#39;re transitioning from hardcoded text in the UI, we should start making use of some kind of sample data.  For the moment, the simplest approach is to treat &lt;code&gt;&amp;lt;Pilots&amp;gt;&lt;/code&gt; as a &amp;quot;container&amp;quot; component, store an array with one item in its state, and pass that down to the list and details components.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/commit/c404584ae486609bd37d38306130a70e7e9d2935&#34;&gt;Commit c404584: Extract components from Pilots panel, and add initial test data&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The main part of our &lt;code&gt;&amp;lt;Pilots&amp;gt;&lt;/code&gt; component now looks like this (skipping library imports):&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/c404584ae486609bd37d38306130a70e7e9d2935/src/features/pilots/Pilots/Pilots.jsx&#34;&gt;features/pilots/Pilots/Pilots.jsx&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-jsx&#34;&gt;import PilotsList from &amp;quot;../PilotsList&amp;quot;;
import PilotDetails from &amp;quot;../PilotDetails&amp;quot;;

const pilots = [
    {
        name : &amp;quot;Natasha Kerensky&amp;quot;,
        rank : &amp;quot;Captain&amp;quot;,
        age : 52,
        gunnery : 2,
        piloting : 3,
        mechType : &amp;quot;WHM-6R&amp;quot;,
    }
];

export class Pilots extends Component {
    state = {
        pilots : pilots,
    }

    render() {
        const {pilots} = this.state;

        // Use the first pilot as the &amp;quot;current&amp;quot; one for display, if available.
        const currentPilot = pilots[0] || {};

        return (
            &amp;lt;Segment&amp;gt;
                &amp;lt;Grid&amp;gt;
                    &amp;lt;Grid.Column width={10}&amp;gt;
                        &amp;lt;Header as=&amp;quot;h3&amp;quot;&amp;gt;Pilot List&amp;lt;/Header&amp;gt;
                        &amp;lt;PilotsList pilots={pilots} /&amp;gt;
                    &amp;lt;/Grid.Column&amp;gt;
                    &amp;lt;Grid.Column width={6}&amp;gt;
                        &amp;lt;Header as=&amp;quot;h3&amp;quot;&amp;gt;Pilot Details&amp;lt;/Header&amp;gt;
                        &amp;lt;Segment &amp;gt;
                            &amp;lt;PilotDetails pilot={currentPilot} /&amp;gt;
                        &amp;lt;/Segment&amp;gt;
                    &amp;lt;/Grid.Column&amp;gt;
                &amp;lt;/Grid&amp;gt;
            &amp;lt;/Segment&amp;gt;
        );
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Since our Mechs list is effectively identical so far, we&#39;ll do the same set of transformations on that as well.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/commit/6b51219a2273170a29251aeff275c01a7feb849b&#34;&gt;Commit 6b51219: Extract components from Mechs panel, and add initial test data&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;There&#39;s one new and useful tidbit to show out of this commit.  In Battletech, a Battlemech can weigh anywhere from 20 to 100 tons, in 5-ton increments.  Mechs are frequently described and grouped based on their &amp;quot;weight class&amp;quot;.  Mechs from 20-35 tons are &amp;quot;Lights&amp;quot;, 40-55 tons are &amp;quot;Mediums&amp;quot;, 60-75 tons are &amp;quot;Heavies&amp;quot;, and a Mech weighing 80-100 tons is an &amp;quot;Assault&amp;quot;.  This is a description that can be derived based on the known weight of a Mech type.  So, we can write a small selector function that takes in a weight value, and returns a description of the weight class:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/6b51219a2273170a29251aeff275c01a7feb849b/src/features/mechs/mechSelectors.js&#34;&gt;features/mechs/mechSelectors.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;const WEIGHT_CLASSES = [
    {name : &amp;quot;Light&amp;quot;, weights : [20, 25, 30, 35]},
    {name : &amp;quot;Medium&amp;quot;, weights : [40, 45, 50, 55]},
    {name : &amp;quot;Heavy&amp;quot;, weights : [60, 65, 70, 75]},
    {name : &amp;quot;Assault&amp;quot;, weights : [80, 85, 90, 95, 100]},
];

export function getWeightClass(weight) {
    const weightClass = WEIGHT_CLASSES.find(wc =&amp;gt; wc.weights.includes(weight)) || {name : &amp;quot;Unknown&amp;quot;};
    return weightClass.name;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Nothing too fancy here.  We define an array with one entry per weight class, and use the &lt;code&gt;Array.find()&lt;/code&gt; method to return the first entry that matches a filter function.  Our filter function uses the &lt;code&gt;Array.includes()&lt;/code&gt; method to see if the given weight value is in the list of weights for that weight class.  If we don&#39;t find a valid weight class, we provide a default result so that we can always &lt;code&gt;return weightClass.name&lt;/code&gt;.  This selector can then be used in &lt;code&gt;&amp;lt;MechsListRow&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;MechDetails&amp;gt;&lt;/code&gt; to provide a display value for the given Mech instance.&lt;/p&gt;

&lt;h2 id=&#34;adding-a-mock-api-for-sample-data&#34;&gt;Adding a Mock API for Sample Data&lt;/h2&gt;

&lt;p&gt;We&#39;re at a point where we need to start working with some data.  In a bigger application or more realistic example, that would probably mean standing up a separate backend server to send back responses, or at least using some kind of &amp;quot;mock API&amp;quot; tool.&lt;/p&gt;

&lt;p&gt;In order to keep this tutorial application as focused as possible, we&#39;re going to follow the classic advice of &lt;a href=&#34;http://www.agilenutshell.com/simplest_thing&#34;&gt;&amp;quot;Do The Simplest Thing That Could Possibly Work&amp;quot;&lt;/a&gt; / &lt;a href=&#34;https://en.wikipedia.org/wiki/You_aren&#39;t_gonna_need_it&#34;&gt;&amp;quot;You Ain&#39;t Gonna Need It&amp;quot;&lt;/a&gt;.  In this case, that means &lt;strong&gt;writing a file to contain our sample data, directly importing it into the source code, and writing a mock API query function that just returns that data in a promise.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We&#39;ll need a bit of UI to actually let us call that mock API function.  Since we&#39;ve already got our tabs bar set up, the simplest way to add some UI is to just create a new panel with a button that fetches the data, and add that as another tab.  We&#39;ll label it the &amp;quot;Tools&amp;quot; panel for now.  It might also make a good place to add &amp;quot;Import&amp;quot; and &amp;quot;Export&amp;quot; buttons down the road.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/commit/db59695446d6342faadbaec11c1af2c6b9c27f78&#34;&gt;Commit db596954: Add a Tools panel and mock API for loading sample data&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The only really interesting bits of out of here are the initial sample data, the mock API function, and our thunk action creator:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/db59695446d6342faadbaec11c1af2c6b9c27f78/src/data/sampleData.js&#34;&gt;data/sampleData.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;const sampleData = {
    unit : {
        name : &amp;quot;Black Widow Company&amp;quot;,
        affiliation : &amp;quot;wd&amp;quot;,
    },
};

export default sampleData;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/db59695446d6342faadbaec11c1af2c6b9c27f78/src/data/mockAPI.js&#34;&gt;data/mockAPI.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;import sampleData from &amp;quot;./sampleData&amp;quot;;

export function fetchData() {
    return Promise.resolve(sampleData);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/db59695446d6342faadbaec11c1af2c6b9c27f78/src/features/tools/toolActions.js&#34;&gt;features/tools/toolActions.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;import {fetchData} from &amp;quot;data/mockAPI&amp;quot;;

import {DATA_LOADED} from &amp;quot;./toolConstants&amp;quot;;

export function loadUnitData() {
    return (dispatch, getState) =&amp;gt; {
        fetchData()
            .then(data =&amp;gt; {
                dispatch({
                    type : DATA_LOADED,
                    payload : data
                })
            });
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;After adding the panel, the UI looks like this:&lt;/p&gt;


&lt;figure &gt;
    &lt;a href=&#34;https://blog.isquaredsoftware.com/images/2016-12-practical-redux-part-5/tools-panel.png&#34;&gt;
        &lt;img src=&#34;https://blog.isquaredsoftware.com/images/2016-12-practical-redux-part-5/tools-panel.png&#34; /&gt;
    &lt;/a&gt;
    
&lt;/figure&gt;


&lt;p&gt;Feel the excitement! :)&lt;/p&gt;

&lt;h2 id=&#34;connecting-the-unit-info-tab&#34;&gt;Connecting the Unit Info Tab&lt;/h2&gt;

&lt;p&gt;It&#39;s time to start hooking up some of our UI to the store.  We&#39;ll start with the simplest part: the Unit Info tab.  First, a bit of background info - it would be helpful to know what a &amp;quot;unit&amp;quot; is.&lt;/p&gt;

&lt;p&gt;&lt;a href=&#34;http://www.sarna.net/wiki/Inner_Sphere_Military_Structure&#34;&gt;A Battletech &amp;quot;unit&amp;quot; is a military group&lt;/a&gt;, which could be part of the official armed forces of one of the various &amp;quot;star nations&amp;quot; in the Battletech universe, or an independent combat group like a mercenary unit.  The five &lt;a href=&#34;http://www.sarna.net/wiki/Successor_States&#34;&gt;Great Houses&lt;/a&gt; in the Battletech universe all maintain vast armies, while hundreds of &lt;a href=&#34;http://www.sarna.net/wiki/Mercenary_unit&#34;&gt;mercenary units&lt;/a&gt; large and small try to make a living through combat.  Some examples of units from the game universe include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Great House army units:

&lt;ul&gt;
&lt;li&gt;24th Dieron Regulars from the Draconis Combine&lt;/li&gt;
&lt;li&gt;2nd Free Worlds Guards from the Free Worlds League&lt;/li&gt;
&lt;li&gt;11th Avalon Hussars from the Federated Suns&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Mercenaries:

&lt;ul&gt;
&lt;li&gt;Wolf&#39;s Dragoons&lt;/li&gt;
&lt;li&gt;21st Centauri Lancers&lt;/li&gt;
&lt;li&gt;Hansen&#39;s Roughriders&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For now, we&#39;re just going to track two attributes for a unit: their name, and what larger group they are affiliated with.&lt;/p&gt;

&lt;p&gt;We&#39;ll start by creating a simple reducer that stores the &amp;quot;Name&amp;quot; and &amp;quot;Affiliation&amp;quot; values, add that to our root reducer, and connect the &lt;code&gt;&amp;lt;UnitInfo&amp;gt;&lt;/code&gt; component to use the data:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/commit/bce3a2d3d4220eb0d80c2bc1d5c7ecc97c0c1e75&#34;&gt;Commit bce3a2d: Add initial unit info reducer and connection&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/bce3a2d3d4220eb0d80c2bc1d5c7ecc97c0c1e75/src/features/unitInfo/unitInfoReducer.js&#34;&gt;features/unitInfo/unitInfoReducer.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;import {createReducer} from &amp;quot;common/utils/reducerUtils&amp;quot;;

const initialState = {
    name : &amp;quot;Black Widow Company&amp;quot;,
    affiliation : &amp;quot;wd&amp;quot;,
};

export default createReducer(initialState, {
});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/bce3a2d3d4220eb0d80c2bc1d5c7ecc97c0c1e75/src/features/unitInfo/unitInfoSelectors.js&#34;&gt;features/unitInfo/unitInfoSelectors.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;export const selectUnitInfo = state =&amp;gt; state.unitInfo;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/bce3a2d3d4220eb0d80c2bc1d5c7ecc97c0c1e75/src/app/reducers/rootReducer.js&#34;&gt;app/reducers/rootReducer.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;import {combineReducers} from &amp;quot;redux&amp;quot;;

import tabReducer from &amp;quot;features/tabs/tabReducer&amp;quot;;
import unitInfoReducer from &amp;quot;features/unitInfo/unitInfoReducer&amp;quot;;

const rootReducer = combineReducers({
    unitInfo : unitInfoReducer,
    tabs : tabReducer,
});

export default rootReducer;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/bce3a2d3d4220eb0d80c2bc1d5c7ecc97c0c1e75/src/features/unitInfo/UnitInfo/UnitInfo.jsx&#34;&gt;features/unitInfo/UnitInfo/UnitInfo.jsx&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-jsx&#34;&gt;const mapState = (state) =&amp;gt; ({
    unitInfo : selectUnitInfo(state),
});

class UnitInfo extends Component {
    render() {
        const {unitInfo} = this.props;
        const {name, affiliation} = unitInfo;

        return (
            &amp;lt;Segment attached=&amp;quot;bottom&amp;quot;&amp;gt;
                &amp;lt;Form size=&amp;quot;large&amp;quot;&amp;gt;
                    &amp;lt;Form.Field name=&amp;quot;name&amp;quot; width={6}&amp;gt;
                        &amp;lt;label&amp;gt;Unit Name&amp;lt;/label&amp;gt;
                        &amp;lt;input placeholder=&amp;quot;Name&amp;quot; value={name}/&amp;gt;
                    &amp;lt;/Form.Field&amp;gt;
                    &amp;lt;Form.Field name=&amp;quot;affiliation&amp;quot; width={6}&amp;gt;
                        &amp;lt;label&amp;gt;Affiliation&amp;lt;/label&amp;gt;
                        &amp;lt;Dropdown
                            selection
                            options={FACTIONS}
                            value={affiliation}
                        /&amp;gt;
                    &amp;lt;/Form.Field&amp;gt;
                &amp;lt;/Form&amp;gt;
            &amp;lt;/Segment&amp;gt;
        );
    }
}

export default connect(mapState)(UnitInfo);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;(Side note: remember how I said I&#39;m still trying to figure out my own best practices for folder structure?  After that last code sample, I definitely have to admit that having the word &amp;quot;unitInfo&amp;quot; show up three times in a path is kinda silly.  Oh well, I&#39;ll deal with it for now.)&lt;/p&gt;

&lt;p&gt;Now that the &lt;code&gt;&amp;lt;UnitInfo&amp;gt;&lt;/code&gt; component is being driven by data from the store, we can do something with that sample data from the mock API.  Let&#39;s update the unit info reducer to respond to the &lt;code&gt;DATA_LOADED&lt;/code&gt; action and see what happens:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/commit/3ccddf180c939351fa8074144d9e2a4c97f60621&#34;&gt;Commit 3ccddf1: Load unit details from sample data&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/3ccddf180c939351fa8074144d9e2a4c97f60621/src/features/unitInfo/unitInfoReducer.js&#34;&gt;features/unitInfo/unitInfoReducer.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;import {createReducer} from &amp;quot;common/utils/reducerUtils&amp;quot;;

import {DATA_LOADED} from &amp;quot;features/tools/toolConstants&amp;quot;;

const initialState = {
    name : &amp;quot;N/A&amp;quot;,
    affiliation : &amp;quot;&amp;quot;,
};

function dataLoaded(state, payload) {
    const {unit} = payload;

    return unit;
}

export default createReducer(initialState, {
    [DATA_LOADED] : dataLoaded,
});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The reducer&#39;s very simple for now.  We start with some empty data in our initial state, listen for &lt;code&gt;DATA_LOADED&lt;/code&gt;, and return the &lt;code&gt;unit&lt;/code&gt; data from the action payload.&lt;/p&gt;

&lt;p&gt;If we load the page, we should see &amp;quot;Name: N/A&amp;quot;.  If we then click the &amp;quot;Reload Unit Data&amp;quot; button in the Tools tab, we should see it change to &amp;quot;Name: Black Widow Company&amp;quot;.  No point in showing a screenshot here, because the UI should still look exactly the same as it has up until now.&lt;/p&gt;

&lt;h2 id=&#34;adding-a-redux-orm-schema-and-model&#34;&gt;Adding a Redux-ORM Schema and Model&lt;/h2&gt;

&lt;p&gt;Okay, so loading two fields was pretty easy.  It&#39;s time to start actually working out what the application&#39;s data model will look like.&lt;/p&gt;

&lt;p&gt;As described back in &lt;a href=&#34;https://blog.isquaredsoftware.com/2016/10/practical-redux-part-0-introduction/&#34;&gt;Part 0&lt;/a&gt; and &lt;a href=&#34;https://blog.isquaredsoftware.com/2016/11/practical-redux-part-3-project-planning-and-setup/&#34;&gt;Part 3&lt;/a&gt;, the goal of this sample application is to build a miniature version of the Battletech &lt;a href=&#34;http://megamek.info/mekhq&#34;&gt;MekHQ game tool&lt;/a&gt;.  &lt;strong&gt;We want to be able to track Battlemech Pilots assigned to a combat unit, which specific Battlemech each Pilot is assigned to, and ultimately organize Battlemechs and their Pilots into groups called &amp;quot;Lances&amp;quot; and &amp;quot;Companies&amp;quot;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;We&#39;re going to use the &lt;a href=&#34;https://github.com/tommikaikkonen/redux-orm&#34;&gt;Redux-ORM&lt;/a&gt; library to help define what our data types are and how they relate to each other.  Those Model types can then be used to help us load data into our store, and query and update that data.  (See &lt;strong&gt;&lt;a href=&#34;https://blog.isquaredsoftware.com/2016/10/practical-redux-part-0-introduction/&#34;&gt;Part 1: Redux-ORM Basics&lt;/a&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;a href=&#34;https://blog.isquaredsoftware.com/2016/10/practical-redux-part-0-introduction/&#34;&gt;Part 2: Redux-ORM Concepts and Techniques&lt;/a&gt;&lt;/strong&gt; for details on how the library works.)&lt;/p&gt;

&lt;p&gt;The first thing we&#39;ll do is &lt;strong&gt;create a Redux-ORM Schema instance, and a parent reducer for all of our entity data&lt;/strong&gt;.  Since this code isn&#39;t specific to a single feature, we&#39;ll add it underneath the &lt;code&gt;app&lt;/code&gt; folder.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/commit/1e48ca2a59acbdc3f1203e231e6637a619893345&#34;&gt;Commit 1e48ca2: Create a Redux-ORM Schema and the initial entities reducer&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/1e48ca2a59acbdc3f1203e231e6637a619893345/src/app/schema/schema.js&#34;&gt;app/schema/schema.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;import {Schema} from &amp;quot;redux-orm&amp;quot;;

const schema = new Schema();

export default schema;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/1e48ca2a59acbdc3f1203e231e6637a619893345/src/app/reducers/entitiesReducer.js&#34;&gt;app/reducers/entitiesReducer.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;import {createReducer} from &amp;quot;common/utils/reducerUtils&amp;quot;;

import schema from &amp;quot;app/schema&amp;quot;

const initialState = schema.getDefaultState();

export default createReducer(initialState, {
});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/1e48ca2a59acbdc3f1203e231e6637a619893345/src/app/reducers/rootReducer.js&#34;&gt;app/reducers/rootReducer.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-diff&#34;&gt;import {combineReducers} from &amp;quot;redux&amp;quot;;

+import entitiesReducer from &amp;quot;./entitiesReducer&amp;quot;;
import tabReducer from &amp;quot;features/tabs/tabReducer&amp;quot;;
import unitInfoReducer from &amp;quot;features/unitInfo/unitInfoReducer&amp;quot;;

const rootReducer = combineReducers({
+   entities : entitiesReducer,
    unitInfo : unitInfoReducer,
    tabs : tabReducer,
});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If we look at our overall app state now using the Redux DevTools, we&#39;ll see &lt;code&gt;entities: {}&lt;/code&gt;.  That&#39;s because we haven&#39;t added any Model types to the Schema instance.&lt;/p&gt;

&lt;p&gt;The first Model type we should add is for pilots.  We&#39;ll keep it &lt;em&gt;really&lt;/em&gt; simple - just a Pilot class, with no relations, and add that to our Schema.  There&#39;s no specific rule for where Model classes should be defined, so for the moment we&#39;re going to define them inside the relevant feature folders.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/commit/4ca88bd3bad4d7c12f8de77f94af88430e081d89&#34;&gt;Commit 4ca88bd: Create Pilot model and add to schema&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/4ca88bd3bad4d7c12f8de77f94af88430e081d89/src/features/pilots/Pilot.js&#34;&gt;features/pilots/Pilot.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;import {Model} from &amp;quot;redux-orm&amp;quot;;

export default class Pilot extends Model {
}

Pilot.modelName = &amp;quot;Pilot&amp;quot;;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/4ca88bd3bad4d7c12f8de77f94af88430e081d89/src/app/schema/schema.js&#34;&gt;app/schema/schema.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-diff&#34;&gt;import {Schema} from &amp;quot;redux-orm&amp;quot;;

+import Pilot from &amp;quot;features/pilots/Pilot&amp;quot;;

const schema = new Schema();
+schema.register(Pilot);

export default schema;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now that we have the Pilot model class registered with the Schema instance, we can go back to the Redux DevTools and see that the generated initial state for our &lt;code&gt;entities&lt;/code&gt; slice reducer now includes an empty &amp;quot;table&amp;quot; for the Pilot type:&lt;/p&gt;


&lt;figure &gt;
    &lt;a href=&#34;https://blog.isquaredsoftware.com/images/2016-12-practical-redux-part-5/devtools-pilot-empty.png&#34;&gt;
        &lt;img src=&#34;https://blog.isquaredsoftware.com/images/2016-12-practical-redux-part-5/devtools-pilot-empty.png&#34; /&gt;
    &lt;/a&gt;
    
&lt;/figure&gt;


&lt;h2 id=&#34;loading-pilot-data-with-redux-orm&#34;&gt;Loading Pilot Data with Redux-ORM&lt;/h2&gt;

&lt;p&gt;With the Pilot model hooked up to the Schema, we can start using it for something useful.  We already have a sample data file and a &lt;code&gt;DATA_LOADED&lt;/code&gt; action being dispatched containing that data.  Let&#39;s add some pilot entries to that list, and load them into memory.&lt;/p&gt;

&lt;p&gt;For sample entries, we&#39;re going to use the characters from the legendary &lt;a href=&#34;http://www.sarna.net/wiki/Black_Widow_Company&#34;&gt;Black Widow Company of the Wolf&#39;s Dragoons mercenary unit&lt;/a&gt;, as they existed in the 3025 game era.  This group was led by the notorious Black Widow herself, &lt;a href=&#34;http://www.sarna.net/wiki/Natasha_Kerensky&#34;&gt;Natasha Kerensky&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We&#39;ll define several attributes for each pilot: an ID, their name, rank, age, in-game Gunnery and Piloting skills (lower is better), and a short description of what type of Battlemech they pilot.  An example looks like:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;{
    pilots: [
        {
            id : 1,
            name : &amp;quot;Natasha Kerensky&amp;quot;,
            rank : &amp;quot;Captain&amp;quot;,
            gunnery : 2,
            piloting : 2,
            age : 52,
            mechType : &amp;quot;WHM-6R&amp;quot;,
        },
        {
            id : 2,
            name : &amp;quot;Colin Maclaren&amp;quot;,
            rank : &amp;quot;Sergeant&amp;quot;,
            gunnery : 3,
            piloting : 4,
            age : 43,
            mechType : &amp;quot;MAD-3R&amp;quot;,
        },
    ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Once those entries have been added to the sample data, they wil be included in the &lt;code&gt;DATA_LOADED&lt;/code&gt; action we&#39;ve been dispatching.  So, we should update our &lt;code&gt;entitiesReducer&lt;/code&gt; to respond to that action.&lt;/p&gt;

&lt;p&gt;Redux-ORM provides methods on Model instances to query, update, and delete instances.  It also provides a &lt;code&gt;create&lt;/code&gt; static method on the class itself to create new instances.  I like to write &lt;code&gt;parse&lt;/code&gt; methods on my Model classes that encapsulate the logic for handling all the relations that might be involved in nested JSON data.  Since this is our first Model type, there&#39;s actually nothing special we need to do:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/commit/04a67852f08ac5e62262a7dc552d1d821543d1bb&#34;&gt;Commit 04a6785: Add Pilot parsing, and load Pilots from sample data&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/04a67852f08ac5e62262a7dc552d1d821543d1bb/src/features/pilots/Pilot.js&#34;&gt;features/pilots/Pilot.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;import {Model} from &amp;quot;redux-orm&amp;quot;;

export default class Pilot extends Model {
    static parse(pilotData) {
        // We could do useful stuff in here with relations,
        // but since we have no relations yet, all we need
        // to do is pass the pilot data on to create()

        // Note that in a static class method, `this` is the
        // class itself, not an instance
        return this.create(pilotData);
    }
}

Pilot.modelName = &amp;quot;Pilot&amp;quot;;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/04a67852f08ac5e62262a7dc552d1d821543d1bb/src/app/reducers/entitiesReducer.js&#34;&gt;app/reducers/entitiesReducer.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;export function loadData(state, payload) {
    // Create a Redux-ORM session from our entities &amp;quot;tables&amp;quot;
    const session = schema.from(state);
    // Get a reference to the correct version of the Pilots class for this Session
    const {Pilot} = session;

    const {pilots} = payload;
    // Queue up creation commands for each pilot entry
    pilots.forEach(pilot =&amp;gt; Pilot.parse(pilot));

    // Apply the queued updates and return the updated &amp;quot;tables&amp;quot;
    return session.reduce();
}

export default createReducer(initialState, {
    [DATA_LOADED] : loadData,
});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Notice that we actually have two different slice reducers responding to the same action!&lt;/strong&gt;  Both our &lt;code&gt;unitInfoReducer&lt;/code&gt; and our &lt;code&gt;entitiesReducer&lt;/code&gt; are responding to the &lt;code&gt;DATA_LOADED&lt;/code&gt; action.  &lt;strong&gt;This is a key concept for Redux usage, which is often misunderstood or ignored&lt;/strong&gt;.  It doesn&#39;t happen by accident, or completely automatically - the &lt;code&gt;combineReducers&lt;/code&gt; function we&#39;re using in our &lt;code&gt;rootReducer&lt;/code&gt; is specifically calling both slice reducers, and giving them a chance to respond to that action by updating their own slice of data.  We could implement the same behavior ourselves, but &lt;code&gt;combineReducers&lt;/code&gt; does it for us.  (&lt;strong&gt;We could also choose &lt;em&gt;not&lt;/em&gt; to use &lt;code&gt;combineReducers&lt;/code&gt; if we wanted to, and maybe handle things a different way if it made sense.&lt;/strong&gt;)&lt;/p&gt;

&lt;p&gt;If we hit the &amp;quot;Reload Unit Data&amp;quot; button in our &amp;quot;Tools&amp;quot; tab and check out the results in the DevTools, our &lt;code&gt;entities&lt;/code&gt; slice should now contain entries for each of the pilot entries in our sample data:&lt;/p&gt;


&lt;figure &gt;
    &lt;a href=&#34;https://blog.isquaredsoftware.com/images/2016-12-practical-redux-part-5/devtools-pilot-full.png&#34;&gt;
        &lt;img src=&#34;https://blog.isquaredsoftware.com/images/2016-12-practical-redux-part-5/devtools-pilot-full.png&#34; /&gt;
    &lt;/a&gt;
    
&lt;/figure&gt;


&lt;p&gt;&lt;strong&gt;Also notice that Redux-ORM automatically stored all the pilots in &amp;quot;normalized&amp;quot; form&lt;/strong&gt;, by creating an &lt;code&gt;items&lt;/code&gt; array for the Pilot type that stores a list of all item IDs, and an &lt;code&gt;itemsById&lt;/code&gt; lookup table that stores the actual objects keyed by their IDs&lt;/p&gt;

&lt;h2 id=&#34;displaying-a-list-of-pilots&#34;&gt;Displaying a List of Pilots&lt;/h2&gt;

&lt;p&gt;Now that we have pilots added to the store, we can update our &lt;code&gt;&amp;lt;Pilots&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;PilotsList&amp;gt;&lt;/code&gt; components to display them.  Since we already had &lt;code&gt;&amp;lt;Pilots&amp;gt;&lt;/code&gt; acting as a container component, all we really need to do is connect it to the store, return an array of plain JS pilot objects as a prop, and switch from using the sample entry we had stored in its state to the array from props.&lt;/p&gt;

&lt;p&gt;To do this, we&#39;re going to import the singleton Redux-ORM Schema instance we created.  In our &lt;code&gt;mapState&lt;/code&gt; function, we&#39;ll create a Session instance from the current set of &amp;quot;tables&amp;quot; in our state, and use the Pilot class we defined to query those tables.  We&#39;ll  retrieve a list of the actual JS objects, and return those as a prop.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/commit/5e2b5d5ce3541d75ebd00f30a2e222e54eb1748b&#34;&gt;Commit 5e2b5d5: Connect the Pilots component to render a list of pilots from the store&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/5e2b5d5ce3541d75ebd00f30a2e222e54eb1748b/src/features/pilots/Pilots/Pilots.jsx&#34;&gt;features/pilots/Pilots/Pilots.jsx&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;// Omit imports not relevant to this commit
import schema from &amp;quot;app/schema&amp;quot;;

const mapState = (state) =&amp;gt; {
    // Create a Redux-ORM Session from our &amp;quot;entities&amp;quot; slice, which
    // contains the &amp;quot;tables&amp;quot; for each model type
    const session = schema.from(state.entities);

    // Retrieve the model class that we need.  Each Session
    // specifically &amp;quot;binds&amp;quot; model classes to itself, so that
    // updates to model instances are applied to that session.
    // These &amp;quot;bound classes&amp;quot; are available as fields in the sesssion.
    const {Pilot} = session;

    // Query the session for all Pilot instances.
    // The QuerySet that is returned from all() can be used to
    // retrieve instances of the Pilot class, or retrieve the
    // plain JS objects that are actually in the store.
    // The toRefArray() method will give us an array of the
    // plain JS objects for each item in the QuerySet.
    const pilots = Pilot.all().toRefArray();

    // Now that we have an array of all pilot objects, return it as a prop
    return {pilots};
}

export class Pilots extends Component {
    render() {
        const {pilots = []} = this.props;

        // Use the first pilot as the &amp;quot;current&amp;quot; one for display, if available.
        const currentPilot = pilots[0] || {};
        
        // Omit rendering code, which didn&#39;t change
    }
}
       
export default connect(mapState)(Pilots);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And with that, we finally have something useful and interesting displayed on screen!&lt;/p&gt;


&lt;figure &gt;
    &lt;a href=&#34;https://blog.isquaredsoftware.com/images/2016-12-practical-redux-part-5/pilots-list.png&#34;&gt;
        &lt;img src=&#34;https://blog.isquaredsoftware.com/images/2016-12-practical-redux-part-5/pilots-list.png&#34; /&gt;
    &lt;/a&gt;
    
&lt;/figure&gt;


&lt;h2 id=&#34;defining-models-with-relations&#34;&gt;Defining Models with Relations&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Redux-ORM allows you to define relations between various model types, using standard database concepts&lt;/strong&gt;.  This is done by adding a &lt;code&gt;fields&lt;/code&gt; entry on a Model class type itself, and using the relation operators provided by Redux-ORM.  Also, as described in &lt;strong&gt;&lt;a href=&#34;https://blog.isquaredsoftware.com/2016/10/practical-redux-part-2-redux-orm-concepts-and-techniques/&#34;&gt;Part 2&lt;/a&gt;&lt;/strong&gt;, when a Model instance is created Redux-ORM will generate getter properties for all fields in the actual data object, as well as all of the relational fields.&lt;/p&gt;

&lt;p&gt;With those ideas in mind, we&#39;re almost ready to define our next couple Model types, but first we need to review a bit more information about the ideas we&#39;re trying to represent.  &lt;strong&gt;In Battletech, there are many different Battlemech designs&lt;/strong&gt;.  Each design has different statistics: weight, speed, armor, weapons, and so on.  There may also be different variations on the same design, which would share the same basic characteristics (usually weight and speed), but maybe have some differences in weapons and armor.  &lt;strong&gt;There can be many different individual mechs of the same design&lt;/strong&gt;.  Here&#39;s some examples of different Battlemech design variants to give you the idea:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Stinger STG-3R&lt;/strong&gt;: 20 tons; 6/9/6 movement points (walk/run/jump); 48 armor points;  1 Medium Laser and 2 Machine Guns&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Stinger STG-3G&lt;/strong&gt;: 20 tons; 6/9/6 movement points; 69 armor points; 2 Medium Lasers&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Warhammer WHM-6R&lt;/strong&gt;: 70 tons; 4/6 movement points; 160 armor points; 2 PPCs, 2 Medium Lasers, 2 Small Lasers, 1 SRM-6 launcher&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Warhammer WHM-6D&lt;/strong&gt;: 70 tons; 4/6 movement points; 217 armor points; 2 PPCs, 2 Medium Lasers, 2 Small Lasers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As a real-life comparison, the F-15 Eagle has several variants: the F-15C is made for air-to-air combat, the F-15D is a training version, the F-15E is intended for ground attacks, and hundreds of individual F-15s have been manufactured.&lt;/p&gt;

&lt;p&gt;For our data modeling, we&#39;re going to create two more Model classes.  We&#39;re going to need to store information on different Battlemech designs, and we also need to track individual mechs.  Rather than copy all the attributes of a design into each individual Mech entry, we can just store the design once, and add a relation between the individual Mech and its design entry.  Meanwhile, since Pilots are going to be assigned to Mechs, we would also want to be able to relate Pilots and Mechs to each other.&lt;/p&gt;

&lt;p&gt;Based on that, &lt;strong&gt;we&#39;re going to create separate models for MechDesigns and Mechs&lt;/strong&gt;.  &lt;strong&gt;The Mech class will use &amp;quot;foreign key&amp;quot; relations to point to a MechDesign instance and a Pilot instance&lt;/strong&gt;.  For now, we&#39;ll also add an FK relation from Pilot to Mech so that we can look up the Mech instance that a given Pilot is assigned to.  We&#39;ll also go ahead and create &lt;code&gt;parse()&lt;/code&gt; methods on them so that we can load them from data.  Finally, we&#39;ll add the Mech and MechDesign classes to our Schema instance, the same way we did with Pilot.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/commit/f28fee9a98c7a5efa456c7e20f1906dca4431ae7&#34;&gt;Commit f28fee9: Define Mech and MechDesign model classes, and add them to the schema&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/f28fee9a98c7a5efa456c7e20f1906dca4431ae7/src/features/mechs/MechDesign.js&#34;&gt;features/mechs/MechDesign.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;import {Model} from &amp;quot;redux-orm&amp;quot;;

export default class MechDesign extends Model {
    static parse(designData) {
        return this.create(designData);
    }
}

MechDesign.modelName = &amp;quot;MechDesign&amp;quot;;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/f28fee9a98c7a5efa456c7e20f1906dca4431ae7/src/features/mechs/Mech.js&#34;&gt;features/mechs/Mech.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;import {Model, fk} from &amp;quot;redux-orm&amp;quot;;


export default class Mech extends Model {
    static get fields() {
        return {
            type : fk(&amp;quot;MechDesign&amp;quot;),
            pilot : fk(&amp;quot;Pilot&amp;quot;),
        };
    }
    
    static parse(mechData) {
        return this.create(mechData);
    }
}

Mech.modelName = &amp;quot;Mech&amp;quot;;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;(The &lt;code&gt;fields&lt;/code&gt; option could have been defined as &lt;code&gt;Mech.fields = {...}&lt;/code&gt; as well, I&#39;ve just been doing it this way since I started using Redux-ORM.  No practical difference as far as I know.)&lt;/p&gt;

&lt;p&gt;After making those changes, we&#39;re also going to be making several other related changes in a follow-up commit.  First, we need to add entries for MechDesigns and Mechs to our sample data.  Second, we need to update the existing Pilot data so that they refer to a specific individual mech&#39;s ID, rather than the ID of a mech type.  Those data changes look roughly like this (for one of the entries):&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/commit/3b25f24b5b7b74dd11d27d58134b11b35802a527&#34;&gt;Commit 3b25f24:Load Mechs and MechDesigns from sample data, and use in display&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/3b25f24b5b7b74dd11d27d58134b11b35802a527/src/data/sampleData.js&#34;&gt;features/data/sampleData.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-diff&#34;&gt;pilots : [
    {
        id : 1,
        name : &amp;quot;Natasha Kerensky&amp;quot;,
        rank : &amp;quot;Captain&amp;quot;,
        gunnery : 2,
        piloting : 2,
        age : 52,
-       mech : &amp;quot;WHM-6R&amp;quot;,
+       mech : 1,
    },
],
+designs : [
+   {
+       id : &amp;quot;WHM-6R&amp;quot;,
+       name : &amp;quot;Warhammer&amp;quot;,
+       weight : 70,
+   },
+],
+mechs : [
+   {
+       id : 1,
+       type : &amp;quot;WHM-6R&amp;quot;,
+       pilot : 1,
+   },
+]
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Third, we need to update our &lt;code&gt;entities&lt;/code&gt; reducer to also load the Mech and Design entries into state:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/3b25f24b5b7b74dd11d27d58134b11b35802a527/src/app/reducers/entitiesReducer.js&#34;&gt;app/reducers/entitiesReducer&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;export function loadData(state, payload) {
    // Create a Redux-ORM session from our entities &amp;quot;tables&amp;quot;
    const session = schema.from(state);
    // Get a reference to the correct version of model classes for this Session
    const {Pilot, MechDesign, Mech} = session;

    const {pilots, designs, mechs} = payload;

    // Queue up creation commands for each entry
    pilots.forEach(pilot =&amp;gt; Pilot.parse(pilot));
    designs.forEach(design =&amp;gt; MechDesign.parse(design));
    mechs.forEach(mech =&amp;gt; Mech.parse(mech));

    // Apply the queued updates and return the updated &amp;quot;tables&amp;quot;
    return session.reduce();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The final change we need to make here is how we prepare the data in the &lt;code&gt;mapState&lt;/code&gt; function for &lt;code&gt;&amp;lt;Pilots&amp;gt;&lt;/code&gt;.  Previously, we just returned the plain JS objects directly.  Now, though, we need to follow the relations from Pilot to Mech to MechDesign in order to display what type of mech this Pilot uses.  The revised &lt;code&gt;mapState&lt;/code&gt; function now looks like this:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/3b25f24b5b7b74dd11d27d58134b11b35802a527/src/features/pilots/Pilots/Pilots.jsx&#34;&gt;features/pilots/Pilots/Pilots.jsx&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;const mapState = (state) =&amp;gt; {
    // Create a Redux-ORM Session from our &amp;quot;entities&amp;quot; slice, which
    // contains the &amp;quot;tables&amp;quot; for each model type
    const session = schema.from(state.entities);

    // Retrieve the model class that we need.  Each Session
    // specifically &amp;quot;binds&amp;quot; model classes to itself, so that
    // updates to model instances are applied to that session.
    // These &amp;quot;bound classes&amp;quot; are available as fields in the sesssion.
    const {Pilot} = session;

    // Query the session for all Pilot instances.
    // The QuerySet that is returned from all() can be used to
    // retrieve instances of the Pilot class, or retrieve the
    // plain JS objects that are actually in the store.

    // The withModels modifier will let us map over Model instances
    // for each entry, rather than the plain JS objects.
    const pilots = Pilot.all().withModels.map(pilotModel =&amp;gt; {
        // Access the underlying plain JS object using the &amp;quot;ref&amp;quot; field,
        // and make a shallow copy of it
        const pilot = {
            ...pilotModel.ref
        };
        
        // We want to look up pilotModel.mech.mechType.  Just in case the
        // relational fields are null, we&#39;ll do a couple safety checks as we go.

        // Look up the associated Mech instance using the foreign-key
        // field that we defined in the Pilot Model class
        const {mech} = pilotModel;

        // If there actually is an associated mech, include the
        // mech type&#39;s ID as a field in the data passed to the component
        if(mech &amp;amp;&amp;amp; mech.type) {
            pilot.mechType = mech.type.id;
        }

        return pilot;
    });

    // Now that we have an array of all pilot objects, return it as a prop
    return {pilots};
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;With these changes in place, the &lt;code&gt;&amp;lt;PilotsList&amp;gt;&lt;/code&gt; should render exactly the same, but with the data for the last column now coming from the MechDesign &amp;quot;table&amp;quot; instead of being directly in each pilot entry.&lt;/p&gt;

&lt;h2 id=&#34;displaying-a-list-of-mechs&#34;&gt;Displaying a List of Mechs&lt;/h2&gt;

&lt;p&gt;We can now connect our &lt;code&gt;&amp;lt;Mechs&amp;gt;&lt;/code&gt; component the same way we did &lt;code&gt;&amp;lt;Pilots&amp;gt;&lt;/code&gt;.  This is pretty straightforward, and the only really interesting part is the &lt;code&gt;mapState&lt;/code&gt; method:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/commit/7a5b7569a14195175e88d6959ae73c1c43b2c834&#34;&gt;Commit 7a5b756: Connect the Mechs component to display a list of mechs from the store&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/7a5b7569a14195175e88d6959ae73c1c43b2c834/src/features/mechs/Mechs/Mechs.jsx&#34;&gt;features/mechs/Mechs/Mechs.jsx&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;// Omit imports

const mapState = (state) =&amp;gt; {
    const session = schema.from(state.entities);
    const {Mech} = session;

    const mechs = Mech.all().withModels.map(mechModel =&amp;gt; {
        const mech = {
            // Copy the data from the plain JS object
            ...mechModel.ref,
            // Provide a default empty object for the relation
            mechType : {},
        };

        if(mechModel.type) {
            // Replace the default object with a copy of the relation&#39;s data
            mech.mechType = {...mechModel.type.ref};
        }

        return mech;
    });

    return {mechs}
}

// Omit component
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And that gives us this update to our UI:&lt;/p&gt;


&lt;figure &gt;
    &lt;a href=&#34;https://blog.isquaredsoftware.com/images/2016-12-practical-redux-part-5/mechs-list.png&#34;&gt;
        &lt;img src=&#34;https://blog.isquaredsoftware.com/images/2016-12-practical-redux-part-5/mechs-list.png&#34; /&gt;
    &lt;/a&gt;
    
&lt;/figure&gt;


&lt;h2 id=&#34;handling-selection-logic&#34;&gt;Handling Selection Logic&lt;/h2&gt;

&lt;p&gt;We&#39;re almost done with this set of changes.  The last thing to add for now is the ability for the user to click on either of the lists and select the item that was clicked on.  Right now, we&#39;re just defaulting to using the first item in an array as the &amp;quot;current&amp;quot; item for display in the Details sections.&lt;/p&gt;

&lt;p&gt;We&#39;ll start with the Pilots list.  We don&#39;t have a reducer for anything pilot-related yet, so we&#39;ll create one.  Going along with the idea of &amp;quot;normalization&amp;quot;, all we need to store is the ID of the currently selected pilot.  We&#39;ll actually get a bit fancy with the reducer logic, and handle de-selecting the current item entirely if the user clicks on it again:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/commit/c42c5bdecc1469481089c2b83273930cb9bd2781&#34;&gt;Commit c42c5bd: Add logic for tracking the currently selected pilot&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/c42c5bdecc1469481089c2b83273930cb9bd2781/src/features/pilots/pilotsReducer.js&#34;&gt;features/pilots/pilotsReducer.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;import {createReducer} from &amp;quot;common/utils/reducerUtils&amp;quot;;

import {PILOT_SELECT} from &amp;quot;./pilotsConstants&amp;quot;;

const initialState = {
    currentPilot : null
};

export function selectPilot(state, payload) {
    const prevSelectedPilot = state.currentPilot;
    const newSelectedPilot = payload.currentPilot;

    const isSamePilot = prevSelectedPilot === newSelectedPilot;
    
    return {
        // Deselect entirely if it&#39;s a second click on the same pilot,
        // otherwise go ahead and select the one that was clicked
        currentPilot : isSamePilot ? null : newSelectedPilot,
    };
}

export default createReducer(initialState, {
    [PILOT_SELECT] : selectPilot,
});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That gives us some data handling, but we need to hook that up to the UI.  We need to pull the &lt;code&gt;currentPilot&lt;/code&gt; ID value into &lt;code&gt;&amp;lt;Pilots&amp;gt;&lt;/code&gt;, and use that in a couple places.  We should pass the actual entry for the current pilot into &lt;code&gt;&amp;lt;PilotDetails&amp;gt;&lt;/code&gt;, and it would also be nice to highlight the row for that pilot in the list.  We also need to call the &lt;code&gt;selectPilot&lt;/code&gt; action creator with the ID of the pilot whose row was just clicked on.  Let&#39;s look at the relevant changes:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/commit/19c3c3a12ad99a01acf8bf6a62076caff8277a81&#34;&gt;Commit 19c3c3a: Implement selection handling for pilots&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/19c3c3a12ad99a01acf8bf6a62076caff8277a81/src/features/pilots/Pilots/Pilots.jsx&#34;&gt;features/pilots/Pilots/Pilots.jsx&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-diff&#34;&gt;// Omit initial imports

+import {selectPilot} from &amp;quot;../pilotsActions&amp;quot;;
+import {selectCurrentPilot} from &amp;quot;../pilotsSelectors&amp;quot;;

const mapState = (state) =&amp;gt; {}
    // Omit pilot objects lookup
    
+   const currentPilot = selectCurrentPilot(state);

    // Now that we have an array of all pilot objects, return it as a prop
-   return {pilots};
+   return {pilots, currentPilot};
}


+// Make an object full of action creators that can be passed to connect
+// and bound up, instead of writing a separate mapDispatch function
+const actions = {
+    selectPilot,
+};

export class Pilots extends Component { 
    render() {
-       const {pilots = []} = this.props;
+       const {pilots = [], selectPilot, currentPilot} = this.props;

-       const currentPilot = pilots[0] || {};
+       const currentPilotEntry = pilots.find(pilot =&amp;gt; pilot.id === currentPilot) || {}

        // Omit irrelevant layout component rendering for space
        return (
            &amp;lt;Segment&amp;gt;
-               &amp;lt;PilotsList pilots={pilots} /&amp;gt;
+               &amp;lt;PilotsList
+                   pilots={pilots}
+                   onPilotClicked={selectPilot}
+                   currentPilot={currentPilot}
+               /&amp;gt;
-               &amp;lt;PilotDetails pilot={currentPilot} /&amp;gt;
+               &amp;lt;PilotDetails pilot={currentPilotEntry} /&amp;gt;
            &amp;lt;/Segment&amp;gt;
        );
    }
}

-export default connect(mapState)(Pilots);
+export default connect(mapState, actions)(Pilots);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/19c3c3a12ad99a01acf8bf6a62076caff8277a81/src/features/pilots/PilotsList/PilotsList.jsx&#34;&gt;features/pilots/PilotsList/PilotsList.jsx&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-diff&#34;&gt;export default class PilotsList extends Component {
    render() {
-       const {pilots} = this.props;
+       const {pilots, onPilotClicked, currentPilot} = this.props;

        const pilotRows = pilots.map(pilot =&amp;gt; (
-           &amp;lt;PilotsListRow pilot={pilot} key={pilot.name}/&amp;gt;
+           &amp;lt;PilotsListRow
+               pilot={pilot}
+               key={pilot.name}
+               onPilotClicked={onPilotClicked}
+               selected={pilot.id === currentPilot}
+           /&amp;gt;
        ));

        // Omit layout rendering for space
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/19c3c3a12ad99a01acf8bf6a62076caff8277a81/src/features/pilots/PilotsList/PilotsListRow.jsx&#34;&gt;features/pilots/PilotsList/PilotsListRow.jsx&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-diff&#34;&gt;+import _ from &amp;quot;lodash&amp;quot;;

-const PilotsListRow = ({pilot={}}) =&amp;gt; {
+const PilotsListRow = ({pilot={}, onPilotClicked=_.noop, selected}) =&amp;gt; {
    const {
+        id = null,
        // Omit other fields
    } = pilot;
    
    return (
-       &amp;lt;Table.Row&amp;gt;
+       &amp;lt;Table.Row onClick={() =&amp;gt; onPilotClicked(id)} active={selected}&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And voila!  If we click on an entry in the pilots list, we should now see that row highlighted, and the entry also shown in the &lt;code&gt;&amp;lt;PilotDetails&amp;gt;&lt;/code&gt; form:&lt;/p&gt;


&lt;figure &gt;
    &lt;a href=&#34;https://blog.isquaredsoftware.com/images/2016-12-practical-redux-part-5/pilots-list-selected.png&#34;&gt;
        &lt;img src=&#34;https://blog.isquaredsoftware.com/images/2016-12-practical-redux-part-5/pilots-list-selected.png&#34; /&gt;
    &lt;/a&gt;
    
&lt;/figure&gt;


&lt;p&gt;And finally, after WAYYYY too long of a blog post, the last thing we&#39;ll do is implement the same behavior for the mechs list as well:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/commit/54794acd672238117943aec309ab5ff75e5ceb7c&#34;&gt;Commit 54794ac: Add logic for tracking the currently selected mech&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/commit/b461cb3276339f33bd5358e9c8ae046a6549a1f7&#34;&gt;Commit b461cb3: Implement selection handling for mechs&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And we see the same nicely highlighted selection for the mechs list:&lt;/p&gt;


&lt;figure &gt;
    &lt;a href=&#34;https://blog.isquaredsoftware.com/images/2016-12-practical-redux-part-5/mechs-list-selected.png&#34;&gt;
        &lt;img src=&#34;https://blog.isquaredsoftware.com/images/2016-12-practical-redux-part-5/mechs-list-selected.png&#34; /&gt;
    &lt;/a&gt;
    
&lt;/figure&gt;


&lt;h2 id=&#34;final-thoughts&#34;&gt;Final Thoughts&lt;/h2&gt;

&lt;p&gt;For those of you who actually got this far, congratulations!  That was a lot of words, code, screenshots, and links.  But, &lt;strong&gt;&lt;em&gt;Project Mini-Mek&lt;/em&gt;&lt;/strong&gt; is now starting to look vaguely useful.  We&#39;ve got some realistic-looking data being loaded up, our first data models are defined, we&#39;re displaying that data in the UI, and we can actually interact with the lists a bit.  It&#39;s taken some time to get here, but we&#39;ve laid a pretty good foundation for the application.  After this, we should be able to start implementing some interesting and useful features with specific techniques.&lt;/p&gt;

&lt;p&gt;Be sure to tune in next time, when we &lt;em&gt;might&lt;/em&gt; just finally get around to doing some of that form editing work I&#39;ve been promising for the last couple posts! :)&lt;/p&gt;

&lt;h2 id=&#34;further-information&#34;&gt;Further Information&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek&#34;&gt;Project Mini-Mek repo&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/pull/3&#34;&gt;PR #3: Practical Redux Part 5 - WIP branch&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/pull/4&#34;&gt;PR #4: Practical Redux Part 5 - Final branch&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Sourcemaps

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://www.html5rocks.com/en/tutorials/developertools/sourcemaps/&#34;&gt;An Introduction to Javascript Source Maps&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://code.tutsplus.com/tutorials/source-maps-101--net-29173&#34;&gt;Source Maps 101&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;http://survivejs.com/webpack/developing-with-webpack/enabling-sourcemaps/&#34;&gt;SurviveJS Enabling Sourcemaps in Webpack&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://lorefnon.me/2016/12/03/on-webpack-and-source-map-integration.html&#34;&gt;On Webpack and Source Map Integration: &lt;code&gt;devtool&lt;/code&gt; Options&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Create-React-App and Sourcemaps

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/facebookincubator/create-react-app/pull/924&#34;&gt;CRA PR #924: Enable sourcemaps in development&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/facebookincubator/create-react-app/pull/1188&#34;&gt;CRA PR #1188: Update Webpack to fix source map issues&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Normalization

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;http://redux.js.org/docs/faq/OrganizingState.html#organizing-state-nested-data&#34;&gt;Redux FAQ: How do I organize nested or relational data in my state?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;http://redux.js.org/docs/recipes/StructuringReducers.html&#34;&gt;Redux docs: Structuring Reducers&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;</description>
    </item>
    
    <item>
      <title>Practical Redux, Part 4: UI Layout and Project Structure</title>
      <link>https://blog.isquaredsoftware.com/2016/11/practical-redux-part-4-ui-layout-and-project-structure/</link>
      <pubDate>Tue, 22 Nov 2016 19:30:36 -0500</pubDate>
      
      <guid>https://blog.isquaredsoftware.com/2016/11/practical-redux-part-4-ui-layout-and-project-structure/</guid>
      <description>&lt;p&gt;&lt;/p&gt;

&lt;h2 id=&#34;intro&#34;&gt;Intro&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://blog.isquaredsoftware.com/2016/11/practical-redux-part-3-project-planning-and-setup/&#34;&gt;Last time&lt;/a&gt;&lt;/strong&gt;, we sketched out a feature list and some UI mockups for &lt;strong&gt;&lt;em&gt;Project Mini-Mek&lt;/em&gt;&lt;/strong&gt;, created a new project using Create-React-App, added a basic Redux configuration, and enabled the use of Hot Module Reloading so that we could see changes in our UI without having to reload the entire page.  In this part, &lt;strong&gt;we&#39;ll set up the initial application layout to match our UI mockups, talk about folder structures, and look at an example of managing UI state with Redux&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Before starting this series, I posted a poll on Twitter asking &lt;a href=&#34;https://twitter.com/acemarke/status/795390842890555393&#34;&gt;whether people would rather see &amp;quot;clean&amp;quot; commits, all WIP commits, or both&lt;/a&gt;.  The responses showed a preference for seeing &amp;quot;clean&amp;quot; commits, but I&#39;m actually going to include a way for people to see both.&lt;/p&gt;

&lt;p&gt;The code for this project is on Github at &lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek&#34;&gt;github.com/markerikson/project-minimek&lt;/a&gt;&lt;/strong&gt;.  The original WIP commits I made for this post can be seen in &lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/pull/1&#34;&gt;PR #1: Practical Redux Part 4 WIP&lt;/a&gt;&lt;/strong&gt;, and the final &amp;quot;clean&amp;quot; commits can be seen in in &lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/pull/2&#34;&gt;PR #2: Practical Redux Part 4 Final&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;h3 id=&#34;table-of-contents&#34;&gt;&lt;strong&gt;Table of Contents&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#choosing-a-ui-toolkit&#34;&gt;Choosing a UI Toolkit&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#setting-up-semantic-ui&#34;&gt;Setting Up Semantic-UI&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#initial-ui-layout&#34;&gt;Initial UI Layout&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#building-a-tabbar-component&#34;&gt;Building a TabBar Component&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#rendering-tab-panels&#34;&gt;Rendering Tab Panels&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#thoughts-on-folder-structure&#34;&gt;Thoughts on Folder Structure&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#enabling-absolute-imports&#34;&gt;Enabling Absolute Imports&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#building-the-first-content-components&#34;&gt;Building the First Content Components&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#handling-tab-state-with-redux&#34;&gt;Handling Tab State with Redux&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#filling-out-the-other-tabs&#34;&gt;Filling Out the Other Tabs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#final-thoughts&#34;&gt;Final Thoughts&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#further-information&#34;&gt;Further Information&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&#34;choosing-a-ui-toolkit&#34;&gt;Choosing a UI Toolkit&lt;/h2&gt;

&lt;p&gt;There&#39;s a seemingly infinite number of web UI toolkits and CSS frameworks out there, of which Bootstrap and its variations are probably the most popular.  I&#39;ve been using &lt;strong&gt;&lt;a href=&#34;http://semantic-ui.com/&#34;&gt;Semantic-UI&lt;/a&gt;&lt;/strong&gt; in another project, and been very happy with it.  It has a nice appearance out of the box, uses very readable markup, and allows considerable customization for theming, including several built-in theme options for various parts such as buttons.&lt;/p&gt;

&lt;p&gt;Semantic-UI consists of two main aspects: CSS-only content for styling, and logic for smarter widgets (such as AJAX fetching capabilities for the Dropdown component).  The original framework uses jQuery to implement its smart widgets.&lt;/p&gt;

&lt;p&gt;There are numerous React libraries that provide React components which render Semantic-UI markup.  However, many of them also try to wrap up the jQuery-based smart components as well.  In my own current app, I&#39;ve been trying to avoid dragging in jQuery as a dependency, so I spent some time looking for a React wrapper for Semantic-UI that avoided the jQuery parts.  I eventually found &lt;a href=&#34;https://github.com/shinzui/react-semantic-ui-kit&#34;&gt;React-Semantic-UI-Kit&lt;/a&gt;, which initially fit the bill.  However, since I started using it, there have been few updates to the wrappers, and there&#39;s some lingering pain points with the library (such as inability to override styles).&lt;/p&gt;

&lt;p&gt;One of the other React/Semantic-UI libraries I looked at was called &amp;quot;Stardust&amp;quot;.  It looked comprehensive and well written, but also wrapped up the jQuery components.  (There was some useful discussion about their approach in &lt;a href=&#34;https://www.reddit.com/r/reactjs/comments/4rpta0/any_feedback_on_stardust_semantic_ui_for_react/&#34;&gt;a Reddit thread about Stardust&lt;/a&gt;.) Since then, the situation has changed.  &amp;quot;Stardust&amp;quot; has been turned into the official &lt;strong&gt;&lt;a href=&#34;http://react.semantic-ui.com/introduction&#34;&gt;Semantic-UI-React&lt;/a&gt;&lt;/strong&gt; library, and now includes completely new React implementations for all of Semantic-UI&#39;s smart components, with no jQuery needed at all.  So, &lt;strong&gt;we&#39;ll be using Semantic-UI-React for the UI layout and styling&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;It&#39;s important to note that Semantic-UI-React is only about generating the correct markup and adding additional logic on top.  In order for that markup to change any appearances, we need to include Semantic-UI&#39;s CSS.  Semantic-UI has &lt;a href=&#34;http://semantic-ui.com/introduction/build-tools.html&#34;&gt;its own build system&lt;/a&gt; that can be used to generate a customized theme, but to simplify things, we&#39;re just going to use the &lt;strong&gt;&lt;a href=&#34;https://github.com/Semantic-Org/Semantic-UI-CSS&#34;&gt;semantic-ui-css&lt;/a&gt;&lt;/strong&gt; package, which provides a prebuilt version of the full Semantic-UI CSS output.&lt;/p&gt;

&lt;h2 id=&#34;setting-up-semantic-ui&#34;&gt;Setting Up Semantic-UI&lt;/h2&gt;

&lt;p&gt;Our first step is to add &lt;code&gt;semantic-ui-react&lt;/code&gt; and &lt;code&gt;semantic-ui-css&lt;/code&gt; to our project;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;yarn add semantic-ui-react semantic-ui-css
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Then, we need to import the main Semantic-UI CSS file into our code so it gets included in the bundle.  We should also render a single Semantic-UI &lt;code&gt;&amp;lt;Header&amp;gt;&lt;/code&gt; component to make sure that&#39;s working as intended.  While we&#39;re at it, let&#39;s yank out the sample component we set up, since we won&#39;t be needing it any more, and also do some cleanup on the original CSS and HTML that generated when the project was created (such as removing the spinning logo, and shrinking the size of the header bar).&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/commit/059c2a73be827ec90e870e9e55b8f5518b69a990&#34;&gt;Commit 059c2a7: Use Semantic-UI and clean up unused code&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/059c2a73be827ec90e870e9e55b8f5518b69a990/src/index.js&#34;&gt;index.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-diff&#34;&gt;import {Provider} from &amp;quot;react-redux&amp;quot;;

-import &#39;./index.css&#39;;
+import &amp;quot;semantic-ui-css/semantic.css&amp;quot;;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/059c2a73be827ec90e870e9e55b8f5518b69a990/src/App.js&#34;&gt;App.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-jsx&#34;&gt;import React, { Component } from &#39;react&#39;;
import {
    Header,
} from &amp;quot;semantic-ui-react&amp;quot;;


import &#39;./App.css&#39;;

class App extends Component {
    render() {
        return (
            &amp;lt;div className=&amp;quot;App&amp;quot;&amp;gt;
                &amp;lt;div className=&amp;quot;App-header&amp;quot;&amp;gt;
                    &amp;lt;Header inverted as=&amp;quot;h1&amp;quot;&amp;gt;Project Mini-Mek&amp;lt;/Header&amp;gt;
                &amp;lt;/div&amp;gt;
            &amp;lt;/div&amp;gt;
        );
    }
}

export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;With the sample code cleaned up, our initial empty UI now looks like:&lt;/p&gt;


&lt;figure &gt;
    &lt;a href=&#34;https://blog.isquaredsoftware.com/images/2016-11-practical-redux-part-4/pmm-semantic-header.png&#34;&gt;
        &lt;img src=&#34;https://blog.isquaredsoftware.com/images/2016-11-practical-redux-part-4/pmm-semantic-header.png&#34; /&gt;
    &lt;/a&gt;
    
&lt;/figure&gt;


&lt;p&gt;Yay - a black bar with some white text!  Isn&#39;t this exciting? :)  Don&#39;t worry, we&#39;ll start adding a lot more from here.&lt;/p&gt;

&lt;h2 id=&#34;initial-ui-layout&#34;&gt;Initial UI Layout&lt;/h2&gt;

&lt;p&gt;Let&#39;s review the original mockup for &lt;strong&gt;&lt;em&gt;Project Mini-Mek&lt;/em&gt;&lt;/strong&gt;&#39;s UI:&lt;/p&gt;


&lt;figure &gt;
    &lt;a href=&#34;https://blog.isquaredsoftware.com/images/2016-11-practical-redux-part-4/ui-mockup-unit-info.png&#34;&gt;
        &lt;img src=&#34;https://blog.isquaredsoftware.com/images/2016-11-practical-redux-part-4/ui-mockup-unit-info.png&#34; /&gt;
    &lt;/a&gt;
    
&lt;/figure&gt;


&lt;p&gt;The main part of our layout is a tab bar with tabs for the four main panels.  Semantic-UI&#39;s &lt;code&gt;&amp;lt;Menu&amp;gt;&lt;/code&gt; component can be configured to display in a tabbed form, so we can go ahead and render an initial hardcoded version of our tabs:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;.&#34;&gt;Commit 9bfab80: Render initial hardcoded tab bar&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/9bfab80acd5eaedeff5706569685fcb2da14cf00/src/App.js&#34;&gt;App.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-diff&#34;&gt;import {
    Header,
+   Container,
+   Menu,
} from &amp;quot;semantic-ui-react&amp;quot;;


class App extends Component {
    render() {
        return (
            &amp;lt;div className=&amp;quot;App&amp;quot;&amp;gt;
                &amp;lt;div className=&amp;quot;App-header&amp;quot;&amp;gt;
                    &amp;lt;Header inverted as=&amp;quot;h1&amp;quot;&amp;gt;Project Mini-Mek&amp;lt;/Header&amp;gt;
                &amp;lt;/div&amp;gt;
+               &amp;lt;Container&amp;gt;
+                   &amp;lt;Menu tabular size=&amp;quot;massive&amp;quot;&amp;gt;
+                       &amp;lt;Menu.Item name=&amp;quot;unitInfo&amp;quot; active={true}&amp;gt;Unit Info&amp;lt;/Menu.Item&amp;gt;
+                       &amp;lt;Menu.Item name=&amp;quot;pilots&amp;quot; active={false}&amp;gt;Pilots&amp;lt;/Menu.Item&amp;gt;
+                       &amp;lt;Menu.Item name=&amp;quot;mechs&amp;quot; active={false}&amp;gt;Mechs&amp;lt;/Menu.Item&amp;gt;
+                       &amp;lt;Menu.Item name=&amp;quot;unitOrganization&amp;quot; active={false}&amp;gt;Unit Organization&amp;lt;/Menu.Item&amp;gt;
+                   &amp;lt;/Menu&amp;gt;
+               &amp;lt;/Container&amp;gt;
            &amp;lt;/div&amp;gt;
        );
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That gives us the following result:&lt;/p&gt;


&lt;figure &gt;
    &lt;a href=&#34;https://blog.isquaredsoftware.com/images/2016-11-practical-redux-part-4/pmm-tab-bar.png&#34;&gt;
        &lt;img src=&#34;https://blog.isquaredsoftware.com/images/2016-11-practical-redux-part-4/pmm-tab-bar.png&#34; /&gt;
    &lt;/a&gt;
    
&lt;/figure&gt;


&lt;p&gt;Still not very exciting, but now we can start filling this out.&lt;/p&gt;

&lt;h2 id=&#34;building-a-tabbar-component&#34;&gt;Building a TabBar Component&lt;/h2&gt;

&lt;p&gt;We&#39;re going to need to track which tab is active, change that on click, and re-render the tab list.  We also will eventually need to swap which content panel is visible as well.  I added a &lt;code&gt;&amp;lt;TabBar&amp;gt;&lt;/code&gt; component that takes an array of tab names and labels and renders the tabs.  Now, we could have the &lt;code&gt;&amp;lt;TabBar&amp;gt;&lt;/code&gt; store the value of which tab is currently selected, but it&#39;s a good practice in React to write &lt;a href=&#34;https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0&#34;&gt;&amp;quot;container components&amp;quot;&lt;/a&gt; which store the state, and keep other components that are &amp;quot;presentational&amp;quot; and just display things based on the props they&#39;re given.  So, we&#39;ll create a &lt;code&gt;&amp;lt;TabBarContainer&amp;gt;&lt;/code&gt; component to track which tab is currently selected:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/commit/c5600b7aabb82b2959785dc67613ae591ac45c97&#34;&gt;Commit c5600b7: Create a TabBar component to render a list of tabs&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/c5600b7aabb82b2959785dc67613ae591ac45c97/src/features/tabs/Tab.jsx&#34;&gt;features/tabs/Tab.jsx&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-jsx&#34;&gt;import React from &amp;quot;react&amp;quot;;
import {Menu} from &amp;quot;semantic-ui-react&amp;quot;;

const Tab = ({name, label, onClick, active}) =&amp;gt; (
    &amp;lt;Menu.Item
        name={name}
        content={label}
        active={active}
        onClick={() =&amp;gt; onClick(name)}
    /&amp;gt;
);

export default Tab;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/c5600b7aabb82b2959785dc67613ae591ac45c97/src/features/tabs/TabBar.jsx&#34;&gt;features/tabs/TabBar.jsx&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-jsx&#34;&gt;import React from &amp;quot;react&amp;quot;;
import {Menu} from &amp;quot;semantic-ui-react&amp;quot;;

import Tab from &amp;quot;./Tab&amp;quot;;

const TabBar = (props) =&amp;gt; {
    const {tabs, currentTab, onTabClick, ...otherProps} = props;

    const tabItems = tabs.map(tabInfo =&amp;gt; {
        const {name, label} = tabInfo;

        return (
            &amp;lt;Tab
                key={name}
                name={name}
                label={label}
                active={currentTab === name}
                onClick={onTabClick}
            /&amp;gt;
        );
    });

    return (
        &amp;lt;div&amp;gt;
            &amp;lt;Menu tabular attached=&amp;quot;top&amp;quot; {...otherProps}&amp;gt;
                {tabItems}
            &amp;lt;/Menu&amp;gt;
        &amp;lt;/div&amp;gt;
    )
}

export default TabBar;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/c5600b7aabb82b2959785dc67613ae591ac45c97/src/features/tabs/TabBarContainer.jsx&#34;&gt;features/tabs/TabBarContainer.jsx&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-jsx&#34;&gt;import React, {Component} from &amp;quot;react&amp;quot;;

import TabBar from &amp;quot;./TabBar&amp;quot;;

export default class TabBarContainer extends Component {
    constructor(props) {
        super(props);

        const {tabs = [{name : null}]} = props;

        const firstTab = tabs[0];

        this.state = {
            currentTab : firstTab.name
        } ;
    }

    onTabClick = (name) =&amp;gt; {
        this.setState({currentTab : name});
    }

    render() {
        const {tabs, ...otherProps} = this.props;
        const {currentTab} = this.state;
        
        return (
            &amp;lt;TabBar
                {...otherProps}
                currentTab={currentTab}
                onTabClick={this.onTabClick}
                tabs={tabs}
            /&amp;gt;
        )
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;With that in place, we can then use it to render our main set of tabs:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/commit/47154d0cd195f5e565af7056ea99751b113a6694&#34;&gt;Commit 47154d0: Render the list of tabs using TabBarContainer&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/47154d0cd195f5e565af7056ea99751b113a6694/src/App.js&#34;&gt;App.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-jsx&#34;&gt;class App extends Component {
    render() {
        const tabs = [
            {name : &amp;quot;unitInfo&amp;quot;, label : &amp;quot;Unit Info&amp;quot;},
            {name : &amp;quot;pilots&amp;quot;, label : &amp;quot;Pilots&amp;quot;},
            {name : &amp;quot;mechs&amp;quot;, label : &amp;quot;Mechs&amp;quot;},
            {name : &amp;quot;unitOrganization&amp;quot;, label : &amp;quot;Unit Organization&amp;quot;}
        ];

        return (
            &amp;lt;div className=&amp;quot;App&amp;quot;&amp;gt;
                &amp;lt;div className=&amp;quot;App-header&amp;quot;&amp;gt;
                    &amp;lt;Header inverted as=&amp;quot;h1&amp;quot;&amp;gt;Project Mini-Mek&amp;lt;/Header&amp;gt;
                &amp;lt;/div&amp;gt;
                &amp;lt;Container&amp;gt;
                    &amp;lt;TabBarContainer tabs={tabs} size=&amp;quot;massive&amp;quot; /&amp;gt;
                &amp;lt;/Container&amp;gt;
            &amp;lt;/div&amp;gt;
        );
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;No major visual changes from this, but we can now click on each tab and see the &amp;quot;active&amp;quot; tab get highlighted.&lt;/p&gt;

&lt;h2 id=&#34;rendering-tab-panels&#34;&gt;Rendering Tab Panels&lt;/h2&gt;

&lt;p&gt;Right now the tab bar only shows the tabs themselves, but no content.  We really need to show a different component as the content for each tab, and swap which component is visible as the active tab changes.&lt;/p&gt;

&lt;p&gt;One way to do this would be to actually change which component is being rendered for the content panel each time the &lt;code&gt;currentTab&lt;/code&gt; prop changes.  Another would be to always render all the tabs, but toggle the visibility instead of un-rendering them.  We&#39;re going to go with toggling visibility, just because I feel like it.&lt;/p&gt;

&lt;p&gt;It&#39;s not too hard to write the logic for toggling the &lt;code&gt;display&lt;/code&gt; style on a given component, but I don&#39;t feel like writing that myself at the moment. There&#39;s a nice little utility component I&#39;ve found called &lt;a href=&#34;https://github.com/ccnokes/react-toggle-display&#34;&gt;React-Toggle-Display&lt;/a&gt; that just renders a span with your content, and toggles the visibility of the span based on a condition or flag prop.&lt;/p&gt;

&lt;p&gt;After adding that to the project, we need to update &lt;code&gt;TabBar&lt;/code&gt; to look for components in the tab definitions, and render those wrapped in a &lt;code&gt;&amp;lt;ToggleDisplay&amp;gt;&lt;/code&gt;.  We also need to add some initial dummy components to our existing tab definitions:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/commit/21393edb923d0447bfeffa8c3ae1f89e1a1ff0be&#34;&gt;Commit 21393ed: Add ability to swap visible tab component based on active tab&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/21393edb923d0447bfeffa8c3ae1f89e1a1ff0be/src/features/tabs/TabBar.jsx&#34;&gt;features/tabs/TabBar.jsx&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-diff&#34;&gt;import {Menu} from &amp;quot;semantic-ui-react&amp;quot;;
+import ToggleDisplay from &#39;react-toggle-display&#39;;


const TabBar = (props) =&amp;gt; {
    const {tabs, currentTab, onTabClick, ...otherProps} = props;

    const tabItems = tabs.map(tabInfo =&amp;gt; { /*.....*/ });

+   const tabPanels = tabs.map(tabInfo =&amp;gt; {
+       const {name, component : TabComponent} = tabInfo;

+       return (
+           &amp;lt;ToggleDisplay show={name === currentTab} key={name}&amp;gt;
+               &amp;lt;TabComponent /&amp;gt;
+           &amp;lt;/ToggleDisplay&amp;gt;
+       )
+   });

    return (
        &amp;lt;div&amp;gt;
            &amp;lt;Menu tabular attached=&amp;quot;top&amp;quot; {...otherProps}&amp;gt;
                {tabItems}
            &amp;lt;/Menu&amp;gt;
+
+            {tabPanels}
        &amp;lt;/div&amp;gt;
    );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/21393edb923d0447bfeffa8c3ae1f89e1a1ff0be/src/App.js&#34;&gt;App.jsx&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-diff&#34;&gt;
+const UnitInfo = () =&amp;gt; &amp;lt;div&amp;gt;Unit Info content&amp;lt;/div&amp;gt;;

+const Pilots = () =&amp;gt; &amp;lt;div&amp;gt;Pilots content&amp;lt;/div&amp;gt;;

+const Mechs = () =&amp;gt; &amp;lt;div&amp;gt;Mechs content&amp;lt;/div&amp;gt;;

+const UnitOrganization = () =&amp;gt; &amp;lt;div&amp;gt;Unit Organization content&amp;lt;/div&amp;gt;;

 class App extends Component {
     render() {
         const tabs = [
+           {name : &amp;quot;unitInfo&amp;quot;, label : &amp;quot;Unit Info&amp;quot;, component : UnitInfo,},
+           {name : &amp;quot;pilots&amp;quot;, label : &amp;quot;Pilots&amp;quot;, component : Pilots,},
+           {name : &amp;quot;mechs&amp;quot;, label : &amp;quot;Mechs&amp;quot;, component : Mechs,},
+           {name : &amp;quot;unitOrganization&amp;quot;, label : &amp;quot;Unit Organization&amp;quot;, component : UnitOrganization}
         ];
         
         // ....
     }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now, as we click between tabs, we can see the visible panel change:&lt;/p&gt;


&lt;figure &gt;
    &lt;a href=&#34;https://blog.isquaredsoftware.com/images/2016-11-practical-redux-part-4/pmm-tab-content.png&#34;&gt;
        &lt;img src=&#34;https://blog.isquaredsoftware.com/images/2016-11-practical-redux-part-4/pmm-tab-content.png&#34; /&gt;
    &lt;/a&gt;
    
&lt;/figure&gt;


&lt;p&gt;Now that we&#39;ve got the tabs working, it&#39;s about time to start filling out the content for those tabs, and that means new components and new files.  But, we&#39;re going to take a detour first.  Creating new files means deciding where to put where to put them, and that&#39;s a topic in and of itself.&lt;/p&gt;

&lt;h2 id=&#34;thoughts-on-folder-structure&#34;&gt;Thoughts on Folder Structure&lt;/h2&gt;

&lt;p&gt;There&#39;s been lots of discussion over what constitutes a good folder structure for a Redux application.  The typical approaches generally fall into two categories: &amp;quot;file-type-first&amp;quot; (folders like &lt;code&gt;/reducers&lt;/code&gt;, &lt;code&gt;/components&lt;/code&gt;, etc), and &amp;quot;feature-first&amp;quot;, also sometimes referred to as &amp;quot;pods&amp;quot; or &amp;quot;domain-based&amp;quot; (folders that each have all the file types for a given feature).&lt;/p&gt;

&lt;p&gt;The original Redux examples use a &amp;quot;file-type-first&amp;quot; approach, but a lot of the recent articles and discussion have shown some convergence on the &amp;quot;feature-first&amp;quot; approach.  There&#39;s tradeoffs either way - &amp;quot;file-type-first&amp;quot; makes it really easy to do something like pulling together all the reducers, but the code for a given feature can be scattered around, and vice versa for &amp;quot;feature-first&amp;quot;.&lt;/p&gt;

&lt;p&gt;My own current approach is mostly a &amp;quot;feature-first&amp;quot;-style approach.  It&#39;s got some similarities to the approach described by Max Stoiber in his article &lt;a href=&#34;https://www.smashingmagazine.com/2016/09/how-to-scale-react-applications/&#34;&gt;How to Scale React Applications&lt;/a&gt;.  The main differences are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I prefer to give my files full unique names, rather than having files named &amp;quot;actions.js&amp;quot; and &amp;quot;reducer.js&amp;quot; in every folder.  This is mostly for ease of finding files and reading file names in editor tabs.  I also would rather give component files unique names, rather than naming them &lt;code&gt;SomeComponent/index.js&lt;/code&gt;.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;I&#39;ve been using &lt;code&gt;index.js&lt;/code&gt; files to re-export functions and components upwards as a sort of &amp;quot;public API&amp;quot; for nested folders.&lt;/li&gt;
&lt;li&gt;I put these folders grouped under a folder named &lt;code&gt;features&lt;/code&gt;, rather than &lt;code&gt;containers&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;I personally tend to use thunks pretty heavily, only using sagas for some specific chunks of async logic.&lt;/li&gt;
&lt;li&gt;I also prefer to use &amp;quot;absolute imports&amp;quot;, such as &lt;code&gt;from &amp;quot;features/someFeature/SomeComponent&amp;quot;&lt;/code&gt;, rather than multi-level relative imports.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All that said, I&#39;m honestly not 100% happy with my current approach.  In particular, in a larger app I&#39;ve noticed that the time needed to hot-reload changes has gone up considerably, and I&#39;m not sure how much is due to just having more code, and how much is due to a more entangled dependency tree causing more files to be affected.  The proliferation of &lt;code&gt;index.js&lt;/code&gt; files and re-exports is also annoying.  So, I&#39;ll freely admit that I&#39;m still trying to figure things out myself.&lt;/p&gt;

&lt;p&gt;So, with those caveats, we&#39;re at a point where we should start extracting files to a more maintainable structure, but there&#39;s a couple tweaks we have to make first.&lt;/p&gt;

&lt;h2 id=&#34;enabling-absolute-imports&#34;&gt;Enabling Absolute Imports&lt;/h2&gt;

&lt;p&gt;As I mentioned, I prefer to consistently use import paths that start from the &lt;code&gt;src&lt;/code&gt; folder.  Among other things, that makes it easier to move files around, as compared to relative import paths.&lt;/p&gt;

&lt;p&gt;Normally, I&#39;d enable that by changing some path resolution options in my Webpack config, but since Create-React-App keeps all the configuration hidden, that&#39;s not an option unless we eject the project.  I did some digging around, and it turns out that, at least for now, there&#39;s a semi-undocumented way to enable this in a CRA app without having to eject.  If the &lt;code&gt;NODE_PATH&lt;/code&gt; environment variable is set, CRA/Webpack will use that in the resolution process.  Also, if a &lt;code&gt;.env&lt;/code&gt; file exists in the project root, those environment variables will be loaded up.  So, we can enable absolute imports by putting those two together.  However, the default &lt;code&gt;.gitignore&lt;/code&gt; file generated by CRA ignores &lt;code&gt;.env&lt;/code&gt;, so we&#39;ll need to fix that:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/commit/922292f02182740a5d496d5972439c506f58b7f5&#34;&gt;Commit 922292f: Enable absolute import paths (such as &amp;quot;features/a/SomeComponent&amp;quot;)&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/922292f02182740a5d496d5972439c506f58b7f5/.env&#34;&gt;.env&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;NODE_PATH=src
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/922292f02182740a5d496d5972439c506f58b7f5/.gitignore&#34;&gt;.gitignore&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-diff&#34;&gt;-.env
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;With that, we can extract the dummy tab panel components into separate feature folders, and import them into App.js:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/commit/07a9c688cb4eaee7aa1939064cd9ea730fc54b90&#34;&gt;Commit 07a9c68: Extract tab panels into separate feature folders&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/07a9c688cb4eaee7aa1939064cd9ea730fc54b90/src/App.js&#34;&gt;App.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-diff&#34;&gt;import TabBarContainer from &amp;quot;./components/TabBar&amp;quot;;
+import UnitInfo from &amp;quot;features/unitInfo/UnitInfo&amp;quot;;
+import Pilots from &amp;quot;features/pilots/Pilots&amp;quot;;
+import Mechs from &amp;quot;features/mechs/Mechs&amp;quot;;
+import UnitOrganization from &amp;quot;features/unitOrganization/UnitOrganization&amp;quot;;

import &#39;./App.css&#39;;

-const UnitInfo = () =&amp;gt; &amp;lt;div&amp;gt;Unit Info content&amp;lt;/div&amp;gt;;
-const Pilots = () =&amp;gt; &amp;lt;div&amp;gt;Pilots content&amp;lt;/div&amp;gt;;
-const Mechs = () =&amp;gt; &amp;lt;div&amp;gt;Mechs content&amp;lt;/div&amp;gt;;
-const UnitOrganization = () =&amp;gt; &amp;lt;div&amp;gt;Unit Organization content&amp;lt;/div&amp;gt;;
&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id=&#34;building-the-first-content-components&#34;&gt;Building The First Content Components&lt;/h2&gt;

&lt;h3 id=&#34;unit-info-tab&#34;&gt;Unit Info Tab&lt;/h3&gt;

&lt;p&gt;The first major piece of our UI will allow displaying and editing the details for whatever fictional Battletech combat group we&#39;ve created.  That includes things like what the name of the group is, what faction they work for, and so on.&lt;/p&gt;

&lt;p&gt;Per the &lt;a href=&#34;#initial-ui-layout&#34;&gt;mockup shown earlier&lt;/a&gt;, the Unit Info tab is just a basic form with a few fields.  We&#39;ll just add the &amp;quot;Name&amp;quot; and &amp;quot;Affiliation&amp;quot; fields for now, and deal with the other fields another time.&lt;/p&gt;

&lt;p&gt;Filling out the &lt;code&gt;&amp;lt;UnitInfo&amp;gt;&lt;/code&gt; component is pretty straightforward:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/commit/7bcde0333b3213f451b288d49ec1b88e125f9a57&#34;&gt;Commit 7bcde03: Add initial form layout for UnitInfo&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/7bcde0333b3213f451b288d49ec1b88e125f9a57/src/features/unitInfo/UnitInfo/UnitInfo.jsx&#34;&gt;features/unitInfo/UnitInfo/UnitInfo.jsx&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-jsx&#34;&gt;import React from &amp;quot;react&amp;quot;;
import {
    Form,
    Dropdown,
    Segment
} from &amp;quot;semantic-ui-react&amp;quot;;

const FACTIONS = [
    // skip other entries
    {value : &amp;quot;lc&amp;quot;, text : &amp;quot;Lyran Commonwealth&amp;quot;},
    {value : &amp;quot;wd&amp;quot;, text : &amp;quot;Wolf&#39;s Dragoons&amp;quot;},
];

const UnitInfo = () =&amp;gt; {

    return (
        &amp;lt;Segment attached=&amp;quot;bottom&amp;quot;&amp;gt;
            &amp;lt;Form size=&amp;quot;large&amp;quot;&amp;gt;
                &amp;lt;Form.Field name=&amp;quot;name&amp;quot; width={6} &amp;gt;
                    &amp;lt;label&amp;gt;Unit Name&amp;lt;/label&amp;gt;
                    &amp;lt;input placeholder=&amp;quot;Name&amp;quot; value=&amp;quot;Black Widow Company&amp;quot;/&amp;gt;
                &amp;lt;/Form.Field&amp;gt;
                &amp;lt;Form.Field name=&amp;quot;affiliation&amp;quot; width={6}&amp;gt;
                    &amp;lt;label&amp;gt;Affiliation&amp;lt;/label&amp;gt;
                    &amp;lt;Dropdown
                       selection
                       options={FACTIONS}
                       value=&amp;quot;wd&amp;quot;
                    /&amp;gt;
                &amp;lt;/Form.Field&amp;gt;
            &amp;lt;/Form&amp;gt;
        &amp;lt;/Segment&amp;gt;
    );
}

export default UnitInfo;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And now we finally have something slightly more visible to show off:&lt;/p&gt;


&lt;figure &gt;
    &lt;a href=&#34;https://blog.isquaredsoftware.com/images/2016-11-practical-redux-part-4/pmm-unit-info-tab.png&#34;&gt;
        &lt;img src=&#34;https://blog.isquaredsoftware.com/images/2016-11-practical-redux-part-4/pmm-unit-info-tab.png&#34; /&gt;
    &lt;/a&gt;
    
&lt;/figure&gt;


&lt;h3 id=&#34;pilots-tab&#34;&gt;Pilots Tab&lt;/h3&gt;

&lt;p&gt;The second major part of the UI is a list of all the pilots that are part of our unit, and a section that will let us view and edit the details of the currently selected pilot.  I&#39;ll skip pasting in the entire Pilots tab component to save space, but here&#39;s the commit and the resulting UI:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/commit/4f871f1684186ba6a0ca8a34d14f3fcd0b26eaf1&#34;&gt;Commit 4f871f1: Add initial Pilots tab layout with hardcoded content&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;


&lt;figure &gt;
    &lt;a href=&#34;https://blog.isquaredsoftware.com/images/2016-11-practical-redux-part-4/pmm-pilots-tab.png&#34;&gt;
        &lt;img src=&#34;https://blog.isquaredsoftware.com/images/2016-11-practical-redux-part-4/pmm-pilots-tab.png&#34; /&gt;
    &lt;/a&gt;
    
&lt;/figure&gt;


&lt;h2 id=&#34;handling-tab-state-with-redux&#34;&gt;Handling Tab State with Redux&lt;/h2&gt;

&lt;p&gt;While working on the Pilots tab, a problem becomes noticeable: because the &amp;quot;current tab&amp;quot; value is stored as state in the &lt;code&gt;&amp;lt;TabBarContainer&amp;gt;&lt;/code&gt; component, reloading the component tree resets the selected tab when the component instance gets wiped out.  This is where Redux can help us, by moving our state outside the component tree.  Fortunately, because we kept the tab state in the &lt;code&gt;&amp;lt;TabBarContainer&amp;gt;&lt;/code&gt; component, we can replace the local component state version with one that pulls the value from Redux  instead.  The feature folder will contain the standard action constants, action creators, and reducers, as well as the selector functions to encapsulate looking up this piece of state.  For simplicity, we&#39;ll just look at the reducer and the new version of &lt;code&gt;&amp;lt;TabBarContainer&amp;gt;&lt;/code&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/commit/e2312e28c36e9487def415562cd4d7bbe3807424&#34;&gt;Commit e2312e2: Rewrite tabs handling to be driven by Redux&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/e2312e28c36e9487def415562cd4d7bbe3807424/src/features/tabs/tabReducer.js&#34;&gt;features/tabs/tabReducer.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-jsx&#34;&gt;import {createReducer} from &amp;quot;common/utils/reducerUtils&amp;quot;;

import {TAB_SELECTED} from &amp;quot;./tabConstants&amp;quot;;

const initialState = {
    currentTab : &amp;quot;unitInfo&amp;quot;,
};

export function selectTab(state, payload) {
    return {
        currentTab : payload.tabName,
    };
}

export default createReducer(initialState, {
    [TAB_SELECTED] : selectTab,
});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/e2312e28c36e9487def415562cd4d7bbe3807424/src/features/tabs/TabBarContainer.jsx&#34;&gt;features/tabs/TabBarContainer.jsx&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-jsx&#34;&gt;import React, {Component} from &amp;quot;react&amp;quot;;
import {connect} from &amp;quot;react-redux&amp;quot;;

import TabBar from &amp;quot;common/components/TabBar&amp;quot;;

import {selectCurrentTab} from &amp;quot;./tabSelectors&amp;quot;;
import {selectTab} from &amp;quot;./tabActions&amp;quot;;

const mapState = (state) =&amp;gt; {
    const currentTab = selectCurrentTab(state);

    return {currentTab};
}

const actions = {onTabClick : selectTab};

export default connect(mapState, actions)(TabBar);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;A couple things to note here.  We&#39;re using one of the umpteen million &lt;code&gt;createReducer&lt;/code&gt; utility functions out there, which lets you define separate reducer functions and a a lookup table instead of switch statements.  We&#39;re also using the object shorthand syntax that &lt;code&gt;connect&lt;/code&gt; supports for the &lt;code&gt;mapDispatch&lt;/code&gt; argument, allowing you to pass in an object full of action creator functions to be bound up, instead of writing an actual &lt;code&gt;mapDispatch&lt;/code&gt; function yourself.&lt;/p&gt;

&lt;h2 id=&#34;filling-out-the-other-tabs&#34;&gt;Filling Out the Other Tabs&lt;/h2&gt;

&lt;h3 id=&#34;mechs-tab&#34;&gt;Mechs Tab&lt;/h3&gt;

&lt;p&gt;With the tab state persisted, we can turn our attention back to laying out the other tabs.  The third major part of the UI is the Mechs tab.  This will basically be identical to the Pilots tab, in that it&#39;s a list of what Battlemechs our force owns, and some form of ability to view and edit details for a selected Battlemech.&lt;/p&gt;

&lt;p&gt;Again, the layout code is long enough that it&#39;s not worth pasting here in full, but here&#39;s what the resulting UI looks like:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/commit/f8f6fc459693e474d96e15d99ccfb79c0273cf9c&#34;&gt;Commit f8f6fc4: Add initial Mechs tab layout with hardcoded content&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;


&lt;figure &gt;
    &lt;a href=&#34;https://blog.isquaredsoftware.com/images/2016-11-practical-redux-part-4/pmm-mechs-tab.png&#34;&gt;
        &lt;img src=&#34;https://blog.isquaredsoftware.com/images/2016-11-practical-redux-part-4/pmm-mechs-tab.png&#34; /&gt;
    &lt;/a&gt;
    
&lt;/figure&gt;


&lt;h3 id=&#34;unit-organization-tab&#34;&gt;Unit Organization Tab&lt;/h3&gt;

&lt;p&gt;The last major part of the UI is the Unit Table of Organization tab.  In Battletech fiction, Pilots and Mechs are grouped together into Lances of four Mechs apiece.  Three Lances are then grouped together to form a Company.  We&#39;re going to need some kind of treeview that will show the hierarchy of Company &amp;gt; Lance &amp;gt; Pilot+Mech, and eventually will need to be able to rearrange which Pilots are in which Lances.  For now, we&#39;ll just hardcode a tree-like display into the UI, and leave things alone until it&#39;s time to build the real thing:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/commit/e5f525845d489b47a9679d0aabdaa168bfcdd340&#34;&gt;Commit e5f5258: Add initial Unit Organization tab layout with hardcoded content&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;


&lt;figure &gt;
    &lt;a href=&#34;https://blog.isquaredsoftware.com/images/2016-11-practical-redux-part-4/pmm-unit-org-tab.png&#34;&gt;
        &lt;img src=&#34;https://blog.isquaredsoftware.com/images/2016-11-practical-redux-part-4/pmm-unit-org-tab.png&#34; /&gt;
    &lt;/a&gt;
    
&lt;/figure&gt;


&lt;h2 id=&#34;final-thoughts&#34;&gt;Final Thoughts&lt;/h2&gt;

&lt;p&gt;That was a pretty good chunk of work.  We&#39;ve got all of our main UI laid out to match the mockups, started using a folder structure that should help the code stay maintainable as we move forward, and added some initial UI logic using Redux.  From here, we can start implementing some actual functionality, and that will give us a chance to look at some specific useful Redux techniques in the process.&lt;/p&gt;

&lt;p&gt;Next time, we&#39;ll look at some approaches for working with forms in Redux, and maybe actually get around to doing some data modeling as well.&lt;/p&gt;

&lt;h2 id=&#34;further-information&#34;&gt;Further Information&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek&#34;&gt;Project Mini-Mek repo&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/pull/1&#34;&gt;PR #1: Practical Redux Part 4 - WIP branch&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/pull/2&#34;&gt;PR #2: Practical Redux Part 4 - Final branch&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Semantic-UI

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;http://semantic-ui.com/&#34;&gt;Semantic-UI home&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;http://react.semantic-ui.com/&#34;&gt;Semantic-UI-React home&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/Semantic-Org/Semantic-UI-CSS&#34;&gt;Semantic-UI-CSS repo&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/ccnokes/react-toggle-display&#34;&gt;React-Toggle-Display&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Container/Presentational Components

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0&#34;&gt;Dan Abramov: Presentational and Container Components&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/markerikson/react-redux-links/blob/master/react-component-patterns.md&#34;&gt;React/Redux Links: React Component Patterns&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Folder Structures

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;http://redux.js.org/docs/faq/CodeStructure.html#structure-file-structure&#34;&gt;Redux FAQ: Code Structure - What should my file structure look like?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.smashingmagazine.com/2016/09/how-to-scale-react-applications/&#34;&gt;Max Stoiber: How to Scale React Applications&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/markerikson/react-redux-links/blob/master/project-structure.md&#34;&gt;React/Redux Links: Project Structure&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/markerikson/react-redux-links/blob/master/redux-architecture.md&#34;&gt;React/Redux Links: Redux Architecture&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Absolute imports in Create-React-App

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/facebookincubator/create-react-app/pull/476&#34;&gt;PR #476: Make Webpack use NODE_PATH variable&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/facebookincubator/create-react-app/pull/693/files&#34;&gt;PR #693: Document existing workaround for absolute imports&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/facebookincubator/create-react-app/issues/741&#34;&gt;Issue #741: Support absolute paths with packages folder&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Selector Functions

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://medium.com/@adamrackis/querying-a-redux-store-37db8c7f3b0f&#34;&gt;Querying a Redux Store&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/markerikson/react-redux-links/blob/master/redux-reducers-selectors.md#selectors-and-normalization&#34;&gt;React/Redux Links: Redux Reducers and Selectors&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;</description>
    </item>
    
    <item>
      <title>Practical Redux, Part 3: Project Planning and Setup</title>
      <link>https://blog.isquaredsoftware.com/2016/11/practical-redux-part-3-project-planning-and-setup/</link>
      <pubDate>Thu, 10 Nov 2016 23:00:00 -0400</pubDate>
      
      <guid>https://blog.isquaredsoftware.com/2016/11/practical-redux-part-3-project-planning-and-setup/</guid>
      <description>&lt;p&gt;&lt;/p&gt;

&lt;h3 id=&#34;table-of-contents&#34;&gt;&lt;strong&gt;Table of Contents&lt;/strong&gt;&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#planning-the-sample-application&#34;&gt;Planning the Sample Application&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#ui-mockups&#34;&gt;UI Mockups&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#project-setup-and-configuration&#34;&gt;Project Setup and Configuration&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#final-thoughts&#34;&gt;Final Thoughts&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#further-information&#34;&gt;Further Information&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&#34;planning-the-sample-application&#34;&gt;Planning The Sample Application&lt;/h2&gt;

&lt;p&gt;As I mentioned in the &lt;strong&gt;&lt;a href=&#34;https://blog.isquaredsoftware.com/2016/10/practical-redux-part-0-introduction/&#34;&gt;series introduction&lt;/a&gt;&lt;/strong&gt;, I&#39;ve got a number of specific techniques and concepts that I&#39;d like to talk about.  I&#39;ve had several requests to show some actual working examples of these techniques, so I&#39;ve decided to try to build a small example application to demonstrate these ideas in a meaningful context.&lt;/p&gt;

&lt;p&gt;I&#39;m a big fan of the &lt;a href=&#34;http://bg.battletech.com/&#34;&gt;Battletech game universe&lt;/a&gt;, a game about big stompy robots with weapons that are used to fight wars a thousand years in the future.  The game universe includes &lt;a href=&#34;http://bg.battletech.com/new-to-the-board-game/&#34;&gt;miniatures tabletop games, computer games, roleplaying games, fiction, and more&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;There&#39;s a number of fan-built projects based in the Battletech universe.  One of the most popular is &lt;a href=&#34;http://megamek.org/about&#34;&gt;Megamek&lt;/a&gt;, a cross-platform computer implementation of the Classic Battletech tabletop game.  In addition, the Megamek authors have built a tool called &lt;strong&gt;&lt;a href=&#34;http://megamek.info/mekhq&#34;&gt;MekHQ&lt;/a&gt;&lt;/strong&gt;, a tool for managing an ongoing campaign for a fictional combat organization, such as a mercenary unit.&lt;/p&gt;

&lt;p&gt;For this blog series, &lt;strong&gt;I&#39;m planning to build a miniature version of the MekHQ application&lt;/strong&gt;.  I definitely do &lt;em&gt;not&lt;/em&gt; intend to seriously rebuild all of MekHQ&#39;s functionality, but it should serve as a useful inspiration and justification for most of the techniques I want to show off.&lt;/p&gt;

&lt;p&gt;On a related note: &lt;strong&gt;I&#39;m absolutely making this up as I go along :)&lt;/strong&gt;  I&#39;ve got some definite ideas for what I want to show off, but I&#39;ll be developing this sample app as I work on each post.  &lt;strong&gt;That means I&#39;ll probably make some mistakes, need to change things, and iterate on the code&lt;/strong&gt;.  This will be a learning experience for everyone involved :)&lt;/p&gt;

&lt;p&gt;Every project needs a good name.  I haven&#39;t come up with a good name yet, so we&#39;ll call this &lt;strong&gt;&lt;em&gt;&amp;quot;Project Mini-Mek&amp;quot;&lt;/em&gt;&lt;/strong&gt; for now.  (If anyone comes up with a better name, I&#39;m listening!)&lt;/p&gt;

&lt;h3 id=&#34;project-features&#34;&gt;Project Features&lt;/h3&gt;

&lt;p&gt;MekHQ is a very complex and in-depth application.  The &amp;quot;About&amp;quot; page describes it this way:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;MekHQ is a Java program that allow users to manage units in-between actual games of MegaMek. It implements most of the rules in the &amp;quot;Maintenance, Repair, and Salvage&amp;quot; section of Strategic Operations, many of the rules and options from the Mercenary Field Manual, and various options that allow users to customize a mercenary, house, or clan campaign to their liking . Some of the features include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Track XP and improve pilot skills and abilities&lt;/li&gt;
&lt;li&gt;Integration with MegaMek and MegaMekLab&lt;/li&gt;
&lt;li&gt;Planetary map and the plotting of jumpship travel&lt;/li&gt;
&lt;li&gt;Organize a TO&amp;amp;E&lt;/li&gt;
&lt;li&gt;Create and resolve missions and scenarios&lt;/li&gt;
&lt;li&gt;Repair and salvage units&lt;/li&gt;
&lt;li&gt;Equipment tracking&lt;/li&gt;
&lt;li&gt;Financial tracking&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;For &lt;strong&gt;&lt;em&gt;Project Mini-Mek&lt;/em&gt;&lt;/strong&gt;, we&#39;re only going to deal with a couple of these, and at a very simple level.  Here&#39;s a tentative list of features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Load JSON data describing the pilots and Battlemechs in a combat force&lt;/li&gt;
&lt;li&gt;For both pilots and Battlemechs:

&lt;ul&gt;
&lt;li&gt;Show a list of all items&lt;/li&gt;
&lt;li&gt;Allow selection of an item in the list, and show details of the selected item&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Edit the details for a pilot&lt;/li&gt;
&lt;li&gt;Organize the pilots and their mechs into &amp;quot;lances&amp;quot; of four mechs, and the &amp;quot;lances&amp;quot; into a &amp;quot;company&amp;quot; of three lances.&lt;/li&gt;
&lt;li&gt;Add and remove pilots and mechs from the force&lt;/li&gt;
&lt;li&gt;Save the force back out to JSON&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, basically Yet Another CRUD APP, with some specific themes :)  For now, &lt;strong&gt;I&#39;m &lt;em&gt;not&lt;/em&gt; planning to deal with a backend or any AJAX handling&lt;/strong&gt;.  I figure I&#39;ll start with static JSON being directly imported, and then maybe add file import/export later on.&lt;/p&gt;

&lt;h3 id=&#34;ui-mockups&#34;&gt;UI Mockups&lt;/h3&gt;

&lt;h4 id=&#34;mekhq-pilot-listing&#34;&gt;MekHQ: Pilot Listing&lt;/h4&gt;

&lt;p&gt;Let&#39;s start by looking at some screenshots of the original MekHQ UI.  First, here&#39;s the screen that shows the list of pilots, and the details for the currently selected pilot:&lt;/p&gt;


&lt;figure &gt;
    &lt;a href=&#34;https://blog.isquaredsoftware.com/images/2016-11-practical-redux-part-3/mekhq-pilot-list.png&#34;&gt;
        &lt;img src=&#34;https://blog.isquaredsoftware.com/images/2016-11-practical-redux-part-3/mekhq-pilot-list.png&#34; /&gt;
    &lt;/a&gt;
    
&lt;/figure&gt;


&lt;h4 id=&#34;mekhq-unit-table-of-organization-tree&#34;&gt;MekHQ: Unit Table of Organization Tree&lt;/h4&gt;

&lt;p&gt;Next, the &amp;quot;Unit Table of Organization&amp;quot; section, showing the various sub-units in a tree structure, and again with a details section on the right:&lt;/p&gt;


&lt;figure &gt;
    &lt;a href=&#34;https://blog.isquaredsoftware.com/images/2016-11-practical-redux-part-3/mekhq-unit-toe.png&#34;&gt;
        &lt;img src=&#34;https://blog.isquaredsoftware.com/images/2016-11-practical-redux-part-3/mekhq-unit-toe.png&#34; /&gt;
    &lt;/a&gt;
    
&lt;/figure&gt;


&lt;p&gt;This gives us a general idea of the UI layout we want: a tab bar across the top, with most of the tab panes containing a list of some kind on the left, and a details box for the currently selected item on the right.&lt;/p&gt;

&lt;p&gt;Here&#39;s some rough mockups of what our UI might look like:&lt;/p&gt;

&lt;h4 id=&#34;project-mini-mek-unit-info&#34;&gt;Project Mini-Mek: Unit Info&lt;/h4&gt;


&lt;figure &gt;
    &lt;a href=&#34;https://blog.isquaredsoftware.com/images/2016-11-practical-redux-part-3/ui-mockup-unit-info.png&#34;&gt;
        &lt;img src=&#34;https://blog.isquaredsoftware.com/images/2016-11-practical-redux-part-3/ui-mockup-unit-info.png&#34; /&gt;
    &lt;/a&gt;
    
&lt;/figure&gt;


&lt;h4 id=&#34;project-mini-mek-pilot-listing&#34;&gt;Project Mini-Mek: Pilot Listing&lt;/h4&gt;


&lt;figure &gt;
    &lt;a href=&#34;https://blog.isquaredsoftware.com/images/2016-11-practical-redux-part-3/ui-mockup-pilots.png&#34;&gt;
        &lt;img src=&#34;https://blog.isquaredsoftware.com/images/2016-11-practical-redux-part-3/ui-mockup-pilots.png&#34; /&gt;
    &lt;/a&gt;
    
&lt;/figure&gt;


&lt;h4 id=&#34;project-mini-mek-mech-listing&#34;&gt;Project Mini-Mek: Mech Listing&lt;/h4&gt;


&lt;figure &gt;
    &lt;a href=&#34;https://blog.isquaredsoftware.com/images/2016-11-practical-redux-part-3/ui-mockup-mechs.png&#34;&gt;
        &lt;img src=&#34;https://blog.isquaredsoftware.com/images/2016-11-practical-redux-part-3/ui-mockup-mechs.png&#34; /&gt;
    &lt;/a&gt;
    
&lt;/figure&gt;


&lt;h4 id=&#34;project-mini-mek-unit-table-of-organization-tree&#34;&gt;Project Mini-Mek: Unit Table of Organization Tree&lt;/h4&gt;


&lt;figure &gt;
    &lt;a href=&#34;https://blog.isquaredsoftware.com/images/2016-11-practical-redux-part-3/ui-mockup-unit-toe.png&#34;&gt;
        &lt;img src=&#34;https://blog.isquaredsoftware.com/images/2016-11-practical-redux-part-3/ui-mockup-unit-toe.png&#34; /&gt;
    &lt;/a&gt;
    
&lt;/figure&gt;


&lt;h2 id=&#34;project-setup-and-configuration&#34;&gt;Project Setup and Configuration&lt;/h2&gt;

&lt;p&gt;We&#39;re going to set up the project using the excellent &lt;strong&gt;&lt;a href=&#34;https://github.com/facebookincubator/create-react-app&#34;&gt;Create-React-App&lt;/a&gt;&lt;/strong&gt; tool.  I&#39;m also going to be using the new &lt;strong&gt;&lt;a href=&#34;https://yarnpkg.com/&#34;&gt;Yarn&lt;/a&gt;&lt;/strong&gt; package manager, partly because it&#39;s supposed to be faster, and partly because this gives me a chance to try it out.  Also, as an FYI, I&#39;m writing all this on Windows, but I don&#39;t expect any meaningful OS/platform issues to pop up as we go.  Finally, &lt;strong&gt;I don&#39;t necessarily intend to show every last command I&#39;ve typed or bit of code I&#39;ve written as we go on&lt;/strong&gt; - the real focus is intended to be on using Redux itself, not using Git or an editor.&lt;/p&gt;

&lt;p&gt;The project is available on Github, at &lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek&#34;&gt;https://github.com/markerikson/project-minimek&lt;/a&gt;&lt;/strong&gt;.  I plan on updating it as I publish each post, and hope to show both some of the nitty-gritty &amp;quot;WIP&amp;quot; commits as well as cleaner &amp;quot;final result&amp;quot; commits.  Also, when I show code snippets or refer to source files in the repo, I&#39;ll usually try to link to that file on Github at the specific version where the changes were made.&lt;/p&gt;

&lt;p&gt;All right, let&#39;s do this!&lt;/p&gt;

&lt;h3 id=&#34;creating-the-project&#34;&gt;Creating the Project&lt;/h3&gt;

&lt;p&gt;Follow the instructions for installing the &lt;code&gt;create-react-app&lt;/code&gt; and &lt;code&gt;yarn&lt;/code&gt; tools on your system.  Once that&#39;s done, we can create our project:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;create-react-app project-minimek
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This is a good time to initialize a Git repo for the initial sample files and project config files.  After the project is created, we want to set up a Yarn lockfile to nail down the specific dependency versions we&#39;re using.  &lt;code&gt;create-react-app&lt;/code&gt; already installed everything it needs (using NPM, although Yarn support is planned), but we need to run &lt;code&gt;yarn&lt;/code&gt; to make sure we&#39;re ready for adding more dependencies:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;cd project-minimek
yarn
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;There&#39;s a bunch more file work done as Yarn figures out what dependencies you have, and prepares its lockfile, &lt;code&gt;yarn.lock&lt;/code&gt;.  That should be committed to Git as well.&lt;/p&gt;

&lt;h3 id=&#34;dependencies&#34;&gt;Dependencies&lt;/h3&gt;

&lt;p&gt;Time to pull in our initial list of dependencies.  Here&#39;s what we&#39;re going to add:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Redux&lt;/strong&gt;: because without it, this would be a really short blog series&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;React-Redux&lt;/strong&gt;: ditto&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Redux-Thunk&lt;/strong&gt;: the most common and simple addon for side effects and complex dispatching logic&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Reselect&lt;/strong&gt;: needed for memoized &amp;quot;selector&amp;quot; functions when retrieving data from our state&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Redux-ORM&lt;/strong&gt;: a handy abstraction layer for managing relational data in our state&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Lodash&lt;/strong&gt;: every useful function you can think of, and a bunch more you didn&#39;t even know existed&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;cuid&lt;/strong&gt;: We&#39;ll probably be generating IDs at some point, so this will fill that need&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We can add them all in at once:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;yarn add redux react-redux redux-thunk reselect redux-orm lodash cuid
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And then commit our &lt;code&gt;package.json&lt;/code&gt; and &lt;code&gt;yarn.lock&lt;/code&gt; again.&lt;/p&gt;

&lt;h3 id=&#34;initial-redux-configuration&#34;&gt;Initial Redux Configuration&lt;/h3&gt;

&lt;p&gt;We need to set up the initial Redux store and reducers, make the store available to our component tree, and make sure that it&#39;s being used.  Here&#39;s what my initial Redux configuration looks like:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/455b1ee41e3968f622f3550dcaafbdebc245d6b9/src/store/configureStore.js&#34;&gt;store/configureStore.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;import {createStore, applyMiddleware, compose} from &amp;quot;redux&amp;quot;;

import thunk from &amp;quot;redux-thunk&amp;quot;;

import rootReducer from &amp;quot;../reducers/rootReducer&amp;quot;;

export default function configureStore(preloadedState) {
    const middlewares = [thunk];
    const middlewareEnhancer = applyMiddleware(...middlewares);

    const storeEnhancers = [middlewareEnhancer];
    
    const composedEnhancer = compose(...storeEnhancers);

    const store = createStore(
        rootReducer,
        preloadedState,
        composedEnhancer
    );

    return store;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I like to keep my store setup logic in a &lt;code&gt;configureStore&lt;/code&gt; function that can be further improved as time goes on.  I also try to keep the setup for each piece of the configuration process separate, so it&#39;s easy to follow what&#39;s going on.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/455b1ee41e3968f622f3550dcaafbdebc245d6b9/src/reducers/testReducer.js&#34;&gt;reducers/testReducer.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;const initialState = {
    data : 42
};

export default function testReducer(state = initialState, action) {
    return state;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/455b1ee41e3968f622f3550dcaafbdebc245d6b9/src/reducers/rootReducer.js&#34;&gt;reducers/rootReducer.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;import {combineReducers} from &amp;quot;redux&amp;quot;;

import testReducer from &amp;quot;./testReducer&amp;quot;;

const rootReducer = combineReducers({
    test : testReducer,
});

export default rootReducer;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Our initial reducers just pass along some test data so we can verify things are working.&lt;/p&gt;

&lt;p&gt;We then create a store instance and use it in the rendering process:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/455b1ee41e3968f622f3550dcaafbdebc245d6b9/src/index.js&#34;&gt;index.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-jsx&#34;&gt;import React from &#39;react&#39;;
import ReactDOM from &#39;react-dom&#39;;
import {Provider} from &amp;quot;react-redux&amp;quot;;

import App from &#39;./App&#39;;
import &#39;./index.css&#39;;

import configureStore from &amp;quot;./store/configureStore&amp;quot;;
const store = configureStore();

ReactDOM.render(
    &amp;lt;Provider store={store}&amp;gt;
        &amp;lt;App /&amp;gt;
    &amp;lt;/Provider&amp;gt;,
    document.getElementById(&#39;root&#39;)
);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Finally, we add a simple test component, connect it to Redux, and render it in our App component to verify that everything&#39;s hooked up properly:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/455b1ee41e3968f622f3550dcaafbdebc245d6b9/src/SampleComponent.jsx&#34;&gt;SampleComponent.jsx&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-jsx&#34;&gt;import React, {Component} from &amp;quot;react&amp;quot;;
import {connect} from &amp;quot;react-redux&amp;quot;;

const mapState = state =&amp;gt; ({
    data : state.test.data
});

class SampleComponent extends Component {
    render() {
        const {data} = this.props;
        
        return (
            &amp;lt;div&amp;gt;
                Data from Redux: {data}
            &amp;lt;/div&amp;gt;
        );
    }
}

export default connect(mapState)(SampleComponent);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/455b1ee41e3968f622f3550dcaafbdebc245d6b9/src/App.js&#34;&gt;App.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-jsx&#34;&gt;import React, { Component } from &#39;react&#39;;
import logo from &#39;./logo.svg&#39;;
import &#39;./App.css&#39;;

import SampleComponent from &amp;quot;./SampleComponent&amp;quot;;

class App extends Component {
    render() {
        return (
            &amp;lt;div className=&amp;quot;App&amp;quot;&amp;gt;
                &amp;lt;div className=&amp;quot;App-header&amp;quot;&amp;gt;
                    &amp;lt;img src={logo} className=&amp;quot;App-logo&amp;quot; alt=&amp;quot;logo&amp;quot;/&amp;gt;
                    &amp;lt;h2&amp;gt;Project Mini-Mek&amp;lt;/h2&amp;gt;
                &amp;lt;/div&amp;gt;
                &amp;lt;SampleComponent /&amp;gt;
            &amp;lt;/div&amp;gt;
        );
    }
}

export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;We should now see the text &amp;quot;Data from Redux: 42&amp;quot; in our page, right below the header bar.&lt;/p&gt;

&lt;h3 id=&#34;adding-the-redux-devtools-extension&#34;&gt;Adding the Redux DevTools Extension&lt;/h3&gt;

&lt;p&gt;One of the original reasons for Redux&#39;s creation was the goal of &lt;strong&gt;&amp;quot;time-travel debugging&amp;quot;&lt;/strong&gt;: the ability to see the list of dispatched actions, view the contents of an action, see what parts of the state were changed after the action was dispatched,  view the overall application state after that dispatch, and step back and forth between dispatched actions.  Dan Abramov wrote the original &lt;a href=&#34;https://github.com/gaearon/redux-devtools&#34;&gt;Redux DevTools&lt;/a&gt; toolset, which showed that information with the UI as a component within the page.&lt;/p&gt;

&lt;p&gt;Since then, Mihail Diordiev has built the &lt;strong&gt;&lt;a href=&#34;https://github.com/zalmoxisus/redux-devtools-extension&#34;&gt;Redux DevTools Extension&lt;/a&gt;&lt;/strong&gt;, a browser extension that bundles together the core Redux DevTools logic and several community-built data visualizers as a browser extension, and adds a bunch of useful functionality on top of that.  Connecting the DevTools Extension to your store requires a few extra checks, so there&#39;s now a package available that encapsulates the process needed to hook up the DevTools Extension to your store.&lt;/p&gt;

&lt;p&gt;We&#39;ll add the helper package with &lt;code&gt;yarn add redux-devtools-extension&lt;/code&gt;, then make a couple small changes to the store setup logic:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/61899ca3b43bbb6a44f60520207663b20992d23d/src/store/configureStore.js&#34;&gt;store/configureStore.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-diff&#34;&gt;- import {createStore, applyMiddleware, compose} from &amp;quot;redux&amp;quot;;
+ import {createStore, applyMiddleware} from &amp;quot;redux&amp;quot;;
+ import { composeWithDevTools } from &#39;redux-devtools-extension/developmentOnly&#39;;


- const composedEnhancer = compose(...storeEnhancers);
+ const composedEnhancer = composeWithDevTools(...storeEnhancers);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This should add the DevTools enhancer to our store, but only when we&#39;re in development mode.  With that installed, the Redux DevTools browser extension can now view the contents of our store and the history of the dispatched actions.&lt;/p&gt;

&lt;h3 id=&#34;component-hot-reloading&#34;&gt;Component Hot Reloading&lt;/h3&gt;

&lt;p&gt;Out of the box, &lt;code&gt;create-react-app&lt;/code&gt; will watch your files on disk, and whenever you save changes, it will recompile the application and reload the entire page.  That&#39;s nice, but we can actually set up some improvements on that.  In particular, the Webpack build tool used by &lt;code&gt;create-react-app&lt;/code&gt; supports a feature known as &lt;strong&gt;&lt;a href=&#34;https://webpack.js.org/concepts/hot-module-replacement/&#34;&gt;Hot Module Replacement&lt;/a&gt;&lt;/strong&gt;, or HMR, which can hot-swap the newly compiled versions of files into your already-open application.  That lets us see our changes faster.  This works great with a React app, and even better in combination with Redux, since we can reload our component tree but still keep the same application state as before.&lt;/p&gt;

&lt;p&gt;We&#39;ll also want to add the &lt;code&gt;redbox-react&lt;/code&gt; package, which we can use to render an error message and a stack trace if something goes wrong.  Once that&#39;s installed, we need to update &lt;code&gt;index.js&lt;/code&gt; to rework the top-level rendering logic:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/ab7392198224f16e8149f12536e709dec284d173/src/index.js&#34;&gt;index.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-jsx&#34;&gt;import React from &#39;react&#39;;
import ReactDOM from &#39;react-dom&#39;;
import {Provider} from &amp;quot;react-redux&amp;quot;;

import &#39;./index.css&#39;;

import configureStore from &amp;quot;./store/configureStore&amp;quot;;
const store = configureStore();

// Save a reference to the root element for reuse
const rootEl = document.getElementById(&amp;quot;root&amp;quot;);

// Create a reusable render method that we can call more than once
let render = () =&amp;gt; {
    // Dynamically import our main App component, and render it
    const App = require(&amp;quot;./App&amp;quot;).default;
    
    ReactDOM.render(
        &amp;lt;Provider store={store}&amp;gt;
            &amp;lt;App /&amp;gt;
        &amp;lt;/Provider&amp;gt;,
        rootEl
    );
};

if(module.hot) {
    // Support hot reloading of components
    // and display an overlay for runtime errors
    const renderApp = render;
    const renderError = (error) =&amp;gt; {
        const RedBox = require(&amp;quot;redbox-react&amp;quot;).default;
        ReactDOM.render(
            &amp;lt;RedBox error={error} /&amp;gt;,
            rootEl,
        );
    };

    // In development, we wrap the rendering function to catch errors,
    // and if something breaks, log the error and render it to the screen
    render = () =&amp;gt; {
        try {
            renderApp();
        }
        catch(error) {
            console.error(error);
            renderError(error);
        }
    };

    // Whenever the App component file or one of its dependencies
    // is changed, re-import the updated component and re-render it
    module.hot.accept(&amp;quot;./App&amp;quot;, () =&amp;gt; {
        setTimeout(render);
    });
}

render();
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;With this in place, editing one of our components (such as changing the text in &lt;code&gt;SampleComponent.jsx&lt;/code&gt;) should now just reload the component tree, rather than reloading the entire page.  If there&#39;s an error, we should see it displayed on the screen and logged in the console.  (To try it out, you can add &lt;code&gt;throw new Error(&amp;quot;Oops!&amp;quot;)&lt;/code&gt; to &lt;code&gt;SampleComponent.render()&lt;/code&gt; and see what happens.)&lt;/p&gt;

&lt;h3 id=&#34;reducer-hot-reloading&#34;&gt;Reducer Hot Reloading&lt;/h3&gt;

&lt;p&gt;Finally, we can also configure our project to hot-reload our reducers as well.  Right now, if we edit the initial state in our &lt;code&gt;testReducer.js&lt;/code&gt; from &lt;code&gt;data : 42&lt;/code&gt; to &lt;code&gt;data : 123&lt;/code&gt;, we&#39;ll see the whole page reload, just like it did for component edits before we added the hot reloading.  We need to listen for updates to the root reducer file, re-import it, and then replace the old reducer in the store with the new one.  The updated &lt;code&gt;configureStore.js&lt;/code&gt; looks like this:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek/blob/5f8ad093e4a856d0d32542226259524acfd7f22a/src/store/configureStore.js&#34;&gt;store/configureStore.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;import {createStore, applyMiddleware} from &amp;quot;redux&amp;quot;;
import { composeWithDevTools } from &#39;redux-devtools-extension/developmentOnly&#39;;

import thunk from &amp;quot;redux-thunk&amp;quot;;

import rootReducer from &amp;quot;../reducers/rootReducer&amp;quot;;

export default function configureStore(preloadedState) {
    const middlewares = [thunk];
    const middlewareEnhancer = applyMiddleware(...middlewares);

    const storeEnhancers = [middlewareEnhancer];
    
    const composedEnhancer = composeWithDevTools(...storeEnhancers);

    const store = createStore(
        rootReducer,
        preloadedState,
        composedEnhancer
    );

    if(process.env.NODE_ENV !== &amp;quot;production&amp;quot;) {
        if(module.hot) {
            module.hot.accept(&amp;quot;../reducers/rootReducer&amp;quot;, () =&amp;gt;{
                const newRootReducer = require(&amp;quot;../reducers/rootReducer&amp;quot;).default;
                store.replaceReducer(newRootReducer)
            });
        }
    }

    return store;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id=&#34;final-thoughts&#34;&gt;Final Thoughts&lt;/h2&gt;

&lt;p&gt;At this point, we know what kind of app we want to build, and have a decent idea what it should do and what it should look like (or at least enough of an idea to get us started).  We also have an initial project set up with our basic dependencies, and some nice tweaks to the development workflow.&lt;/p&gt;

&lt;p&gt;Next time, we&#39;ll at setting up some initial UI layout, and possibly tackle some of the initial data modeling as well.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If you&#39;ve got questions, comments, or suggestions, please let me know!&lt;/strong&gt;  Leave me a comment here, file an issue in the repo, or ping me on Twitter or Reactiflux.&lt;/p&gt;

&lt;h2 id=&#34;further-information&#34;&gt;Further Information&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/markerikson/project-minimek&#34;&gt;Project Mini-Mek repo&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/facebookincubator/create-react-app&#34;&gt;Create-React-App home&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Time travel debugging:

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://www.youtube.com/watch?v=xsSnOQynTHs&#34;&gt;Dan Abramov&#39;s original &amp;quot;Hot Reloading with Time Travel talk&amp;quot;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/gaearon/redux-devtools&#34;&gt;Redux DevTools repo&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/zalmoxisus/redux-devtools-extension&#34;&gt;Redux DevTools Extension repo&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/markerikson/react-redux-links/blob/master/redux-techniques.md#debugging&#34;&gt;React/Redux Links: Redux Techniques - Debugging&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/markerikson/redux-ecosystem-links/blob/master/devtools.md&#34;&gt;Redux Addons Catalog: Dev Tools&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Webpack Hot Module Replacement info

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://webpack.js.org/concepts/hot-module-replacement/&#34;&gt;Webpack docs: Concepts - Hot Module Replacement&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://webpack.js.org/guides/hot-module-replacement/&#34;&gt;Webpack docs: Guides - Hot Module Replacement&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://medium.com/@rajaraodv/webpack-hot-module-replacement-hmr-e756a726a07&#34;&gt;Webpack HMR: How It Works&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://ctheu.com/2015/12/29/webpack-hot-reloading-and-react-how/&#34;&gt;Webpack Hot Reloading and React&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/markerikson/react-redux-links/blob/master/webpack-advanced-techniques.md#hot-module-replacement&#34;&gt;React/Redux Links: Webpack Advanced Techniques - HMR&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;</description>
    </item>
    
  </channel>
</rss>