import {Middleware} from '@reduxjs/toolkit';

export const vanillaPromiseMiddleware: Middleware = store => next => (action: unknown) => {
  if (typeof (action as {then?: unknown}).then !== 'function') {
    return next(action);
  }

  return Promise.resolve(action).then((resolvedAction: unknown) => store.dispatch(resolvedAction));
};
