<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: peabody00</title>
    <description>The latest articles on Forem by peabody00 (@peabody00).</description>
    <link>https://forem.com/peabody00</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F519096%2Ff09d8ca1-557a-41b9-84dc-34cbc93364a6.jpeg</url>
      <title>Forem: peabody00</title>
      <link>https://forem.com/peabody00</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/peabody00"/>
    <language>en</language>
    <item>
      <title>React, Flatiron Mod 5 Project, Part 2</title>
      <dc:creator>peabody00</dc:creator>
      <pubDate>Tue, 07 Dec 2021 18:59:02 +0000</pubDate>
      <link>https://forem.com/peabody00/react-flatiron-mod-5-project-part-2-3mfn</link>
      <guid>https://forem.com/peabody00/react-flatiron-mod-5-project-part-2-3mfn</guid>
      <description>&lt;h3&gt;
  
  
  Where were we?
&lt;/h3&gt;

&lt;p&gt;In my last blog &lt;a href="https://dev.to/peabody00/react-flatiron-mod-5-project-part-1-3bp6"&gt;post&lt;/a&gt; I was trying to explain in my limited, beginner understanding how Redux works in React.  I had gone over how Redux takes the store out of the components and centralizes it.  This gives the ability to access the store from any component.&lt;/p&gt;

&lt;h3&gt;
  
  
  Now what?
&lt;/h3&gt;

&lt;p&gt;Having access to the state from anywhere is great and all but what about making changes to the state.  There needs to be ways to change the state based on user interactions.  This is where actions and reducers come in.&lt;/p&gt;

&lt;p&gt;One of the functions that comes with creating the store this way is &lt;code&gt;dispatch(action)&lt;/code&gt;.  Dispatching an action is the only way to trigger a change in the state.&lt;/p&gt;

&lt;p&gt;An action is simply just a JavaScript object with a property of &lt;code&gt;type&lt;/code&gt;.  Here is a very basic example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;increaseCount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;INCREASE_COUNT&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This action could be called something like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;increaseCount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Dispatch sends this action to the reducer to then alter the state.  A reducer is a function that takes an action and returns the new state.  The action describes what is happening and it is the reducer's job to return the new state based on the action.&lt;/p&gt;

&lt;p&gt;For the above example, a simple reducer might look like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;reducer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;INCREASE_COUNT&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="nl"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here the initial state is set as 0 and calling dispatch with &lt;code&gt;increaseCount&lt;/code&gt; as the argument tells the reducer to run the action type of &lt;code&gt;'INCREASE_COUNT'&lt;/code&gt;.  It then returns the new state which is the old state +1.&lt;/p&gt;

&lt;p&gt;The switch case format is a standard one that allows you to have other ways to alter the state.  The reducer knows which case to use by the action type given to it.&lt;/p&gt;

&lt;p&gt;This is obviously a very simple example and things can get really complicated quickly.  As a beginner though, I am trying to keep it simple to not confuse myself, much less others.&lt;/p&gt;

&lt;h3&gt;
  
  
  What about Thunk?
&lt;/h3&gt;

&lt;p&gt;Thunk is a middleware that can be used with our Redux store.  Thunk lets you call action creators that return a function instead of an action object. That function receives the store's dispatch method, which is then used to dispatch regular synchronous actions inside the function's body once the asynchronous operations have been completed (&lt;a href="https://www.digitalocean.com/community/tutorials/redux-redux-thunk"&gt;ref&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;The reason this is needed is for apps that need to communicate with an API or perform side effects.  In my project I have a an API to get movie data as a well as a Rails backend that saves information from my app.  For both of those I am making fetch calls to get information. Fetch is an asynchronous function so when Redux is running things synchronously you can run into issues.&lt;/p&gt;

&lt;p&gt;Thunk is a way to make sure that promise that fetch gives back gets resolved before continuing code execution.  Here is an example from my movie project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;fetchMovie&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;movie&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;apiURL&lt;/span&gt;&lt;span class="p"&gt;}${&lt;/span&gt;&lt;span class="nx"&gt;movie&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;?api_key=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;MY_API_KEY&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;resp&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;resp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;movie&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;SEARCH_MOVIES&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;movie&lt;/span&gt;&lt;span class="p"&gt;}));&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead of my action passing an object, I am returning a function that dispatches my &lt;code&gt;'SEARCH_MOVIES'&lt;/code&gt; action type with the payload of the movie information I got back from my fetch call.  That tells the reducer I have set up how to alter the state.  In this case I am making the movie in my store be the one that is was just searched.&lt;/p&gt;

