<?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: Marc West</title>
    <description>The latest articles on Forem by Marc West (@marcdwest32).</description>
    <link>https://forem.com/marcdwest32</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%2F206938%2F021ea315-97d4-4fa7-a346-c8bd068cf8d4.jpeg</url>
      <title>Forem: Marc West</title>
      <link>https://forem.com/marcdwest32</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/marcdwest32"/>
    <language>en</language>
    <item>
      <title>Ruby on Rails</title>
      <dc:creator>Marc West</dc:creator>
      <pubDate>Mon, 10 Feb 2020 08:42:21 +0000</pubDate>
      <link>https://forem.com/marcdwest32/ruby-on-rails-4fie</link>
      <guid>https://forem.com/marcdwest32/ruby-on-rails-4fie</guid>
      <description>&lt;p&gt;Ruby is an object-oriented, coding language first released in 1995 by Yukiro Matsumoto. It was specially designed with a focus on productivity and simplicity. Some of its major selling points are that Ruby does not take long to learn, and it is open source so it can be modified according to the user’s specific needs. Although it was largely developed on Linux, it functions across all platforms, including Mac OS and Windows.&lt;/p&gt;

&lt;p&gt;Built on the Ruby programming language, Ruby on Rails is a web framework that comes with everything you need to complete a website project out of the box - including the ability to manage logic and routing and handle applications. These useful tools also include database integration and controllers which makes it easier to integrate web development from front to back. &lt;/p&gt;

&lt;p&gt;To get started with a rails application, you first need to install Ruby and Rails. After a lot of searching I came across &lt;a href="https://gorails.com/setup/ubuntu/19.10"&gt;this article&lt;/a&gt; which seemed to have all the steps I needed to get them running on Linux Mint 19.3. Once installed you can run the command &lt;code&gt;rails new [app name]&lt;/code&gt; to generate a new application with all the files needed to get started including the &lt;code&gt;Gemfile&lt;/code&gt;. The Gemfile is much like Node.js' package.json, and similarly it also has an install command which needs to be run, &lt;code&gt;bundle install&lt;/code&gt;, to download dependencies. After that enter in &lt;code&gt;rails s&lt;/code&gt; or &lt;code&gt;rails server&lt;/code&gt; to run the built-in development server and you will be greeted in localhost:3000&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fJgUGfKW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/4xjwk2p2a7kqs7s79p2n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fJgUGfKW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/4xjwk2p2a7kqs7s79p2n.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A controller handles communication between models and views. It makes the model data available to the view so it can display that data to the user, and it saves or updates user data to the model. A controller is a Ruby class which inherits from &lt;code&gt;ApplicationController&lt;/code&gt; and has methods just like any other class. When your application receives a request, the routing will determine which controller and action to run, then Rails creates an instance of that controller and runs the method with the same name as the action. To create a controller enter &lt;code&gt;rails generate controller [ControllerName]&lt;/code&gt;. This will generate a controller file, helper file, and view folder for your controller as well as a few other helpful files like stylesheets. Functions in Ruby are declared with &lt;code&gt;def&lt;/code&gt; followed by the function name and closed off with &lt;code&gt;end&lt;/code&gt;. This function will determine what data is relayed to the &lt;code&gt;about.html.erb&lt;/code&gt; page. &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--P9cgrHs7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1i686cl49uslgcjvha9l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--P9cgrHs7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1i686cl49uslgcjvha9l.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The information on the view is dynamically bound to the variables &lt;code&gt;@title&lt;/code&gt; and &lt;code&gt;@content&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h1&amp;gt;&amp;lt;%= @title %&amp;gt;&amp;lt;/h1&amp;gt;
&amp;lt;p&amp;gt;&amp;lt;%= @content %&amp;gt;&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;about.html.erb&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;To produce the &lt;code&gt;about&lt;/code&gt; route go to &lt;code&gt;routes.rb&lt;/code&gt; inside the &lt;code&gt;config&lt;/code&gt; file. In there we need to make a get request to get the pages controller at the about view. That can be achieved with this syntax &lt;code&gt;get 'about' =&amp;gt; 'pages#about', as: 'about'&lt;/code&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wm6PFWI2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/psytlt0k3yipdkgn9jrt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wm6PFWI2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/psytlt0k3yipdkgn9jrt.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
The final product will look like this&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---5z7sH_Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/br96pbrwehinoefapoih.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---5z7sH_Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/br96pbrwehinoefapoih.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To create a model you can run &lt;code&gt;rails g [Model]&lt;/code&gt;. This will create a model and also a migration file located in &lt;code&gt;db/migrate&lt;/code&gt;. Run the migration file by entering &lt;code&gt;rake db:migrate&lt;/code&gt; in the cli. The migrate file will be the template, in this example a post, of what will be saved to the database by the model. &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rQX17flu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ggthkdc5o79jouejld3f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rQX17flu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ggthkdc5o79jouejld3f.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>React Native Modals</title>
      <dc:creator>Marc West</dc:creator>
      <pubDate>Mon, 03 Feb 2020 14:17:30 +0000</pubDate>
      <link>https://forem.com/marcdwest32/react-native-modals-d84</link>
      <guid>https://forem.com/marcdwest32/react-native-modals-d84</guid>
      <description>&lt;p&gt;When you first start making a React Native application, you naturally set out to create components and pages like you would in a regular React.JS app. This will work for a while when you're making and testing your components, but what about when you need those components to interact with or display on top of a screen or another component? Can you just place those components inside JSX elements and render them like in React.JS? Unfortunately, the answer is no. You have to do a little bit more to get the elements to interact the way you want them to in native applications. That's where modals come in. The Modal component is a basic way to present content above an enclosing view. There's a couple of different options when it comes to modals, but I went with &lt;code&gt;react-native-modals&lt;/code&gt; when designing my application. In order to use the Modal component you will need to install the package -&lt;br&gt;
