Bacancy Bacancy
  • Customers

      Fortune 500 Clients

      Verizon
      Verizon
      Franklin Templeton
      Franklin Templeton
      The Container Store
      The Container Store
      KPMG
      KPMG
      AdviceWorks
      AdviceWorks
      Bridgestone
      Bridgestone
      NatWest Markets
      NatWest Markets
      Shell
      Shell
      Bangkok Bank Ltd
      Bangkok Bank Ltd
      The Children's Place
      The Children's Place
      Edward Jones
      Edward Jones
      United Parcel Service
      United Parcel Service
      Academy Sports & Outdoors
      Academy Sports & Outdoors

      Case Studies

      React JS VueJS Angular JS React Native Flutter Full Stack
      Ruby on Rails Node JS Golang AI & ML Data Science Java
      Python Salesforce DevOps Laravel Mobile App Embedded & Hardware

      Industries

      Information Technology BFSI Education Marketing & Advertising Manufacturing Retail Logistics & Transportation
      Healthcare eCommerce Public Services Travel & Hospitality Cloud Telecommunications Real Estate
      Explore All
      skype-icon

      Skype ID

      bacancy
      gmail-icon

      Email Us

      [email protected]
      call-yellow-icon

      USA

      +1 347 441 4161
      wp-icon

      UK

      +44 127 479 2316
  • what we do

      Experience

      Digital Workplace Services Product Enhancement

      Insights

      AI & Automation Data Analytics

      SAP Solutions

      SAP Consultation

      Innovate

      Robotic Process Automation Software Engineering Services Internet of Things (IoT) Data Science Artificial Intelligence Machine Learning

      Accelerate

      Cloud - Bacancy Combat Digital Process Automation Open Source Microsoft Dynamics Salesforce

      Assure

      Quality Assurance IT Staff Augmentation

      Embedded & Hardware

      Product Engineering Analog Design Services FPGA Engineering Service Wireless Design Embedded Software Design

      not list

      Hardware Engineering Power Engineering IoT Hardware
      skype-icon

      Skype ID

      bacancy
      gmail-icon

      Email Us

      [email protected]
      call-yellow-icon

      USA

      +1 347 441 4161
      wp-icon

      UK

      +44 127 479 2316
  • who we work with

      Industries

      Banking Financial services & Insurance Startups Oil & Gas

      not list

      Healthcare Life Science Real Estate & Construction Logistics
      bacancy

      Let’s grow together Partner with us

      get quote
      skype-icon

      Skype ID

      bacancy
      gmail-icon

      Email Us

      [email protected]
      call-yellow-icon

      USA

      +1 347 441 4161
      wp-icon

      UK

      +44 127 479 2316
  • about us

      Culture

      Agile Mindset Bacancy Values Bacancy Culture

      About Company

      About Us Leadership Team Awards & Recognition Infrastructure

      not list

      Customer Reviews Our Locations Partnership Media Coverage

      WE ARE

      GREAT PLACE TO WORK - CERTIFIEDTM

      Building and sustaining High-Trust, High-Performance CultureTM

      Bacancy Great Place to Work
      skype-icon

      Skype ID

      bacancy
      gmail-icon

      Email Us

      [email protected]
      call-yellow-icon

      USA

      +1 347 441 4161
      wp-icon

      UK

      +44 127 479 2316
  • technology

      Front End

      Angular Reactjs Vue.js UI/UX

      Platforms

      MS Dynamics Salesforce

      Back End

      Ruby on Rails Node.js Golang Laravel .NET Java Python

      Mobile

      React Native Flutter Android iOS

      Cloud

      AWS DevOps

      QA

      Automation Testing Software Testing

      Embedded & Hardware

      Embedded
      bacancy

      World-class expertise,Delivered

      get quote
      Explore All
      skype-icon

      Skype ID

      bacancy
      gmail-icon

      Email Us

      [email protected]
      call-yellow-icon

      USA

      +1 347 441 4161
      wp-icon

      UK

      +44 127 479 2316
  • PRODUCTS

      EV Products

      Battery Management System Motor Controller AC Charger Explore All

      not list

      CCS2 Controller DC Fast Charger AC Charge Controller
      bacancy

      Let’s grow together Partner with us

      get quote
      skype-icon

      Skype ID

      bacancy
      gmail-icon

      Email Us

      [email protected]
      call-yellow-icon

      USA

      +1 347 441 4161
      wp-icon

      UK

      +44 127 479 2316
hire developers

Bacancy

Bacancy represents the connected world, offering innovative and customer-centric information technology experiences, enabling Enterprises, Associates and the Society to Rise™.

12+

Countries where we have happy customers

1050+

Agile enabled employees

06

World wide offices

12+

Years of Experience

05

Agile Coaches

14

Certified Scrum Masters

1000+

Clients projects

1458