&lt;p&gt;With all that information, we can now see the flow of how actions interact with the centralized state as well as seeing the need of middleware like Thunk to help as we use APIs to add more functionality to our web apps.&lt;/p&gt;

&lt;p&gt;I am not sure how helpful any of that is but I know I benefitted from getting the chance to spend more time going over the lessons I had about Redux as well as searching online for more information.&lt;/p&gt;

</description>
      <category>react</category>
      <category>flatironschool</category>
      <category>redux</category>
      <category>beginners</category>
    </item>
    <item>
      <title>React, Flatiron Mod 5 Project, Part 1</title>
      <dc:creator>peabody00</dc:creator>
      <pubDate>Mon, 06 Dec 2021 20:40:12 +0000</pubDate>
      <link>https://forem.com/peabody00/react-flatiron-mod-5-project-part-1-3bp6</link>
      <guid>https://forem.com/peabody00/react-flatiron-mod-5-project-part-1-3bp6</guid>
      <description>&lt;p&gt;Of the 5 modules for Flatiron School (Ruby, Sinatra, Rails, Javascript, and React), I think I have found this one the most difficult to wrap my head around.&lt;/p&gt;

&lt;p&gt;I can definitely see the benefits of React.  It's approach of focusing on clean user interfaces using components that are aware of state and able to re-render only the parts that are needed is very powerful.&lt;/p&gt;

&lt;p&gt;I found myself getting lost when, on top of learning all this stuff for React, they throw in Redux and Thunk as new concepts and code to learn about.&lt;/p&gt;

&lt;p&gt;In a lot of ways I feel like I am limping across the finish line as I come to the end of my time with Flatiron.&lt;/p&gt;

&lt;p&gt;Here is a link to my &lt;a href="https://github.com/peabody00/My-Movie-DB"&gt;project&lt;/a&gt; if you are interested.&lt;/p&gt;

&lt;h3&gt;
  
  
  Important Lessons
&lt;/h3&gt;

&lt;p&gt;Since I struggled so much with Redux and Thunk, I am splitting my blog post in two parts to go over each idea in the hopes that it will sink some of the concepts deeper into my mind.  Redux does make more sense to me than Thunk and hopefully I am able to explain it well enough.&lt;/p&gt;

&lt;h4&gt;
  
  
  Redux
&lt;/h4&gt;

&lt;p&gt;Redux seems to be about taking much of the logic out of the React components and moving it elsewhere so that the components can focus on presenting data and letting the user interact with the app.&lt;/p&gt;

&lt;p&gt;Redux moves the application's state out of the components to a central store of data.  This makes it so every component that needs access to the store data can get it more easily.&lt;/p&gt;

&lt;p&gt;This isn't going to be a tutorial about how to set up Redux.  There are plenty of those online.  I would recommend the Redux &lt;a href="https://redux.js.org/"&gt;documentation&lt;/a&gt; for in depth explanation of setup and ideas.  This is more about going over the main concepts of Redux.&lt;/p&gt;

&lt;p&gt;With that in mind, if the state is now outside of the components then it needs to exist.  Here is the code from my &lt;code&gt;index.js&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;ReactDOM&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-dom&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createStore&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;applyMiddleware&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;redux&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Provider&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-redux&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;thunk&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;redux-thunk&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;rootReducer&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./reducers/rootReducer&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;composeWithDevTools&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;redux-devtools-extension&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./index.css&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./App&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;BrowserRouter&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;Router&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-router-dom&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;



&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;store&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;createStore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rootReducer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;composeWithDevTools&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;applyMiddleware&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;thunk&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;


