如何在redux中使用取消功能;timeoutScheduler“;中间件文档示例?

如何在redux中使用取消功能;timeoutScheduler“;中间件文档示例?,redux,middleware,Redux,Middleware,当我实现MW时,它工作得很好,但是如何调用“cancel”函数呢 如果我想清除超时? 以下是代码:() 假设链中的所有其他中间件正确执行返回下一步(操作),那么对dispatch()的调用将返回此cancel函数。例如: const cancel = store.dispatch({type : "INCREMENT", meta : {delay : 1000}}); // kill it off cancel(); 或者,与React组件中的绑定动作创建者类似: // assume we

当我实现MW时,它工作得很好,但是如何调用“cancel”函数呢 如果我想清除超时? 以下是代码:()


假设链中的所有其他中间件正确执行
返回下一步(操作)
,那么对
dispatch()
的调用将返回此
cancel
函数。例如:

const cancel = store.dispatch({type : "INCREMENT", meta : {delay : 1000}});

// kill it off
cancel();
或者,与React组件中的绑定动作创建者类似:

// assume we have an action creator like this passed to connect():
function incrementWithDelay() {
    return {type : "INCREMENT", meta : {delay : 1000}};
}


const cancel = this.props.incrementWithDelay();
cancel();

在这种情况下,使
dispatch
返回一个函数以取消超时。
// assume we have an action creator like this passed to connect():
function incrementWithDelay() {
    return {type : "INCREMENT", meta : {delay : 1000}};
}


const cancel = this.props.incrementWithDelay();
cancel();