&lt;code&gt;npm install --save react-native-modals&lt;br&gt;
OR&lt;br&gt;
yarn add react-native-modals&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;So the only thing you really need to do to turn a normal component into a modal is to make it to where that component can be toggled in and out of view. For my first attempt at this I took the difficult path and built the entire modal into the component I wanted it to render on top of. This proved to be difficult, but not impossible. Because I was unfamiliar with the technology and not sure it would actually work, I imported the Modal tag in and began to fiddle around with it inside the component. This took several hours of trial and error; trying to shift the Modal tags up and down and screwing around with CSS until it finally resembled a working screen. The end result code-wise is kind of ugly to look at and takes up too many lines &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XEmbE43b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1b4deg7cytorate3pvdb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XEmbE43b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1b4deg7cytorate3pvdb.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I don't recommend doing this. It's overly complicated, especially when using the modal for the first time, and it kind of flies in the face of modular component structure. The good news however is that it does work.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9xmhIPt6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/muqpe4gwnpao16enmj18.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9xmhIPt6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/muqpe4gwnpao16enmj18.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;My second approach to this problem was initiated much like the first. I wanted to jump in as quickly as possible and make something work because of an unreasonable deadline, which led to me trying to do the simplest thing I could think of: just stick my already built component that I wanted to be a modal in the screen I wanted it to display on wrapped in some &lt;code&gt;Modal&lt;/code&gt; tags. Genius. This idea worked pretty much instantly, and I was able to get it to behave the way I wanted with much less tinkering than my previous exploit. To toggle the modal off I simply placed the toggle switch in the &lt;code&gt;Modal&lt;/code&gt; tag's &lt;code&gt;onBackButtonPress&lt;/code&gt; method, and it is toggled on by pressing the card title in the top level component.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1tZFboQT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/huz79m85y4zhpt8ygwcy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1tZFboQT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/huz79m85y4zhpt8ygwcy.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The resulting modal looks and behaves exactly how I wanted it.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fag_Njdc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/a1l8e92z90fyq8bduf35.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fag_Njdc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/a1l8e92z90fyq8bduf35.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Basically what I learned is that you can make any component display and behave as a modal simply by encapsulating the code, or a previously constructed component, inside &lt;code&gt;Modal&lt;/code&gt; tags. You can make this as complicated as you want, but the main takeaway is to stick to the basics of React. Keep your code modular and separated, and it will be easier to implement scary new technologies. &lt;/p&gt;

</description>
      <category>react</category>
      <category>reactnative</category>
      <category>codenewbie</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Making a Map for Your Native App</title>
      <dc:creator>Marc West</dc:creator>
      <pubDate>Thu, 30 Jan 2020 08:28:48 +0000</pubDate>
      <link>https://forem.com/marcdwest32/making-a-map-for-your-native-app-m9g</link>
      <guid>https://forem.com/marcdwest32/making-a-map-for-your-native-app-m9g</guid>
      <description>&lt;p&gt;Making a React Native app turned out to be much more difficult than I originally thought it would be, so I figured I would share some of what I learned and try to save you from some of the hellish nightmares I experienced when working with these poorly documented technologies. Unfortunately, almost every mobile app needs a map feature because these danged millennials nowadays don't know where anything is located anymore. Back in my day we used a real map or printed out directions from Map Quest, or we just got lost. And we were grateful dag-nabbit! Anyway, enough nonsense, let's get started.&lt;/p&gt;

&lt;p&gt;First you're going to want to install Expo. Expo is a framework and a platform for universal React applications. It is a set of tools and services built around React Native and native platforms that help you develop, build, and deploy on iOS and Android. If Expo really makes building a mobile app easier I seriously do not want to know what the more difficult option is like. Go ahead and install Expo globally and init a new project.&lt;br&gt;
&lt;code&gt;# Install the command line tools&lt;br&gt;
npm install --global expo-cli&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;# Create a new project&lt;br&gt;
expo init my-map-app&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now you're probably going to need to install Watchman also. Watchman exists to watch files and record when they change. That sounds important, even though I'm not really sure what it means. Expo recommends using it if you're running on iOS, but I was running on Android and still had to download it, so just get it. The cli commands are as follows - &lt;br&gt;
&lt;code&gt;$ cd ~&lt;br&gt;
$ git clone https://github.com/facebook/watchman.git&lt;br&gt;
$ cd watchman/&lt;br&gt;
$ git checkout v4.9.0&lt;br&gt;
$ sudo apt-get install -y autoconf automake build-essential python-dev&lt;br&gt;
$ sudo apt-get install libtool&lt;br&gt;
$ ./autogen.sh &lt;br&gt;
$ ./configure &lt;br&gt;
$ make&lt;br&gt;
$ sudo make install&lt;br&gt;
$ watchman --version&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Almost started. Fantastic. Open up your new app in your favorite code editor, and let's get that map in there. From the cli run &lt;code&gt;npm install react-native-maps --save-exact&lt;/code&gt; or &lt;code&gt;yarn add react-native-maps -E&lt;/code&gt; if you're into that kind of thing. You now have everything you need to get a map on a phone screen. Sweet. This next step is kind of iffy, because who really knows if we need all this stuff? I don't, Expo doesn't, React sure doesn't - or at least they're not telling us. So wing it we shall! Follow my lead and import all this stuff - &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fegr09qz62k7zqhtmzdcy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fegr09qz62k7zqhtmzdcy.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You'll probably want your map app to know where you are, and for that it will need your permission to get your location. Luckily, Expo actually documents how to do that here (&lt;a href="https://docs.expo.io/versions/latest/sdk/permissions/" rel="noopener noreferrer"&gt;https://docs.expo.io/versions/latest/sdk/permissions/&lt;/a&gt;). &lt;br&gt;
But who wants to read docs??? Here's the code - &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Flfek027pg20iddzm09k2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Flfek027pg20iddzm09k2.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;BTW this example takes place solely in App.js, so don't be bouncing around all confused about where to put stuff. You'll only need to keep track of location and loading for this app, so just two simple useState() calls will do it for you -&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ff814qz6ljndxbunlf4t1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ff814qz6ljndxbunlf4t1.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
And you also need a couple functions to handle loading and errors -&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fzxk03jgcifs9ykzjycqb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fzxk03jgcifs9ykzjycqb.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Alright let's wrap this up. Expo has a handy-dandy component called &lt;code&gt;AppLoading&lt;/code&gt; that hides away the rest of the app while it loads the needed resources with &lt;code&gt;startAsync&lt;/code&gt;, and after the resources have loaded it can perform a function with &lt;code&gt;onFinish&lt;/code&gt; to get the app started. You'll want to pass the previously mentioned &lt;code&gt;getLocationAsync&lt;/code&gt; to &lt;code&gt;onFinish&lt;/code&gt; here, and use the location to set your state. It'll look like this - &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1ofybgx1k1yofn09vti9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1ofybgx1k1yofn09vti9.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you have the location you can render your map. You need to put the &lt;code&gt;MapView&lt;/code&gt; component inside a &lt;code&gt;ScrollView&lt;/code&gt; component and possibly inside a &lt;code&gt;SafeAreaView&lt;/code&gt; component. It's an inexact science to say the least, but that's what I had to do.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fnvac646qqiuutfvtknjs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fnvac646qqiuutfvtknjs.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you can't get the location to come out right, don't worry, it's not you, React Native Maps hates everyone equally. Just mess around with it for a while and eventually you'll get what you need. The object that &lt;code&gt;initialRegion&lt;/code&gt; is looking for is built like this -&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F8m961q65qfpdkjqtkk9e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F8m961q65qfpdkjqtkk9e.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So there you have it. A mobile app map. There's a lot of other stuff you can do with your map, but you'll obviously want to look elsewhere for advice. I'm currently trying to render a scrollable list of messages over mine, so if you have any good ideas let me know.&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>codenewbie</category>
      <category>expo</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Intro to Redux in React</title>
      <dc:creator>Marc West</dc:creator>
      <pubDate>Mon, 20 Jan 2020 05:50:16 +0000</pubDate>
      <link>https://forem.com/marcdwest32/intro-to-redux-in-react-54pg</link>
      <guid>https://forem.com/marcdwest32/intro-to-redux-in-react-54pg</guid>
      <description>&lt;p&gt;Redux is a JavaScript library used to manage the state of an application. It is very popular and is commonly used in React applications, although it can also be used with other libraries such as AngularJS, Vue.js, Polymer, Ember, Backbone.js and Meteor. Redux maintains the state of an entire application in a single immutable state object that cannot be changed directly. When something in the application changes, a new state object is created using actions and reducers. I will be discussing some of the basics of Redux here.&lt;/p&gt;

&lt;h2&gt;
  
  
  Store
&lt;/h2&gt;

&lt;p&gt;Redux believes in maintaining a 'single source of truth'. That means that there is only one place in the application where all of the state is stored. Conveniently, in Redux this is called the &lt;code&gt;Store&lt;/code&gt;. The Store, like almost everything in JavaScript, is an object, and this special object comes with some helper methods in order to register event listeners, dispatch actions, and access the state in addition to holding the &lt;code&gt;state tree&lt;/code&gt; of the application. In order to create a Redux Store you need to call &lt;code&gt;createStore()&lt;/code&gt; and pass it the &lt;code&gt;reducer&lt;/code&gt;, the &lt;code&gt;[preloadedState]&lt;/code&gt;, and the &lt;code&gt;[enhancer]&lt;/code&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Arguments
&lt;/h4&gt;

&lt;p&gt;reducer (Function): &lt;em&gt;A reducing function that returns the next state tree, given the current state tree and an action to handle.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;preloadedState (any): &lt;em&gt;The initial state. You may optionally specify it to hydrate the state from the server in universal apps, or to restore a previously serialized user session. If you produced reducer with combineReducers, this must be a plain object with the same shape as the keys passed to it. Otherwise, you are free to pass anything that your reducer can understand.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;enhancer (Function): &lt;em&gt;The store enhancer. You may optionally specify it to enhance the store with third-party capabilities such as middleware, time travel, persistence, etc. The only store enhancer that ships with Redux is applyMiddleware().&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Returns
&lt;/h4&gt;

&lt;p&gt;(Store): &lt;em&gt;An object that holds the complete state of your app. The only way to change its state is by dispatching actions. You may also subscribe to the changes to its state to update the UI.&lt;/em&gt;&lt;br&gt;
&lt;em&gt;from redux.js.org&lt;/em&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ydowjEsR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/uj80hc6erc8ttkvae2q4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ydowjEsR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/uj80hc6erc8ttkvae2q4.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Actions
&lt;/h2&gt;

&lt;p&gt;Actions are objects that describe changes that happened in the application. Actions are the only way to send data to the Redux Store, which means that all data collected from user interface events, network callbacks, or other sources must be dispatched as actions. Actions have to have a &lt;code&gt;type&lt;/code&gt; field which specifies which action is to be performed by the reducer. The actions do not actually change the state, they just send information to the reducer.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--n0BkwPfy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/mx9xubmtvoicma3yp69x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--n0BkwPfy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/mx9xubmtvoicma3yp69x.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Reducers
&lt;/h2&gt;

