简体   繁体   English

redux-saga takeEvery只能使用setTimeout调用

[英]redux-saga takeEvery only called with setTimeout

I have a container that dispatches the following action: 我有一个分派以下操作的容器:

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

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

In my component (to which props are sent through the container) I've added: 在我的组件(通过容器向其发送道具的组件)中添加了:

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

The saga: 传奇:

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'); 
}

The saga watcher calls the fetchPageTree properly using takeEvery when applying setTimeout in the component, but doesn't execute fetchPageTree without. 佐贺观察家调用fetchPageTree正确使用takeEvery申请时setTimeout的成分,但不执行fetchPageTree没有。
No error gets thrown either. 也不会引发任何错误。

Any idea about the cause? 关于原因有什么想法吗?

Edit: 编辑:
The index.es6 file contains the following initialization logic, but is overall standard: 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); 

When did you call render function? 您何时调用了render函数? If the render function is called after sagaMiddleware.run(rootSaga); 如果在sagaMiddleware.run(rootSaga);之后调用了render函数sagaMiddleware.run(rootSaga); , it should work wo deferred call of this.props.getPageTree . ,它应该可以对this.props.getPageTree延迟调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM