Skip to content

It is not documented that return value of store.dispatch() may be changed by middleware #754

@ronag

Description

@ronag

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions