2016-07-21 3 views
0

- 모호한 제목에 대해서는 사과드립니다. 내가 가지고있는 이슈는 그 제목을 붙이는 방법이 정말로 혼란 스럽다. 나는 편집 할 준비가되어 있습니다. 기본적으로 나는 react-redux를 사용하고 있으며 데이터베이스의 일부 내용을 업데이트하는 모달이 있습니다. 업데이트 할 때 모든 감속기 상태를 기본값으로 설정하고 모달을 닫습니다. (모든 값을 기본값으로 설정하는 업데이트 기능을 트리거하고 있기 때문에 간단합니다.) 그러나 업데이트 할 때 업데이트의 업데이트 또는 오류 메시지에서 업데이트를 표시하고 싶습니다. 토스터에 대한 구성 요소와 작업을 설정했습니다.비동기 적으로 값을 다시 설정하는 방법 redux

문제는 매장의 상수 작업과 일치하기 전에 모달의 축소 기가 이미 기본값으로 설정되어 있기 때문에 토스트 러가 메시지를 표시하지 않는다는 것입니다. 이것을 극복하기위한 최선의 방법은 무엇입니까?

내가 다른 lifec을 시도

export function checkForRouterConfigUpdateState(routerConfig) { 

    let message = {}; 
    let messageText; 

    switch (_.get(routerConfig, 'updateStatus')) { 
case '_error': 
     messageText = 'An error has been occurred while updating configuration'; 
     return message = { 
     mode: 'normal', 
     title: 'Error', 
     type: 'info', 
     status: _.get(routerConfig, 'updateStatus'), 
     text: messageText 
     }; 

    case '_updated': 
     messageText = 'Successfully Updated'; 
     return message = { 
     mode: 'normal', 
     title: 'Updated', 
     type: 'info', 
     status: _.get(routerConfig, 'updateStatus'), 
     text: messageText 
     }; 
} 
} 

Modal.jsx

//update 
    updateConfig() { 
      this.props.updateConfigNode(node, latestConfigData); //update action 
      this.closeModal(); 
     } 
    closeModal() { 
     this.props.status(false); //Close modal 
     this.props.update(''); //Set update action status 'updated or error' to '' 
     } 

Toastr.jsx

componentDidUpdate() { 
    this.routerConfigNotification(this.props.config); //Getting from store 
    } 
    configNotify(config) { 
     const message = checkForRouterConfigUpdateState(config); 
    if(message) { 
      this._addNotificationNormal(message.title, message.type, message.text); 
      } 
    } 

의 Utils ycle 업데이트 방법이 있지만이 문제를 해결하기 위해 가장 가까운 것은 내가 알고있는 setTimeout 함수를 사용하는 것입니다. 이러한 종류의 비동기 문제를 해결할 수있는 방법이 있다고 확신합니다. 미리 감사드립니다.

+0

음, 어둠에 휩싸여 있지만, 업데이트 할 때 모달 상태를 다시 고집하는 이유는 무엇입니까? 열리기 전에 다시 설정해야합니다. 그렇다면 황금색입니까? – WTK

+0

시도해 보았지만 업데이트를위한 토스트 (toastr) 사이에 다른 동작 트리거가 있는지 확인해보십시오. 상태를 기본값으로 설정하지 않았기 때문에 모달이 표시됩니다. 내 요점은? –

+0

Thunk는 비동기 작업에 사용됩니다. 당신은 그것에 들여다 보았습니까? – andHapp

답변

0

this.props.updateConfigNode(node, latestConfigData)은 약속입니까? 그렇다면 then 블록에 closeModal을 입력하면 요청이 완료 될 때만 호출됩니다.

this.props.updateConfigNode(node, latestConfigData).then(() => { 
    this.closeModal(); 
}); 
+0

그것은 약속이 아니다. –

관련 문제