<?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 samet acar on Medium]]></title>
        <description><![CDATA[Stories by samet acar on Medium]]></description>
        <link>https://medium.com/@samet-acar?source=rss-503744769173------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*gsL5_tw2HmTQboD_.jpeg</url>
            <title>Stories by samet acar on Medium</title>
            <link>https://medium.com/@samet-acar?source=rss-503744769173------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 22:36:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@samet-acar/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[Using Interfaces Inside Tuples in TypeScript — Correct Usage, Mistakes, and Best Practices]]></title>
            <link>https://medium.com/@samet-acar/using-interfaces-inside-tuples-in-typescript-correct-usage-mistakes-and-best-practices-0ae3192b6d43?source=rss-503744769173------2</link>
            <guid isPermaLink="false">https://medium.com/p/0ae3192b6d43</guid>
            <category><![CDATA[array-methods]]></category>
            <category><![CDATA[interfaces]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[tuple-method]]></category>
            <category><![CDATA[tuples]]></category>
            <dc:creator><![CDATA[samet acar]]></dc:creator>
            <pubDate>Wed, 03 Dec 2025 13:03:18 GMT</pubDate>
            <atom:updated>2025-12-03T13:03:18.187Z</atom:updated>
            <content:encoded><![CDATA[<h3>Using Interfaces Inside Tuples in TypeScript — Correct Usage, Mistakes, and Best Practices</h3><p>A long time ago in a galaxy far, far away; when I first encountered TypeScript while working with Angular 2, I made several mistakes while using it. Yesterday I was just reminded of one of them: Using a tuple that contained an interface.[interface]</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g4r3lIhUuizK5_1-10wr9w.png" /><figcaption>Interface inside Tuple?</figcaption></figure><p>It seemed to work fine, unless we assigned a list of objects to the tuple. It ran without errors in the Angular 2–6 era, but that was definitely not best practice. So, I had usage like this back then;</p><pre>let users : [user] = userService.getUsers(); <br>// assuming userService.getUsers() returned an array of User objects</pre><p>Back then, TypeScript’s strict mode wasn’t widely enforced. I probably encountered some poor examples on Stack Overflow or elsewhere… And to be honest, I was more ignorant back then. I often assigned an object list to a tuple in those days. Sorry, old projects, and sorry, boss!</p><p>While we’re on the subject of confessions, perhaps we can take a brief look at Tuples to refresh our memory?</p><h3>What is Tuple?</h3><p>If we’re talking about Typescript, we could describe it as an array with a fixed number of elements, where the type of each element is <strong>known</strong> and <strong>fixed</strong> (and in a specific order). Let’s look at a generic example;</p><pre>const coordinates: [string, string] = [&quot;41.015137&quot;, &quot;28.979530&quot;];</pre><p>Coordinates variable is a tuple which is restricted with <strong>two string</strong> elements. We cannot add a <strong>third</strong> string to it, nor can we remove one of the existing elements.</p><p>We also cannot change the type of either element.</p><pre>coordinates = [&quot;41.015137&quot;]; <br>// Type &#39;[string]&#39; is not assignable to type &#39;[string, string]&#39;.<br></pre><p>On the other hand, the tuple remains mutable (changeable) just like standard arrays. We can change one of the values;</p><pre>coordinates[1] = &quot;&quot;;<br>console.log(coordinates) ;  <br>// [LOG]: [&quot;41.015137&quot;, &quot;&quot;]</pre><h3>Using Interfaces in Tuples</h3><p>So, we can define a tuple using an interface as well; <strong>[interface]</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8XvNbRE3ur_VpwlQZbp8Vw.png" /></figure><blockquote>Some people accept this structure as a tuple, while others do not. Those who disagree say that this is simply an array containing one object (like User[]), not a true tuple. A tuple is an array feature, but it is typically used to represent a fixed number of elements where each element has a distinct and fixed type</blockquote><pre>interface User { <br>  id: number,<br>  name: string<br>};<br><br>const user: [User] = [{id: 1, name: &quot;Neo&quot;}]; // This is the usage I am referring to.</pre><p>We cannot add a second object directly during the tuple definition, as TypeScript doesn’t allow it.</p><p>However, demonstrating standard array behavior, we can still use the <strong>.push()</strong> method to add another object to this tuple after initialization. This means the tuple violates its own principle of having a fixed length.</p><pre>user.push({name: &quot;Morpheus&quot;, id: 2}); // TypeScript allows this!</pre><p>In modern TypeScript, tuples are technically arrays, so .push() cannot be fully prevented. Even with strict mode enabled, tuple length guarantees are not absolute. If you need a truly fixed-length tuple, you must declare it as <strong>readonly</strong>.</p><p>Furthermore, if we look inside the object defined within the tuple, we can change the order of the object’s properties (like swapping the position of id and name). This is generally discouraged because one of the main principles of a tuple is the strict order of its elements.</p><p>If we need to define a two-element tuple where both elements are of the User interface type, we would define it explicitly like this:</p><pre>const matrixUsers: [User, User] = [ <br>    { id: 1, name: &quot;Neo&quot; }, <br>    { id: 2, name: &quot;Morpheus&quot; }<br>];</pre><p>The core problem was that in early TypeScript versions, the compiler often couldn’t distinguish clearly between a regular array (User[]) and a tuple ([User]) when it came to methods like .push().</p><h3>Conclusion</h3><p>Using a tuple that contains an interface is something you very rarely need.<br>But let’s say you do use it, and later you want to create an array from it.<br>In that case, it’s usually better to avoid tuples and use a normal list of objects instead.</p><p>It’s simpler, easier to read, and works more naturally in TypeScript.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0ae3192b6d43" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Angular Zones — Part 2: The Role of NgZone]]></title>
            <link>https://medium.com/@samet-acar/mastering-angular-zones-part-2-the-role-of-ngzone-7a3691d522b2?source=rss-503744769173------2</link>
            <guid isPermaLink="false">https://medium.com/p/7a3691d522b2</guid>
            <category><![CDATA[zonejs-in-angular]]></category>
            <category><![CDATA[ngzone]]></category>
            <category><![CDATA[angular-change-detection]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[samet acar]]></dc:creator>
            <pubDate>Fri, 08 Aug 2025 13:24:23 GMT</pubDate>
            <atom:updated>2025-08-08T13:24:23.201Z</atom:updated>
            <content:encoded><![CDATA[<h3>Mastering Angular Zones — Part 2: The Role of NgZone</h3><p>In the first part of this series, we explored the role of Zone.js in Angular’s change detection mechanism. In this article, we’ll take a look at NgZone which is a wrapper around Zone.js provided by Angular to manage change detection more precisely.</p><h4>What is NgZone?</h4><p>Angular contains both Zone.js and NgZone. Although they work closely together, they are not the same thing. In fact, NgZone is an Angular-specific service built on top of Zone.js. As we talked about in the first part, Zone.js is a library that monkey-patches asynchronous browser APIs like XHR, DOM events, and timers etc. Zone.js essentially creates an “execution context” (called a zone) around asynchronous operations, allowing it to observe when they start and when they complete. You can think of Zone.js as the low-level “observer” that detects these asynchronous changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vlbj8KX5xYwIxI3ja8_b1w.png" /><figcaption><strong>Zone.js </strong>is observer and herald of change. it detects asynchronous changes, and <strong>NgZone</strong> uses this information to trigger Angular’s change detection.</figcaption></figure><p>On the other hand, NgZone is the “operator” or control center for this process. It listens for the signals from Zone.js when an asynchronous task finishes. When it receives this signal, NgZone’s primary job is to trigger Angular’s change detection mechanism. This is where NgZone gives us great power to control over change detection behavior.</p><h3>Taking Control of Change Detection with NgZone</h3><p>Let’s take a look these special powers of NgZone;</p><h4>runOutsideAngular()</h4><p>It’s probably the most commonly used function provided by NgZone. As the name suggests; It ignores the signals sent by Zone.js when asynchronous operations complete. It essentially creates a “safe zone” where Angular’s change detection won’t be triggered by asynchronous events. This can be especially useful for improving performance. Especially, isolate the process of constantly working and effecting performance from Angular’s Change Detection mechanism. For example;</p><pre>private listener!: EventListener;<br><br>ngOnInit(): void {<br>  this.listener = (event: Event) =&gt; {<br>    const mouseEvent = event as MouseEvent;<br>    const target = document.elementFromPoint(<br>      mouseEvent.clientX,<br>      mouseEvent.clientY<br>    );<br>    this.moveCount++;<br>  };<br>   <br>  container.addEventListener(&#39;mousemove&#39;, this.listener);<br>}</pre><p>This mousemove event listener fires constantly. Without NgZone, each mouse movement would be detected by Zone.js, which would then notify NgZone to trigger a change detection cycle. It says, ‘Hey bro, the mouse is moved, you may check that is there any changes’.</p><p>So, whenever it happens, Angular change detection mechanism start to check every values such as, ngIf, ngFor ngClass etc. And triggering change detection on every mouse movement would be inefficient and negatively affect performance. So, we can tell Angular via ngZone that it doesn’t need to run change detection for this operation. And that function is, runOutsideAngular().</p><pre>ngOnInit(): void {<br>  const container = document.getElementById(&#39;container-box&#39;);<br>  const box = document.getElementById(&#39;tracker-box&#39;);<br> <br>  this.ngZone.runOutsideAngular(() =&gt; {<br>    this.listener = (event: Event) =&gt; {<br>      const mouseEvent = event as MouseEvent;<br>      const target = document.elementFromPoint(<br>        mouseEvent.clientX,<br>        mouseEvent.clientY<br>      );<br>      this.moveCount++;<br>    };<br><br>    container.addEventListener(&#39;mousemove&#39;, this.listener);<br>  });<br>}</pre><p>By wrapping the event listener with ngZone.runOutsideAngular(), we ensure that mouse movement events occur in a zone where they don’t trigger Angular’s change detection. So Angular won’t need to evaluate structural directives like ngIf or ngFor on every mouse event. So it is a great approach for performance.</p><h4>run()</h4><p>It allows us to manually trigger. Some changes caused by 3rd-party libraries or direct DOM manipulations (e.g., iframes) are not detected by Angular’s change detection. In such cases, we can use run() to manually trigger it. we can say, ‘Hey buddy, something important happened — please check for changes’.</p><p>On the other hand we can use it with runOutsideAngular also. Let’s continue with above example.</p><pre>&lt;div id=&quot;container-box&quot;&gt;<br>  &lt;div id=&quot;untracker-box&quot; class=&quot;box&quot;&gt;<br>    &lt;span&gt;Outside Angular&lt;/span&gt;<br>    &lt;p&gt;Mouse Movement: {{ moveCount }}&lt;/p&gt;<br>    &lt;p&gt;Move Your Mouse&lt;/p&gt;<br>  &lt;/div&gt;<br>&lt;/div&gt;</pre><pre>ngOnInit(): void {<br>  const container = document.getElementById(&#39;container-box&#39;);<br>  const box = document.getElementById(&#39;untracker-box&#39;);<br>  if (!container || !box) return;<br><br>  this.ngZone.runOutsideAngular(() =&gt; {<br>    this.listener = (event: Event) =&gt; {<br>      const mouseEvent = event as MouseEvent;<br>      const target = document.elementFromPoint(<br>        mouseEvent.clientX,<br>        mouseEvent.clientY<br>      );<br><br>      // if mouse on untracker-box do not count<br>      if (box.contains(target)) return;<br><br>      // otherwise, increment the counter<br>      this.ngZone.run(() =&gt; {<br>        this.moveCount++;<br>      });<br>    };<br><br>    container.addEventListener(&#39;mousemove&#39;, this.listener);<br>  });<br>}</pre><p>In here, for #untracker-box, we are keeping the mouse movement listener *<em>outside</em>* of Angular’s zone. If mouse is been on container except #untracker-box we manually <em>re-enter </em>the Angular zone to trigger change detection specifically for updating the moveCount variable;</p><pre>this.ngZone.run(() =&gt; {<br>    this.moveCount++;<br>});</pre><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fstackblitz.com%2Fedit%2Fstackblitz-starters-n9n4anwj%3Fembed%3D1%26file%3Dsrc%252Fapp%252Fcomponents%252Fmouse-tracker%252Fmouse-tracker.component.ts%26initialPath%3Dmouse-tracker%26theme%3Dlight&amp;display_name=StackBlitz&amp;url=https%3A%2F%2Fstackblitz.com%2Fedit%2Fstackblitz-starters-n9n4anwj%3Fembed%3D1%26file%3Dsrc%252Fapp%252Fcomponents%252Fmouse-tracker%252Fmouse-tracker.component.ts%26initialPath%3Dmouse-tracker%26theme%3Dlight&amp;image=https%3A%2F%2Fsocial-img.staticblitz.com%2Fprojects%2Fstackblitz-starters-n9n4anwj%2F6612cf1c43a736bd0b355948707a43f2&amp;type=text%2Fhtml&amp;schema=stackblitz" width="745" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b5b9432fd6167d3be15b3083b7f243b/href">https://medium.com/media/7b5b9432fd6167d3be15b3083b7f243b/href</a></iframe><h4>onStable()</h4><p>onStable is run once all asynchronous tasks have completed and Angular considers the application to be stable again.</p><pre>ngAfterViewInit() {<br>  this.ngZone.onStable.subscribe(() =&gt; {<br>    console.log(&#39;All async work is done. The user interface is now stable.&#39;);<br>  });<br>}</pre><h4>onUnstable()</h4><p>onUnstable is triggered when Angular detects that an asynchronous task has started — before it completes. It signals that the application is no longer stable and that change detection may be required soon. On the other hand, it says; ‘something is happening right now’.</p><p>Let’s examine a simple example about onStable() and onUnstable();</p><pre>ngOnInit() {<br>  this.ngZone.onUnstable.subscribe(() =&gt; {<br>    console.log(&#39;Async operation started&#39;);<br>    this.isLoading = true;<br>  });<br><br>  this.ngZone.onStable.subscribe(() =&gt; {<br>    console.log(&#39;Async operation completed&#39;);<br>    this.isLoading = false;<br>  });<br>}</pre><p>Here, onStable() and onUnstable() allow us to control the visibility of the loading spinner.</p><p>In next part we’ll look at Zoneless Angular. We’ll explore how you can build Angular applications without relying on Zone.js at all — and still keep everything reactive.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7a3691d522b2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[“Understanding Angular Change Detection — Part 1: The Role of Zone.js”]]></title>
            <link>https://medium.com/@samet-acar/understanding-angular-change-detection-part-1-the-role-of-zone-js-d5e56527d35c?source=rss-503744769173------2</link>
            <guid isPermaLink="false">https://medium.com/p/d5e56527d35c</guid>
            <category><![CDATA[ngzone]]></category>
            <category><![CDATA[zonejs-in-angular]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[zone]]></category>
            <category><![CDATA[change-detection]]></category>
            <dc:creator><![CDATA[samet acar]]></dc:creator>
            <pubDate>Sun, 15 Jun 2025 08:04:58 GMT</pubDate>
            <atom:updated>2025-08-08T11:41:13.164Z</atom:updated>
            <content:encoded><![CDATA[<h3>Mastering Angular Zones — Part 1: The Role of Zone.js</h3><p>In this blog series, we’ll explore Angular’s ‘Change Detection Strategy’ and the concept of ‘zoneless’ Angular applications. This will be a comprehensive exploration, so I’ve decided to divide it into multiple parts. In this first chapter, we’ll begin with Zone.js which acts as the core mechanism that triggers Angular’s change detection after asynchronous operations.</p><h3>What is Zone.js?</h3><p>In 2014, Zone.js was developed by Brian Ford and later adopted by Angular to facilitate change detection. It emerged as a key technology during the transition from Angular.js to Angular 2, offering a fundamental shift away from the dirty-checking mechanism of <em>$scope.$watch()</em> in Angular.js, and enabling a more performant and predictable change detection strategy in Angular 2 and beyond.</p><h4>Zone.js and Change Detection</h4><p>As mentioned, Angular 2 adopted a new change detection strategy, moving away from the dirty-checking mechanism of $scope.$watch() used in AngularJS.</p><p>Through its patching of asynchronous browser APIs — such as DOM events (click, submit…), XHRs (for fetching data from remote servers), Promises, and native timers (setTimeout, setInterval) — Zone.js notifies Angular when these operations complete. This notification is what triggers Angular’s change detection mechanism, allowing the application to efficiently detect and reflect any changes in its data models.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*90LInwwLu1gLXcGdLy0WFQ.png" /></figure><p>In short, Zone.js acts as a kind of messenger for async browser APIs in Angular.</p><h3>What happens outside Angular’s Zone?</h3><p>Let’s look at a practical example:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fstackblitz.com%2Fedit%2Fstackblitz-starters-n9n4anwj%3Fembed%3D1%26file%3Dsrc%252Fapp%252Fcomponents%252Fsith%252Fsith.component.ts%26theme%3Dlight&amp;display_name=StackBlitz&amp;url=https%3A%2F%2Fstackblitz.com%2Fedit%2Fstackblitz-starters-n9n4anwj%3Fembed%3D1%26file%3Dsrc%252Fapp%252Fcomponents%252Fsith%252Fsith.component.ts%26theme%3Dlight&amp;image=https%3A%2F%2Fsocial-img.staticblitz.com%2Fprojects%2Fstackblitz-starters-n9n4anwj%2F6f23700995b770d6f686260fad40059c&amp;type=text%2Fhtml&amp;schema=stackblitz" width="745" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/f74e44170bac3253dfe231d5bcdaaa13/href">https://medium.com/media/f74e44170bac3253dfe231d5bcdaaa13/href</a></iframe><p>In this demo;</p><ul><li>The Obi-Wan Kenobi (Jedi) component runs inside Angular’s zone.</li><li>The Darth Maul (Sith) component runs outside of it.</li></ul><p>When the “Click Me” button is clicked, Obi-Wan’s lightsaber color changes to Green (and the UI updates), while Darth Maul’s internal data changes but no view update occurs.</p><pre>&lt;button id=&quot;sith-btn&quot;&gt;Click Me&lt;/button&gt;</pre><pre>ngAfterViewInit(): void {<br>    // Here is important, runs it outside ngZone<br>    this.ngZone.runOutsideAngular(() =&gt; {<br>      const btn = this.el.nativeElement.querySelector(&#39;#sith-btn&#39;);<br><br>      btn.addEventListener(&#39;click&#39;, () =&gt; {<br>        this.lightsaberColor = &#39;green&#39;;<br>        this.lightsaberText = &#39;Green Lightsaber&#39;;<br>      });<br>    });<br>}</pre><p>Here, we’re listening to the button click event outside Angular. You can see “ngZone” in here. NgZone is a service that wraps Zone.js context, enabling Angular to monitor and respond to asynchronous operations.</p><p><em>Note: Zone.js is still active in this example, but using runOutsideAngular() allows us to bypass Angular’s automatic change detection for this specific block of code. If you truly want to disable Zone.js entirely, you can remove it from your angular.json configuration. However, in this example, I used ngZone.runOutsideAngular() to demonstrate the difference while still having Zone.js present.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oXl-9fPQYCtabDXW2ZBS5A.jpeg" /><figcaption>A quick look at how Zone.js intercepts async events (like a button click), triggers Angular’s change detection via NgZone, and updates the DOM accordingly.</figcaption></figure><h3>What’s next?</h3><p>In the next chapter, we’ll dive deeper into Angular’s Change Detection mechanism itself — exploring how it works under the hood and how you can control it for better performance.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d5e56527d35c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mutable and Immutable Data in JavaScript/TypeScript: Shallow vs. Deep Copy Explained]]></title>
            <link>https://medium.com/@samet-acar/mutable-and-immutable-data-in-javascript-typescript-shallow-vs-deep-copy-explained-49b0a0d37fb0?source=rss-503744769173------2</link>
            <guid isPermaLink="false">https://medium.com/p/49b0a0d37fb0</guid>
            <category><![CDATA[mutable]]></category>
            <category><![CDATA[deep-copy]]></category>
            <category><![CDATA[immutable]]></category>
            <category><![CDATA[shallow-copy]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[samet acar]]></dc:creator>
            <pubDate>Fri, 04 Apr 2025 09:42:55 GMT</pubDate>
            <atom:updated>2025-04-04T09:42:55.698Z</atom:updated>
            <content:encoded><![CDATA[<p>As you know, there are two types of variables in JavaScript: primitive and non-primitive/reference types. Primitive types are immutable, whereas reference types are mutable.,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4x68--KY0bLy5yh7COLuBw.png" /><figcaption>generated by ChatGpt</figcaption></figure><h3>What is Immutable?</h3><pre>let number = 1;<br>let numero;<br><br>numero = number;<br>number = 5;<br><br>console.log(number); // 5 <br>console.log(numero); // 1 </pre><p>If we assign a primitive variable to another variable, its value itself is copied, not the reference. For example, just above; we assign number to numero. But after change the value of “number” to 5, “number” is rewritten again in memory with independently. And numero is not affected from that. Its value is still 1.</p><p>So we can say that, Primitive types (string, number, boolean, null, undefined, bigint, and symbol) are stored directly in memory and copied by value. When we assign a primitive variable to another variable, its value is copied, not its reference. Each primitive variable has its own independent memory space.</p><h3>Mutable</h3><pre>let character_1 = {<br>  name: &#39;Gandalf&#39;,<br>  location: &#39;Moria&#39;,<br>};<br><br>let character_2;<br>character_2 = character_1;<br><br>character_2.location = &#39;Rohan&#39;;<br><br>console.log(character_1.location); // Rohan<br>console.log(character_2.location); // Rohan</pre><p>In here, when we assign character_1 to character_2, we are not copying the object itself, but rather its memory reference. Both variables now point to the same object in memory. Mutable types such as Arrays and Objects are stored in memory only once, and multiple variables can reference the same memory location. When we assign a mutable variable to another variable, the value of the new variable is not written in memory again. When assigning a mutable variable to another variable, the new variable does not store a separate copy of the object. Instead, it stores a reference to the original object, meaning both variables point to the same data in memory.</p><figure><img alt="Mutable Frog" src="https://cdn-images-1.medium.com/max/1024/1*B3F5A-VEctE_cJWuUJDGWg.jpeg" /><figcaption>Mutable Frog - Generated by Grok</figcaption></figure><p>So when we change the object’s property for one of them. It will be changed for all of them. Because there is actually only one instance of the data in memory. And <em>character_1 </em>and <em>character_2 </em>just shares the memory’s reference address.</p><p>And that’s why it is called mutable. We can change it’s value.</p><h3>How to Create an Independent Copy of a Mutable Value in TypeScript/JavaScript?</h3><p>There are some methods and operators to create shallow copy such as <em>map(), slice(), spread operator(…), Object.assign(), Array.from()</em> etc. Those methods help to create independent new copy variable for array and objects. Some of them also have their own special abilities. For example, The <em>map()</em> method creates a new array where each element is transformed based on the provided function. It does not directly create a copy but rather a modified version of the original array.</p><p>But if we just wish to create a brand new copy of mutable array/object. When choosing a method for copying data, performance should be a key consideration. I did a small test for you. I have a string array which contains 15000 element;</p><pre>[<br>    &quot;Godric&quot;,<br>    &quot;Wulfstan&quot;,<br>    &quot;Thryma&quot;,<br>    &quot;Eomer&quot;,<br>    .<br>    .<br>]</pre><p>Here is the test and result;</p><pre>import PeopleOfRohan from &#39;./data/people-of-rohan.json&#39;;<br><br>let people = PeopleOfRohan;<br><br>console.time(&#39;map()&#39;);<br>let people2 = people.map((item) =&gt; item);<br>console.timeEnd(&#39;map()&#39;);<br><br>console.time(&#39;Object.assign()&#39;);<br>let people3 = Object.assign([], people);<br>console.timeEnd(&#39;Object.assign()&#39;);<br><br>console.time(&#39;slice()&#39;);<br>let people4 = people.slice();<br>console.timeEnd(&#39;slice()&#39;);<br><br>console.time(&#39;spread operator&#39;);<br>let people5 = [...people];<br>console.timeEnd(&#39;spread operator&#39;);<br><br>console.time(&#39;Array.from()&#39;);<br>let people6 = Array.from(people);<br>console.timeEnd(&#39;Array.from()&#39;);</pre><pre>map(): 0.65185546875 ms<br>Object.assign(): 5.18505859375 ms<br>slice(): 0.007080078125 ms<br>spread operator: 1.248046875 ms<br>Array.from(): 1.02001953125 ms</pre><p>According the results, it seems, using slice() operator could be the best choice for performance issue.<br>On the other hand, these shallow copy methods do not work properly for lists of objects. So we need to do deep copy for them.</p><h3>What is Deep Copy?</h3><p>What if we have an object list data, instead of array;</p><pre>[<br>    {<br>        &quot;name&quot;: &quot;Hirluin&quot;,<br>        &quot;age&quot;: 71,<br>        &quot;city&quot;: &quot;Tarnost&quot;<br>    },<br>    {<br>        &quot;name&quot;: &quot;Faramir&quot;,<br>        &quot;age&quot;: 34,<br>        &quot;city&quot;: &quot;Minas Tirith&quot;<br>    },<br>    .<br>    .<br>]</pre><pre>import PeopleOfGondor from &#39;./data/people-of-gondor.json&#39;;<br><br>let peopleGondor = PeopleOfGondor;<br>let peopleGondor2 = peopleGondor.slice();<br><br>peopleGondor2[0].name = &#39;Aragorn&#39;;<br><br>console.log(peopleGondor[0].name);  // Aragorn<br>console.log(peopleGondor2[0].name); // Aragorn</pre><p>Shallow copy methods like <em>slice()</em> create a new array instance, but the objects within it still reference the original memory locations. As a result, modifying an object inside the copied array will also affect the original one.</p><figure><img alt="shallow copy vs deep copy for array of objects" src="https://cdn-images-1.medium.com/max/1024/1*4JT4JWrJSWTXKmwveJrFNg.png" /><figcaption>shallow copy vs deep copy for arr. of objects</figcaption></figure><p>This means modifying an object inside the copied array will also affect the original array. It can’t change the reference of inner objects. So we use deep copy methods for it like <em>JSON.parse(JSON.stringify(obj)), _.cloneDeep(obj) (Lodash), structuredClone(obj)</em>.</p><p>Let’s check their performances;</p><pre>import PeopleOfGondor from &#39;./data/people-of-gondor.json&#39;;<br>import _ from &#39;lodash&#39;;<br><br>let peopleGondor = PeopleOfGondor;<br><br>console.time(&#39;JSON.parse(JSON.stringify())&#39;);<br>let peopleGondor2 = JSON.parse(JSON.stringify(peopleGondor));<br>console.timeEnd(&#39;JSON.parse(JSON.stringify())&#39;);<br><br>console.time(&#39;structuredClone()&#39;);<br>let peopleGondor3 = structuredClone(peopleGondor);<br>console.timeEnd(&#39;structuredClone()&#39;);<br><br>console.time(&#39;lodash&#39;);<br>let peopleGondor4 = _.cloneDeep(peopleGondor);<br>console.timeEnd(&#39;lodash&#39;);</pre><pre>JSON.parse(JSON.stringify()): 2.85009765625 ms<br>valinor.component.ts:48 structuredClone(): 5.236083984375 ms<br>valinor.component.ts:52 lodash: 20.825927734375 ms</pre><p><em>JSON.parse(JSON.stringify(obj))</em> is a performant deep copy method, but it does not correctly handle special data types like <em>Date</em>, <em>RegExp</em>, <em>Map</em>,<em> Set</em>, and <em>functions</em>. The <em>structuredClone()</em> method is likely the best choice for deep copying, as it correctly handles functions and Date objects, unlike <em>JSON.parse(JSON.stringify(obj))</em>.</p><h3>Why Do We Need These Copy Methods in Angular?</h3><ul><li>When you assign an object to another variable, only the reference is copied; it is not a copy of the original object but a pointer pointing to the same memory. This can cause problems when using two-way binding or input/output in Angular.</li><li>If you use Angular’s ‘OnPush’ change detection strategy, immutability becomes even more crucial, as Angular only re-renders components when input references change. Angular’s change detection is based on reference equality. If only a shallow copy is taken, Angular might not recognize that the data has changed, leading to UI inconsistencies.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=49b0a0d37fb0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Use Standalone Components and Pipes in a Modular Angular Project?]]></title>
            <link>https://medium.com/@samet-acar/how-to-use-standalone-components-and-pipes-in-a-modular-angular-project-4cc0c823afdb?source=rss-503744769173------2</link>
            <guid isPermaLink="false">https://medium.com/p/4cc0c823afdb</guid>
            <category><![CDATA[angular-standalone]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[standalone-component]]></category>
            <category><![CDATA[angular-module]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[samet acar]]></dc:creator>
            <pubDate>Thu, 20 Mar 2025 16:08:43 GMT</pubDate>
            <atom:updated>2025-03-20T16:08:43.183Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s say we have a modular Angular project(the project is built on modules). And we need to add a new component or a custom pipe in it. And we decided to add it as <em>standalone</em>. How can we add it into module system? Can we use it with importing in related component? If not, how do we add it to a module? Let’s find out together.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8UQNba5sxf2NksvemVJV4g.png" /></figure><p>As you know, with Angular v14.1, Angular introduced <em>Standalone components</em>. At that time, this was actually an experimental metadata for components. However, with Angular 15, they introduced a stable version of standalone components and this was going to be an introduction to module-less Angular applications.</p><p>In fact with Angular 19, <em>standalone </em>will become the default behavior for components. But on the other hand, the module system can still be a great choice for complex applications. And also, Our old projects still could stay as modular. So let’s find out how to add a <em>standalone</em> component to modular app.</p><p>We can add a standalone component/directive/pipe to a module again. but a bit different.</p><pre>src/<br>├── app/<br>│   ├── components/               # Shared components<br>│   │   └── character-display/    # Component for displaying character info<br>│   ├── pages/                    # Feature pages<br>│   │   ├── good-side-pages.module.ts<br>│   │   ├── bad-side-pages.module.ts<br>│   │   ├── gondor/<br>│   │   ├── mordor/<br>│   │   ├── rivendell/<br>│   │   └── rohan/<br>│   ├── pipes/                    # Custom pipes<br>│   │   └── character-info.pipe.ts<br>│   ├── app.component.ts          # Root component<br>│   ├── app.module.ts             # Root module<br>│   └── app-routing.module.ts     # Application routes<br>└── ...</pre><p>This was my project’s structure. It helped a lot for <a href="https://medium.com/@samet-acar/understanding-angular-ngmodule-imports-declarations-and-more-ce71fc1dc9b9">previous post</a>. You can download that repo from <a href="https://github.com/sametacar/angular-decorator-example">here</a>. You can see there, <em>CharacterInfoPipe </em>has non-standalone decorator metadata in <em>character-info.pipe.ts </em>Let’s change it to<em> </em>standalone;</p><pre>import { Pipe, PipeTransform } from &#39;@angular/core&#39;;<br><br>@Pipe({<br>  name: &#39;characterInfo&#39;,<br>  standalone: true, // &lt;--- This is the key for the pipe to be standalone<br>})<br>export class CharacterInfoPipe implements PipeTransform {<br>  transform(value: string): string {<br>    if (!value) return &#39;&#39;;<br><br>    // Convert to uppercase and add &quot;- fraction hero&quot; suffix<br>    return `${value.toUpperCase()} - SelectedFraction Hero`;<br>  }<br>}</pre><p>Now let’s add it to it’s own module which is PipesModule ;</p><pre>@NgModule({<br>  declarations: [],<br>  imports: [CommonModule, CharacterInfoPipe],<br>  exports: [CharacterInfoPipe],<br>})<br>export class PipesModule {}</pre><p>Normally in Modular structure, we add <em>components/pipes/directives</em> to declarations. However, Standalone components cannot be declared. But if you really want to add it into module, we have to add it into <em>imports</em>, instead of <em>declarations</em>. Then we can import <em>PipesModule </em>in related module(ComponentsModule) normally.</p><p>Alternatively, instead of importing <em>PipesModule</em>, we can directly import <em>CharacterInfoPipe</em> into <em>ComponentsModule </em>as well.</p><pre>import { NgModule } from &#39;@angular/core&#39;;<br>import { CommonModule } from &#39;@angular/common&#39;;<br>import { CharacterDisplayComponent } from &#39;./character-display/character-display.component&#39;;<br>import { PipesModule } from &#39;../pipes/pipes.module&#39;; // &lt;-- No need to import the pipe&#39;s module here.<br>import { CharacterInfoPipe } from &#39;../pipes/character-info.pipe&#39;;<br><br>@NgModule({<br>  declarations: [CharacterDisplayComponent],<br>  imports: [CommonModule, CharacterInfoPipe],<br>  exports: [CharacterDisplayComponent],<br>})<br>export class ComponentsModule {}</pre><p>But we cannot import <em>CharacterInfoPipe</em> in <em>CharacterDisplayComponent </em>directly. Because the component is non-standalone. If we want to use <em>CharacterInfoPipe</em> directly inside <em>CharacterDisplayComponent</em>, we first need to make CharacterDisplayComponent standalone as well. But like this, then it starts to evolve into something completely different. And we’re going to examine standalone app in next blogposts.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4cc0c823afdb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Angular @NgModule: Imports, Declarations, and More]]></title>
            <link>https://medium.com/@samet-acar/understanding-angular-ngmodule-imports-declarations-and-more-ce71fc1dc9b9?source=rss-503744769173------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce71fc1dc9b9</guid>
            <category><![CDATA[metadata]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[ngmodule]]></category>
            <category><![CDATA[angular-decorator]]></category>
            <dc:creator><![CDATA[samet acar]]></dc:creator>
            <pubDate>Sat, 15 Mar 2025 23:47:58 GMT</pubDate>
            <atom:updated>2025-03-15T23:47:58.363Z</atom:updated>
            <content:encoded><![CDATA[<p>After <em>Angular 15</em>, Angular starts to recommend using Standalone components instead of Modules. In fact, with <em>Angular 19</em>, Components come with <em>standalone: ​​true</em> by default. On the other hand, although the Modular structure has become an old fashioned method, we continue to use it for old projects.</p><p>And after setting up the project, sometimes we can forget where to add a new pipe or directive. Let’s start examining the <strong>@NgModule</strong> decorator metadata together. <strong>@NgModule</strong> decorator has 5 metadata which are <em>declarations</em>, <em>imports</em>, <em>exports</em>, <em>providers</em>, <em>bootstrap</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*BQKf7VSJWTqSzS2NFX-buQ.jpeg" /><figcaption>@NgModule Decorator Metadata Diagram</figcaption></figure><h3><strong>Declarations</strong></h3><p>Let’s say we have a component called <em>RohanComponent</em>. And we will bind this component to a module. For this, we use <strong>declarations</strong> metadata.</p><p>In short, in Declarations we define which components, directives or pipes belong to which module. <strong>A component (or directive/pipe) can be defined in only one module.</strong></p><p>Lets examine <a href="https://github.com/sametacar/angular-decorator-example">our example</a>. We have 4 pages which are Mordor, Rohan, Rivendell, Gondor pages. Let’s define these in two separate modules: GoodSidePages Module, BadSidePages Module. Let’s define Rohan, Rivendell, and Gondor to <em>GoodPagesModule</em>. To do this, let’s add them to the <em>GoodPagesModule</em> declarations.</p><pre>@NgModule({<br>  declarations: [GondorComponent, RivendellComponent, RohanComponent]<br>})<br>export class GoodSidePagesModule {}</pre><p>So Rohan belongs to <em>GoodSidePagesModule</em>.🐎</p><pre>src/<br>├── app/<br>│   ├── components/               # Shared components<br>│   │   └── character-display/    # Component for displaying character info<br>│   ├── pages/                    # Feature pages<br>│   │   ├── good-side-pages.module.ts<br>│   │   ├── bad-side-pages.module.ts<br>│   │   ├── gondor/<br>│   │   ├── mordor/<br>│   │   ├── rivendell/<br>│   │   └── rohan/<br>│   ├── pipes/                    # Custom pipes<br>│   │   └── character-info.pipe.ts<br>│   ├── app.component.ts          # Root component<br>│   ├── app.module.ts             # Root module<br>│   └── app-routing.module.ts     # Application routes<br>└── ...</pre><h3>Imports</h3><p>We have defined the <em>GoodSidePagesModule</em>. Great news! But it’s not over. In order to use the Rohan page in app.component, we need to import the <em>GoodSidePagesModule</em> in the <em>AppModule</em>.</p><pre>@NgModule({<br>  declarations: [AppComponent],<br>  imports: [<br>    BrowserModule,<br>    FormsModule,<br>    AppRoutingModule,<br>    GoodSidePagesModule,<br>    BadSidePagesModule,<br>  ]<br>})<br>export class AppModule {}</pre><p>Like same logic, for example if we need to use a pipe or a directive in a component we have to import that pipe’s module in related page module. <br>For example; Let’s have a custom pipe named <em>CharacterInfoPipe</em>. And let’s create the module of the pipe and define the pipe there.</p><pre>@NgModule({<br>  declarations: [CharacterInfoPipe],<br>  imports: [CommonModule],<br>  exports: [CharacterInfoPipe],<br>})<br>export class PipesModule {}</pre><p>And to use this pipe, let’s import it to another module. for example, let’s import it to ComponentsModule and use it inside <em>CharacterDisplayComponent</em>.</p><pre>@NgModule({<br>  declarations: [CharacterDisplayComponent],<br>  imports: [CommonModule, PipesModule],<br>  exports: [CharacterDisplayComponent],<br>})<br>export class ComponentsModule {}</pre><p>character-display.component.html;</p><pre>&lt;div *ngIf=&quot;character&quot; class=&quot;selected-info&quot;&gt;<br>  &lt;p&gt;Selected character: &lt;strong&gt;{{ character | characterInfo }}&lt;/strong&gt;&lt;/p&gt;<br>&lt;/div&gt;</pre><h3>Exports</h3><p>It’s the opposite of imports. We define a component in a module, and if we wish to use this component in a different module, we have to add it to the exports of the module.</p><pre>@NgModule({<br>  declarations: [CharacterInfoPipe],<br>  imports: [CommonModule],<br>  exports: [CharacterInfoPipe],<br>})<br>export class PipesModule {}</pre><p>After declaring <em>CharacterInfoPipe</em> in <em>PipesModule</em>, if we do not add it to <strong>exports</strong>, we can only use it in <em>PipesModule</em>. In order to use it in other modules, therefore in other components, we need to add it to exports.</p><p>And of course, we have to <strong>import </strong><em>PipesModule </em>in the module of related component so that we can use it there.</p><h3>Bootstrap</h3><p>Bootstrap determines the first component that Angular will run. There can be only one <strong>bootstrap</strong> metadata in the project.</p><pre>@NgModule({<br>  declarations: [AppComponent],<br>  imports: [<br>    BrowserModule,<br>    FormsModule,<br>    AppRoutingModule,<br>    GoodSidePagesModule,<br>    BadSidePagesModule,<br>  ],<br>  bootstrap: [AppComponent],<br>})<br>export class AppModule {}</pre><p>Project’s bootstrap is usually defined as AppComponent, but of course it can also be defined as another custom component.</p><h3>Providers</h3><p>Mostly, we use providers to inject services into the related module or components. This array is where we declare the services (or other dependencies) that the Angular injector will use to create and manage instances of these services for dependency injection. The providers can be used at the module, component, or directive level to control the scope of service instances.</p><p>You can checkout my <a href="https://github.com/sametacar/angular-decorator-example">NgModule Decorator repo</a> if you wish. <br>In the next article, we will examine the <strong>standalone</strong> components.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce71fc1dc9b9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Is using Angular Pipe good for performance?]]></title>
            <link>https://medium.com/@samet-acar/is-using-angular-pipe-good-for-performance-f8f02f476ac3?source=rss-503744769173------2</link>
            <guid isPermaLink="false">https://medium.com/p/f8f02f476ac3</guid>
            <category><![CDATA[angular-pipe]]></category>
            <category><![CDATA[pipes]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[samet acar]]></dc:creator>
            <pubDate>Sat, 08 Mar 2025 07:00:06 GMT</pubDate>
            <atom:updated>2025-03-08T07:00:06.869Z</atom:updated>
            <content:encoded><![CDATA[<p>First of all, I would like to clarify that, we’re gonna talk about Angular pipes, not the <a href="https://rxjs.dev/api/index/function/pipe">RxJS pipe</a>. Although the working logic of the two is similar, but their uses are a bit different.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QmqJN75cE4HHDBk0u9sFFQ.jpeg" /></figure><p>First of all, let’s point out that it’s name comes from unix/linux. and it uses vertical bar notation “|”.</p><h3>What is Angular Pipe?</h3><p>Well, probably you know what it is, but let me remind it to you simply. it is a good operator for <strong>transforming</strong> the data into a different form in the browser <strong>without changing the data itself</strong>.</p><p>For example, Let’s assume that you have a name value in your incoming JSON in lower case. And you would like to show it with upper case format in browser without changing it, Angular pipe is one of the best method to do it.</p><pre>characters[0].name = &#39;Frodo Baggins&#39;;</pre><pre>&lt;span&gt;{{ character[0].name | uppercase }}&lt;/span&gt;</pre><figure><img alt="Browser view of Upper Case pipe" src="https://cdn-images-1.medium.com/max/593/1*XWtFiEKXA74SBZ22CfPtrA.jpeg" /><figcaption>Browser view of Upper Case pipe</figcaption></figure><p>But on the other hand, the value is still ‘Frodo Baggins’. There are lots of Angular pipes like this, some of them; AsyncPipe, DecimalPipe, UpperCasePipe, I18nSelectPipe, SlicePipe… and so on.</p><h3>How About Performance?</h3><p>If we use inline method call for changing value in template,</p><pre>&lt;span class=&quot;highlight&quot;&gt;{{ convertUpperCase(character.name) }}&lt;/span&gt;</pre><p>This ‘convertUpperCase’ function is run every time the <strong>Change Detection Cycle</strong> is triggered. If you have a lot of events in your project like Event Handlers, setTimeout, lots of Http requests, lots of @Input() properties in components etc. These events and properties trigger the Change Detection Cycle. Especially if your component has not OnPush detection strategy.</p><pre>@Component({<br>  selector: &#39;app-some-component&#39;,<br>  changeDetection: ChangeDetectionStrategy.Default<br>})</pre><p>But in most of the projects, the Detection Strategies of many components are ‘Default’ instead of ‘OnPush’. In fact, if we don’t declare it in component decorator, it comes as ‘Default’, as you know. And using inline calling function methods may cause some performance problems with in this settings. At this very moment, We can get help from Angular Pipe. 🥳</p><p>Pipe only works if the value (or parameter of the pipe) is changed, even if you use the default detection strategy(unless it’s a impure pipe). In fact, I personally use pipes in ‘ngClass’ in some of my projects. Because all directives such as ngClass, ngIf, ngFor <strong>are executed</strong> repeatedly in <strong>each ‘Change Detection Cycle’</strong>.</p><h3>Are Impure Pipes the Bad Guys in Pipes World?</h3><p>When defining a pipe’s decorator(custom pipe), there is a metadata property called ‘pure’, which can be either a boolean or undefined. If it’s not explicitly defined, it automatically takes the value <em>pure: true</em> in AOT(Ahead-of-Time) compilation.</p><pre>@Pipe({<br>  name: &#39;characterFormatterImpure&#39;,<br>  standalone: true,<br>  pure: false, // Impure pipe - will be called on every change detection cycle<br>})</pre><p>When we define the <em>pure </em>property as <em>false</em>, the pipe behaves like a directive, <strong>executing every time the Change Detection cycle is triggered</strong>, regardless of whether the value has changed.</p><p>So why do we need impure pipes? Angular cannot detect changes in mutable data, such as Observables, Arrays, and Objects (both as values and parameters). This is where impure pipes come in. Even some core Angular pipes are impure, such as <em>JsonPipe</em>, <em>KeyValuePipe</em>, and <em>SlicePipe</em>.</p><p>Let’s do a simple example for it,</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fstackblitz.com%2Fedit%2Fbolt-angular-dz4nokjx%3Fembed%3D1%26file%3Dsrc%252Fapp%252Fapp.component.html&amp;display_name=StackBlitz&amp;url=https%3A%2F%2Fstackblitz.com%2Fedit%2Fbolt-angular-dz4nokjx%3Fembed%3D1%26file%3Dsrc%252Fapp%252Fapp.component.html&amp;image=https%3A%2F%2Fsocial-img.staticblitz.com%2Fprojects%2Fbolt-angular-dz4nokjx%2Fc8b0812fb5ba85c2098aeac75d409a39&amp;type=text%2Fhtml&amp;schema=stackblitz" width="745" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/31a599eb60e3c0f59de38aaaeb4b2bb6/href">https://medium.com/media/31a599eb60e3c0f59de38aaaeb4b2bb6/href</a></iframe><pre>formatOptions: { [key: string]: string } = {<br>    showRace: &#39;true&#39;,<br>    showAge: &#39;true&#39;,<br>    showWeapon: &#39;true&#39;,<br>    titlePrefix: &#39;Brave&#39;,<br>};</pre><p>We updated the properties of the <em>formatOptions</em> object by clicking the ‘Change Format Options’ button. However, since the object reference hasn’t changed, the pure pipe does not detect the update.</p><p>But if we do not wish to use an impure pipe due to performance concerns, we can update <em>formatOptions</em> using the ‘spread operator’, or alternatively, we can define it as an Observable (e.g., BehaviorSubject). Or, we can trigger it manually with the detectChanges() function of <em>ChangeDetectorRef</em>. But that’s another topic — we’ll look into that later.</p><p>If you want to examine more Angular pipe examples, you can clone the <a href="https://github.com/sametacar/angular-pipe-examples">repo</a> I created and examine it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f8f02f476ac3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[If you look at rear mirror too long, accident becomes inevitable]]></title>
            <link>https://medium.com/@samet-acar/if-you-look-at-rear-mirror-too-long-accident-becomes-inevitable-11c038417bb0?source=rss-503744769173------2</link>
            <guid isPermaLink="false">https://medium.com/p/11c038417bb0</guid>
            <category><![CDATA[life]]></category>
            <dc:creator><![CDATA[samet acar]]></dc:creator>
            <pubDate>Thu, 13 Feb 2025 00:00:41 GMT</pubDate>
            <atom:updated>2025-03-07T19:02:35.304Z</atom:updated>
            <content:encoded><![CDATA[<p>I watched a video months ago, in there a reporter asked a question to <a href="https://en.wikipedia.org/wiki/%C4%B0lber_Ortayl%C4%B1">Ilber Ortayli</a> who is historian, and writer. Question was ‘Do you ever get depressed?’. And Mr. Ortayli answered, ‘Of course, like everyone else, I get depressed from time to time.’ Well that answer shocked me a bit. Because he is so weel educated and very knowledgeable man. he knows how to enjoy life or how to spend time properly. and he said, yes I get depressed too. Wow.. that enlightened me a lot. And then I just realized that, being depressed is so normal, and so human thing.</p><p>Unless you do not allow to take it too much time. when the right time comes, you have to let it go, instead of embracing it. remember what dear <a href="https://www.imdb.com/name/nm0000158/">Tom Hanks</a> said; “ <strong>This too shall pass</strong>”. even good things and bad thigs in our lives, well all they shall pass.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-VHhRsx3QRC1XXEd" /></figure><p>Just do not dig it more and more. don’t stuck with your past. if you look at your past too much, you cannot see your what’s in front of you. and the accident becomes inevitable. On the other hand, yes, I totally agree, we learn a lot from our past. But I believe that no need to turning the same pages over and over again. Put a label on the past and move it to the library. you cannot make a profitable gain on it by digging it more than necessary.</p><p>let’s give an ear to Miles;<br><a href="https://www.youtube.com/watch?v=1uGoCqUBY2E">https://www.youtube.com/watch?v=1uGoCqUBY2E</a></p><p>“You can’t control the wind, but you can adjust your sails, its not about what happens to you, it’s how you REACT!” what a simple and mindful thoughts they are, right?</p><p>Stop complaining about what happens to you while you’re alive. Yes life is not that fair, it’s a fact. But I have never seen anyone gain from complaining. We should define the things we complain about as experiences, and move on. we have to move on, even we do not want move on.</p><p>Forexample, today when I woke up, I did not want to do anything. even I can’t move my arm. Life seemed so hard. But I didn’t fall for those tricks from life and forced myself to go to the gym. And after some exercises, I’ve become a new guy who is so energetic, lovefull, joyfull :) And these lines you are reading now are its fruit.</p><p>So everything is on our hands. whatever we do, we do it for ourselves. So, let’s take action…</p><p><em>Originally published at </em><a href="https://sametacar.com/blog/if-you-look-at-rear-mirror-too-long-accident-becomes-inevitable."><em>https://sametacar.com</em></a><em> on February 13, 2025.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=11c038417bb0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The rabbit does not run away because it is afraid, it is afraid because it runs away]]></title>
            <link>https://medium.com/@samet-acar/the-rabbit-does-not-run-away-because-it-is-afraid-it-is-afraid-because-it-runs-away-22ec09ba1493?source=rss-503744769173------2</link>
            <guid isPermaLink="false">https://medium.com/p/22ec09ba1493</guid>
            <category><![CDATA[life]]></category>
            <dc:creator><![CDATA[samet acar]]></dc:creator>
            <pubDate>Tue, 21 Jan 2025 00:00:16 GMT</pubDate>
            <atom:updated>2025-03-07T18:38:41.043Z</atom:updated>
            <content:encoded><![CDATA[<p>‘The rabbit does not run away because it is afraid, it is afraid because it runs away’. It’s a quote from the ‘ <a href="https://en.wikipedia.org/wiki/Kuva-yi_Milliye">Kuvayi Milliye</a>’ poem of <a href="https://en.wikipedia.org/wiki/N%C3%A2z%C4%B1m_Hikmet">Nazım Hikmet</a>.</p><p>Probably, Nazım Hikmet refers to the <a href="https://en.wikipedia.org/wiki/James%E2%80%93Lange_theory">James-Lange Theory</a> here. And yes, sometimes in our lives, we can observe that emotional reaction in reverse. Also, <a href="https://en.wikipedia.org/wiki/William_James">William James</a>, one of the discoverers of the Theory of Emotion, said another word which is ‘The greatest weapon against stress is our ability to choose one thought over another.’ Let us make an effort to ensure that the other thoughts mentioned here are positive ones.</p><p>Meanwhile, Humanity has another problems;</p><p>‘Got a million things to distract my mind<br>There’s a million ways I could spend my time<br>Keeping me from who I need to be <br>Distracting me from what I need to do’</p><p>Dear Katrine Stenbekk who is the singer of <a href="https://open.spotify.com/intl-tr/artist/2N0vFuOoMtAQfBmhsRo24e?si=yOpeDwlcTlS5jCV0vZgyEQ">Kalandra</a>, says above words while singing the <a href="https://www.youtube.com/watch?v=FjghdvL-LW0">Slow Motion</a> song(great song by the way). How true these words are, especially for today. Social media, streaming services, etc. have an amazing ability to distract our focus from what we need to be doing. You know, if you use sugar for your daily nutrition, the brain will carefully request it from us during or after the meal when you do not use sugar. Because it is so easy to get energy from sugar instead of vegetables etc.</p><p>Brain just wants instant energy. Don’t want to waste it also. The brain’s tendency is not to waste its energy on unnecessary problems(according to it). In other words, we try our body to make it better for ourselves while doing sport, even if our body sometimes does not want to do it. So I believe, we should use same practice to our brain also.</p><p>To cut it short; no matter how old we are, whatever we have experienced, just keep working for harder and better. If we stop, we’ll lose. Never give up, and do not forget to enjoy with your life, and fight for it.</p><p>May the force be with us all, always.</p><p><em>Originally published at </em><a href="https://sametacar.com/blog/the-rabbit-does-not-run-away-because-it-is-afraid-it-is-afraid-because-it-runs-away"><em>https://sametacar.com</em></a><em> on January 21, 2025.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22ec09ba1493" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>