Rules of Thumb pt2
Last updated
Last updated
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
Don’t do it
Complicates reducers
Easy to mutate store
Prefer dictionaries vs arrays (NgRx Entity)
Use Selectors to filter/manipulate data from the store
Supports parameters
Memoized
Release memoization
Most projects don’t need NgRx
Simple pattern
Works well with container/presenter
Upgradable to NgRx
Regular Angular service
Private member variable of type BehaviorSubject
Public get prop to access stream
Service methods update stream
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/service-with-subject