2016-06-28 9 views
0

を完了し、私はそうのようなplainRoutesを使用:getIndexRouteはすべて私の反応-ルータをルートで

getComponent (nextState, cb) { 
    require.ensure([], (require) => { 
     const CoreLayout = require('../layouts/CoreLayout/CoreLayout').default 
     const userActions = require('../store/user').actions 
     store.dispatch(userActions.fetch()) 
     cb(null, CoreLayout) 
    }) 
}, 

今私は.fetchが完了するまで未定義であることができ、私のIndexRouteのために、状態のものが必要:

indexRoute: Default(store), 

デフォルト

import { injectReducer } from '../../store/reducers' 

export default (store) => ({ 
    getComponent (nextState, cb) { 
    const state = store.getState(); 
    require.ensure([], (require) => { 
     const actions = require('../modules').actions 
     store.dispatch(actions.fetch(state.list.selected)) 
     // snipped for brevity 
     cb(null, Default) 
    }, 'default') 
    } 
}) 

最初の非同期フェッチが完了したことを確認する方法を教えてください。

答えて

0

thenは、非同期処理が約束を返す場合に使用できます。たとえば:

//

export default function fetch(id) { 
    return (dispatch) => 
    fetch('/getSomething?id=' + id) 
     .then(response => { 
     dispatch({ 
      type: FETCH 
      payload: response 
     }) 
     }); 
} 

が//デフォルトactions.js

... 
    store.dispatch(actions.fetch(state.list.selected)) 
    .then(response => { 
     cb(null, Default) 
    }); 
    ... 
関連する問題