1

我有一个调度以下操作的容器:

const mapDispatchToProps = (dispatch, ownProps) => { 
    return { 
        getPageTree: (siteId) => { 
            dispatch(getPageTree(siteId)); 
        }
    }
} 

const explorer = connect(
    mapStateToProps, 
    mapDispatchToProps
)(Explorer); 

在我的组件(通过容器发送道具)中,我添加了:

componentWillMount(){ 
    setTimeout(() => this.props.getPageTree()); 
}

传奇:

function* fetchPageTree(action){ 
    try{ 
        const data = yield call(Api.fetchPageTree, action.payload.url); 
        yield put({type: 'FETCH_SUCCEEDED', data}); 
    }catch(error){ 
        yield put({type: 'FETCH_FAILED', error})
    } 
}

export function* watchFetchData(){ 
    console.log('watch'); 
    yield* takeEvery('GET_PAGETREE', fetchPageTree); 
    console.log('finish watch'); 
}

saga watcher在组件中应用时调用fetchPageTree正确使用,但没有执行。 也不会抛出任何错误。 takeEverysetTimeoutfetchPageTree

关于原因的任何想法?

编辑:
index.es6 文件包含以下初始化逻辑,但总体标准:

const sagaMiddleware = createSagaMiddleware(); 
const store = createStore(
    appReducers, //Combined reducers 
    applyMiddleware(sagaMiddleware)
); 

render(
    <Provider store={store}>
        <App />
        </Provider>, 
    document.getElementById('zp-app')
)
sagaMiddleware.run(rootSaga); 
4

1 回答 1

0

你什么时候调用render函数?如果渲染函数在之后调用sagaMiddleware.run(rootSaga);,它应该在延迟调用之后工作this.props.getPageTree

于 2017-03-10T02:05:15.750 回答