<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: V.D</title>
    <description>The latest articles on DEV Community by V.D (@vivekdogra02).</description>
    <link>https://dev.to/vivekdogra02</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1079373%2F0393ce87-67ad-45bd-a836-94587a59583d.jpeg</url>
      <title>DEV Community: V.D</title>
      <link>https://dev.to/vivekdogra02</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vivekdogra02"/>
    <language>en</language>
    <item>
      <title>Atomic Design Unleashed: Building Consistency through Design Systems</title>
      <dc:creator>V.D</dc:creator>
      <pubDate>Mon, 21 Aug 2023 14:07:41 +0000</pubDate>
      <link>https://dev.to/vivekdogra02/atomic-design-unleashed-building-consistency-through-design-systems-2jc8</link>
      <guid>https://dev.to/vivekdogra02/atomic-design-unleashed-building-consistency-through-design-systems-2jc8</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0iz2mNUG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/0%2AzkTQLHErzn56h-f_" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0iz2mNUG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/0%2AzkTQLHErzn56h-f_" alt="1" width="800" height="534"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Photo by Clark Tibbs on Unsplash&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Hi Folks, Today we are going to learn and explore about what are design systems, what is your role as an engineer to know about design systems, is it really useful to use a design systems or it is mere a proof of concept to be used? and also how it will be beneficial for a team to have a design system across various projects while developing application.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is a Design System?
&lt;/h3&gt;

&lt;p&gt;A design system is a comprehensive collection of guidelines, components, patterns, and assets that are used to create consistent and cohesive user interfaces across a product or organization. It serves as a single source of truth for design and UI-related decisions, making it easier to maintain a unified and polished look and feel across different parts of an application.&lt;/p&gt;

&lt;h4&gt;
  
  
  That is it ?
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Really&lt;/strong&gt; , Let me break down for you, A design system is nothing but a collection of style guidelines, components(Atoms), assets, combination of components(Molecules) ex: Header section, navbar etc. which consists of different types of components(atoms). It is something like a LEGO bricks which constitutes to a whole new structure when being joined together.&lt;/p&gt;

&lt;p&gt;So, think about design systems as a magic recipe book for making websites and apps. Inside, there are secret ingredients called “design tokens” that give colors, fonts, and spaces their special flavors. These ingredients help designers and builders speak the same language, so everything they create looks like they belong together.&lt;/p&gt;

&lt;p&gt;Imagine a box of building blocks. Design systems give you those blocks, but they’re not just ordinary blocks — they’re smart blocks. They know how to make buttons, menus, and other cool things that people use on screens. This means that instead of starting from scratch every time, we can use these smart blocks to build things faster and better.&lt;/p&gt;

&lt;p&gt;So, there is concept of Atomic Design system, when we talk about design system, it is the basic and more foundational one to understand the design system as a whole.&lt;/p&gt;

&lt;h3&gt;
  
  
  Atomic Design System(Methodology)
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IXqXmgkb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/1%2AsUD_2b__PTbp5H7aLlkGSA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IXqXmgkb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/1%2AsUD_2b__PTbp5H7aLlkGSA.png" alt="2" width="800" height="379"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Atoms, molecules, organisms, templates, and pages&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Welcome to the Atomic design system, a dynamic toolkit that empowers designers and developers to build interfaces that are not just visually appealing, but also functionally robust. Think of it as a LEGO set for creating stunning user experiences! 🚀&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Atoms&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4pzWif2U--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/0%2ACAIdZZKHPY1TZQs5" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4pzWif2U--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/0%2ACAIdZZKHPY1TZQs5" alt="3" width="800" height="600"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Photo by Shubham Dhage on Unsplash&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The elemental building blocks of your interface. These atoms are like the tiny particles that form the foundation of everything, from simple buttons to intricate navigation bars. &lt;strong&gt;&lt;em&gt;They’re your UI’s DNA&lt;/em&gt;&lt;/strong&gt; , defining colors, typography, and spacing that ensure consistency across the board. Imagine them as the primary hues on your painter’s palette, ready to splash vibrancy onto your canvas.&lt;/p&gt;

&lt;p&gt;But atoms alone don’t tell the whole story.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Molecules&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SAQWTItq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/0%2AcWi7X12zB6Ye2pCs" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SAQWTItq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/0%2AcWi7X12zB6Ye2pCs" alt="4" width="800" height="534"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Photo by Terry Vlisidis on Unsplash&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Atoms come together to form ‘molecules’ — charming clusters of atoms that fulfill specific functions. &lt;strong&gt;Think of a search bar:&lt;/strong&gt; it’s not just a button or an input field, it’s a fusion of both that serves a distinct purpose. Molecules are the quirky puzzle pieces that snap together seamlessly, forming the framework for your user interface landscape.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Organisms&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GSIIcNlV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/0%2AFXxaUxgdfvleHXo7" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GSIIcNlV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/0%2AFXxaUxgdfvleHXo7" alt="5" width="800" height="800"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Photo by CDC on Unsplash&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Zoom out a bit more, and you encounter ‘organisms’ — dynamic ecosystems composed of molecules and atoms working in harmony. &lt;strong&gt;Consider a navigation menu:&lt;/strong&gt; it’s more than just a collection of buttons; it’s a thoughtful arrangement of components that guide users on their digital journey. Organisms are like mini worlds where UI elements collaborate to create delightful user experiences.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Templates&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FbDGlKpX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/0%2ARcrcR_cGsPzACKd9" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FbDGlKpX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/0%2ARcrcR_cGsPzACKd9" alt="6" width="800" height="477"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Photo by Tim Arterbury on Unsplash&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Crafting Consistent Layouts with Purpose. Templates are the blueprints that guide the arrangement of &lt;strong&gt;organisms&lt;/strong&gt; , &lt;strong&gt;molecules&lt;/strong&gt; , and &lt;strong&gt;atoms&lt;/strong&gt; across various sections of your application. Think of them as the architectural plans for your digital spaces. Templates establish the structural framework, ensuring that your user interface maintains a consistent and visually pleasing layout.&lt;/p&gt;

&lt;p&gt;Just as architects design floor plans for different rooms in a building, templates define the structure of your application’s different screens or sections. They dictate where specific elements should go, such as headers, sidebars, content sections, and footers. By adhering to template guidelines, you ensure a seamless transition between different areas of your app, creating a sense of familiarity for users.&lt;/p&gt;

&lt;p&gt;Templates also play a crucial role in responsiveness. With the prevalence of various devices and screen sizes, templates help you design interfaces that adapt gracefully to different contexts.&lt;/p&gt;

&lt;h4&gt;
  
  
  Pages
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CB2hZzdM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/0%2AxN3x3LgMKSB4fLPu" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CB2hZzdM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/0%2AxN3x3LgMKSB4fLPu" alt="7" width="800" height="534"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Photo by Olga Tutunaru on Unsplash&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Pages are where the magic happens — they’re the dynamic culmination of templates populated with real content and data. Just as a movie’s script comes to life on the big screen, your design system’s components come together on pages to tell a compelling digital story.&lt;/p&gt;

&lt;p&gt;Pages showcase how various elements interact with each other in real-world scenarios. They demonstrate how different organisms, molecules, and atoms collaborate to create meaningful user journeys. Imagine a product page on an e-commerce site: it’s not just about displaying images and text; it’s about crafting an experience that entices users to explore, engage, and ultimately make a purchase.&lt;/p&gt;

&lt;p&gt;The beauty of the Atomic design system shines through on pages. By assembling pre-designed components into coherent layouts, you save time and effort in the development process. Consistency and harmony reign supreme, as the building blocks you’ve meticulously designed and tested fit together seamlessly.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In essence, &lt;strong&gt;templates and pages&lt;/strong&gt; complete the narrative of your Atomic design system. Templates establish the guidelines that ensure cohesion and adaptability, while pages breathe life into your design vision, showing how your UI components come together to deliver exceptional user experiences. This approach empowers you to create interfaces that not only dazzle the eye but also guide users through delightful journeys in the digital realm.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Benefits of Design Systems:
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Consistency: Design systems ensure that UI elements and patterns remain consistent throughout the application, reducing confusion for users and making the design process more efficient for developers.&lt;/li&gt;
&lt;li&gt;Efficiency: By providing reusable components, design systems speed up development time. Developers can focus more on implementing functionality rather than reinventing the wheel for common UI elements.&lt;/li&gt;
&lt;li&gt;Scalability: As an application grows, a well-structured design system can accommodate changes and new features without sacrificing design integrity.&lt;/li&gt;
&lt;li&gt;Collaboration: Design systems foster collaboration between designers and developers. Both parties work with the same set of components and guidelines, reducing miscommunication and promoting teamwork.&lt;/li&gt;
&lt;li&gt;Accessibility: Design systems can enforce accessibility standards, ensuring that UI components are usable by a wider range of users.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Design System Components:
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Design Tokens:&lt;/strong&gt; These are design-specific variables that define things like colors, typography, spacing, and more. They provide a consistent foundation for design decisions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;UI Components:&lt;/strong&gt; Reusable building blocks that make up the interface. Examples include buttons, forms, navigation bars, and modals.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Guidelines and Documentation:&lt;/strong&gt; Clear documentation helps designers and developers understand how to use each component, the intended behavior, and when to use it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Patterns and Best Practices:&lt;/strong&gt; Design systems often provide guidance on how to combine components to create larger UI patterns. This ensures a cohesive and consistent user experience.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  What is your role as an engineer to know about design systems
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YZlZQqxu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/0%2AjjR2mdXwzqOZsPND" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YZlZQqxu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/0%2AjjR2mdXwzqOZsPND" alt="8" width="800" height="534"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Photo by ThisisEngineering RAEng on Unsplash&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;As a developer/engineer, while crafting an application or a project, you should be well aware of the building blocks you are using while creating the project. As an engineer, understanding design systems plays a crucial role in ensuring the successful development and maintenance of user interfaces.&lt;/p&gt;

&lt;p&gt;While your primary focus might be on the technical implementation, your awareness and involvement in design systems contribute to a more holistic and efficient product development process.&lt;/p&gt;

&lt;p&gt;Here’s how your role intersects with design systems:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Consistent Implementation&lt;/strong&gt; : Design systems provide guidelines and specifications for UI elements. By understanding these guidelines, you can implement UI components consistently, ensuring that the design vision is faithfully translated into code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reusability&lt;/strong&gt; : Design systems promote the reuse of UI components. As an engineer, you’ll be responsible for creating and maintaining these reusable components, which not only saves time but also ensures uniformity across the application.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Efficient Development&lt;/strong&gt; : By using pre-designed components and following established patterns, you can streamline your development process. This allows you to focus more on the logic and functionality of the application rather than spending time on designing individual UI elements.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Collaboration with Designers&lt;/strong&gt; : Understanding design principles helps you communicate effectively with designers. You can discuss technical constraints, propose solutions, and ensure that the components can be implemented within the given specifications.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Component Libraries:&lt;/strong&gt; Engineers often build and maintain libraries of UI components. These libraries are integral to design systems as they house the building blocks of the user interface. Familiarity with design systems aids in creating well-structured and cohesive component libraries.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Adaptation and Flexibility:&lt;/strong&gt; Design systems can evolve over time. As an engineer, your understanding of the design system’s principles allows you to adapt to changes and updates while maintaining the intended user experience.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;User-Centered Development:&lt;/strong&gt; Design systems emphasize user-centered design. By understanding the design system’s user-centric approach, you can ensure that the UI components you implement align with the needs and expectations of the users.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Testing and QA:&lt;/strong&gt; Your knowledge of design systems can help you conduct more accurate testing, ensuring that the implemented components align with the expected behavior and design standards.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Accessibility:&lt;/strong&gt; Design systems often include accessibility guidelines. As an engineer, you’ll need to ensure that the components you build adhere to these guidelines, making the application usable for a wider audience.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Problem Solving:&lt;/strong&gt; Design systems might not cover every scenario. In cases where a specific component or interaction isn’t defined, your understanding of the design system principles can help you make informed decisions that maintain consistency.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In essence, your role as an engineer in understanding design systems extends beyond coding; it involves collaborating with designers, translating design into code, maintaining consistency, and contributing to the overall user experience of the product.&lt;/p&gt;

&lt;p&gt;To understand more on design systems, I would highly recommend to check this site, it contains the whole sole knowledge of the design systems, why we should always considered design systems while crafting or architecting any application, it resolves the purpose of having the design systems while building application from small scale to enterprise level application or project.&lt;/p&gt;

&lt;h4&gt;
  
  
  Link — &lt;a href="https://atomicdesign.bradfrost.com/table-of-contents/"&gt;https://atomicdesign.bradfrost.com/table-of-contents/&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;Please check out this one, it will be very helpful to understand the concept and start using it.&lt;/p&gt;

&lt;p&gt;Thanks for your time, will be back with more interesting content.&lt;/p&gt;

&lt;p&gt;“🌟 Embark on a journey of knowledge and creativity with me!&lt;/p&gt;

&lt;p&gt;Join my circle to stay updated on insightful content that fuels inspiration. Let’s explore, learn, and write our stories together! 🚀✍️ #FollowForIdeas #CreateAndConnect”&lt;/p&gt;

&lt;h3&gt;
  
  
  Thanks for reading
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;👏 Please clap for the story and follow me 👉&lt;/li&gt;
&lt;li&gt;📰 &lt;a href="https://medium.com/@vivekdogra02"&gt;View more content&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;🔔 Follow me: &lt;a href="https://www.linkedin.com/in/vivek-dogra-7404a530/"&gt;LinkedIn&lt;/a&gt;| &lt;a href="https://twitter.com/VivekDo07905087"&gt;Twitter&lt;/a&gt;| &lt;a href="https://github.com/vivekdogra02"&gt;Github&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>designthinking</category>
      <category>webdev</category>
      <category>web</category>
      <category>design</category>
    </item>
    <item>
      <title>Future-Proof Your JavaScript Code</title>
      <dc:creator>V.D</dc:creator>
      <pubDate>Tue, 30 May 2023 18:07:23 +0000</pubDate>
      <link>https://dev.to/vivekdogra02/future-proof-your-javascript-code-2op5</link>
      <guid>https://dev.to/vivekdogra02/future-proof-your-javascript-code-2op5</guid>
      <description>&lt;h3&gt;
  
  
  Future-Proof Your JavaScript Code: The Game-Changing Immutability Revolution
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9uYibz16--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/1%2Aa2X20MBG5FswCc_5rOlNNQ.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9uYibz16--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/1%2Aa2X20MBG5FswCc_5rOlNNQ.jpeg" alt="1" width="800" height="534"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this article, we will explore a set of new array methods that offer a fresh approach to achieving immutability.&lt;/p&gt;

&lt;p&gt;The methods under discussion are with, toSorted, toReversed, and toSpliced.&lt;/p&gt;

&lt;p&gt;Immutability ensures that the original array remains unchanged, and modifications are made on a new copy. While there were existing techniques for achieving immutability, such as utilizing the spread operator, these new array methods present more convenient alternatives.&lt;/p&gt;

