2016-03-04 38 views
0

我正在使用react和flux utils,使用es6。我希望SalesStore在執行自己的調度之前等待SessionStore完成。在SalesStore我有以下,但調度不等。有誰知道這個問題可能是什麼?謝謝。如何等待派遣?

class SalesStore extends ReduceStore { 

    getInitialState() { 
     return {}; 
    } 

    reduce(state, action) { 
     switch(action.type) { 
      case Constants.FETCH_SALES: 
       this.getDispatcher().waitFor([SessionStore.getDispatchToken()]); 
       return state; 

      case Constants.FETCH_SALES_SUCCESS:     
       this.getDispatcher().waitFor([SessionStore.getDispatchToken()]); 
       return action.payload; 

      case Constants.FETCH_SALES_FAILURE: 
       this.getDispatcher().waitFor([SessionStore.getDispatchToken()]); 
       return state; 

      default: 
       return state; 
     } 
    } 

} 

export default new SalesStore(AppDispatcher); 

回答

-1

減速機必須是純功能 所以你應該將異步調用的行動創造者

function getToken(){ 
    // Async call then 
    return { 
    type:'GET_TOKEN_SUCCESS' 
    } 
} 

function getSales(){ 
    // async then 
    return { 
    type:'GET_SALES_SUCCESS' 
    } 
} 

// main action will call `getToken` and `fetchSales` actions 
function fetchSales(params){ 
    return dispatch => { 
     dispatch(getToken()).then((res)=> dispatch(getSales()) 
    } 
} 

要管理的承諾,你可以使用這個middleware