&lt;span class="nx"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Router&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Provider&lt;/span&gt; &lt;span class="na"&gt;store&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;store&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;App&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Provider&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Router&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;,&lt;/span&gt;
  &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The important parts here are the &lt;code&gt;createStore&lt;/code&gt; function, the &lt;code&gt;rootReducer&lt;/code&gt; file, and &lt;code&gt;&amp;lt;Provider&amp;gt;&lt;/code&gt; tags.  My variable &lt;code&gt;store&lt;/code&gt; is what is created when the function &lt;code&gt;createStore&lt;/code&gt; runs.  The &lt;code&gt;rootReducer&lt;/code&gt; file takes in my reducer functions which are responsible for returning the next state tree, given the current state tree and an action.  More on that later.&lt;/p&gt;

&lt;p&gt;The app now knows about the store and how the store gets changed based on actions.  What it needs is to make that store available to the components.  That's where the &lt;code&gt;&amp;lt;Provider&amp;gt;&lt;/code&gt; comes in.  By Wrapping the &lt;code&gt;&amp;lt;App /&amp;gt;&lt;/code&gt; component in the &lt;code&gt;&amp;lt;Provider&amp;gt;&lt;/code&gt; and giving it the &lt;code&gt;store&lt;/code&gt;, we give every child component of &lt;code&gt;&amp;lt;App /&amp;gt;&lt;/code&gt; the ability to access the store no matter where they fall in the hierarchy of components.&lt;/p&gt;

&lt;p&gt;To connect one of my components to the store, I can use something similar to this code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;connect&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-redux&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="p"&gt;...&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mapStateToprops&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;movie&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;movies&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mapStateToprops&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="nx"&gt;MovieCard&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This now adds everything that is in my store under &lt;code&gt;movies&lt;/code&gt; as props to my component with the key of &lt;code&gt;movie:&lt;/code&gt;.  So in this component I can now display the current state.  My project, where this code is from, searches an API to return movie data.  So in my component I can display things now like &lt;code&gt;{this.props.movie.title}&lt;/code&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Actions &amp;amp; Reducers
&lt;/h4&gt;

&lt;p&gt;That brings us to how we can change the store data.  I will save that explanation for part 2 where I can also talk about Thunk and how it works into all of this.&lt;/p&gt;

&lt;p&gt;Thanks for reading.&lt;/p&gt;

</description>
      <category>react</category>
      <category>flatironschool</category>
      <category>redux</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Javascript, MOD4 Project</title>
      <dc:creator>peabody00</dc:creator>
      <pubDate>Fri, 24 Sep 2021 17:04:14 +0000</pubDate>
      <link>https://forem.com/peabody00/javascript-mod4-project-kmn</link>
      <guid>https://forem.com/peabody00/javascript-mod4-project-kmn</guid>
      <description>&lt;p&gt;This module has been a roller coaster ride.  I enjoyed many parts of Javascript and can see the lessons I learned all throughout the modern Internet.&lt;/p&gt;

&lt;p&gt;As I approached my project for this module I wanted to do something that I was excited about and lined up with my interests.  So I chose to make a simple pixel art web app.  As simple as it sounded in my head it turned out to be much more difficult to create.&lt;/p&gt;

&lt;p&gt;I learned a great deal making this project but I wanted to focus on one important lesson I learned.&lt;/p&gt;

&lt;p&gt;Here is a link to my &lt;a href="https://github.com/peabody00/PixelFun"&gt;project&lt;/a&gt; if you are interested.&lt;/p&gt;

&lt;h3&gt;
  
  
  Important Lesson
&lt;/h3&gt;

&lt;p&gt;One of the big lessons I learned is when I tried to create a drawing tool that is pretty standard in any drawing app.  It is the flood fill tool.  The idea is to click inside an enclosed area and have it fill with the selected color.&lt;/p&gt;

