<?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>DEV Community: Nick Raphael</title>
    <description>The latest articles on DEV Community by Nick Raphael (@nickraphael).</description>
    <link>https://dev.to/nickraphael</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%2F255007%2F026b7b60-d269-4e45-bf98-f89dfc78ba79.jpeg</url>
      <title>DEV Community: Nick Raphael</title>
      <link>https://dev.to/nickraphael</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nickraphael"/>
    <language>en</language>
    <item>
      <title>Redux: Uncaught TypeError: Cannot read properties of undefined (reading 'mySlice')</title>
      <dc:creator>Nick Raphael</dc:creator>
      <pubDate>Tue, 21 Jun 2022 01:05:07 +0000</pubDate>
      <link>https://dev.to/nickraphael/redux-uncaught-typeerror-cannot-read-properties-of-undefined-reading-myslice-1nbh</link>
      <guid>https://dev.to/nickraphael/redux-uncaught-typeerror-cannot-read-properties-of-undefined-reading-myslice-1nbh</guid>
      <description>&lt;p&gt;Oh man, I just had a really annoying redux-toolkit error...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Uncaught TypeError: Cannot read properties of undefined (reading 'mySlice')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This was caused by a circular dependency in my file structure. I have a file structure like this...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;stuff
  -&amp;gt; store
    -&amp;gt; index.ts
       reducer.ts
       selectors.ts
  feature
    -&amp;gt; store
      -&amp;gt; index.ts
         slice.ts
         selectors.ts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Any code outside of the store files references store stuff via the index.tx which just exports all the other files.&lt;/p&gt;

&lt;p&gt;My problem was a selector referencing a selector from a higher level in my store structure via another index.ts.  The reducer at this higher level was referencing the slice at the lower level, again via index.ts.&lt;br&gt;
This is a circular reference.  To fix it, I chose to remove the higher level index.ts and reference the selector file directly.&lt;/p&gt;

&lt;p&gt;Hope this helps somebody.&lt;/p&gt;

</description>
      <category>redux</category>
    </item>
    <item>
      <title>List git branches ordered by date of last commit</title>
      <dc:creator>Nick Raphael</dc:creator>
      <pubDate>Mon, 10 Jan 2022 00:59:30 +0000</pubDate>
      <link>https://dev.to/nickraphael/list-git-branches-ordered-by-date-of-last-commit-42dc</link>
      <guid>https://dev.to/nickraphael/list-git-branches-ordered-by-date-of-last-commit-42dc</guid>
      <description>&lt;p&gt;First day back after Christmas break and I'm a bit hazy on what I was working on.  I know I was working on an area of code weeks ago but not sure if it got merged into Master.  &lt;/p&gt;

&lt;p&gt;Git can help.  I'll list all my local branches by descending commit date.  Luckily my branch names are taken from my workitem id.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git branch --sort=-committerdate  # DESC
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I found the branch I was after near the top of the list.  I then checked if the last commit on that branch was in master.  Easy.&lt;/p&gt;

&lt;p&gt;One to remember...&lt;/p&gt;

</description>
      <category>git</category>
    </item>
    <item>
      <title>How to change the url of a remote git repo...</title>
      <dc:creator>Nick Raphael</dc:creator>
      <pubDate>Tue, 07 Dec 2021 22:53:52 +0000</pubDate>
      <link>https://dev.to/nickraphael/how-to-change-the-url-of-a-remote-git-repo-2goi</link>
      <guid>https://dev.to/nickraphael/how-to-change-the-url-of-a-remote-git-repo-2goi</guid>
      <description>&lt;p&gt;Hi all,&lt;/p&gt;

&lt;p&gt;I recently got myself into the situation where all my local git repos had the wrong remote addresses.  This was caused by a change up on our git account.  &lt;/p&gt;

&lt;p&gt;You can see the url that git is currently using by opening the 'config' file in the .git folder.  You'll see it under the '[remote "origin"]' section.&lt;/p&gt;

&lt;p&gt;Luckily this is pretty trivial to fix.  You can either update the url directly in the config file, or run the following command...&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="nx"&gt;git&lt;/span&gt; &lt;span class="nx"&gt;remote&lt;/span&gt; &lt;span class="kd"&gt;set&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="nx"&gt;origin&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;git&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;xyz&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>git</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Fixing VSCode terminal font</title>
      <dc:creator>Nick Raphael</dc:creator>
      <pubDate>Thu, 11 Jun 2020 05:43:56 +0000</pubDate>
      <link>https://dev.to/nickraphael/fixing-vscode-terminal-font-44kd</link>
      <guid>https://dev.to/nickraphael/fixing-vscode-terminal-font-44kd</guid>
      <description>&lt;p&gt;I just noticed that my vscode terminal window was having font issues.  Especially obvious when it shows the git branch.  Those little squares don't look right...&lt;/p&gt;