Happy customers

  • Customers
      Case Studies
      • React JS
      • Angular JS
      • Vue JS
      • Node JS
      • AI & ML
      • Explore All
      Fortune 500 Clients
      • Verizon
      • The Container Store
      • KPMG
      • Academy Sports & Outdoors
      • Bangkok Bank Ltd
      • The Children's Place
      • Edward Jones
      • Franklin Templeton
      • AdviceWorks
      • NatWest Markets
      • Bridgestone
      • United Parcel Service
      Industries
      • Information Technology
      • BFSI
      • Education
      • Marketing & Advertising
      • Manufacturing
      • Retail
      • Logistics & Transportation
      • Healthcare
      • eCommerce
      • Public Services
      • Travel & Hospitality
      • Cloud
      • Telecommunications
      • Real Estate
  • What we do
      Experience
      • Digital Workplace Services
      • Product Enhancement
      Insights
      • AI & Automation
      • Data Analytics
      SAP Solutions
      • SAP Consultation
      Innovate
      • Blockchain
      • Software Engineering Services
      • Internet of Things (IoT)
      Accelerate
      • Cloud - Bacancy Combat
      • Digital Process Automation
      • Open Source
      • Microsoft Dynamics
      • Salesforce
      • Service Experience Transformation
      Assure
      • Testing
      • Resource Augmentation
      Embedded & Hardware
      • Product Engineering
      • Analog Design Services
      • FPGA Engineering Service
      • Wireless Design
      • Embedded Software Design
      • Hardware Engineering
      • Power Engineering
      • IoT Hardware
      • AL/ML
  • who we work with
      Industries
      • Banking Financial services & Insurance
      • Startups
      • Oil & Gas
      • Healthcare Life Science
      • Real Estate & Construction
      • Logistics
  • About Us
      About Company
      • About Us
      • Leadership Team
      • Awards & Recognition
      • Infrastructure
      • Our Locations
      • Partnership
      Culture
      • Agile Mindset
      • Bacancy Values
      • Bacancy Culture
  • Technology
      Front End
      • Angular
      • Reactjs
      • Vue.js
      • UI/UX
      Platforms
      • MS Dynamics
      • Salesforce
      Back End
      • Ruby on Rails
      • Node.js
      • Golang
      • Laravel
      • .NET
      • Java
      • Python
      Mobile
      • React Native
      • Flutter
      • Android
      • iOS
      Cloud
      • AWS
      • DevOps
      QA
      • Automation Testing
      • Software Testing
      Embedded & Hardware
      • Embedded
      Explore All
  • Products
    • Battery Management System
    • Motor Controller
    • CCS2 Controller
    • AC Charger
    • DC Fast Charger
    • AC Charge Controller
    • Explore All
  • Careers
  • Work @ Bacancy
  • Blogs
  • Resources
  • Customer Reviews
  • Contact
  • Get Quote
Angular + Redux + RxJs = NGRX

NGRX = A Detailed Introduction of Angular + Redux + RxJs

Chandresh Patel
Chandresh Patel CEO and Agile Coach
Last Updated on January 2, 2023 | Written By: Dolly Shah
December 6, 2019 5 min read

Let’s get started!

What is NgRx?

NGRX is an open-source group of libraries, inspired by the react/redux that helps in managing the state of your application at the root level.

Why Do We Need NgRx?

Does it ever happen to you that you were required to share the data between the components or at the root level? Indeed yes! In angular, Input/Output and service-based sharing are preety popular for sharing data.

Let’s have a look at what to do when a problem arises.

Suppose there are two components, namely componentA that is parent component and componentB is child component. And you are required to share User object between these two.

(i) If we share the data using @Input() from componentA to componentB. If any property of the User object is changed from the componentB, componentA will not get an updated user object.

Why?

The data modification is reflected in the component where the change is made; however, other components won’t be affected that results in state management problems.

(ii) If you are sharing the data using shared service, it will hold the state into a single variable from where the user gets updated state object to all the components. Shared service can obviously solve the state management problem; however, there are chances that a user can make the mistake of copying the state and modifying it from the component. Also, on page reload, all the values get reset.

There’s where we welcome the NgRx. Yay!

Let’s have a look at the core concepts of NgrX.

1. Store – It is an object that brings Actions, Reducers, Selectors together.

A whole application has a single store that contains the current state of your application. That is the state will be loaded in the store. To see your state and the store, you can add the Redux DevTools extension in your browser.

2. Actions – In general, what is action?

In angular actions are the events or activities which are dispatched from our component. Like an event fired by the user. I.e. mouse events.

Actions are the classes that implement the Action interface from ngrx/store. It has two parameters.

i) Payload (optional): The data that is passed to the reducers with its action.

ii) Type: type is read-only which specifies your action type.

3. State – It is an object which holds the latest state value that can be altered by reducers.

4. Reducer – Reducers are the pure functions that contains the switch cases of the actions, having initial state and action as a parameter. However, reducers can change the state of your application and helps to update the state in the store.