&lt;p&gt;Reducers are functions that accept an accumulation and a value and return a new accumulation. They are used to boil a collection down to a single value. Reducers are common in computer programming, and most of us have used the built in versions already, such as &lt;code&gt;Array.prototype.reduce()&lt;/code&gt; in JavaScript (which should not be ripped off of the Array prototype to reduce a string). In Redux, the collection being reduced to a single value is the state, and the values being accumulated are the actions. Reducers take the previous state value and the action being dispatched to it and return a new state for the application. &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--r4hjYnOZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/byft7x9de5bjs59wf0ne.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--r4hjYnOZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/byft7x9de5bjs59wf0ne.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If your application has more than one reducer they can be combined with the aptly named &lt;code&gt;combineReducers()&lt;/code&gt; helper function into what is conventionally called the &lt;code&gt;rootReducer&lt;/code&gt;. &lt;code&gt;combineReducers()&lt;/code&gt; merges all of the reducers in the app into one root reducer. Every reducer is responsible for its own part of the app state, and the state parameter is different for every reducer. This makes it much easier to understand and follow where code is coming from and to maintain file structure.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--S-CWpBUK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/fifd0xp2wo6nzqbt429i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--S-CWpBUK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/fifd0xp2wo6nzqbt429i.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Building a Pokedex with Next.js</title>
      <dc:creator>Marc West</dc:creator>
      <pubDate>Mon, 13 Jan 2020 05:29:53 +0000</pubDate>
      <link>https://forem.com/marcdwest32/building-a-pokedex-with-next-js-4jjj</link>
      <guid>https://forem.com/marcdwest32/building-a-pokedex-with-next-js-4jjj</guid>
      <description>&lt;p&gt;Next.js is a React framework for JavaScript created by Zeit which allows you to build server-side rendered single-page web applications. We're going to be using Next.js to create a Pokedex application. All you need to get started making an application with Next.js is npm version 5.2 or higher, and you can simply run the create next app command in the cli, passing the name of your app as the second parameter.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npx create-next-app pokedex&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You should see this message &lt;code&gt;Installing react, react-dom, and next using npm...&lt;/code&gt;, and then a success message. Your newly created app now has everything necessary to start. Entering &lt;code&gt;npm run dev&lt;/code&gt; in the console will get your development page up and running on &lt;code&gt;http://localhost:3000/&lt;/code&gt;, and upon visiting the site you will see this Next.js welcome screen - &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xHXcLRm3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ga8optf79a36qxv24211.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xHXcLRm3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ga8optf79a36qxv24211.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Back inside your code editor, you will see a &lt;code&gt;pages&lt;/code&gt; folder that was automatically generated for you when the application was created. This is where the top-level React components will be. Inside this folder is the &lt;code&gt;index.js&lt;/code&gt; file, which is currently being rendered on localhost:3000. For our Pokedex application we won't need anything below the closing &lt;code&gt;&amp;lt;/Head&amp;gt;&lt;/code&gt; tag, nor will we need to import the Nav component. It should now look like this - &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--L0sd_eMY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/fjo6it2ytydwkwb406dt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--L0sd_eMY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/fjo6it2ytydwkwb406dt.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, to get our pokemon we'll be using the pokemon api found here - &lt;code&gt;https://pokeapi.co/&lt;/code&gt;. Next.js has a unique lifecycle hook, &lt;code&gt;getInitialProps&lt;/code&gt; that allows us to access route related data such as request and response and use that data in our app as props. Like all lifecycle hooks, we just need to tell it what we need it to do; in this case, catch us some pokemon! Start by importing &lt;code&gt;axios&lt;/code&gt; and then below the &lt;code&gt;Home&lt;/code&gt; functional component in &lt;code&gt;index.js&lt;/code&gt; craft your &lt;code&gt;getInitialProps&lt;/code&gt; method to reach out to the pokemon api and give you back all 964 of the critters. You can now pass the retrieved data to the &lt;code&gt;Home&lt;/code&gt; component as props and, using regular JavaScript, map the captured pokemon to your site. &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--K9VdMCj2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/7s90e9og7oe9iy70q2cs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--K9VdMCj2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/7s90e9og7oe9iy70q2cs.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Resulting in -&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3th9rxJd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ddxlnt7sur26kckgon7g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3th9rxJd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ddxlnt7sur26kckgon7g.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;--missing section--&lt;br&gt;
Sweet! Next you're going to want to display the individual pokemon and their information on their own page. Inside the &lt;code&gt;pages&lt;/code&gt; folder, create a new folder named &lt;code&gt;pokemon&lt;/code&gt;. In your new &lt;code&gt;pokemon&lt;/code&gt; folder, make a file called &lt;code&gt;[number].js&lt;/code&gt;. This odd looking naming convention is unique to Next.js. It signifies to Next.js that you will be creating dynamic routes for each of your pokemon. Craft your &lt;code&gt;getInitialProps&lt;/code&gt; here with &lt;code&gt;query&lt;/code&gt; being passed as the parameter. The &lt;code&gt;query&lt;/code&gt; will contain the number in the url for the corresponding pokemon you wish to display. You can then use that number to make your axios call to the pokeapi for the specific critter you need and display their data. I've chosen to display the name, default image, and shiny image for each pokemon. &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---jS5210K--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/m0fvddlizwyogi5r2ddj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---jS5210K--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/m0fvddlizwyogi5r2ddj.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Almost done! Back in &lt;code&gt;index.js&lt;/code&gt; there's just a few changes to make to tie it all together. Once again import &lt;code&gt;Link&lt;/code&gt;, this time to link us to the pokemon pages. Add a &lt;code&gt;&amp;lt;Link href={&lt;/code&gt;/pokemon/${i + 1}&lt;code&gt;}&amp;gt;&lt;/code&gt; tag to the return statement inside your map function which renders the pokemon list. This will tie the corresponding pokemon to the query in &lt;code&gt;[number].js&lt;/code&gt;.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IHcUNFac--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/vdotgmn5eirlc498s9m1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IHcUNFac--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/vdotgmn5eirlc498s9m1.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's it! Now head to your browser to catch some pokemon. Clicking on a pokemon will dynamically route you to that pokemon's page and show you their details. &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--69_toM6Q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/a8upsh73saz1tpus0cgr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--69_toM6Q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/a8upsh73saz1tpus0cgr.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope you enjoyed building a Pokedex using Next.js, and if you really liked your app, they also make it very easy to deploy at  &lt;code&gt;zeit.co&lt;/code&gt;. With a few simple steps you can have your Pokedex on the web for free. &lt;/p&gt;