&lt;p&gt;Take a look...&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%2Fnwscrms1g3e7oadjzusx.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%2Fnwscrms1g3e7oadjzusx.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It's super easy to fix though.  Download a powerline font (I like 'Cascadia Code PL') and install it on your machine. &lt;/p&gt;

&lt;p&gt;Now all you need to do is add the following line to your vscode settings.json...&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

"terminal.integrated.fontFamily": "Cascadia Code PL"


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And hey presto...&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%2Ftgl1xymnynoaswmmqb07.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%2Ftgl1xymnynoaswmmqb07.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If vscode gives you any errors like 'terminal only supports monospace fonts' then you can try 'MesloLGM Nerd Font'.&lt;/p&gt;

&lt;p&gt;Laters&lt;/p&gt;

</description>
      <category>vscode</category>
    </item>
    <item>
      <title>With the ngrxLet directive we could get rid of that *ngIf trick that we lovehated</title>
      <dc:creator>Nick Raphael</dc:creator>
      <pubDate>Wed, 22 Apr 2020 04:05:12 +0000</pubDate>
      <link>https://dev.to/nickraphael/with-the-ngrxlet-directive-we-could-get-rid-of-that-ngif-trick-that-we-lovehated-20m4</link>
      <guid>https://dev.to/nickraphael/with-the-ngrxlet-directive-we-could-get-rid-of-that-ngif-trick-that-we-lovehated-20m4</guid>
      <description>&lt;h2&gt;
  
  
  Note: As of writing (22-04-2020), ngrx/components is still experimental.
&lt;/h2&gt;

&lt;p&gt;First, I'll go over the 'hack' that I'm talking about.&lt;/p&gt;