&lt;p&gt;These methods offer improved code readability and performance benefits, making them advantageous for developers.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UsRRB3UH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/525/1%2Aop_Qx8-AxhGN6dUA4tPUHg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UsRRB3UH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/525/1%2Aop_Qx8-AxhGN6dUA4tPUHg.png" alt="" width="525" height="327"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;with() Method&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The with() method of &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array"&gt;Array&lt;/a&gt; instances is the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array#copying_methods_and_mutating_methods"&gt;copying&lt;/a&gt; version of using the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors#bracket_notation"&gt;bracket notation&lt;/a&gt; to change the value of a given index. It returns a new array with the element at the given index replaced with the given value.&lt;/p&gt;

&lt;p&gt;array.with(index, value) — will return a new array with the element at index replaced with value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const arr = [1, 2, 3, 4, 5];
console.log(arr.with(2, 6)); // [1, 2, 6, 4, 5]
console.log(arr); // [1, 2, 3, 4, 5]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. toSpliced()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;splice() — is method that will work on your original array, rather that on their copy.&lt;/p&gt;

&lt;p&gt;For eg: — in below example, splice has replaced the start and end index with the new value i.e. ““mango””&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--07rioeIQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1001/1%2A2AnL-qmbdPRG1rvd3h7FLg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--07rioeIQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1001/1%2A2AnL-qmbdPRG1rvd3h7FLg.png" alt="" width="800" height="298"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;what toSpliced() will do, it will not update the original array, rather than work on its copy and original array remains intact. It returns a new array instead of modifying the original array.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TFq4_Sb6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/708/1%2AsmEHKVMB8SQ0jxV3Gr2awQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TFq4_Sb6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/708/1%2AsmEHKVMB8SQ0jxV3Gr2awQ.png" alt="" width="708" height="191"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. toSorted()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Normally, we do sort by adding &lt;strong&gt;sort()&lt;/strong&gt; after any array, and it will sort the original array, there is a change in original array.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--u5DyS1W8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/931/1%2A4jrJQ_vwLzo4w2vBnAgYBQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--u5DyS1W8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/931/1%2A4jrJQ_vwLzo4w2vBnAgYBQ.png" alt="" width="800" height="289"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To remain intact with original array, you need to introduced spread operator and create a separate copy of that like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Bw4hoRXC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/962/1%2ALYz9Tb9QyuNZrqt_3BsW2Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Bw4hoRXC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/962/1%2ALYz9Tb9QyuNZrqt_3BsW2Q.png" alt="" width="800" height="305"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To remove this step, javascript has a new array method, there is no need to use the spread operator ie. toSorted()&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--A7cdZsJb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/686/1%2ALiz66Yxyu3FdJ-w1dNGqUA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--A7cdZsJb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/686/1%2ALiz66Yxyu3FdJ-w1dNGqUA.png" alt="" width="686" height="211"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. toReversed()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This method is working same as &lt;strong&gt;array.reverse(),&lt;/strong&gt; but rather than changing original array, it will create a new copy and original array remains intact.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mJlVA0AV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/526/1%2AwXWsCUJj31vGJP2NmqZtFA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mJlVA0AV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/526/1%2AwXWsCUJj31vGJP2NmqZtFA.png" alt="" width="526" height="212"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before using, any of these methods, please check their browser compatibility as many of them is not supported in Firefox, so make use if required. &lt;a href="https://caniuse.com/?search=array.with"&gt;https://caniuse.com/?search=array.with&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Also please make sure to check &lt;a href="https://developer.mozilla.org/en-US/"&gt;MDN Website&lt;/a&gt;to check for upcoming features in Javascript.&lt;/p&gt;

&lt;h3&gt;
  
  
  Thanks for reading
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;👏 Please clap for the story and follow me 👉&lt;/li&gt;
&lt;li&gt;📰 &lt;a href="https://medium.com/@vivekdogra02"&gt;View more content&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;🔔 Follow me: &lt;a href="https://www.linkedin.com/in/vivek-dogra-7404a530/"&gt;LinkedIn&lt;/a&gt;| &lt;a href="https://twitter.com/VivekDo07905087"&gt;Twitter&lt;/a&gt;| &lt;a href="https://github.com/vivekdogra02"&gt;Github&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




</description>
      <category>arrays</category>
      <category>javascript</category>
      <category>web</category>
      <category>python</category>
    </item>
    <item>
      <title>Angular —Adapter Pattern: Simplify Data Integration(Kanban Board)</title>
      <dc:creator>V.D</dc:creator>
      <pubDate>Fri, 19 May 2023 11:18:43 +0000</pubDate>
      <link>https://dev.to/vivekdogra02/angular-adapter-pattern-simplify-data-integrationkanban-board-3e0i</link>
      <guid>https://dev.to/vivekdogra02/angular-adapter-pattern-simplify-data-integrationkanban-board-3e0i</guid>
      <description>&lt;h3&gt;
  
  
  Simplifying Integration and Enhancing Flexibility
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_wvUiNS4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/1%2AFUgSi8RZKjq5rAGbKzATqw.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_wvUiNS4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/1%2AFUgSi8RZKjq5rAGbKzATqw.jpeg" alt="1" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Introduction
&lt;/h3&gt;

&lt;p&gt;A common requirement in modern web development is the integration of data from multiple sources. However, working with various data formats and APIs can be complex, and code can be tightly coupled to specific data sources. To overcome this problem, the adapter pattern provides a solution by acting as a bridge between incompatible interfaces. In this article, we’ll showcase the adapter pattern, using the Kanban board as an example. Will also provide code examples and practical use cases to illustrate the benefits.&lt;/p&gt;

&lt;h3&gt;
  
  
  Understanding the Adapter Pattern:
&lt;/h3&gt;

&lt;p&gt;The Adapter pattern is a structural design pattern that allows objects with incompatible interfaces to work together. It acts as an intermediary between two incompatible classes, translating requests from one to the other. This pattern provides a way to reuse existing code and promotes loose coupling between components.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The main components of the Adapter pattern are:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Target&lt;/strong&gt; : The interface that the client interacts with.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Adaptee&lt;/strong&gt; : The existing interface that needs to be adapted.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Adapter&lt;/strong&gt; : The bridge between the Target and the Adaptee that implements the Target interface and internally uses the Adaptee to perform the desired operations.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Real world use cases:
&lt;/h3&gt;

&lt;p&gt;To better understand the practical use of the adapter pattern, let’s look at a real world scenario. Imagine building a project management application with Angular and deciding to implement a Kanban board to visualize tasks and progress.&lt;/p&gt;

&lt;p&gt;Kanban boards integrate with various task management systems such as Jira, Trello, and Asana, each with its own API and data structure. Without the adapter pattern, you would have to write custom code for each task management system to tightly couple your application to these external services.&lt;/p&gt;

&lt;p&gt;However, the adapter pattern allows you to create an adapter for each project task management system by abstracting the details of the underlying API and data structures. This allows you to switch between different task management systems without changing the core logic of your application.&lt;/p&gt;

&lt;h3&gt;
  
  
  Implementing the Adapter Pattern in Angular:
&lt;/h3&gt;

&lt;p&gt;Now let’s dive into the implementation of the Adapter pattern in an Angular application. We’ll focus on integrating a Kanban board with two different task management systems: Jira and Trello.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Define the Kanban Board Component:&lt;/strong&gt;
First, let’s create the Kanban board component, which will be responsible for rendering the tasks and their corresponding status columns. Here’s a simplified example of the KanbanBoardComponent in Angular:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Component, OnInit } from '@angular/core';
import { Task } from './task.interface';
import { TaskManagementAdapter } from './task-management-adapter';

@Component({
  selector: 'app-kanban-board',
  template: `
    &amp;lt;div class="kanban-board"&amp;gt;
      &amp;lt;div class="column" *ngFor="let statusColumn of statusColumns"&amp;gt;
        &amp;lt;h2&amp;gt;{{ statusColumn }}&amp;lt;/h2&amp;gt;
        &amp;lt;div class="task" *ngFor="let task of getTasksByStatus(statusColumn)"&amp;gt;
          {{ task.title }}
        &amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  `,
  styleUrls: ['./kanban-board.component.css']
})
export class KanbanBoardComponent implements OnInit {
  statusColumns: string[] = ['To Do', 'In Progress', 'Done'];
  tasks: Task[] = [];
  taskManagementAdapter: TaskManagementAdapter;

  constructor(private adapter: TaskManagementAdapter) {
    this.taskManagementAdapter = adapter;
  }

  ngOnInit(): void {
    this.loadTasks();
  }

  loadTasks(): void {
    this.tasks = this.taskManagementAdapter.getTasks();
  }