&lt;p&gt;tl/dr &lt;a href="https://pokedex.marcdwest.now.sh/"&gt;https://pokedex.marcdwest.now.sh/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>nextjs</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>mongoDB or SQL?</title>
      <dc:creator>Marc West</dc:creator>
      <pubDate>Mon, 16 Dec 2019 05:16:07 +0000</pubDate>
      <link>https://forem.com/marcdwest32/intro-to-mongodb-5d3p</link>
      <guid>https://forem.com/marcdwest32/intro-to-mongodb-5d3p</guid>
      <description>&lt;p&gt;MongoDB is a popular cross-platform NoSQL document-based database that was released in 2010. Maybe you are wondering if mongoDB is the right database for your current project, and the answer to that is simple: it depends. &lt;/p&gt;

&lt;p&gt;MongoDB is great at doing some things and not so great at doing others. Deciding whether you should use mongoDB or an SQL database is something you should do early in the planning stages of a project. Choosing the wrong option can have damning ramifications for your project and produce catastrophic results. So, when should you use mongoDB? &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ApTJfzU4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/wvu1ytq7r5uy3ruugp1x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ApTJfzU4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/wvu1ytq7r5uy3ruugp1x.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;MongoDB's strengths lie in its versatility. Unlike SQL databases, with mongoDB data is stored in collections of JSON-like BSON objects called documents. This means that it allows you to create and use databases without having to map-out and design a rigid schema. MongoDB is a great choice if you have heterogeneous data because the document system allows for adding unique information to a single document. Additionally mongoDB can store complex datatypes within a document allowing for nested objects and arrays. However, versatility isn't mongoDB's only strength.&lt;/p&gt;

&lt;p&gt;If Node is your forte, mongoDB may be easy for you to pick up. It is frequently used in Node applications because of its familiarity and compatibility with JavaScript. Plus, the native query language for mongoDB is designed to emulate JavaScript. This means if you know JavaScript, then you already know how to query a mongoDB database. MongoDB also offers a cloud database, mongoDB Atlas, to make managing your data even easier. But for all its positives, mongoDB still leaves room for SQL in modern applications.&lt;/p&gt;

&lt;p&gt;Let's take a look at how you might store some data in mongoDB vs an SQL database.&lt;/p&gt;

&lt;h2&gt;
  
  
  SQL
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Jer-wXc5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/kk7afxpcvo1q2hd5dumz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Jer-wXc5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/kk7afxpcvo1q2hd5dumz.png" alt="A fairly simple SQL schema"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  mongoDB
&lt;/h2&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;_id&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;5cf0029caff5056591b0ce7d&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;firstname&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Grap&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;lastname&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Pina&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;contact&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;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;email&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="nx"&gt;grap&lt;/span&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;banas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;,
    &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="nx"&gt;phone1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;: &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="mi"&gt;5045554727&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;,
    &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="nx"&gt;phone2&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;: &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="mi"&gt;5045557462&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;,
  },
  “dept&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;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;mgmt&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;sales&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;Now we'll check out some example queries.&lt;/p&gt;

&lt;h2&gt;
  
  
  SQL
&lt;/h2&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;username&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;VALUES&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="n"&gt;Grap&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="n"&gt;mamagrapmaidnname&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="n"&gt;grap&lt;/span&gt;&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;banas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  mongoDB
&lt;/h2&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;insert&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;username&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Grap&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="na"&gt;password&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;mamagrapmaidnname&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;grap@banas.com&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;While mongoDB can technically handle foreign keys, SQL is still king when it comes to highly-correlated data. If your database could be expressed well in a giant Excel spreadsheet, you should consider SQL over mongoDB. The atomic nature of data in an SQL database, that is - each cell of data contains exactly one item (a string, a number, etc), indexing data in SQL databases allows for fine-grain sorting that can't be achieved with complex datatypes in the mix. Lastly, in a broad sense, SQL queries tend to be slower on small data sets, but when your records number in the millions, SQL will blow mongoDB out of the water.&lt;/p&gt;

&lt;p&gt;So where does that leave us? Well, although it isn't a total replacement for relational databases, mongoDB may be a better option for some projects. Consider using mongoDB if you need a more flexible, schema-less solution for working with unstructured data, but if you need to perform multi-row transactions on highly-structured data sets, you're probably better off sticking to SQL. Figure out which one is best for you before committing.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Callbacks and Promises</title>
      <dc:creator>Marc West</dc:creator>
      <pubDate>Mon, 09 Dec 2019 05:07:54 +0000</pubDate>
      <link>https://forem.com/marcdwest32/callbacks-and-promises-201o</link>
      <guid>https://forem.com/marcdwest32/callbacks-and-promises-201o</guid>
      <description>&lt;p&gt;In synchronous programming, all operations happen in a sequence with each operation firing after the result of the previous one is obtained. When a function is called that performs a long-running action, the rest of the program has to stop and wait for it to return before continuing. This can be highly problematic in JavaScript because we are frequently dealing with user-interfaces and servers. User inputs and server requests are unpredictable, and we need our programs to continue to perform operations while waiting on their results. Because JavaScript is single-threaded and synchronous by default, we have to use a few special tools if we want to perform these asynchronous tasks. Two of these tools are async callbacks and promises.&lt;/p&gt;

&lt;h2&gt;
  
  
  Callbacks
&lt;/h2&gt;

