nugrx/store 1.5를 썽크 미들웨어와 함께 사용하는 응용 프로그램에서 작업하고 있고 ngrx/store 2.0 및 ngrx/effects로 이동하려고합니다. 여러 가지 관련 작업 및/또는 효과를 처리하는 방법과 관련하여 몇 가지 질문이 있습니다.ngrx/effects를 사용하여 여러 관련 작업/효과/작업을 수행하는 방법
나는 썽크와 이펙트의 "사고 방식"이 다르다는 것과 다른 점을 생각하면서 머리를 쓰려고한다는 것을 알고 있습니다. 내가 사용할 수있는 예제 애플 리케이션을 통해 보았고, 내가 시도하고있는 것에 맞을 것으로 보이지 않는 것을 찾지 못했고, 아마도 나는 여전히 그것을 완전히 틀리게 접근하고있다. 을 감안할 때
@Effect login$: any = this.updates$
.whenAction(LoginActions.LOGIN)
.map(toPayload)
.switchMap(payload =>
this.loginService.login(payload.user, payload.password)
.map(result => this.actions.loginSuccess(value))
.catch((error) => Observable.of(this.loginError(error)))
));
초기 부작용은, 무엇은 "올바른 될 것이라고 : 여기에 시나리오 1
는 로그인을 위해 서버로 요청을 처리 할 수있는 부작용입니다 로그인 성공시 "집"화면으로 탐색을 시작하는 "또는"제안 된 "방법? 이것은 일련의 행동이나 조작을 단순히 유발하는 것으로 일반화 될 수도 있습니다.
몇 가지 옵션을 나는 생각했다 :
(A) 탐색을 트리거 후속 조치를 발사 로그인 성공에 의해 트리거 또 다른 효과를?
@Effect navigateHome$: any = this.updates$
.whenAction(LoginActions.LOGIN_SUCCEEDED)
.mapTo(this.actions.navigateHome());
(b) 로그인 성공에 의해 유발 된 또 다른 효과는 단순히 탐색 작업을 수행하는 것입니까?
@Effect navigateHome$: any = this.updates$
.whenAction(LoginActions.LOGIN_SUCCEEDED)
.do(this.navigateHome())
.filter(() => false);
(c) 초기 로그인 효과에 의해 방출 된 액션을 추가로 연결 하시겠습니까? (샘플은 분명히 정확하지는 않지만 아이디어를 준다)
@Effect login$: any = this.updates$
.whenAction(LoginActions.LOGIN)
.map(toPayload)
.switchMap(password => Observable.concat(
this.loginService.login(passcode)
.map(result => this.actions.loginSuccess(value))
.catch((error) => Observable.of(this.loginError(error))),
Observable.of(this.actions.navigateHome())
));
(d) 기타? 2
시나리오는 요청의 수를 순서대로 할 필요가 경우를 고려하고, 각 요청을 시작으로 우리는 피드백이 사용자에게 제공 할 수 있도록 "상태"를 업데이트 할.
그 라인을 따라 뭔가 썽크의 예 :
다시multiphaseAction() {
return (dispatch) => {
dispatch(this.actions.updateStatus('Executing phase 1');
this.request1()
.flatMap(result => {
dispatch(this.actions.updateStatus('Executing phase 2');
return this.request2();
})
.flatMap(result => {
dispatch(this.actions.updateStatus('Executing phase 3');
return this.request3();
})
...
}
}
, 무엇이 "올바른"또는 효과의 접근 방식을 사용하여 이것에 대해 갈 방법을 "제안"것입니까?
어떻게 든 일부 .do(this.store.dispatch(this.actions.updateStatus(...))
추가하는 대신 다른 할 수 무엇을 더에 붙어, 정말 확신이 하나 ... 나뿐만 아니라이 물건을 배우고
시나리오. –