2016-08-22 2 views
0

반응 나는이 두 가지 작업을 전달합니다 다음 핸들러 ... 내가 대신 같이이 싶습니다 무엇는 돌아 오는

_onPress =() => { 
    let { request,userId} = this.props; 
    this.props.dispatch(acceptRequest(request.id,userId)) 
    this.props.dispatch(navigatePop()); 
} 

은 다음과 ...

입니다
_onPress =() => { 
    let { request,userId} = this.props; 
    this.props.dispatch(acceptRequest(request.id,userId)) 
     .then(this.props.dispatch(navigatePop())) 
} 
내 ActionCreator은 다음과 같습니다

...

export function acceptRequest(requestId,fulfilledBy){ 
    return dispatch => { 
    fulfillments.create(requestId,fulfilledBy) 
     .then(response => response.json()) 
     .then(fulfillment => { 
     dispatch(_acceptRequestSuccess(fulfillment)) 
     }) 
     .catch(err => { 
     console.log(err); 
     dispatch(_acceptRequestError(error)) 
     }) 
    } 
} 

나는 그들이 많은 미들웨어 (들)을 가지고 있음을 알고 그 사람들이 제안하지만, 나는 을 처리하지 않으면이 시나리오에 맞는 것을 보지 못합니다. . 내 특정 경우

, 나는 첫 번째 성공 경우 번째 차이점 조치를 파견하고 싶은,하지만 덜 재사용 때문에 작업 창조자에서이 작업을 수행 할 수 없습니다.

답변

0

오케이, 나는 당신을 오해하고 있습니다. 당신은 redux-thunk를 사용하고 있다고 언급해야합니다.

_onPress =() => { 
    let { request,userId} = this.props; 

    fulfillments.create(requestId,fulfilledBy) 
     .then(response => response.json()) 
     .then(fulfillment => { 
      this.props.dispatch(_acceptRequestSuccess(fulfillment)) 
     }) 
     .then(() => { 
      this.props.dispatch(navigatePop()); 
     }) 
     .catch(err => { 
     console.log(err); 
     this.props.dispatch(_acceptRequestError(error)) 
     }) 
} 

을하지만 당신은 여전히를 반환 할 경우 :

내가 REDUX 조치가 약속을 반환해야합니다 생각하지 않는다, 나는 당신이 구성 요소의 모든 것을 다음과 같이 약속과 함께 연주해야한다고 생각 액션 안에서 함수를 만들면 약속을 되 찾을 수 있다고 약속하십시오 :

export function acceptRequest(requestId,fulfilledBy){ 
    return dispatch => { 
    return fulfillments.create(requestId,fulfilledBy) 
     .then(response => response.json()) 
     .then(fulfillment => { 
     dispatch(_acceptRequestSuccess(fulfillment)) 
     }) 
     .catch(err => { 
     console.log(err); 
     dispatch(_acceptRequestError(error)) 
     }) 
    } 
}