&lt;p&gt;This lead me to the concept of &lt;strong&gt;Recursion&lt;/strong&gt;.  In the most basic sense, recursion is a function that calls on itself until a condition is met.  Once that condition is met the function stops running.  Here is an example (the information that follows comes from &lt;a href="https://javascript.info/recursion"&gt;javascript.info&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Here is the recursive function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;pow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;pow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;pow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 8&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This function takes x and multiplies itself n times or x to the power of n.  It does this by first checking if &lt;code&gt;n == 1&lt;/code&gt;.  If it does, it just returns the number x because a number to the power of 1 is just the number.  If n does not equal 1 then it returns &lt;code&gt;x * pow(x,n-1)&lt;/code&gt;.  It keeps calling this function until &lt;code&gt;n == 1&lt;/code&gt; and then returns the final value.&lt;/p&gt;

&lt;p&gt;There is obviously much more to it.  But this is about the level of my beginner brain.  For a more in-depth explanation please visit this &lt;a href="https://javascript.info/recursion"&gt;page&lt;/a&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  How does this relate to my tool?
&lt;/h4&gt;

&lt;p&gt;My implementation of a pixel art app uses table cells and changes their background color.  For the flood fill to work I need to check what the value of the background color is to cells adjacent to where I click.  If their background color doesn't match my current color, it changes the color and moves on to the next cell.  Sounds like a good case for recursion.  Here is the code I used (Not all my code.  A lot of research went into it).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;fillBucket&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;sc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;newColor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;targetColor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;sr&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;sr&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;cells&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;sc&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sr&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sc&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sr&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;gridHeight&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sc&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;gridWidth&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;sr&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;cells&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;sc&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;backgroundColor&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;targetColor&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;backgroundColor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;newColor&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nx"&gt;fillBucket&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sr&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;sc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;newColor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;targetColor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;fillBucket&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sr&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;sc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;newColor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;targetColor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;fillBucket&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;sc&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;newColor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;targetColor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;fillBucket&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;sc&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;newColor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;targetColor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It basically checks the 4 cells around where the user clicks (up, down, left, right) and changes the color if it doesn't match.  This is a slow method of accomplishing this.  It requires a lot of checks.  So if the area to fill is big, it can slow down.  There are other recursive methods that can do this more quickly but I was already swimming in deep waters and didn't want to confuse myself more.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;It was difficult to get this working but it did teach me an important principal and gave me more depth as a programmer.  It certainly helped me appreciate the thought that goes into programming a seemingly simple feature.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>flatironschool</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Ruby on Rails, Flatiron Mod3 Project</title>
      <dc:creator>peabody00</dc:creator>
      <pubDate>Wed, 12 May 2021 01:08:57 +0000</pubDate>
      <link>https://forem.com/peabody00/ruby-on-rails-flatiron-mod3-project-2fhe</link>
      <guid>https://forem.com/peabody00/ruby-on-rails-flatiron-mod3-project-2fhe</guid>
      <description>&lt;h2&gt;
  
  
  Ruby on Rails
&lt;/h2&gt;

&lt;p&gt;Module 3 for Flatiron School builds on the previous lessons of Sinatra and ActiveRecord.  &lt;/p&gt;

&lt;h3&gt;
  
  
  Project Idea
&lt;/h3&gt;

&lt;p&gt;I decided to do a simple college website for my project.  I call it Chesapeake Clown College.  The idea is that two types of users (teachers and students) can log into the website and manage different things.  A teacher login can create new courses and activities for the student.  The student login can look at the courses and assign them to their schedule.  They can also join different activities.  &lt;/p&gt;

&lt;p&gt;Here is a link to the &lt;a href="https://github.com/peabody00/clown-college"&gt;project&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Important Lesson
&lt;/h3&gt;

&lt;p&gt;I think one of the biggest lessons I got from this module involves how Rails makes routing much easier.  With Sinatra the routes had to be explicitly stated in the controllers for things to run properly.  Rails simplifies this by declaring all the routes in a file called &lt;code&gt;routes.rb&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The routes can be described in several different ways in this file but the easiest way is to simply declare resources for the different models.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Rails&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;application&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;routes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;draw&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="n"&gt;get&lt;/span&gt; &lt;span class="s1"&gt;'/login'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'sessions#new'&lt;/span&gt;
  &lt;span class="n"&gt;post&lt;/span&gt; &lt;span class="s1"&gt;'/login'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'sessions#create'&lt;/span&gt;
  &lt;span class="n"&gt;get&lt;/span&gt; &lt;span class="s1"&gt;'/teacherlogin'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'sessions#teacher_new'&lt;/span&gt;
  &lt;span class="n"&gt;post&lt;/span&gt; &lt;span class="s1"&gt;'/teacherlogin'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'sessions#teacher_create'&lt;/span&gt;
  &lt;span class="n"&gt;post&lt;/span&gt; &lt;span class="s1"&gt;'/logout'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'sessions#destroy'&lt;/span&gt;
  &lt;span class="n"&gt;get&lt;/span&gt; &lt;span class="s1"&gt;'/auth/:provider/callback'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'sessions#omniauth'&lt;/span&gt;
  &lt;span class="n"&gt;root&lt;/span&gt; &lt;span class="s1"&gt;'welcome#index'&lt;/span&gt;
  &lt;span class="n"&gt;resources&lt;/span&gt; &lt;span class="ss"&gt;:activities&lt;/span&gt;
  &lt;span class="n"&gt;resources&lt;/span&gt; &lt;span class="ss"&gt;:courses&lt;/span&gt;
  &lt;span class="n"&gt;resources&lt;/span&gt; &lt;span class="ss"&gt;:schedules&lt;/span&gt;
  &lt;span class="n"&gt;resources&lt;/span&gt; &lt;span class="ss"&gt;:students_activities&lt;/span&gt;
  &lt;span class="n"&gt;resources&lt;/span&gt; &lt;span class="ss"&gt;:teachers&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="n"&gt;resources&lt;/span&gt; &lt;span class="ss"&gt;:courses&lt;/span&gt;
    &lt;span class="n"&gt;resources&lt;/span&gt; &lt;span class="ss"&gt;:activities&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
  &lt;span class="n"&gt;resources&lt;/span&gt; &lt;span class="ss"&gt;:students&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="n"&gt;resources&lt;/span&gt; &lt;span class="ss"&gt;:schedules&lt;/span&gt;
    &lt;span class="n"&gt;resources&lt;/span&gt; &lt;span class="ss"&gt;:students_activities&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
  &lt;span class="n"&gt;resources&lt;/span&gt; &lt;span class="ss"&gt;:sessions&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the code for the &lt;code&gt;routes.rb&lt;/code&gt; from my project.  I don't know if it's perfectly correct but it works in my project.&lt;/p&gt;

&lt;p&gt;The advantage of declaring routes this way is that &lt;code&gt;resources :activities&lt;/code&gt; allows Rails to know the routes for the Activities controller automatically.&lt;/p&gt;

&lt;p&gt;Running &lt;code&gt;rails routes&lt;/code&gt; gives us this result for Activities.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;       Prefix Verb   URI Pattern                          Controller#Action
   activities GET    /activities(.:format)                activities#index
              POST   /activities(.:format)                activities#create
 new_activity GET    /activities/new(.:format)            activities#new
edit_activity GET    /activities/:id/edit(.:format)       activities#edit
     activity GET    /activities/:id(.:format)            activities#show
              PATCH  /activities/:id(.:format)            activities#update
              PUT    /activities/:id(.:format)            activities#update
              DELETE /activities/:id(.:format)            activities#destroy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With just the simple declaration of &lt;code&gt;resources :activities&lt;/code&gt; all RESTful CRUD routes are created for me.&lt;/p&gt;

&lt;p&gt;This also creates helper methods that can be used in my code.  If I need to link a route I just take the prefix from above and add &lt;code&gt;_path&lt;/code&gt; to it to create a link. &lt;code&gt;activities_path&lt;/code&gt; will take me to the INDEX route for activities.  It is a simple yet elegant way to manage routing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Rails works magic in so many different areas but the routes are one area that it really shined for me.  As overwhelming as this module was, I feel I came away from it with some good lessons.&lt;/p&gt;

</description>
      <category>rails</category>
      <category>ruby</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Module 2 Sinatra Project for Flatiron School</title>
      <dc:creator>peabody00</dc:creator>
      <pubDate>Mon, 08 Mar 2021 00:51:00 +0000</pubDate>
      <link>https://forem.com/peabody00/module-2-sinatra-project-for-flatiron-school-24n9</link>
      <guid>https://forem.com/peabody00/module-2-sinatra-project-for-flatiron-school-24n9</guid>
      <description>&lt;h2&gt;
  
  
  Sinatra Project
&lt;/h2&gt;

&lt;p&gt;This module has been a much different experience than the last one.  In this module there were so many more concepts that we learned that I felt much more uncertain of what I was learning.  The project has helped deepen my understanding of the concepts but I still feel like I am just barely scratching the surface.  Luckily I have a few individuals that I rely on for support both technical and emotional &lt;em&gt;(Thanks Evelyn and Jenny)&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Here is a link to my &lt;a href="https://github.com/peabody00/LifeTCG"&gt;project&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Project Idea
&lt;/h3&gt;

&lt;p&gt;I struggled a lot more this time with my project idea.  It changed a few times as I thought more about what was required of me and what I thought I could accomplish.&lt;/p&gt;

&lt;p&gt;I finally settled on creating a simple trading card game.  The basic idea is to collect cards to increase your Life score compared to other players.  The interface allows a player to view their collection and open new card packs.  There is a messaging area where players can post messages on a wall for all to see.  A player can always edit and delete their own posts.  There was a planned trading card feature that requires more work that I will talk about later.&lt;/p&gt;

&lt;h3&gt;
  
  
  Important Lessons
&lt;/h3&gt;

&lt;p&gt;I learned many concepts while making this project but the biggest lesson came from ActiveRecord associations.  I used some of the simpler associations during the course but learned about many other ways that ActiveRecord can associate models.  My project uses 5 models &lt;code&gt;User&lt;/code&gt;, &lt;code&gt;Card&lt;/code&gt;, &lt;code&gt;Post&lt;/code&gt;, &lt;code&gt;UserCard&lt;/code&gt;, and &lt;code&gt;Trade&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Some associations were simple. A user has many posts, a post belongs to a user.  Others got more complicated, a user has many cards and cards have many users.  A usercard model was needed to join the other models so a usercard belongs to both users and cards.&lt;/p&gt;

&lt;p&gt;As I thought through the unfinished trading feature the association became more complicated and unfamiliar.  The way I tried to implement it was suggested by a coding partner.  It involved using an alias and a foreign key to help identify both users and both cards in a trade.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Card &amp;lt; ActiveRecord::Base
    has_many :user_cards
    has_many :trades
    has_many :trades, :foreign_key =&amp;gt; "other_card_id"
    has_many :users, through: :user_cards
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Trade &amp;lt; ActiveRecord::Base
    belongs_to :user
    belongs_to :other_user, :class_name =&amp;gt; "User"
    belongs_to :card
    belongs_to :other_card, :class_name =&amp;gt; "Card"
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However the more I thought about it that didn't seem to be the right relationship. It occurred to be that a users collection of cards existed in the &lt;code&gt;usercards&lt;/code&gt; table of the database.  If that is the case then a trade needed a belongs to, through relationship.  That doesn't seem supported in Sinatra as I researched it.  There is a has one relationship that I need to research more but time was running out for my project.&lt;/p&gt;

&lt;p&gt;I ended up making sure the features I had in program met all the requirements so I could turn that in.  My plan is to work more on a trade feature before my project review.&lt;/p&gt;

&lt;h3&gt;
  
  
  Final Thoughts
&lt;/h3&gt;

&lt;p&gt;I understand how things are building as I progress through my Flatiron Software Engineering course.  Sometimes it is hard as we learn the fundamentals knowing that later tools will make doing what we are doing now easier.  For now I will do my best to learn the material and enjoy the ride.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>ruby</category>
      <category>sinatra</category>
      <category>activerecord</category>
    </item>
    <item>
      <title>CLI Project for Flatiron School</title>
      <dc:creator>peabody00</dc:creator>
      <pubDate>Sun, 10 Jan 2021 23:05:32 +0000</pubDate>
      <link>https://forem.com/peabody00/cli-project-for-flatiron-school-1049</link>
      <guid>https://forem.com/peabody00/cli-project-for-flatiron-school-1049</guid>
      <description>&lt;h3&gt;
  
  
  Module 1 Project
&lt;/h3&gt;

&lt;p&gt;As I have been working these past two months through the Flatiron Software Engineering program, I barely had time to consider anything else aside from the daily labs and instruction I was receiving.  It seemed like everything was about getting a lab to run properly so there were no failures. That took trying to decipher what was being asked of me (which sometimes wasn't very clear).&lt;/p&gt;

&lt;p&gt;As I have approached my Module 1 project, things changed when I was writing code.  I was solving my own problems and it made me feel different about my code.  It gave me the freedom to solve problems in my way, not necessarily the way a lab was asking me to.  It was a good feeling.&lt;/p&gt;

&lt;h3&gt;
  
  
  Project Idea
&lt;/h3&gt;

&lt;p&gt;When I was considering what I should do for my project I went through several ideas.  I was watching videos showing projects being made and I was reading ideas about what a project might entail.  The idea that I settled on is a Mad Lib Creator &amp;amp; Dictionary.&lt;/p&gt;

&lt;p&gt;In my mind, this seemed like a fun idea but one that would challenge my limited coding knowledge.&lt;/p&gt;

&lt;h3&gt;
  
  
  Big Lesson
&lt;/h3&gt;

&lt;p&gt;The first challenge I had to overcome was just getting started.  The blank screen can be very intimidating.  One thing that helped me was a &lt;a href="https://youtu.be/_lDExWIhYKI"&gt;video&lt;/a&gt; from Avi Flombaum, one of Flatiron's founders.  In it he described how to create a Ruby Gem.  In that video he said we wanted to "write the code I wish I had." He said this many times and I took that to heart.&lt;/p&gt;

&lt;p&gt;I started with the file I wanted people to use to run my CLI program.  &lt;code&gt;./bin/madlib&lt;/code&gt; started very basic with &lt;code&gt;puts "Hello World"&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;From there I stepped through each part of the program and created things as I needed.  I was always able to test things as I went because I started with the first thing a user would use.  In this way my framework for my program was built from the ground up.  It was able to support where I wanted to eventually get to with my program because I laid the groundwork for it in the beginning.&lt;/p&gt;

&lt;h3&gt;
  
  
  Overview
&lt;/h3&gt;

&lt;p&gt;My program ended up with 5 classes of objects CLI, API, and a class for each of my Mad Libs.  Each class was responsible for a different portion of my program.  The CLI class is the menu that guides the user around my program.  The API class was how my program interacted with the dictionary API that I used to find and validate words and the 3 Mad Lib classes are the individual Mad Libs that were created for users to interact with.&lt;/p&gt;

&lt;h3&gt;
  
  
  Other Big Lesson
&lt;/h3&gt;

&lt;p&gt;The other big issue that I had to work through came when I was trying to interpret the data I was receiving from my API.  The API was helpful in that it gave me Ruby code to help create my connection.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;url = URI("https://wordsapiv1.p.rapidapi.com/words/word)

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Get.new(url)
request["x-rapidapi-key"] = API_KEY
request["x-rapidapi-host"] = 'wordsapiv1.p.rapidapi.com'

response = http.request(request)
puts response.read_body
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The &lt;code&gt;puts response.read_body&lt;/code&gt; looked like a hash but wouldn't work like a hash.  It didn't click until I was looking through some notes and remembered that the API data came in as JSON and needed to be parsed by Ruby.  Once that clicked, working with my API became much easier.  Another big help with that was the Ruby gem &lt;a href="https://rubygems.org/gems/awesome_print/versions/1.8.0"&gt;Awesome Print&lt;/a&gt;.  Making my objects more readable was a big step towards seeing the data that I needed to pull out from my API calls.&lt;/p&gt;

&lt;h3&gt;
  
  
  Favorite Feature
&lt;/h3&gt;

&lt;p&gt;One of my favorite features of my program involves a validation I created for the words that users can type into the Mad Libs.  I wanted to make sure if the program asked the user for a noun that the word the user typed in had to be a noun.  It took several steps and versions but this is the code I created.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def valid_partofspeech?
    if @word.include? " "
        false
    else
        @url_combined = URI(URL + @word + "/definitions")
        self.connection(url_combined)

        part_array = []
        if @word_hash["success"] == false
            false
        else
            word_hash["definitions"].each do |def_hash|
                def_hash.each do |var1, var2|
                    if var1 == "partOfSpeech"
                    part_array &amp;lt;&amp;lt; var2
                    end
                end
            end
        end
        part_array.include?(part_of_speech)
    end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The first part of the validation, &lt;code&gt;if @word.include? " "&lt;/code&gt; checked if the user had a space in the word they typed.  If that happened then the validation returned &lt;code&gt;false&lt;/code&gt;.  The next step took the users input (which is created in the Mad Lib class) and made sure the API call was successful, &lt;code&gt;if @word_hash["success"] == false&lt;/code&gt;.  If the user misspelled a word or typed in gibberish the API endpoint "success" would be &lt;code&gt;false&lt;/code&gt;.  If that happened then my the validation would return &lt;code&gt;false&lt;/code&gt;.  Finally if all the user's input worked past those validations the API would look up the user's word, take out the "partOfSpeech" endpoint and put it in an array, and then check that the part of speech the the Mad Lib needed was included in the array that held all the parts of speech.&lt;/p&gt;

&lt;p&gt;In that way, I could be sure that one of the definitions of the the user's word matched the part of speech needed by the Mad Lib.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;This whole project ended up as a big boost to my confidence when it came to coding.  Doing the labs and the classwork always made me feel like I was behind or not understanding the topics we were going over.  Having completed my Module 1 project though has shown me that the lessons have sunk in and that even if I do run into a problem I can do the research and figure out what I need to do.  I am grateful to my instructor and the others that have helped me through this first section of my course.  &lt;/p&gt;

</description>
      <category>flatiron</category>
      <category>cli</category>
      <category>ruby</category>
    </item>
    <item>
      <title>Why did I decide to study Software Engineering?</title>
      <dc:creator>peabody00</dc:creator>
      <pubDate>Mon, 23 Nov 2020 02:24:51 +0000</pubDate>
      <link>https://forem.com/peabody00/why-did-i-decide-to-study-software-engineering-48jk</link>
      <guid>https://forem.com/peabody00/why-did-i-decide-to-study-software-engineering-48jk</guid>
      <description>&lt;p&gt;:001 &amp;gt; puts "Hello World!"&lt;br&gt;
&lt;strong&gt;Hello World!&lt;/strong&gt;&lt;br&gt;
 =&amp;gt; nil&lt;/p&gt;

&lt;p&gt;I recently joined Flatiron School in their Software Engineering program.  The first two weeks of the course are called the First Mile.  As part of that I was tasked with writing a blog post to answer the question above.&lt;/p&gt;

&lt;p&gt;As I think back to where my journey with coding first started, I go back to Christmas of 1984.  I was almost 6 years old and my family got a Vic20 as a present.&lt;/p&gt;

&lt;p&gt;I remember being excited to have such a cool and wonderful piece of technology available to me.  I remember opening the manual and finding instructions on writing small programs in BASIC.  I would work slowing typing those instructions into the interface.  Often I would have something off in my syntax and have to re-type everything and hope I got it right.  If I did I was rewarded with a sound or some colors and it was an exciting feeling for a six year old.&lt;/p&gt;

&lt;p&gt;Since then I have been interested in technology in many different ways.  I never got much deeper into coding but I was into computers and the internet and everything tech related.&lt;/p&gt;

&lt;p&gt;Over the years I tried to get into coding with various levels of success.  Coding always seemed to me like magical powers and the people who could use it like wizards.  It was mysterious and the wizards had their own language to keep away outsiders.  I wanted that power but never really had the time while working and having a wife and kids.&lt;/p&gt;

&lt;p&gt;It finally got to the point where I was offered an opportunity by some family to really throw myself into it.  I decided it was time.  &lt;/p&gt;

&lt;p&gt;These past two weeks have been a roller coaster.  I felt confident in the first week and felt like I was understanding what was presented.  In the second week there were some hard days where I was asking myself "WHY did I decide to study software engineering?"&lt;/p&gt;

&lt;p&gt;The breakthroughs and successes have carried me through.  I still know there is so much to learn and I know it will be complex and hard at times.  I feel like with the support of my family and my online classmates that I can do this.&lt;/p&gt;

&lt;p&gt;Thanks for reading.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>flatiron</category>
    </item>
  </channel>
</rss>
