UNPKG

@reduxjs/toolkit

Version:

The official, opinionated, batteries-included toolset for efficient Redux development

1 lines 4.26 kB
{"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>>>) => 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\n const createDispatchWithMiddlewareHookFactory = ( // @ts-ignore\n context: Context<ReactReduxContextValue<State, ActionFromDispatch<Dispatch>>> = ReactReduxContext) => {\n const useDispatch = // @ts-ignore\n context === ReactReduxContext ? useDefaultDispatch : createDispatchHook(context);\n\n function createDispatchWithMiddlewareHook<Middlewares extends Middleware<any, State, Dispatch>[]>(...middlewares: Middlewares) {\n instance.addMiddleware(...middlewares);\n return useDispatch;\n }\n\n createDispatchWithMiddlewareHook.withTypes = () => createDispatchWithMiddlewareHook;\n\n return (createDispatchWithMiddlewareHook as CreateDispatchWithMiddlewareHook<State, Dispatch>);\n };\n\n const createDispatchWithMiddlewareHook = createDispatchWithMiddlewareHookFactory();\n return { ...instance,\n createDispatchWithMiddlewareHookFactory,\n createDispatchWithMiddlewareHook\n };\n};"],"mappings":"2dAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,6BAAAE,IAAA,eAAAC,EAAAH,GAGAI,EAAAJ,EAAc,4BAHd,gBCEA,IAAAK,EAA+C,4BAE/CC,EAAyF,uBAa5EC,EAA0B,IAAkJ,CACvL,IAAMC,KAAW,EAAAC,yBAAqB,EAEhCC,EAA0C,CAChDC,EAAgF,sBAAsB,CACpG,IAAMC,EACND,IAAY,oBAAoB,EAAAE,eAAqB,sBAAmBF,CAAO,EAE/E,SAASG,KAA4FC,EAA0B,CAC7H,OAAAP,EAAS,cAAc,GAAGO,CAAW,EAC9BH,CACT,CAEA,OAAAE,EAAiC,UAAY,IAAMA,EAE3CA,CACV,EAEMA,EAAmCJ,EAAwC,EACjF,MAAO,CAAE,GAAGF,EACV,wCAAAE,EACA,iCAAAI,CACF,CACF","names":["react_exports","__export","createDynamicMiddleware","__toCommonJS","__reExport","import_toolkit","import_react_redux","createDynamicMiddleware","instance","cDM","createDispatchWithMiddlewareHookFactory","context","useDispatch","useDefaultDispatch","createDispatchWithMiddlewareHook","middlewares"]}