5. Effects – What if we need to call an API from the ngrx structure? There come effects in a picture. Effects provide a way to interact with those services and isolate them from the components which ultimately generate other actions on their success and failure.

6. Selectors – In simple words, Selectors helps in giving only selected data from our current state. Selectors are the functions used for obtaining slices of store state.

NGRX store facilitates the function “select” to obtain slices of our store. If we want to apply some logic to that slice before using the data in the components, there is when selectors come into the picture. It slices the state by providing logic and then returns that state.

For e.g.: If there are 100 users present in our current state, but we want only that users who live in India, then we can create a selector variable that holds the sliced state of users and return it to our component.

How NgRx works?

NGRX

Always : NGRX LifeCyle starts from Component

  • An interaction made by a user causes the component to dispatch an action.
  • It checks the corresponding action in reducer, and also checks is that action is provided in effects? If yes, then it performs the operation (like http requests), and ultimately dispatches other actions.
  • Reducers accept the previous state and action and then create the new state.
  • So, we have now successfully got our central state object in our store.
  • Now selectors allow us to get the part of the store we want, and subscribe to changes to it from the component.

Pros of NgRx

There are 3 significant benefits to use Ngrx. They Are:

  • Single Source of Truth
  • Sounds a bit confusing right? Don’t worry, I will make it clear in just a moment.

    It means that the state of your whole application is stored in a single object within a single store. When an angular application is built, the state is manipulated from different components and services by dispatching actions. As the application starts growing, keeping the track of your states becomes difficult and unmanageable. It also gets hard to debug and test your application. So, it would be a way easier to handle the state in one object and one place.

  • State is read-only
  • As the title suggests, the state will be read-only. How it can be achieved? When any action gets dispatched, the reducer function will match the related action and the state object will be changed accordingly. And then, the updated state will get read.

    You are never going to change the state directly, instead, you are going to dispatch actions. This helps in debugging and testing the state as only reducer can change the state.

  • Changes are made with pure functions
  • Reducers are pure functions. States are immutable, so reducer changes something in state, it returns a newly updated state object.

    That’s it. In this first part, I have provided an in-detail explanation of NGRX. I hope you have enjoyed the blog post and thanks for taking some time to read this blog post.

In the second part we will discuss exemplified explanation, code inclusive, of the content above and more. In case of any question or suggestion, please feel free to discuss in the comments section below.

Happy Learning!


Expand Your Digital Horizons With Us.

Start a new project or take an existing one to the next level. Get in touch to start small, scale-up, and go Agile.


Or
E-mail us : [email protected]

Your Success Is Guaranteed !

Related Articles

Voice UI in Web
Divyesh Maheta

July 13, 2023

Web Development

How Can You Leverage Voice User Interface in Web Development?

By : Divyesh Maheta

Quick Summary: There was a time when people used to interact with computers using Character User Interface or CUI; wherein people used to type text...

< 1 Minute Read
Read More
Custom Web App Development
Riken Solanki
Paridhi Wadhwani

September 8, 2022

Web Development

A Complete Guide to Custom Web App Development in 2023

By : Riken Solanki & Paridhi Wadhwani

Quick Summary: Are you also on the threshold of choosing a custom web application for your product but are rattled due to the lack of...

19 Minute Read
Read More
Outsourcing Web Development
Paridhi Wadhwani

October 14, 2021

Web Development

Outsourcing Web Development: Ultimate Guide

By : Paridhi Wadhwani

Quick Summary: One of the most heated debates in an organization includes the popular: In-house web development VS outsourced web development approach when it comes...

10 Minute Read
Read More

How Can We Help You?

india India (HQ)

Corporate House
15-16, Times Corporate Park, Thaltej, Ahmedabad, Gujarat 380059

USA USA

601 Brickell Key Drive, Suite 700, Miami, Florida, 33131, USA

canada Canada

71 Dawes Road, Brampton, On L6X 5N9, Toronto

australia-flag Australia

351A Hampstead Rd, Northfield SA 5085

UAE UAE

1608 Clover Bay, Business Bay, Dubai, UAE. PO Box 62049

sweden Sweden

Junkergatan 4, 126 53 Hagersten


Get in Touch

call-yellow-icon

Contact Number

+1 347 441 4161

gmail-icon

Email Us

[email protected]


  • Employee
  • Brochure
  • Quality Assurance
  • Resources
  • Privacy Policy
  • Sitemap
  • Solutions
  • Careers
  • Testimonials
  • Tutorials
  • QandA
  • Contact Us
  • bacancy google review 4.6
    bacancy google review
    bacancy glassdoor review 4.5
    bacancy glassdoor review
    bacancy clutch review 4.8
    bacancy clutch review
    bacancy goodfirms review 4.8
    bacancy goodfirms review
    iso
    X

    Get Our Newsletter

    Be The First To Get The Latest Updates And Tutorials.

    Request A Free Consultation