&lt;p&gt;Let's suppose we have a rather uninteresting app that shows a different random value every second...&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="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;selector&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;app-root&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;template&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`
    index: {{ (timer$ | async)?.index }}&amp;lt;br /&amp;gt;
    randomValue: {{ (timer$ | async)?.randomValue }}&amp;lt;br /&amp;gt;
    randomValue again:{{ (timer$ | async)?.randomValue }}
  `&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;AppComponent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;timer$&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Observable&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;index&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;randomValue&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&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="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;timer$&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;timer&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="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;pipe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&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;index&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;randomValue&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;random&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="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;Look at that template. Ugh, we had to repeat the '(timer$ | async)' every time we want to render a property of the object. But it's actually worse than that. Each use of async creates a new subscription.  See how the two randomValues are different? Perhaps not what we might have expected.&lt;/p&gt;

&lt;p&gt;So we started using a little trick.  *ngIf can store a conditional result in a variable.  This is fully documented on the angular docs.  It allows us to avoid repeating the async bit.&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="nx"&gt;template&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`
    &amp;lt;div *ngIf="timer$ | async as randomNumbers"&amp;gt;
      index: {{ randomNumbers.index }}&amp;lt;br /&amp;gt;
      randomValue: {{ randomNumbers.randomValue }}&amp;lt;br /&amp;gt;
      randomValue again:{{ randomNumbers.randomValue }}
    &amp;lt;/div&amp;gt;
  `&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You'll now see that the two random numbers are the same.  Woohoo, we only have one subscription.  That's great and far more efficient.  As a bonus, we didn't need to use the '?' safe navigation operator.  Our div was only rendered when the observable was truthy.  &lt;/p&gt;

&lt;p&gt;So what's wrong with that?  Sounds perfect.  And it almost is.  We don't like the fact that we co-opted the *ngIf for something that wasn't really a show/hide issue.  In fact, we may have a different *ngIf statement that we want to use here.  Also, using *ngIf here can interfere with angulars rendering and if your observable returns a falsy value, your div will hidden.  Messy.&lt;/p&gt;

&lt;p&gt;Along comes ngrxLet which comes with ngrx/components.  This library as a set of reactive helpers.  There is a desire in the angular community to move away from zones, and ngrx/components helps us do that.&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="nx"&gt;template&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`
    &amp;lt;div *ngrxLet="timer$ as randomNumbers"&amp;gt;
      index: {{ randomNumbers.index }}&amp;lt;br /&amp;gt;
      randomValue: {{ randomNumbers.randomValue }}&amp;lt;br /&amp;gt;
      randomValue again:{{ randomNumbers.randomValue }}
    &amp;lt;/div&amp;gt;
  `&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It only took a small update to our code.  *ngIf is still available to us if we want visibility logic.  That's a better seperation of concerns.&lt;/p&gt;

&lt;p&gt;There are a few other magical advantages to using ngrxLet.  It also passes us '$error' and '$complete' from the underlaying observable.  Like this...&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="nx"&gt;template&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`
    &amp;lt;div *ngrxLet="timer$ as randomNumbers; let e = $error, let c = $complete"&amp;gt;
      index: {{ randomNumbers.index }}&amp;lt;br /&amp;gt;
      randomValue: {{ randomNumbers.randomValue }}&amp;lt;br /&amp;gt;
      randomValue again:{{ randomNumbers.randomValue }}
      &amp;lt;div *ngIf="e"&amp;gt;
        error: {{e}}
      &amp;lt;/div&amp;gt;
      &amp;lt;div *ngIf="c"&amp;gt;
        completed: {{c}}
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  `&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I hope this makes it into a full release from ngrx.  I like it.&lt;/p&gt;

</description>
      <category>angular</category>
    </item>
    <item>
      <title>c# quicky. Should we 'throw;' or 'throw e;'?</title>
      <dc:creator>Nick Raphael</dc:creator>
      <pubDate>Mon, 06 Apr 2020 01:57:01 +0000</pubDate>
      <link>https://dev.to/nickraphael/c-quicky-should-we-throw-or-throw-e-112f</link>
      <guid>https://dev.to/nickraphael/c-quicky-should-we-throw-or-throw-e-112f</guid>
      <description>&lt;p&gt;This is a bit of an oldie.  Very old, in fact, since this question has been around since c# was born.  And likely before that for other languages.&lt;/p&gt;

&lt;p&gt;What's the difference between these code snippets?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;try&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="n"&gt;some&lt;/span&gt; &lt;span class="n"&gt;code&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Exception&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;throw&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;try&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="n"&gt;some&lt;/span&gt; &lt;span class="n"&gt;code&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Exception&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="n"&gt;e&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;Well, it's all about where the exception originates and what happend to the stacktrace...&lt;/p&gt;

&lt;p&gt;throw : Using a "throw" statement preserves the original error stack information. In exception handling "throw" with empty parameter is also called re-throwing the last exception.&lt;/p&gt;

&lt;p&gt;throw e : Using a "throw e" statement, the stack trace of exception will be replaced with a stack trace starting at the re-throw point. It is used to intentionally hide stack trace information.&lt;/p&gt;

&lt;p&gt;Most of the time you will want to 'throw;'.&lt;/p&gt;

</description>
      <category>csharp</category>
    </item>
    <item>
      <title>Getting the min or max value from an array of numbers in javascript</title>
      <dc:creator>Nick Raphael</dc:creator>
      <pubDate>Fri, 27 Mar 2020 04:56:08 +0000</pubDate>
      <link>https://dev.to/nickraphael/getting-the-min-or-max-value-from-an-array-of-numbers-in-javascript-307n</link>
      <guid>https://dev.to/nickraphael/getting-the-min-or-max-value-from-an-array-of-numbers-in-javascript-307n</guid>
      <description>&lt;p&gt;Turns out this is simple.  Well, it was simple anyway, but it's also quite concise.&lt;/p&gt;

&lt;p&gt;I'll provide my code examples in javascript.&lt;/p&gt;

&lt;p&gt;Let's suppose we have an array of number...&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;var&lt;/span&gt; &lt;span class="nx"&gt;myNumbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can use swanky destructuring assignment, which I know more commonly as the spread operator.&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;var&lt;/span&gt; &lt;span class="nx"&gt;myNumbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;myMinNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;myNumbers&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;myMaxNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;myNumbers&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Short and sweet.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Got a 'git' conflict and just want to blow away your local changes and take 'theirs'?</title>
      <dc:creator>Nick Raphael</dc:creator>
      <pubDate>Thu, 19 Mar 2020 07:01:40 +0000</pubDate>
      <link>https://dev.to/nickraphael/got-a-git-conflict-and-just-want-to-blow-away-your-local-changes-and-take-theirs-a21</link>
      <guid>https://dev.to/nickraphael/got-a-git-conflict-and-just-want-to-blow-away-your-local-changes-and-take-theirs-a21</guid>
      <description>&lt;p&gt;I just did a 'git merge' with another branch and I have a merge conflict.  I'm happy to lose my changes in preference to the changes on the other branch.&lt;/p&gt;

&lt;p&gt;Well, as with all things, there is a simple git command for this...&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="nx"&gt;git&lt;/span&gt; &lt;span class="nx"&gt;checkout&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nx"&gt;theirs&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;to&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;file&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Too easy.&lt;/p&gt;

</description>
      <category>git</category>
    </item>
    <item>
      <title>Did you just say you want to 'git add' all those files except 1?</title>
      <dc:creator>Nick Raphael</dc:creator>
      <pubDate>Wed, 11 Mar 2020 00:30:50 +0000</pubDate>
      <link>https://dev.to/nickraphael/did-you-just-say-you-want-to-git-add-all-those-files-except-1-327h</link>
      <guid>https://dev.to/nickraphael/did-you-just-say-you-want-to-git-add-all-those-files-except-1-327h</guid>
      <description>&lt;p&gt;You run a 'git status' and see that you've updated a heap of files.  One of those files you don't want to commit (often a config).  What's the easiest thing to do?  Well, I have a few options.&lt;/p&gt;

&lt;p&gt;Option 1.  Use 'git assume-unchanged'.  I have a blog post about that here:  &lt;a href="https://dev.to/nickraphael/git-assume-unchanged-for-when-you-want-git-to-ignore-an-edit-for-a-while-2lig"&gt;https://dev.to/nickraphael/git-assume-unchanged-for-when-you-want-git-to-ignore-an-edit-for-a-while-2lig&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Option 2.  Just undo you edit before doing the add.  Basically using 'git checkout xxx/dontcheckmein.txt'&lt;/p&gt;

&lt;p&gt;Option 3.  Run a 'git add .' to add all the files.  Then run 'git reset -- xxx/dontcheckmein.txt'.  This will undo the add.&lt;/p&gt;

&lt;p&gt;Then you can 'git commit' to your hearts content.&lt;/p&gt;

</description>
      <category>git</category>
    </item>
    <item>
      <title>Oops, I just pushed a git commit to the wrong branch. What now?</title>
      <dc:creator>Nick Raphael</dc:creator>
      <pubDate>Thu, 23 Jan 2020 01:41:02 +0000</pubDate>
      <link>https://dev.to/nickraphael/oops-i-just-pushed-a-git-commit-to-the-wrong-branch-what-now-1nle</link>
      <guid>https://dev.to/nickraphael/oops-i-just-pushed-a-git-commit-to-the-wrong-branch-what-now-1nle</guid>
      <description>&lt;p&gt;We are currently running off two active branches in our git repository.  And by accident I just committed an update on the wrong branch and pushed it.  Luckily, getting out of this mess isn't hard.&lt;/p&gt;

&lt;p&gt;The erroneous commit is 65c356c8c&lt;/p&gt;

&lt;p&gt;First, lets pull the commit from Branch1 into Branch2 where it should be...&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="nx"&gt;git&lt;/span&gt; &lt;span class="nx"&gt;checkout&lt;/span&gt; &lt;span class="nx"&gt;Branch2&lt;/span&gt; 
   &lt;span class="nx"&gt;git&lt;/span&gt; &lt;span class="nx"&gt;cherry&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;pick&lt;/span&gt; &lt;span class="mi"&gt;65&lt;/span&gt;&lt;span class="nx"&gt;c356c8c&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This pulls the commit across into the correct branch.  Great.  We can now push the commit is normal.  But what about the commit still sitting on Branch1 in my local index?  Lets fix that now.&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="nx"&gt;git&lt;/span&gt; &lt;span class="nx"&gt;checkout&lt;/span&gt; &lt;span class="nx"&gt;Branch1&lt;/span&gt;
   &lt;span class="nx"&gt;git&lt;/span&gt; &lt;span class="nx"&gt;reset&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nx"&gt;hard&lt;/span&gt; &lt;span class="nx"&gt;HEAD&lt;/span&gt;&lt;span class="o"&gt;~&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will reverse the last commit.  &lt;/p&gt;

&lt;p&gt;As with all git issues, the secret is to not panic.  Jump on the net and find a simple solution.  &lt;/p&gt;

</description>
      <category>git</category>
    </item>
    <item>
      <title>Angular's providedIn: "root". What if two lazy modules provided the same service?</title>
      <dc:creator>Nick Raphael</dc:creator>
      <pubDate>Wed, 18 Dec 2019 05:50:22 +0000</pubDate>
      <link>https://dev.to/nickraphael/angular-s-providedin-root-what-if-two-lazy-modules-provided-the-same-service-166p</link>
      <guid>https://dev.to/nickraphael/angular-s-providedin-root-what-if-two-lazy-modules-provided-the-same-service-166p</guid>
      <description>&lt;p&gt;Sheesh, I'm not sure about that title.  Let's unpack it a little.  The modern way for an angular application to register a singleton service class is using &lt;em&gt;providedin&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://angular.io/guide/singleton-services"&gt;https://angular.io/guide/singleton-services&lt;/a&gt;&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="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Injectable&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;@angular/core&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="nd"&gt;Injectable&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;providedIn&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;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;UserService&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;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;NgModule&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="p"&gt;...&lt;/span&gt;
  &lt;span class="na"&gt;providers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;UserService&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;What if we the module that &lt;em&gt;provides&lt;/em&gt; the service is a lazy loaded module?  Well, that service code will compile into the lazy loaded bundle for that module.  Simple enough.  But what if a second lazy loaded module also provides it?  Where does angular (webpack?) put the service code?  What bundle?  Does it put it in the main bundle, in both lazy bundles or something else?&lt;/p&gt;

&lt;p&gt;The answer is: something else.  Angular is smart enough to realise there is a service that is shared between lazy modules.  It puts that code in its own &lt;em&gt;common&lt;/em&gt; module.  Then whichever lazy module loads first, downloads the &lt;em&gt;common&lt;/em&gt; module along with the lazy module.  That way, the service isn't downloaded before it's needed and is still only downloaded once, despite being &lt;em&gt;provided&lt;/em&gt; by two different lazy loaded routes.  &lt;/p&gt;

&lt;p&gt;Pretty clever.  &lt;/p&gt;

</description>
      <category>angular</category>
    </item>
    <item>
      <title>The common misconception of @Injectable() in angular</title>
      <dc:creator>Nick Raphael</dc:creator>
      <pubDate>Wed, 11 Dec 2019 23:42:00 +0000</pubDate>
      <link>https://dev.to/nickraphael/the-common-misconception-of-injectable-in-angular-5g4n</link>
      <guid>https://dev.to/nickraphael/the-common-misconception-of-injectable-in-angular-5g4n</guid>
      <description>&lt;p&gt;The official angular docs give the following description of &lt;em&gt;@Injectable()&lt;/em&gt;...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://angular.io/api/core/Injectable"&gt;https://angular.io/api/core/Injectable&lt;/a&gt;&lt;br&gt;
&lt;em&gt;"Decorator that marks a class as available to be provided and injected as a dependency."&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I think that description isn't right.  Or at least it leads me to misinterpret the meaning.  Let me start by defining a concrete example...&lt;/p&gt;

&lt;p&gt;Let's say we have AppComponent and UserService.  By default the angularCli will add &lt;em&gt;@Injectable()&lt;/em&gt; to the service when it is generated.  &lt;/p&gt;

&lt;p&gt;Now, to me, the official statement makes me think that &lt;em&gt;@Injectable()&lt;/em&gt; on UserService allows us to add it in the constructor of AppComponent as a dependency.  "...marks a class as available to be provided and injected as a dependency".  But what happens if we remove the &lt;em&gt;@Injectable()&lt;/em&gt; from the service?  Let me tell you - it still gets injected into AppComponent.  &lt;/p&gt;

&lt;p&gt;Now lets add a second service, OrderService and add it as a dependency of UserService.  Now our application throws an error.  &lt;em&gt;"Can't resolve all parameters for UserService"&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;When we add &lt;em&gt;@Injectable()&lt;/em&gt; to the UserService it actually allows UserService to have dependencies injected into itself.  Not allow itself to be injected into AppComponent.&lt;/p&gt;

&lt;p&gt;So we add &lt;em&gt;@Injectable()&lt;/em&gt; to UserService since it needs to register with the dependency injected system to get a reference to OrderService.  We can even remove &lt;em&gt;@Injectable()&lt;/em&gt; from OrderService since it doesn't have any dependencies.&lt;/p&gt;

&lt;p&gt;I'm not saying you should remove &lt;em&gt;@Injectable()&lt;/em&gt;.  In fact, you should leave it there even if your service doesn't have dependencies.  It does no harm.  I once had a service where the injected services weren't working and it took me ages to notice that &lt;em&gt;@Injectable()&lt;/em&gt; was missing.  So don't do that.  &lt;/p&gt;

&lt;p&gt;You might wonder why components are not marked with &lt;em&gt;@Injectable()&lt;/em&gt; since they have dependencies injected into them.  Well, if memory serves, any decorator will have the effect of registering the class with the DI system.  So in this case @Component() is doing it.&lt;/p&gt;

&lt;p&gt;Am I the only one who feels the description of &lt;em&gt;@Injectable()&lt;/em&gt; isn't quite right?  Let me know.&lt;/p&gt;

</description>
      <category>angular</category>
    </item>
  </channel>
</rss>
