{"version":3,"sources":["../../src/react/index.ts","../../src/dynamicMiddleware/react/index.ts"],"sourcesContent":["// This must remain here so that the `mangleErrors.cjs` build script\n// does not have to import this into each source file it rewrites.\nimport { formatProdErrorMessage } from '@reduxjs/toolkit';\nexport * from '@reduxjs/toolkit';\nexport { createDynamicMiddleware } from '../dynamicMiddleware/react';","import type { Action as ReduxAction, UnknownAction, Dispatch as ReduxDispatch, Middleware } from 'redux';\nimport type { TSHelpersExtractDispatchExtensions } from '@reduxjs/toolkit';\nimport { createDynamicMiddleware as cDM } from '@reduxjs/toolkit';\nimport type { ReactReduxContextValue } from 'react-redux';\nimport { ReactReduxContext, useDispatch as useDefaultDispatch, createDispatchHook } from 'react-redux';\nimport type { Context } from 'react';\nimport type { DynamicMiddlewareInstance, GetDispatch, GetState, MiddlewareApiConfig } from '@reduxjs/toolkit';\nexport type UseDispatchWithMiddlewareHook<Middlewares extends Middleware<any, State, Dispatch>[] = [], State = any, Dispatch extends ReduxDispatch<UnknownAction> = ReduxDispatch<UnknownAction>> = () => TSHelpersExtractDispatchExtensions<Middlewares> & Dispatch;\nexport type CreateDispatchWithMiddlewareHook<State = any, Dispatch extends ReduxDispatch<UnknownAction> = ReduxDispatch<UnknownAction>> = {\n  <Middlewares extends [Middleware<any, State, Dispatch>, ...Middleware<any, State, Dispatch>[]]>(...middlewares: Middlewares): UseDispatchWithMiddlewareHook<Middlewares, State, Dispatch>;\n  withTypes<MiddlewareConfig extends MiddlewareApiConfig>(): CreateDispatchWithMiddlewareHook<GetState<MiddlewareConfig>, GetDispatch<MiddlewareConfig>>;\n};\ntype ActionFromDispatch<Dispatch extends ReduxDispatch<ReduxAction>> = Dispatch extends ReduxDispatch<infer Action> ? Action : never;\ninterface ReactDynamicMiddlewareInstance<State = any, Dispatch extends ReduxDispatch<UnknownAction> = ReduxDispatch<UnknownAction>> extends DynamicMiddlewareInstance<State, Dispatch> {\n  createDispatchWithMiddlewareHookFactory: (context?: Context<ReactReduxContextValue<State, ActionFromDispatch<Dispatch>> | null>) => CreateDispatchWithMiddlewareHook<State, Dispatch>;\n  createDispatchWithMiddlewareHook: CreateDispatchWithMiddlewareHook<State, Dispatch>;\n}\nexport const createDynamicMiddleware = <State = any, Dispatch extends ReduxDispatch<UnknownAction> = ReduxDispatch<UnknownAction>>(): ReactDynamicMiddlewareInstance<State, Dispatch> => {\n  const instance = cDM<State, Dispatch>();\n  const createDispatchWithMiddlewareHookFactory = (\n  // @ts-ignore\n  context: Context<ReactReduxContextValue<State, ActionFromDispatch<Dispatch>> | null> = ReactReduxContext) => {\n    const useDispatch = context === ReactReduxContext ? useDefaultDispatch : createDispatchHook(context);\n    function createDispatchWithMiddlewareHook<Middlewares extends Middleware<any, State, Dispatch>[]>(...middlewares: Middlewares) {\n      instance.addMiddleware(...middlewares);\n      return useDispatch;\n    }\n    createDispatchWithMiddlewareHook.withTypes = () => createDispatchWithMiddlewareHook;\n    return (createDispatchWithMiddlewareHook as CreateDispatchWithMiddlewareHook<State, Dispatch>);\n  };\n  const createDispatchWithMiddlewareHook = createDispatchWithMiddlewareHookFactory();\n  return {\n    ...instance,\n    createDispatchWithMiddlewareHookFactory,\n    createDispatchWithMiddlewareHook\n  };\n};"],"mappings":";AAGA,cAAc;;;ACDd,SAAS,2BAA2B,WAAW;AAE/C,SAAS,mBAAmB,eAAe,oBAAoB,0BAA0B;AAalF,IAAM,0BAA0B,MAAkJ;AACvL,QAAM,WAAW,IAAqB;AACtC,QAAM,0CAA0C,CAEhD,UAAuF,sBAAsB;AAC3G,UAAM,cAAc,YAAY,oBAAoB,qBAAqB,mBAAmB,OAAO;AACnG,aAASA,qCAA4F,aAA0B;AAC7H,eAAS,cAAc,GAAG,WAAW;AACrC,aAAO;AAAA,IACT;AACA,IAAAA,kCAAiC,YAAY,MAAMA;AACnD,WAAQA;AAAA,EACV;AACA,QAAM,mCAAmC,wCAAwC;AACjF,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA;AAAA,EACF;AACF;","names":["createDispatchWithMiddlewareHook"]}