0

just a question about the pipeline that I haven't understood yet.

Is the following pipeline the right one?

app.component --> store.select(user).subscribe(loggedUser => { got to home })
app.component --> store.select(loginErrorMessage).subscribe(errorMessage => { show error message })
app.component.login() 
     --> user.service.login(user, password) 
           --> if (login OK) new ActionLogin(loggedUser)
                --> authReducer(state, action ) return {...state, user:action.payload.loggedUser}
           --> else new ActionWrongLogin(errorMessage)
                --> authReducer(state, action ) return {...state, loginErrorMessage:action.payload.errorMessage}

or this one is better:

app.component --> store.select(user).subscribe(loggedUser => { got to home })
app.component --> store.select(loginErrorMessage).subscribe(errorMessage => { show error message })
app.component.login() 
     --> new ActionDoLogin(user, password)
           --> user.service.login(user, password) 
                  --> if (login OK) new ActionLogin(loggedUser)
                        --> authReducer(state, action ) return {...state, user:action.payload.loggedUser}
                  --> else new ActionWrongLogin(errorMessage)
                        --> authReducer(state, action ) return {...state, loginErrorMessage:action.payload.errorMessage}
Fabry
  • 1,498
  • 4
  • 23
  • 47
  • For `new ActionDoLogin(user, password)` following code inside will be handled by `ngrx/effects`? – amitdigga Apr 18 '18 at 13:07
  • Sorry the concept of ngrx/effects is still unknown to me. I'm gonna to read it now. If I answer yes then the right pipeline is the second one? Basically I wolud like to know if I have to call services functions directly from the angular components or from the Actions or Effects as you suggested – Fabry Apr 18 '18 at 13:20
  • Services can be handled inside component directly. `--> new ActionDoLogin(user, password)` is the only difference? What is the intention of this? – amitdigga Apr 18 '18 at 13:43
  • Exactly, this was my question: Can I handle the services directly in the components end then call the Action or the components don't know anything about the services. The difference in the pipeline is that in the first one the component call directly the service and the service call the ActionLogin. In the second one the Component call the ActionDoLogin, the action handle the service and the service call ActionLogin – Fabry Apr 18 '18 at 14:09
  • I found this post that answer to my question in details: https://stackoverflow.com/questions/39552067/what-is-the-purpose-of-ngrx-effects-library/39626187#39626187 – Fabry Apr 18 '18 at 14:32

1 Answers1

2

Based on your comment, you can call service directly in component. There is no need go for extra effort only for this.

And in the second option, structure looks like

onClickLogin -> 
  DoActionLogin ->
    Service.login()

The only purpose of DoActionLogin is to call another method, so this should be eliminated. First option is better.

amitdigga
  • 6,550
  • 4
  • 26
  • 31