<?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 Sean Haddock on Medium]]></title>
        <description><![CDATA[Stories by Sean Haddock on Medium]]></description>
        <link>https://medium.com/@seanhaddock_60973?source=rss-ead78f1ef34c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*0_qOiGj3ZiRnIJ0qvDxx3g.jpeg</url>
            <title>Stories by Sean Haddock on Medium</title>
            <link>https://medium.com/@seanhaddock_60973?source=rss-ead78f1ef34c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 07:48:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@seanhaddock_60973/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[Code Health]]></title>
            <link>https://blog.stackademic.com/code-health-381157ef00a3?source=rss-ead78f1ef34c------2</link>
            <guid isPermaLink="false">https://medium.com/p/381157ef00a3</guid>
            <category><![CDATA[health-code]]></category>
            <category><![CDATA[best-practice-programming]]></category>
            <category><![CDATA[clean-code]]></category>
            <dc:creator><![CDATA[Sean Haddock]]></dc:creator>
            <pubDate>Fri, 28 Feb 2025 14:19:26 GMT</pubDate>
            <atom:updated>2025-03-03T06:45:42.493Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pcec7pv3mIGcRVxP" /><figcaption>Photo by <a href="https://unsplash.com/@hush52?utm_source=medium&amp;utm_medium=referral">Hush Naidoo Jade Photography</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>One of the things I struggle with in my role is explaining the benefit and justification for spending time bringing code into alignment with generally accepted Software Engineering best practices — especially to non-technical audiences. I like to refer to alignment with best practices as <strong>Code Health</strong>, because I think it is analogous to our own health.</p><p>Often, questions will be asked such as “how much time will this save”, or “what will happen if we don&#39;t do this”. This is somewhat like your doctor giving you advice on healthy living and you saying “OK, but before I commit, I want to know which health problems I will experience if I don’t, and how much better I will feel and how much longer I will live if I do.</p><p>Your doctor can&#39;t give you those answers. What he will do is speak in generalizations and tell you what is <em>likely</em> to happen based on patterns that have been observed in the general population over time. He can also give you <em>reasons</em> why the prescribed steps will help prevent health problems or increase lifespan. But there&#39;s no guarantee that if you do those things, you will live a longer, healthier life, or that if you <em>don&#39;t</em> do them, you will experience certain health problems and die younger. It is <em>general</em> advice based on large population samples.</p><p>We are in a similar situation when it comes to Software Engineering best practices. We can give reasons why following best practices generally yields better results. But we cannot guarantee that following these practices <em>will</em> yield these results or, especially, to what <em>degree</em>. We also cannot guarantee that <em>not</em> following these practices will cause X amount of pain and issues.</p><p>The best that we can offer is that, based on what we know from our experience — but much more from the experience of <em>many </em>software developers over <em>decades — </em>is that following best practices <em>generally</em> results in fewer bugs, faster time-to-market, more maintainable code and a more enjoyable development experience for <em>most</em> teams and projects.</p><p>Just as with our own health, we must decide if we want to follow the consensus advice or try and beat the odds.</p><h3>Thank you for being a part of the community</h3><p><em>Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://x.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>YouTube</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a> | <a href="https://open.spotify.com/show/7qxylRWKhvZwMz2WuEoua0"><strong>Podcast</strong></a> | <a href="https://differ.blog/inplainenglish"><strong>Differ</strong></a></li><li><a href="https://cofeed.app/"><strong>Check out CoFeed, the smart way to stay up-to-date with the latest in tech</strong></a> <strong>🧪</strong></li><li><a href="https://differ.blog/"><strong>Start your own free AI-powered blog on Differ</strong></a> 🚀</li><li><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Join our content creators community on Discord</strong></a> 🧑🏻‍💻</li><li>For more content, visit <a href="https://plainenglish.io/"><strong>plainenglish.io</strong></a> + <a href="https://stackademic.com/"><strong>stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=381157ef00a3" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/code-health-381157ef00a3">Code Health</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[New(ish) Angular Features]]></title>
            <link>https://blog.stackademic.com/new-ish-angular-features-2bde6f726358?source=rss-ead78f1ef34c------2</link>
            <guid isPermaLink="false">https://medium.com/p/2bde6f726358</guid>
            <category><![CDATA[angular-19-new-features]]></category>
            <category><![CDATA[angular-17-features]]></category>
            <category><![CDATA[angular-18-features]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Sean Haddock]]></dc:creator>
            <pubDate>Fri, 14 Feb 2025 21:01:57 GMT</pubDate>
            <atom:updated>2025-02-17T04:47:45.798Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Change is good (photo of coins)" src="https://cdn-images-1.medium.com/max/1024/0*32QEAhhQ8w0AYi4F" /><figcaption>Photo by <a href="https://unsplash.com/@steve_j?utm_source=medium&amp;utm_medium=referral">Steve Johnson</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>There have been so many changes in Angular over the past couple of years that it can be hard for developers to keep up. The 2024 Angular developer survey shows this level of adoption of new features:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/771/1*gGNvo1T9h_zJFKPcoemjYQ.png" /><figcaption>Latest Angular developer survey showing new feature adoption</figcaption></figure><p>In order to help developers on my team remember how and when they should start using some of these new features, I came up with this simple, practical guide:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*8ypsJ99_oQK4UyLtzLBOIw.png" /><figcaption>General rules of thumb for when to use new Angular features</figcaption></figure><blockquote>A way to sum up most of this is that in <strong><em>general</em></strong> you should<em> </em>be using @ <strong><em>more</em></strong> in the template and <strong><em>less</em></strong> in the .ts file.</blockquote><p>⚠️ Note that I am <strong><em>NOT </em></strong>saying that there could never be any <em>exceptions</em> to any of these guidelines— I&#39;m sacrificing completeness for <em>concision</em> and <em>memorability</em> here. These are just <em>general</em> rules of thumb meant to stick in developers’ minds and help them start using the new features — especially those developers who don&#39;t know where to start.</p><p>As with anything, there is nuance to explore once you become better acquainted with these new features.</p><h3>Bibliography</h3><ul><li><a href="https://blog.angular.dev/angular-2025-strategy-9ca333dfc334">Angular 2025 Strategy. For the past two and a half years… | by Minko Gechev | Jan, 2025 | Angular Blog</a></li><li><a href="https://angular.dev/api/core/@if#">@if • Angular</a></li><li><a href="https://angular.dev/api/core/@for">@for • Angular</a></li><li><a href="https://angular.dev/api/core/@switch">@switch • Angular</a></li><li><a href="https://angular.dev/guide/signals#">Signals • Overview • Angular</a></li><li><a href="https://angular.dev/api/core/input">input • Angular</a></li><li><a href="https://angular.dev/api/core/output#">output • Angular</a></li><li><a href="https://angular.dev/api/core/viewChild#">viewChild • Angular</a></li><li><a href="https://angular.dev/api/core/contentChild#">contentChild • Angular</a></li><li><a href="https://angular.dev/api/core/@let">@let • Angular</a></li><li><a href="https://blog.angular.dev/try-out-the-new-signal-input-migrations-80783969ac9d">Try Out the New Signal Input Migrations | by Angular | Jan, 2025 | Angular Blog</a></li></ul><h3>Thank you for being a part of the community</h3><p><em>Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://x.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>YouTube</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a> | <a href="https://open.spotify.com/show/7qxylRWKhvZwMz2WuEoua0"><strong>Podcast</strong></a></li><li><a href="https://cofeed.app/"><strong>Check out CoFeed, the smart way to stay up-to-date with the latest in tech</strong></a> <strong>🧪</strong></li><li><a href="https://differ.blog/"><strong>Start your own free AI-powered blog on Differ</strong></a> 🚀</li><li><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Join our content creators community on Discord</strong></a> 🧑🏻‍💻</li><li>For more content, visit <a href="https://plainenglish.io/"><strong>plainenglish.io</strong></a> + <a href="https://stackademic.com/"><strong>stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2bde6f726358" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/new-ish-angular-features-2bde6f726358">New(ish) Angular Features</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Conduct a Code Review]]></title>
            <link>https://blog.stackademic.com/how-to-conduct-a-code-review-b59b55475169?source=rss-ead78f1ef34c------2</link>
            <guid isPermaLink="false">https://medium.com/p/b59b55475169</guid>
            <category><![CDATA[pull-request-reviews]]></category>
            <category><![CDATA[code-review]]></category>
            <category><![CDATA[mentoring]]></category>
            <category><![CDATA[health-code]]></category>
            <dc:creator><![CDATA[Sean Haddock]]></dc:creator>
            <pubDate>Tue, 27 Aug 2024 14:40:37 GMT</pubDate>
            <atom:updated>2024-08-28T00:54:04.262Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sYVBJQ4nnkC0nKJ0" /><figcaption>Photo by <a href="https://unsplash.com/@grstocks?utm_source=medium&amp;utm_medium=referral">GR Stocks</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>It’s difficult to set down universal best practices for code reviews, that hold irrespective of the context of the company, the developer, the reviewer and the code being reviewed.</p><p>But in this post, I will attempt to lay some out, based on my experience and research and with the assumption that the reviews are being conducted in an environment where code is expected to match objective standards.</p><h3>Be a Considerate Reviewer</h3><p>Let’s start with some guidelines for being the type of reviewer your peers will appreciate and not dread.</p><h4>Keep it Objective</h4><p>A sure-fire way to bog down the SDLC and try the patience of your fellow developers is to make comments like “I would have done it this way” without further clarification as to <em>why</em>. Doing something differently than how the reviewer would have done it does not make it wrong and is not justification for requesting a change.</p><p>There are two broad reasons for making a comment on a PR:</p><ol><li>The code does not follow some objective standard</li><li>A good argument can be made that the code is objectively inferior to an alternative approach</li></ol><p>Be sure to indicate why the comment is being made, and it should be for one of those two reasons.</p><p>Examples:</p><p>❌ “Use a pipe instead.”</p><p>✅ “Use a pipe here because it doesn’t execute unless the inputs change, which makes it more performant in this scenario.”</p><h4>Depersonalize</h4><p>Avoid using the word “you” in code reviews as it can feel accusatory and put the developer on the defensive. Refer to the code and not the coder.</p><p>Examples:</p><p>❌ “You are repeating this code over and over. Put it in a reusable method.”</p><p>✅ “This block of code is repeated multiple times. Can we put it in a reusable method (DRY)?”</p><p>❌ “Why are you not using variables here?”</p><p>✅ “Please use variables for these colors (DRY).”</p><p>Note: Do we really need to indicate here that the reason for the comment is to adhere to the DRY principle? I think it’s a judgment call. Some comments may be so obvious as to not require an explicit reason. Then again, what is obvious to some is not obvious to others, so it doesn’t hurt to be explicit.</p><h4>Differentiate between Suggestions and Requests for Changes</h4><p>Make it clear when you are just suggesting that the developer <em>consider</em> making a change versus when you are actually requesting the change and withholding approval until it’s made (or until it’s mutually agreed that it doesn’t need to be made).</p><p>Examples:</p><p>❌ “Can use functional interceptor”</p><p>✅ “Please use a functional interceptor because that is what Angular now recommends.”</p><p>❌ “Could be split into multiple components”</p><p>✅ “Suggest splitting into multiple components to promote reusability and make them easier to read and maintain.”</p><p>Also, don’t forget to use the appropriate voting options on your platform. Azure DevOps has “Approved with suggestions” and “Wait for author” and Bitbucket has “Request changes”.</p><h4>Respect the Developer’s Time</h4><p>Be reasonably certain about the suggestions you make. Don’t send the developer on a wild-goose chase for something you think you may remember reading about a couple of years ago.</p><h3>Be an Effective Reviewer</h3><p>Now let’s talk about some guidelines for being the type of reviewer that will have an impact on the codebase, the team and the company.</p><h4>Be Critical</h4><p>Don’t be afraid to make comments! As long as you’re being a considerate reviewer, you don’t need to apologize for finding fault or suggesting improvement. Code reviews are about producing a better product and making everyone’s life easier in the long run.</p><p>Never seeing any comments on PRs is a team red flag.</p><h4>Don’t Anticipate Reactions</h4><p>Do not think about how the developer will react to your comments. Again, as long as you are being respectful and objective, you do not need to worry about offending the developer.</p><p>Part of a developer’s growth is learning how to accept critical feedback.</p><h4>Respect Your Time</h4><p>This may vary based on the company, who’s making the change and who’s reviewing, but <em>generally speaking</em> you are not required to pull down, run and perform QA on every PR. Be smart and use your time wisely so that you can review more code and still get your own development done.</p><h4>Don’t Rewrite Code</h4><p>It is the reviewer’s job to make suggestions and request changes, not provide the rewritten code or solve the problem. At the same time, don’t be so vague that the developer doesn’t know what you’re talking about. Be specific.</p><h4>Have a List of Things to Always Check For</h4><p>Consider making a list of things you always need to check for in a code review. Start with general things like: strings that should be constants, inconsistent naming, duplicated code, etc.</p><p>Then include things that are specific to your tech stack. For example, in Angular you might always look for subscriptions that are not cleaned up or the use of *ngIf instead of the newer @if, etc.</p><p>You may have to reference the list at first but eventually the items on it will become internalized and you won’t need to.</p><h3>Why Bother?</h3><p>We have talked about how to perform an effective code review but maybe we should ask the question: Why bother doing code reviews in the first place?</p><p>An obvious answer is to prevent bugs from being introduced. Catching a would-be bug is the best possible outcome of a code review but it is not the only good outcome. It’s like hitting a home run in baseball. It’s great if you do but that’s not the only way to contribute.</p><h4>Code Health</h4><p>Code reviews are also about improving the overall code health of the application. This will help to prevent bugs in the future.</p><p>It’s a bit like our own health. We know that there are things that we can do that will most likely improve our health in the long run because in the aggregate that has proven to be the case.</p><p>So, we know that things like not smoking, watching what we eat, exercising etc., will <em>most likely</em> increase our long-term health, even though there are people who <em>don’t</em> do these things who live to be a hundred and there are people who <em>do</em> them that have health problems anyway. The effects are not universal or immediate, but in the long-term and in the aggregate, studies and experience have shown that these things increase our health and so we do our best to do those things.</p><p>Similarly, there are things that experience shows will contribute to the long-term health of an application and we want to do our best to do those things to prevent problems in both the near and long term. Code reviews are about making sure that code adheres to best practices even if there does not appear to be an <em>immediate </em>impact.</p><h4>Consistency</h4><p>If you work in a shop with multiple applications, the more consistent those applications are with each other, the easier everyone’s life will be. Developers will be able to work on any application with less ramp up time.</p><p>Code reviews aren’t just about preventing <em>bad</em> code. They are also about increasing consistency.</p><h4>Image Matters</h4><p>Why does the military care so much that a soldier’s bunk is made properly and the floor is clean? Why does it matter? I think part of the reason is that cleanliness, structure and orderliness project a certain image and reflect discipline and this has a psychological impact.</p><p>Working on a clean, orderly code base helps to instill pride in the product and encourages a higher level of engagement and effort. Working with sloppy code on the other hand has the opposite effect and just breeds sloppier practices and lowers morale. Why clean my dish when the sink is full of dirty dishes?</p><p>Code reviews are about maintaining that image even if the requested changes don’t have a large and/or immediate impact.</p><h4>Education</h4><p>Finally, code reviews provide an opportunity for education and mentorship. They are a chance to introduce newer developers to established patterns and practices.</p><p>They are also a good place to update the team on the latest trends and best practices.</p><h3>Summary List</h3><ul><li>Keep it Objective</li><li>Depersonalize</li><li>Differentiate between Suggestions and Requests for Changes</li><li>Respect the Developer’s Time</li><li>Be Critical</li><li>Don’t Anticipate Reactions</li><li>Respect Your Time</li><li>Don’t Rewrite Code</li><li>Have a List of Things to Always Check For</li></ul><h3>Stackademic 🎓</h3><p>Thank you for reading until the end. Before you go:</p><ul><li>Please consider <strong>clapping</strong> and <strong>following</strong> the writer! 👏</li><li>Follow us <a href="https://twitter.com/stackademichq"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/stackademic"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/c/stackademic"><strong>YouTube</strong></a> | <a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Discord</strong></a></li><li>Visit our other platforms: <a href="https://plainenglish.io/"><strong>In Plain English</strong></a> | <a href="https://cofeed.app/"><strong>CoFeed</strong></a> | <a href="https://differ.blog/"><strong>Differ</strong></a></li><li>More content at <a href="https://stackademic.com/"><strong>Stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b59b55475169" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/how-to-conduct-a-code-review-b59b55475169">How to Conduct a Code Review</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Lazy Loading Without Angular Modules]]></title>
            <link>https://blog.stackademic.com/lazy-loading-without-angular-modules-bb853bd7991d?source=rss-ead78f1ef34c------2</link>
            <guid isPermaLink="false">https://medium.com/p/bb853bd7991d</guid>
            <category><![CDATA[route]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[lazy-load-component]]></category>
            <category><![CDATA[modules]]></category>
            <category><![CDATA[lazy-loading]]></category>
            <dc:creator><![CDATA[Sean Haddock]]></dc:creator>
            <pubDate>Thu, 08 Aug 2024 15:22:18 GMT</pubDate>
            <atom:updated>2024-08-09T00:40:58.299Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rFU4BlsFz4A2T0sX" /><figcaption>Photo by <a href="https://unsplash.com/@priscilladupreez?utm_source=medium&amp;utm_medium=referral">Priscilla Du Preez 🇨🇦</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>The Angular team now recommends using standalone components for all new development. This does not mean that you can no longer use modules, but one thing you do not need to use Angular modules for is lazy loading.</p><p>Lazy loading means that a component or group of components will be output to a separate JavaScript chunk and will only be loaded from the server when the user navigates to the route that needs them. This can improve initial load times by not retrieving <em>all</em> of the bytes needed by the application when it is initially loaded. Additionally, the user may never go to some routes and so some of those chunks may <em>never</em> need to be loaded.</p><p>In this post we’ll look at how to do lazy loading without Angular modules. The code samples were created with Angular 18.</p><h3>Lazy Loading a Component</h3><p>You can lazy load a single standalone component like this:</p><pre>// app.routes.ts<br><br>import { Routes } from &#39;@angular/router&#39;;<br><br>export const routes: Routes = [<br>  {<br>    path: &#39;about&#39;,<br>    loadComponent: () =&gt;<br>      import(&#39;./about/about.component&#39;).then((m) =&gt; m.AboutComponent),<br>  }<br>];</pre><p>The route definition has the familiar path property, but instead of the component property we see the loadComponent property. The loadComponent property takes a function that loads a module (but <strong><em>not</em></strong> an <strong><em>Angular</em></strong> module) and then returns the AboutComponent from that (<strong><em>non-Angular</em></strong>) module.</p><p>When we run ng serve, we see from the terminal output that the AboutComponent has been placed in its own chunk:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/386/1*Uq96xW8XYzZY1mF8FU6W-w.png" /><figcaption>ng serve output showing the AboutComponent in its own chunk</figcaption></figure><p>Next, we open the browser, navigate to the Network tab in dev tools and clear the history. When we then navigate to /about, we can see this same chunk get retrieved from the server:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*i_cdqZZQMIkbZpl8M3ieJQ.png" /><figcaption>Network tab showing the AboutComponent chunk getting loaded</figcaption></figure><p>Note that you must navigate using routerLink to observe the lazy loading behavior. If you enter the URL in the address bar it will reload the site.</p><h3>Lazy Loading a Group of Components</h3><p>Most of the time you will probably want to load a group of components corresponding to a feature of your application, such as Admin. We don’t need an Angular module to group the components in the Admin feature — a folder works just as well for grouping.</p><p>You organize your application without Angular modules the same way you did with modules — you just don’t have the [feature].module or the [feature]-routing.module files. Instead, for our Admin feature we just need an admin-routes.ts file:</p><pre>// admin-routes.ts<br><br>import { Route } from &#39;@angular/router&#39;;<br>import { UsersComponent } from &#39;./users/users.component&#39;;<br>import { AdminHomeComponent } from &#39;./admin-home/admin-home.component&#39;;<br><br>export default [<br>  { path: &#39;home&#39;, component: AdminHomeComponent },<br>  { path: &#39;users&#39;, component: UsersComponent },<br>] satisfies Route[];</pre><p>This is just a normal routes array. We are exporting the array as the default export from this file (module) and using satisfies so that we can define and export in one statement.</p><p>Back in the app.routes file, we use loadChildren to load these routes under the admin path (e.g., admin/home):</p><pre>// app.routes.ts<br><br>import { Routes } from &#39;@angular/router&#39;;<br><br>export const routes: Routes = [<br>  {<br>    path: &#39;about&#39;,<br>    loadComponent: () =&gt;<br>      import(&#39;./about/about.component&#39;).then((m) =&gt; m.AboutComponent),<br>  },<br>  {<br>    path: &#39;admin&#39;,<br>    loadChildren: () =&gt; import(&#39;./admin/admin-routes&#39;),<br>  },<br>];</pre><p>Now the terminal output from ng serve shows that the components for these two admin routes have been chunked separately:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/347/1*WEm60uM_D4irWQaCuTpZEQ.png" /><figcaption>ng serve output showing the admin route components in their own chunk</figcaption></figure><p>Once again, in dev tools when we navigate to /admin/home we can see this same chunk get retrieved from the server:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*lzE3-e8_a8dpQjxiRcZNKg.png" /><figcaption>Network tab showing the admin routes chunk getting loaded</figcaption></figure><h3>Bibliography</h3><ul><li><a href="https://v17.angular.io/guide/standalone-components#routing-and-lazy-loading">Angular — Getting started with standalone components</a> (this is the older site, but at time of writing I can’t find the same doc on the new site)</li><li><a href="https://angular.dev/guide/components/importing#standalone-components">Importing and using components • Angular</a></li></ul><h3>Stackademic 🎓</h3><p>Thank you for reading until the end. Before you go:</p><ul><li>Please consider <strong>clapping</strong> and <strong>following</strong> the writer! 👏</li><li>Follow us <a href="https://twitter.com/stackademichq"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/stackademic"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/c/stackademic"><strong>YouTube</strong></a> | <a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Discord</strong></a></li><li>Visit our other platforms: <a href="https://plainenglish.io/"><strong>In Plain English</strong></a> | <a href="https://cofeed.app/"><strong>CoFeed</strong></a> | <a href="https://differ.blog/"><strong>Differ</strong></a></li><li>More content at <a href="https://stackademic.com/"><strong>Stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bb853bd7991d" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/lazy-loading-without-angular-modules-bb853bd7991d">Lazy Loading Without Angular Modules</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implementing ControlValueAccessor for a Custom Control]]></title>
            <link>https://blog.stackademic.com/implementing-controlvalueaccessor-for-a-custom-control-b28159551f1d?source=rss-ead78f1ef34c------2</link>
            <guid isPermaLink="false">https://medium.com/p/b28159551f1d</guid>
            <category><![CDATA[custom-component]]></category>
            <category><![CDATA[components]]></category>
            <category><![CDATA[controlvalueaccessor]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Sean Haddock]]></dc:creator>
            <pubDate>Thu, 27 Jun 2024 15:23:21 GMT</pubDate>
            <atom:updated>2024-07-09T02:31:48.905Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ffwy6xaIfMPe9eyX" /><figcaption>Photo by <a href="https://unsplash.com/@toqeerakk?utm_source=medium&amp;utm_medium=referral">Muhammad Toqeer</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In this post I want to walk through how to implement the ControlValueAccessor interface for a custom control.</p><h3>Why?</h3><p>First off, when would you need to do this? You need to implement the ControlValueAccessor interface anytime you need your custom control to integrate with Angular forms — either Template Driven or Reactive.</p><p>Consider the two form examples below:</p><pre>&lt;!-- Template Driven --&gt;<br>&lt;form&gt;<br>  &lt;my-time-picker [(ngModel)]=&quot;time&quot; name=&quot;time&quot;&gt;&lt;/my-time-picker&gt;<br>&lt;/form&gt;<br><br>&lt;!-- Reactive --&gt;<br>&lt;form [formGroup]=&quot;timeForm&quot;&gt;<br>  &lt;my-time-picker formControlName=&quot;time&quot;&gt;&lt;/my-time-picker&gt;<br>&lt;/form&gt;</pre><p>The &lt;form&gt;s are just HTML, but the [(ngModel)], [formGroup]=&quot;timeForm&quot; and formControlName=&quot;time&quot; pieces are what make them Angular Forms. These allow you to work with the forms in an Angular way--data binding, Angular validators, testing, etc. This is not possible without implementing the ControlValueAccessor interface.</p><h3>The Control</h3><p>Let’s say we have a simple time control called TimePickerComponent with four inputs for hours, minutes and AM/PM:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/229/1*K1dvBHBZJ3kfopqO2cjheg.png" /><figcaption>Example Time Control</figcaption></figure><p>And we have event handlers for when each of those inputs change:</p><pre>onHourChange(hour: number): void {<br>  <br>}<br><br>onMinuteChange(minute: number): void {<br>  <br>}<br><br>onAmPmChange(amPm: AmPm): void {<br>  <br>}</pre><p>Now let’s implement the interface.</p><h3>ControlValueAccessor</h3><p>First a caveat. <strong>Implementing a robust time control requires a lot of logic and validation that I am going to omit so that I can just focus on the implementation of the interface.</strong> The scope of this article is just demonstrating how to implement the ControlValueAccessor interface, not how to create a robust, fully functional time control.</p><p>We start by providing our component for the NG_VALUE_ACCESSOR. We do this in the component itself, in the Component decorator:</p><pre>providers: [<br>  {<br>    provide: NG_VALUE_ACCESSOR,<br>    useExisting: TimePickerComponent,<br>    multi: true,<br>  },<br>],</pre><p>Next, we implement the ControlValueAccessor interface which gives us the following methods to be fleshed out:</p><pre>writeValue(obj: any): void {<br>  throw new Error(&#39;Method not implemented.&#39;);<br>}<br>registerOnChange(fn: any): void {<br>  throw new Error(&#39;Method not implemented.&#39;);<br>}<br>registerOnTouched(fn: any): void {<br>  throw new Error(&#39;Method not implemented.&#39;);<br>}<br>setDisabledState?(isDisabled: boolean): void {<br>  throw new Error(&#39;Method not implemented.&#39;);<br>}</pre><p>Let’s deal with each in turn.</p><h3>writeValue</h3><p>The writeValue method is called when the consumer of the component gives us a value to display in our control.</p><p>A form control accepts a single value, so we need to represent the time value of our control as a single value and in this example, we’re going to use an ISO 8601 string.</p><p>That means, in the writeValue method, we will receive an ISO string and we will then parse it out to set our hour, minute, and AM/PM internally so that they display in their respective inputs.</p><p>An implementation might look like this (with error handling/validation omitted):</p><pre>writeValue(time: string | null): void {<br>  if (time) {<br>    const date = new Date(time);<br><br>    this.hour = date.getHours();<br>    this.minute = date.getMinutes();<br>    this.setAmPm();<br>  } else {<br>    this.resetTime();<br>  }<br>}</pre><h3>registerOnChange</h3><p>This method accepts a callback function that is called when the value is changed in the UI by the user. This is the counterpart to writeValue. The writeValue method updates the view from the model. The registerOnChange callback updates the model from the view.</p><p>We must do two things:</p><p>Store the callback function:</p><pre>onChange: any = () =&gt; {};<br><br>registerOnChange(fn: any): void {<br>  this.onChange = fn;<br>}</pre><p>Call it when the UI changes:</p><pre>onHourChange(hour: number): void {<br>  this.updateValue();<br>}<br><br>onMinuteChange(minute: number): void {<br>  this.updateValue();  <br>}<br><br>onAmPmChange(amPm: AmPm): void {<br>  this.updateValue();<br>}<br><br>updateValue(): void {<br>  let isoString = null;<br><br>  // logic to convert the values of the inputs to an ISO string<br>  <br>  this.onChange(isoString);  <br>}</pre><h3>registerOnTouched</h3><p>This is the equivalent of registerOnChange except it’s for when the control is “touched.” Again, we must do two things:</p><p>Store the callback function:</p><pre>onTouched: any = () =&gt; {};<br><br>registerOnTouched(fn: any): void {<br>  this.onTouched = fn;<br>}</pre><p>Call it when the UI changes or any of the inputs are blurred:</p><pre>updateValue(): void {<br>  // code for onChange  <br><br>  this.onTouched();<br>}<br><br>handleBlur(): void {<br>  this.onTouched();<br>}<br><br>// in template, (blur)=&quot;handleBlur()&quot;</pre><h3>setDisabledState</h3><p>Finally, when our custom control is disabled, we need to disable each of our 4 inputs. We do that by implementing setDisabledState:</p><pre>setDisabledState(isDisabled: boolean): void {<br>  this.disabled = isDisabled;<br>}<br><br>// each of the 4 inputs then sets their disabled = this.disabled--i.e., <br>// [disabled]=&quot;disabled&quot;</pre><h3>Conclusion</h3><p>Now our custom time component can be used in an Angular form like any other form control. Again, there is much work left to be done to make the time component robust and fully functional, but this article has shown the minimum required to allow it to be integrated with Angular Forms.</p><h3>Bibliography</h3><ul><li><a href="https://angular.dev/api/forms/ControlValueAccessor">Angular</a></li></ul><h3>Stackademic 🎓</h3><p>Thank you for reading until the end. Before you go:</p><ul><li>Please consider <strong>clapping</strong> and <strong>following</strong> the writer! 👏</li><li>Follow us <a href="https://twitter.com/stackademichq"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/stackademic"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/c/stackademic"><strong>YouTube</strong></a> | <a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Discord</strong></a></li><li>Visit our other platforms: <a href="https://plainenglish.io/"><strong>In Plain English</strong></a> | <a href="https://cofeed.app/"><strong>CoFeed</strong></a> | <a href="https://differ.blog/"><strong>Differ</strong></a></li><li>More content at <a href="https://stackademic.com/"><strong>Stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b28159551f1d" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/implementing-controlvalueaccessor-for-a-custom-control-b28159551f1d">Implementing ControlValueAccessor for a Custom Control</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Global State Management Options in Angular]]></title>
            <link>https://blog.stackademic.com/global-state-management-options-in-angular-c063214380d0?source=rss-ead78f1ef34c------2</link>
            <guid isPermaLink="false">https://medium.com/p/c063214380d0</guid>
            <category><![CDATA[ngrx]]></category>
            <category><![CDATA[state-management]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[signalstore]]></category>
            <category><![CDATA[signal]]></category>
            <dc:creator><![CDATA[Sean Haddock]]></dc:creator>
            <pubDate>Fri, 26 Apr 2024 16:25:43 GMT</pubDate>
            <atom:updated>2024-04-29T00:41:26.397Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Cbi6v9NqX1rNMyw-" /><figcaption>Photo by <a href="https://unsplash.com/@kylejglenn?utm_source=medium&amp;utm_medium=referral">Kyle Glenn</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In this post I want to run through the various state management options we now have available in Angular.</p><h3>What is State?</h3><p>First, what <em>is</em> state? State is any piece of information about the application at a given point in time.</p><p><em>Shared</em> (or Global) state, is state that is shared among multiple components.</p><p>An important thing to keep in mind is that not all state needs to be shared! But if a piece of state needs to be shared beyond a parent and child component, you will need an option for global state management.</p><h3><strong>Requirements for State Management</strong></h3><p>Requirements for State Management will vary by application, but I’m going to use the following when evaluating the different state management options:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SAaHKj4ixr5_skRrnxYY1w.png" /><figcaption>Requirements for State Management</figcaption></figure><p>Of these requirements, the first is the most important and it’s a deal breaker if it is not met.</p><h3>Options for State Management in Angular</h3><p>In Angular we have the following options for state management:</p><p>1.Every component loads the state it needs from the API</p><p>2.Inputs and Outputs</p><p>3.Variables in Services</p><p>4.Observables in Services</p><p>5.NgRx</p><p>6.Signals in Services</p><p>7.NgRx Signal Store</p><p>Let’s quickly review how each of these options fulfills our requirements.</p><h3>Every component loads the state it needs from the API</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mifBC3WoXciKzQFAz0y26w.png" /><figcaption>Every component loads the state it needs from API</figcaption></figure><p>This method would likely be the first one tried by new developers. It’s easy at first but becomes complicated as the application grows.</p><p>In addition, it fails to satisfy nearly all of our requirements, including the first one which is a deal breaker.</p><h3>Inputs and Outputs</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WAl_t3ySgLUnc-o15NOMhw.png" /><figcaption>Inputs and Outputs</figcaption></figure><p>The next option, Inputs and Outputs, fairs a little better but still fails to meet half of our requirements.</p><p>Again, it fails to meet our first requirement because although we can theoretically achieve consistent state that updates multiple components and routes without re-retrieving data, this approach is anything but easy to follow.</p><p>Passing data far down a component tree, and daisy-chaining the events back up becomes very difficult to follow and maintain, which is the biggest knock against this approach.</p><h3>Variables in Services</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P3W2e9MDH1c2uDZYzjXaBA.png" /><figcaption>Variables in Services</figcaption></figure><p>This option is a huge leap forward over the previous two. However, it still only meets half of our requirements.</p><p>Notable failures are that it doesn’t work with OnPush Change Detection (without extra work) and it can be difficult to run business logic when state changes. Sometimes you need to introduce a component input to pass in the service variable so that you can do something in ngOnChanges.</p><h3>Observables in Services</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*78fIziDlke9iZw08VX5-1w.png" /><figcaption>Observables in Services</figcaption></figure><p>With this option, we are now entering the realm of acceptable solutions. It only fails on two requirements.</p><p>I think it’s pretty non-controversial to say that learning how to work with observables is difficult, especially for those new to Angular or JavaScript in general. That doesn’t mean you shouldn’t use it of course. It’s just that, all things being equal, something that is easy to use would be preferable to something that is more difficult.</p><p>Also, I think having the service be responsible for both performing CRUD operations against the API and state management does not adhere as closely to the Single-Responsibility principal as it could.</p><h3>NgRx</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F52qAoOcc3tGbU-yPaIZRA.png" /><figcaption>NgRx</figcaption></figure><p>I think using NgRx is a step above implementing your own Subject-in-a-Service pattern because it makes it easier to maintain consistency across the code base and it better adheres to the Single-Responsibility principal.</p><p>But it’s not easy. Again, I’m not suggesting that we only do things that are easy. Sometimes difficult problems require difficult solutions. But if there’s an easier path that’s just as good, why not take it?</p><h3>Signals in Services</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J_JKhdS0MySGFGq9pZkZsw.png" /><figcaption>Signals in Services</figcaption></figure><p>I think using signals in services is a good alternative to observables in services because they are easier to use and adequate for most circumstances.</p><p>The only knock against this approach is, again, that I don’t think it adheres to the Single-Responsibility principle as well as it could, since the services are responsible both for CRUD operations and managing state.</p><h3>NgRx Signal Store</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bEOJ7BSsSYNk5_XWeXtfAQ.png" /><figcaption>NgRx Signal Store</figcaption></figure><p>Finally, I think the Signal Store may be the best option going forward. I think it is the only approach that checks all of our requirement boxes, although I could see someone making the argument that the previous three approaches do as well. But as I’ve said, I think the previous three approaches fall just <em>slightly</em> short.</p><h3>Other Advantages with NgRx Signal Store</h3><p>In addition, I think there are other advantages to using the Signal Store.</p><p>The first is, why reinvent the wheel? Of course, you could implement the same functionality on your own, but I just feel like if there is already a tool dedicated to that functionality, and it’s easy to use, why not use it? Also, I think it makes it harder to deviate from a common pattern which is helpful in large teams with developers of mixed experience.</p><p>A second advantage I see is that it is championed by leaders in the Angular community. I am a big believer in leaning on the experience of the community. I know there are developers who have implemented many applications of many different types, so I always like to take advantage of lessons they’ve learned.</p><p>A third advantage is the use of <a href="https://microsoftedge.microsoft.com/addons/detail/redux-devtools/nnkgneoiohoecpdiaponcejilbhhikei">Redux DevTools</a> that allow you to see the state change in the application. Currently this is offered through the <a href="https://github.com/angular-architects/ngrx-toolkit">ngrx-toolkit</a>.</p><p>Finally, I think the Signal Store offers some helpful features. The first I’ll mention is <a href="https://ngrx.io/api/signals/rxjs-interop/rxMethod">rxMethod</a>, which makes it trivial to prevent multiple HTTP calls when loading state into the store:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/593/1*hYKmWYdzkzqt2_STjMwDog.png" /><figcaption>rxMethod</figcaption></figure><p>Here we can easily add a debounceTime() operator, without having to create an additional observable just so that we can debounce the load call. Again, it’s not that you couldn’t create your own observable to do this, but I think being able to use it in this way is cleaner and easier.</p><p>The second set of features I’ll mention is DeepSignals and patchState. I think the benefit of these is best illustrated by a comparison with the signals in a service approach.</p><p>With the Signal Store, you can update state individually or as a whole but still always read each slice as individual signals:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o_JNodzcXf5wy3eFxECSNA.png" /><figcaption>Updating state with Signal Store</figcaption></figure><p>With signals in a service, to mimic the behavior of the effect() above, you either have to create a signal for each piece of state individually, which means you have to update them individually:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*LLj-wwF3dI84gPcCF0n6EA.png" /><figcaption>Updating state individually with Signals in a Service</figcaption></figure><p>Or you can manually make each property of a complex object a signal, which is more verbose:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/961/1*CyXGoTkvLOjRooWceZADyg.png" /><figcaption>Complex object in state with Signals in a Service</figcaption></figure><p>With the Signal Store, UserState is a DeepSignal which means that each property is also a signal, so that you don’t have to declare and set each signal property in the verbose way above.</p><p>So, these are a couple of helpful features we already get with the Signal Store, and I’d be willing to bet there will be more in the future.</p><h3>Option Ranking</h3><p>Given all I’ve said above, this is how I would rank the options:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I57p4Pd1pixERTeAfy25xQ.png" /><figcaption>Option Ranking</figcaption></figure><p>Again, starting with the Observables in Services approach we enter the realm of acceptable solutions. From there, we only achieve incremental gains, but I think gains, nonetheless.</p><p>Even if a solution is only <em>slightly </em>better why not use it if it’s not any more difficult and does not introduce additional complexity? I would place the NgRx Signal Store in this category.</p><h3>Bibliography</h3><ul><li><a href="https://ngrx.io/guide/signals/signal-store">NgRx — SignalStore</a></li></ul><h3>Stackademic 🎓</h3><p>Thank you for reading until the end. Before you go:</p><ul><li>Please consider <strong>clapping</strong> and <strong>following</strong> the writer! 👏</li><li>Follow us <a href="https://twitter.com/stackademichq"><strong>X</strong></a><strong> | </strong><a href="https://www.linkedin.com/company/stackademic"><strong>LinkedIn</strong></a><strong> | </strong><a href="https://www.youtube.com/c/stackademic"><strong>YouTube</strong></a><strong> | </strong><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Discord</strong></a></li><li>Visit our other platforms: <a href="https://plainenglish.io/"><strong>In Plain English</strong></a><strong> | </strong><a href="https://cofeed.app/"><strong>CoFeed</strong></a><strong> | </strong><a href="https://venturemagazine.net/"><strong>Venture</strong></a><strong> | </strong><a href="https://blog.cubed.run/"><strong>Cubed</strong></a></li><li>More content at <a href="https://stackademic.com/"><strong>Stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c063214380d0" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/global-state-management-options-in-angular-c063214380d0">Global State Management Options in Angular</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular Signals]]></title>
            <link>https://blog.stackademic.com/angular-signals-6cb8d68fe385?source=rss-ead78f1ef34c------2</link>
            <guid isPermaLink="false">https://medium.com/p/6cb8d68fe385</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[change-detection]]></category>
            <category><![CDATA[onpush]]></category>
            <category><![CDATA[signal]]></category>
            <dc:creator><![CDATA[Sean Haddock]]></dc:creator>
            <pubDate>Fri, 16 Feb 2024 14:20:41 GMT</pubDate>
            <atom:updated>2024-02-19T01:33:45.799Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DIUYXf61Of4M_yJB" /><figcaption>Photo by <a href="https://unsplash.com/@jsshotz?utm_source=medium&amp;utm_medium=referral">Jorge Salvador</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>There is no shortage of articles about Angular signals. But here’s another one. Signals are one of the most popular new Angular features to be introduced recently. The description of signals from the documentation can’t really be improved:</p><blockquote>Angular Signals is a system that granularly tracks how and where your state is used throughout an application, allowing the framework to optimize rendering updates.</blockquote><p><strong>Signals are basically just properties that let you know when they change.</strong></p><p>I think there are two reasons why signals are important:</p><ol><li>They are easier to learn and use than observables and are adequate for <em>most </em>use cases.</li><li>They allow Angular to be more granular about change detection which is more performant and <em>might </em>lead to the eventual removal of zone-based change detection.</li></ol><p>Let’s dive in.</p><h3>The Simplest Possible Example</h3><p>I’m starting with a brand new Angular 17 application.</p><p>You create a signal by calling the signal() function:</p><pre>import { signal } from &#39;@angular/core&#39;;<br>.<br>.<br>cartItems = signal(0);</pre><p>You then read the value in the template like so:</p><pre>My Cart: {{ cartItems() }}</pre><p>Probably the two biggest things to get used to are contained right there in this simple example:</p><ol><li>You call a<em> function</em> to instantiate the signal (signal(0)).</li><li>A signal <em>is</em> a function, so you <em>call</em> it to read it (cartItems()).</li></ol><h3>Updating the Signal</h3><p>If the signal is writable (which it is by default) you can update it in one of two ways:</p><pre>this.cartItems.set(1);<br>//OR<br>this.cartItems.update((value) =&gt; value + 1);</pre><p>Note that My Cart: {{ cartItems() }} will update every time the value changes — you don’t have to do anything else.</p><h3>Computed Signal</h3><p>A computed signal is just like a computed property or a computed database column. Its value is derived from one or more <em>other</em> signals. If we pretend we only sell one item and it costs $10, we can create a subtotal computed signal as follows:</p><pre>import { computed } from &#39;@angular/core&#39;;<br>.<br>.<br>subTotal = computed(() =&gt; {<br>    return this.cartItems() * 10;<br>});</pre><p>Note that the computed function does not take any parameters. It just references the input signal(s) like any other function in the class would.</p><h3>Effects</h3><p>The last feature of signals that we will discuss are effects. Effects allow you to respond and perform actions when a signal value changes. The following effect writes a message to the console every time the <em>cartItems</em> signal is updated:</p><pre>effect(() =&gt; {<br>  console.log(&#39;Cart Items Updated:&#39;, this.cartItems());<br>});</pre><p>Note that we are not subscribing to cartItems or anything of that sort. Just referencing it is enough to make the effect monitor it for changes.</p><p>Also note that as written above, the effect would have to be put in the constructor so that it has access to an injection context.</p><p>To place the effect outside of the constructor you could assign it to a field:</p><pre>cartItemsUpdated = effect(() =&gt; {<br>  console.log(&#39;Cart Items Updated:&#39;, this.cartItems());<br>});</pre><h3>Can’t we do all this with properties?</h3><p>Yes and no. We <em>can</em> achieve what we have done with properties. Here is a full example of one way you could do it (with additional code to make the cartItems signal update at an interval):</p><pre>import { Component, OnInit, ChangeDetectionStrategy } from &#39;@angular/core&#39;;<br>import { RouterOutlet } from &#39;@angular/router&#39;;<br><br>@Component({<br>  selector: &#39;app-root&#39;,<br>  standalone: true,<br>  imports: [RouterOutlet],<br>  template: `My Cart: {{ cartItems }} Sub Total: {{ subTotal }}`,<br>  styleUrl: &#39;./app.component.scss&#39;,<br>})<br>export class AppComponent implements OnInit {<br>  #cartItems = 0;<br>  get cartItems() {<br>    return this.#cartItems;<br>  }<br>  set cartItems(value) {<br>    this.#cartItems = value;<br>    console.log(&#39;Cart Items Updated:&#39;, value);<br>  }<br><br>  get subTotal() {<br>    return this.cartItems * 10;<br>  }<br><br>  ngOnInit() {<br>    let counter = 0;<br>    const intervalId = setInterval(() =&gt; {<br>      counter++;<br>      this.cartItems = counter;<br>    }, 1000);<br>  }<br>}</pre><p>This works…until you implement OnPush change detection. Setting change detection to OnPush allows Angular change detection to run less often, resulting in more performant applications. From Angular:</p><blockquote>Change detection is sufficiently fast for most applications. However, when an application has an especially large component tree, running change detection across the whole application can cause performance issues. You can address this by configuring change detection to only run on a subset of the component tree.</blockquote><blockquote>If you are confident that a part of the application is not affected by a state change, you can use <a href="https://angular.io/api/core/ChangeDetectionStrategy">OnPush</a> to skip change detection in an entire component subtree.</blockquote><p>Let’s implement OnPush and see what happens:</p><pre>import { ChangeDetectionStrategy } from &#39;@angular/core&#39;;<br>.<br>.<br>@Component({<br>  .<br>  .<br>  changeDetection: ChangeDetectionStrategy.OnPush,<br>})</pre><p>Now it no longer works (template does not update), unless you manually tell Angular to run the change detection cycle:</p><pre>import { ChangeDetectorRef } from &#39;@angular/core&#39;;<br>.<br>.<br>#changeDetectorRef = inject(ChangeDetectorRef);<br>.<br>.<br>set cartItems(value) {<br>  .<br>  .<br>  this.#changeDetectorRef.markForCheck();<br>  .<br>  .<br>}</pre><p>Now the template is updating again.</p><p>But if we use signals, we don’t have to do those extra steps — it just works.</p><p>Here is the same solution implemented with signals:</p><pre>import {<br>  Component,<br>  OnInit,<br>  computed,<br>  signal,<br>  effect,<br>  ChangeDetectionStrategy,<br>} from &#39;@angular/core&#39;;<br>import { RouterOutlet } from &#39;@angular/router&#39;;<br><br>@Component({<br>  selector: &#39;app-root&#39;,<br>  standalone: true,<br>  imports: [RouterOutlet],<br>  template: `My Cart: {{ cartItems() }} Sub Total: {{ subTotal() }}`,<br>  styleUrl: &#39;./app.component.scss&#39;,<br>  changeDetection: ChangeDetectionStrategy.OnPush,<br>})<br>export class AppComponent implements OnInit {<br>  cartItems = signal(0);<br><br>  subTotal = computed(() =&gt; {<br>    return this.cartItems() * 10;<br>  });<br><br>  constructor() {<br>    effect(() =&gt; {<br>      console.log(&#39;Cart Items Updated:&#39;, this.cartItems());<br>    });<br>  }<br><br>  ngOnInit() {<br>    let counter = 0;<br>    const intervalId = setInterval(() =&gt; {<br>      counter++;<br>      this.cartItems.set(counter);<br>    }, 1000);<br>  }<br>}</pre><p>And here is the diff between the two:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pSPaxmAstsHQGPFyecyeKQ.png" /><figcaption>Diff between property and signal solutions</figcaption></figure><h3>Conclusion</h3><p>So, should you start using signals? Yes (on Angular 17+).</p><p>While you could argue that it’s not <em>that</em> much easier/less verbose than properties (or even RxJS if you’re already very familiar with it), or that your application doesn’t really <em>need</em> OnPush change detection, I would argue:</p><ol><li>I think it’s clear that signals are at least <em>somewhat</em> simpler/less verbose under certain scenarios, and techniques that are simpler and less verbose tend to win in the long run.</li><li>Maybe you don’t <em>have</em> to implement OnPush, but why not make your application more performant if the development cost is very low?</li><li>I think it’s possible that in the future you will be required to use signals in order to achieve reactivity in Angular. I think the fine-grained reactivity that signals provide are going to allow the Angular team to introduce new powerful features that will be dependent upon signals.</li></ol><blockquote>Signals are basically just properties that let you know when they change.</blockquote><h3>Bibliography</h3><ul><li><a href="https://angular.io/guide/signals">Angular — Angular Signals</a></li><li><a href="https://angular.io/guide/change-detection-skipping-subtrees">Angular — Skipping component subtrees</a></li></ul><h3>Stackademic 🎓</h3><p>Thank you for reading until the end. Before you go:</p><ul><li>Please consider <strong>clapping</strong> and <strong>following</strong> the writer! 👏</li><li>Follow us <a href="https://twitter.com/stackademichq"><strong>X</strong></a><strong> | </strong><a href="https://www.linkedin.com/company/stackademic"><strong>LinkedIn</strong></a><strong> | </strong><a href="https://www.youtube.com/c/stackademic"><strong>YouTube</strong></a><strong> | </strong><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Discord</strong></a></li><li>Visit our other platforms: <a href="https://plainenglish.io/"><strong>In Plain English</strong></a><strong> | </strong><a href="https://cofeed.app/"><strong>CoFeed</strong></a><strong> | </strong><a href="https://venturemagazine.net/"><strong>Venture</strong></a><strong> | </strong><a href="https://blog.cubed.run/"><strong>Cubed</strong></a></li><li>More content at <a href="https://stackademic.com/"><strong>Stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6cb8d68fe385" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/angular-signals-6cb8d68fe385">Angular Signals</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Converting an Angular Project to Standalone]]></title>
            <link>https://blog.stackademic.com/converting-an-angular-project-to-standalone-ceb00669f9ec?source=rss-ead78f1ef34c------2</link>
            <guid isPermaLink="false">https://medium.com/p/ceb00669f9ec</guid>
            <category><![CDATA[standalone]]></category>
            <category><![CDATA[standalone-component]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Sean Haddock]]></dc:creator>
            <pubDate>Thu, 04 Jan 2024 19:34:32 GMT</pubDate>
            <atom:updated>2024-01-05T01:30:27.212Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3GOtowrdwv-WOJL5" /><figcaption>Photo by <a href="https://unsplash.com/@anthonytori?utm_source=medium&amp;utm_medium=referral">Anthony Tori</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Standalone is the future of Angular and is now the default when scaffolding a new application. In the latest Angular Developer Survey, 96% of respondents reported that they use the latest standalone APIs. In this post I want to walk through migrating an Angular module-based application to standalone in order to highlight the differences.</p><h3>App Setup</h3><p>For this post I’m going to start with the Tour of Heroes application which can be downloaded <a href="https://angular.io/generated/zips/toh-pt6/toh-pt6.zip">here</a>.</p><p>Once downloaded, update the typescript dependency in package.json to version ~5.2.0:</p><p>“typescript”: “~5.2.0”</p><p>Next, run npm i --legacy-peer-deps &amp; npm run start to see the working application.</p><h3>Migrating The Components</h3><p>First, we will migrate all of the components to standalone. Run: ng g @angular/core:standalone and choose the first option:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/446/1*QpU_QRhM_q68RCFjtRdY3w.png" /><figcaption>Running the migration schematic and choosing the first option</figcaption></figure><p>Next, choose root path by pressing Enter:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*QQ3WT7Dlj_BwxIKKnzmrzQ.png" /><figcaption>Choosing the root path</figcaption></figure><p>Let’s examine the changes. First, look at app.module.ts and notice that the components are no longer <em>declared</em> in the app module:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/763/1*MQEKdJs7-hyQjdUVMMm4ew.png" /><figcaption>Components are no longer declared in the AppModule</figcaption></figure><p>Instead, they are now <em>imported</em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/251/1*a-ogD4C_sIqFhpK7J3RGZA.png" /><figcaption>Components are imported in the AppModule</figcaption></figure><p>Next, look at dashboard.component.spec.ts and observe that components also have to be moved from declarations to imports, in any spec files that reference them:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dZimNXrOUcD_u2pydsnXLw.png" /><figcaption>Components moved from declarations to imports in the spec file</figcaption></figure><p>Finally, let’s look at the DashboardComponent in dashboard.component.ts:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/427/1*N-LWGBvVwUIEAVzMH7UB1w.png" /><figcaption>Changes to the dashboard component after migration</figcaption></figure><p>Two things to notice:</p><ol><li>standalone: true has been added in the Component decorator.</li><li>NgFor, RouterLink, and HeroSearchComponent are now <em>imported</em>.</li></ol><p>Why the imports? NgFor, RouterLink, and HeroSearchComponent are a structural directive, attribute directive, and component respectively that are contained in the HTML of the dashboard component:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/310/1*0ZGWrW0WogcK_tmBgr55oQ.png" /><figcaption>HTML of the dashboard component</figcaption></figure><p>These are imported by the AppModule (the first two indirectly via other modules) and previously the DashboardComponent was declared in the AppModule, so it had access to these.</p><p>But now the DashboardComponent is a standalone component and is no longer part of the AppModule (or any module), so it does not have access to anything imported by the AppModule. Being standalone, it must now import everything that it needs directly so that it can be used anywhere. It must be a self-contained unit.</p><p>The story is the same for the other components that have been migrated to standalone. Anything that a standalone component needs must be imported directly in that component. It cannot rely on anything imported by any module in the application.</p><h3>Creating a New Standalone Component</h3><p>Let’s check-in those changes and create a new component with:</p><p>ng g c my-component --standalone</p><p>Note that starting with version 17, the standalone flag is not needed because it’s the default.</p><p>The resulting component looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/386/1*mnGfYLJ-gB1dNcl-WGENfA.png" /><figcaption>Newly created standalone component</figcaption></figure><p>Obviously standalone has been set to true, and also notice that the CommonModule has been imported, which gives you access to the common Angular directives all in one shot, as opposed to importing directives and such individually.</p><h3>Removing Unnecessary NgModule Classes</h3><p>Run the migration again: ng g @angular/core:standalone and this time choose the second option:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/442/1*MqPDE7bWFgwIYlEYnWfgKw.png" /><figcaption>Choosing the second option of the migration</figcaption></figure><p>For this project there is nothing to be done here. But this step would help if there were modules whose only job was importing components that are now standalone, leaving them nothing else to do.</p><h3>Bootstrapping Using Standalone APIs</h3><p>Lastly, run the migration again: ng g @angular/core:standalone and this time choose the third option:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/470/1*8ZOOsNMXsuFRcKLg6WcRlA.png" /><figcaption>Choosing the third option of the migration</figcaption></figure><p>This step removes the AppModule completely and converts the AppComponent to standalone following the same pattern we saw before — i.e., adding standalone:true and importing directives and components directly in the component:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/1*CUa4hvbuzR49Vhq5CeaxjA.png" /><figcaption>The AppComponent after migration</figcaption></figure><p>Finally, the way the application is bootstrapped has been changed in main.ts:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EvR5F7nTxXt54K9_94Lf8A.png" /><figcaption>Main.ts after the migration</figcaption></figure><p>The importProvidersFrom function “collects providers from all NgModules and standalone components, including transitively imported ones”. Not all providers have moved to use the new provide functions, but rather still use the NgModule API. In this case, that’s BrowserModule, FormsModule, and AppRoutingModule, and HttpClientInMemoryWebApiModule.</p><p>Note that HttpClientInMemoryWebApiModule is there because this application uses angular-in-memory-web-api, which your application may or may not use.</p><p>The provideHttpClient function is an example of a provider that <em>has</em> moved to use the new provide functions. This function is adding HttpClient functionality to the application <em>without</em> importing an HttpClient module.</p><p>Note that the migration uses the withInterceptorsFromDi function in order to support DI-provided interceptors. If you have interceptors in your application, you should update them to be <em>functional</em> interceptors and then provide them using withInterceptors instead. Here’s an <a href="https://medium.com/stackademic/how-to-create-a-functional-interceptor-in-angular-c2302cc67a90">article</a> that details how to do this.</p><p>That’s it! I hope you found this useful.</p><h3>Bibliography</h3><ul><li><a href="https://angular.io/guide/standalone-migration">Angular — Migrate an existing Angular project to standalone</a></li><li><a href="https://angular.io/guide/standalone-components">Angular — Getting started with standalone components</a></li><li><a href="https://angular.io/api/common/http/withInterceptorsFromDi#description">Angular — withInterceptorsFromDi</a></li><li><a href="https://angular.io/api/common/http/withInterceptors">Angular — withInterceptors</a></li><li><a href="https://angular.io/api/core/importProvidersFrom">Angular — importProvidersFrom</a></li><li><a href="https://medium.com/angular-blog/angular-developer-survey-2023-86372317c95f">Angular Developer Survey 2023. Over the past year we’ve been evolving… | by Minko Gechev | Jan, 2024 | Angular Blog (medium.com)</a></li></ul><h3>Stackademic</h3><p><em>Thank you for reading until the end. Before you go:</em></p><ul><li><em>Please consider </em><strong><em>clapping</em></strong><em> and </em><strong><em>following</em></strong><em> the writer! 👏</em></li><li><em>Follow us on </em><a href="https://twitter.com/stackademichq"><strong><em>Twitter(X)</em></strong></a><em>, </em><a href="https://www.linkedin.com/company/stackademic"><strong><em>LinkedIn</em></strong></a><em>, and </em><a href="https://www.youtube.com/c/stackademic"><strong><em>YouTube</em></strong></a><strong><em>.</em></strong></li><li><em>Visit </em><a href="http://stackademic.com/"><strong><em>Stackademic.com</em></strong></a><em> to find out more about how we are democratizing free programming education around the world.</em></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ceb00669f9ec" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/converting-an-angular-project-to-standalone-ceb00669f9ec">Converting an Angular Project to Standalone</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Quick Summary of Angular 17]]></title>
            <link>https://medium.com/@seanhaddock_60973/quick-summary-of-angular-17-bf1776e96b8e?source=rss-ead78f1ef34c------2</link>
            <guid isPermaLink="false">https://medium.com/p/bf1776e96b8e</guid>
            <category><![CDATA[summary]]></category>
            <category><![CDATA[new-features]]></category>
            <category><![CDATA[angular-17]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Sean Haddock]]></dc:creator>
            <pubDate>Mon, 13 Nov 2023 18:14:42 GMT</pubDate>
            <atom:updated>2023-11-13T18:14:42.112Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*B8w8g6fh_tYV_TI7" /><figcaption>Angular’s New Logo</figcaption></figure><p>Angular 17 was released last week, and this is my attempt to summarize Minko Gechev’s excellent post “<a href="https://blog.angular.io/introducing-angular-v17-4d7033312e4b">Introducing Angular v17</a>” as succinctly as possible. I recommend reading his post in full, but here is the Reader’s Digest version:</p><h4>New control flow syntax (developer preview)</h4><p>More intuitive and performant (up to 90% faster) <a href="https://angular.io/guide/control_flow">control flow</a> syntax (replaces *ngIf, *ngSwitch and *ngFor). Here are the examples presented in the <a href="https://blog.angular.io/introducing-angular-v17-4d7033312e4b">post</a> (condensed):</p><pre>// if<br>@if (loggedIn) {<br>  The user is logged in<br>} @else {<br>  The user is not logged in<br>}<br><br>// switch<br>@switch (accessLevel) {<br>  @case (&#39;admin&#39;) { &lt;admin-dashboard/&gt; }<br>  @case (&#39;moderator&#39;) { &lt;moderator-dashboard/&gt; }<br>  @default { &lt;user-dashboard/&gt; }<br>}<br><br>// for loop<br>@for (user of users; track user.id) {<br>  {{ user.name }}<br>} @empty {<br>  Empty list of users<br>}</pre><h4>Deferrable views (developer preview)</h4><p><a href="https://angular.io/guide/defer#deferrable-views">Deferrable views</a> utilize <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import">dynamic imports</a> and the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API">Intersection Observer API</a> to lazy load components and their dependencies (optionally with prefetching) based on various triggers, such as when the component enters the viewport. Here is an example from the <a href="https://blog.angular.io/introducing-angular-v17-4d7033312e4b">post</a>:</p><pre>@defer (on viewport; prefetch on idle) {<br>  &lt;comment-list/&gt;<br>} @loading {<br>  Loading…<br>} @error {<br>  Loading failed :(<br>} @placeholder {<br>  &lt;img src=&quot;comments-placeholder.png&quot;&gt;<br>}</pre><p>Other <a href="https://angular.io/guide/defer#triggers">triggers</a> are idle, immediate, timer, interaction, hover and when &lt;expr&gt;.</p><h4>SSR/SSG improvements</h4><p>Angular Universal (SSR) has been moved to the <a href="https://angular.io/guide/ssr#enable-server-side-rendering">CLI</a> so that you get prompted to enable SSR and SSG when executing ng new (or you can add it later with ng add @angular/ssr). Also, <a href="https://angular.io/guide/hydration"><em>hydration</em></a> is out of developer preview and is enabled by default.</p><h4>Miscellaneous</h4><ul><li>Standalone is now the default for all schematics and the recommendation is to move all projects to standalone gradually.</li><li><a href="https://angular.dev/">Angular.dev</a> will replace Angular.io in v18 for documentation and interactive learning. It also has a <a href="https://angular.dev/playground">Playground</a>.</li><li>Signals are out of developer preview and more enhancements are coming in v18.</li><li><a href="https://esbuild.github.io/">esbuild</a> plus <a href="https://vitejs.dev/">Vite</a> is out of developer preview and enabled by default, yielding 67%, 87%, 80% speed improvements for build time, hybrid build time and hybrid serve time respectively.</li><li>New <a href="https://angular.io/api/core/afterRender">afterRender</a> and <a href="https://angular.io/api/core/afterNextRender">afterNextRender</a> lifecycle hooks.</li><li>You don’t need to use an array when setting a component style — e.g., styleUrl: ‘styles.css’ instead of styleUrl: [‘styles.css’].</li><li>New UI in <a href="https://angular.io/guide/devtools">Angular DevTools</a> for dependency injection debugging.</li><li>Ability to use native browser animated transitions between routes by passing <a href="https://angular.dev/api/router/withViewTransitions">withViewTransitions()</a> to provideRouter().</li><li>Ability to lazy load the animations module with <a href="https://angular.dev/guide/animations#enabling-the-animations-module">provideAnimationsAsync()</a>.</li><li>Continued work on <a href="https://jestjs.io/">Jest</a> and <a href="https://modern-web.dev/docs/test-runner/overview/">Web Test Runner</a> (which will replace Karma).</li><li>You can do this &lt;my-expander expanded/&gt; instead of this &lt;my-expander expanded=“true”/&gt; if you add a <a href="https://angular.dev/guide/components/inputs#input-transforms">transform</a> to your input like this: @Input({ transform: booleanAttribute }) expanded: boolean = false;</li><li>Rebranding.</li></ul><h4>Reminders</h4><ul><li>Developer preview doesn’t mean that something is not ready to use, it just means that breaking changes could be introduced before the next major release.</li><li>Always check to see if there is a schematic to help you migrate legacy code.</li></ul><h4><strong>Bibliography</strong></h4><ul><li><a href="https://blog.angular.io/introducing-angular-v17-4d7033312e4b">Introducing Angular v17. Last month marked the 13th anniversary… | by Minko Gechev | Nov, 2023 | Angular Blog</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bf1776e96b8e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Enhancing npm Script Tasks with Node.js and JavaScript]]></title>
            <link>https://blog.stackademic.com/enhancing-npm-script-tasks-with-node-js-and-javascript-3ed8d174d895?source=rss-ead78f1ef34c------2</link>
            <guid isPermaLink="false">https://medium.com/p/3ed8d174d895</guid>
            <category><![CDATA[development-workflow]]></category>
            <category><![CDATA[npm-scripts]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[node]]></category>
            <dc:creator><![CDATA[Sean Haddock]]></dc:creator>
            <pubDate>Mon, 06 Nov 2023 14:24:52 GMT</pubDate>
            <atom:updated>2023-11-14T00:43:54.083Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*H--AyqUH-GOvNvgq" /><figcaption>Photo by <a href="https://unsplash.com/@kellysikkema?utm_source=medium&amp;utm_medium=referral">Kelly Sikkema</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Npm script tasks are an integral part of any modern JavaScript project. They allow us to automate mundane tasks and prevent us from having to remember a bunch of different commands.</p><p>You can accomplish many things without ever leaving package.json. But sometimes you need to do more than can be done in the single line definition of a script task or with multiple tasks.</p><p>If you find yourself in that situation you can offload the work to a JavaScript file and define the script task so that it runs that file with Node.js.</p><h3>Running a JavaScript file with Node</h3><p>Running a JavaScript file with an <strong>npm</strong> script task is as simple as:</p><pre>&quot;my-script-task&quot;: &quot;node ./my-script.mjs&quot;</pre><p>When you execute npm run my-script-task in the terminal, <strong>npm</strong> will execute this task, which runs the my-script.mjs file using <strong>Node</strong>.</p><p>Why does the file have an .mjs extension? The .mjs extension stands for “Module JavaScript”. It is used to explicitly tell Node that the file should be run as an ES module, which allows us to use ESM syntax. See this post to learn more about JavaScript <a href="https://medium.com/@seanhaddock_60973/modules-modules-modules-oh-my-c170efde7292">Modules</a>.</p><h3>Helpful Modules</h3><p>I have found that I can accomplish a lot by only importing 3 modules:</p><pre>import { execSync } from &#39;child_process&#39;;<br>import readline from &#39;readline&#39;;<br>import chalk from &#39;chalk&#39;;</pre><p>If you are using ESLint, it may complain about the import statement unless you add this to your .eslintrc.json file:</p><pre>{<br>  &quot;files&quot;: [&quot;*.mjs&quot;],<br>  &quot;parserOptions&quot;: {<br>    &quot;sourceType&quot;: &quot;module&quot;,<br>    &quot;ecmaVersion&quot;: &quot;latest&quot;<br>  }<br>}</pre><h4>execSync</h4><p>execSync is built into Node and is the workhorse. It is used to execute shell commands which actually accomplish the work we need to perform. Note that it is surrounded by {} in the import statement because it is a named export rather than the default export.</p><p>To use it, you just pass in the command that you would normally run in the terminal. For example, if I want to bump the prerelease version of my package, I can do:</p><pre>execSync(`npm version prerelease --preid=test`);</pre><h4>readLine</h4><p>readLine also comes with Node and allows for user interaction. For example, we can make the user confirm what they are about to do:</p><pre>const rl = readline.createInterface({<br>  input: process.stdin,<br>  output: process.stdout,<br>});<br><br>// make the user confirm what they are about to do<br>rl.question(&#39;Are you sure? (y/n) &#39;, (answer) =&gt; {<br>  if (answer.toLowerCase() === &#39;y&#39;) {<br>    // do your work<br>  } else {<br>    // abort<br>    rl.close();<br>  }<br>});</pre><h4>chalk</h4><p>chalk is a third-party <a href="https://github.com/chalk/chalk">package</a> we can use to style the terminal, so that we can make questions and messages stand out. To use it, you just wrap the text in a function call:</p><pre>chalk.yellowBright(<br>   ‘This text will be bright yellow’<br>);</pre><p>You can use this when passing text to both rl.question and console.log:</p><pre>console.log(<br>   chalk.redBright(<br>     ‘This text will be bright red’<br>   )<br>);</pre><p>With this combination of tools, I’ve been able to greatly enhance our development workflows.</p><p>That’s it! I hope you found this useful.</p><h3>Bibliography</h3><ul><li><a href="https://nodejs.org/api/child_process.html#child_processexecsynccommand-options">Child process | Node.js v21.1.0 Documentation (nodejs.org)</a></li><li><a href="https://nodejs.org/api/readline.html">Readline | Node.js v21.1.0 Documentation (nodejs.org)</a></li><li><a href="https://v8.dev/features/modules#mjs">JavaScript modules · V8</a></li><li><a href="https://docs.npmjs.com/cli/v10/using-npm/scripts">scripts | npm Docs (npmjs.com)</a></li><li><a href="https://github.com/chalk/chalk">GitHub — chalk/chalk: 🖍 Terminal string styling done right</a></li></ul><h3>Stackademic</h3><p><em>Thank you for reading until the end. Before you go:</em></p><ul><li><em>Please consider </em><strong><em>clapping</em></strong><em> and </em><strong><em>following</em></strong><em> the writer! 👏</em></li><li><em>Follow us on </em><a href="https://twitter.com/stackademichq"><strong><em>Twitter(X)</em></strong></a><em>, </em><a href="https://www.linkedin.com/company/stackademic"><strong><em>LinkedIn</em></strong></a><em>, and </em><a href="https://www.youtube.com/c/stackademic"><strong><em>YouTube</em></strong></a><strong><em>.</em></strong></li><li><em>Visit </em><a href="http://stackademic.com/"><strong><em>Stackademic.com</em></strong></a><em> to find out more about how we are democratizing free programming education around the world.</em></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ed8d174d895" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/enhancing-npm-script-tasks-with-node-js-and-javascript-3ed8d174d895">Enhancing npm Script Tasks with Node.js and JavaScript</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>