ngrx-workshop
Search…
Table of Contents
Setup and Configuration
Rules of Thumb
Rules of Thumb pt2
NgRx Libraries
NgRx Data
NgRx Entity
Action Creators
NgRx Auto Entity
NgRx Facades
NgRx Facades
Testing
Testing Factory
Testing Reducers
Testing Selectors
Testing Effects
Advanced Actions
3 Types of Actions
Deciders
Splitter Actions
Aggregators
ToDo
Todo
Powered By
GitBook
Rules of Thumb pt2
When to create actions?
Anytime we want to interact with the store or API
No shortcuts
Use classes for actions
Use enums for action names
Export actions types using a union type
3 action approach - request, success, failure
Consider Action Creators
Single action that does everything - Anti Pattern
1
// Single action that does everything
2
export class UpdateUsers implements Action {
3
readonly type = UserActionTypes.UpdateUsers;
4
constructor(public payload: { users: User[] }) {}
5
}
Copied!
Sample Action
Related/Nested Data
Don’t do it
Complicates reducers
Easy to mutate store
Prefer dictionaries vs arrays (NgRx Entity)
Maximize Selectors
Use Selectors to filter/manipulate data from the store
Supports parameters
Memoized
Release memoization
Service With a Subject
Most projects don’t need NgRx
Simple pattern
Works well with container/presenter
Upgradable to NgRx
Service with a subject basics
Regular Angular service
Private member variable of type BehaviorSubject
Public get prop to access stream
Service methods update stream
When NOT to use Service with a Subject?
Application or feature is complex
Want to track state changes
Recreate user errors
Implement advanced logging
Refactor Tour of Heroes to use Service with a subject
https://stackblitz.com/github/jessesanders/tour-of-heroes/tree/
s
ervice-with-subject
Previous
Rules of Thumb
Next - NgRx Libraries
NgRx Data
Last modified
2yr ago
Copy link
Contents
When to create actions?
Sample Action
Related/Nested Data
Maximize Selectors
Service With a Subject
Service with a subject basics
When NOT to use Service with a Subject?