<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tal Gershman on Medium]]></title>
        <description><![CDATA[Stories by Tal Gershman on Medium]]></description>
        <link>https://medium.com/@tal-gershman?source=rss-54b0140241dc------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*cImv4YSYYsfGz7x27xrrNA.jpeg</url>
            <title>Stories by Tal Gershman on Medium</title>
            <link>https://medium.com/@tal-gershman?source=rss-54b0140241dc------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 14:41:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tal-gershman/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Angular: Don’t Go To Battle Unarmed]]></title>
            <link>https://tal-gershman.medium.com/angular-dont-go-to-battle-unarmed-813ab0d3cb4f?source=rss-54b0140241dc------2</link>
            <guid isPermaLink="false">https://medium.com/p/813ab0d3cb4f</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Tal Gershman]]></dc:creator>
            <pubDate>Tue, 01 Jun 2021 11:25:15 GMT</pubDate>
            <atom:updated>2021-08-21T13:53:59.964Z</atom:updated>
            <content:encoded><![CDATA[<h4>A collection of tools that will improve any Angular project</h4><p>A good solider always makes sure he has the right weapons before going to battle, same goes for a developer who needs the right tools before taking on a new task .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aszGXrLZUej1T5U55Szr9A.jpeg" /></figure><p><strong>In this article I will share with you some tools that will make your coding more efficient, responsible and clear.</strong></p><h3>1. Preformance: “memoize” &amp; Change Detection Logs</h3><h4>Lodash decorator “memoize”</h4><p>As you know, when ever you call a function in your template it gets triggered on every change detection. If that function run some “heavy” logic it may cause performance issues.</p><p>There are a couple of solutions to avoid this:</p><p>1.Move that function to a pure pipe — but writing a new pipe for every use case can be annoying.</p><p>2. Writing the function as an inline code, something like:</p><pre>[class.some-class]=&quot;firstVar === &#39;good&#39; &amp;&amp; (secondVar ===&#39;1&#39; | thirdVar === &#39;2&#39;)&quot;</pre><p>This is fine but it makes the template code very ugly, and I prefer that all my logic will be place inside the ‘component.ts’ file.</p><p>My suggestion is that you use another solution, which is using regular functions in your template but with memoize decorator.</p><p>Memoize works similar to pipes. What it does is for every input the function takes it create a hash key and cache the result, if that key repeats it will restore the cache result.</p><pre>install:<br>npm i lodash-decorators --save</pre><p>For a function that take only 1–0 arguments you can use :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/015e8e40e1dfe93c1a5a3d5548877ab0/href">https://medium.com/media/015e8e40e1dfe93c1a5a3d5548877ab0/href</a></iframe><p>For a function that take more than one argument use:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4c01067ec1c6be2a51c5353630f92de5/href">https://medium.com/media/4c01067ec1c6be2a51c5353630f92de5/href</a></iframe><p><em>Notes</em>:</p><ol><li>Beware of some internal state in your function that can cause different outputs.</li><li>Try to use only primitive types as objects and arrays are cached by reference.</li><li>There are other helpful decorators that you can use from this library like : debounce, throttle and etc.</li></ol><h4>Change Detection Logs</h4><p>This trick I always make sure is running when I am developing, It makes me aware of change detection cycles in my application and how much each cycle took. It’s is especially useful when you integrate some third-party and want to see what change detection it causes.</p><p>To enable this use the following configuration, make sure that this code is executed only in develop ( I use the ‘isDevelopment’ flag) :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/135098a50769bdf4b1c2cf7bff718360/href">https://medium.com/media/135098a50769bdf4b1c2cf7bff718360/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/62356823c630d3449d00d7a4957925ca/href">https://medium.com/media/62356823c630d3449d00d7a4957925ca/href</a></iframe><p>Then you will see in the console log the following :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/885/1*6lL4sCL3n3Mf03dg-s5idw.png" /></figure><h3><strong>2. Unit Testing : SpyHelper</strong></h3><p>Is a helper class that will make mocking servces in your project a breeze.</p><p>Define in your project the following classs:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/96019a5cfd467aea86392830114f40f4/href">https://medium.com/media/96019a5cfd467aea86392830114f40f4/href</a></iframe><p>For basic usage you only need to mock class:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6fc4fca301eb47aa8cbe72b1f7da761d/href">https://medium.com/media/6fc4fca301eb47aa8cbe72b1f7da761d/href</a></iframe><p>If you do need to mock some logic in the service you can you do the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/69e74792f0bd454024a0ae0b3a351885/href">https://medium.com/media/69e74792f0bd454024a0ae0b3a351885/href</a></iframe><h3>4. Custom Validations Class</h3><p>Place all your custom validations in a single class, then you can use it the same way as you use the build in validations.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/31e33a3d30811fd389bf039a20245369/href">https://medium.com/media/31e33a3d30811fd389bf039a20245369/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/768068a868565813b6be46c228a764e6/href">https://medium.com/media/768068a868565813b6be46c228a764e6/href</a></iframe><p>Another advantage of this, is that you can share logic bettwen validation functions.</p><h3><strong>4. Generic Safe Pipe</strong></h3><p>This is a common pipe that I use often, when ever I need to inject some unsafe code to a template.</p><p>Create a following pipe:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3083c6b2a11df8299bcfe23c085ef359/href">https://medium.com/media/3083c6b2a11df8299bcfe23c085ef359/href</a></iframe><p>Usage :</p><pre>&lt;div [innerHTML]=&quot;previewHtml | safe: &#39;html&#39;&quot;&gt;&lt;/div&gt;</pre><h3>In Case You Missed :</h3><ul><li>Angular New Project Configuration : <a href="https://tal-gershman.medium.com/angular-new-project-boilerplate-workspace-unit-testing-pre-commits-hooks-custom-library-eslint-fcc40873698a">https://tal-gershman.medium.com/angular-new-project-boilerplate-workspace-unit-testing-pre-commits-hooks-custom-library-eslint-fcc40873698a</a></li></ul><p><strong>Thanks for reading! If you got any question let me know in the comments.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=813ab0d3cb4f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular New Project Boilerplate: Workspace, Unit testing, Pre-commits hooks ,Custom Library…]]></title>
            <link>https://tal-gershman.medium.com/angular-new-project-boilerplate-workspace-unit-testing-pre-commits-hooks-custom-library-eslint-fcc40873698a?source=rss-54b0140241dc------2</link>
            <guid isPermaLink="false">https://medium.com/p/fcc40873698a</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[workspace]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Tal Gershman]]></dc:creator>
            <pubDate>Thu, 13 May 2021 17:30:41 GMT</pubDate>
            <atom:updated>2021-08-21T13:53:47.491Z</atom:updated>
            <content:encoded><![CDATA[<h4>All your project configuration in a single article</h4><p>Starting a new project can be confusing as you need a lot of different setups, so I decided to gather all the configuration that you will need in one simple 6 steps guide .</p><figure><img alt="HTML Boilerplate" src="https://cdn-images-1.medium.com/max/400/1*DJKqwKt-1-YYwfGoDps6ZQ.jpeg" /></figure><h4>In this article I will demostratie all the necessary setup that you will need when creating a new Angular project :</h4><ol><li>Setting the project as a workspace, great for code sharing and common settings accross multiple applications.</li><li>Using a custom Angular library in our Angular project.</li><li>Some custom configuration for Karma &amp; Jasmine unit testing.</li><li>Setting a pre-commit hook to lint our stages files with ESLint + prettier.</li><li>Setting alias path with Typescript.</li><li>Setting up multiple environments for : local, staging, production + Injecting process.env variables into our project.</li></ol><h3>1. Workspace :</h3><p>A workspace is very convenient way to manage multiple applications, one of benefits is having one package.json for managing your projects dependencies.</p><p>Create an empty workspace:</p><pre>ng new my-workspace --create-application false</pre><p>Create an empty application in the workspace.</p><pre>cd my-workspace<br>ng g application my-app --prefix ma --style scss --routing</pre><p>This will create a new application with SCSS styling and routing.</p><pre>// angular.json<br>{<br>  //...<br>  &quot;my-app&quot;: {<br>      &quot;projectType&quot;: &quot;application&quot;,<br>      &quot;schematics&quot;: {<br>          &quot;<a href="http://twitter.com/schematics/angular">@schematics/angular</a>:component&quot;: {<br>              &quot;style&quot;: &quot;scss&quot;,<br>              &quot;changeDetection&quot;: &quot;OnPush&quot;<br>          }<br>      },<br>   }<br>}</pre><p>The above will change the default change detection to “onPush” inyour application.</p><h3>2. Library :</h3><p>Library makes it easy to place all the common code for your applications, such as : services, components, directives, pipes … etc.</p><p>I prefer using a library than a core module because you can publish it and make it available for other developers in your company, which often have the same core usage as you.</p><p>This article is nice guide for creating one : <a href="https://medium.com/@tomsu/how-to-build-a-library-for-angular-apps-4f9b38b0ed11">https://medium.com/@tomsu/how-to-build-a-library-for-angular-apps-4f9b38b0ed11</a>.</p><p>If you are not inserted on publishing your library to npm, you can use the following to consume it:</p><pre>//package.json<br>....<br>&quot;optionalDependencies&quot;: {<br>  &quot;my-app&quot;: &quot;file:dist/my-app&quot;<br>}</pre><p>I also recommend adding a watch script for the library so it will rebuild on every code change, run following npm script in a separate terminal tab.</p><pre>///package.json<br>...<br>&quot;build&quot;: &quot;ng build my-lib --watch&quot;,</pre><h3>3. Unit Testing :</h3><p>Angular comes out of the box with unit testing configuration but you can add some settings to make your life a bit easier.</p><p>Add the following script :</p><pre>//package.json<br>...<br>scripts: {</pre><pre>&quot;unit-test:my-app:code-coverage&quot;: &quot;ng test --project=my-app --code-coverage --reporters=spec&quot;,<br>    &quot;unit-test:my-app&quot;: &quot;ng test --project=my-app  --reporters=spec,kjhtml&quot;</pre><pre>}</pre><p>Using flag “code-coverage” generates a index.html that shows you a breakdown of all your coverage per component / service.</p><p>This is my config file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/17ebe25f4e6def22016afa469e132eae/href">https://medium.com/media/17ebe25f4e6def22016afa469e132eae/href</a></iframe><p>You will need to install all the plugins. (JUnit is for CI pipeline)</p><p>Also this will open chrome in a full screen with dev tools opened.</p><h3>4. Pre-Commits :</h3><p>We will make a pre commit hook that will run ESLint + Prettier on every commit.</p><p>Install ESlint:</p><pre>npm install --save -dev eslint</pre><p>Config file: (you will need to install all the extends if you use this)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/01ea88ae9ee6eaa760bf61814e0cccdb/href">https://medium.com/media/01ea88ae9ee6eaa760bf61814e0cccdb/href</a></iframe><pre>Install husky:</pre><pre>npm install --save -dev husky<br>npm install --save -dev lint-staged</pre><p>Add the following scripts and config :</p><pre>/package.json<br>...<br>&quot;scripts&quot;: {<br>    &quot;lint:my-app&quot;: &quot;ng lint --fix --project=my-app&quot;,<br>    &quot;lint:my-lib&quot;: &quot;ng lint --fix --project=my-lib&quot;,<br>    ...<br>}<br>...<br>&quot;husky&quot;: {<br>  &quot;hooks&quot;: {<br>      &quot;pre-commit&quot;: &quot;lint-staged --relative&quot;<br>    }<br>},<br>&quot;lint-staged&quot;: {<br>   &quot;*.{js,ts}&quot;: [<br>      &quot;eslint --fix&quot;<br>   ],<br>   &quot;*.{html,scss}&quot;: [<br>      &quot;prettier --write&quot;<br>   ]<br>},</pre><p>Prettier config:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bad9d86aa83e8f89456e93e08bbd77de/href">https://medium.com/media/bad9d86aa83e8f89456e93e08bbd77de/href</a></iframe><h3>5. Path Alias :</h3><p>Defining path alias make it easy to move files around in your project, also the import path looks a lot nicer.</p><pre>//tsconfig.json<br>...<br>&quot;paths&quot;: {<br>   &quot;<a href="http://twitter.com/environments">@environments</a>/*&quot;: [&quot;projects/my-app/src/environments/*&quot;],<br>   &quot;<a href="http://twitter.com/pages">@pages</a>/*&quot;: [&quot;projects/my-app/src/app/pages/*&quot;],<br>   &quot;my-lib&quot;: [&quot;dist/my-lib&quot;]  <br>}</pre><h3>6. Multiple Environments:</h3><p>Setting up multiple environments such as : production, staging and local. Also, I will show how you can support process env variables such as CI build number to be available in your project.</p><p>Create the following files under my-app/environments:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6b4402e2f09b8162f20a25ab6f2e0089/href">https://medium.com/media/6b4402e2f09b8162f20a25ab6f2e0089/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5ea8ebe1c97dae70bf23374cd22a69f7/href">https://medium.com/media/5ea8ebe1c97dae70bf23374cd22a69f7/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2b596a117580461f14b53bcf9848065b/href">https://medium.com/media/2b596a117580461f14b53bcf9848065b/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f0b445016ed3e7bf5871b9ad452555dd/href">https://medium.com/media/f0b445016ed3e7bf5871b9ad452555dd/href</a></iframe><p>Create a script under root directory:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8674cf8595156303dce6d13c543c99b5/href">https://medium.com/media/8674cf8595156303dce6d13c543c99b5/href</a></iframe><p>Change Angular.json:</p><pre>//angular.json</pre><pre>&quot;projects&quot;: {<br>    &quot;my-lib&quot;: {<br>      ...<br>    },<br>    &quot;my-app&quot;: {<br>      ...<br>      &quot;architect&quot;: {<br>        &quot;build&quot;: {<br>          ...<br>          &quot;configurations&quot;: {<br>            &quot;staging&quot;: {<br>              &quot;fileReplacements&quot;: [<br>                {<br>                  &quot;replace&quot;: &quot;projects/my-app/src/environments/environment.ts&quot;,<br>                  &quot;with&quot;: &quot;projects/my-app/src/environments/environment.staging.ts&quot;<br>                }<br>              ],<br>              ...<br>            },<br>            &quot;production&quot;: {<br>              &quot;fileReplacements&quot;: [<br>                {<br>                  &quot;replace&quot;: &quot;projects/my-app/src/environments/environment.ts&quot;,<br>                  &quot;with&quot;: &quot;projects/my-app/src/environments/environment.production.ts&quot;<br>                }<br>              ],<br>              ....<br>            }<br>       ...<br>}</pre><p>Finally add to your package.json:</p><pre>//package.json<br>...<br>scripts: {<br>...<br>&quot;build-dynamic-env&quot;: &quot;ts-node -O &#39;{\&quot;module\&quot;: \&quot;commonjs\&quot;}&#39; ./generate-dynamic-env.ts&quot;,<br>&quot;build:production&quot;: &quot;npm run build-dynamic-env &amp;&amp; ng build --project=my-app --configuration=production&quot;,<br>    &quot;build:staging&quot;: &quot;npm run build-dynamic-env &amp;&amp; ng build --project=my-app --configuration=staging&quot;,<br>}</pre><p><strong>Thanks for reading! If you got any question let me know in the comments.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fcc40873698a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>