<?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 Beccs Bo on Medium]]></title>
        <description><![CDATA[Stories by Beccs Bo on Medium]]></description>
        <link>https://medium.com/@rebeca.boanca?source=rss-f3f6bae5efad------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*QrMu18DWKlT6E5Sm_i-brg.jpeg</url>
            <title>Stories by Beccs Bo on Medium</title>
            <link>https://medium.com/@rebeca.boanca?source=rss-f3f6bae5efad------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 21:12:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rebeca.boanca/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[Understanding the rest parameter and reduce through a Christmas story. Rest vs Spread]]></title>
            <link>https://medium.com/@rebeca.boanca/understanding-the-rest-parameter-and-reduce-through-a-christmas-story-rest-vs-spread-d4732db74381?source=rss-f3f6bae5efad------2</link>
            <guid isPermaLink="false">https://medium.com/p/d4732db74381</guid>
            <dc:creator><![CDATA[Beccs Bo]]></dc:creator>
            <pubDate>Fri, 28 Nov 2025 14:12:02 GMT</pubDate>
            <atom:updated>2025-11-28T14:12:02.335Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s walk through the TypeScript rest parameter and the reduce() method using a simple Christmas story.</p><h3>A Christmas Eve Problem in Winter town</h3><p>Once upon a snowy Christmas Eve in the small village of <strong>Winter town</strong>, Alex was getting ready for a big holiday delivery. But this year, something unusual happened.</p><p>Every helper brought a different number of presents.</p><ul><li>Sam brought 3 gifts.</li><li>Ben brought 5.</li><li>Mia brought 1.</li><li>Leo ran in with 7 last-minute packages.</li><li>Others came with even more.</li></ul><p>Alex sighed. “How am I supposed to count all these gifts when each person brings a different amount?”</p><p>Jamie, a thoughtful helper, stepped in and said: “Alex, we need a way to collect any number of gifts — however many people bring — and put them into one list. <strong>That’s exactly what the rest parameter does.</strong>”</p><h3>The rest parameter: collecting any number of values</h3><p>Alex opened a laptop and wrote this TypeScript function:</p><pre>const countGifts = (...gifts: number[]) =&gt; {<br>  console.log(gifts);<br>};</pre><p>Jamie pointed to the three dots. “What does ...gifts mean?”</p><p>Alex explained: “The rest parameter takes all the values passed into the function and bundles them together into one array. It doesn’t matter if people bring two numbers or ten — they all get collected.”</p><p>For example:</p><pre>countGifts(3, 5, 1, 7);</pre><p>Inside the function, gifts becomes:</p><pre>[3, 5, 1, 7]</pre><p>Just like the helpers in Winter Town drop all their presents into a single box, the rest parameter groups all function arguments into a single list.</p><h3>Adding Reduce: Turning the List Into a Total</h3><p>Jamie looked at the list of gifts on the screen. “Okay, we have the list. But we still need the total number.”</p><p>Alex added one more piece of code:</p><pre>const countGifts = (...gifts: number[]) =&gt; {<br>  return gifts.reduce((total, current) =&gt; {<br>    return total + current;<br>  }, 0);<br>};</pre><p>“How does that work?” Jamie asked.</p><p>Alex explained:</p><ul><li>total is the running total of gifts so far.</li><li>current is the number being added right now.</li><li>0 is where the counting begins.</li></ul><p>So if the helpers bring:</p><pre>countGifts(3, 5, 1, 7);</pre><p>reduce() processes the array step by step:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-1DOJmrV2CJtXJAY-ZiDsw.png" /></figure><p>The function returns 16, the total number of gifts.</p><h3>Why This Matters</h3><p>Jamie summed it up:</p><ul><li>“The rest parameter gathers all the values.</li><li>The reduce method adds them up.”</li></ul><h3>Additional Useful Information</h3><p>When the counting was finished and the last gift box was sealed, Jamie stretched and said, “That rest parameter trick was really helpful. I didn’t realize functions could take any number of values like that.”</p><p>Alex nodded. “Since we’re already looking at this code, it might be the perfect time to understand something closely related. It uses the same dots, but works in the opposite direction. If you learn both now, you’ll never be confused by them again.”</p><p>Jamie pulled up a chair. “Alright. Show me.”</p><h3>Rest vs Spread</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eI0kPqHKuGcYcKGTEKs3cA.png" /></figure><p>Jamie nodded. “Okay. Rest gathers. Spread opens up.”</p><h3>When Rest Is Useful (The Way Alex Listed It)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1P9cMuk1e-z55fxtNAko0A.png" /></figure><p>Jamie looked at the table. “So rest is the collecting basket.”</p><h3>When Spread Makes Things Easier</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XTEjhQSJEcZyLmRNrxscsg.png" /></figure><p>Jamie grinned. “So spread is the opposite — it pours things out.”</p><h3>The Memory Trick Alex Shared</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*slIu3JF1bQ97oE-XqjDxqQ.png" /></figure><p>Jamie smiled. “That actually makes sense. Rest and spread do opposite things.”</p><p>Alex closed the laptop. “Exactly. And once you see it this way, you never mix them up again.”</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d4732db74381" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unwrapping the Spread Operator: A Holiday Coding Tale]]></title>
            <link>https://medium.com/@rebeca.boanca/unwrapping-the-spread-operator-a-holiday-coding-tale-4a34109e0538?source=rss-f3f6bae5efad------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a34109e0538</guid>
            <category><![CDATA[spread-operator]]></category>
            <category><![CDATA[objectcloning]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[es6]]></category>
            <category><![CDATA[array-manipulation]]></category>
            <dc:creator><![CDATA[Beccs Bo]]></dc:creator>
            <pubDate>Wed, 08 Oct 2025 15:39:53 GMT</pubDate>
            <atom:updated>2025-10-09T07:59:51.798Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s say you’re getting ready for Christmas… You are sitting by the fireplace, a cup of hot chocolate in hand, and you decide it’s the perfect time to make a playlist of Christmas songs. You open your laptop, fire up your favorite code editor, and start writing a bit of JavaScript to keep track of your songs.</p><p>You start simple:</p><pre>const christmasSongList = [&quot;Silent Night&quot;];</pre><p>One song so far — a classic. But wait, Christmas isn’t complete without a few more tunes. You find two more songs you love:</p><pre>const newChristmasSongs = [<br>  &quot;It&#39;s Beginning to Look a Lot Like Christmas&quot;,<br>  &quot;Last Christmas&quot; <br>]</pre><p>Now you want to <strong>combine both lists</strong>. Maybe you are considering this:</p><pre>christmasSongList.push(newChristmasSongs);</pre><p>But when you check your list, you see something unexpected:</p><pre>[&#39;Silent Night&#39;, [&quot;It&#39;s Beginning to Look a Lot Like Christmas&quot;, &quot;Last Christmas&quot;]]</pre><p>Oops — now you’ve got a playlist inside a playlist. That’s not what you wanted.</p><p>So you take another sip of cocoa and remember something you read about: the spread operator ( ... )</p><p>So you try again — this time with the magical three dots:</p><pre>const updatedChristmasSongList = [<br>  …christmasSongList,<br>  …newChristmasSongs<br>];</pre><p>And here you have it:</p><pre>[&#39;Silent Night&#39;, &quot;It&#39;s Beginning to Look a Lot Like Christmas&quot;, &quot;Last Christmas&quot;]</pre><p>Perfect! Everything’s laid out just the way you wanted. The <strong>spread operator </strong>has just spread the contents of both arrays into one flat list. No nesting. Just clean, simple JavaScript.</p><p>Then you remember your favorite Christmas book and you decide to do something similar with objects. You have an object representing your favorite Christmas book:</p><pre>const favoriteChristmasBook = {<br>  name: &quot;A Christmas Carol&quot;,<br>  author: &quot;Charles Dickens&quot;<br>};</pre><p>You want to <strong>make a copy of it </strong>— maybe to add extra details later, without touching the original. You could do it the old-fashioned way, looping through keys, but tonight’s about the easy way:</p><pre>const copiedFavoriteChristmasBook = { …favoriteChristmasBook };</pre><p>And just like that, you’ve made a copy. Merging feels like wrapping gifts.</p><p>It’s important to remember: if you instead did</p><pre>const copiedFavoriteChristmasBook = favoriteChristmasBook;</pre><p>you wouldn’t be making a copy at all — you’d just be copying the <strong>reference</strong>. That means both variables would point to the same object, and changing one would change the other. Using the spread operator avoids that, giving you a <strong>fresh object</strong> you can safely work with.</p><p>Then you think — what if you want to <strong>merge two objects</strong>?</p><pre>const favoriteChristmasBook = {<br>  name: &quot;A Christmas Carol&quot;,<br>  author: &quot;Charles Dickens&quot;<br>};<br><br>const bookDetails = { year: 1843, genre: &quot;Fiction&quot; };<br><br>const fullBookInfo = {<br>  …favoriteChristmasBook,<br>  …bookDetails<br>};</pre><p>Now fullBookInfo contains everything in one tidy package:</p><pre>{<br>name: &quot;A Christmas Carol&quot;,<br>author: &quot;Charles Dickens&quot;,<br>year: 1843,<br>genre: &quot;Fiction&quot;<br>}</pre><p>You can almost imagine putting a bow on it.</p><p>So what’s really happening here? The spread operator (...) unpacks elements from any iterable (such as an array, string, set, or map) or the properties of an object.</p><p>It’s like opening a gift box and laying everything out neatly on the table.</p><p>But the more you use it, the more you realize the <strong>spread operator</strong> isn’t just a shortcut — it’s a tiny superpower.</p><p>Those three dots can <strong>copy arrays</strong>, <strong>merge objects</strong>, or <strong>expand function arguments</strong> with almost no effort. They make your code cleaner, easier to read, and far less error-prone. Instead of wrestling with loops or Object.assign(), you can just… spread.</p><p>It’s one of those features that quietly changes how you think about writing JavaScript.</p><p>You take the last sip of cocoa, smiling. Your playlist is ready. Your objects are neat.<br>And your JavaScript? A little more beautiful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a34109e0538" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering RxJS Operators in Angular: A Practical Example]]></title>
            <link>https://medium.com/@rebeca.boanca/mastering-rxjs-operators-in-angular-a-practical-example-bf3a1c531cc7?source=rss-f3f6bae5efad------2</link>
            <guid isPermaLink="false">https://medium.com/p/bf3a1c531cc7</guid>
            <category><![CDATA[router]]></category>
            <category><![CDATA[rxjs]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[resolver]]></category>
            <dc:creator><![CDATA[Beccs Bo]]></dc:creator>
            <pubDate>Tue, 29 Jul 2025 11:55:03 GMT</pubDate>
            <atom:updated>2025-07-29T11:55:03.534Z</atom:updated>
            <content:encoded><![CDATA[<p>When building Angular applications, handling asynchronous data streams is a daily task. RxJS operators make this not only possible, but elegant and robust. In this post, we’ll break down some of the most useful RxJS operators — combineLatest, map, catchError, and of—using a real resolver implementation from an Angular project.</p><h3>The Example: User Data Resolver</h3><p>Suppose you need to fetch user data from multiple sources before activating a route. Here’s how you can do it with RxJS:</p><pre>import { ResolveFn } from &#39;@angular/router&#39;;<br>import { inject } from &#39;@angular/core&#39;;<br>import { UserService } from &#39;./user.service&#39;;<br>import { combineLatest, map, catchError, of } from &#39;rxjs&#39;;<br><br>export interface UserData {<br>  userUuid: string;<br>  userAccounts: string[];<br>  userIdEncrypted: string;<br>}<br><br>export const userDataResolver: ResolveFn&lt;UserData&gt; = () =&gt; {<br>  const userService = inject(UserService);<br>  return combineLatest([<br>    userService.userUuid$,<br>    userService.userAccounts$,<br>    userService.userIdEncrypted$<br>  ]).pipe(<br>    map(([userUuid, userAccounts, userIdEncrypted]) =&gt; ({<br>      userUuid,<br>      userAccounts,<br>      userIdEncrypted<br>    })),<br>    catchError(() =&gt;<br>      of({<br>        userUuid: &#39;&#39;,<br>        userAccounts: [],<br>        userIdEncrypted: &#39;&#39;<br>      })<br>    )<br>  );<br>};</pre><h3>Operator Breakdown</h3><ul><li><strong>combineLatest</strong>:<br>Waits for all provided Observables to emit at least once, then emits the latest values from each as an array. Here, it combines three user-related streams.</li><li><strong>pipe</strong>:<br>Allows you to chain multiple RxJS operators together in a readable way. In this code, it passes the combined values through map and catchError.</li><li><strong>map</strong>:<br>Transforms the emitted array into a structured UserData object, making it easier to use in your components.</li><li><strong>catchError</strong>:<br>Catches any error in the stream and lets you return a fallback value instead of breaking the Observable chain.</li><li><strong>of</strong>:<br>Creates a new Observable that emits the provided fallback value (an empty user object in this case).</li></ul><h3>How Is the Resolver Used in Practice?</h3><ol><li>Register the Resolver in Your Routing Module</li></ol><pre>import { Routes } from &#39;@angular/router&#39;;<br>import { DemoUserDataComponent } from &#39;./components/demo-user-data/demo-user-data.component&#39;;<br>import { userDataResolver } from &#39;./user-data.resolver&#39;;<br><br>const routes: Routes = [<br>  {<br>    path: &#39;user&#39;,<br>    component: DemoUserDataComponent,<br>    resolve: { userData: userDataResolver }<br>  }<br>];</pre><p>2. Access the Resolved Data in Your Component</p><pre>import { Component } from &#39;@angular/core&#39;;<br>import { ActivatedRoute } from &#39;@angular/router&#39;;<br>import { UserData } from &#39;../user-data.resolver&#39;;<br><br>@Component({<br>  selector: &#39;app-demo-user-data&#39;,<br>  template: `<br>    &lt;div *ngIf=&quot;userData&quot;&gt;<br>      &lt;h2&gt;User Data&lt;/h2&gt;<br>      &lt;pre&gt;{{ userData | json }}&lt;/pre&gt;<br>    &lt;/div&gt;<br>  `<br>})<br>export class DemoUserDataComponent {<br>  userData: UserData;<br><br>  constructor(private route: ActivatedRoute) {<br>    this.userData = this.route.snapshot.data[&#39;userData&#39;];<br>  }<br>}</pre><h3>What Happens?</h3><ul><li>When you navigate to /user, Angular runs the resolver before activating the route.</li><li>The resolver combines and transforms the user data streams, handling errors if needed.</li><li>The resolved userData is injected into the component and can be used directly in the template.</li></ul><h3>Conclusion</h3><p>RxJS operators like combineLatest, map, catchError, and of make it easy to compose, transform, and handle errors in your data streams. By chaining them with pipe, you can build powerful, readable, and maintainable async logic in Angular. This approach keeps your code clean and your user experience smooth—even when dealing with complex, asynchronous data.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bf3a1c531cc7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Better Loading Experiences in Angular 18 with ngx-skeleton-loader]]></title>
            <link>https://medium.com/@rebeca.boanca/better-loading-experiences-in-angular-18-with-ngx-skeleton-loader-7e0eee72e084?source=rss-f3f6bae5efad------2</link>
            <guid isPermaLink="false">https://medium.com/p/7e0eee72e084</guid>
            <category><![CDATA[user-experience]]></category>
            <category><![CDATA[angular-18]]></category>
            <category><![CDATA[ngx-skeleton-loader]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[loading-state]]></category>
            <dc:creator><![CDATA[Beccs Bo]]></dc:creator>
            <pubDate>Tue, 06 May 2025 15:37:20 GMT</pubDate>
            <atom:updated>2025-05-06T15:37:20.735Z</atom:updated>
            <content:encoded><![CDATA[<p>Ever built an Angular app and felt annoyed by how empty and awkward it looks while waiting for data to load? Instead of showing a blank screen or a boring spinner, you can give users something better: <strong>skeleton loaders</strong> — those grey placeholders that look like your content is just about to appear.</p><p>In this article, we’ll show you how to add skeleton loaders to your Angular 18 app using a handy library called ngx-skeleton-loader.</p><h3>What’s a Skeleton Loader?</h3><p>A skeleton loader is a UI placeholder that mimics the shape of your content — like circles for profile pictures or lines for text — so users know something is loading.</p><h3>Step 1: Install the Package</h3><p>You can add the loader to your project with one of these commands:</p><pre>yarn add ngx-skeleton-loader<br># or<br>npm install ngx-skeleton-loader</pre><p>Then open your app.module.ts and add it to your imports:</p><pre>import { NgxSkeletonLoaderModule } from &#39;ngx-skeleton-loader&#39;;<br><br>@NgModule({<br>  imports: [<br>    NgxSkeletonLoaderModule,<br>    // other modules...<br>  ]<br>})<br>export class AppModule {}</pre><h3>Step 2: Build the UI</h3><p>Let’s say you’re loading a list of users, each with a name and avatar. Here’s the idea:</p><ul><li>Show <strong>5 circle skeletons</strong> as placeholder avatars.</li><li>Show <strong>3 line skeletons</strong> as placeholder names.</li><li>When the data finishes loading, swap them out for the real content.</li></ul><p>Here’s what the HTML looks like:</p><pre>&lt;div class=&quot;skeleton-container&quot;&gt;<br>  &lt;div class=&quot;skeleton-avatars&quot;&gt;<br>    &lt;ngx-skeleton-loader<br>      *ngIf=&quot;isLoading&quot;<br>      count=&quot;5&quot;<br>      appearance=&quot;circle&quot;<br>      [theme]=&quot;{ width: &#39;50px&#39;, height: &#39;50px&#39;, &#39;margin-right&#39;: &#39;10px&#39; }&quot;<br>    &gt;&lt;/ngx-skeleton-loader&gt;<br><br>    &lt;ng-container *ngIf=&quot;!isLoading&quot;&gt;<br>      &lt;img<br>        *ngFor=&quot;let user of users&quot;<br>        [src]=&quot;user.avatar&quot;<br>        alt=&quot;{{ user.name }}&quot;<br>        class=&quot;avatar&quot;<br>      /&gt;<br>    &lt;/ng-container&gt;<br>  &lt;/div&gt;<br><br>  &lt;div *ngIf=&quot;isLoading; else showContent&quot; class=&quot;skeleton-lines&quot;&gt;<br>    &lt;ngx-skeleton-loader<br>      count=&quot;3&quot;<br>      [theme]=&quot;{ height: &#39;20px&#39;, &#39;margin-bottom&#39;: &#39;10px&#39; }&quot;<br>    &gt;&lt;/ngx-skeleton-loader&gt;<br>  &lt;/div&gt;<br><br>  &lt;ng-template #showContent&gt;<br>    &lt;div class=&quot;user-list&quot;&gt;<br>      &lt;div class=&quot;user-card&quot; *ngFor=&quot;let user of users&quot;&gt;<br>        {{ user.name }}<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>  &lt;/ng-template&gt;<br>&lt;/div&gt;</pre><h3>Step 3: Add the Logic (TS Class)</h3><p>Now we simulate loading with a delay in the component:</p><pre>import { Component, OnInit } from &#39;@angular/core&#39;;<br><br>@Component({<br>  selector: &#39;app-users&#39;,<br>  templateUrl: &#39;./users.component.html&#39;,<br>  styleUrls: [&#39;./users.component.css&#39;]<br>})<br>export class UsersComponent implements OnInit {<br>  users = [];<br>  isLoading = true;<br><br>  ngOnInit() {<br>    setTimeout(() =&gt; {<br>      this.users = [<br>        { name: &#39;Alice&#39;, avatar: &#39;https://randomuser.me/api/portraits/women/1.jpg&#39; },<br>        { name: &#39;Bob&#39;, avatar: &#39;https://randomuser.me/api/portraits/men/1.jpg&#39; },<br>        { name: &#39;Charlie&#39;, avatar: &#39;https://randomuser.me/api/portraits/men/2.jpg&#39; },<br>        { name: &#39;Dana&#39;, avatar: &#39;https://randomuser.me/api/portraits/women/2.jpg&#39; },<br>        { name: &#39;Eli&#39;, avatar: &#39;https://randomuser.me/api/portraits/men/3.jpg&#39; }<br>      ];<br>      this.isLoading = false;<br>    }, 3000);<br>  }<br>}</pre><h3>Optional: A Bit of Style</h3><p>Here’s some CSS to make it all look neat:</p><pre>.skeleton-container {<br>  max-width: 600px;<br>  margin: 40px auto;<br>  padding: 20px;<br>  border-radius: 12px;<br>  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);<br>  background-color: #fff;<br>  text-align: center;<br>}<br><br>.skeleton-avatars {<br>  display: flex;<br>  justify-content: center;<br>  gap: 10px;<br>  margin-bottom: 20px;<br>}<br><br>.skeleton-lines {<br>  margin-bottom: 20px;<br>}<br><br>.avatar {<br>  width: 50px;<br>  height: 50px;<br>  border-radius: 50%;<br>}<br><br>.user-card {<br>  padding: 10px;<br>  background-color: #f9f9f9;<br>  border-radius: 8px;<br>  margin: 5px 0;<br>}</pre><h3>The Result</h3><p>You’ve now got a clean loading UI that:</p><ul><li>Shows friendly placeholders while loading.</li><li>Seamlessly swaps in real data when ready.</li><li>Looks professional and improves user experience.</li></ul><h3>Final Thoughts</h3><p>Using ngx-skeleton-loader in your Angular app is an easy way to make your UI feel smoother and more user-friendly — especially on slow connections or large data sets.</p><p>Next time you build a feature with loading content, don’t leave your users staring at an empty screen. Give them a sneak peek with skeletons!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7e0eee72e084" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular Routing Is Great, But Don’t Forget About the window Object]]></title>
            <link>https://medium.com/@rebeca.boanca/angular-routing-is-great-but-dont-forget-about-the-window-object-2afff877c9d5?source=rss-f3f6bae5efad------2</link>
            <guid isPermaLink="false">https://medium.com/p/2afff877c9d5</guid>
            <category><![CDATA[window-event-handling]]></category>
            <category><![CDATA[angular-focus-event]]></category>
            <category><![CDATA[window-size-detection]]></category>
            <category><![CDATA[browser-event-handling]]></category>
            <category><![CDATA[window-object-in-angular]]></category>
            <dc:creator><![CDATA[Beccs Bo]]></dc:creator>
            <pubDate>Tue, 08 Apr 2025 18:00:38 GMT</pubDate>
            <atom:updated>2025-04-08T18:00:38.812Z</atom:updated>
            <content:encoded><![CDATA[<p>When you’re building a modern Angular app, <strong>routing</strong> is one of the first things you learn. It lets you move between different components or views seamlessly without reloading the page, making your app feel fast and dynamic. But while Angular’s routing system is a powerhouse for in-app navigation, it doesn’t handle everything. For certain tasks — things like interacting with the browser’s window size, managing storage, or handling external URLs — you’ll still need the <strong>window object</strong>.</p><p>In this post, we’ll dive into why the window object is still essential, even when you&#39;re using Angular&#39;s routing, and how it can help you fill in the gaps.</p><h3>1. Navigating Beyond Your Angular App</h3><p>Angular’s router does an excellent job of navigating between views inside your app, but what if you need to send your users outside of the app? Whether it’s linking to an external website or opening a new tab, <strong>Angular’s routing</strong> can’t handle that on its own.</p><ul><li><strong>Opening new tabs or windows</strong>: Need to open an external link in a new tab? You’ll have to turn to window.open().</li><li><strong>Redirecting to an external page</strong>: If you need to send users to a completely different website, window.location.href is your go-to method.</li></ul><p><strong>Example:</strong></p><pre>// Open an external URL in a new tab<br>window.open(&#39;https://www.example.com&#39;, &#39;_blank&#39;);<br><br>// Redirect the user to an external website<br>window.location.href = &#39;https://www.example.com&#39;;</pre><h3>2. Adapting to Window Size: Creating a Responsive Experience</h3><p>Building a responsive app means your layout needs to change based on the browser window’s size. Whether you’re showing a mobile view or a desktop view, <strong>Angular’s router</strong> doesn’t manage window resizing. Thankfully, the window object can give you real-time information about the window’s size, so you can adjust your layout accordingly.</p><p><strong>Example:</strong></p><pre>const width = window.innerWidth;<br>if (width &lt; 768) {<br>  // Switch to mobile layout<br>} else {<br>  // Switch to desktop layout<br>}</pre><p><strong>Why </strong><strong>window?</strong> Angular doesn’t track the browser’s viewport dimensions. You’ll need to tap into the window object to handle responsiveness and ensure your app looks good on all screen sizes.</p><h3>3. Tracking Browser Events: Resize, Scroll, and Focus</h3><p>There’s more going on in the browser than just navigation. You might want to track when the user resizes the window, scrolls the page, or even switches tabs. These events are a fundamental part of user interaction, but Angular’s routing system doesn’t deal with them.</p><p>With the window object, you can listen for these events and take action accordingly—whether it’s updating a UI element, pausing a video, or tracking user engagement.</p><p><strong>Example:</strong></p><pre>// Listen for window resizing events<br>window.addEventListener(&#39;resize&#39;, () =&gt; {<br>  console.log(&#39;Window has been resized&#39;);<br>});</pre><p><strong>Why </strong><strong>window?</strong> Angular doesn’t provide hooks for browser events like resizing, scrolling, or focus changes. You’ll need to interact with the window object to track these interactions.</p><h3>4. Keeping Data Between Views: Using Browser Storage</h3><p>Sometimes, you need to store data that stays with the user even when they leave the current view or refresh the page. Think of things like remembering a user’s preferences, saving a session token, or persisting a shopping cart. For this, <strong>localStorage</strong> and <strong>sessionStorage</strong> are your best friends, and both are accessed via the window object.</p><p><strong>Example:</strong></p><pre>// Save data to localStorage<br>localStorage.setItem(&#39;userToken&#39;, &#39;abc123&#39;);<br><br>// Retrieve the stored data<br>const token = localStorage.getItem(&#39;userToken&#39;);</pre><p><strong>Why </strong><strong>window?</strong> Angular provides state management tools, but <strong>browser storage</strong> is something that Angular doesn’t handle by default. The window object is where you’ll go for storing data locally that needs to survive page reloads or navigation.</p><h3>5. Refreshing the Page or Navigating Outside Angular</h3><p>While Angular routing takes care of navigation inside your app, sometimes you need to reload the entire page or send users to a completely different app. That’s where the window object shines.</p><p>For instance, if a user logs out or completes a certain task, you might want to refresh the page or redirect them to another website entirely. For that, you’ll need to interact with the window object.</p><p><strong>Example:</strong></p><pre>// Redirect to a different page or app<br>window.location.href = &#39;/login&#39;; // Or an external URL: &#39;https://www.example.com&#39;<br><br>// Refresh the current page<br>window.location.reload();</pre><p><strong>Why </strong><strong>window?</strong> Angular routing handles in-app navigation, but <strong>full-page navigation</strong> or refreshing the browser window needs to be done through window.location.</p><h3>6. Detecting When the Window Is Focused or in the Background</h3><p>Ever wondered if your user has switched away from your app’s tab? The window object can let you know when the window is <strong>focused</strong> (the user is active on the tab) or <strong>blurred</strong> (the user is inactive or has switched tabs). This is particularly useful when you want to pause videos, stop animations, or trigger alerts based on whether the user is engaged with your app.</p><p><strong>Example:</strong></p><pre>// Detect when the window gains or loses focus<br>window.addEventListener(&#39;focus&#39;, () =&gt; {<br>  console.log(&#39;Window is focused&#39;);<br>});<br><br>window.addEventListener(&#39;blur&#39;, () =&gt; {<br>  console.log(&#39;Window is not focused&#39;);<br>});</pre><p><strong>Why </strong><strong>window?</strong> Angular doesn’t have built-in support for tracking <strong>window focus</strong> events. For apps that need to track when the user switches between tabs or minimizes the window, you’ll need the window object to capture this information.</p><h3>Conclusion: Angular Routing and window—a Perfect Pair</h3><p>While Angular’s <strong>router</strong> is fantastic for navigating between views inside your app, the <strong>window object</strong> is what handles the browser-level interactions that Angular doesn’t manage. From handling external navigation, managing storage, tracking window events, and dealing with focus, the window object is just as critical to your app’s functionality.</p><p>By combining the power of Angular routing with the flexibility of the window object, you can build dynamic, responsive, and user-friendly web applications that go beyond basic navigation. So, the next time you think about Angular routing, don’t forget that the window object is always there to help you complete the experience!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2afff877c9d5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Keeping Git History Clean: The Case for Rebase (and When to Merge)]]></title>
            <link>https://medium.com/@rebeca.boanca/keeping-git-history-clean-the-case-for-rebase-and-when-to-merge-4a1016e8e80d?source=rss-f3f6bae5efad------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a1016e8e80d</guid>
            <category><![CDATA[version-control]]></category>
            <category><![CDATA[clean-commit-history]]></category>
            <category><![CDATA[git-workflow]]></category>
            <category><![CDATA[code-quality]]></category>
            <category><![CDATA[git-merge-vs-rebase]]></category>
            <dc:creator><![CDATA[Beccs Bo]]></dc:creator>
            <pubDate>Tue, 08 Apr 2025 07:57:34 GMT</pubDate>
            <atom:updated>2025-04-08T07:57:34.555Z</atom:updated>
            <content:encoded><![CDATA[<p>If you’ve ever found yourself staring at a tangled Git history wondering how it got so messy, you’re not alone. One of the most common forks in the road (pun intended) comes down to this: <strong>should you merge </strong><strong>main into your feature branch, or rebase your feature branch onto </strong><strong>main</strong>?</p><p>On the surface, both seem to do the same thing — they bring your branch up to date with the latest changes. But under the hood, they work very differently, and the choice you make can have a big impact on your project’s commit history, collaboration experience, and even your team’s sanity.</p><p>In this post, we’ll break down the difference between merging and rebasing, explore the pros and cons of each, and help you figure out which approach is right for your workflow.</p><h3>🔀 Merging main into your feature branch:</h3><p>When other teams <strong>merge</strong> the main branch into their feature branch, they’re doing this:</p><pre>git checkout feature-branch<br>git merge main</pre><p>This brings in the latest changes from main and <strong>creates a merge commit</strong> if necessary.</p><h4>Pros:</h4><ul><li><strong>History is preserved</strong> exactly as it happened.</li><li>Safe and non-destructive — nothing is rewritten.</li><li>Easier to trace the actual order of events and merges.</li></ul><h4>Cons:</h4><ul><li>The commit history can get <strong>messy and cluttered</strong> with a lot of merge commits.</li><li>Not as clean when looking at the project history — especially in active repos.</li></ul><h3>🔁 Rebasing feature branch onto main:</h3><p>When you <strong>rebase</strong> your feature branch onto main, you&#39;re doing:</p><pre>git checkout feature-branch<br>git rebase main</pre><p>This <strong>replays your feature branch commits on top of the latest </strong><strong>main</strong>, as if they were created after the latest changes on main.</p><h4>Pros:</h4><ul><li>Results in a <strong>clean, linear history</strong>.</li><li>Easier to understand with tools like git log or git blame.</li><li>Looks like the feature was created from the latest version of main.</li></ul><h4>Cons:</h4><ul><li><strong>Rewrites history</strong>, which can be dangerous if your feature branch is shared with others.</li><li>Requires more Git knowledge to handle rebase conflicts.</li></ul><h3>So the main difference?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/1*7-yqYRX5KXFVDNETuRmM9Q.png" /></figure><h3>TL;DR:</h3><p>If you care about a <strong>clean, readable history</strong>, rebase.<br>If you care about <strong>safety and avoiding surprises</strong>, merge.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a1016e8e80d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a navigation menu in Angular, using Observables and Routing]]></title>
            <link>https://medium.com/@rebeca.boanca/building-a-navigation-menu-in-angular-using-observables-and-routing-a2f29fcb85eb?source=rss-f3f6bae5efad------2</link>
            <guid isPermaLink="false">https://medium.com/p/a2f29fcb85eb</guid>
            <category><![CDATA[json]]></category>
            <category><![CDATA[observables]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[routing]]></category>
            <dc:creator><![CDATA[Beccs Bo]]></dc:creator>
            <pubDate>Wed, 02 Apr 2025 18:22:09 GMT</pubDate>
            <atom:updated>2025-04-02T18:32:45.400Z</atom:updated>
            <content:encoded><![CDATA[<p>In this post, we will fetch navigation items from a local JSON file using Angular’s HttpClient.<br> ✅ Using <strong>Observables</strong> to handle data.<br> ✅ Implementing <strong>Angular Routing</strong> to navigate between components.</p><p>By the end, we will have a working navigation menu powered by a JSON file and Angular’s router!</p><h3>Why use Observables?</h3><p>When fetching data, an Observable ensures that we can react to updates, errors and completion events in a structured way.</p><h3>Before we start:</h3><p>We need to make sure we have a working Angular app. Else, we can create a new one by running the following command:</p><pre>ng new my-angular-app<br>cd my-angular-app<br>ng serve</pre><p>This will create a new Angular project and start a development server at http://localhost:4200/.</p><p>Next, we will install @angular/router (if it&#39;s not already included):</p><pre>ng add @angular/router</pre><p>Now, we’re ready to proceed!</p><h3>📌 Step 1: Set up the Navigation JSON File</h3><p>First, we need a JSON file to store our navigation items. We will create a navigation.json file inside the assets folder:</p><pre>[<br>  { &quot;id&quot;: 1, &quot;name&quot;: &quot;Home&quot;, &quot;url&quot;: &quot;home&quot; },<br>  { &quot;id&quot;: 2, &quot;name&quot;: &quot;About&quot;, &quot;url&quot;: &quot;about&quot; },<br>  { &quot;id&quot;: 3, &quot;name&quot;: &quot;Contact&quot;, &quot;url&quot;: &quot;contact&quot; }<br>]</pre><h3>📌 Step 2: Create the Navigation Model</h3><p>We ensure type safety with an interface for the navigation items. Thus, we create a new file navigation-item.model.ts:</p><pre>export interface NavigationItem {<br>  id: number;<br>  name: string;<br>  url: string;<br>}</pre><h3>📌 Step 3: Create an Angular Service to Fetch Navigation Data</h3><p>We need a service to fetch the JSON data and return it as an Observable.</p><p>We’ll run the following command in the terminal:</p><pre>ng generate service navigation</pre><p>This will create navigation.service.ts, where we add the following code:</p><pre>import { Injectable } from &#39;@angular/core&#39;;<br>import { HttpClient } from &#39;@angular/common/http&#39;;<br>import { Observable } from &#39;rxjs&#39;;<br>import { NavigationItem } from &#39;./navigation-item.model&#39;;<br><br>@Injectable({<br>  providedIn: &#39;root&#39;<br>})<br>export class NavigationService {<br>  constructor(private http: HttpClient) {}<br><br>  public getNavigationItems(): Observable&lt;NavigationItem[]&gt; {<br>    return this.http.get&lt;NavigationItem[]&gt;(&#39;./assets/navigation.json&#39;);<br>  }<br>}</pre><p>Here’s what’s happening:</p><ul><li><strong>HttpClient</strong> fetches the JSON file asynchronously</li><li><strong>Observable&lt;NavigationItem[]&gt;</strong> ensures the data is reactive and can be subscribed to in a component.</li></ul><h3>📌 Step 4: Enable HttpClientModule in app.module.ts</h3><p>Since we are using HttpClient, we need to import its module. Let’s also add AppRoutingModule, which we will address later:</p><pre>import { HttpClientModule } from &#39;@angular/common/http&#39;;<br><br>@NgModule({<br>  imports: [<br>   AppRoutingModule,<br>    HttpClientModule<br>  ],<br>})<br>export class AppModule {}</pre><h3>📌 Step 5: Display Navigation Items in a Component, by injecting the Service and Fetch Data</h3><p>Let’s modify app.component.ts to retrieve the navigation items:</p><pre>import { Component, OnInit } from &#39;@angular/core&#39;;<br>import { NavigationService } from &#39;./navigation.service&#39;;<br>import { NavigationItem } from &#39;./navigation-item.model&#39;;<br><br>@Component({<br>  selector: &#39;app-root&#39;,<br>  templateUrl: &#39;./app.component.html&#39;,<br>  styleUrls: [&#39;./app.component.css&#39;]<br>})<br>export class AppComponent implements OnInit {<br>  navigationItems: NavigationItem[] = [];<br><br>  constructor(private navigationService: NavigationService) {}<br><br>  ngOnInit(): void {<br>    this.navigationService.getNavigationItems().subscribe(data =&gt; {<br>      this.navigationItems = data;<br>    });<br>  }<br>}</pre><p>Now, the navigationItems array will be populated with data from navigation.json. We can also console it:</p><pre>ngOnInit(): void {<br>    this.navigationService.getNavigationItems().subscribe(data =&gt; {<br>      console.log(&#39;Navigation items received:&#39;, data);<br>      this.navigationItems = data;<br>    });<br>  }</pre><h3>📌 Step 6: Implement Angular Routing</h3><h3>1️⃣ Generate Components for Each Route</h3><p>We will run the following commands to create three components:</p><pre>ng generate component home<br>ng generate component about<br>ng generate component contact</pre><p>Each of these components should have a simple template like:</p><p><strong>home.component.html</strong></p><pre>&lt;h2&gt;Home Page&lt;/h2&gt;<br>&lt;p&gt;Welcome to the home page!&lt;/p&gt;</pre><p><strong>about.component.html</strong></p><pre>&lt;h2&gt;About Us&lt;/h2&gt;<br>&lt;p&gt;Learn more about our application.&lt;/p&gt;</pre><p><strong>contact.component.html</strong></p><pre>&lt;h2&gt;Contact Us&lt;/h2&gt;<br>&lt;p&gt;Reach out to us through this page.&lt;/p&gt;</pre><h3>2️⃣ Configure Routes</h3><p>Let’s define routes in app-routing.module.ts:</p><pre>import { NgModule } from &#39;@angular/core&#39;;<br>import { RouterModule, Routes } from &#39;@angular/router&#39;;<br>import { HomeComponent } from &#39;./home/home.component&#39;;<br>import { AboutComponent } from &#39;./about/about.component&#39;;<br>import { ContactComponent } from &#39;./contact/contact.component&#39;;<br><br>const routes: Routes = [<br>  { path: &#39;&#39;, redirectTo: &#39;/home&#39;, pathMatch: &#39;full&#39; },<br>  { path: &#39;home&#39;, component: HomeComponent },<br>  { path: &#39;about&#39;, component: AboutComponent },<br>  { path: &#39;contact&#39;, component: ContactComponent }<br>];<br><br>@NgModule({<br>  imports: [RouterModule.forRoot(routes)],<br>  exports: [RouterModule]<br>})<br>export class AppRoutingModule {}</pre><h3>📌 Step 7: Update Navigation to Use Angular Routing</h3><p>Let’s modify app.component.html to use routerLink instead of href:</p><pre>&lt;ul&gt;<br>  &lt;li *ngFor=&quot;let item of navigationItems&quot;&gt;<br>    &lt;a [routerLink]=&quot;item.url&quot;&gt;{{ item.name }}&lt;/a&gt;<br>  &lt;/li&gt;<br>&lt;/ul&gt;<br><br>&lt;h3&gt;Raw JSON Data:&lt;/h3&gt;<br>&lt;pre&gt;{{ navigationItems | json }}&lt;/pre&gt;<br><br>&lt;!-- Loads the selected component dynamically --&gt;<br>&lt;router-outlet&gt;&lt;/router-outlet&gt;</pre><h3>🎉 Final Testing</h3><p>If we run our application now and we click on <strong>Home, About, or Contact</strong> we will navigate to the respective pages dynamically!</p><pre>ng serve</pre><h3>✨ Bonus: Error Handling</h3><p>To handle errors in case the JSON file is missing or has issues, we can modify the service:</p><pre>import { catchError } from &#39;rxjs/operators&#39;;<br>import { throwError } from &#39;rxjs&#39;;<br><br>public getNavigationItems(): Observable&lt;NavigationItem[]&gt; {<br>  return this.http.get&lt;NavigationItem[]&gt;(&#39;./assets/navigation.json&#39;).pipe(<br>    catchError(error =&gt; {<br>      console.error(&#39;Error fetching navigation items&#39;, error);<br>      return throwError(() =&gt; new Error(&#39;Failed to load navigation data&#39;));<br>    })<br>  );<br>}</pre><p>Now, if an error occurs while fetching data, it will be logged in the console.</p><h3>Conclusion</h3><p>In this post, we:<br> ✅ Fetched navigation data from a local JSON file using HttpClient.<br> ✅ Used <strong>Observables</strong> to manage asynchronous data fetching.<br> ✅ Implemented <strong>Angular Routing</strong> to navigate between components dynamically.</p><p>This approach is useful for dynamic menus, mock APIs during development, and organizing navigation in a scalable way.</p><p>Would you like to see how to add <strong>active link highlighting</strong> or <strong>lazy loading</strong> next? Let me know in the comments!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a2f29fcb85eb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>