<?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 Simon Sharp on Medium]]></title>
        <description><![CDATA[Stories by Simon Sharp on Medium]]></description>
        <link>https://medium.com/@simon.sharp_25406?source=rss-3e08a427abe3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ic92ED55XUUp3JYv3mQ0Yg.jpeg</url>
            <title>Stories by Simon Sharp on Medium</title>
            <link>https://medium.com/@simon.sharp_25406?source=rss-3e08a427abe3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 22:28:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@simon.sharp_25406/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: Alternatives after the deprecation of ::ng-deep]]></title>
            <link>https://medium.com/@simon.sharp_25406/angular-alternatives-after-the-deprecation-of-ng-deep-b51591a296e7?source=rss-3e08a427abe3------2</link>
            <guid isPermaLink="false">https://medium.com/p/b51591a296e7</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[ng-deep]]></category>
            <category><![CDATA[scss]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Simon Sharp]]></dc:creator>
            <pubDate>Fri, 17 Mar 2023 12:43:45 GMT</pubDate>
            <atom:updated>2023-03-17T12:43:45.624Z</atom:updated>
            <content:encoded><![CDATA[<h3>Angular: Alternatives after the deprecation of ::ng-deep</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_6MkqztXWBgzdMErloTUBw.jpeg" /></figure><h3>Overview</h3><p>Quite a while ago the Angular team has deprecated the ::ng-deep pseudo class in the SCSS styling system that allowed to define global styles or to break the style encapsulation of a component. It is currently not clear how long the ::ng-deep pseudo class will still be available. What was always missing was the new tool or way to replace ::ng-deep with. What is rather unknown is that the tools are already there. So lets take a look into the available alternatives.</p><h3>The ngClass version</h3><p>You can hand over a variable by using an @Input() annotation on a component and then use [ngClass] to set a conditional class on your component that defines a class that can then be covered in one of the CSS files.</p><p>The test.component.ts typescript file</p><pre>@Component({<br>  selector: &#39;test&#39;,<br>  styles: [<br>    &#39;./test.component.scss&#39;,<br>  ],<br>  template: `<br>    &lt;div [ngClass]=&quot;getTestClass()&quot;&gt;Test&lt;/div&gt;<br>  `<br>})<br>export class TestComponent {<br>  @Input()<br>  public hasSpecificStyle: boolean = false;<br><br>  public getTestClass(): {[key: string]: boolean } {<br>    return {<br>     &#39;test__specific-style&#39;: this.hasSpecificStyle<br>    };<br>  }<br>}</pre><p>And the test.component.scss file</p><pre>.test__specific-style {<br>  border: 1px solid red;<br>}</pre><p>This works kind of well for components that you write by yourself. But the code has also quite some overhead. And the component has to be changed whenever a new style is needed. This makes it no particularly usefull when used with libraries.</p><h3>The styles.scss way</h3><p>The styles.scss file contains global styles that do not care about the style encapsulation. Changes here are global and therefore need to be handeled with a bit more care. Try to encapsulate your styles here by being very specific.</p><h3>The host-context version</h3><p>In this version the page component that uses our test file defines a class on the component and the component itself picks that up and uses it. To pick the class up we use the :host-context(.class) pseudo class as described here</p><p>The page html file</p><pre>&lt;test class=&quot;specific-style&quot;&gt;&lt;/test&gt;</pre><p>The test.component.ts typescript file</p><pre>@Component({<br>  selector: &#39;test&#39;,<br>  styles: [<br>    &#39;./test.component.scss&#39;,<br>  ],<br>  template: `<br>    &lt;div class=&quot;test__main&quot;&gt;Test&lt;/div&gt;<br>  `<br>})<br>export class TestComponent {<br>}</pre><p>And the test.component.scss file</p><pre>:host {<br>  :host-context(.specific-style) &amp; {<br>    .test {<br>      &amp;__main {<br>        border: 1px solid red;<br>      }<br>    }<br>  }<br>}</pre><h3>The SCSS variable way</h3><p>In this version we are using the var( — custom-border-color, red) declaration in the SCSS file. This allows us to define a style attribute per variable. The variable is then declared or overwritten as described on the page block below when using the component. This is a good version if your code should work as a library that provides components to the outside or for shared components. The downside here is that you can only overwrite already defined variables and not apply new styles that have not been set so far.</p><p>The page SCSS file. Thats the file that uses the test component</p><pre>:host {<br>  test {<br>    --custom-border-color: green;<br>  }<br>}</pre><p>The test.component.ts typescript file</p><pre>@Component({<br>  selector: &#39;test&#39;,<br>  styles: [<br>    &#39;./test.component.scss&#39;,<br>  ],<br>  template: `<br>    &lt;div class=&quot;test__main&quot;&gt;Test&lt;/div&gt;<br>  `<br>})<br>export class TestComponent {<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_6MkqztXWBgzdMErloTUBw.jpeg" /></figure><p>And the test.component.scss file</p><pre>.test {<br>  &amp;__main {<br>    border-width: 1px;<br>    border-style: solid;<br>    border-color: var(--custom-border-color, red); <br>  }<br>}</pre><h3>Source</h3><p><a href="https://www.youtube.com/watch?v=PPmba5cBu3w">https://www.youtube.com/watch?v=PPmba5cBu3w</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b51591a296e7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Signals in Angular]]></title>
            <link>https://medium.com/@simon.sharp_25406/signals-in-angular-3dc2c97ce5a6?source=rss-3e08a427abe3------2</link>
            <guid isPermaLink="false">https://medium.com/p/3dc2c97ce5a6</guid>
            <category><![CDATA[rxjs]]></category>
            <category><![CDATA[signal]]></category>
            <category><![CDATA[obsrevables]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Simon Sharp]]></dc:creator>
            <pubDate>Fri, 17 Mar 2023 10:28:59 GMT</pubDate>
            <atom:updated>2023-03-30T12:14:59.711Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eOI0CnJSj08Evzjq_4ByTA.jpeg" /></figure><h3>Overview and current state of development</h3><p>Presumably with Angular 16 or 17, Google is going to introduce a new concept into Angular that is called Signals. Signals is a simplified version of state management and is going to be integrated into the Angular Core. It is supposed to have an impact when working with BehaviorSubject, NGRX, Observables and Promises. It can be tested out in the release candidate versions of Angular 16, but the developers have not yet agreed on the API they want to use. That means the concept is currently in the testing phase and the implementation will likely change until the final release.</p><p>Signals is supposed to be a simpler version of Observables. And it is designed to flawlessly work with Observables. Signal is going to integrate into, extend and possibly replace NGRX. It is designed to make the work with state management easier.</p><p>And finally, under the hood, it is planned to use it in the change detection to simplify the work that is currently done by zone.js. These changes are going to be mainly black boxed and therefore invisible. There is most likely going to be an impact on the ChangeDetectionStrategy.OnPush, which is going to be made obsolete.</p><p>It is also expected to further reduce the package size of an Angular project and increase the performance.</p><p>To update to the next Angular version and unlock the feature you can use the ng update command as follows:</p><pre>ng update @angular/cli @angular/core --next=true</pre><h3>So, what are Signals and how do I work with it? (signal)</h3><p>In the simplest version it looks something like this</p><pre>import { Component, signal, SettableSignal } from &#39;@angular/core&#39;;<br><br>@Component({<br> selector: &#39;signal-test-component&#39;,<br> template: &#39;{{valueX()}}&#39;<br>})<br>export class SignalTestComponent {<br> public valueX: SettableSignal&lt;number&gt; = signal&lt;number&gt;(5);<br> constructor() {<br>  console.log(&#39;The number is: &#39; + valueX());<br> }<br>}</pre><p>The signal named valueX is set to a number in the variable declaration of the class. And then it is used to be displayed in the template as well as in the console.log in the constructor. To get the value out you need to call it as a function valueX(). While the console.log output will only be called once and will grab and display the value of the signal in the specific moment, the value in the template will automatically be re-rendered once the value in the signal changes.</p><p>To set a value of a signal you call the function signal like</p><pre>variableName = signal&lt;type&gt;(value);</pre><p>And to get the value out of the signal you call the variableName as a function like</p><pre>variableName();</pre><h3>How do I change the value of a signal once it has been defined? (update and mutate)</h3><p>To change the value of a signal there are 2 methods available. Update and mutate.</p><h3>Update</h3><p>The update method takes a new value and replaces the current signal value with the new value. The value is completely replaced. Meaning that when you update to a new object it will have a new location in memory and direct comparison using === will no longer work.</p><pre>variableName.update(value =&gt; value + 1);</pre><p>When this is done, all spots in the code that listen to the signal will be updated</p><h3>Mutate</h3><p>The mutate method takes a new value and mutates the current value. This while leaving the variable in the place it has been before. So === comparison will theoretically still work. Because this is irrelevant on primitive values, the mutate function is used on objects.</p><pre>variableName = signal&lt;any&gt;({<br>	a: &#39;Test&#39;<br>});<br><br>variableName.mutate(<br> currentValue =&gt; currentValue.b = &#39;Another Test&#39;;<br>);</pre><p>or</p><pre>variableName = signal&lt;CustomerItem[]&gt;([<br>  {<br>    customer: &#39;SBB&#39;<br>  }<br>]);<br><br>variableName.mutate(<br>  customerArray =&gt; customerArray.push = {<br>    customer: &#39;Postfinance&#39;<br>  };<br>);</pre><p>It also changes the value and notifies everybody who listens to the signal.</p><h3>Listen to when the value changes (effect and computed)</h3><h3>effect</h3><p>Effects are a concept that developers might already know from NGRX. Besides just getting the value by calling the signal by name like variableName(), they trigger an action that has no impact on the signals value but is executed when the value of the signal changes. The effect is also triggered when the function is executed for the first time. This means you can not only define it and it will be triggerred once the singals value changes. Its executed the first time the code runs over the effect.</p><pre>public weatherData$: Observable&lt;WeatherData&gt;;<br>public dateSignal = signal&lt;Date&gt;(Date.now());<br><br>public effectRef = effect(<br> () =&gt; {<br>  this.weatherData$ = this.httpClient.get&lt;WeatherData&gt;(&#39;/weatherData?date=&#39; + dateSignal());<br> }<br>)</pre><p>The effect knows which signals are used inside it and triggers the effect when one of the used signals have a change in value.</p><p>If the effect had an if else statement in it where one signal was in the if and another signal was in the else statement. It will register to both signals. But it is only executed when one of those 2 signals change. Its not executed when a third signal changes that is not mentioned in the effect.</p><p>The effect() function returns an Effect. It can be manually scheduled or destroyed. There are 3 methods on the Effect.</p><ul><li>schedule(): Schedule the effect for manual execution.</li><li>destroy(): Shut down the effect, removing it from any upcoming scheduled executions.</li><li>consumer: Direct access to the effect’s Consumer for advanced use cases.</li></ul><h3>computed</h3><p>The computed function is like an effect. The difference is that it returns a new (and immutable) signal of type Signal instead of an Effect. This means that we can recalculate several other signal values if some signal changes.</p><pre>import {  Component, computed, SettableSignal, signal, Signal } from &#39;@angular/core&#39;;<br><br>@Component({<br> selector: &#39;signal-test-component&#39;,<br> template: &#39;{{valueX()}}&#39;<br>})<br>export class SignalTestComponent {<br> public valueX: SettableSignal&lt;number&gt; = signal&lt;number&gt;(5);<br> public valueY: SettableSignal&lt;number&gt; = signal&lt;number&gt;(5); <br> public valueZ: Signal&lt;number&gt;;<br><br> constructor() {<br>  console.log(&#39;The number is: &#39; + valueX());<br>  this.valueZ = computed(<br>   () =&gt; this.valueX() + this.valueY()<br>  );<br> }<br>}</pre><p>valueZ will always depend on valueX and valueY and therefore has no methods to update or mutate. It does not need them. Thats the difference between a SettableSignal and a Signal.</p><h3>Naming conventions for signals</h3><p>With Observables the naming convention was to end a variable name with a $. Like variableName$: Observable&lt;unknown&gt;.</p><p>I have currently seen 2 way to handle this with signals. Either it was just the pure variable name, like I have used in this document. Or the variable name ended with Sig. Like variableNameSig.</p><h3>Integration with NGRX or Observables</h3><p>There are 2 methods to convert a signal into and from an Observable. These methods are currently called fromSignal and fromObservable. This allows us to integrate the concept signals into our preojects without effort.</p><pre>valueX = signal&lt;number&gt;(5);<br>valueX$ = fromSignal(valueX).pipe(...);<br>valueY = fromObservable(valueX$);</pre><h3>Sources about signals</h3><p><a href="https://itnext.io/angular-signals-the-future-of-angular-395a69e60062">https://itnext.io/angular-signals-the-future-of-angular-395a69e60062</a></p><p><a href="https://github.com/ziedzayani/angular-signal-demo">https://github.com/ziedzayani/angular-signal-demo</a></p><p><a href="https://www.youtube.com/watch?v=HCg3vJpfYeg">https://www.youtube.com/watch?v=HCg3vJpfYeg</a></p><p><a href="https://www.youtube.com/watch?v=Mo8ttiatVCg">https://www.youtube.com/watch?v=Mo8ttiatVCg</a></p><p><a href="https://www.youtube.com/watch?v=4FkFmn0LmLI">https://www.youtube.com/watch?v=4FkFmn0LmLI</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3dc2c97ce5a6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The state of Angular by the Google Angular team]]></title>
            <link>https://medium.com/@simon.sharp_25406/the-state-of-angular-by-the-google-angular-team-9ea8f6571c5f?source=rss-3e08a427abe3------2</link>
            <guid isPermaLink="false">https://medium.com/p/9ea8f6571c5f</guid>
            <category><![CDATA[standalone-component]]></category>
            <category><![CDATA[angular-renderer]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[directive-composition-api]]></category>
            <category><![CDATA[esbuild]]></category>
            <dc:creator><![CDATA[Simon Sharp]]></dc:creator>
            <pubDate>Fri, 03 Feb 2023 10:16:15 GMT</pubDate>
            <atom:updated>2023-02-03T10:16:15.320Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OrS-AndLudgmDS_r37_Vdw.jpeg" /></figure><p>On February 2nd, 2023, we had the opportunity to meet and listen to a presentation of the Angular Core Team at Google Zürich through the Angular Zürich Meetup group. The talk was very interesting and will be soon published as a video on the <a href="https://angularzurich.dev/">https://angularzurich.dev/</a> website.</p><p>In short: Angular is doing well and has the full support of Google. Lots of features are planned to improve it.</p><p>In this article I want to cover the topics that were discussed during the meeting.</p><h3>Improve the build speed with esbuild</h3><p>Angular is currently built on webpack to build a running version in development as well as for the production environment. Anyone who had worked on a larger project knows that suddenly, the build can take 30 seconds or longer. The Angular team knows about this and is looking for ways to improve the build time in general. Their approach is to move to a build system called esbuild. According to their measurements the build speed will be improved by around 99%. Which sounds a bit unbelievable, and it is. When running in a proper live project at least they could show that they could reduce the build time by about 50%. And that is already impressive. It will have a great impact on our build servers and improve productivity. Esbuild is currently available as an <strong>experimental</strong> feature when using Angular 15. They told us you can use it when running</p><p>ng build –esbuild</p><p>When building in Angular 15. But so far, I don’t see that feature. It’s possible that it will be coming soon. So far it has to be done over the angular.json.</p><p>And there are articles on the net that describe in depth on how you can use it.</p><p><a href="https://www.danywalls.com/maximizing-your-angular-build-performance-with-esbuild">https://www.danywalls.com/maximizing-your-angular-build-performance-with-esbuild</a></p><h3>Easier learning</h3><p>The Angular team has acknowledged that the learning curve for people who start with Angular is a bit too steep. Because of this they will put up some new learning programs on the webpage and improve documentation to flatten the learning curve. They also try to improve the tooling so that schematics will build the necessary features for you.</p><h3>Improve error messages</h3><p>And finally, they will try to improve error messages during build and run time. This includes working together with the developers of the chrome browser that will allow the further analysis of errors that are thrown. Goal here is that the stack trace will better tell you where the error has occurred and not to hide everything behind an ngZone abstraction.</p><h3>Ng generate config</h3><p>“ng generate config” is a command to generate configurations based on Google Schematics as described in <a href="https://angular.io/cli/generate#config-command">https://angular.io/cli/generate#config-command</a>.</p><p>This allows you to generate config files for Karma or generate a Browserlist that helps Angular to import shim files to add missing functionality to browsers.</p><h3>Ng generate environment</h3><p>“ng generate environments” will help you to set up different environments like prod, staging, dev and more. It’s described under <a href="https://angular.io/guide/build">https://angular.io/guide/build</a>.</p><h3>Standalone components</h3><p>Also because of the flatter learning curve they improve the ability to work with Angular after you have just created a project. They don’t want people to have to learn about modules first. For this they improve the features regarding standalone components. Standalone components already exist in Angular and are a way to quickly bootstrap one component as the main way to bootstrap into the application.</p><p>For more detail and because I don’t have the code they have shown, I suggest you watch the video once it gets out.</p><p>To quickly build an application they introduced the command “ng new –standalone”</p><h3>Directive composition Api</h3><p>Described in <a href="https://angular.io/guide/directive-composition-api">https://angular.io/guide/directive-composition-api</a></p><p>When we are writing directives on our own or use directives from frameworks it is sometimes hard to tell for the next developer which of these directives go together. In many cases when you apply one directive a second directive further clarifies what you want to configure.</p><p>The current strategy is to use a prefix to know which framework provided the directive and then you go and read the documentation on how to further use the parameters. The goal is to change that.</p><p>The possibility they have introduced is the hostDirectives parameter/attribute in the @Component and @Directive annotation. This allows you to add one or more directives on the component shell tag you are currently writing. And furthermore, it allows to hand over input and output variables to the declared directives. So, with this feature you can define a specific behavior that is composed of several directives.</p><h3>Image directive</h3><p>As described in <a href="https://angular.io/guide/image-directive">https://angular.io/guide/image-directive</a></p><p>Images are very important on most webpages these days. They also make the webpage load slowly if not done correctly. So, handling them correctly and efficiently is very important. The image directive gives you a toolset to improve the user experience.</p><p>You can add a priority tag to an image to tell the browser to load relevant pictures first.</p><p>You can add a fill attribute to an image tag to make it just use all of the space available of the surrounding tag.</p><p>And you can define which image should be loaded on which device.</p><p>There are more features and I suggest you read Agular’s documentation.</p><h3>Performance measurement</h3><p>We were not going deep into this topic, but they are using tools called Lighthouse and Web page test for performance measurements on Angular pages.</p><h3>Web assembly</h3><p>It is currently not planned to add web assembly functionality features to Angular because that’s not what web assembly is for. There are other ways/frameworks to work with web assemblies and the Angular code is not suited to be used with web assemblies.</p><h3>Renderer 5 is in planning</h3><p>Last point is that the 5th version of the Angular renderer is being built. They will further improve speed by anticipating and pre-calculating your next behavior when browsing on the page. When you make a click the result is already there and will be inserted extremely quick. It will take some time to get there, and the new renderer should not be expected any time soon. Even the Ivy renderer took quite a while to be finished.</p><p>They also explained how the Ivy renderer had gotten its name. It was the 4th renderer and had matched the roman numerals IV. I always thought it was the 3rd generation.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9ea8f6571c5f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unclutter your CSS]]></title>
            <link>https://medium.com/elca-it/unclutter-your-css-68a1769c83a9?source=rss-3e08a427abe3------2</link>
            <guid isPermaLink="false">https://medium.com/p/68a1769c83a9</guid>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[web]]></category>
            <category><![CDATA[organizational-culture]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Simon Sharp]]></dc:creator>
            <pubDate>Tue, 11 Oct 2022 07:18:56 GMT</pubDate>
            <atom:updated>2022-10-14T06:08:31.789Z</atom:updated>
            <content:encoded><![CDATA[<h3>Unclutter your CSS with <strong>Block-Element-Modifier (BEM)</strong></h3><p>Have you ever worked in an HTML Project and had to set the font color of a title? You gave the surrounding div a CSS class with the name title and declared the color attribute in the “.title” section in the CSS file. You committed your change in Git and you were happy that you had finished your task. Only to find out about 5 minutes later that you had also unintentionally changed the title color on some other pages in your project. So as a solution you tried to find a very broad CSS class that is somewhere up the DOM that would not interfere with other pages or you created one of your own and referenced in the CSS with a cascading “.mypage .somesection .title”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wsD4NpLmOBQSd1IbX5Xfxw.jpeg" /><figcaption>© Simon Sharp</figcaption></figure><p>And when you were done there you figured out that you completely lost oversight of what is where and you were not sure if you are going to break something again once you entered another class. Let alone got lost in chaos once I had to refactor my code. I surely have. And more than once I have cursed about the structure and stupidity of CSS.</p><p>Then one day I was applying for a job. And in the job description I found the need for knowledge of BEM or SMACSS. I took a quick look at what it is and found the solution to my CSS frustration.</p><p><strong>In short: The solution is to write your CSS class name in a structured and meaningful way.</strong></p><h3>Description</h3><p>Let’s have a look at <strong>BEM</strong>. Its going to be the one approach I will focus on in this text. BEM stands for <strong>Block/Element/Modifier</strong> and can be looked up on <a href="http://www.getbem.com/">http://www.getbem.com</a>. There is nothing to download to work with this approach. It’s completely conceptional.</p><p>The goal is to provide such a <strong>meaningful name for a class</strong>, that it is always going to be <strong>unique</strong> in your project. As a result, it will hardly ever be necessary to cascade the class names in your CSS file. You are always working on the first level. So let’s have a look on who BEM asks you to set up the class name.</p><p><strong>block__element — modifier</strong> or when used in an example <strong>offer__title — overdue</strong></p><p>First, we start with the <strong>Block</strong> part. The Block refers to the page or component you are writing the CSS for. In my example I go with the offer page. The offer page might have several sections like title, description, pricing information and so on.</p><p>So those sections are named <strong>Element</strong>s in BEM. Make sure that you give them meaningful names and if possible do not repeat yourself. Of course, it is possible to have CSS classes with the same name on a page. Specially if you loop over something. That’s why we are talking about CSS classes and not id’ s. But make sure that when you are using the same name that the element has the same structure.</p><p><strong>Blocks and Elements</strong> are already enough to give the class name for what we need in most cases and it’s completely ok to just use those two parts.</p><p>The <strong>Modifier</strong> comes into play when the element you are referring to has several states. Like active, inactive, state-success, state-danger, overdue or whatever you need in your project.</p><h3>Possible downsides</h3><p>Too much information: Now when someone uses BEM on their page for the first time, they might say that they struggle with creating a lot of redundant information. This is because the page name is now visible n times in the html. There is nothing that I can say against that. I can only refer to the benefits we get when we are not destroying our colleague’s CSS.</p><h3>SCSS</h3><p>When we are using SCSS we do not have to repeat ourselves in the CSS file. With SCSS it is possible to concatenate string by using the &amp; character.</p><pre>.offer {<br>     &amp;__title {<br>          &amp;--overdue {<br>                color: red;<br>          }<br>     }<br>}</pre><p>So, we don’t have to repeat ourselves and also changing the names when renaming something is much faster.</p><h3>In an Angular Project</h3><p>When we are working in an Angular project the CSS is already separated by Angular. If we are writing CSS for one component it is separated from the CSS in another component. So does it makes sense to use BEM in an Angular project? In my opinion it does. It’s also not the case that it puts too much information into the HTML part.</p><p>In Angular it is also possible to declare styles in the styles.scss file that applies to the entire project. With this it would be easily possible to generate a theming for our project.</p><p>So I would highly recommend to also use BEM in your Angular projects.</p><h3>Benefit for support and bug fixing</h3><p>The last point I want to mention is the benefit when your project comes into the maintaining phase of the project. Or if you have found a bug in your program and need to find the location in the thousand files you have in your project. BEM class names are supposed to be unique. Therefore, you will land on the correct spot to solve your bugs every time.</p><h3>The Future of BEM</h3><p>There are several technologies that already exist. Like “CSS Modules” and “Styled Components”. Just to name a few. They move the CSS into variables so they can also be used over a JavaScript import section. The creation of the CSS is then done during the webpack build steps or during runtime.</p><p>Like any tech this comes with some advantages and disadvantages. Currently I am personally happy with using BEM and I might point out some reasons why this is the case. I might be wrong.</p><ul><li>Both of these concepts break down easily when not only applied to classes.</li><li>You need some additional setup to get it working that currently not come out of the box.</li><li>It does not support you in any ways when you are debugging or testing your code because it hides the spot where the declaration is made in the HTML output.</li><li>They both work well if you have general styles, but thats a place that is covered well by the scss mixin/import declaration.</li><li>And finally, it is sort of what Angular is doing with the encapsulation of the components.</li></ul><p>So, I accept that there is newer technology to work with CSS. But I would say that this then can be handled in another Blogpost.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=68a1769c83a9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/elca-it/unclutter-your-css-68a1769c83a9">Unclutter your CSS</a> was originally published in <a href="https://medium.com/elca-it">ELCA IT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>