&lt;p&gt;The original way of dealing with this dilemma is with asynchronous callbacks. A callback is basically a function passed as an argument to another function to be executed upon the completion of an asynchronous operation. These callback functions can either be defined functions or anonymous functions created on the fly, but typically they need to be able to either handle an error, passed in as their first argument, or pass on their collected data or result.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fzulx80s7h3rcsls6lz3j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fzulx80s7h3rcsls6lz3j.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
In this example we are passing the callback function as the last parameter in &lt;code&gt;getStatusCode&lt;/code&gt;, and then we define it anonymously on the next line passing it &lt;code&gt;err&lt;/code&gt; and the expected data to be retrieved as &lt;code&gt;data&lt;/code&gt;. After &lt;code&gt;request.get&lt;/code&gt; completes the resulting data or error will be handled by our callback function. &lt;/p&gt;

&lt;p&gt;This all seems pretty clean and simple, and it can be, but because we have to handle both the result and error possibilities in all of our callbacks, things can get pretty messy when dealing with nested callbacks. If you're not careful you could have something that looks like this 'callback hell' pattern -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fs.readdir(source, function (err, files) {
  if (err) {
    console.log('Error finding files: ' + err)
  } else {
    files.forEach(function (filename, fileIndex) {
      console.log(filename)
      gm(source + filename).size(function (err, values) {
        if (err) {
          console.log('Error identifying file size: ' + err)
        } else {
          console.log(filename + ' : ' + values)
          aspect = (values.width / values.height)
          widths.forEach(function (width, widthIndex) {
            height = Math.round(width / aspect)
            console.log('resizing ' + filename + 'to ' + height + 'x' + height)
            this.resize(width, height).write(dest + 'w' + width + '_' + filename, function (err) {
              if (err) console.log('Error writing file: ' + err)
            })
          }.bind(this))
        }
      })
    })
  }
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Promises
&lt;/h2&gt;

&lt;p&gt;Introduced in 2015 with ES6, promises offer us a cleaner and more efficient way of handling asynchronous code than their predecessor the callback. A promise is an object that contains a callback function carrying both &lt;code&gt;resolve&lt;/code&gt; and &lt;code&gt;reject&lt;/code&gt; outcomes. This allows us to use the promises' provided methods &lt;code&gt;.then()&lt;/code&gt; and &lt;code&gt;.catch()&lt;/code&gt; to handle what happens upon success or failure rather than having to pass in a callback function.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fbk9fygyeon52ygo76z62.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fbk9fygyeon52ygo76z62.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Here we construct &lt;code&gt;getFiles&lt;/code&gt; to return a new promise. If there is an error, the promise will reject. If there is no error the promise resolves, and we are given a promise object with &lt;code&gt;.then()&lt;/code&gt; and &lt;code&gt;.catch()&lt;/code&gt; methods. Now when we call &lt;code&gt;createFile&lt;/code&gt;, because it returns a promise, we no longer pass it a callback. Instead we can chain on &lt;code&gt;.then()&lt;/code&gt; and &lt;code&gt;.catch()&lt;/code&gt; to perform the respective success or fail responses. It may not seem like much on this small scale, but this allows us to chain on many &lt;code&gt;.then()&lt;/code&gt; calls followed by a single &lt;code&gt;.catch()&lt;/code&gt; rather than falling into a nested callback pattern.&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>Inheritance and Subclassing</title>
      <dc:creator>Marc West</dc:creator>
      <pubDate>Mon, 02 Dec 2019 07:40:24 +0000</pubDate>
      <link>https://forem.com/marcdwest32/inheritance-and-subclassing-2ema</link>
      <guid>https://forem.com/marcdwest32/inheritance-and-subclassing-2ema</guid>
      <description>&lt;p&gt;In programming, inheritance is the process by which an object or class receives methods and properties from another object or class. There are many different ways of accomplishing this across both classical object-oriented programming and JavaScript, but the purpose is basically the same: to give us the ability to reuse code to pass on properties, rather than than having to rewrite and redefine our methods whenever they are needed elsewhere. Subclassing also allows us to create specialist objects by customizing inherited properties from the object's super-class and adding new methods as well.&lt;/p&gt;

&lt;p&gt;Classes work differently in classical object-oriented programming than they do in JavaScript, and if you're a beginner like I am, with no coding experience outside of JavaScript, it can be a little difficult to understand these differences. In languages like Ruby, Java, PHP, Python, C#, C++, and others, classes are a special data-type used to instantiate objects. In stark contrast to JavaScript, Ruby only has one way of creating new objects - by first declaring a class, and then calling the &lt;code&gt;new()&lt;/code&gt; method on it. This newly created object will inherit most, but not all, of the class's properties. Most noticeably missing from the new object's properties is the &lt;code&gt;new()&lt;/code&gt; method, which is reserved exclusively for classes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AMn6kL7g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/d2tlngrm9mwfjrcijh0t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AMn6kL7g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/d2tlngrm9mwfjrcijh0t.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In JavaScript the rules for creating objects are slightly more relaxed. Pretty much everything in JavaScript is an object, and objects can be created in many ways, including function results and methods. The simplest way to make an object is to just declare it - &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YW7Xkvf0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/77njvooriqwb8gduu9vt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YW7Xkvf0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/77njvooriqwb8gduu9vt.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;All objects are instances of &lt;code&gt;Object&lt;/code&gt; and inherit all properties and methods from the &lt;code&gt;Object.prototype&lt;/code&gt;. Properties can be inherited via the prototype chain - as exemplified here using the &lt;code&gt;Object.create()&lt;/code&gt; method - &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sIvr1kXe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/0oc478631qo1seqws238.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sIvr1kXe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/0oc478631qo1seqws238.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Properties and methods can also be passed along in a more familiar way to classical programmers by using the new ES6 &lt;code&gt;class&lt;/code&gt; keyword and assigning our new class a name - &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--C1utMide--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/h2w6gvfgsp58euo6km6h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--C1utMide--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/h2w6gvfgsp58euo6km6h.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now if we want to build a more specialized object we define a new class that extends the previous class. We can then add new properties and methods to this sub-class while retaining the super-class properties. If we want, we can even alter properties to our new sub-class's needs - &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GU73Ll1Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/5luhb2fvsatnq9zydv6i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GU73Ll1Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/5luhb2fvsatnq9zydv6i.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;JavaScript allows us to customize even more by not restricting us to extending only from the super. We can also simply extend a sub-class of another super-class and inherit the properties of both - &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Q7wmi0D8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/0elwhe082i753cqvb6ou.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Q7wmi0D8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/0elwhe082i753cqvb6ou.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Although this it similar to creating classes in object-oriented languages, it is really just another way that JavaScript allows us to create objects and pass along methods and properties that will need to be repeated in your code. Unlike in other languages, JavaScript is not restricted to using only this method to produce objects, this gives it more flexibility to make specific changes to code without having to completely rewrite it, which allows us to save space and also reduce time spent searching for bugs in our code.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
    </item>
    <item>
      <title>An Intro to jQuery</title>
      <dc:creator>Marc West</dc:creator>
      <pubDate>Mon, 25 Nov 2019 14:15:16 +0000</pubDate>
      <link>https://forem.com/marcdwest32/an-intro-to-jquery-1lfm</link>
      <guid>https://forem.com/marcdwest32/an-intro-to-jquery-1lfm</guid>
      <description>&lt;p&gt;jQuery is a lightweight, "write less, do more" JavaScript library. Released in 2006, it's purpose is to offer you a much easier way to traverse and manipulate the HTML DOM, or Document Object Model, handle events and CSS, and simplify AJAX calls. jQuery replaces a lot of common JavaScript functions that require many lines of code to run with simple methods that can be called with a single line.&lt;/p&gt;

