I am using NGXS for state management in my angular application.
Which one is a good practice?
- First HTTP call then Dispatch action in it's subscription?
- First Dispatch action and then HTTP call in it's pipe method?
For example, what is the process of user login using state management? Here, I have to make an HTTP call & then I have to do something depending on the response I get from the HTTP response.
Which one is good practice & why?
Also, please share example. Thanks in advance.
Typical flow would look like so that
LoginInaction, triggers HTTP requestauthService.loginIn()to validate credentials, successful response triggersLoginSuccess, that action sets credentials to service/storage etc (isLoggedIn = true), components/services listening to state change react (or use authService to store logIn state);LoginComponent.ts
AuthService.ts
Effects.ts
Actions.ts
Reducer.ts
HomeComponent.ts