MCPcopy
hub / github.com/reduxjs/redux / applyMiddleware

Function applyMiddleware

src/applyMiddleware.ts:53–77  ·  view source on GitHub ↗
(
  ...middlewares: Middleware[]
)

Source from the content-addressed store, hash-verified

51 ...middlewares: Middleware<any, S, any>[]
52): StoreEnhancer<{ dispatch: Ext }>
53export default function applyMiddleware(
54 ...middlewares: Middleware[]
55): StoreEnhancer<any> {
56 return createStore => (reducer, preloadedState) => {
57 const store = createStore(reducer, preloadedState)
58 let dispatch: Dispatch = () => {
59 throw new Error(
60 'Dispatching while constructing your middleware is not allowed. ' +
61 'Other middleware would not be applied to this dispatch.'
62 )
63 }
64
65 const middlewareAPI: MiddlewareAPI = {
66 getState: store.getState,
67 dispatch: (action, ...args) => dispatch(action, ...args)
68 }
69 const chain = middlewares.map(middleware => middleware(middlewareAPI))
70 dispatch = compose<typeof dispatch>(...chain)(store.dispatch)
71
72 return {
73 ...store,
74 dispatch
75 }
76 }
77}

Callers 7

applyFunction · 0.85
configureStoreFunction · 0.85
index.jsFile · 0.85
configureStoreFunction · 0.85
configureStoreFunction · 0.85
index.jsFile · 0.85

Calls 3

createStoreFunction · 0.85
composeFunction · 0.85
dispatchFunction · 0.70

Tested by

no test coverage detected