&lt;p&gt;First, in order to use jQuery you need to bring it in to your web page. This can be accomplished by either downloading a local copy or by using the content delivery network (CDN). Downloading is usually recommended for larger projects and production while accessing jQuery with a CDN is a simple way to use it in smaller projects. Either way you choose, make sure to include a link to it in the HTML file using the &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Although it is not unique to jQuery, the dollar sign &lt;code&gt;$&lt;/code&gt; is one of its most recognizable features. Indicating the following code is going to be jQuery,it is essentially another variable for &lt;code&gt;jQuery&lt;/code&gt;, and is used to distinguish it from regular JavaScript.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// bling example
$(function() {
  $( "p" ).text( "Bling!" );
});

// jQ example
jQuery(function() {
  jQuery( "p" ).text( "Same thing!" );
});
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;After calling jQuery with the dollar sign &lt;code&gt;$&lt;/code&gt;, you pass it the DOM element you wish to access and then the method you want to perform, i.e., &lt;code&gt;$("selector").action()&lt;/code&gt;. There are  different ways to access different elements on the DOM: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;$("tags")&lt;/code&gt; - nothing precedes tag name&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;$(".class")&lt;/code&gt; - class name is preceded by dot&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;$("#id")&lt;/code&gt; - id name is preceded by pound symbol / hashtag&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are tons of different methods you can perform with jQuery, but I'll go over just a few of the most commonly used.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;text()&lt;/code&gt; - The result of the .text() method is a string containing the combined text of all matched elements. &lt;code&gt;$("h3").text()&lt;/code&gt; will return a string of all text in h3 tags.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;prop()&lt;/code&gt; - Get the value of a property for the first element in the set of matched elements or set one or more properties for every matched element. &lt;code&gt;$("#button1").prop("disabled", true);&lt;/code&gt; will disable the button's functionality&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;addClass()&lt;/code&gt; - Adds the specified class(es) to each element in the set of matched elements. &lt;code&gt;$("#button2").addClass("btn-primary");&lt;/code&gt; will add the class of btn-primary to the elements with the &lt;code&gt;button2&lt;/code&gt; id.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;css.()&lt;/code&gt; - Get the value of a computed style property for the first element in the set of matched elements or set one or more CSS properties for every matched element. &lt;code&gt;$("button").css("color", "red");&lt;/code&gt; will change the text color of all button tags red.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;jQuery also gives you to simplified method to make AJAX (Asynchronous JavaScript And XML) requests. AJAX requests allow you to load and manipulate remote data on your website. jQuery lets you specify authentication details, request parameters, and the data type you want back in calls to the server. These calls are chained to success or fail callbacks which you use to handle the data you are sending or receiving.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$.ajax({
  type: "POST",             // specify type of request
  url: "/players/submit",   // url location
  data: {
    name: "Drew",           // data you wish to send the server
    team: "New Orleans"
  }
})
  .then(function(msg) {     // success callback
    alert("Data Saved: " + msg);
  })
  .catch(function(xmlHttpRequest, statusText, errorThrown) {    // error callback
    alert(
      "Your form submission failed.\n\n" +
        "XML Http Request: " +
        JSON.stringify(xmlHttpRequest) +
        ",\nStatus Text: " +
        statusText +
        ",\nError Thrown: " +
        errorThrown
    );
  });
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;These are just a few of the jQuery methods you can use to affect your code and make your page more dynamic, and as you can see they are quite simple to implement. This makes jQuery a great tool for JavaScript beginners especially. Overly-complicated JavaScript functions get replaced by easy to learn one-line methods, allowing you to write simpler, cleaner, easier to read code. If you are a JavaScript beginner, like myself, jQuery is a great tool for you to learn to help you build your programming skills.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>jquery</category>
    </item>
    <item>
      <title>AngularJS Factory Vs Service Vs Provider</title>
      <dc:creator>Marc West</dc:creator>
      <pubDate>Mon, 19 Aug 2019 05:42:50 +0000</pubDate>
      <link>https://forem.com/marcdwest32/angularjs-factory-vs-service-vs-provider-1577</link>
      <guid>https://forem.com/marcdwest32/angularjs-factory-vs-service-vs-provider-1577</guid>
      <description>&lt;p&gt;AngularJS is a JavaScript based framework used to design single-page component-based web apps. For beginners, such as myself, it can be a little confusing as to what logic and data should be put in the controller, or what service should be used instead. Typically controllers should not be full of persistent because they are instantiated only when needed and then discarded. That just leaves the many service methods you have to choose from. &lt;/p&gt;

