Angular NgRx Flashcards

1
Q

What is state in context of ngrx?

A

It can be view state, user state (info), entity data, user selection input or any other data that application tracks

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

The purpose of NgRx is

A
  • Provide formal pattern for organizing app state into one single local state container, managing that state, and communicating state changes throughout components
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

NgRX =

A

redux patter + angular

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Redux pattern helps us to

A

manage application state by providing one way dataflow throughout the application

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Redux patter - how it works

A

View (on user event)
updates the
Component, which dispatches an action
Action is send to reducer, that updates state In store

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Store (state) is

A

a single in-memory client-side state container

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Without ngrx we can use a service to retain some state

A

But with bigger application, we will have more services with similar purpose. Over time we will find ourselves with dozen of these little services

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Without ngrx.
Example with service getting data with http.get.
On init in the component, we would get data each time user navigates to the component.

A

With frequently changing data, this might be desired. We could manually implement a data cache in our service.
But with Ngrx the store provides a client-side cache.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Ngrx helps with loos coupling

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Use NgRx When…

A
  • There is lots of state and little services. The store provides a convenient place to put UI state to retain it between router views
  • When there are excessive HTTP requests. Store provides client-side cache
  • When there are complex component interactions. It keeps components decoupled and helps with race condition issues
  • It has great tooling (time travel debugging)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Don’t use NgRx if

A
  • you’re new to Angular.
  • If application is simple. Extra code required for Ngrx for a simple application
  • If you already have a good state management system
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is Redux Pattern?

A

A way to build a predicteble state container for JavaScript

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

3 Redux Principles

A
  1. Single source of truth called the store
  2. State is read only and only changed by dispatching actions
  3. Changes are made using pure functions called reducers
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What should not go in the redux store

A
  • Unshared state
  • Angular form state
  • Non serializable state
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Exapmles ot actions to dispach to change a change

A
  • Login action after a login form submission
  • toggle side menu action after a button click
  • Retrieve data action when initializing a component
  • Start global spinner action when saving data
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Actions are events that have

A

type property desctribing the action and have optional data associated with them.

Immutability - if you need to change the state - change whole state, not just a property of it

17
Q

Use Reducers to change state. Examlpes:

A
  • Set a userDetail property on login
  • Toggle sideMenuVisible property on button click
  • Set property to something when change data
18
Q

Actions with side efects - Use NGRX EFFECTS library for managing side efects

A
19
Q

Reducers

A

are pure functions and handle each state transition synchronously

20
Q

Advantages of the redux pattern

A

Centralized immutable state

Performance