Fabry
Fabry

Reputation: 1650

Angular ngrx/store one way data flow

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}

Upvotes: 0

Views: 182

Answers (1)

amitdigga
amitdigga

Reputation: 7158

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.

Upvotes: 2

Related Questions