&lt;h3&gt;
  
  
  Factories
&lt;/h3&gt;

&lt;p&gt;Factories are the most frequently used method for registering a service. The reason for that being that they are easier to write and use, and your business logic and other data is never exposed to the rest of the app. The factory method takes two parameters: the string you want to name the factory, and the factory function which will declare and return the object. Any properties attached to the new object will then be available to other parts of the app through a controller. Because the service is wrapped in an instance of an object, the internal logic and data remains unexposed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Service
&lt;/h3&gt;

&lt;p&gt;Very similar to the factory is the service. The main difference between the two is that the service method uses a constructor function to register the service. Services are instantiated in AngularJS with the 'new' keyword, which means properties are added using the 'this' keyword, and the service constructor returns 'this'. When passed through to the controller, the properties on 'this' will be available in that part of your app, but, because of this all of the internal logic of a given service is exposed to the rest of the app.&lt;/p&gt;

&lt;h3&gt;
  
  
  Providers
&lt;/h3&gt;

&lt;p&gt;Providers also do basically the same thing, but with a little more work involved and a few bonus features. Providers are the only service that can be passed directly into the .config() function. This allows alterations to be made to portions of the service before it is made available to the rest of the app. Also the only properties on the provider that will be available to the controller will be the ones assigned to this.$get. This allows the programmer to keep internal logic hidden or exposed as they see fit. &lt;/p&gt;

&lt;p&gt;This is just a brief rundown of a few service methods available to you in AgularJS, and there's obviously a lot more detail involved, but this should help clear up some of the uses. You will probably want to use a factory most of the time, use a service for simpler logic, and use a provider when you need more customization options.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Big O Notation</title>
      <dc:creator>Marc West</dc:creator>
      <pubDate>Mon, 12 Aug 2019 02:56:00 +0000</pubDate>
      <link>https://forem.com/marcdwest32/big-o-notation-4ah0</link>
      <guid>https://forem.com/marcdwest32/big-o-notation-4ah0</guid>
      <description>&lt;p&gt;Time complexity in computer science is the amount of time it takes for a machine to process an algorithm. Specifically we are interested in how processing time grows in relation to input size. Because processing time can differ for varying inputs of the same size, time complexity notation is factored considering a worst-case scenario. Since this can involve some very complicated mathematical computations, we use Big O notation as a shorthand for various levels of time complexity. Let's take a look at some of the common types of complexity we expect to see in programming, from best to worse performance.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OwPnscUG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/8zbtouevt7a2tucptx29.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OwPnscUG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/8zbtouevt7a2tucptx29.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Constant Time O(1)
&lt;/h3&gt;

&lt;p&gt;Constant Time means that no matter what the input size, the time it takes for the algorithm to run will remain the same. A familiar example of a constant time algorithm is looking up a value in an array at a known index. &lt;/p&gt;

&lt;h3&gt;
  
  
  Logarithmic Time O(log n)
&lt;/h3&gt;

&lt;p&gt;Logarithmic Time means that as the size of your input grows, the processing time grows, but at an ever-reducing rate. A good example of this is a binary search tree. The reason for this being that the search field is reduced by half at every search cycle.&lt;/p&gt;

&lt;h3&gt;
  
  
  Linear Time O(n)
&lt;/h3&gt;

&lt;p&gt;Linear Time means that as the input size increases, the processing time increases at a consistent rate. Common occurrences of linear time algorithms would be any function that may potentially have to loop over the entire input. Many higher-order functions such as map, filter, and forEach are examples of linear time algorithms.  &lt;/p&gt;

&lt;h3&gt;
  
  
  Quadratic Time O(n^2)
&lt;/h3&gt;

&lt;p&gt;Quadratic Time is when processing time increases at a rate which itself increases multiplicatively. Common examples of this are nesting a loop within a loop. Put in simpler terms, as input increases in size, processing time increases by the size of the input raised to some power.&lt;/p&gt;

&lt;h3&gt;
  
  
  Exponential Time O(c^n)
&lt;/h3&gt;

&lt;p&gt;Exponential Time algorithms are when processing time increases exponentially as the size of the input grows. One common example of this is brute-force cracking of a password. This means that as input size grows, processing time increases by some constant raised to the power of the size of the input.&lt;/p&gt;

&lt;p&gt;There are many other types of time complexity that we won't discuss here, but understanding these few examples is crucial in developing performant algorithms in your programs. We should all strive to improve the time complexity of our applications.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Object.create()</title>
      <dc:creator>Marc West</dc:creator>
      <pubDate>Mon, 05 Aug 2019 05:31:29 +0000</pubDate>
      <link>https://forem.com/marcdwest32/object-create-14j7</link>
      <guid>https://forem.com/marcdwest32/object-create-14j7</guid>
      <description>&lt;h1&gt;
  
  
  The Object.create() Method
&lt;/h1&gt;

&lt;p&gt;Object.create is a newer method in JavaScript that can be a more simple and efficient way for you to create objects. Although there are many ways to accomplish making new objects and assigning them properties, the Object.create method is unique because it lets you bypass making a constructor function by allowing you to set any existing object as the prototype for a new object.&lt;/p&gt;

&lt;p&gt;This method takes two parameters: the first being the object being used as the prototype, and the second an optional properties object which is used to set specific properties on the new object. When the new object is returned it will have all the properties of its prototype plus its own properties, either given through the properties object or added later with dot or bracket notation. &lt;/p&gt;

&lt;p&gt;in conclusion, Object.create is a quick and easy way to create new objects. With the seemingly endless ways to make new objects, Object.create simplifies the process. Even with its awkward optional second parameter, it is an easy way for programmers, especially newcomers like myself, to create new objects and keep track of their inheritance.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
