In the documentation it says that store.dispatch returns (Object†): The dispatched action.
However, in the middleware examples there is the following example that seems to invalidate that assertion:
/**
* Schedules actions with { meta: { delay: N } } to be delayed by N milliseconds.
* Makes `dispatch` return a function to cancel the timeout in this case.
*/
const timeoutScheduler = store => next => action => {
if (!action.meta || !action.meta.delay) {
return next(action);
}
let timeoutId = setTimeout(
() => next(action),
action.meta.delay
);
return function cancel() {
clearTimeout(timeoutId);
};
};
Where the function cancel will be returned by the dispatch instead of the dispatched action.
This is a bit confusing. Is the documentation wrong? Why would you even want the dispatched action to be returned? Am I missing something?