  getTasksByStatus(status: string): Task[] {
    return this.tasks.filter(task =&amp;gt; task.status === status);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Create the Task Interface and Adapters:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Next, let’s define the Task interface, which represents a task on the Kanban board. We’ll also create adapters for Jira and Trello, implementing the &lt;strong&gt;TaskManagementAdapter&lt;/strong&gt; interface. Here’s an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export interface Task {
  id: number;
  title: string;
  status

: string;
}

export interface TaskManagementAdapter {
  getTasks(): Task[];
}

export class JiraAdapter implements TaskManagementAdapter {
  getTasks(): Task[] {
    // Implement Jira-specific logic to fetch tasks
    // and map them to the Task interface
  }
}

export class TrelloAdapter implements TaskManagementAdapter {
  getTasks(): Task[] {
    // Implement Trello-specific logic to fetch tasks
    // and map them to the Task interface
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Implement the Adapters:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Now, it’s time to implement the &lt;strong&gt;JiraAdapter&lt;/strong&gt; and &lt;strong&gt;TrelloAdapter&lt;/strong&gt;. These adapters encapsulate the logic of interacting with the respective task management systems’ APIs and converting the data into the Task interface format. Here’s a simplified example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export class JiraAdapter implements TaskManagementAdapter {
  getTasks(): Task[] {
    // Use Jira API to fetch tasks
    // Convert and map the fetched data to the Task interface format
    return jiraAPI.getTasks().map(task =&amp;gt; ({
      id: task.id,
      title: task.name,
      status: task.status
    }));
  }
}

export class TrelloAdapter implements TaskManagementAdapter {
  getTasks(): Task[] {
    // Use Trello API to fetch tasks
    // Convert and map the fetched data to the Task interface format
    return trelloAPI.getTasks().map(task =&amp;gt; ({
      id: task.id,
      title: task.title,
      status: task.status
    }));
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Wiring Everything Together:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Finally, we need to provide the appropriate adapter to the KanbanBoardComponent. In your Angular module, you can configure the dependency injection to provide the desired adapter. Here’s an example using the JiraAdapter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { AppComponent } from './app.component';
import { KanbanBoardComponent } from './kanban-board/kanban-board.component';
import { TaskManagementSystemAdapter } from './adapters/task-management-system.adapter';
import { JiraAdapter } from './adapters/jira.adapter';
import { TrelloAdapter } from './adapters/trello.adapter';

@NgModule({
  declarations: [
    AppComponent,
    KanbanBoardComponent
  ],
  imports: [
    BrowserModule
  ],
  providers: [
    { provide: TaskManagementSystemAdapter, useClass: JiraAdapter }, // Using JiraAdapter
    { provide: TaskManagementSystemAdapter, useClass: TrelloAdapter } // Using TrelloAdapter
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the above code, both the &lt;strong&gt;JiraAdapter&lt;/strong&gt; and the &lt;strong&gt;TrelloAdapter&lt;/strong&gt; are provided as implementations for the &lt;strong&gt;TaskManagementSystemAdapter&lt;/strong&gt; token. By doing this, Angular’s dependency injection will be able to inject the appropriate adapter based on the context.&lt;/p&gt;

&lt;p&gt;Now, when the &lt;strong&gt;KanbanBoardComponent&lt;/strong&gt; is instantiated, Angular will inject both the &lt;strong&gt;JiraAdapter&lt;/strong&gt; and the &lt;strong&gt;TrelloAdapter&lt;/strong&gt; as separate instances of the &lt;strong&gt;TaskManagementSystemAdapter&lt;/strong&gt;. You can then use these adapters based on your specific requirements within the &lt;strong&gt;KanbanBoardComponent&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This approach allows you to integrate and work with multiple task management systems simultaneously within your K &lt;strong&gt;anban board application&lt;/strong&gt;. You can handle different tasks and operations with each &lt;strong&gt;adapter&lt;/strong&gt; , providing a comprehensive solution that caters to diverse needs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// kanban-board.component.ts
import { Component, OnInit } from '@angular/core';
import { TaskManagementSystemAdapter } from '../adapters/task-management-system.adapter';

@Component({
  selector: 'app-kanban-board',
  templateUrl: './kanban-board.component.html',
  styleUrls: ['./kanban-board.component.css']
})
export class KanbanBoardComponent implements OnInit {
  tasks: string[] = [];

  constructor(
    private jiraAdapter: TaskManagementSystemAdapter,
    private trelloAdapter: TaskManagementSystemAdapter
  ) {}

  ngOnInit() {
    this.loadTasks();
  }

  loadTasks() {
    // Use the JiraAdapter to fetch tasks from Jira
    const jiraTasks = this.jiraAdapter.getTasks();
    this.tasks.push(...jiraTasks);

    // Use the TrelloAdapter to fetch tasks from Trello
    const trelloTasks = this.trelloAdapter.getTasks();
    this.tasks.push(...trelloTasks);
  }

  addTask(task: string) {
    // Use the JiraAdapter to create a new task in Jira
    this.jiraAdapter.createTask(task);

    // Use the TrelloAdapter to create a new task in Trello
    this.trelloAdapter.createTask(task);
  }

  removeTask(index: number) {
    this.tasks.splice(index, 1);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the above code, the &lt;strong&gt;KanbanBoardComponent&lt;/strong&gt; has two dependencies injected: &lt;strong&gt;jiraAdapter&lt;/strong&gt; of type &lt;strong&gt;TaskManagementSystemAdapter&lt;/strong&gt; and &lt;strong&gt;trelloAdapter&lt;/strong&gt; of type &lt;strong&gt;TaskManagementSystemAdapter&lt;/strong&gt;. These dependencies are provided by the &lt;strong&gt;AppModule&lt;/strong&gt; , where we configured the dependency injection to use both the &lt;strong&gt;JiraAdapter&lt;/strong&gt; and the &lt;strong&gt;TrelloAdapter&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;addTask&lt;/strong&gt; method allows you to create a new task. Using the &lt;strong&gt;jiraAdapter&lt;/strong&gt; and &lt;strong&gt;trelloAdapter&lt;/strong&gt; , we can call the &lt;strong&gt;createTask&lt;/strong&gt; method on each adapter to &lt;strong&gt;create the task in both Jira and Trello simultaneously.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;removeTask&lt;/strong&gt; method removes a task from the tasks array when it is completed or deleted, as per your implementation.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;By using both adapters in the KanbanBoardComponent&lt;/strong&gt; , you can seamlessly integrate and work with multiple task management systems, such as Jira and Trello, within the same Kanban board application. This provides the flexibility to manage tasks across different platforms without writing separate code for each system.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Furthermore, the Adapter pattern promotes a modular and extensible architecture. We can extend our application to support additional task management systems simply by creating new adapters that adhere to the TaskManagementAdapter interface. This flexibility is especially beneficial in scenarios where we may need to integrate multiple external systems or switch between different providers over time.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;By applying the &lt;strong&gt;Adapter pattern in our Angular application&lt;/strong&gt; , we have successfully decoupled the &lt;strong&gt;Kanban board component&lt;/strong&gt; from s &lt;strong&gt;pecific task management systems&lt;/strong&gt;. The adapters act as intermediaries, enabling seamless integration with different APIs and data structures. This approach promotes code reusability, flexibility, and maintainability.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Adapter pattern&lt;/strong&gt; is a powerful tool in Angular development when dealing with disparate data sources. Whether you’re integrating with external APIs, databases, or other systems, the Adapter pattern provides an elegant solution to manage the complexities of data integration.&lt;/p&gt;

&lt;p&gt;Start incorporating this pattern into your angular projects and experience the benefits firsthand. Happy coding!&lt;/p&gt;

&lt;h3&gt;
  
  
  Thanks for reading
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;👏 Please clap for the story and follow me 👉&lt;/li&gt;
&lt;li&gt;📰 &lt;a href="https://medium.com/@vivekdogra02"&gt;View more content&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;🔔 Follow me: &lt;a href="https://www.linkedin.com/in/vivek-dogra-7404a530/"&gt;LinkedIn&lt;/a&gt;| &lt;a href="https://twitter.com/VivekDo07905087"&gt;Twitter&lt;/a&gt;| &lt;a href="https://github.com/vivekdogra02"&gt;Github&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




</description>
      <category>webdev</category>
      <category>typescript</category>
      <category>angular</category>
      <category>webdesign</category>
    </item>
    <item>
      <title>14 Tips for Enhancing Angular Performance</title>
      <dc:creator>V.D</dc:creator>
      <pubDate>Fri, 19 May 2023 06:41:55 +0000</pubDate>
      <link>https://dev.to/vivekdogra02/14-tips-for-enhancing-angular-performance-1i3i</link>
      <guid>https://dev.to/vivekdogra02/14-tips-for-enhancing-angular-performance-1i3i</guid>
      <description>&lt;h4&gt;
  
  
  Practical Techniques to Boost Angular Application Performance
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nSmkG20_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/1%2A8j4H_U1U4Jkx32GIVBqBUA.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nSmkG20_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/1%2A8j4H_U1U4Jkx32GIVBqBUA.jpeg" alt="1" width="800" height="699"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Introduction:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Angular is a powerful framework for building &lt;strong&gt;powerful&lt;/strong&gt; web applications, and &lt;strong&gt;optimization&lt;/strong&gt; is &lt;strong&gt;key&lt;/strong&gt;  &lt;strong&gt;to&lt;/strong&gt;  &lt;strong&gt;providing&lt;/strong&gt; a &lt;strong&gt;great&lt;/strong&gt; user experience. In this &lt;strong&gt;post,&lt;/strong&gt;  &lt;strong&gt;we’ll&lt;/strong&gt;  &lt;strong&gt;go&lt;/strong&gt;  &lt;strong&gt;over&lt;/strong&gt; some practical tips to &lt;strong&gt;improve&lt;/strong&gt; Angular performance. Each tip is accompanied by code examples to illustrate the implementation.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Lazy Loading Modules:&lt;/strong&gt;
Lazy loading helps reduce the initial load time by loading modules on-demand. Use the &lt;code&gt;**loadChildren**&lt;/code&gt; property in the route configuration to specify which modules should be lazily loaded.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const routes: Routes = [
 { path: 'lazy', loadChildren: () =&amp;gt; import('./lazy/lazy.module').then(m =&amp;gt; m.LazyModule) },
];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;2. Ahead-of-Time (AOT) Compilation:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Enable AOT compilation to generate optimized and smaller bundles. AOT compilation reduces the bundle size and improves the application’s startup time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Change Detection Strategy:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Optimize change detection by using &lt;code&gt;OnPush&lt;/code&gt; strategy for components that don’t require frequent updates. This strategy reduces unnecessary checks and improves overall performance.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Component({
 selector: 'app-example',
 templateUrl: './example.component.html',
 changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ExampleComponent { }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. TrackBy Function in ngFor:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
When using &lt;code&gt;ngFor&lt;/code&gt; directive, provide a &lt;code&gt;trackBy&lt;/code&gt; function to track item changes efficiently. This reduces the re-rendering of elements that haven’t changed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;ul&amp;gt;
 &amp;lt;li *ngFor="let item of items; trackBy: trackByFn"&amp;gt;{{ item }}&amp;lt;/li&amp;gt;
&amp;lt;/ul&amp;gt;

Typescript

trackByFn(index: number, item: any): any {
 return item.id; // Replace with a unique identifier for each item
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5. Unsubscribe when not in use:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Manually unsubscribe from subscriptions to prevent memory leaks. Use &lt;code&gt;**takeUntil**&lt;/code&gt; operator and a subject to manage subscriptions and unsubscribe when the component is destroyed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;private destroy$ = new Subject();
ngOnInit(): void {
 someObservable$
 .pipe(takeUntil(this.destroy$))
 .subscribe((data) =&amp;gt; {
 // Handle the data
 });
}
ngOnDestroy(): void {
 this.destroy$.next();
 this.destroy$.complete();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6. ChangeDetectionRef.markForCheck():&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Use &lt;code&gt;**markForCheck** ()&lt;/code&gt; method from &lt;code&gt;**ChangeDetectionRef**&lt;/code&gt; to selectively trigger change detection only when necessary. This can improve performance in specific scenarios.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;constructor(private cdr: ChangeDetectorRef) { }
updateData(): void {
 // Update data here
 this.cdr.markForCheck();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;7. NgZone Optimization:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Leverage the &lt;code&gt;NgZone&lt;/code&gt; service to optimize the execution of code that doesn’t require Angular’s change detection. Use the &lt;code&gt;**runOutsideAngular**&lt;/code&gt; method to execute code outside Angular’s zone.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;constructor(private ngZone: NgZone) { }
performHeavyTask(): void {
 this.ngZone.runOutsideAngular(() =&amp;gt; {
 // Perform heavy task here
 });
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;8. Avoid Excessive DOM Manipulation:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Minimize direct DOM manipulation and use Angular’s data binding and directives instead. Excessive DOM manipulation can impact performance negatively.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;9. Use Angular Pipes Wisely:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Angular pipes can impact performance if used improperly. While pipes offer great flexibility and convenience, it’s important to use them judiciously to ensure optimal performance.&lt;/p&gt;

&lt;p&gt;Angular provides two types of pipes: pure and impure. Pure pipes are memoized, meaning they only recalculate when the input value changes. This reduces unnecessary computations and improves performance. Always strive to use pure pipes whenever possible.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Avoid performing heavy computations within pipes, especially if the computation is not necessary for every change detection cycle. Complex calculations can introduce performance bottlenecks, so consider moving such computations to the component class or leveraging caching techniques to optimize performance.&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Pipe({
  name: 'instantPipe',
  pure: true
})
export class InstantPipe implements PipeTransform {
  transform(value: any): any {
    // Transformation logic here
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;10. Debounce Input Events:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Use the &lt;code&gt;debounceTime&lt;/code&gt; operator to reduce the frequency of input event handling. This prevents excessive updates and reduces unnecessary processing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;searchInput.valueChanges
 .pipe(debounceTime(300))
 .subscribe((value) =&amp;gt; {
 // Handle the search value
 });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;11. Optimize HTTP Requests:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Reduce the number of HTTP requests by combining multiple requests or using caching strategies. Leverage features like HTTP interceptors to handle common functionality across requests.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Combine multiple HTTP requests
forkJoin([http.get('data1'), http.get('data2')]).subscribe(([data1, data2]) =&amp;gt; {
  // Handle the responses
});

// Implement caching using an interceptor
@Injectable()
export class CachingInterceptor implements HttpInterceptor {
  // ...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;12. Use Angular Reactive Forms:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Reactive Forms offer better performance than template-driven forms, especially when dealing with complex form scenarios. They provide more control and allow for fine-grained validation and data handling.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { FormGroup, FormControl, Validators } from '@angular/forms';

const form = new FormGroup({
  name: new FormControl('', Validators.required),
  // ...
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;13. Angular Universal for Server-Side Rendering (SSR):&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Implement &lt;strong&gt;Angular Universal&lt;/strong&gt; for server-side rendering. SSR improves initial load times, enables search engine optimization, and provides a better user experience, especially for low-bandwidth or high-latency environments.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;14. Use Angular Performance Tools:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Angular offers various performance tools, such as Angular &lt;strong&gt;DevTools&lt;/strong&gt; and &lt;strong&gt;Augury&lt;/strong&gt; , which provide insights into performance bottlenecks and help identify areas for optimization.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt; :&lt;br&gt;&lt;br&gt;
By implementing these performance optimization tips, you can significantly enhance the speed and responsiveness of your Angular applications. Remember to analyze and profile your application to identify specific areas for improvement and measure the impact of these optimizations. Building performant Angular applications not only improves the user experience but also ensures scalability and efficiency.&lt;/p&gt;

&lt;p&gt;Start incorporating these into your angular projects and experience the benefits firsthand. Happy coding!&lt;/p&gt;

&lt;h3&gt;
  
  
  Thanks for reading
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;👏 Please clap for the story and follow me 👉&lt;/li&gt;
&lt;li&gt;📰 &lt;a href="https://medium.com/@vivekdogra02"&gt;View more content&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;🔔 Follow me: &lt;a href="https://www.linkedin.com/in/vivek-dogra-7404a530/"&gt;LinkedIn&lt;/a&gt;| &lt;a href="https://twitter.com/VivekDo07905087"&gt;Twitter&lt;/a&gt;| &lt;a href="https://github.com/vivekdogra02"&gt;Github&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




</description>
      <category>angular</category>
      <category>webdev</category>
      <category>performance</category>
      <category>webdesign</category>
    </item>
    <item>
      <title>React: Abstract Design Pattern-DRY &amp; Single Shared Responsibility(Part-2)</title>
      <dc:creator>V.D</dc:creator>
      <pubDate>Sun, 14 May 2023 05:54:34 +0000</pubDate>
      <link>https://dev.to/vivekdogra02/react-abstract-design-pattern-dry-single-shared-responsibilitypart-2-l61</link>
      <guid>https://dev.to/vivekdogra02/react-abstract-design-pattern-dry-single-shared-responsibilitypart-2-l61</guid>
      <description>&lt;h3&gt;
  
  
  React: Abstract Design Pattern-DRY &amp;amp; Single Shared Responsibility(Part-2)
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Understanding the Abstract Method pattern in React and exploring how it can be implemented in your applications.
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oHqTocpv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/1%2AKGprQ-67EafNQzDbPEEnjw.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oHqTocpv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/1%2AKGprQ-67EafNQzDbPEEnjw.jpeg" alt="img" width="800" height="572"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is in continuation with the last article on &lt;strong&gt;React — Abstract Design pattern&lt;/strong&gt;. This article is basically on the potential areas where performance issues could arise.&lt;a href="https://vivekdogra02.medium.com/react-abstract-design-pattern-dry-single-shared-responsibility-part-1-c63dfac5eb8c"&gt;Link to last article&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  In continuation with the last post code, there are a few potential areas where performance issues could arise,
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Rendering large datasets&lt;/strong&gt; : If the &lt;strong&gt;transactions&lt;/strong&gt; array contains a large number of items, rendering them all at once can impact performance. To mitigate this, consider implementing pagination or virtualization techniques to load and render only the visible portion of the dataset.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dynamic function creation&lt;/strong&gt; : The &lt;strong&gt;getFormatAmount&lt;/strong&gt; function dynamically creates the &lt;strong&gt;formatAmount&lt;/strong&gt; function based on the transaction type. While this approach provides flexibility, it can impact performance if the function creation process becomes complex or computationally expensive. Ensure that the function creation logic remains simple and efficient to avoid any performance bottlenecks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Complex transaction processing&lt;/strong&gt; : If the processing or manipulation of transaction data within the &lt;strong&gt;TransactionItem&lt;/strong&gt; component becomes computationally intensive, it may lead to performance issues. Analyze the operations performed on each transaction and optimize them as necessary. Consider leveraging memoization or caching techniques to avoid unnecessary calculations or redundant operations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Inefficient rendering updates:&lt;/strong&gt; If there are frequent updates to the &lt;strong&gt;transactions&lt;/strong&gt; array or individual transactions, it can trigger unnecessary re-renders. To optimize this, ensure that the &lt;strong&gt;transactions&lt;/strong&gt; array and its items are immutably updated to prevent unintended re-renders. Additionally, consider implementing more granular component updates using React's &lt;strong&gt;shouldComponentUpdate&lt;/strong&gt; or &lt;strong&gt;React.memo&lt;/strong&gt; to prevent unnecessary rendering of components that have not changed.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;It’s important to profile and analyze the performance of your application using tools like &lt;strong&gt;React DevTools, Chrome DevTools, or other performance monitoring tools&lt;/strong&gt;. By identifying and addressing specific performance bottlenecks, you can optimize the code and improve the overall performance of your financial app.&lt;/p&gt;

&lt;h4&gt;
  
  
  To avoid potential performance issues in the provided code, here are some suggestions:
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Implement pagination or virtualization:&lt;/strong&gt; If the &lt;strong&gt;transactions&lt;/strong&gt; array contains a large number of items, consider implementing pagination or virtualization techniques. Instead of rendering all transactions at once, load and render only a subset of transactions based on the current viewport or user interaction. This approach improves initial load time and reduces rendering overhead.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Optimize the dynamic function creation&lt;/strong&gt; : The &lt;strong&gt;getFormatAmount&lt;/strong&gt; function dynamically creates the &lt;strong&gt;formatAmount&lt;/strong&gt; function based on the transaction type. To optimize performance, ensure that the function creation logic remains lightweight and efficient. Avoid complex computations or heavy operations within the function creation process. If possible, precompute or memoize the format functions to avoid repetitive calculations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Streamline transaction processing:&lt;/strong&gt; Analyze the operations performed on each transaction within the &lt;strong&gt;TransactionItem&lt;/strong&gt; component. Look for opportunities to optimize data processing and manipulation. Use efficient algorithms and data structures to minimize computational overhead. Consider memoization techniques to cache expensive calculations or avoid redundant operations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use immutability and granular updates&lt;/strong&gt; : Ensure that the &lt;strong&gt;transactions&lt;/strong&gt; array and its items are updated in an immutable manner. Avoid mutating the original array directly, as it can lead to unnecessary re-renders. Instead, create new arrays or objects when making updates. Additionally, utilize React's &lt;strong&gt;shouldComponentUpdate&lt;/strong&gt; lifecycle method or the &lt;strong&gt;React.memo&lt;/strong&gt; higher-order component to prevent unnecessary re-renders of components that have not changed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Profile and optimize&lt;/strong&gt; : Utilize &lt;strong&gt;performance profiling tools&lt;/strong&gt; such as React DevTools or Chrome DevTools to identify performance bottlenecks. Measure the rendering times, identify components with excessive re-renders, and analyze the performance of critical code sections. Optimize the identified areas by refactoring, simplifying computations, or implementing caching strategies.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;By implementing these suggestions, you can improve the performance of your application, ensuring efficient rendering and minimizing unnecessary computations. &lt;strong&gt;Regular performance testing and profiling&lt;/strong&gt; will help you identify specific areas for optimization and ensure your financial app performs optimally.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here’s an updated version of the code with optimizations to address the performance concerns:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useMemo } from 'react';
const FinancialApp = ({ transactions }) =&amp;gt; {
  // Pagination or virtualization logic here
  const getFormatAmount = useMemo(() =&amp;gt; {
    const formatAmount = (amount) =&amp;gt; `$${amount}`;
    return (type) =&amp;gt; {
      switch (type) {
        case 'expense':
          return (amount) =&amp;gt; `- $${amount}`;
        case 'income':
          return (amount) =&amp;gt; `+ $${amount}`;
        case 'transfer':
          return (amount) =&amp;gt; `$${amount}`;
        default:
          return formatAmount;
      }
    };
  }, []);
  return (
    &amp;lt;div&amp;gt;
      {/* Rendering logic with pagination or virtualization */}
      {visibleTransactions.map((transaction, index) =&amp;gt; (
        &amp;lt;div key={transaction.id}&amp;gt;
          &amp;lt;TransactionItem transaction={transaction} formatAmount={getFormatAmount(transaction.type)} /&amp;gt;
        &amp;lt;/div&amp;gt;
      ))}
    &amp;lt;/div&amp;gt;
  );
};
const TransactionItem = ({ transaction, formatAmount }) =&amp;gt; {
  // Transaction item rendering logic here
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;span&amp;gt;{transaction.description}&amp;lt;/span&amp;gt;
      &amp;lt;span&amp;gt;{formatAmount(transaction.amount)}&amp;lt;/span&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;In the updated code:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The &lt;strong&gt;getFormatAmount&lt;/strong&gt; function is &lt;strong&gt;memoized&lt;/strong&gt; using the &lt;strong&gt;useMemo&lt;/strong&gt; hook. This ensures that the function is only created once and doesn't get re-computed on subsequent renders unless the dependencies change. It improves performance by avoiding unnecessary function re-creation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The rendering logic includes placeholders for pagination or virtualization techniques.&lt;/strong&gt; Based on your specific requirements, you can implement the necessary logic to render a subset of transactions based on the current viewport or user interactions. This approach improves performance by reducing the number of rendered items.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;TransactionItem&lt;/strong&gt; component receives the &lt;strong&gt;formatAmount&lt;/strong&gt; function as a prop. This allows the component to access the appropriate format function without dynamically creating it on each render. It reduces redundancy and optimizes rendering by avoiding unnecessary function calls.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Remember to adapt the code to your specific needs, including the implementation of &lt;strong&gt;pagination or virtualization&lt;/strong&gt; logic. These optimizations provide a starting point for improving performance, but the exact implementation will depend on your application’s requirements and complexity.&lt;/p&gt;

&lt;h3&gt;
  
  
  Here are some additional customization options for the Pagination component, each with its own code example:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Custom Styling:&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Pagination = ({ currentPage, totalPages, onPageChange }) =&amp;gt; {
  const pages = [...Array(totalPages).keys()].map((page) =&amp;gt; page + 1);

  return (
    &amp;lt;div className="pagination-container"&amp;gt;
      {pages.map((page) =&amp;gt; (
        &amp;lt;button
          key={page}
          onClick={() =&amp;gt; onPageChange(page)}
          className={currentPage === page ? 'active' : ''}
        &amp;gt;
          {page}
        &amp;lt;/button&amp;gt;
      ))}
    &amp;lt;/div&amp;gt;
  );
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we add a custom CSS class 'pagination-container' to the parent div element. You can then define the styling for the pagination component using CSS to match your desired look and feel.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Previous and Next Buttons:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Pagination = ({ currentPage, totalPages, onPageChange }) =&amp;gt; {
  const pages = [...Array(totalPages).keys()].map((page) =&amp;gt; page + 1);

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;button onClick={() =&amp;gt; onPageChange(currentPage - 1)} disabled={currentPage === 1}&amp;gt;
        Previous
      &amp;lt;/button&amp;gt;

      {pages.map((page) =&amp;gt; (
        &amp;lt;button
          key={page}
          onClick={() =&amp;gt; onPageChange(page)}
          className={currentPage === page ? 'active' : ''}
        &amp;gt;
          {page}
        &amp;lt;/button&amp;gt;
      ))}

      &amp;lt;button onClick={() =&amp;gt; onPageChange(currentPage + 1)} disabled={currentPage === totalPages}&amp;gt;
        Next
      &amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we add previous and next buttons to allow the user to navigate to the previous and next pages, respectively. The buttons are disabled when the user is on the first or last page to prevent unnecessary navigation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Compact View:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Pagination = ({ currentPage, totalPages, onPageChange }) =&amp;gt; {
  const pages = [...Array(totalPages).keys()].map((page) =&amp;gt; page + 1);

  return (
    &amp;lt;div&amp;gt;
      {pages.map((page) =&amp;gt; (
        &amp;lt;button
          key={page}
          onClick={() =&amp;gt; onPageChange(page)}
          className={currentPage === page ? 'active' : ''}
        &amp;gt;
          {page}
        &amp;lt;/button&amp;gt;
      ))}

      &amp;lt;span&amp;gt;Page {currentPage} of {totalPages}&amp;lt;/span&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we remove the previous and next buttons and instead display the current page number and total number of pages. This provides a more compact view of the pagination component.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Custom Labels:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Pagination = ({ currentPage, totalPages, onPageChange }) =&amp;gt; {
  const pages = [...Array(totalPages).keys()].map((page) =&amp;gt; page + 1);

  return (
    &amp;lt;div&amp;gt;
      {pages.map((page) =&amp;gt; (
        &amp;lt;button
          key={page}
          onClick={() =&amp;gt; onPageChange(page)}
          className={currentPage === page ? 'active' : ''}
        &amp;gt;
          {page}
        &amp;lt;/button&amp;gt;
      ))}

      &amp;lt;button onClick={() =&amp;gt; onPageChange(currentPage + 1)} disabled={currentPage === totalPages}&amp;gt;
        Next Page
      &amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we customize the label of the next button to display “Next Page” instead of just “Next”. This provides a more descriptive and user-friendly label for navigation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Page Size Selection:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Pagination = ({ currentPage, totalPages, onPageChange, pageSizeOptions, pageSize, onPageSizeChange }) =&amp;gt; {
  const pages = [...Array(totalPages).keys()].map((page) =&amp;gt; page + 1);

  return (
    &amp;lt;div&amp;gt;
      {pages.map((page) =&amp;gt; (
        &amp;lt;button
          key={page}
          onClick={() =&amp;gt; onPageChange(page)}
          className={currentPage === page ? 'active' : ''}
        &amp;gt;
          {page}
        &amp;lt;/button&amp;gt;
      ))}

      &amp;lt;select value={pageSize} onChange={(e) =&amp;gt; onPageSizeChange(e.target.value)}&amp;gt;
        {pageSizeOptions.map((option) =&amp;gt; (
          &amp;lt;option key={option} value={option}&amp;gt;
            {option}
          &amp;lt;/option&amp;gt;
        ))}
      &amp;lt;/select&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we introduce a page size selection feature. It includes a dropdown select element where the user can choose the number of items to display per page. The pageSizeOptions array contains the available page size options, and the pageSize state represents the currently selected page size. The onPageSizeChange function is called when the user selects a new page size.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Custom Page Range:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Pagination = ({ currentPage, totalPages, onPageChange, pageRange }) =&amp;gt; {
  const startPage = currentPage - Math.floor(pageRange / 2);
  const endPage = currentPage + Math.floor(pageRange / 2);
  const pages = [...Array(totalPages).keys()].map((page) =&amp;gt; page + 1).slice(startPage, endPage + 1);

  return (
    &amp;lt;div&amp;gt;
      {pages.map((page) =&amp;gt; (
        &amp;lt;button
          key={page}
          onClick={() =&amp;gt; onPageChange(page)}
          className={currentPage === page ? 'active' : ''}
        &amp;gt;
          {page}
        &amp;lt;/button&amp;gt;
      ))}
    &amp;lt;/div&amp;gt;
  );
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we introduce a custom page range feature. The pageRange represents the number of consecutive page buttons to display around the current page. The startPage and endPage variables calculate the range of pages to be shown based on the current page and the page range. The pages array is then sliced to obtain the desired range of page numbers.&lt;/p&gt;

&lt;p&gt;Feel free to mix and match these customization options or come up with your own variations based on your application’s specific needs. The goal is to tailor the Pagination component to fit your desired functionality and design.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;By leveraging the abstract method pattern in React,&lt;/strong&gt; we can build a robust and modular financial app that effectively manages various types of transactions and ensures clean, reusable code.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion:
&lt;/h3&gt;

&lt;p&gt;By implementing the Abstract Method pattern in React using a functional approach, we can achieve code reuse, remove redundancy, and avoid code smells. The abstract component provides a common structure and behavior, while child components extend it to define specific rendering and logic. This approach promotes a cleaner and more maintainable codebase, making it easier to scale and modify our applications.&lt;/p&gt;

&lt;p&gt;Remember, the Abstract Method pattern is just one of many patterns that can be leveraged in React development. It’s important to evaluate its suitability based on the specific needs and complexity of your application. By applying design patterns thoughtfully, we can enhance code quality and build.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I Hope you liked it, By leveraging this pattern,&lt;/strong&gt; you can build applications that are easier to manage and evolve over time. Understanding and applying design patterns in React empowers developers to write clean, efficient, and robust code.&lt;/p&gt;

&lt;p&gt;Start incorporating the Abstract Design pattern into your React projects and experience the benefits firsthand. Happy coding!&lt;/p&gt;

&lt;h3&gt;
  
  
  Thanks for reading
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;👏 Please clap for the story and follow me 👉&lt;/li&gt;
&lt;li&gt;📰 &lt;a href="https://medium.com/@vivekdogra02"&gt;View more content&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;🔔 Follow me: &lt;a href="https://www.linkedin.com/in/vivek-dogra-7404a530/"&gt;LinkedIn&lt;/a&gt;| &lt;a href="https://twitter.com/VivekDo07905087"&gt;Twitter&lt;/a&gt;| &lt;a href="https://github.com/vivekdogra02"&gt;Github&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




</description>
      <category>react</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>design</category>
    </item>
    <item>
      <title>React: Abstract Design Pattern-DRY &amp; Single Shared Responsibility(Part-1)</title>
      <dc:creator>V.D</dc:creator>
      <pubDate>Sun, 14 May 2023 05:53:19 +0000</pubDate>
      <link>https://dev.to/vivekdogra02/react-abstract-design-pattern-dry-single-shared-responsibilitypart-1-58me</link>
      <guid>https://dev.to/vivekdogra02/react-abstract-design-pattern-dry-single-shared-responsibilitypart-1-58me</guid>
      <description>&lt;h3&gt;
  
  
  Understanding the Abstract Method pattern in React and exploring how it can be implemented in your applications.
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NeXmaCi7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/1%2AeRd7P--4RUgH8T3Q2BuJpA.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NeXmaCi7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/1%2AeRd7P--4RUgH8T3Q2BuJpA.jpeg" alt="img1" width="800" height="572"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Today, I am going to showcase ADP(Abstract design pattern) inside react, and how can we achieve it. If you want see this happening in action inside Angular, please read this blog &lt;a href="https://dev.to/vivekdogra02/angular-abstract-design-pattern-dry-single-shared-responsibility-29j"&gt;Angular-ADP&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Before jumping into react, we need to know that what is an Abstract design pattern and whether it is there in react too. So, let me make it clear that, in any language or framework we are using in today’s world, to make your code organized and reliable to be bug/error free, you should always adopt a design pattern. A design pattern is universal, you can implement in any language as it states only the way you are designing your application.&lt;/p&gt;

&lt;p&gt;It is a misconception that a design pattern is used for increasing the performance only. Its primary goal is to promote code reuse and remove redundancy by defining a common structure and behavior.&lt;/p&gt;

&lt;h3&gt;
  
  
  So, let’s get started
&lt;/h3&gt;

&lt;p&gt;If you don't know what is an ADP(Abstract Design Pattern), please read this blog &lt;a href="https://dev.to/vivekdogra02/angular-abstract-design-pattern-dry-single-shared-responsibility-29j"&gt;Angular-ADP&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In React, the Abstract Method pattern provides a way to define a common structure for components while allowing specific implementations to be defined in child components. This pattern promotes code reuse, reduces redundancy, and helps maintain a clean and scalable codebase. In this article, we will explore the Abstract Method pattern in React and demonstrate its implementation using a functional approach. We will showcase detailed examples and discuss best practices to remove redundancy and avoid code smells.&lt;/p&gt;

&lt;h3&gt;
  
  
  Understanding the Abstract Method Pattern:
&lt;/h3&gt;

&lt;p&gt;The Abstract Method pattern is based on the concept of abstract classes and methods in object-oriented programming. &lt;strong&gt;While React does not directly support abstract classes, we can achieve a similar effect by leveraging higher-order components (HOCs) or custom hooks.&lt;/strong&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Example Scenario:
&lt;/h4&gt;

&lt;p&gt;Consider a scenario in which you want to create a notification system in your application that supports different types of notifications, such as success, error, and warning. We want to define a common structure for these notifications, but allow specific rendering and behavior for each type&lt;/p&gt;

&lt;h3&gt;
  
  
  Implementation steps
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Defines an AbstractNotificationcomponent that describes the general structure and behavior of notifications. These components can contain common user interface elements and functions common to all types of notifications.&lt;/li&gt;
&lt;li&gt;Create child components, such as SuccessNotification, ErrorNotification, and WarningNotification, that extend the AbstractNotification component. These child components will provide the specific rendering and behavior for each notification type.&lt;/li&gt;
&lt;li&gt;Implement abstract methods in &lt;strong&gt;AbstractNotification&lt;/strong&gt; component. This method can serve as a placeholder to override certain logic in child components. For example, you could define an abstract method called &lt;strong&gt;renderDataContent&lt;/strong&gt; for child components to implement to render content specific to each notification type.&lt;/li&gt;
&lt;li&gt;Utilize the abstract method within the AbstractNotification component's render method. This allows child components to inject their specific content while maintaining the common structure provided by the abstract component.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// AbstractNotification.js
import React from 'react';

const AbstractNotification = ({ title, message }) =&amp;gt; {
  const renderDataContent= () =&amp;gt; {
    throw new Error('Child component must override the renderDataContent method.');
  };

  return (
    &amp;lt;div className="notification"&amp;gt;
      &amp;lt;h2&amp;gt;{title}&amp;lt;/h2&amp;gt;
      &amp;lt;div className="content"&amp;gt;{renderDataContent()}&amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

------------------------------------------------------------------------------

export default AbstractNotification;

// SuccessNotification.js
import React from 'react';
import AbstractNotification from './AbstractNotification';

const SuccessNotification = ({ title, message }) =&amp;gt; {
  const renderDataContent= () =&amp;gt; {
    return &amp;lt;p className="success-message"&amp;gt;{message}&amp;lt;/p&amp;gt;;
  };

  return &amp;lt;AbstractNotification title={title} message={message} renderDataContent={renderDataContent} /&amp;gt;;
};

export default SuccessNotification;
------------------------------------------------------------------------------

// App.js
import React from 'react';
import SuccessNotification from './SuccessNotification';

const App = () =&amp;gt; {
  return (
    &amp;lt;div className="app"&amp;gt;
      &amp;lt;SuccessNotification title="Success!" message="Operation completed successfully." /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code, we have the AbstractNotification component that serves as the abstract component. It receives title and message props and defines an abstract method called renderDataContent. The renderDataContentmethod throws an error, indicating that child components must override it.&lt;/p&gt;

&lt;p&gt;In the SuccessNotification component, we define the renderDataContentmethod specific to the success notification. Here, we return a p tag element with a CSS class for styling.&lt;/p&gt;

&lt;p&gt;In the App component, we import and render the SuccessNotification component. We pass the title and message props specific to the success notification.&lt;/p&gt;

&lt;p&gt;By following this pattern, you can easily create additional child components, such as ErrorNotification or WarningNotification, that extend the abstract component and provide their own implementation of the renderDataContentmethod.&lt;/p&gt;

&lt;p&gt;This approach helps remove redundancy and code smells by centralizing common functionality in the abstract component while allowing child components to focus on their specific rendering and behavior.&lt;/p&gt;

&lt;p&gt;Remember to apply appropriate error handling and validation in the abstract component to ensure that child components correctly implement the required abstract methods.&lt;/p&gt;

&lt;h4&gt;
  
  
  This one is the easy one to demo the React ADP pattern.Lets see other more realistic demo
&lt;/h4&gt;

&lt;p&gt;Let’s continue to see it for a finance app that focuses on managing personal finances using the abstract method pattern in React.&lt;/p&gt;

&lt;p&gt;First, let’s create the abstract component for a financial transaction:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// AbstractTransaction.js
import React from 'react';

const AbstractTransaction = ({ transaction }) =&amp;gt; {
  const formatAmount = () =&amp;gt; {
    throw new Error('Child component must override the formatAmount method.');
  };

  return (
    &amp;lt;div className="transaction"&amp;gt;
      &amp;lt;h3&amp;gt;{transaction.description}&amp;lt;/h3&amp;gt;
      &amp;lt;p&amp;gt;Amount: {formatAmount()}&amp;lt;/p&amp;gt;
      &amp;lt;p&amp;gt;Date: {transaction.date}&amp;lt;/p&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default AbstractTransaction;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code, we have the AbstractTransaction component as our abstract component. It receives a transaction prop and defines an abstract method called formatAmount. The formatAmount method throws an error, indicating that child components must override it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now, let’s create a child component that extends the abstract component for an expense transaction:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// ExpenseTransaction.js
import React from 'react';
import AbstractTransaction from './AbstractTransaction';

const ExpenseTransaction = ({ transaction }) =&amp;gt; {
  const formatAmount = () =&amp;gt; {
    // Display the expense amount with a negative sign
    return `- $${transaction.amount}`;
  };

  return &amp;lt;AbstractTransaction transaction={transaction} formatAmount={formatAmount} /&amp;gt;;
};

export default ExpenseTransaction;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the ExpenseTransaction component, we provide the implementation for the formatAmount method specific to an expense transaction. Here, we display the expense amount with a negative sign.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Next, let’s create a child component that extends the abstract component for an income transaction:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// IncomeTransaction.js
import React from 'react';
import AbstractTransaction from './AbstractTransaction';

const IncomeTransaction = ({ transaction }) =&amp;gt; {
  const formatAmount = () =&amp;gt; {
    // Display the income amount with a positive sign
    return `+ $${transaction.amount}`;
  };

  return &amp;lt;AbstractTransaction transaction={transaction} formatAmount={formatAmount} /&amp;gt;;
};

export default IncomeTransaction;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the IncomeTransaction component, we provide the implementation for the formatAmount method specific to an income transaction. Here, we display the income amount with a positive sign.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now, let’s create a child component that extends the abstract component for a transfer transaction:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// TransferTransaction.js
import React from 'react';
import AbstractTransaction from './AbstractTransaction';

const TransferTransaction = ({ transaction }) =&amp;gt; {
  const formatAmount = () =&amp;gt; {
    // Display the transfer amount without any sign
    return `$${transaction.amount}`;
  };

  return &amp;lt;AbstractTransaction transaction={transaction} formatAmount={formatAmount} /&amp;gt;;
};

export default TransferTransaction;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the TransferTransaction component, we provide the implementation for the formatAmount method specific to a transfer transaction. Here, we display the transfer amount without any sign.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now, let’s use these components in our financial app:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// FinancialApp.js
// FinancialApp.js
import React from 'react';
import AbstractTransaction from './AbstractTransaction';
import ExpenseTransaction from './ExpenseTransaction';
import IncomeTransaction from './IncomeTransaction';
import TransferTransaction from './TransferTransaction';

const FinancialApp = () =&amp;gt; {
  const transactions = [
    { description: 'Groceries', amount: 50, date: '2023-05-01' },
    { description: 'Salary', amount: 2000, date: '2023-05-15' },
    { description: 'Transfer to Savings', amount: 500, date: '2023-05-10' },
  ];

  return (
    &amp;lt;div className="financial-app"&amp;gt;
      &amp;lt;h2&amp;gt;Transactions&amp;lt;/h2&amp;gt;
      {transactions.map((transaction, index) =&amp;gt; (
        &amp;lt;div key={index}&amp;gt;
          &amp;lt;ExpenseTransaction transaction={transaction} /&amp;gt;
          &amp;lt;IncomeTransaction transaction={transaction} /&amp;gt;
          &amp;lt;TransferTransaction transaction={transaction} /&amp;gt;
        &amp;lt;/div&amp;gt;
      ))}
    &amp;lt;/div&amp;gt;
  );
};

export default FinancialApp;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the updated FinancialApp component, we have added a transfer transaction to the transactions array. We now render the TransferTransaction component alongside the ExpenseTransaction and IncomeTransaction components for each transaction.&lt;/p&gt;

&lt;p&gt;By extending the abstract component and overriding the formatAmount method, we can handle different types of financial transactions with their specific formatting requirements. This approach helps remove code redundancy and promotes code reuse and maintainability.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In a real-world financial app&lt;/strong&gt; , you can further extend the child components to include additional functionality or customize the rendering based on specific transaction types. &lt;strong&gt;The abstract method pattern&lt;/strong&gt; provides a flexible and scalable approach to handle diverse financial transactions while keeping the core logic centralized in the abstract component.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;This pattern helps remove redundant code and promotes code reuse and maintainability in our financial app.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To improve performance in rendering the transactions in our financial app, we can make use of &lt;strong&gt;React’s memoization technique&lt;/strong&gt; and optimize the child components.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let’s modify the child components&lt;/strong&gt; (ExpenseTransaction, IncomeTransaction, and TransferTransaction) to leverage React's React.memo to memoize the components and prevent unnecessary re-renders:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// ExpenseTransaction.js
import React from 'react';
import AbstractTransaction from './AbstractTransaction';

const ExpenseTransaction = React.memo(({ transaction }) =&amp;gt; {
  const formatAmount = () =&amp;gt; {
    // Display the expense amount with a negative sign
    return `- $${transaction.amount}`;
  };

  return &amp;lt;AbstractTransaction transaction={transaction} formatAmount={formatAmount} /&amp;gt;;
});

export default ExpenseTransaction;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Similarly, update the&lt;/strong&gt;  &lt;strong&gt;IncomeTransaction and&lt;/strong&gt;  &lt;strong&gt;TransferTransaction components with&lt;/strong&gt;  &lt;strong&gt;React.memo:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// IncomeTransaction.js
import React from 'react';
import AbstractTransaction from './AbstractTransaction';

const IncomeTransaction = React.memo(({ transaction }) =&amp;gt; {
  const formatAmount = () =&amp;gt; {
    // Display the income amount with a positive sign
    return `+ $${transaction.amount}`;
  };

  return &amp;lt;AbstractTransaction transaction={transaction} formatAmount={formatAmount} /&amp;gt;;
});

export default IncomeTransaction;

-------------------------------------------------------------------------

// TransferTransaction.js
import React from 'react';
import AbstractTransaction from './AbstractTransaction';

const TransferTransaction = React.memo(({ transaction }) =&amp;gt; {
  const formatAmount = () =&amp;gt; {
    // Display the transfer amount without any sign
    return `$${transaction.amount}`;
  };

  return &amp;lt;AbstractTransaction transaction={transaction} formatAmount={formatAmount} /&amp;gt;;
});

export default TransferTransaction;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;By memoizing the child components using&lt;/strong&gt;  &lt;strong&gt;React.memo&lt;/strong&gt; , we ensure that the components are only re-rendered if their props (transaction in this case) have changed. This optimization can significantly improve the performance of the financial app, especially when dealing with a large number of transactions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Additionally, you can further optimize the financial app by implementing a key prop when rendering the child components&lt;/strong&gt;. The key prop should be a unique identifier associated with each transaction to help React efficiently update and re-render the components when necessary.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{transactions.map((transaction, index) =&amp;gt; (
  &amp;lt;div key={transaction.id}&amp;gt;
    &amp;lt;ExpenseTransaction transaction={transaction} /&amp;gt;
    &amp;lt;IncomeTransaction transaction={transaction} /&amp;gt;
    &amp;lt;TransferTransaction transaction={transaction} /&amp;gt;
  &amp;lt;/div&amp;gt;
))}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;By providing a unique key for each transaction,&lt;/strong&gt; React can perform more efficient updates and prevent unnecessary re-renders of the child components.&lt;/p&gt;

&lt;p&gt;These performance optimizations help ensure that the financial app runs smoothly and efficiently, even when dealing with a large number of transactions &lt;strong&gt;. By memoizing the components&lt;/strong&gt; and &lt;strong&gt;providing proper keys,&lt;/strong&gt; we can minimize unnecessary re-renders and improve the overall performance of the app.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Let’s further improve the code to make it more generic and performant.&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;We’ll refactor the child components (ExpenseTransaction, IncomeTransaction, and TransferTransaction) to eliminate code redundancy and improve performance by avoiding unnecessary re-renders.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First, let’s create a single optimized component called&lt;/strong&gt;  &lt;strong&gt;TransactionItem that handles all transaction types:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// TransactionItem.js
import React from 'react';
import AbstractTransaction from './AbstractTransaction';

const TransactionItem = React.memo(({ transaction, formatAmount }) =&amp;gt; {
  return &amp;lt;AbstractTransaction transaction={transaction} formatAmount={formatAmount} /&amp;gt;;
});

export default TransactionItem;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The TransactionItem component accepts the transaction object and the formatAmount function as props, which will be specific to each transaction type.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Next, we can create a higher-order component (HOC) called&lt;/strong&gt;  &lt;strong&gt;withTransactionType that takes in a transaction type and returns a memoized component with the appropriate&lt;/strong&gt;  &lt;strong&gt;formatAmount function:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// withTransactionType.js
import React from 'react';

const withTransactionType = (transactionType, formatAmount) =&amp;gt; {
  const TransactionComponent = React.memo(({ transaction }) =&amp;gt; {
    return &amp;lt;TransactionItem transaction={transaction} formatAmount={formatAmount} /&amp;gt;;
  });

  return TransactionComponent;
};

export default withTransactionType;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Now, we can create specific transaction components using the&lt;/strong&gt;  &lt;strong&gt;withTransactionType HOC. For example, let's create the&lt;/strong&gt;  &lt;strong&gt;ExpenseTransaction component:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// ExpenseTransaction.js
import React from 'react';
import withTransactionType from './withTransactionType';

const formatExpenseAmount = (amount) =&amp;gt; `- $${amount}`;

const ExpenseTransaction = withTransactionType('expense', formatExpenseAmount);

export default ExpenseTransaction;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Similarly, create the&lt;/strong&gt;  &lt;strong&gt;IncomeTransaction and&lt;/strong&gt;  &lt;strong&gt;TransferTransaction components:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// IncomeTransaction.js
import React from 'react';
import withTransactionType from './withTransactionType';

const formatIncomeAmount = (amount) =&amp;gt; `+ $${amount}`;

const IncomeTransaction = withTransactionType('income', formatIncomeAmount);

export default IncomeTransaction;

----------------------------------------------------------------------

// TransferTransaction.js
import React from 'react';
import withTransactionType from './withTransactionType';

const formatTransferAmount = (amount) =&amp;gt; `$${amount}`;

const TransferTransaction = withTransactionType('transfer', formatTransferAmount);

export default TransferTransaction;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Now, we can use these components in our financial app:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// FinancialApp.js
import React from 'react';
import TransactionItem from './TransactionItem';

const FinancialApp = () =&amp;gt; {
  const transactions = [
    { type: 'expense', description: 'Groceries', amount: 50, date: '2023-05-01' },
    { type: 'income', description: 'Salary', amount: 2000, date: '2023-05-15' },
    { type: 'transfer', description: 'Transfer to Savings', amount: 500, date: '2023-05-10' },
  ];

  return (
    &amp;lt;div className="financial-app"&amp;gt;
      &amp;lt;h2&amp;gt;Transactions&amp;lt;/h2&amp;gt;
      {transactions.map((transaction, index) =&amp;gt; {
        const { type, ...rest } = transaction;
        return (
          &amp;lt;div key={index}&amp;gt;
            &amp;lt;TransactionItem transaction={rest} formatAmount={getFormatAmount(type)} /&amp;gt;
          &amp;lt;/div&amp;gt;
        );
      })}
    &amp;lt;/div&amp;gt;
  );
};

const getFormatAmount = (type) =&amp;gt; {
  // Define the formatAmount function based on transaction type
  switch (type) {
    case 'expense':
      return (amount) =&amp;gt; `- $${amount}`;
    case 'income':
      return (amount) =&amp;gt; `+ $${amount}`;
    case 'transfer':
      return (amount) =&amp;gt; `$${amount}`;
    default:
      return null;
  }
};

export default FinancialApp;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code, we define the getFormatAmount function, which takes in the transaction type and returns the appropriate formatAmount function based on the type.&lt;/p&gt;

&lt;p&gt;Now, when rendering the transactions, we pass the transaction data (rest) and the corresponding formatAmount function to the TransactionItem component.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;By organizing the code in this manner, we achieve a more generic and performant solution&lt;/em&gt;&lt;/strong&gt;. The TransactionItem component handles the common logic for rendering transactions, while the specific formatAmount functions are provided dynamically based on the transaction type.&lt;/p&gt;

&lt;p&gt;This approach eliminates &lt;strong&gt;code redundancy&lt;/strong&gt; , reduces the number of components, and improves performance by leveraging &lt;strong&gt;memoization&lt;/strong&gt; and &lt;strong&gt;avoiding unnecessary re-renders&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Additionally, by using a key prop when rendering the TransactionItem component, &lt;strong&gt;we enable efficient updates and re-renders:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div key={index}&amp;gt;
  &amp;lt;TransactionItem transaction={rest} formatAmount={getFormatAmount(type)} /&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Providing a unique key&lt;/strong&gt; for each transaction helps React accurately track and update only the necessary components, further optimizing performance.&lt;/p&gt;

&lt;p&gt;With these improvements, the financial app can efficiently manage and render various types of transactions while maintaining code cleanliness, reusability, and performance.&lt;/p&gt;

&lt;p&gt;It’s important to profile and analyze the performance of your application using tools like React DevTools, Chrome DevTools, or other performance monitoring tools. By identifying and addressing specific performance bottlenecks, you can optimize the code and improve the overall performance of your financial app.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;In the provided code, there are a few potential areas where performance issues could arise&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;let see what are they and how to avoid it in the next upcoming article. Here is the link &lt;a href="https://vivekdogra02.medium.com/react-abstract-design-pattern-dry-single-shared-responsibility-9fbef42a6e56"&gt;https://vivekdogra02.medium.com/react-abstract-design-pattern-dry-single-shared-responsibility-9fbef42a6e56&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, stay tuned guys.&lt;/p&gt;

&lt;p&gt;Hope you liked it,&lt;/p&gt;

&lt;p&gt;Start incorporating the Abstract Design pattern into your React projects and experience the benefits firsthand. Happy coding!&lt;/p&gt;

&lt;h3&gt;
  
  
  Thanks for reading
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;👏 Please clap for the story and follow me 👉&lt;/li&gt;
&lt;li&gt;📰 &lt;a href="https://medium.com/@vivekdogra02"&gt;View more content&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;🔔 Follow me: &lt;a href="https://www.linkedin.com/in/vivek-dogra-7404a530/"&gt;LinkedIn&lt;/a&gt;| &lt;a href="https://twitter.com/VivekDo07905087"&gt;Twitter&lt;/a&gt;| &lt;a href="https://github.com/vivekdogra02"&gt;Github&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




</description>
      <category>design</category>
      <category>webdev</category>
      <category>webdesign</category>
      <category>javascript</category>
    </item>
    <item>
      <title>The Power of Web Components in Frontend Development with Angular</title>
      <dc:creator>V.D</dc:creator>
      <pubDate>Sat, 13 May 2023 03:21:58 +0000</pubDate>
      <link>https://dev.to/vivekdogra02/the-power-of-web-components-in-frontend-development-with-angular-2ccl</link>
      <guid>https://dev.to/vivekdogra02/the-power-of-web-components-in-frontend-development-with-angular-2ccl</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eia6jhR0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/1%2ALUy2rIMbUbhPagvfO0JAcA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eia6jhR0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/1%2ALUy2rIMbUbhPagvfO0JAcA.png" alt="img1" width="800" height="534"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Introduction:
&lt;/h3&gt;

&lt;p&gt;In today’s fast-paced web development landscape, creating reusable and modular UI components is crucial for building scalable and maintainable applications. One technology that has gained significant popularity in achieving this goal is &lt;strong&gt;Web Components&lt;/strong&gt;. In this article, we will explore the power of Web Components in frontend development using Angular. We will dive into the key concepts of Web Components, demonstrate their usage within an Angular application, and provide code examples to showcase their benefits.&lt;/p&gt;

&lt;h3&gt;
  
  
  Table of Contents:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Understanding Web Components&lt;/li&gt;
&lt;li&gt;Benefits of Web Components in Angular&lt;/li&gt;
&lt;li&gt;Creating a Web Component in Angular&lt;/li&gt;
&lt;li&gt;Using Web Components in Angular Applications&lt;/li&gt;
&lt;li&gt;Styling Web Components in Angular&lt;/li&gt;
&lt;li&gt;Communication between Web Components and Angular&lt;/li&gt;
&lt;li&gt;Lifecycle Hooks and Events in Web Components&lt;/li&gt;
&lt;li&gt;Testing Web Components in Angular&lt;/li&gt;
&lt;li&gt;Performance Considerations&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  1. Understanding Web Components
&lt;/h3&gt;

&lt;p&gt;Web Components are a set of web platform APIs that allow developers to create reusable and encapsulated UI components. They consist of three main technologies: &lt;strong&gt;Custom Elements,&lt;/strong&gt;  &lt;strong&gt;Shadow DOM, and HTML Templates.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Custom Elements&lt;/strong&gt; enable the creation of new HTML tags with custom behaviors,&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Shadow DOM&lt;/strong&gt; provides encapsulation and scoping of styles and markup.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HTML Templates&lt;/strong&gt; allow developers to define reusable markup structures that can be cloned and inserted into the DOM.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Benefits of Web Components in Angular
&lt;/h3&gt;

&lt;p&gt;Integrating Web Components into Angular applications brings several benefits.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Firstly, Web Components&lt;/strong&gt; promote reusability by allowing developers to create self-contained and independent UI components. These components can be easily shared and used across different Angular projects.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Secondly, Web Components&lt;/strong&gt; enable better collaboration between frontend and backend teams, as they provide a clear separation of concerns. Frontend developers can focus on building UI components, while backend developers can provide the necessary data and APIs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lastly, Web Components&lt;/strong&gt; are framework-agnostic, meaning they can be used with Angular or any other frontend framework.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Creating a Web Component in Angular
&lt;/h3&gt;

&lt;p&gt;To create a Web Component in Angular, we can leverage the &lt;strong&gt;Angular Elements package&lt;/strong&gt;. Angular Elements allows us to package an Angular component as a Web Component, which can be used in any HTML page or framework. We define the component using the @Component() decorator, specifying the necessary properties and methods.&lt;/p&gt;

&lt;p&gt;We then use the createCustomElement() function from the @angular/elements package to convert the Angular component into a Web Component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Component, Input, OnInit } from '@angular/core';
import { createCustomElement } from '@angular/elements';

@Component({
  selector: 'app-custom-component',
  template: `
    &amp;lt;div&amp;gt;
      &amp;lt;h2&amp;gt;{{ title }}&amp;lt;/h2&amp;gt;
      &amp;lt;p&amp;gt;{{ content }}&amp;lt;/p&amp;gt;
    &amp;lt;/div&amp;gt;
  `,
})
export class CustomComponent implements OnInit {
  @Input() title: string;
  @Input() content: string;

  ngOnInit() {
    // Component initialization logic
  }
}

const customElement = createCustomElement(CustomComponent, { injector: this.injector });
customElements.define('app-custom-component', customElement);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;4. Using Web Components in Angular Applications&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Once the Web Component is created, it can be used in Angular applications like any other HTML element. We can include the Web Component in an Angular template by referencing the custom element tag. We can pass data to the Web Component using attributes or properties.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;app-custom-component title="Hello" content="Welcome to the Web Component"&amp;gt;&amp;lt;/app-custom-component&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;5. Styling Web Components in Angular&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Styling Web Components in Angular is similar to styling regular Angular components. We can use CSS styles within the component’s template or define them in an external stylesheet. The styles defined within the component are scoped to the component, ensuring that they do not affect other components or styles on the page.&lt;/p&gt;

&lt;p&gt;Angular’s component-based architecture allows for modular and encapsulated styling, enhancing the reusability of Web Components.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Component({
  selector: 'app-custom-component',
  template: `
    &amp;lt;div class="custom-component"&amp;gt;
      &amp;lt;h2&amp;gt;{{ title }}&amp;lt;/h2&amp;gt;
      &amp;lt;p&amp;gt;{{ content }}&amp;lt;/p&amp;gt;
    &amp;lt;/div&amp;gt;
  `,
  styleUrls: ['./custom-component.component.css']
})
export class CustomComponent implements OnInit {
  @Input() title: string;
  @Input() content: string;

  ngOnInit() {
    // Component initialization logic
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  6. Communication between Web Components and Angular
&lt;/h3&gt;

&lt;p&gt;Web Components can communicate with the surrounding Angular application through attributes, properties, events, and methods. Attributes and properties allow for data passing from the Angular application to the Web Component, while events enable the Web Component to notify the Angular application of certain actions or state changes. Methods provide an interface for the Angular application to interact with the behavior of the Web Component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Component({
  selector: 'app-parent-component',
  template: `
    &amp;lt;app-custom-component [title]="componentTitle" (customEvent)="handleCustomEvent($event)"&amp;gt;&amp;lt;/app-custom-component&amp;gt;
  `
})
export class ParentComponent {
  componentTitle = 'Hello Web Component';

  handleCustomEvent(event: CustomEvent) {
    // Handle custom event emitted by the Web Component
  }
}

export class CustomComponent {
  @Input() title: string;
  @Output() customEvent = new EventEmitter&amp;lt;string&amp;gt;();

  handleClick() {
    // Emit a custom event
    this.customEvent.emit('Custom event emitted!');
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  7. Lifecycle Hooks and Events in Web Components
&lt;/h3&gt;

&lt;p&gt;Web Components in Angular can leverage Angular’s lifecycle hooks, such as ngOnInit, ngOnChanges, and ngOnDestroy. These hooks allow for additional initialization, state updates, and cleanup operations within the Web Component. Additionally, Web Components can define and emit custom events to communicate with the outside world.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export class CustomComponent implements OnInit, OnChanges, OnDestroy {
  // ...

  ngOnInit() {
    // Perform initialization logic
  }

  ngOnChanges(changes: SimpleChanges) {
    // React to input property changes
  }

  ngOnDestroy() {
    // Cleanup operations
  }

  handleClick() {
    // Emit a custom event
    this.dispatchEvent(new CustomEvent('customEvent', { detail: 'Custom event emitted!' }));
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  8. Testing Web Components in Angular
&lt;/h3&gt;

&lt;p&gt;Angular provides a rich testing environment for Web Components. We can write unit tests using tools like Jasmine and Karma to verify the behavior of the Web Component. Additionally, Angular’s testing utilities allow for integration testing, where we can test the interaction between the Web Component and the Angular application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;describe('CustomComponent', () =&amp;gt; {
  let component: CustomComponent;
  let fixture: ComponentFixture&amp;lt;CustomComponent&amp;gt;;

  beforeEach(async () =&amp;gt; {
    await TestBed.configureTestingModule({
      declarations: [CustomComponent]
    }).compileComponents();
  });

  beforeEach(() =&amp;gt; {
    fixture = TestBed.createComponent(CustomComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should create', () =&amp;gt; {
    expect(component).toBeTruthy();
  });

  it('should display the title and content', () =&amp;gt; {
    component.title = 'Test Title';
    component.content = 'Test Content';
    fixture.detectChanges();
    const element = fixture.nativeElement as HTMLElement;
    expect(element.querySelector('h2').textContent).toBe('Test Title');
    expect(element.querySelector('p').textContent).toBe('Test Content');
  });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  9. Performance Considerations
&lt;/h3&gt;

&lt;p&gt;While Web Components offer powerful features for frontend development, it’s important to consider their impact on performance. Here are some considerations to keep in mind:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Minimize the Shadow DOM:&lt;/strong&gt; The Shadow DOM can introduce a performance overhead, especially when it contains complex DOM structures. To optimize performance, strive to keep the Shadow DOM tree as minimal and shallow as possible.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Efficient Data Binding:&lt;/strong&gt; Angular provides powerful data binding capabilities. However, excessive data binding can lead to performance degradation. Be mindful of the number of data bindings within your Web Components and consider using one-time or unidirectional data binding where appropriate.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lazy Loading&lt;/strong&gt; : If your application utilizes a large number of Web Components, consider implementing lazy loading techniques. Load only the necessary components initially and dynamically load additional components as needed. This can significantly improve the initial loading time and resource consumption.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Code Optimization:&lt;/strong&gt; Ensure that your Web Components are well-optimized by following best practices for code structure, size, and performance. Minify and bundle your component code to reduce file sizes and leverage caching techniques for faster subsequent loads.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Browser Compatibility:&lt;/strong&gt; While Web Components are supported in most modern browsers, it’s essential to consider browser compatibility, especially for older versions. Use feature detection or polyfills to ensure consistent behavior across different browsers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Performance Testing:&lt;/strong&gt; Regularly conduct performance tests to identify bottlenecks and optimize the rendering and execution of your Web Components. Measure metrics such as load time, rendering time, and CPU usage to assess the impact of your components on overall application performance.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  10. Conclusion
&lt;/h3&gt;

&lt;p&gt;Web Components bring immense power and flexibility to frontend development, enabling the creation of reusable and encapsulated UI components. In this article, we explored the integration of Web Components within Angular applications, leveraging Angular’s features and tools.&lt;/p&gt;

&lt;p&gt;We learned &lt;strong&gt;how to create Web Components using Angular Elements&lt;/strong&gt; , &lt;strong&gt;style them using scoped CSS&lt;/strong&gt; , and &lt;strong&gt;establish communication between Web Components and Angular using attributes, properties, events, and methods&lt;/strong&gt;. Additionally, we discussed the importance of testing and performance considerations when working with Web Components.&lt;/p&gt;

&lt;p&gt;By incorporating Web Components into your Angular projects, you can unlock the benefits of reusability, maintainability, and collaboration. However, it’s crucial to balance the usage of Web Components with performance optimizations and best practices to ensure a smooth and efficient user experience.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Remember to continuously update your knowledge and stay up-to-date with the latest advancements in Web Components and Angular. &lt;em&gt;Experiment, iterate, and leverage the power of Web Components&lt;/em&gt; to build modern and performant frontend applications.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Thank you for reading this article. If you found it helpful, please consider sharing it with others who might benefit from it. Happy coding!&lt;/p&gt;

&lt;h3&gt;
  
  
  Thanks for reading
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;👏 Please clap for the story and follow me 👉&lt;/li&gt;
&lt;li&gt;📰 &lt;a href="https://medium.com/@vivekdogra02"&gt;View more content&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;🔔 Follow me: &lt;a href="https://www.linkedin.com/in/vivek-dogra-7404a530/"&gt;LinkedIn&lt;/a&gt;| &lt;a href="https://twitter.com/VivekDo07905087"&gt;Twitter&lt;/a&gt;| &lt;a href="https://github.com/vivekdogra02"&gt;Github&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>angular</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Angular — The Builder Pattern -Building Better Objects with TypeScript</title>
      <dc:creator>V.D</dc:creator>
      <pubDate>Sat, 13 May 2023 03:11:18 +0000</pubDate>
      <link>https://dev.to/vivekdogra02/angular-the-builder-pattern-building-better-objects-with-typescript-1bed</link>
      <guid>https://dev.to/vivekdogra02/angular-the-builder-pattern-building-better-objects-with-typescript-1bed</guid>
      <description>&lt;h3&gt;
  
  
  Angular — The Builder Pattern -Building Better Objects with TypeScript
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Iu4xfPdk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/1%2A049aoL54wQaJYiQsubtAug.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Iu4xfPdk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/1%2A049aoL54wQaJYiQsubtAug.jpeg" alt="img1" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Introduction:
&lt;/h3&gt;

&lt;p&gt;In software development, creating complex objects with multiple optional parameters can lead to bloated constructors and maintenance challenges. The Builder pattern provides an elegant solution to build objects step by step, enabling flexible configuration and reducing code duplication. In this article, we’ll explore how to implement the Builder pattern in Angular with TypeScript, examine its benefits in terms of performance, code cleanliness, and demonstrate real-world use cases.&lt;/p&gt;

&lt;h3&gt;
  
  
  Overview of the Builder Pattern:
&lt;/h3&gt;

&lt;p&gt;The Builder pattern is a creational design pattern that allows the construction of complex objects by separating the construction process from the object representation. It provides a fluent and step-by-step approach to building objects, making the code more readable and maintainable.&lt;/p&gt;

&lt;h3&gt;
  
  
  Implementation:
&lt;/h3&gt;

&lt;p&gt;To implement the Builder pattern in Angular with TypeScript, we’ll follow these steps:&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 1: Define the Product Class
&lt;/h4&gt;

&lt;p&gt;First, let’s define the class representing the complex object we want to build. This class should have multiple properties and optional parameters.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Product {
  property1: string;
  property2: number;
  property3: boolean;

  constructor(builder: ProductBuilder) {
    this.property1 = builder.property1;
    this.property2 = builder.property2;
    this.property3 = builder.property3;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2: Create the Builder Class
&lt;/h3&gt;

&lt;p&gt;Next, we create a Builder class that provides methods to set the optional parameters of the Product class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class ProductBuilder {
  property1: string;
  property2: number;
  property3: boolean;

  setProperty1(value: string): ProductBuilder {
    this.property1 = value;
    return this;
  }

  setProperty2(value: number): ProductBuilder {
    this.property2 = value;
    return this;
  }

  setProperty3(value: boolean): ProductBuilder {
    this.property3 = value;
    return this;
  }

  build(): Product {
    return new Product(this);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 3: Use the Builder to Construct the Object
&lt;/h3&gt;

&lt;p&gt;Now, we can use the Builder to construct the object step by step, setting the desired properties.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const product = new ProductBuilder()
  .setProperty1('Value 1')
  .setProperty2(42)
  .setProperty3(true)
  .build();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Benefits of the Builder Pattern:
&lt;/h3&gt;

&lt;p&gt;The Builder pattern offers several benefits in Angular development:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Improved Readability and Maintainability:&lt;/strong&gt; By separating the object construction logic from the complex object itself, the Builder pattern improves code readability and maintainability. It provides a fluent interface that clearly indicates the steps involved in building the object.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Flexible Configuration:&lt;/strong&gt; The Builder pattern allows the optional parameters of the complex object to be set in any order or skipped entirely. This flexibility enables developers to configure objects based on specific use cases without cluttering the constructor with numerous parameters.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Avoidance of Telescoping Constructors:&lt;/strong&gt; Telescoping constructors occur when a class has multiple constructors with different combinations of parameters. The Builder pattern avoids this issue by providing a single constructor and using method chaining to set optional parameters.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Performance Improvement:&lt;/strong&gt; In scenarios where objects are frequently created with similar configurations, using the Builder pattern can improve performance. Instead of recreating the entire object each time, only the necessary properties are modified, reducing redundant code execution.&lt;/p&gt;

&lt;h3&gt;
  
  
  Real-World Use Case:
&lt;/h3&gt;

&lt;p&gt;One common use case for the Builder pattern in Angular is form building. In Angular, reactive forms can benefit from the Builder pattern. Let’s consider a scenario where we need to build a dynamic form with multiple fields, validators, and nested structures. Here’s an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';

@Component({
  selector: 'app-my-form',
  template: `
    &amp;lt;form [formGroup]="myForm" (submit)="onSubmit()"&amp;gt;
      &amp;lt;input formControlName="name" placeholder="Name"&amp;gt;
      &amp;lt;input formControlName="email" placeholder="Email"&amp;gt;
      &amp;lt;!-- More fields --&amp;gt;

      &amp;lt;button type="submit"&amp;gt;Submit&amp;lt;/button&amp;gt;
    &amp;lt;/form&amp;gt;
  `
})
export class MyFormComponent implements OnInit {
  myForm: FormGroup;

  constructor(private formBuilder: FormBuilder) {}

  ngOnInit() {
    this.myForm = this.formBuilder.group({
      name: ['', Validators.required],
      email: ['', [Validators.required, Validators.email]],
      // More fields
    });
  }

  onSubmit() {
    if (this.myForm.valid) {
      console.log('Form submitted!', this.myForm.value);
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, the FormBuilder acts as a Builder to construct the form. We use the formBuilder.group method to create a FormGroup with various form controls and validators. This approach allows us to define complex forms with clean and readable code.&lt;/p&gt;

&lt;h3&gt;
  
  
  Further Use Cases and Considerations:
&lt;/h3&gt;

&lt;p&gt;While the Builder pattern is beneficial in various scenarios, here are a few additional use cases where it can provide significant advantages:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. API Requests:&lt;/strong&gt; When making API requests, you often need to construct complex payloads with optional parameters, headers, or authentication tokens. The Builder pattern can simplify the construction of these requests and provide a clean and readable way to configure different aspects of the request.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Object Initialization:&lt;/strong&gt; In situations where you have objects with multiple properties and configurations, the Builder pattern can be used for their initialization. By using a Builder, you can ensure that the object is constructed correctly, enforce certain rules or validations, and make the initialization process more maintainable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Configuration Objects:&lt;/strong&gt; If you have configuration objects with numerous optional properties, the Builder pattern can help create these objects in a flexible manner. It allows you to specify the desired configurations explicitly, reducing the chance of missing or incorrectly setting properties.&lt;/p&gt;

&lt;h3&gt;
  
  
  Considerations:
&lt;/h3&gt;

&lt;p&gt;While the Builder pattern brings many benefits, it’s essential to consider the following points:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Complexity vs. Simplicity:&lt;/strong&gt; For simple objects with just a few properties, using the Builder pattern might add unnecessary complexity. Evaluate whether the object’s complexity justifies the use of a Builder or if simpler approaches, such as direct object instantiation, are more appropriate.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Code Duplication:&lt;/strong&gt; Be cautious not to introduce code duplication when implementing the Builder pattern. If multiple objects require similar construction logic, consider creating a base Builder class or using inheritance to share common functionality.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Trade-off with Immutability:&lt;/strong&gt; The Builder pattern often involves mutable objects, as properties are set incrementally. If immutability is a critical requirement for your objects, you might need to adapt the Builder implementation accordingly, such as by cloning the object at each step.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion:
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;The Builder pattern&lt;/strong&gt; is a powerful tool in Angular and TypeScript, providing a flexible and readable way to construct complex objects. It enhances code maintainability, improves performance by reducing redundant code execution, and offers a structured approach to configure objects. By leveraging the Builder pattern in appropriate scenarios, developers can create more scalable, modular, and maintainable Angular applications.&lt;/p&gt;

&lt;p&gt;In this article, we explored &lt;strong&gt;the concept of the Builder pattern&lt;/strong&gt; , its implementation in Angular with TypeScript, and showcased its benefits and use cases. By understanding and applying this pattern effectively, developers can write cleaner, more efficient code and overcome challenges related to object construction and configuration.&lt;/p&gt;

&lt;p&gt;Start incorporating the Builder pattern into your Angular projects and experience the benefits firsthand. Happy coding!&lt;/p&gt;

&lt;h3&gt;
  
  
  Thanks for reading
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;👏 Please clap for the story and follow me 👉&lt;/li&gt;
&lt;li&gt;📰 &lt;a href="https://medium.com/@vivekdogra02"&gt;View more content&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;🔔 Follow me: &lt;a href="https://www.linkedin.com/in/vivek-dogra-7404a530/"&gt;LinkedIn&lt;/a&gt;| &lt;a href="https://twitter.com/VivekDo07905087"&gt;Twitter&lt;/a&gt;| &lt;a href="https://github.com/vivekdogra02"&gt;Github&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




</description>
      <category>typescript</category>
      <category>javascript</category>
      <category>angular</category>
      <category>webdesign</category>
    </item>
    <item>
      <title>Custom Implementation or Polyfills for Array Methods in JavaScript</title>
      <dc:creator>V.D</dc:creator>
      <pubDate>Wed, 10 May 2023 12:33:49 +0000</pubDate>
      <link>https://dev.to/vivekdogra02/custom-implementation-or-polyfills-for-array-methods-in-javascript-45b0</link>
      <guid>https://dev.to/vivekdogra02/custom-implementation-or-polyfills-for-array-methods-in-javascript-45b0</guid>
      <description>&lt;h4&gt;
  
  
  Part 1: Custom Implementation of map(), reduce(), and filter() methods in JavaScript.
&lt;/h4&gt;

&lt;h3&gt;
  
  
  Polyfills in JavaScript
&lt;/h3&gt;

&lt;p&gt;Hi guys, today I am going to show you the implementation or we call it the Polyfills (custom implementation) of the 3 widely-used and famous array methods.&lt;/p&gt;

&lt;p&gt;This is something that an interviewer can ask you to write about the behind-the-scenes implementation of these methods (map, reduce, filter). These functions are written every time for a new copy of an array so it won't mutate your actual array.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oEQoF2EX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/0%2AdlRGbsFkjToRXhrT" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oEQoF2EX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/0%2AdlRGbsFkjToRXhrT" alt="image1" width="800" height="1200"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Photo by AltumCode on Unsplash&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  1. map()
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;map() is a method that accepts a callback function that executes for every element of the array. In simpler terms, it is used for manipulating/transforming the elements present inside that array.&lt;/li&gt;
&lt;li&gt;It returns a new array (which means it won't mutate or change your actual array).&lt;/li&gt;
&lt;li&gt;The array coming out of the map is a transformed array which may or may not be identical to the actual array.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Custom implementation
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pD9yfJ01--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/952/1%2ATEIyDIi7cP6k-k17R9T7Rw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pD9yfJ01--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/952/1%2ATEIyDIi7cP6k-k17R9T7Rw.png" alt="map1" width="800" height="745"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Custom map implementation&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This custom implementation of map() will return the transformed array.&lt;/p&gt;

&lt;h4&gt;
  
  
  Why do we need to attach its prototype?
&lt;/h4&gt;

&lt;p&gt;As the array is just like an object and it has some built-in methods. To override or write our custom methods and make them available to the array class, it needs to attach to the prototypal chain which will do the inheritance in JavaScript. So to make available any custom method for array or objects, you need to call your methods on its prototypal chain.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. reduce()
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;reduce() is the method that accepts a callback function called a reducer.&lt;/li&gt;
&lt;li&gt;It is called on every element of the array which accumulates to a single value at last.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The callbackFunc(reducer) contains the following arguments:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;previousValue:&lt;/strong&gt; The value which we got from the last function call. On the first call, it will return ‘ &lt;strong&gt;initialValue&lt;/strong&gt; ’ if given, otherwise, it will return the value of** arr[0].**&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;currentValue&lt;/strong&gt; : The value of the current element. On the first call, if &lt;strong&gt;initialValue&lt;/strong&gt; is given, then it returns the value of arr[0], otherwise, the value of arr[1] is returned.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;currentIndex&lt;/strong&gt; : The current index of the element. If &lt;strong&gt;initialValue&lt;/strong&gt; is given, it must be 0 otherwise it should start from index 1.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;array&lt;/strong&gt; : The array used for traversal.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Use cases:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Without initial value&lt;/li&gt;
&lt;li&gt;With initial value&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LLa9yPN4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1002/1%2Ab4t5QUbHsEK0YyQJ0Qw8Mw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LLa9yPN4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1002/1%2Ab4t5QUbHsEK0YyQJ0Qw8Mw.png" alt="reduce" width="800" height="709"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Custom implementation of Reduce()&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;3. filter()&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;filter() method accepts a callback, that executes for every item of the given array.&lt;/li&gt;
&lt;li&gt;Same as above — it returns a new array.&lt;/li&gt;
&lt;li&gt;It will return the filtered truthy value.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yJvh2XTh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/756/1%2AK7TWx7hH3wJM13R1l3Bm6A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yJvh2XTh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/756/1%2AK7TWx7hH3wJM13R1l3Bm6A.png" alt="filter" width="756" height="935"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Custom implementation of the filter() function.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This is how the custom implementation of a few array methods works and a good starting point where you can learn how JavaScript, under the hood, creates its inbuilt method implementation and how it works.&lt;/p&gt;

&lt;p&gt;You can create your own Polyfills or custom methods like this and attach it to the prototype chain to make it available to the reference or abstract class used inside the JavaScript environment.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hope you liked it, please clap, subscribe and share and also save it for future reference. :)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Thanks&lt;/em&gt;&lt;/p&gt;




</description>
      <category>arrays</category>
      <category>javascript</category>
      <category>coding</category>
      <category>learning</category>
    </item>
    <item>
      <title>Custom Implementation of JavaScript Methods</title>
      <dc:creator>V.D</dc:creator>
      <pubDate>Wed, 10 May 2023 12:32:44 +0000</pubDate>
      <link>https://dev.to/vivekdogra02/custom-implementation-of-javascript-methods-2doc</link>
      <guid>https://dev.to/vivekdogra02/custom-implementation-of-javascript-methods-2doc</guid>
      <description>&lt;h4&gt;
  
  
  Part 2: Custom implementation of shallowCompare() and deepCompare() with the typeof operator in JavaScript.
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pbQMaBcp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/396/1%2ATMswwB3rNiQyyo35hYfyzw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pbQMaBcp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/396/1%2ATMswwB3rNiQyyo35hYfyzw.png" alt="img1" width="396" height="356"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Deep/Shallow comparison with typeof operator&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Hi guys, today I am going to show you how to write the custom implementation for the shallow and deep copy with the use of the custom typeof operator.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let’s get started.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;First, we need to know what are Shallow and Deep comparisons. These terms were quite intimidating when we were asked in the interviews but once you get an understanding of the JavaScript runtime environment, their meaning becomes quite simple.&lt;/p&gt;

&lt;p&gt;Let me tell you that the comparison in JavaScript between primitive types and non-primitive types is quite confusing in some parts but if you know exactly what might be the difference between primitive and non-primitive types in JavaScript, these would be quite easy to answer and explain to anybody else.&lt;/p&gt;

&lt;h4&gt;
  
  
  What are primitive types and non-primitives types in JavaScript?
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Primitive data types are data types that are not any object and have no properties or methods attached to them.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;There are 7 primitive data types:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;string&lt;/li&gt;
&lt;li&gt;number&lt;/li&gt;
&lt;li&gt;bigint&lt;/li&gt;
&lt;li&gt;boolean&lt;/li&gt;
&lt;li&gt;undefined&lt;/li&gt;
&lt;li&gt;symbol&lt;/li&gt;
&lt;li&gt;null&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One important point related to primitive data types is all primitives are &lt;em&gt;immutable&lt;/em&gt;; that is, they cannot be altered.&lt;/p&gt;

&lt;p&gt;If you need to know more information about the primitive data types, just visit: &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Primitive"&gt;https://developer.mozilla.org/en-US/docs/Glossary/Primitive&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Non-primitive data types are known as derivatives (reference type) which means it is derived from the primitive data types only.&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Arrays&lt;/li&gt;
&lt;li&gt;Objects&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now that we have a little understanding of what primitive and reference data types are, let’s move on to the topic of deep and shallow comparison.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. shallowCompare()
&lt;/h4&gt;

&lt;p&gt;Shallow comparison is a type of comparison which checks if two values are equal. It should be checked on one level which means nested object references are not ready for comparison, only one level of comparison between primitive and non-primitive data types is allowed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9_Lj4uoy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/1%2AVWokWO1hGb2xzvObXAoKEQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9_Lj4uoy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/1%2AVWokWO1hGb2xzvObXAoKEQ.png" alt="img2" width="800" height="395"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Shallow comparison on 1st level&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This figure states that if there is a shallow comparison happening it should happen correctly at one level, not at the nested level.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QbqKXJUu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/935/1%2AogEWHhmZbJzNSl7liWrenQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QbqKXJUu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/935/1%2AogEWHhmZbJzNSl7liWrenQ.png" alt="img3" width="800" height="287"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Shallow comparison is not allowed on nested references.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Before we jump into the&lt;/em&gt; &lt;strong&gt;&lt;em&gt;custom implementation of shallow comparison&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;we need to do one more custom implementation of the&lt;/em&gt; &lt;strong&gt;&lt;em&gt;typeof Operator&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;(a built-in JavaScript method) — you can use the&lt;/em&gt; &lt;em&gt;typeof operator to find the data type of a JavaScript variable.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qcu68I19--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/632/1%2AVbNJx1lGNNknfaGsfilqGw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qcu68I19--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/632/1%2AVbNJx1lGNNknfaGsfilqGw.png" alt="img4" width="632" height="345"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Inbuilt type of operator&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;** One major drawback or pitfall which I think is in JavaScript is that it will return the type of object for all the reference types such as an array, object, date, null, etc.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3iTZiSLI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/552/1%2AN6RS5chqhCGWjhda99wVMQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3iTZiSLI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/552/1%2AN6RS5chqhCGWjhda99wVMQ.png" alt="img5" width="552" height="141"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;So if you need to know whether it is an array or an object, it won’t be possible. It always returns an object which is quite confusing but, after all, it was designed by the JavaScript guys keeping in mind that an array is treated like an object, due to its nature of dynamic typing in JavaScript.**&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;So, to achieve functionality to showcase whether it is an array or an object, or a date, we need to write our custom typeof operator.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let me show you what it looks like:&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Custom Implementation — typeof operator&lt;/em&gt;&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eplP95UH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/886/1%2AW_KDCoyVUI8st1WtEYka3A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eplP95UH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/886/1%2AW_KDCoyVUI8st1WtEYka3A.png" alt="img6" width="800" height="524"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Custom TypeOf operator&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now we get the exact type of the reference data types that we pass, whether it is an array, an object, or a date.&lt;/p&gt;

&lt;p&gt;Before making any further delay, let’s concentrate on the shallow comparison.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Custom Implementation — shallowCompare()&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DPALS2la--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/727/1%2ALvsVNAstYc0UAAZ7AyE6aA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DPALS2la--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/727/1%2ALvsVNAstYc0UAAZ7AyE6aA.png" alt="img7" width="727" height="488"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this implementation, we have used the custom typeof operator, to check whether it is an array or an object or a date, or something else. This function will do only shallow comparisons at one level, not on the nested level. Let's see an example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8WxKX1oV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/1%2ADUi8i9y51cskVgQx8iz3kQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8WxKX1oV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/1%2ADUi8i9y51cskVgQx8iz3kQ.png" alt="img8" width="800" height="535"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Examples&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2. deepCompare()
&lt;/h3&gt;

&lt;p&gt;Deep comparison is a type of comparison which checks if two values are equal it should be checked on all levels which means nested object references are ready for comparison. Deep comparison is tested on nested objects, arrays, etc.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Custom Implementation — deepCompare()&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JN5-7VXV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/896/1%2AKWa118ualbzLe8FH8lVU8Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JN5-7VXV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/896/1%2AKWa118ualbzLe8FH8lVU8Q.png" alt="img9" width="800" height="555"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Deep comparison&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;There is only one point to note is that in deep comparison, you need to do a recursive call to the same function due to comparison at the multi-level or nested level. As we have nested objects, and arrays, we need to check them on multiple levels.&lt;/p&gt;

&lt;p&gt;And also, due to recursive call, a deep comparison is comparatively slow to a shallow comparison.&lt;/p&gt;

&lt;p&gt;Let’s see the examples:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZG53CHNl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/1%2AC4Vd_uB1MMNODH99Toykig.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZG53CHNl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/1%2AC4Vd_uB1MMNODH99Toykig.png" alt="img10" width="800" height="396"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Deep comparison examples.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;So, we have learnt about the custom implementation of typeof operator, shallowCompare(), and deepCompare() functions in JavaScript and how they are being used to work and compare between primitive and non-primitive data types.&lt;/p&gt;

&lt;p&gt;In the coming parts of the custom implementation, we will see more custom implementation which will help you understand what is happening behind the scenes. Stay tuned for more!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hope you liked it, please clap, subscribe and share and also save it for future reference. :)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Thanks&lt;/em&gt;&lt;/p&gt;




</description>
      <category>comparison</category>
      <category>coding</category>
      <category>javascript</category>
      <category>programming</category>
    </item>
    <item>
      <title>Authorization VS Authentication —  Tools/Strategies</title>
      <dc:creator>V.D</dc:creator>
      <pubDate>Wed, 10 May 2023 12:30:52 +0000</pubDate>
      <link>https://dev.to/vivekdogra02/authorization-vs-authentication-toolsstrategies-23ni</link>
      <guid>https://dev.to/vivekdogra02/authorization-vs-authentication-toolsstrategies-23ni</guid>
      <description>&lt;h3&gt;
  
  
  Authorization VS Authentication — Tools/Strategies
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hULvMs6A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/0%2A7wv-E8oj7MAW-7ju" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hULvMs6A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/0%2A7wv-E8oj7MAW-7ju" alt="Authentication vs Authorizaiton" width="800" height="534"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Authentication vs Authorization&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Today, we are going to cover what exactly the authorization and authentication in the tech world.&lt;/p&gt;

&lt;p&gt;We have different systems/ways which can be used for authorization and authentication into an application. But what exactly is Authorization and Authentication in layman terms.&lt;/p&gt;

&lt;p&gt;Did you ever face challenge while the interviewer asked you about the difference between authorization and authentication as these terms sounds similar?&lt;/p&gt;

&lt;p&gt;Nope that is good but some of us still wondering how can we relate to the term Authorization and Authentication and what comes first or last.&lt;/p&gt;

&lt;p&gt;To clarify the difference,&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Authentication&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It is the process of verifying the identity of a user or device. This is to determine that it is the exact user or device this application verified for.&lt;/p&gt;

&lt;p&gt;For example, User A only has access to relevant information and cannot see the sensitive information of User B.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Authorization&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It is the process of determining what a user or device is allowed to do, after it is being authentication or his identity is being verified.&lt;/p&gt;

&lt;p&gt;For example — Access controls encompass: File permissions, such as the right to create, read, edit or delete a file.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Lets understand the difference between OAuth, OpenID Connect and SAML&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8QhIZtVJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/0%2ASRezRHncfOPbSoR0" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8QhIZtVJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/0%2ASRezRHncfOPbSoR0" alt="img1" width="800" height="1066"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Photo by Chris Curry on Unsplash&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;1. OAuth 2.0 (Open Authentication)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;OAuth(2.0) is an open standard for providing and implementing authorization. It is standard designed to allow a website or web apps to access resources hosted by other web apps on behalf of a user. OAuth2.0 uses access Tokens(a piece of information that represents the authorization on behalf of the end user.&lt;/p&gt;

&lt;p&gt;For more info — &lt;a href="https://auth0.com/intro-to-iam/what-is-oauth-2"&gt;https://auth0.com/intro-to-iam/what-is-oauth-2&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note: OAuth allows a third party application to access a user’s resources with their permission and without their login credentials.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;2. OpenID Connect(OIDC)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;OpenID connect is an open standard/open source solution for initiating and implementing the authentication process. It allows client to verify the identity of the end-user based on the authentication process. It allows users to choose the third-party OpenID provider they want to use to login to any website that accepts the OpenID standard (which could be also custom you have build).&lt;/p&gt;

&lt;p&gt;You have seen it many times a day, when you try to login into the account of medium or Spotify or any other app through google account.&lt;/p&gt;

&lt;p&gt;OpenID is useful for the developers who want to authenticate users, but are not willing to take the risk of storing user records on their own due to security aspects.&lt;/p&gt;

&lt;p&gt;For more info — &lt;a href="https://openid.net/connect/"&gt;https://openid.net/connect/&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note : You can see it as SSO(Single Sign On) for consumer applications.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  3. Security Assertion Markup Language (SAML)
&lt;/h3&gt;

&lt;p&gt;This is also one of the ways for authentication and authorization.&lt;/p&gt;

&lt;p&gt;SAML is an open standard for authentication and authorization and is used mostly in enterprises. It’s a framework for single-sign on (SSO), what it means that if you successfully logged in to an application of your organization, you can also access other apps without the need to re-enter your credentials.&lt;/p&gt;

&lt;p&gt;SAML uses XML to exchange authentication and authorization messages between the specific identity providers to verify user identity and permissions, if access to an application is granted or denied. we can say it like it uses to transfer authentication data between two parties — the identity provider (IdP) and the service provider (SP).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Many benefits of using SAML :-&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;SAML also offers &lt;strong&gt;&lt;em&gt;increased security.&lt;/em&gt;&lt;/strong&gt; Since the identity provider stores all login information, the service provider does not need to store any user credentials on their system.&lt;/li&gt;
&lt;li&gt;It improves the user experience as you only need to &lt;strong&gt;&lt;em&gt;sign in once&lt;/em&gt;&lt;/strong&gt; to access multiple web applications.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;organization&lt;/strong&gt; also benefits from this feature as it means fewer Help Desk calls for password resets.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For more info — How does it works behind the scene- visit — &lt;a href="https://www.onelogin.com/learn/saml"&gt;https://www.onelogin.com/learn/saml&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note: It can be seen as SSO for enterprise applications.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QJdlPJMt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/0%2AnGK0Jf23xdmeVYaO" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QJdlPJMt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/0%2AnGK0Jf23xdmeVYaO" alt="img2" width="800" height="533"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Photo by Christopher Gower on Unsplash&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Summary&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;O_Auth_&lt;/strong&gt; &lt;em&gt;allows a third-party application to access a user’s resources with their permission and without their login credentials&lt;/em&gt; &lt;strong&gt;&lt;em&gt;.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;OIDC&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;adds an authentication layer to OAuth, allowing the application to verify the user’s identity and obtain basic profile information.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;SAML&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;is used for enterprise single sign-on, allowing users to authenticate with their corporate credentials and access enterprise resources.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Thanks for reading
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;👏 Please clap for the story and follow me 👉&lt;/li&gt;
&lt;li&gt;📰 &lt;a href="https://medium.com/@vivekdogra02"&gt;View more content&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;🔔 Follow me: &lt;a href="https://www.linkedin.com/in/vivek-dogra-7404a530/"&gt;LinkedIn&lt;/a&gt;| &lt;a href="https://twitter.com/VivekDo07905087"&gt;Twitter&lt;/a&gt;| &lt;a href="https://github.com/vivekdogra02"&gt;Github&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




</description>
      <category>authentication</category>
      <category>tools</category>
      <category>strategy</category>
      <category>authorization</category>
    </item>
    <item>
      <title>ReactJS vs Angular: Which One Should You Choose?</title>
      <dc:creator>V.D</dc:creator>
      <pubDate>Wed, 10 May 2023 12:29:29 +0000</pubDate>
      <link>https://dev.to/vivekdogra02/reactjs-vs-angular-which-one-should-you-choose-3p92</link>
      <guid>https://dev.to/vivekdogra02/reactjs-vs-angular-which-one-should-you-choose-3p92</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xsGNB-8y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/0%2A7gc8FOlR_0Uu_FgO" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xsGNB-8y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/0%2A7gc8FOlR_0Uu_FgO" alt="img1" width="800" height="534"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;ReactJS, developed by Facebook, is a JavaScript library for building user interfaces. It is lightweight and easy to learn, making it a popular choice among developers. Angular, on the other hand, is a full-featured JavaScript framework developed by Google. It is a more comprehensive solution for building complex applications.&lt;/p&gt;

&lt;p&gt;So, which one should you choose? Let’s take a closer look at the differences between ReactJS and Angular.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;1. Approach&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;ReactJS follows a component-based approach, where UI elements are broken down into smaller, reusable components. Each component has its own logic and state, making it easy to manage and update. React also uses a virtual DOM, which updates only the necessary components, resulting in faster performance.&lt;/p&gt;

&lt;p&gt;Angular, on the other hand, follows a template-based approach, where UI elements are defined in templates and bound to the component’s data. Angular also has a two-way data binding feature, which automatically updates the view when the model changes.&lt;/p&gt;

&lt;h4&gt;
  
  
  2. Features
&lt;/h4&gt;

&lt;p&gt;ReactJS is a lightweight library that focuses on the view layer, leaving the rest of the application to be implemented using other libraries or frameworks. React also has a strong ecosystem, with a wide range of libraries and tools that can be used to extend its functionality.&lt;/p&gt;

&lt;p&gt;Angular, on the other hand, is a complete framework that provides everything you need to build complex applications, including routing, forms, animations, and more. It also has a built-in testing framework, making it easier to write and run tests for your application.&lt;/p&gt;

&lt;h4&gt;
  
  
  3. Learning Curve
&lt;/h4&gt;

&lt;p&gt;ReactJS has a relatively low learning curve, making it easy for beginners to get started. Its syntax is simple and easy to understand, and its documentation is clear and concise. React also has a large community of developers, which means there are plenty of resources available to help you learn.&lt;/p&gt;

&lt;p&gt;Angular, on the other hand, has a steeper learning curve due to its comprehensive feature set. It has a more complex syntax and a larger API, making it harder to learn than React. However, once you master Angular, you can build complex applications with ease.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Both ReactJS and Angular are powerful tools for building web applications. ReactJS is a lightweight library that is easy to learn and has a strong ecosystem, while Angular is a complete framework that provides everything you need to build complex applications. Choosing between the two depends on your project requirements, team’s skill set, and personal preferences.&lt;/p&gt;

&lt;p&gt;At the end of the day, it’s not about which one is better, but which one suits your needs the best. If you’re building a small to medium-sized application and want to get up and running quickly, ReactJS might be the right choice for you. If you’re building a large, complex application that requires a complete solution, Angular might be a better fit.&lt;/p&gt;

&lt;p&gt;So, which one will you choose for your next project? Let us know in the comments below!&lt;/p&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Facebook, Netflix, Airbnb, and Dropbox use ReactJS.&lt;/li&gt;
&lt;li&gt;Google, Microsoft, and IBM use Angular.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Thanks for reading
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;👏 Please clap for the story and follow me 👉&lt;/li&gt;
&lt;li&gt;📰 &lt;a href="https://medium.com/@vivekdogra02"&gt;View more content&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;🔔 Follow me: &lt;a href="https://www.linkedin.com/in/vivek-dogra-7404a530/"&gt;LinkedIn&lt;/a&gt;| &lt;a href="https://twitter.com/VivekDo07905087"&gt;Twitter&lt;/a&gt;| &lt;a href="https://github.com/vivekdogra02"&gt;Github&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




</description>
      <category>angular</category>
      <category>programming</category>
      <category>react</category>
      <category>web3</category>
    </item>
  </channel>
</rss>
